Compare commits
2 Commits
master
...
MeterBusNo
Author | SHA1 | Date | |
---|---|---|---|
![]() |
3071f5862d | ||
![]() |
dd5579414e |
18
Config.cpp
18
Config.cpp
@ -88,6 +88,24 @@ bool Config::isInitialized() {
|
||||
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);
|
||||
}
|
||||
|
4
Config.h
4
Config.h
@ -49,6 +49,7 @@ namespace Config {
|
||||
const int THERMOMETER_CAL[4] = {12, 16, 20, 24}; // 4 x 4
|
||||
const int THERMOMETER_DEBUG = 28; // 1
|
||||
const int THERMOMETER_INFO = 29; // 1
|
||||
const int METERBUSCLIENT_ADDRESS = 30; // 1
|
||||
|
||||
bool getBool(int pos);
|
||||
void setBool(int pos, bool value);
|
||||
@ -59,6 +60,9 @@ namespace Config {
|
||||
unsigned long getULong(int pos);
|
||||
void setULong(int pos, unsigned long value);
|
||||
|
||||
void initialize();
|
||||
|
||||
|
||||
bool isInitialized();
|
||||
|
||||
void setMagic();
|
||||
|
97
MeterBusClient.cpp
Normal file
97
MeterBusClient.cpp
Normal file
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* MeterBusClient.cpp
|
||||
*
|
||||
* Created on: 08.03.2014
|
||||
* Author: wn
|
||||
*/
|
||||
|
||||
#include "MeterBusClient.h"
|
||||
|
||||
|
||||
MeterBusClient::MeterBusClient() : m_address(0) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void MeterBusClient::begin(CmdServer *cmdServer) {
|
||||
Serial3.begin(1200);
|
||||
|
||||
|
||||
//setAddress(Config::getUChar(Config::METERBUSCLIENT_ADDRESS));
|
||||
}
|
||||
|
||||
void MeterBusClient::setAddress(unsigned char a) {
|
||||
//Config::setUChar(Config::METERBUSCLIENT_ADDRESS, a);
|
||||
m_address = a;
|
||||
}
|
||||
|
||||
unsigned char MeterBusClient::getAddress() {
|
||||
return m_address;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Single Character: E5h
|
||||
*
|
||||
* Short Frame:
|
||||
* Start 10h
|
||||
* C-Field
|
||||
* A-Field
|
||||
* Check-Sum
|
||||
* Stop 16h
|
||||
*
|
||||
* Control Frame:
|
||||
* Start 68h
|
||||
* Length
|
||||
* Length
|
||||
* Start 68h
|
||||
* C-Field
|
||||
* A-Field
|
||||
* CI-Field
|
||||
* Check-Sum
|
||||
* Stop 16h
|
||||
*
|
||||
* Long Frame:
|
||||
* Start 68h
|
||||
* Length
|
||||
* Length
|
||||
* Start 68h
|
||||
* C-Field
|
||||
* A-Field
|
||||
* CI-Field
|
||||
* User-Data
|
||||
* Check-Sum
|
||||
* Stop 16h
|
||||
*
|
||||
* Frames:
|
||||
* SND_NKE
|
||||
* Short Frame, C: 40h
|
||||
*
|
||||
* REQ_UD2
|
||||
* Short Frame, C: 5Bh
|
||||
*/
|
||||
|
||||
|
||||
void MeterBusClient::exec() {
|
||||
static uint8_t state = 0;
|
||||
bool done = false;
|
||||
|
||||
if (Serial3.available()) {
|
||||
int chi;
|
||||
while ((chi = Serial3.read()) != -1) {
|
||||
char ch = (char) chi;
|
||||
switch (state) {
|
||||
case 0:
|
||||
break;
|
||||
}
|
||||
|
||||
if (done) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
47
MeterBusClient.h
Normal file
47
MeterBusClient.h
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* MeterBusClient.h
|
||||
*
|
||||
* Created on: 08.03.2014
|
||||
* Author: wn
|
||||
*/
|
||||
|
||||
#ifndef METERBUSCLIENT_H_
|
||||
#define METERBUSCLIENT_H_
|
||||
|
||||
#include "cmd.h"
|
||||
#include "Config.h"
|
||||
#include "Resources.h"
|
||||
|
||||
|
||||
class MeterBusClient;
|
||||
|
||||
|
||||
|
||||
class MeterBusClientConfig : public Cmd {
|
||||
public:
|
||||
MeterBusClientConfig(MeterBusClient *meterBusClient) : m_meterBusClient(meterBusClient) {};
|
||||
virtual String getCmdName() { return "MBCC"; }
|
||||
virtual String getHelp() { return getResource(MBC_CONFIG_HELP_KEY); }
|
||||
virtual String exec(String params);
|
||||
private:
|
||||
MeterBusClient *m_meterBusClient;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class MeterBusClient {
|
||||
public:
|
||||
MeterBusClient();
|
||||
void begin(CmdServer *cmdServer);
|
||||
void exec();
|
||||
friend class MeterBusClientConfig;
|
||||
private:
|
||||
unsigned char m_address;
|
||||
void setAddress(unsigned char address);
|
||||
unsigned char getAddress();
|
||||
};
|
||||
|
||||
|
||||
|
||||
#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(": ");
|
||||
|
53
Resources.h
53
Resources.h
@ -61,60 +61,9 @@ const uint8_t THERMCONFIG_HELP_KEY = 45;
|
||||
const uint8_t THERMVALUES_HELP_KEY = 46;
|
||||
const uint8_t THERMCALIBRATE_HELP_KEY = 47;
|
||||
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",
|
||||
};
|
||||
|
||||
|
||||
|
||||
const String& getResource(uint8_t key);
|
||||
|
@ -21,6 +21,10 @@ static Thermometer thermometer;
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
|
||||
Config::initialize();
|
||||
|
||||
|
||||
spiInit();
|
||||
|
||||
cmdServer.begin();
|
||||
|
@ -252,7 +252,7 @@ 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);
|
||||
@ -264,6 +264,7 @@ void Thermometer::begin(CmdServer *cmdServer) {
|
||||
Config::setBool(Config::THERMOMETER_INFO, true);
|
||||
Config::setMagic();
|
||||
}
|
||||
*/
|
||||
|
||||
setAlpha(Config::getFloat(Config::THERMOMETER_ALPHA));
|
||||
setPeriodMeasure(Config::getULong(Config::THERMOMETER_PERIOD));
|
||||
|
Loading…
x
Reference in New Issue
Block a user