disable loop mechanism
This commit is contained in:
@ -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=1483538890
|
||||
environment/project/it.baeyens.arduino.core.toolChain.release.1227494943/A.EXTRA.TIME.LOCAL/value=1483552040
|
||||
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=1483535290
|
||||
environment/project/it.baeyens.arduino.core.toolChain.release.1227494943/A.EXTRA.TIME.UTC/value=1483548440
|
||||
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
|
||||
|
@ -145,7 +145,8 @@ MeterBusMaster::MeterBusMaster() : m_sendOctets(this), m_measureCurrent(this),
|
||||
m_calibrationSupport(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_responseCallback(0), m_sampling(true), m_calibration(false), m_errorCount(0),
|
||||
m_disabled(false), m_loopIsDisabled(false), m_disableDelay(0), m_disableTime(0) {
|
||||
pinMode(RX_EN_PIN, OUTPUT);
|
||||
digitalWrite(RX_EN_PIN, RX_DISABLE);
|
||||
Serial3.begin(2400);
|
||||
@ -183,9 +184,22 @@ void MeterBusMaster::prepareResponse(bool err, uint8_t in) {
|
||||
if (err) {
|
||||
m_errorCount++;
|
||||
|
||||
uint8_t errorCode = 0;
|
||||
if (m_disabled) {
|
||||
errorCode = 2;
|
||||
} else {
|
||||
errorCode = 1;
|
||||
m_disableDelay++;
|
||||
|
||||
}
|
||||
|
||||
if (! m_disabled && (m_disableDelay > DISABLE_DELAY)) {
|
||||
m_disabled = true;
|
||||
}
|
||||
|
||||
//Serial << "r1" << endl;
|
||||
if (m_responseCallback != 0) {
|
||||
m_responseCallback->sendError(1, m_errorCount, m_token, m_name);
|
||||
m_responseCallback->sendError(errorCode, m_errorCount, m_token, m_name);
|
||||
}
|
||||
expectedChars = 0;
|
||||
state = 0;
|
||||
@ -259,6 +273,21 @@ void MeterBusMaster::hold() {
|
||||
}
|
||||
}
|
||||
|
||||
void MeterBusMaster::disableLoop() {
|
||||
if (! m_loopIsDisabled) {
|
||||
m_loopIsDisabled = true;
|
||||
m_disableTime = millis();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void MeterBusMaster::enableLoop() {
|
||||
if (m_loopIsDisabled) {
|
||||
m_loopIsDisabled = false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void MeterBusMaster::exec() {
|
||||
if (! m_calibration) {
|
||||
static unsigned long cmdSendTime = 0;
|
||||
@ -289,6 +318,15 @@ void MeterBusMaster::exec() {
|
||||
}
|
||||
}
|
||||
|
||||
// disabling
|
||||
if (m_disabled) {
|
||||
disableLoop();
|
||||
|
||||
if (m_loopIsDisabled && ((millis() - m_disableTime) > DISABLE_TIMEOUT)) {
|
||||
enableLoop();
|
||||
}
|
||||
}
|
||||
|
||||
int serialInChar = Serial3.read();
|
||||
if (serialInChar != -1) {
|
||||
//Serial << "Got: " << _HEX(serialInChar) << endl;
|
||||
|
@ -55,6 +55,8 @@ private:
|
||||
|
||||
const uint8_t SEND_BUFFER_SIZE = 30;
|
||||
const uint8_t RECEIVE_BUFFER_SIZE = 250;
|
||||
const uint8_t DISABLE_DELAY = 5;
|
||||
const uint32_t DISABLE_TIMEOUT = 15000;
|
||||
|
||||
class MeterBusMaster : public RequestSender {
|
||||
public:
|
||||
@ -82,9 +84,15 @@ private:
|
||||
bool m_sampling;
|
||||
bool m_calibration;
|
||||
uint16_t m_errorCount;
|
||||
bool m_disabled;
|
||||
bool m_loopIsDisabled;
|
||||
uint8_t m_disableDelay;
|
||||
uint32_t m_disableTime;
|
||||
void prepareResponse(bool err, uint8_t in);
|
||||
void sample();
|
||||
void hold();
|
||||
void disableLoop();
|
||||
void enableLoop();
|
||||
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user