Compare commits
2 Commits
deadEnd24
...
MeterBusNo
Author | SHA1 | Date | |
---|---|---|---|
3071f5862d | |||
dd5579414e |
55
Config.cpp
55
Config.cpp
@ -8,7 +8,6 @@
|
||||
|
||||
#include <EEPROM.h>
|
||||
#include "Config.h"
|
||||
#include "Resources.h"
|
||||
|
||||
|
||||
|
||||
@ -84,47 +83,29 @@ void Config::setULong(int pos, unsigned long value) {
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char Config::getUChar(int pos) {
|
||||
u_uchar u;
|
||||
for (unsigned int i = 0; i < sizeof(unsigned char); i++) {
|
||||
u.e[i] = EEPROM.read(pos + i);
|
||||
}
|
||||
return u.c;
|
||||
}
|
||||
|
||||
void Config::setUChar(int pos, unsigned char value) {
|
||||
u_uchar u;
|
||||
u.c = value;
|
||||
for (unsigned int i = 0; i < sizeof(unsigned char); i++) {
|
||||
EEPROM.write(pos + i, u.e[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Config::initialize() {
|
||||
if (! Config::isInitialized()) {
|
||||
Serial.println(getResource(CONFIG_INIT_KEY));
|
||||
Config::setFloat(Config::THERMOMETER_ALPHA, 1.0);
|
||||
Config::setULong(Config::THERMOMETER_PERIOD, 1000);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
Config::setFloat(Config::THERMOMETER_CAL[i], 1.0);
|
||||
}
|
||||
Config::setBool(Config::THERMOMETER_DEBUG, true);
|
||||
Config::setBool(Config::THERMOMETER_INFO, true);
|
||||
|
||||
|
||||
Config::setUChar(Config::METERBUSCLIENT_ADDRESS, 0);
|
||||
|
||||
Config::setMagic();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Config::isInitialized() {
|
||||
unsigned int magic = getUInt(MAGIC);
|
||||
return magic == MAGIC_TOKEN;
|
||||
}
|
||||
|
||||
void Config::initialize() {
|
||||
if (! isInitialized()) {
|
||||
//Serial.println(getResource(CONFIG_INIT_KEY));
|
||||
setFloat(THERMOMETER_ALPHA, 1.0);
|
||||
setULong(THERMOMETER_PERIOD, 1000);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
setFloat(THERMOMETER_CAL[i], 1.0);
|
||||
}
|
||||
setBool(THERMOMETER_DEBUG, true);
|
||||
setBool(THERMOMETER_INFO, true);
|
||||
|
||||
|
||||
//Config::setUChar(Config::METERBUSCLIENT_ADDRESS, 0);
|
||||
|
||||
setMagic();
|
||||
}
|
||||
}
|
||||
|
||||
void Config::setMagic() {
|
||||
setUInt(MAGIC, MAGIC_TOKEN);
|
||||
}
|
||||
|
9
Config.h
9
Config.h
@ -39,11 +39,6 @@ typedef union {
|
||||
uint8_t e[sizeof(bool)];
|
||||
} u_bool;
|
||||
|
||||
typedef union {
|
||||
unsigned char c;
|
||||
uint8_t e[sizeof(unsigned char)];
|
||||
} u_uchar;
|
||||
|
||||
|
||||
namespace Config {
|
||||
const unsigned int MAGIC_TOKEN = 0xDEADBEEF;
|
||||
@ -56,7 +51,6 @@ namespace Config {
|
||||
const int THERMOMETER_INFO = 29; // 1
|
||||
const int METERBUSCLIENT_ADDRESS = 30; // 1
|
||||
|
||||
|
||||
bool getBool(int pos);
|
||||
void setBool(int pos, bool value);
|
||||
float getFloat(int pos);
|
||||
@ -65,11 +59,10 @@ namespace Config {
|
||||
void setUInt(int pos, unsigned int value);
|
||||
unsigned long getULong(int pos);
|
||||
void setULong(int pos, unsigned long value);
|
||||
unsigned char getUChar(int pos);
|
||||
void setUChar(int pos, unsigned char value);
|
||||
|
||||
void initialize();
|
||||
|
||||
|
||||
bool isInitialized();
|
||||
|
||||
void setMagic();
|
||||
|
@ -1,11 +1,11 @@
|
||||
/*
|
||||
* meterBusClient.cpp
|
||||
* MeterBusClient.cpp
|
||||
*
|
||||
* Created on: 08.03.2014
|
||||
* Author: wn
|
||||
*/
|
||||
|
||||
#include "meterBusClient.h"
|
||||
#include "MeterBusClient.h"
|
||||
|
||||
|
||||
MeterBusClient::MeterBusClient() : m_address(0) {
|
||||
@ -18,11 +18,11 @@ void MeterBusClient::begin(CmdServer *cmdServer) {
|
||||
Serial3.begin(1200);
|
||||
|
||||
|
||||
setAddress(Config::getUChar(Config::METERBUSCLIENT_ADDRESS));
|
||||
//setAddress(Config::getUChar(Config::METERBUSCLIENT_ADDRESS));
|
||||
}
|
||||
|
||||
void MeterBusClient::setAddress(unsigned char a) {
|
||||
Config::setUChar(Config::METERBUSCLIENT_ADDRESS, a);
|
||||
//Config::setUChar(Config::METERBUSCLIENT_ADDRESS, a);
|
||||
m_address = a;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* meterBusClient.h
|
||||
* MeterBusClient.h
|
||||
*
|
||||
* Created on: 08.03.2014
|
||||
* Author: wn
|
||||
@ -8,11 +8,11 @@
|
||||
#ifndef METERBUSCLIENT_H_
|
||||
#define METERBUSCLIENT_H_
|
||||
|
||||
|
||||
#include "cmd.h"
|
||||
#include "Config.h"
|
||||
#include "Resources.h"
|
||||
|
||||
|
||||
class MeterBusClient;
|
||||
|
||||
|
||||
@ -43,4 +43,5 @@ private:
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* METERBUSCLIENT_H_ */
|
@ -12,6 +12,62 @@
|
||||
|
||||
//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",
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
const String& getResource(uint8_t key) {
|
||||
//TEXT = String("T") + key + String(": ");
|
||||
|
56
Resources.h
56
Resources.h
@ -41,7 +41,7 @@ const uint8_t SET_TEMPERATURE_DEBUG_2_KEY = 25;
|
||||
const uint8_t SET_TEMPERATURE_DEBUG_3_KEY = 26;
|
||||
const uint8_t CONF_COLON_KEY = 27;
|
||||
const uint8_t MODE_COLON_KEY = 28;
|
||||
const uint8_t CONFIG_INIT_KEY = 29;
|
||||
const uint8_t THERMOMETER_BEGIN_1_KEY = 29;
|
||||
const uint8_t STATE_0_KEY = 30;
|
||||
const uint8_t TO_STATE_1_KEY = 31;
|
||||
const uint8_t TO_STATE_10_KEY = 32;
|
||||
@ -64,60 +64,6 @@ const uint8_t CALIBRATION_ZEOR_MODE_HINT_KEY = 48;
|
||||
const uint8_t MBC_CONFIG_HELP_KEY = 49;
|
||||
|
||||
|
||||
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",
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
const String& getResource(uint8_t key);
|
||||
|
@ -7,39 +7,37 @@
|
||||
#include "spi.h"
|
||||
|
||||
|
||||
#define ENABLE_CONFIGURATION_INVALID_CMD 1
|
||||
// #define ENABLE_CONFIGURATION_INVALID_CMD 1
|
||||
|
||||
|
||||
//static CmdServer cmdServer(&Serial);
|
||||
static CmdServer cmdServer(&Serial);
|
||||
#ifdef ENABLE_CONFIGURATION_INVALID_CMD
|
||||
// static ConfigInvalidateCmd configInvalidateCmd;
|
||||
static ConfigInvalidateCmd configInvalidateCmd;
|
||||
#endif
|
||||
//static Uptime uptime;
|
||||
//static Thermometer thermometer;
|
||||
static Uptime uptime;
|
||||
static Thermometer thermometer;
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
|
||||
//Config::initialize();
|
||||
Config::initialize();
|
||||
|
||||
//spiInit();
|
||||
|
||||
//cmdServer.begin();
|
||||
spiInit();
|
||||
|
||||
cmdServer.begin();
|
||||
#ifdef ENABLE_CONFIGURATION_INVALID_CMD
|
||||
//configInvalidateCmd.registerYourself(&cmdServer);
|
||||
configInvalidateCmd.registerYourself(&cmdServer);
|
||||
#endif
|
||||
//uptime.begin(&cmdServer);
|
||||
//thermometer.begin(&cmdServer);
|
||||
uptime.begin(&cmdServer);
|
||||
thermometer.begin(&cmdServer);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
//cmdServer.exec();
|
||||
//uptime.exec();
|
||||
//thermometer.exec();
|
||||
|
||||
Serial.println("Tick");
|
||||
delay(1000);
|
||||
cmdServer.exec();
|
||||
uptime.exec();
|
||||
thermometer.exec();
|
||||
}
|
||||
|
@ -252,7 +252,19 @@ void Thermometer::begin(CmdServer *cmdServer) {
|
||||
AD7190_Calibrate(AD7190_MODE_CAL_INT_ZERO, AD7190_CH_AIN1P_AINCOM);
|
||||
AD7190_Calibrate(AD7190_MODE_CAL_INT_FULL, AD7190_CH_AIN1P_AINCOM);
|
||||
|
||||
|
||||
/*
|
||||
if (! Config::isInitialized()) {
|
||||
Serial.println(getResource(THERMOMETER_BEGIN_1_KEY));
|
||||
Config::setFloat(Config::THERMOMETER_ALPHA, 1.0);
|
||||
Config::setULong(Config::THERMOMETER_PERIOD, 1000);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
Config::setFloat(Config::THERMOMETER_CAL[i], 1.0);
|
||||
}
|
||||
Config::setBool(Config::THERMOMETER_DEBUG, true);
|
||||
Config::setBool(Config::THERMOMETER_INFO, true);
|
||||
Config::setMagic();
|
||||
}
|
||||
*/
|
||||
|
||||
setAlpha(Config::getFloat(Config::THERMOMETER_ALPHA));
|
||||
setPeriodMeasure(Config::getULong(Config::THERMOMETER_PERIOD));
|
||||
@ -262,7 +274,12 @@ void Thermometer::begin(CmdServer *cmdServer) {
|
||||
setDebug(Config::getBool(Config::THERMOMETER_DEBUG));
|
||||
setInfo(Config::getBool(Config::THERMOMETER_INFO));
|
||||
|
||||
//setCalibrateFactor(0, 1.002999);
|
||||
//setCalibrateFactor(1, 1.001804);
|
||||
//setCalibrateFactor(2, 1.000794);
|
||||
//setCalibrateFactor(3, 1.001071);
|
||||
|
||||
// prepare
|
||||
prepareAdc();
|
||||
}
|
||||
|
||||
@ -374,7 +391,6 @@ void Thermometer::exec() {
|
||||
if (currentMillis >= (lastMillis + getPeriodMeasure())) {
|
||||
lastMillis = currentMillis;
|
||||
state = 0;
|
||||
Serial3.println("Tick");
|
||||
}
|
||||
break;
|
||||
|
||||
|
Reference in New Issue
Block a user