From 3071f5862d26af86b1b61dc6a9f1e51b8a6aab23 Mon Sep 17 00:00:00 2001 From: hg Date: Sat, 8 Mar 2014 20:32:38 +0100 Subject: [PATCH] many changes, move large data structure in Resources from h to cpp --- Config.h | 1 + MeterBusClient.cpp | 97 ++++++++++++++++++++++++++++++++++++++++++++++ MeterBusClient.h | 47 ++++++++++++++++++++++ Resources.cpp | 56 ++++++++++++++++++++++++++ Resources.h | 53 +------------------------ ThermometerPro.cpp | 4 ++ thermometer.cpp | 3 +- 7 files changed, 208 insertions(+), 53 deletions(-) create mode 100644 MeterBusClient.cpp create mode 100644 MeterBusClient.h diff --git a/Config.h b/Config.h index e47962c..2e1eda0 100644 --- a/Config.h +++ b/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); diff --git a/MeterBusClient.cpp b/MeterBusClient.cpp new file mode 100644 index 0000000..eacc34a --- /dev/null +++ b/MeterBusClient.cpp @@ -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) { + } + } + } + +} + + diff --git a/MeterBusClient.h b/MeterBusClient.h new file mode 100644 index 0000000..059cf3a --- /dev/null +++ b/MeterBusClient.h @@ -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_ */ diff --git a/Resources.cpp b/Resources.cpp index 9fe0a26..26130b0 100644 --- a/Resources.cpp +++ b/Resources.cpp @@ -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(": "); diff --git a/Resources.h b/Resources.h index 03de30a..e8a8737 100644 --- a/Resources.h +++ b/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); diff --git a/ThermometerPro.cpp b/ThermometerPro.cpp index c52b64d..5e3073d 100644 --- a/ThermometerPro.cpp +++ b/ThermometerPro.cpp @@ -21,6 +21,10 @@ static Thermometer thermometer; void setup() { Serial.begin(9600); + + Config::initialize(); + + spiInit(); cmdServer.begin(); diff --git a/thermometer.cpp b/thermometer.cpp index e90dd1c..76ddd66 100644 --- a/thermometer.cpp +++ b/thermometer.cpp @@ -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));