mbc seems to work partly now, finally

This commit is contained in:
hg
2014-03-08 20:57:17 +01:00
parent b333be0cd9
commit 854d2f202a
7 changed files with 107 additions and 82 deletions

View File

@ -6,18 +6,44 @@
*/
#if 0
#include "meterBusClient.h"
MeterBusClient::MeterBusClient() : m_address(0) {
String MeterBusClientConfig::exec(String params) {
String res = "done";
int space = params.indexOf(' ');
String p1 = "";
char pb1[128];
if (space != -1) {
params.toCharArray(pb1, 128, space+1);
}
if (params.startsWith("a ") && (space != -1)) {
unsigned int a = atoi(pb1);
m_meterBusClient->setAddress(a);
} else {
res = "subcommand not found";
}
return res;
}
MeterBusClient::MeterBusClient() : m_meterBusClientConfig(this), m_address(0) {
}
void MeterBusClient::begin(CmdServer *cmdServer) {
m_meterBusClientConfig.registerYourself(cmdServer);
Serial3.begin(1200);
@ -134,14 +160,17 @@ void MeterBusClient::exec() {
case STATE_IDLE:
if (chi != -1) {
if (ch == 0x10) {
Serial.println("switching to short frame, c field");
m_frame.startDelimiter = 0x10;
state = STATE_SHORT_FRAME;
subState = SUBSTATE_C_FIELD;
} else if (ch == 0x68) {
Serial.println("switching to long frame, length");
m_frame.startDelimiter = 0x68;
state = STATE_LONG_CTRL_FRAME;
subState = SUBSTATE_LENGTH;
} else {
Serial.println("switching to invalid");
state = STATE_INVALID;
}
}
@ -223,6 +252,7 @@ void MeterBusClient::exec() {
break;
case STATE_HANDLE:
Serial.println("handle frame");
if (m_frame.valid) {
handleFrame();
} else {
@ -243,5 +273,4 @@ void MeterBusClient::exec() {
}
}
#endif