mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 03:39:49 +03:00
1w,MBUSv1,inputs resp fixes. update libs!
This commit is contained in:
@@ -1936,7 +1936,7 @@ return itemType;
|
||||
|
||||
// Setup FLAG_SEND_RETRY flag to repeat unsucsessfull modbus tranzaction after release line
|
||||
void Item::mb_fail(int result) {
|
||||
debugSerial<<F("Modbus op failed:")<<_HEX(result)<<endl;
|
||||
debugSerial<<F("Modbus op ")<<itemArr->name<<F(" failed:")<<_HEX(result)<<endl;
|
||||
setFlag(FLAG_SEND_RETRY);
|
||||
// isPendedModbusWrites=true;
|
||||
}
|
||||
@@ -2132,7 +2132,7 @@ int Item::VacomSetFan(itemCmd st) {
|
||||
}
|
||||
uint8_t result;
|
||||
int addr = getArg();
|
||||
debugSerial<<F("VC#")<<addr<<F("=")<<val<<endl;
|
||||
debugSerial<<F("MB: VC#")<<addr<<F("=")<<val<<endl;
|
||||
if (modbusBusy) {
|
||||
// setCmd(cmd);
|
||||
// setVal(val);
|
||||
@@ -2152,7 +2152,7 @@ int Item::VacomSetFan(itemCmd st) {
|
||||
//node.writeSingleRegister(2001-1,1);
|
||||
} else result=node.writeSingleRegister(2001 - 1, 0);
|
||||
delay(100);
|
||||
if (result == node.ku8MBSuccess) debugSerial << F("MB ok")<<endl;
|
||||
if (result == node.ku8MBSuccess) debugSerial << F("MB: ok")<<endl;
|
||||
result = node.writeSingleRegister(2003 - 1, val * 100);
|
||||
modbusBusy = 0;
|
||||
//resumeModbus();
|
||||
@@ -2179,7 +2179,7 @@ int addr;
|
||||
if (it.isValid() && it.itemType == CH_VC) addr=it.getArg();
|
||||
else return 0;
|
||||
|
||||
debugSerial<<F("VC_heat#")<<addr<<F("=")<<val<<F(" cmd=")<<cmd<<endl;
|
||||
debugSerial<<F("MB: VC_heat#")<<addr<<F("=")<<val<<F(" cmd=")<<cmd<<endl;
|
||||
if (modbusBusy) {
|
||||
//setCmd(cmd);
|
||||
//setVal(val);
|
||||
@@ -2219,7 +2219,7 @@ int Item::modbusDimmerSet(int addr, uint16_t _reg, int _regType, int _mask, uint
|
||||
if (_regType != MODBUS_COIL_REG_TYPE || _regType != MODBUS_HOLDING_REG_TYPE) {
|
||||
|
||||
}
|
||||
|
||||
debugSerial<<F("MB: Addr:")<<addr<<F(" Reg:0x")<<_HEX(_reg)<<F(" T:")<<_regType<<F(" Val:0x")<<_HEX(value)<<endl;
|
||||
if (modbusBusy) {
|
||||
mb_fail();
|
||||
return 0;
|
||||
@@ -2251,7 +2251,7 @@ int Item::modbusDimmerSet(int addr, uint16_t _reg, int _regType, int _mask, uint
|
||||
|
||||
|
||||
}
|
||||
debugSerial<<F("Addr:")<<addr<<F(" Reg:0x")<<_HEX(_reg)<<F(" T:")<<_regType<<F(" Val:0x")<<_HEX(value)<<endl;
|
||||
|
||||
switch (_regType) {
|
||||
case MODBUS_HOLDING_REG_TYPE:
|
||||
result = node.writeSingleRegister(_reg, value);
|
||||
@@ -2260,7 +2260,7 @@ int Item::modbusDimmerSet(int addr, uint16_t _reg, int _regType, int _mask, uint
|
||||
result = node.writeSingleCoil(_reg, value);
|
||||
break;
|
||||
default:
|
||||
debugSerial<<F("Not supported reg type\n");
|
||||
debugSerial<<F("MB: Not supported reg type\n");
|
||||
}
|
||||
modbusBusy = 0;
|
||||
//resumeModbus();
|
||||
@@ -2297,12 +2297,13 @@ int Item::checkFM() {
|
||||
modbusSerial.begin(MODBUS_FM_BAUD, MODBUS_FM_PARAM);
|
||||
node.begin(getArg(), modbusSerial);
|
||||
|
||||
|
||||
debugSerial << F("MB: polling FM ") << itemArr->name<< endl;
|
||||
delay(50);
|
||||
result = node.readHoldingRegisters(2101 - 1, 10);
|
||||
|
||||
// do something with data if read is successful
|
||||
if (result == node.ku8MBSuccess) {
|
||||
debugSerial<<F(" FM Val :");
|
||||
debugSerial<<F("MB: FM Val :");
|
||||
for (j = 0; j < 10; j++) {
|
||||
data = node.getResponseBuffer(j);
|
||||
debugSerial<<_HEX(data)<<F("-");
|
||||
@@ -2330,10 +2331,12 @@ int Item::checkFM() {
|
||||
}
|
||||
}
|
||||
} else
|
||||
debugSerial << F("Modbus polling error=") << _HEX(result) << endl;
|
||||
debugSerial << F("MB: polling ") << itemArr->name<< F(" error=") << _HEX(result) << endl;
|
||||
|
||||
if (node.getResponseBuffer(0) & 8) //Active fault
|
||||
{
|
||||
debugSerial << F("MB: polling FM fault ") << itemArr->name<< endl;
|
||||
delay(50);
|
||||
result = node.readHoldingRegisters(2111 - 1, 1);
|
||||
if (result == node.ku8MBSuccess) aJson.addNumberToObject(out, "flt", (long int) node.getResponseBuffer(0));
|
||||
modbusBusy=0;
|
||||
@@ -2342,13 +2345,14 @@ int Item::checkFM() {
|
||||
if (isActive()>0) Off(); //Shut down ///
|
||||
modbusBusy=1;
|
||||
} else aJson.addNumberToObject(out, "flt", (long int)0);
|
||||
|
||||
|
||||
debugSerial << F("MB: polling PI ") << itemArr->name<< endl;
|
||||
delay(50);
|
||||
result = node.readHoldingRegisters(20 - 1, 4);
|
||||
|
||||
// do something with data if read is successful
|
||||
if (result == node.ku8MBSuccess) {
|
||||
debugSerial << F(" PI Val :");
|
||||
debugSerial << F("MB: PI Val :");
|
||||
for (j = 0; j < 4; j++) {
|
||||
data = node.getResponseBuffer(j);
|
||||
debugSerial << data << F("-");
|
||||
@@ -2371,7 +2375,8 @@ int Item::checkFM() {
|
||||
Off(); //Shut down
|
||||
}
|
||||
} else
|
||||
debugSerial << F("Modbus polling error=") << _HEX(result);
|
||||
debugSerial << F("MB: polling PI ") << itemArr->name<< F(" error=") << _HEX(result) << endl;
|
||||
|
||||
outch = aJson.print(out);
|
||||
if (mqttClient.connected() && !ethernetIdleCount)
|
||||
mqttClient.publish(addrstr, outch);
|
||||
@@ -2388,7 +2393,7 @@ int Item::checkModbusDimmer() {
|
||||
|
||||
short numpar = 0;
|
||||
if ((itemArg->type != aJson_Array) || ((numpar = aJson.getArraySize(itemArg)) < 2)) {
|
||||
debugSerial<<F("Illegal arguments\n");
|
||||
debugSerial<<F("MB: Illegal arguments\n");
|
||||
return -4;
|
||||
}
|
||||
|
||||
@@ -2415,7 +2420,7 @@ int Item::checkModbusDimmer() {
|
||||
|
||||
modbusSerial.begin(MODBUS_SERIAL_BAUD, MODBUS_SERIAL_PARAM);
|
||||
node.begin(addr, modbusSerial);
|
||||
|
||||
debugSerial << F("MB: polling dimmer ") << itemArr->name<< endl;
|
||||
switch (_regType) {
|
||||
case MODBUS_HOLDING_REG_TYPE:
|
||||
result = node.readHoldingRegisters(reg, 1);
|
||||
@@ -2430,7 +2435,7 @@ int Item::checkModbusDimmer() {
|
||||
result = node.readInputRegisters(reg, 1);
|
||||
break;
|
||||
default:
|
||||
debugSerial<<F("Not supported reg type\n");
|
||||
debugSerial<<F("MB: Not supported reg type\n");
|
||||
}
|
||||
|
||||
if (result == node.ku8MBSuccess) {
|
||||
@@ -2448,7 +2453,8 @@ int Item::checkModbusDimmer() {
|
||||
pollingItem = items->child;
|
||||
}
|
||||
} else
|
||||
debugSerial << F("Modbus polling error=") << _HEX(result) << endl;
|
||||
debugSerial << F("MB: polling ") << itemArr->name<< F(" error=") << _HEX(result) << endl;
|
||||
|
||||
modbusBusy = 0;
|
||||
//resumeModbus();
|
||||
|
||||
@@ -2457,6 +2463,8 @@ return 1;
|
||||
|
||||
|
||||
int Item::checkModbusDimmer(int data) {
|
||||
if (getFlag(FLAG_SEND_RETRY)) return 0; //Active send transaction
|
||||
|
||||
short mask = getArg(2);
|
||||
itemCmd st;
|
||||
|
||||
|
||||
@@ -140,6 +140,7 @@ volatile unsigned long timerCount=0;
|
||||
volatile int16_t timerNumber=-1;
|
||||
volatile int8_t timerHandlerBusy=0;
|
||||
volatile uint32_t cryptoSalt=0;
|
||||
//uint32_t timerCtr=0;
|
||||
|
||||
aJsonObject *pollingItem = NULL;
|
||||
|
||||
@@ -1978,18 +1979,19 @@ void postTransmission() {
|
||||
|
||||
void TimerHandler(void)
|
||||
{
|
||||
timerHandlerBusy++;
|
||||
interrupts();
|
||||
timerCount=micros();
|
||||
timerCount=micros();
|
||||
if (configLoaded && !timerHandlerBusy)
|
||||
{
|
||||
timerHandlerBusy++;
|
||||
interrupts();
|
||||
|
||||
inputLoop(CHECK_INTERRUPT);
|
||||
#ifdef DMX_SMOOTH
|
||||
DMXOUT_propagate();
|
||||
#endif
|
||||
timerHandlerBusy--;
|
||||
}
|
||||
timerCount=micros()-timerCount;
|
||||
timerHandlerBusy--;
|
||||
timerCount=micros()-timerCount;
|
||||
}
|
||||
|
||||
#if defined(__SAM3X8E__) && defined (TIMER_INT)
|
||||
@@ -2273,9 +2275,7 @@ while ((digitalRead(CONFIG_CLEAN_PIN)==LOW) && !needClean)
|
||||
delay(20);
|
||||
//owReady = 0;
|
||||
|
||||
#ifdef _owire
|
||||
setupOwIdle(&owIdle);
|
||||
#endif
|
||||
|
||||
|
||||
mqttClient.setCallback(mqttCallback);
|
||||
|
||||
@@ -2674,13 +2674,32 @@ if (initializedListeners) ipmodbusLoop();
|
||||
|
||||
}
|
||||
|
||||
//static uint32_t tm=0;
|
||||
|
||||
void owIdle(void) {
|
||||
// timerCtr++;
|
||||
#ifdef _artnet
|
||||
if (artnet && (lanStatus>=HAVE_IP_ADDRESS)) artnet->read();
|
||||
#endif
|
||||
|
||||
wdt_res();
|
||||
inputLoop(CHECK_INTERRUPT);
|
||||
inputLoop(CHECK_INPUT);
|
||||
//inputLoop(CHECK_INTERRUPT);
|
||||
/*
|
||||
if (isTimeOver(tm,millis(),100))
|
||||
{
|
||||
tm=millis();
|
||||
debugSerial<<F("1WT: Tick")<<endl;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#if defined (_espdmx)
|
||||
yield();
|
||||
dmxout.update();
|
||||
#endif
|
||||
|
||||
return; //?????
|
||||
|
||||
#ifdef _dmxin
|
||||
@@ -2688,10 +2707,7 @@ inputLoop(CHECK_INTERRUPT);
|
||||
DMXCheck();
|
||||
#endif
|
||||
|
||||
#if defined (_espdmx)
|
||||
yield();
|
||||
dmxout.update();
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef IPMODBUS
|
||||
if (initializedListeners) ipmodbusLoop();
|
||||
@@ -2707,14 +2723,9 @@ ethernetIdleCount++;
|
||||
ethernetIdleCount--;
|
||||
};
|
||||
|
||||
//static uint32_t tm=0;
|
||||
|
||||
void modbusIdle(void) {
|
||||
/*
|
||||
if (isTimeOver(tm,millis(),500))
|
||||
{
|
||||
tm=millis();
|
||||
debugSerial<<F("MB: Tick")<<endl;
|
||||
} */
|
||||
|
||||
wdt_res();
|
||||
statusLED.poll();
|
||||
yield();
|
||||
|
||||
@@ -28,6 +28,7 @@ e-mail anklimov@gmail.com
|
||||
#include "aJSON.h"
|
||||
|
||||
extern aJsonObject *owArr;
|
||||
extern uint32_t timerCtr;
|
||||
aJsonObject *dev2Check = NULL;
|
||||
|
||||
OneWire *oneWire = NULL;
|
||||
@@ -96,6 +97,7 @@ int owUpdate() {
|
||||
while (oneWire->wireSearch(dev) > 0)
|
||||
{
|
||||
wdt_res();
|
||||
// owIdle();
|
||||
char addrstr[17];
|
||||
SetBytes(dev, 8, addrstr);
|
||||
addrstr[16] = 0;
|
||||
@@ -112,45 +114,7 @@ int owUpdate() {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if (oneWire) oneWire->reset_search();
|
||||
for (short i = 0; i < t_count; i++) wstat[i] &= ~SW_FIND; //absent
|
||||
|
||||
while (oneWire && oneWire->wireSearch(term[t_count]) > 0 && (t_count < t_max) && !isTimeOver(finish,millis(), OW_UPDATE_INTERVAL))//&& finish > millis())
|
||||
{
|
||||
short ifind = -1;
|
||||
if (oneWire->crc8(term[t_count], 7) == term[t_count][7]) {
|
||||
for (short i = 0; i < t_count; i++)
|
||||
if (!memcmp(term[i], term[t_count], 8)) {
|
||||
ifind = i;
|
||||
wstat[i] |= SW_FIND;
|
||||
debugSerial.print(F(" Node:"));
|
||||
PrintBytes(term[t_count], 8,0);
|
||||
processTemp(-1, term[t_count], 0.0); //print note
|
||||
debugSerial.println(F(" alive"));
|
||||
break;
|
||||
}; //alive
|
||||
if (ifind < 0 && sensors && !zero(term[t_count],8))
|
||||
{
|
||||
wstat[t_count] = SW_FIND; //Newly detected
|
||||
debugSerial<<F("dev#")<<t_count<<F(" Addr:");
|
||||
PrintBytes(term[t_count], 8,0);
|
||||
if processTemp(-1, term[t_count], 0.0); //print note
|
||||
debugSerial.println();
|
||||
if (term[t_count][0] == 0x28) {
|
||||
sensors->setResolution(term[t_count], TEMPERATURE_PRECISION);
|
||||
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
||||
oneWire->setStrongPullup();
|
||||
#endif
|
||||
// sensors.requestTemperaturesByAddress(term[t_count]);
|
||||
}
|
||||
t_count++;
|
||||
}
|
||||
}//if
|
||||
} //while
|
||||
|
||||
debugSerial<<F("1-wire count: ")<<t_count<<endl;
|
||||
*/
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
@@ -175,20 +139,7 @@ if (!oneWire)
|
||||
errorSerial<<F("Error 1-w init")<<endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
term = new DeviceAddress[t_max];
|
||||
debugSerial<<F("Term. Free:")<<freeRam()<<endl;
|
||||
//regs = new int [t_max];
|
||||
wstat = new uint16_t[t_max];
|
||||
debugSerial<<F("wstat. Free:")<<freeRam()<<endl;
|
||||
if (!term || ! wstat)
|
||||
{
|
||||
errorSerial<<F("Error 1-w init #2 Free:")<<freeRam()<<endl;
|
||||
return false;
|
||||
}
|
||||
owChanged = owCh;
|
||||
*/
|
||||
|
||||
|
||||
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
||||
Wire.begin();
|
||||
@@ -241,6 +192,9 @@ debugSerial<<F("1WT: setup resolution ")<<item->name<<endl;
|
||||
sensors->setResolution(curDev,TEMPERATURE_PRECISION);
|
||||
item=item->next;
|
||||
}
|
||||
|
||||
//owUpdate();
|
||||
|
||||
return true;
|
||||
|
||||
#else //1w is not disabled
|
||||
@@ -293,13 +247,8 @@ if (!sensors || !owArr)
|
||||
///owUpdate(); //every check circle - scan for new devices
|
||||
}
|
||||
|
||||
/*
|
||||
if (si >= t_count) {
|
||||
owUpdate(); //every check circle - scan for new devices
|
||||
si = 0;
|
||||
return 8000;
|
||||
}
|
||||
*/
|
||||
|
||||
setupOwIdle(&owIdle);
|
||||
DeviceAddress curDev;
|
||||
|
||||
if (dev2Check && SetAddr(dev2Check->name,curDev))
|
||||
@@ -308,14 +257,17 @@ if (!sensors || !owArr)
|
||||
switch (curDev[0]) {
|
||||
|
||||
case 0x28: // Thermomerer
|
||||
|
||||
//debugSerial<<millis()<<" "<<timerCtr<<endl;
|
||||
|
||||
t = sensors->getTempC(curDev);//*10.0;
|
||||
//owIdle();
|
||||
//debugSerial<<millis()<<" "<<timerCtr<<endl;
|
||||
processTemp(dev2Check, t);
|
||||
|
||||
//owIdle();
|
||||
|
||||
sensors->requestTemperaturesByAddress(curDev);
|
||||
|
||||
//owIdle();
|
||||
//debugSerial<<millis()<<" "<<timerCtr<<endl;
|
||||
} //switch
|
||||
}
|
||||
|
||||
@@ -334,34 +286,7 @@ void owLoop() {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
int owFind(DeviceAddress addr) {
|
||||
for (short i = 0; i < t_count; i++) if (!memcmp(term[i], addr, 8)) return i;//find
|
||||
return -1;
|
||||
}
|
||||
|
||||
void owAdd(DeviceAddress addr) {
|
||||
#ifndef OWIRE_DISABLE
|
||||
infoSerial<<F("dev#")<<t_count<<F(" Addr:");
|
||||
PrintBytes(term[t_count], 8,0);
|
||||
infoSerial<<endl;
|
||||
|
||||
if (t_count>=t_max) return;
|
||||
if (zero(term[t_count],8)) return;
|
||||
|
||||
wstat[t_count] = SW_FIND; //Newly detected
|
||||
memcpy(term[t_count], addr, 8);
|
||||
|
||||
|
||||
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
||||
if (term[t_count][0] == 0x28)
|
||||
oneWire->setStrongPullup();
|
||||
#endif
|
||||
t_count++;
|
||||
#endif
|
||||
}
|
||||
|
||||
*/
|
||||
#endif
|
||||
|
||||
void setupOwIdle (void (*ptr)())
|
||||
|
||||
Reference in New Issue
Block a user