From f44646bceda295faae774bd0da3244bd1b72b0da Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Thu, 5 Jan 2017 00:07:07 +0100 Subject: [PATCH] loop control commands and fixes for error disabling --- .settings/org.eclipse.cdt.core.prefs | 4 +-- meterBusMaster.cpp | 8 +++--- meterBusMaster.h | 5 ++++ overCurrentProt.cpp | 39 +++++++++++++++++++++------- overCurrentProt.h | 14 ++-------- 5 files changed, 43 insertions(+), 27 deletions(-) diff --git a/.settings/org.eclipse.cdt.core.prefs b/.settings/org.eclipse.cdt.core.prefs index 812caa7..eb75973 100644 --- a/.settings/org.eclipse.cdt.core.prefs +++ b/.settings/org.eclipse.cdt.core.prefs @@ -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=1483552040 +environment/project/it.baeyens.arduino.core.toolChain.release.1227494943/A.EXTRA.TIME.LOCAL/value=1483571868 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=1483548440 +environment/project/it.baeyens.arduino.core.toolChain.release.1227494943/A.EXTRA.TIME.UTC/value=1483568268 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 diff --git a/meterBusMaster.cpp b/meterBusMaster.cpp index e11fd8a..a4959e1 100644 --- a/meterBusMaster.cpp +++ b/meterBusMaster.cpp @@ -176,7 +176,7 @@ void MeterBusMaster::sendBufferReady(uint16_t sendBufLen, uint8_t token, char *n } void MeterBusMaster::prepareResponse(bool err, uint8_t in) { - //Serial << "resp in, err: " << err << endl; + Serial << "resp in, err: " << err << endl; static int16_t expectedChars = -1; static uint8_t state = 0; @@ -187,6 +187,7 @@ void MeterBusMaster::prepareResponse(bool err, uint8_t in) { uint8_t errorCode = 0; if (m_disabled) { errorCode = 2; + m_disableDelay = 0; } else { errorCode = 1; m_disableDelay++; @@ -277,14 +278,14 @@ void MeterBusMaster::disableLoop() { if (! m_loopIsDisabled) { m_loopIsDisabled = true; m_disableTime = millis(); - + digitalWrite(CURRENT_SHUTDOWN, CURRENT_OFF); } } void MeterBusMaster::enableLoop() { if (m_loopIsDisabled) { m_loopIsDisabled = false; - + digitalWrite(CURRENT_SHUTDOWN, CURRENT_ON); } } @@ -323,6 +324,7 @@ void MeterBusMaster::exec() { disableLoop(); if (m_loopIsDisabled && ((millis() - m_disableTime) > DISABLE_TIMEOUT)) { + m_disabled = false; enableLoop(); } } diff --git a/meterBusMaster.h b/meterBusMaster.h index db90769..5997584 100644 --- a/meterBusMaster.h +++ b/meterBusMaster.h @@ -13,6 +13,11 @@ const uint8_t RX_EN_PIN = 2; const uint8_t RX_ENABLE = LOW; const uint8_t RX_DISABLE = HIGH; +const uint8_t CURRENT_SHUTDOWN = 5; +const uint8_t CURRENT_ON = LOW; +const uint8_t CURRENT_OFF = HIGH; + + const uint8_t CURRENT_IN = A1; const double U_UNIT = 4.9; // mV const double R_SHUNT = 10.0; diff --git a/overCurrentProt.cpp b/overCurrentProt.cpp index bdff00e..0ff37cc 100644 --- a/overCurrentProt.cpp +++ b/overCurrentProt.cpp @@ -1,5 +1,6 @@ #include #include "overCurrentProt.h" +#include @@ -22,20 +23,39 @@ OverCurrentProtCmd::OverCurrentProtCmd(OverCurrentProt *overCurrentProt) : m_ove } String OverCurrentProtCmd::exec(String params) { - return String("") + m_overCurrentProt->getEventCnt(); -} + String res = "done"; -OverCurrentResetCmd::OverCurrentResetCmd(OverCurrentProt *overCurrentProt) : m_overCurrentProt(overCurrentProt) { -} - -String OverCurrentResetCmd::exec(String params) { - m_overCurrentProt->resetEventCnt(); - return "done"; + Print *out = m_server; + if (params.equalsIgnoreCase("help")) { + *out << "help ..... this help page" << endl; + *out << "show ..... show statistics" << endl; + *out << "reset .... reset statistics" << endl; + *out << "disable .. disable loop" << endl; + *out << "enable ... enable loop" << endl; + *out << endl; + } else if (params.equalsIgnoreCase("enable")) { + digitalWrite(CURRENT_SHUTDOWN, CURRENT_ON); + *out << "Loop enabled" << endl; + } else if (params.equalsIgnoreCase("disable")) { + digitalWrite(CURRENT_SHUTDOWN, CURRENT_OFF); + *out << "Loop disabled" << endl; + } else if (params.equalsIgnoreCase("show")) { + *out << "Over current counter: " << m_overCurrentProt->getEventCnt() << endl; + } else if (params.equalsIgnoreCase("reset")) { + m_overCurrentProt->resetEventCnt(); + *out << "Over current counter reseted" << endl; + } else { + *out << "unknown subcommand" << endl; + res = "failed"; + } + return res; } -OverCurrentProt::OverCurrentProt() : m_overCurrentProtCmd(this), m_overCurrentResetCmd(this), + + +OverCurrentProt::OverCurrentProt() : m_overCurrentProtCmd(this), m_eventCnt(0), m_timestamp(0) { } @@ -43,7 +63,6 @@ OverCurrentProt::OverCurrentProt() : m_overCurrentProtCmd(this), m_overCurrentRe void OverCurrentProt::begin(CmdServer *cmdServer) { m_overCurrentProtCmd.registerYourself(cmdServer); - m_overCurrentResetCmd.registerYourself(cmdServer); pinMode(CURRENT_SHUTDOWN, OUTPUT); digitalWrite(CURRENT_SHUTDOWN, CURRENT_ON); overCurrentMarker = false; diff --git a/overCurrentProt.h b/overCurrentProt.h index f4ffd1b..5bdf9be 100644 --- a/overCurrentProt.h +++ b/overCurrentProt.h @@ -18,22 +18,13 @@ class OverCurrentProt; class OverCurrentProtCmd : public Cmd { public: OverCurrentProtCmd(OverCurrentProt *overCurrentProt); - virtual String getCmdName() { return "OCPC"; } - virtual String getHelp() { return "OCP count"; } + virtual String getCmdName() { return "LC"; } + virtual String getHelp() { return "Loop control"; } virtual String exec(String params); private: OverCurrentProt *m_overCurrentProt; }; -class OverCurrentResetCmd : public Cmd { -public: - OverCurrentResetCmd(OverCurrentProt *overCurrentProt); - virtual String getCmdName() { return "OCRST"; } - virtual String getHelp() { return "OCP reset"; } - virtual String exec(String params); -private: - OverCurrentProt *m_overCurrentProt; -}; @@ -46,7 +37,6 @@ public: void resetEventCnt() { m_eventCnt = 0; }; private: OverCurrentProtCmd m_overCurrentProtCmd; - OverCurrentResetCmd m_overCurrentResetCmd; uint32_t m_eventCnt; unsigned long m_timestamp; };