3 Commits

Author SHA1 Message Date
08ab509dc8 deadEnd24 2017-01-09 16:31:10 +01:00
hg
317899fe43 meterBus and nearly everything disabled, still not working 2014-03-08 19:36:00 +01:00
hg
d3d2c75541 start integrating MeterBus client 2014-03-08 13:23:09 +01:00
7 changed files with 215 additions and 30 deletions

View File

@ -8,6 +8,7 @@
#include <EEPROM.h> #include <EEPROM.h>
#include "Config.h" #include "Config.h"
#include "Resources.h"
@ -83,6 +84,42 @@ 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() { bool Config::isInitialized() {
unsigned int magic = getUInt(MAGIC); unsigned int magic = getUInt(MAGIC);
return magic == MAGIC_TOKEN; return magic == MAGIC_TOKEN;

View File

@ -39,6 +39,11 @@ typedef union {
uint8_t e[sizeof(bool)]; uint8_t e[sizeof(bool)];
} u_bool; } u_bool;
typedef union {
unsigned char c;
uint8_t e[sizeof(unsigned char)];
} u_uchar;
namespace Config { namespace Config {
const unsigned int MAGIC_TOKEN = 0xDEADBEEF; const unsigned int MAGIC_TOKEN = 0xDEADBEEF;
@ -49,6 +54,8 @@ namespace Config {
const int THERMOMETER_CAL[4] = {12, 16, 20, 24}; // 4 x 4 const int THERMOMETER_CAL[4] = {12, 16, 20, 24}; // 4 x 4
const int THERMOMETER_DEBUG = 28; // 1 const int THERMOMETER_DEBUG = 28; // 1
const int THERMOMETER_INFO = 29; // 1 const int THERMOMETER_INFO = 29; // 1
const int METERBUSCLIENT_ADDRESS = 30; // 1
bool getBool(int pos); bool getBool(int pos);
void setBool(int pos, bool value); void setBool(int pos, bool value);
@ -58,6 +65,10 @@ namespace Config {
void setUInt(int pos, unsigned int value); void setUInt(int pos, unsigned int value);
unsigned long getULong(int pos); unsigned long getULong(int pos);
void setULong(int pos, unsigned long value); void setULong(int pos, unsigned long value);
unsigned char getUChar(int pos);
void setUChar(int pos, unsigned char value);
void initialize();
bool isInitialized(); bool isInitialized();

View File

@ -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 SET_TEMPERATURE_DEBUG_3_KEY = 26;
const uint8_t CONF_COLON_KEY = 27; const uint8_t CONF_COLON_KEY = 27;
const uint8_t MODE_COLON_KEY = 28; const uint8_t MODE_COLON_KEY = 28;
const uint8_t THERMOMETER_BEGIN_1_KEY = 29; const uint8_t CONFIG_INIT_KEY = 29;
const uint8_t STATE_0_KEY = 30; const uint8_t STATE_0_KEY = 30;
const uint8_t TO_STATE_1_KEY = 31; const uint8_t TO_STATE_1_KEY = 31;
const uint8_t TO_STATE_10_KEY = 32; const uint8_t TO_STATE_10_KEY = 32;
@ -61,6 +61,7 @@ const uint8_t THERMCONFIG_HELP_KEY = 45;
const uint8_t THERMVALUES_HELP_KEY = 46; const uint8_t THERMVALUES_HELP_KEY = 46;
const uint8_t THERMCALIBRATE_HELP_KEY = 47; const uint8_t THERMCALIBRATE_HELP_KEY = 47;
const uint8_t CALIBRATION_ZEOR_MODE_HINT_KEY = 48; const uint8_t CALIBRATION_ZEOR_MODE_HINT_KEY = 48;
const uint8_t MBC_CONFIG_HELP_KEY = 49;
const String TEXT_RESOURCES[] = { const String TEXT_RESOURCES[] = {
@ -113,6 +114,8 @@ const String TEXT_RESOURCES[] = {
"Show thermometer measurement values", "Show thermometer measurement values",
"Thermometer calibration operations", "Thermometer calibration operations",
"No, no, we are in calibration zero mode, so directly switch to state 20", "No, no, we are in calibration zero mode, so directly switch to state 20",
"MeterBus Client Configuration",
}; };

View File

@ -7,33 +7,39 @@
#include "spi.h" #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 #ifdef ENABLE_CONFIGURATION_INVALID_CMD
static ConfigInvalidateCmd configInvalidateCmd; // static ConfigInvalidateCmd configInvalidateCmd;
#endif #endif
static Uptime uptime; //static Uptime uptime;
static Thermometer thermometer; //static Thermometer thermometer;
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
spiInit();
cmdServer.begin(); //Config::initialize();
//spiInit();
//cmdServer.begin();
#ifdef ENABLE_CONFIGURATION_INVALID_CMD #ifdef ENABLE_CONFIGURATION_INVALID_CMD
configInvalidateCmd.registerYourself(&cmdServer); //configInvalidateCmd.registerYourself(&cmdServer);
#endif #endif
uptime.begin(&cmdServer); //uptime.begin(&cmdServer);
thermometer.begin(&cmdServer); //thermometer.begin(&cmdServer);
} }
void loop() { void loop() {
cmdServer.exec(); //cmdServer.exec();
uptime.exec(); //uptime.exec();
thermometer.exec(); //thermometer.exec();
Serial.println("Tick");
delay(1000);
} }

View 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) {
}
}
}
}

46
meterBusClient.h-disabled Normal file
View File

@ -0,0 +1,46 @@
/*
* 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_ */

View File

@ -253,17 +253,6 @@ void Thermometer::begin(CmdServer *cmdServer) {
AD7190_Calibrate(AD7190_MODE_CAL_INT_FULL, 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)); setAlpha(Config::getFloat(Config::THERMOMETER_ALPHA));
setPeriodMeasure(Config::getULong(Config::THERMOMETER_PERIOD)); setPeriodMeasure(Config::getULong(Config::THERMOMETER_PERIOD));
@ -273,12 +262,7 @@ void Thermometer::begin(CmdServer *cmdServer) {
setDebug(Config::getBool(Config::THERMOMETER_DEBUG)); setDebug(Config::getBool(Config::THERMOMETER_DEBUG));
setInfo(Config::getBool(Config::THERMOMETER_INFO)); setInfo(Config::getBool(Config::THERMOMETER_INFO));
//setCalibrateFactor(0, 1.002999);
//setCalibrateFactor(1, 1.001804);
//setCalibrateFactor(2, 1.000794);
//setCalibrateFactor(3, 1.001071);
// prepare
prepareAdc(); prepareAdc();
} }
@ -390,6 +374,7 @@ void Thermometer::exec() {
if (currentMillis >= (lastMillis + getPeriodMeasure())) { if (currentMillis >= (lastMillis + getPeriodMeasure())) {
lastMillis = currentMillis; lastMillis = currentMillis;
state = 0; state = 0;
Serial3.println("Tick");
} }
break; break;