diff --git a/lighthub/item.cpp b/lighthub/item.cpp index 11f0dbb..9da0885 100644 --- a/lighthub/item.cpp +++ b/lighthub/item.cpp @@ -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<name<name<< endl; + delay(50); result = node.readHoldingRegisters(2101 - 1, 10); // do something with data if read is successful if (result == node.ku8MBSuccess) { - debugSerial<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<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<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; diff --git a/lighthub/main.cpp b/lighthub/main.cpp index 365ecb1..fbf6001 100644 --- a/lighthub/main.cpp +++ b/lighthub/main.cpp @@ -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<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<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<name<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<getTempC(curDev);//*10.0; + //owIdle(); +//debugSerial<requestTemperaturesByAddress(curDev); - + //owIdle(); +//debugSerial<=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)())