mbc seems to work partly now, finally
This commit is contained in:
16
Config.cpp
16
Config.cpp
@ -102,20 +102,20 @@ void Config::setUChar(int pos, unsigned char value) {
|
|||||||
|
|
||||||
|
|
||||||
void Config::initialize() {
|
void Config::initialize() {
|
||||||
if (! Config::isInitialized()) {
|
if (! isInitialized()) {
|
||||||
Serial.println(getResource(CONFIG_INIT_KEY));
|
Serial.println(getResource(CONFIG_INIT_KEY));
|
||||||
Config::setFloat(Config::THERMOMETER_ALPHA, 1.0);
|
setFloat(THERMOMETER_ALPHA, 1.0);
|
||||||
Config::setULong(Config::THERMOMETER_PERIOD, 1000);
|
setULong(THERMOMETER_PERIOD, 1000);
|
||||||
for (int i = 0; i < 4; i++) {
|
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);
|
setBool(THERMOMETER_DEBUG, false);
|
||||||
Config::setBool(Config::THERMOMETER_INFO, false);
|
setBool(THERMOMETER_INFO, false);
|
||||||
|
|
||||||
|
|
||||||
Config::setUChar(Config::METERBUSCLIENT_ADDRESS, 0);
|
setUChar(METERBUSCLIENT_ADDRESS, 0);
|
||||||
|
|
||||||
Config::setMagic();
|
setMagic();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,65 @@
|
|||||||
|
|
||||||
//String TEXT;
|
//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) {
|
const String& getResource(uint8_t key) {
|
||||||
//TEXT = String("T") + key + String(": ");
|
//TEXT = String("T") + key + String(": ");
|
||||||
|
59
Resources.h
59
Resources.h
@ -68,65 +68,6 @@ const uint8_t MBC_INVALID_CHECKSUM_KEY = 52;
|
|||||||
const uint8_t MBC_NOT_FOR_ME_KEY = 53;
|
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);
|
const String& getResource(uint8_t key);
|
||||||
|
|
||||||
|
@ -5,31 +5,29 @@
|
|||||||
#include "thermometer.h"
|
#include "thermometer.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "spi.h"
|
#include "spi.h"
|
||||||
// #include "meterBusClient.h"
|
#include "meterBusClient.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static CmdServer cmdServer(&Serial);
|
static CmdServer cmdServer(&Serial);
|
||||||
// static ConfigInvalidateCmd configInvalidateCmd;
|
static ConfigInvalidateCmd configInvalidateCmd;
|
||||||
static Uptime uptime;
|
static Uptime uptime;
|
||||||
static Thermometer thermometer;
|
static Thermometer thermometer;
|
||||||
// static MeterBusClient meterBusClient;
|
static MeterBusClient meterBusClient;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|
||||||
// Config::initialize();
|
Config::initialize();
|
||||||
delay(5000);
|
|
||||||
Serial.println("Hello world!");
|
|
||||||
|
|
||||||
|
|
||||||
spiInit();
|
spiInit();
|
||||||
|
|
||||||
cmdServer.begin();
|
cmdServer.begin();
|
||||||
//configInvalidateCmd.registerYourself(&cmdServer);
|
configInvalidateCmd.registerYourself(&cmdServer);
|
||||||
uptime.begin(&cmdServer);
|
uptime.begin(&cmdServer);
|
||||||
thermometer.begin(&cmdServer);
|
thermometer.begin(&cmdServer);
|
||||||
// meterBusClient.begin(&cmdServer);
|
meterBusClient.begin(&cmdServer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -37,5 +35,5 @@ void loop() {
|
|||||||
cmdServer.exec();
|
cmdServer.exec();
|
||||||
uptime.exec();
|
uptime.exec();
|
||||||
thermometer.exec();
|
thermometer.exec();
|
||||||
// meterBusClient.exec();
|
meterBusClient.exec();
|
||||||
}
|
}
|
||||||
|
@ -6,18 +6,44 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
|
|
||||||
#include "meterBusClient.h"
|
#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) {
|
void MeterBusClient::begin(CmdServer *cmdServer) {
|
||||||
|
m_meterBusClientConfig.registerYourself(cmdServer);
|
||||||
|
|
||||||
|
|
||||||
Serial3.begin(1200);
|
Serial3.begin(1200);
|
||||||
|
|
||||||
|
|
||||||
@ -134,14 +160,17 @@ void MeterBusClient::exec() {
|
|||||||
case STATE_IDLE:
|
case STATE_IDLE:
|
||||||
if (chi != -1) {
|
if (chi != -1) {
|
||||||
if (ch == 0x10) {
|
if (ch == 0x10) {
|
||||||
|
Serial.println("switching to short frame, c field");
|
||||||
m_frame.startDelimiter = 0x10;
|
m_frame.startDelimiter = 0x10;
|
||||||
state = STATE_SHORT_FRAME;
|
state = STATE_SHORT_FRAME;
|
||||||
subState = SUBSTATE_C_FIELD;
|
subState = SUBSTATE_C_FIELD;
|
||||||
} else if (ch == 0x68) {
|
} else if (ch == 0x68) {
|
||||||
|
Serial.println("switching to long frame, length");
|
||||||
m_frame.startDelimiter = 0x68;
|
m_frame.startDelimiter = 0x68;
|
||||||
state = STATE_LONG_CTRL_FRAME;
|
state = STATE_LONG_CTRL_FRAME;
|
||||||
subState = SUBSTATE_LENGTH;
|
subState = SUBSTATE_LENGTH;
|
||||||
} else {
|
} else {
|
||||||
|
Serial.println("switching to invalid");
|
||||||
state = STATE_INVALID;
|
state = STATE_INVALID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -223,6 +252,7 @@ void MeterBusClient::exec() {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case STATE_HANDLE:
|
case STATE_HANDLE:
|
||||||
|
Serial.println("handle frame");
|
||||||
if (m_frame.valid) {
|
if (m_frame.valid) {
|
||||||
handleFrame();
|
handleFrame();
|
||||||
} else {
|
} else {
|
||||||
@ -243,5 +273,4 @@ void MeterBusClient::exec() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
#define METERBUSCLIENT_H_
|
#define METERBUSCLIENT_H_
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
|
|
||||||
#include "cmd.h"
|
#include "cmd.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
@ -71,6 +70,7 @@ public:
|
|||||||
void exec();
|
void exec();
|
||||||
friend class MeterBusClientConfig;
|
friend class MeterBusClientConfig;
|
||||||
private:
|
private:
|
||||||
|
MeterBusClientConfig m_meterBusClientConfig;
|
||||||
unsigned char m_address;
|
unsigned char m_address;
|
||||||
void setAddress(unsigned char address);
|
void setAddress(unsigned char address);
|
||||||
unsigned char getAddress();
|
unsigned char getAddress();
|
||||||
@ -78,7 +78,6 @@ private:
|
|||||||
MeterBusFrame m_frame;
|
MeterBusFrame m_frame;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* METERBUSCLIENT_H_ */
|
#endif /* METERBUSCLIENT_H_ */
|
||||||
|
@ -374,7 +374,6 @@ void Thermometer::exec() {
|
|||||||
if (currentMillis >= (lastMillis + getPeriodMeasure())) {
|
if (currentMillis >= (lastMillis + getPeriodMeasure())) {
|
||||||
lastMillis = currentMillis;
|
lastMillis = currentMillis;
|
||||||
state = 0;
|
state = 0;
|
||||||
Serial3.println("Tick");
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user