From b27f964e20d8257f96763741f2c63ed55cc23756 Mon Sep 17 00:00:00 2001 From: hg Date: Wed, 13 May 2015 17:37:05 +0200 Subject: [PATCH] add command, argument evaluation --- MqttClient.cpp | 37 +++++++++++++++++++++++++++++++++++-- NetMeterBusMaster2.cpp | 7 +++++-- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/MqttClient.cpp b/MqttClient.cpp index 95780c2..1deab9b 100644 --- a/MqttClient.cpp +++ b/MqttClient.cpp @@ -68,9 +68,42 @@ String MqttConfig::exec(String params) { } } else if (params.startsWith("add ")) { // add an mbus client, params: token address period + char paramBuf[64]; + char *paramPtr; + strncpy(paramBuf, params.c_str(), sizeof(paramBuf)); + paramPtr = paramBuf; + char *tokenStr = 0; + char *addressStr = 0; + char *periodStr = 0; + if ((paramPtr != 0) && (*paramPtr != 0)){ + // command + strsep(¶mPtr, " "); + } + if ((paramPtr != 0) && (*paramPtr != 0)){ + tokenStr = strsep(¶mPtr, " "); + } + if ((paramPtr != 0) && (*paramPtr != 0)){ + addressStr = strsep(¶mPtr, " "); + } + if ((paramPtr != 0) && (*paramPtr != 0)){ + periodStr = strsep(¶mPtr, " "); + } - configWrite(CONFIG_DEVICES, sizeof(mc->m_mbusDevTuple), (char*)mc->m_mbusDevTuple); - res = "done"; + if ((tokenStr != 0) && (*tokenStr != 0) && + (addressStr != 0) && (*addressStr != 0) && + (periodStr != 0) && (*periodStr != 0)) { + *out << "Token: " << tokenStr << endl; + *out << "Address: " << addressStr << endl; + *out << "Period: " << periodStr << endl; + + res = "done"; + } else { + *out << "not enough arguments" << endl; + res = "failure"; + } + + + // configWrite(CONFIG_DEVICES, sizeof(mc->m_mbusDevTuple), (char*)mc->m_mbusDevTuple); } else if (params.startsWith("del ")) { // delete an mbus client, params: index int space = params.indexOf(' '); diff --git a/NetMeterBusMaster2.cpp b/NetMeterBusMaster2.cpp index 0699d25..e65d52e 100644 --- a/NetMeterBusMaster2.cpp +++ b/NetMeterBusMaster2.cpp @@ -32,7 +32,7 @@ static MqttClient mqttClient(&meterBusMaster); static OverCurrentProt overCurrentProt; Metro wdogTick = Metro(1000); -Metro dhcpTick = Metro(5* 60 * 1000); +Metro dhcpTick = Metro(60 * 1000); extern "C" { void startup_early_hook( ) __attribute__ ((weak)); @@ -84,6 +84,8 @@ void setup() { } void loop() { + static uint16_t maxTmroutl = 0; + // watchdog refresh cli(); WDOG_REFRESH = 0xa602; @@ -94,9 +96,10 @@ void loop() { if (wdogTick.check() == 1) { uint16_t h = WDOG_TMROUTH; uint16_t l = WDOG_TMROUTL; + maxTmroutl = (maxTmroutl > l) ? maxTmroutl : l; uint16_t c = WDOG_RSTCNT; - Serial << "WDog, h: " << _HEX(h) << ", l: " << _HEX(l) << ", c: " << _HEX(c) << endl; + Serial << "WDog, h: " << _HEX(h) << ", l: " << _HEX(l) << ", c: " << _HEX(c) << ", m: " << _HEX(maxTmroutl) << endl; } if (dhcpTick.check() == 1) {