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

@ -102,20 +102,20 @@ void Config::setUChar(int pos, unsigned char value) {
void Config::initialize() {
if (! Config::isInitialized()) {
if (! isInitialized()) {
Serial.println(getResource(CONFIG_INIT_KEY));
Config::setFloat(Config::THERMOMETER_ALPHA, 1.0);
Config::setULong(Config::THERMOMETER_PERIOD, 1000);
setFloat(THERMOMETER_ALPHA, 1.0);
setULong(THERMOMETER_PERIOD, 1000);
for (int i = 0; i < 4; i++) {
Config::setFloat(Config::THERMOMETER_CAL[i], 1.0);
setFloat(THERMOMETER_CAL[i], 1.0);
}
Config::setBool(Config::THERMOMETER_DEBUG, false);
Config::setBool(Config::THERMOMETER_INFO, false);
setBool(THERMOMETER_DEBUG, false);
setBool(THERMOMETER_INFO, false);
Config::setUChar(Config::METERBUSCLIENT_ADDRESS, 0);
setUChar(METERBUSCLIENT_ADDRESS, 0);
Config::setMagic();
setMagic();
}
}

View File

@ -12,6 +12,65 @@
//String TEXT;
const String TEXT_RESOURCES[] = {
"Text1",
"PeriodMeasure (ms): ",
"Alpha: ",
"Calibration: ",
"Info: ",
"Debug: ",
"COMPILE_TIME_DEBUG: ",
"TimeOuts: ",
"Cycles: ",
"Period (ms): ",
"Alpha: ",
"index: ",
"cal: ",
"t: ",
"ts: ",
", ",
" enable : enable the calibration mode",
" disable : disable the calibration mode",
" show : show parameters for calibration process",
" r : set value of calibration resistor",
" start <0..3>: start calibration on channel",
" stop <0..3>: stop calibration on channel",
" enabled : ",
" r_cal : ",
"setTemperature: i=",
"t=",
"t_smoothed=",
"CONF: ",
"MODE: ",
"Initializing EEPROM",
"State 0",
"Switching to State 1",
"Switching to State 10",
"State 9",
"Timeout: ",
"State 10",
"No, no, we are in calibration high mode, so directly switch to state 20",
"Switching to state 11",
"r_avg on channel ",
"calibration factor: ",
"Calibration stopped",
"Save calibration factor for channel ",
": ",
"HELP List this help for all commands",
"command not found",
"Thermometer configuration operations",
"Show thermometer measurement values",
"Thermometer calibration operations",
"No, no, we are in calibration zero mode, so directly switch to state 20",
"MeterBus Client Configuration",
"Invalid frame",
"No valid frame available",
"Invalid checksum",
"Not for me but for ",
};
const String& getResource(uint8_t key) {
//TEXT = String("T") + key + String(": ");

View File

@ -68,65 +68,6 @@ const uint8_t MBC_INVALID_CHECKSUM_KEY = 52;
const uint8_t MBC_NOT_FOR_ME_KEY = 53;
const String TEXT_RESOURCES[] = {
"Text1",
"PeriodMeasure (ms): ",
"Alpha: ",
"Calibration: ",
"Info: ",
"Debug: ",
"COMPILE_TIME_DEBUG: ",
"TimeOuts: ",
"Cycles: ",
"Period (ms): ",
"Alpha: ",
"index: ",
"cal: ",
"t: ",
"ts: ",
", ",
" enable : enable the calibration mode",
" disable : disable the calibration mode",
" show : show parameters for calibration process",
" r : set value of calibration resistor",
" start <0..3>: start calibration on channel",
" stop <0..3>: stop calibration on channel",
" enabled : ",
" r_cal : ",
"setTemperature: i=",
"t=",
"t_smoothed=",
"CONF: ",
"MODE: ",
"Initializing EEPROM",
"State 0",
"Switching to State 1",
"Switching to State 10",
"State 9",
"Timeout: ",
"State 10",
"No, no, we are in calibration high mode, so directly switch to state 20",
"Switching to state 11",
"r_avg on channel ",
"calibration factor: ",
"Calibration stopped",
"Save calibration factor for channel ",
": ",
"HELP List this help for all commands",
"command not found",
"Thermometer configuration operations",
"Show thermometer measurement values",
"Thermometer calibration operations",
"No, no, we are in calibration zero mode, so directly switch to state 20",
"MeterBus Client Configuration",
"Invalid frame",
"No valid frame available",
"Invalid checksum",
"Not for me but for ",
};
const String& getResource(uint8_t key);

View File

@ -5,31 +5,29 @@
#include "thermometer.h"
#include "Config.h"
#include "spi.h"
// #include "meterBusClient.h"
#include "meterBusClient.h"
static CmdServer cmdServer(&Serial);
// static ConfigInvalidateCmd configInvalidateCmd;
static ConfigInvalidateCmd configInvalidateCmd;
static Uptime uptime;
static Thermometer thermometer;
// static MeterBusClient meterBusClient;
static MeterBusClient meterBusClient;
void setup() {
Serial.begin(9600);
// Config::initialize();
delay(5000);
Serial.println("Hello world!");
Config::initialize();
spiInit();
cmdServer.begin();
//configInvalidateCmd.registerYourself(&cmdServer);
configInvalidateCmd.registerYourself(&cmdServer);
uptime.begin(&cmdServer);
thermometer.begin(&cmdServer);
// meterBusClient.begin(&cmdServer);
meterBusClient.begin(&cmdServer);
}
@ -37,5 +35,5 @@ void loop() {
cmdServer.exec();
uptime.exec();
thermometer.exec();
// meterBusClient.exec();
meterBusClient.exec();
}

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

View File

@ -9,7 +9,6 @@
#define METERBUSCLIENT_H_
#if 0
#include "cmd.h"
#include "Config.h"
@ -71,6 +70,7 @@ public:
void exec();
friend class MeterBusClientConfig;
private:
MeterBusClientConfig m_meterBusClientConfig;
unsigned char m_address;
void setAddress(unsigned char address);
unsigned char getAddress();
@ -78,7 +78,6 @@ private:
MeterBusFrame m_frame;
};
#endif
#endif /* METERBUSCLIENT_H_ */

View File

@ -374,7 +374,6 @@ void Thermometer::exec() {
if (currentMillis >= (lastMillis + getPeriodMeasure())) {
lastMillis = currentMillis;
state = 0;
Serial3.println("Tick");
}
break;