loop disable counter in stats
This commit is contained in:
parent
d28908c735
commit
8cab7f8392
@ -166,10 +166,10 @@ environment/project/it.baeyens.arduino.core.toolChain.release.1227494943/A.EXTRA
|
||||
environment/project/it.baeyens.arduino.core.toolChain.release.1227494943/A.EXTRA.TIME.DTS/value=0
|
||||
environment/project/it.baeyens.arduino.core.toolChain.release.1227494943/A.EXTRA.TIME.LOCAL/delimiter=\:
|
||||
environment/project/it.baeyens.arduino.core.toolChain.release.1227494943/A.EXTRA.TIME.LOCAL/operation=replace
|
||||
environment/project/it.baeyens.arduino.core.toolChain.release.1227494943/A.EXTRA.TIME.LOCAL/value=1483574950
|
||||
environment/project/it.baeyens.arduino.core.toolChain.release.1227494943/A.EXTRA.TIME.LOCAL/value=1483816101
|
||||
environment/project/it.baeyens.arduino.core.toolChain.release.1227494943/A.EXTRA.TIME.UTC/delimiter=\:
|
||||
environment/project/it.baeyens.arduino.core.toolChain.release.1227494943/A.EXTRA.TIME.UTC/operation=replace
|
||||
environment/project/it.baeyens.arduino.core.toolChain.release.1227494943/A.EXTRA.TIME.UTC/value=1483571350
|
||||
environment/project/it.baeyens.arduino.core.toolChain.release.1227494943/A.EXTRA.TIME.UTC/value=1483812501
|
||||
environment/project/it.baeyens.arduino.core.toolChain.release.1227494943/A.EXTRA.TIME.ZONE/delimiter=\:
|
||||
environment/project/it.baeyens.arduino.core.toolChain.release.1227494943/A.EXTRA.TIME.ZONE/operation=replace
|
||||
environment/project/it.baeyens.arduino.core.toolChain.release.1227494943/A.EXTRA.TIME.ZONE/value=3600
|
||||
|
@ -242,10 +242,11 @@ void MqttClient::sendResponse(uint8_t *responseBuffer, uint16_t responseBufferLe
|
||||
}
|
||||
}
|
||||
|
||||
void MqttClient::sendError(uint8_t code, uint16_t count, uint8_t token, char *name) {
|
||||
void MqttClient::sendError(uint8_t code, uint16_t errorCount, uint16_t loopDisabledCount, uint8_t token, char *name) {
|
||||
String msg = String("{ \"metadata\": { \"device\": \"MeterbusHub\", \"error\": ")
|
||||
+ code + String(", \"count\": ") + count + String(", \"token\": ") + token + String(", \"name\": ") + String(name) + String(" }, \"data\": { \"uptime\": ") + m_uptime + String("}}");
|
||||
m_errorCount = count;
|
||||
+ code + String(", \"errCnt\": ") + errorCount + String(", \"loopDsbld\": ") + loopDisabledCount + String(", \"token\": ") + token + String(", \"name\": ") + String(name) + String(" }, \"data\": { \"uptime\": ") + m_uptime + String("}}");
|
||||
m_errorCount = errorCount;
|
||||
m_loopDisabledCount = loopDisabledCount;
|
||||
if (m_disconnectState == 0) {
|
||||
//Serial << "publishing " << msg << endl;
|
||||
//Serial << "length: " << msg.length() << endl;
|
||||
@ -335,7 +336,7 @@ void MqttClient::exec() {
|
||||
}
|
||||
|
||||
byte wdogCnt = WDOG_RSTCNT;
|
||||
String msg = String("{ \"metadata\": { \"device\": \"MeterbusHub\" }, \"data\": { \"uptime\": ") + m_uptime + String(", \"errCnt\": ") + m_errorCount + String(", \"watchdogCnt\": ") + wdogCnt + String("}}");
|
||||
String msg = String("{ \"metadata\": { \"device\": \"MeterbusHub\" }, \"data\": { \"uptime\": ") + m_uptime + String(", \"errCnt\": ") + m_errorCount + String(", \"loopDsbld\": ") + m_loopDisabledCount + String(", \"watchdogCnt\": ") + wdogCnt + String("}}");
|
||||
if (m_disconnectState == 0) {
|
||||
m_mqttClient.publish("IoT/Heartbeat/MeterbusHub", (char*)msg.c_str());
|
||||
} else {
|
||||
|
@ -45,7 +45,7 @@ public:
|
||||
void begin(CmdServer *cmdServer);
|
||||
void exec();
|
||||
virtual void sendResponse(uint8_t *responseBuffer, uint16_t responseBufferLength, uint8_t token, char *name);
|
||||
virtual void sendError(uint8_t code, uint16_t count, uint8_t token, char *name);
|
||||
virtual void sendError(uint8_t code, uint16_t errorCount, uint16_t loopDisabledCount, uint8_t token, char *name);
|
||||
friend class MqttConfig;
|
||||
private:
|
||||
MqttConfig m_mqttConfig;
|
||||
@ -59,6 +59,7 @@ private:
|
||||
uint8_t m_deviceIdx;
|
||||
bool m_enabled;
|
||||
uint16_t m_errorCount;
|
||||
uint16_t m_loopDisabledCount;
|
||||
mbusDevTuple_t m_mbusDevTuple[NUM_OF_DEVICES];
|
||||
};
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
class ResponseCallback {
|
||||
public:
|
||||
virtual void sendResponse(uint8_t *responseBuffer, uint16_t responseBufferLength, uint8_t token, char *name) =0;
|
||||
virtual void sendError(uint8_t code, uint16_t count, uint8_t token, char *name) = 0;
|
||||
virtual void sendError(uint8_t code, uint16_t errorCount, uint16_t loopDisabledCount, uint8_t token, char *name) = 0;
|
||||
};
|
||||
|
||||
class RequestSender {
|
||||
|
@ -122,15 +122,17 @@ void SendOctets::sendResponse(uint8_t *responseBuffer, uint16_t responseBufferLe
|
||||
out->println("");
|
||||
}
|
||||
|
||||
void SendOctets::sendError(uint8_t code, uint16_t count, uint8_t token, char *name) {
|
||||
void SendOctets::sendError(uint8_t code, uint16_t errorCount, uint16_t loopDisabledCount, uint8_t token, char *name) {
|
||||
Print *out = m_server;
|
||||
switch (code) {
|
||||
case 1:
|
||||
out->println("SO RESP: no resp.");
|
||||
out->print("Code: ");
|
||||
out->println(code);
|
||||
out->print("Count: ");
|
||||
out->println(count);
|
||||
out->print("ErrorCount: ");
|
||||
out->println(errorCount);
|
||||
out->print("LoopDisabledCount: ");
|
||||
out->println(loopDisabledCount);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -146,7 +148,8 @@ MeterBusMaster::MeterBusMaster() : m_sendOctets(this), m_measureCurrent(this),
|
||||
m_cmdReadyToSend(false), m_cmdReadyFromRecv(false), m_expectResponse(false),
|
||||
m_sendBufLen(0), m_recvBufLen(0), m_retransmitCount(0), m_token(0),
|
||||
m_responseCallback(0), m_sampling(true), m_calibration(false), m_errorCount(0),
|
||||
m_disabled(false), m_loopIsDisabled(false), m_disableDelay(0), m_disableTime(0) {
|
||||
m_disabled(false), m_loopIsDisabled(false), m_disableThreshold(0), m_disableTime(0),
|
||||
m_loopDisabledCount(0) {
|
||||
pinMode(RX_EN_PIN, OUTPUT);
|
||||
digitalWrite(RX_EN_PIN, RX_DISABLE);
|
||||
Serial3.begin(2400);
|
||||
@ -187,20 +190,21 @@ void MeterBusMaster::prepareResponse(bool err, uint8_t in) {
|
||||
uint8_t errorCode = 0;
|
||||
if (m_disabled) {
|
||||
errorCode = 2;
|
||||
m_disableDelay = 0;
|
||||
m_disableThreshold = 0;
|
||||
} else {
|
||||
errorCode = 1;
|
||||
m_disableDelay++;
|
||||
m_disableThreshold++;
|
||||
|
||||
}
|
||||
|
||||
if (! m_disabled && (m_disableDelay > DISABLE_DELAY)) {
|
||||
if (! m_disabled && (m_disableThreshold > DISABLE_THRESHOLD)) {
|
||||
m_disabled = true;
|
||||
m_loopDisabledCount++;
|
||||
}
|
||||
|
||||
//Serial << "r1" << endl;
|
||||
if (m_responseCallback != 0) {
|
||||
m_responseCallback->sendError(errorCode, m_errorCount, m_token, m_name);
|
||||
m_responseCallback->sendError(errorCode, m_errorCount, m_loopDisabledCount, m_token, m_name);
|
||||
}
|
||||
expectedChars = 0;
|
||||
state = 0;
|
||||
|
@ -30,7 +30,7 @@ public:
|
||||
virtual String getHelp() { return "Send octets"; }
|
||||
virtual String exec(String params);
|
||||
virtual void sendResponse(uint8_t *responseBuffer, uint16_t responseBufferLength, uint8_t token, char *name);
|
||||
virtual void sendError(uint8_t code, uint16_t count, uint8_t token, char *name);
|
||||
virtual void sendError(uint8_t code, uint16_t errorCount, uint16_t loopDisabledCount, uint8_t token, char *name);
|
||||
private:
|
||||
RequestSender *m_meterBusMaster;
|
||||
};
|
||||
@ -60,7 +60,7 @@ private:
|
||||
|
||||
const uint8_t SEND_BUFFER_SIZE = 30;
|
||||
const uint8_t RECEIVE_BUFFER_SIZE = 250;
|
||||
const uint8_t DISABLE_DELAY = 5;
|
||||
const uint8_t DISABLE_THRESHOLD = 5;
|
||||
const uint32_t DISABLE_TIMEOUT = 15000;
|
||||
|
||||
class MeterBusMaster : public RequestSender {
|
||||
@ -91,8 +91,9 @@ private:
|
||||
uint16_t m_errorCount;
|
||||
bool m_disabled;
|
||||
bool m_loopIsDisabled;
|
||||
uint8_t m_disableDelay;
|
||||
uint8_t m_disableThreshold;
|
||||
uint32_t m_disableTime;
|
||||
uint16_t m_loopDisabledCount;
|
||||
void prepareResponse(bool err, uint8_t in);
|
||||
void sample();
|
||||
void hold();
|
||||
|
Loading…
x
Reference in New Issue
Block a user