Compare commits
2 Commits
master
...
MeterBusNo
Author | SHA1 | Date | |
---|---|---|---|
3071f5862d | |||
dd5579414e |
1
.hgtags
1
.hgtags
@ -1,2 +1 @@
|
|||||||
55e33ac01375df1e3e295262fcc03a568ddf48e3 before_switch_to_arm
|
55e33ac01375df1e3e295262fcc03a568ddf48e3 before_switch_to_arm
|
||||||
4c0a748c4e0681d22d1d3e1faf4e09266a64dc8c MBC_WORKING_FIRST_FRAME_ANSWERED
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<configuration id="it.baeyens.arduino.core.toolChain.release.1909314976" name="Release">
|
<configuration id="it.baeyens.arduino.core.toolChain.release.1909314976" name="Release">
|
||||||
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
|
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
|
||||||
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
||||||
<provider class="it.baeyens.arduino.toolchain.ArduinoLanguageProvider" console="false" env-hash="-1881042430836" id="it.baeyens.arduino.languageSettingsProvider" keep-relative-paths="false" name="Arduino Compiler Settings" parameter="${COMMAND} -E -P -v -dD ${INPUTS}" prefer-non-shared="true">
|
<provider class="it.baeyens.arduino.toolchain.ArduinoLanguageProvider" console="false" env-hash="-2011256820" id="it.baeyens.arduino.languageSettingsProvider" keep-relative-paths="false" name="Arduino Compiler Settings" parameter="${COMMAND} -E -P -v -dD ${INPUTS}" prefer-non-shared="true">
|
||||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||||
</provider>
|
</provider>
|
||||||
|
@ -171,6 +171,7 @@ unsigned char AD7190_Init(void)
|
|||||||
// TIME_DelayMs(1);
|
// TIME_DelayMs(1);
|
||||||
delay(1); // arduino function
|
delay(1); // arduino function
|
||||||
regVal = AD7190_GetRegisterValue(AD7190_REG_ID, 1, 1);
|
regVal = AD7190_GetRegisterValue(AD7190_REG_ID, 1, 1);
|
||||||
|
Serial.print(String("regVal: ") + regVal + "\n");
|
||||||
if( (regVal & AD7190_ID_MASK) != ID_AD7190)
|
if( (regVal & AD7190_ID_MASK) != ID_AD7190)
|
||||||
{
|
{
|
||||||
status = 0;
|
status = 0;
|
||||||
|
35
Config.cpp
35
Config.cpp
@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "Resources.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -84,49 +83,29 @@ void Config::setULong(int pos, unsigned long value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char Config::getUChar(int pos) {
|
bool Config::isInitialized() {
|
||||||
u_uchar u;
|
unsigned int magic = getUInt(MAGIC);
|
||||||
for (unsigned int i = 0; i < sizeof(unsigned char); i++) {
|
return magic == MAGIC_TOKEN;
|
||||||
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() {
|
void Config::initialize() {
|
||||||
if (! isInitialized()) {
|
if (! isInitialized()) {
|
||||||
Serial.println(getResource(CONFIG_INIT_KEY));
|
//Serial.println(getResource(CONFIG_INIT_KEY));
|
||||||
setFloat(THERMOMETER_ALPHA, 1.0);
|
setFloat(THERMOMETER_ALPHA, 1.0);
|
||||||
setULong(THERMOMETER_PERIOD, 1000);
|
setULong(THERMOMETER_PERIOD, 1000);
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
setFloat(THERMOMETER_CAL[i], 1.0);
|
setFloat(THERMOMETER_CAL[i], 1.0);
|
||||||
}
|
}
|
||||||
setBool(THERMOMETER_DEBUG, false);
|
setBool(THERMOMETER_DEBUG, true);
|
||||||
setBool(THERMOMETER_INFO, false);
|
setBool(THERMOMETER_INFO, true);
|
||||||
|
|
||||||
|
|
||||||
setUChar(METERBUSCLIENT_ADDRESS, 0);
|
//Config::setUChar(Config::METERBUSCLIENT_ADDRESS, 0);
|
||||||
setBool(METERBUSCLIENT_DEBUG, false);
|
|
||||||
setBool(METERBUSCLIENT_INFO, false);
|
|
||||||
|
|
||||||
setMagic();
|
setMagic();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Config::isInitialized() {
|
|
||||||
unsigned int magic = getUInt(MAGIC);
|
|
||||||
return magic == MAGIC_TOKEN;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Config::setMagic() {
|
void Config::setMagic() {
|
||||||
setUInt(MAGIC, MAGIC_TOKEN);
|
setUInt(MAGIC, MAGIC_TOKEN);
|
||||||
}
|
}
|
||||||
|
12
Config.h
12
Config.h
@ -39,11 +39,6 @@ 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;
|
||||||
@ -55,10 +50,6 @@ namespace Config {
|
|||||||
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
|
const int METERBUSCLIENT_ADDRESS = 30; // 1
|
||||||
const int METERBUSCLIENT_DEBUG = 31; // 1
|
|
||||||
const int METERBUSCLIENT_INFO = 32; // 1
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool getBool(int pos);
|
bool getBool(int pos);
|
||||||
void setBool(int pos, bool value);
|
void setBool(int pos, bool value);
|
||||||
@ -68,11 +59,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();
|
void initialize();
|
||||||
|
|
||||||
|
|
||||||
bool isInitialized();
|
bool isInitialized();
|
||||||
|
|
||||||
void setMagic();
|
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_ */
|
@ -9,12 +9,9 @@
|
|||||||
#include "Resources.h"
|
#include "Resources.h"
|
||||||
|
|
||||||
|
|
||||||
#define USE_REAL_TEXTS 1
|
|
||||||
|
|
||||||
|
//String TEXT;
|
||||||
|
|
||||||
#ifndef USE_REAL_TEXTS
|
|
||||||
String TEXT;
|
|
||||||
#else
|
|
||||||
const String TEXT_RESOURCES[] = {
|
const String TEXT_RESOURCES[] = {
|
||||||
"Text1",
|
"Text1",
|
||||||
"PeriodMeasure (ms): ",
|
"PeriodMeasure (ms): ",
|
||||||
@ -66,38 +63,15 @@ const String TEXT_RESOURCES[] = {
|
|||||||
"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",
|
"MeterBus Client Configuration",
|
||||||
"Invalid frame",
|
|
||||||
"No valid frame available",
|
|
||||||
"Invalid checksum",
|
|
||||||
"Not for me but for ",
|
|
||||||
"Unhandled frame",
|
|
||||||
"s: ",
|
|
||||||
"l: ",
|
|
||||||
"c: ",
|
|
||||||
"a: ",
|
|
||||||
"ci: ",
|
|
||||||
"u: ",
|
|
||||||
" ",
|
|
||||||
"frames: ",
|
|
||||||
"my frames: ",
|
|
||||||
"invalid frames: ",
|
|
||||||
"invalid checksum: ",
|
|
||||||
"mbus address: ",
|
|
||||||
"collisions: ",
|
|
||||||
"r: ",
|
|
||||||
"setR: i=",
|
|
||||||
"r=",
|
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const String& getResource(uint8_t key) {
|
const String& getResource(uint8_t key) {
|
||||||
#ifndef USE_REAL_TEXTS
|
//TEXT = String("T") + key + String(": ");
|
||||||
TEXT = String(" T") + key + String(": ");
|
//return TEXT;
|
||||||
return TEXT;
|
|
||||||
#else
|
|
||||||
return TEXT_RESOURCES[key];
|
return TEXT_RESOURCES[key];
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
25
Resources.h
25
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 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 CONFIG_INIT_KEY = 29;
|
const uint8_t THERMOMETER_BEGIN_1_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;
|
||||||
@ -62,27 +62,8 @@ 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 uint8_t MBC_CONFIG_HELP_KEY = 49;
|
||||||
const uint8_t MBC_INVALID_FRAME_KEY = 50;
|
|
||||||
const uint8_t MBC_NO_VALID_FRAME_KEY = 51;
|
|
||||||
const uint8_t MBC_INVALID_CHECKSUM_KEY = 52;
|
|
||||||
const uint8_t MBC_NOT_FOR_ME_KEY = 53;
|
|
||||||
const uint8_t MBC_UNHANDLED_FRAME_KEY = 54;
|
|
||||||
const uint8_t MBC_START_DELIMITER_KEY = 55;
|
|
||||||
const uint8_t MBC_LENGTH_KEY = 56;
|
|
||||||
const uint8_t MBC_CFIELD_KEY = 57;
|
|
||||||
const uint8_t MBC_ADDRESS_KEY = 58;
|
|
||||||
const uint8_t MBC_CIFIELD_KEY = 59;
|
|
||||||
const uint8_t MBC_USERDATA_KEY = 60;
|
|
||||||
const uint8_t SPACE_KEY = 61;
|
|
||||||
const uint8_t MBC_FRAMES_KEY = 62;
|
|
||||||
const uint8_t MBC_MYFRAMES_KEY = 63;
|
|
||||||
const uint8_t MBC_INVALID_FRAMES_KEY = 64;
|
|
||||||
const uint8_t MBC_INVALID_CHECKSUM_CNT_KEY = 65;
|
|
||||||
const uint8_t MBC_ADDRESS_LONG_KEY = 66;
|
|
||||||
const uint8_t MBC_COLLISION_CNT_KEY = 67;
|
|
||||||
const uint8_t R_KEY = 68;
|
|
||||||
const uint8_t SET_R_KEY = 69;
|
|
||||||
const uint8_t R_EQUALS_KEY = 70;
|
|
||||||
|
|
||||||
|
|
||||||
const String& getResource(uint8_t key);
|
const String& getResource(uint8_t key);
|
||||||
|
@ -5,24 +5,22 @@
|
|||||||
#include "thermometer.h"
|
#include "thermometer.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "spi.h"
|
#include "spi.h"
|
||||||
#include "meterBusClient.h"
|
|
||||||
|
|
||||||
|
|
||||||
const unsigned char OK_LED_PIN = 2;
|
// #define ENABLE_CONFIGURATION_INVALID_CMD 1
|
||||||
|
|
||||||
|
|
||||||
static CmdServer cmdServer(&Serial);
|
static CmdServer cmdServer(&Serial);
|
||||||
static ConfigInvalidateCmd configInvalidateCmd;
|
#ifdef ENABLE_CONFIGURATION_INVALID_CMD
|
||||||
|
static ConfigInvalidateCmd configInvalidateCmd;
|
||||||
|
#endif
|
||||||
static Uptime uptime;
|
static Uptime uptime;
|
||||||
static Thermometer thermometer;
|
static Thermometer thermometer;
|
||||||
static MeterBusClient meterBusClient;
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
pinMode(OK_LED_PIN, OUTPUT);
|
Serial.begin(9600);
|
||||||
digitalWrite(OK_LED_PIN, LOW);
|
|
||||||
|
|
||||||
// delay(5000);
|
|
||||||
|
|
||||||
Serial.begin(115200);
|
|
||||||
|
|
||||||
Config::initialize();
|
Config::initialize();
|
||||||
|
|
||||||
@ -30,12 +28,11 @@ void setup() {
|
|||||||
spiInit();
|
spiInit();
|
||||||
|
|
||||||
cmdServer.begin();
|
cmdServer.begin();
|
||||||
|
#ifdef ENABLE_CONFIGURATION_INVALID_CMD
|
||||||
configInvalidateCmd.registerYourself(&cmdServer);
|
configInvalidateCmd.registerYourself(&cmdServer);
|
||||||
|
#endif
|
||||||
uptime.begin(&cmdServer);
|
uptime.begin(&cmdServer);
|
||||||
thermometer.begin(&cmdServer);
|
thermometer.begin(&cmdServer);
|
||||||
meterBusClient.begin(&cmdServer, &thermometer, &uptime);
|
|
||||||
|
|
||||||
digitalWrite(OK_LED_PIN, HIGH);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -43,5 +40,4 @@ void loop() {
|
|||||||
cmdServer.exec();
|
cmdServer.exec();
|
||||||
uptime.exec();
|
uptime.exec();
|
||||||
thermometer.exec();
|
thermometer.exec();
|
||||||
meterBusClient.exec();
|
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
|
#include <avr/interrupt.h>
|
||||||
#include"fatal.h"
|
#include"fatal.h"
|
||||||
|
|
||||||
#include <Arduino.h>
|
|
||||||
|
|
||||||
void fatal(uint8_t code) {
|
void fatal(uint8_t code) {
|
||||||
// cli();
|
// cli();
|
||||||
// do something with the code and somehow show that there is a problem
|
// do something with the code and somehow show that there is a problem
|
||||||
Serial.print("Fatal: "); Serial.println(code);
|
|
||||||
while (1);
|
while (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,393 +0,0 @@
|
|||||||
/*
|
|
||||||
* meterBusClient.cpp
|
|
||||||
*
|
|
||||||
* Created on: 08.03.2014
|
|
||||||
* Author: wn
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "meterBusClient.h"
|
|
||||||
|
|
||||||
|
|
||||||
const bool MBC_COMPILE_TIME_DEBUG = false;
|
|
||||||
|
|
||||||
|
|
||||||
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);
|
|
||||||
Serial.print("Address is now "); Serial.println(a);
|
|
||||||
Serial.print("MBC is at "); Serial.println((long) m_meterBusClient, 16);
|
|
||||||
} else if (params.startsWith("debug ") && (space != -1)) {
|
|
||||||
bool b = (strcmp(pb1, "on") == 0);
|
|
||||||
m_meterBusClient->setDebug(b);
|
|
||||||
} else if (params.startsWith("info ") && (space != -1)) {
|
|
||||||
bool b = (strcmp(pb1, "on") == 0);
|
|
||||||
m_meterBusClient->setInfo(b);
|
|
||||||
} else if (params.startsWith("show")) {
|
|
||||||
Serial.print(getResource(MBC_FRAMES_KEY)); Serial.print(m_meterBusClient->m_frameCnt); Serial.println();
|
|
||||||
Serial.print(getResource(MBC_MYFRAMES_KEY)); Serial.print(m_meterBusClient->m_myFrameCnt); Serial.println();
|
|
||||||
Serial.print(getResource(MBC_INVALID_FRAMES_KEY)); Serial.print(m_meterBusClient->m_invalidFrameCnt); Serial.println();
|
|
||||||
Serial.print(getResource(MBC_INVALID_CHECKSUM_CNT_KEY)); Serial.print(m_meterBusClient->m_invalidChecksum); Serial.println();
|
|
||||||
Serial.print(getResource(MBC_COLLISION_CNT_KEY)); Serial.print(m_meterBusClient->m_collisionCnt); Serial.println();
|
|
||||||
Serial.print(getResource(MBC_ADDRESS_LONG_KEY)); Serial.print(m_meterBusClient->getAddress()); Serial.println();
|
|
||||||
} else {
|
|
||||||
res = "subcommand not found";
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
MeterBusClient::MeterBusClient() : m_meterBusClientConfig(this), m_address(0),
|
|
||||||
m_frameCnt(0), m_accessCnt(0), m_myFrameCnt(0), m_invalidFrameCnt(0), m_invalidChecksum(0),
|
|
||||||
m_collisionCnt(0) {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void MeterBusClient::begin(CmdServer *cmdServer, Thermometer *thermometer, Uptime *uptime) {
|
|
||||||
Serial.print("I'm at "); Serial.println((long)this, 16);
|
|
||||||
|
|
||||||
|
|
||||||
m_meterBusClientConfig.registerYourself(cmdServer);
|
|
||||||
m_thermometer = thermometer;
|
|
||||||
m_uptime = uptime;
|
|
||||||
|
|
||||||
//Serial3.begin(1200);
|
|
||||||
//Serial3.begin(2400, SERIAL_8E1);
|
|
||||||
Serial3.begin(2400);
|
|
||||||
UART2_C1 |= UART_C1_PE | UART_C1_M;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MeterBusClient::setDebug(bool b) {
|
|
||||||
Config::setBool(Config::METERBUSCLIENT_DEBUG, b);
|
|
||||||
m_debug = b;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MeterBusClient::getDebug() {
|
|
||||||
return m_debug;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MeterBusClient::setInfo(bool b) {
|
|
||||||
Config::setBool(Config::METERBUSCLIENT_INFO, b);
|
|
||||||
m_info = b;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MeterBusClient::getInfo() {
|
|
||||||
return m_info;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned char MeterBusClient::getStatus() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned char MeterBusClient::getAccessCnt() {
|
|
||||||
return m_accessCnt;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Single Character: E5h
|
|
||||||
*
|
|
||||||
* Short Frame:
|
|
||||||
* Start 10h
|
|
||||||
* C-Field
|
|
||||||
* A-Field
|
|
||||||
* Check-Sum
|
|
||||||
* Stop 16h
|
|
||||||
*
|
|
||||||
* Control Frame:
|
|
||||||
* Start 68h
|
|
||||||
* Length = 3
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
bool isChecksumValid(MeterBusFrame frame) {
|
|
||||||
unsigned char ctrlsum = frame.aField + frame.cField + frame.ciField;
|
|
||||||
for (int i = 0; i < (frame.length - 3); i++) {
|
|
||||||
ctrlsum += frame.userData[i];
|
|
||||||
}
|
|
||||||
return (ctrlsum == frame.checksum);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool MeterBusClient::handleFrame() {
|
|
||||||
bool res = false;
|
|
||||||
m_frameCnt++;
|
|
||||||
if (! isChecksumValid(m_frame)) {
|
|
||||||
Serial.println(getResource(MBC_INVALID_CHECKSUM_KEY));
|
|
||||||
m_invalidChecksum++;
|
|
||||||
} else if (m_frame.aField != getAddress()) {
|
|
||||||
if (MBC_COMPILE_TIME_DEBUG && getDebug()) { Serial.print(getResource(MBC_NOT_FOR_ME_KEY)); Serial.print((int)m_frame.aField, 16); Serial.println();}
|
|
||||||
} else {
|
|
||||||
m_myFrameCnt++;
|
|
||||||
// handle the frame
|
|
||||||
if (MBC_COMPILE_TIME_DEBUG && getDebug()) { Serial.print(getResource(MBC_START_DELIMITER_KEY)); Serial.println(m_frame.startDelimiter, 16);}
|
|
||||||
if (MBC_COMPILE_TIME_DEBUG && getDebug()) { Serial.print(getResource(MBC_LENGTH_KEY)); Serial.println(m_frame.length, 16);}
|
|
||||||
if (MBC_COMPILE_TIME_DEBUG && getDebug()) { Serial.print(getResource(MBC_CFIELD_KEY)); Serial.println(m_frame.cField, 16);}
|
|
||||||
if (MBC_COMPILE_TIME_DEBUG && getDebug()) { Serial.print(getResource(MBC_ADDRESS_KEY)); Serial.println(m_frame.aField, 16);}
|
|
||||||
if (MBC_COMPILE_TIME_DEBUG && getDebug()) { Serial.print(getResource(MBC_CIFIELD_KEY)); Serial.println(m_frame.ciField, 16);}
|
|
||||||
|
|
||||||
if (m_frame.length > 3) {
|
|
||||||
if (MBC_COMPILE_TIME_DEBUG && getDebug()) { Serial.print(getResource(MBC_USERDATA_KEY));}
|
|
||||||
for (unsigned char i = 0; i < (m_frame.length - 3); i++) {
|
|
||||||
if (MBC_COMPILE_TIME_DEBUG && getDebug()) { Serial.print(m_frame.userData[i], 16);}
|
|
||||||
if (MBC_COMPILE_TIME_DEBUG && getDebug()) { Serial.print(getResource(SPACE_KEY));}
|
|
||||||
}
|
|
||||||
if (MBC_COMPILE_TIME_DEBUG && getDebug()) { Serial.println();}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (m_frame.startDelimiter == 0x10) {
|
|
||||||
if (m_frame.cField == 0x40) {
|
|
||||||
SND_NKE();
|
|
||||||
res = true;
|
|
||||||
} else if (m_frame.cField == 0x5b) {
|
|
||||||
m_accessCnt++;
|
|
||||||
REQ_UD2();
|
|
||||||
res = true;
|
|
||||||
} else {
|
|
||||||
Serial.println(getResource(MBC_UNHANDLED_FRAME_KEY));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
STATE_START, STATE_IDLE, STATE_SHORT_FRAME, STATE_LONG_CTRL_FRAME, STATE_HANDLE, STATE_INVALID, STATE_DONE,
|
|
||||||
STATE_DELAYED_RESPONSE, STATE_DELAY, STATE_RESPONSE, STATE_RECEIVE_ECHO
|
|
||||||
} e_meterBusClientState;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
SUBSTATE_LENGTH, SUBSTATE_LENGTH_REPEAT, SUBSTATE_START_REPEAT, SUBSTATE_C_FIELD, SUBSTATE_A_FIELD, SUBSTATE_CI_FIELD,
|
|
||||||
SUBSTATE_USERDATA, SUBSTATE_CHECKSUM, SUBSTATE_STOP
|
|
||||||
} e_meterBusClientSubState;
|
|
||||||
|
|
||||||
|
|
||||||
void MeterBusClient::exec() {
|
|
||||||
static e_meterBusClientState state = STATE_IDLE;
|
|
||||||
static e_meterBusClientSubState subState = SUBSTATE_LENGTH;
|
|
||||||
static unsigned char userDataCnt = 0;
|
|
||||||
static unsigned int echoReceiveCnt = 0;
|
|
||||||
static unsigned long receivedDoneTimestamp;
|
|
||||||
|
|
||||||
int chi = Serial3.read();
|
|
||||||
//if (chi != -1) {
|
|
||||||
// Serial.print("Received: "); Serial.println(chi, 16);
|
|
||||||
//}
|
|
||||||
char ch = (char) chi;
|
|
||||||
|
|
||||||
switch (state) {
|
|
||||||
case STATE_START:
|
|
||||||
m_frame.startDelimiter = 0;
|
|
||||||
m_frame.length = 0;
|
|
||||||
m_frame.cField = 0;
|
|
||||||
m_frame.aField = 0;
|
|
||||||
m_frame.ciField = 0;
|
|
||||||
//memset(m_frame.userData, 0, sizeof(m_frame.userData));
|
|
||||||
m_frame.valid = false;
|
|
||||||
state = STATE_IDLE;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case STATE_IDLE:
|
|
||||||
if (chi != -1) {
|
|
||||||
if (ch == 0x10) {
|
|
||||||
m_frame.startDelimiter = 0x10;
|
|
||||||
state = STATE_SHORT_FRAME;
|
|
||||||
subState = SUBSTATE_C_FIELD;
|
|
||||||
} else if (ch == 0x68) {
|
|
||||||
m_frame.startDelimiter = 0x68;
|
|
||||||
state = STATE_LONG_CTRL_FRAME;
|
|
||||||
subState = SUBSTATE_LENGTH;
|
|
||||||
} else {
|
|
||||||
state = STATE_INVALID;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case STATE_SHORT_FRAME:
|
|
||||||
if (chi != -1) {
|
|
||||||
if (subState == SUBSTATE_C_FIELD) {
|
|
||||||
m_frame.cField = ch;
|
|
||||||
subState = SUBSTATE_A_FIELD;
|
|
||||||
} else if (subState == SUBSTATE_A_FIELD) {
|
|
||||||
m_frame.aField = ch;
|
|
||||||
subState = SUBSTATE_CHECKSUM;
|
|
||||||
} else if (subState == SUBSTATE_CHECKSUM) {
|
|
||||||
m_frame.checksum = ch;
|
|
||||||
subState = SUBSTATE_STOP;
|
|
||||||
} else if (subState == SUBSTATE_STOP) {
|
|
||||||
if (ch == 0x16) {
|
|
||||||
m_frame.valid = true;
|
|
||||||
state = STATE_HANDLE;
|
|
||||||
} else {
|
|
||||||
state = STATE_INVALID;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case STATE_LONG_CTRL_FRAME:
|
|
||||||
if (chi != -1) {
|
|
||||||
if (subState == SUBSTATE_LENGTH) {
|
|
||||||
m_frame.length = ch;
|
|
||||||
if ((m_frame.length < 3) || (m_frame.length > 252)) {
|
|
||||||
state = STATE_INVALID;
|
|
||||||
} else {
|
|
||||||
subState = SUBSTATE_LENGTH_REPEAT;
|
|
||||||
}
|
|
||||||
} else if (subState == SUBSTATE_LENGTH_REPEAT) {
|
|
||||||
if (ch == m_frame.length) {
|
|
||||||
subState = SUBSTATE_START_REPEAT;
|
|
||||||
} else {
|
|
||||||
state = STATE_INVALID;
|
|
||||||
}
|
|
||||||
} else if (subState == SUBSTATE_START_REPEAT) {
|
|
||||||
if (ch == 0x68) {
|
|
||||||
subState = SUBSTATE_C_FIELD;
|
|
||||||
} else {
|
|
||||||
state = STATE_INVALID;
|
|
||||||
}
|
|
||||||
} else if (subState == SUBSTATE_C_FIELD) {
|
|
||||||
m_frame.cField = ch;
|
|
||||||
subState = SUBSTATE_A_FIELD;
|
|
||||||
} else if (subState == SUBSTATE_A_FIELD) {
|
|
||||||
m_frame.aField = ch;
|
|
||||||
subState = SUBSTATE_CI_FIELD;
|
|
||||||
} else if (subState == SUBSTATE_CI_FIELD) {
|
|
||||||
m_frame.ciField = ch;
|
|
||||||
if (m_frame.length == 3) {
|
|
||||||
subState = SUBSTATE_CHECKSUM;
|
|
||||||
} else {
|
|
||||||
subState = SUBSTATE_USERDATA;
|
|
||||||
userDataCnt = 0;
|
|
||||||
}
|
|
||||||
} else if (subState == SUBSTATE_USERDATA) {
|
|
||||||
m_frame.userData[userDataCnt] = ch;
|
|
||||||
userDataCnt++;
|
|
||||||
if (userDataCnt >= (m_frame.length - 3)) {
|
|
||||||
subState = SUBSTATE_CHECKSUM;
|
|
||||||
}
|
|
||||||
} else if (subState == SUBSTATE_CHECKSUM) {
|
|
||||||
m_frame.checksum = ch;
|
|
||||||
subState = SUBSTATE_STOP;
|
|
||||||
} else if (subState == SUBSTATE_STOP) {
|
|
||||||
if (ch == 0x16) {
|
|
||||||
m_frame.valid = true;
|
|
||||||
state = STATE_HANDLE;
|
|
||||||
} else {
|
|
||||||
state = STATE_INVALID;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case STATE_INVALID:
|
|
||||||
Serial.println("INVALID FRAME");
|
|
||||||
m_invalidFrameCnt++;
|
|
||||||
state = STATE_START;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case STATE_HANDLE:
|
|
||||||
state = STATE_DONE;
|
|
||||||
if (m_frame.valid) {
|
|
||||||
receivedDoneTimestamp = millis();
|
|
||||||
if (handleFrame()) {
|
|
||||||
state = STATE_DELAY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case STATE_DELAY:
|
|
||||||
if ((receivedDoneTimestamp + RESPONSE_DELAY) < millis()) {
|
|
||||||
state = STATE_DELAYED_RESPONSE;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case STATE_DELAYED_RESPONSE:
|
|
||||||
for (unsigned int i = 0; i < m_sendBufferLen; i++) {
|
|
||||||
Serial3.write(m_sendBuffer[i]);
|
|
||||||
}
|
|
||||||
echoReceiveCnt = 0;
|
|
||||||
state = STATE_RECEIVE_ECHO;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case STATE_RECEIVE_ECHO:
|
|
||||||
if (chi != -1) {
|
|
||||||
//Serial.println("echo character");
|
|
||||||
if (ch == m_sendBuffer[echoReceiveCnt]) {
|
|
||||||
echoReceiveCnt++;
|
|
||||||
if (echoReceiveCnt == m_sendBufferLen) {
|
|
||||||
state = STATE_DONE;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
m_collisionCnt++;
|
|
||||||
state = STATE_DONE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case STATE_DONE:
|
|
||||||
// may be another useful message
|
|
||||||
state = STATE_START;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
120
meterBusClient.h
120
meterBusClient.h
@ -1,120 +0,0 @@
|
|||||||
/*
|
|
||||||
* meterBusClient.h
|
|
||||||
*
|
|
||||||
* Created on: 08.03.2014
|
|
||||||
* Author: wn
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef METERBUSCLIENT_H_
|
|
||||||
#define METERBUSCLIENT_H_
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "cmd.h"
|
|
||||||
#include "Config.h"
|
|
||||||
#include "Resources.h"
|
|
||||||
#include "Thermometer.h"
|
|
||||||
#include "uptime.h"
|
|
||||||
|
|
||||||
|
|
||||||
const unsigned long RESPONSE_DELAY = 50;
|
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct MeterBusFrame {
|
|
||||||
/*
|
|
||||||
* Short Frame:
|
|
||||||
* Start 10h
|
|
||||||
* C-Field
|
|
||||||
* A-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
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
unsigned char startDelimiter;
|
|
||||||
unsigned char length;
|
|
||||||
unsigned char cField;
|
|
||||||
unsigned char aField;
|
|
||||||
unsigned char ciField;
|
|
||||||
unsigned char userData[255];
|
|
||||||
unsigned char checksum;
|
|
||||||
bool valid;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class MeterBusClient {
|
|
||||||
public:
|
|
||||||
MeterBusClient();
|
|
||||||
void begin(CmdServer *cmdServer, Thermometer *thermometer, Uptime *uptime);
|
|
||||||
void exec();
|
|
||||||
friend class MeterBusClientConfig;
|
|
||||||
private:
|
|
||||||
MeterBusClientConfig m_meterBusClientConfig;
|
|
||||||
Thermometer *m_thermometer;
|
|
||||||
Uptime *m_uptime;
|
|
||||||
unsigned char m_address;
|
|
||||||
void setAddress(unsigned char address);
|
|
||||||
unsigned char getAddress();
|
|
||||||
bool handleFrame();
|
|
||||||
MeterBusFrame m_frame;
|
|
||||||
|
|
||||||
unsigned char m_sendBuffer[265];
|
|
||||||
unsigned int m_sendBufferLen;
|
|
||||||
void aSB(unsigned char v); // append to send buffer
|
|
||||||
void aSB(unsigned int v);
|
|
||||||
void aSB(unsigned long v);
|
|
||||||
void aSB(float v);
|
|
||||||
unsigned char calcSendChecksum();
|
|
||||||
void calcAndSetFrameLength();
|
|
||||||
|
|
||||||
unsigned long m_frameCnt;
|
|
||||||
unsigned char m_accessCnt;
|
|
||||||
unsigned long m_myFrameCnt;
|
|
||||||
unsigned long m_invalidFrameCnt;
|
|
||||||
unsigned long m_invalidChecksum;
|
|
||||||
unsigned long m_collisionCnt;
|
|
||||||
|
|
||||||
unsigned char getAccessCnt();
|
|
||||||
unsigned char getStatus();
|
|
||||||
|
|
||||||
bool m_debug;
|
|
||||||
bool getDebug();
|
|
||||||
void setDebug(bool b);
|
|
||||||
bool m_info;
|
|
||||||
bool getInfo();
|
|
||||||
void setInfo(bool b);
|
|
||||||
|
|
||||||
void SND_NKE();
|
|
||||||
void REQ_UD2();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* METERBUSCLIENT_H_ */
|
|
@ -1,190 +0,0 @@
|
|||||||
/*
|
|
||||||
* meterBusClientFrames.cpp
|
|
||||||
*
|
|
||||||
* Created on: 09.03.2014
|
|
||||||
* Author: wn
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "meterBusClient.h"
|
|
||||||
|
|
||||||
void MeterBusClient::aSB(unsigned char v) {
|
|
||||||
m_sendBuffer[m_sendBufferLen] = v;
|
|
||||||
m_sendBufferLen++;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MeterBusClient::aSB(unsigned int v) {
|
|
||||||
// 16 bit
|
|
||||||
union {
|
|
||||||
unsigned int i;
|
|
||||||
unsigned char c[2];
|
|
||||||
} u;
|
|
||||||
u.i = v;
|
|
||||||
m_sendBuffer[m_sendBufferLen] = u.c[0];
|
|
||||||
m_sendBufferLen++;
|
|
||||||
m_sendBuffer[m_sendBufferLen] = u.c[1];
|
|
||||||
m_sendBufferLen++;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MeterBusClient::aSB(unsigned long v) {
|
|
||||||
// 32 bit
|
|
||||||
union{
|
|
||||||
unsigned long l;
|
|
||||||
unsigned char c[4];
|
|
||||||
} u;
|
|
||||||
u.l = v;
|
|
||||||
m_sendBuffer[m_sendBufferLen] = u.c[0];
|
|
||||||
m_sendBufferLen++;
|
|
||||||
m_sendBuffer[m_sendBufferLen] = u.c[1];
|
|
||||||
m_sendBufferLen++;
|
|
||||||
m_sendBuffer[m_sendBufferLen] = u.c[2];
|
|
||||||
m_sendBufferLen++;
|
|
||||||
m_sendBuffer[m_sendBufferLen] = u.c[3];
|
|
||||||
m_sendBufferLen++;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MeterBusClient::aSB(float v) {
|
|
||||||
// 32 bit
|
|
||||||
union{
|
|
||||||
float f;
|
|
||||||
unsigned char c[4];
|
|
||||||
} u;
|
|
||||||
u.f = v;
|
|
||||||
m_sendBuffer[m_sendBufferLen] = u.c[0];
|
|
||||||
m_sendBufferLen++;
|
|
||||||
m_sendBuffer[m_sendBufferLen] = u.c[1];
|
|
||||||
m_sendBufferLen++;
|
|
||||||
m_sendBuffer[m_sendBufferLen] = u.c[2];
|
|
||||||
m_sendBufferLen++;
|
|
||||||
m_sendBuffer[m_sendBufferLen] = u.c[3];
|
|
||||||
m_sendBufferLen++;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned char MeterBusClient::calcSendChecksum() {
|
|
||||||
unsigned char checksum = 0;
|
|
||||||
for (unsigned int i = 4; i < m_sendBufferLen; i++) {
|
|
||||||
checksum += m_sendBuffer[i];
|
|
||||||
}
|
|
||||||
return checksum;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MeterBusClient::calcAndSetFrameLength() {
|
|
||||||
unsigned char frameLength = m_sendBufferLen - 6;
|
|
||||||
m_sendBuffer[1] = frameLength;
|
|
||||||
m_sendBuffer[2] = frameLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MeterBusClient::SND_NKE() {
|
|
||||||
m_sendBufferLen = 0;
|
|
||||||
aSB((unsigned char)0xE5);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MeterBusClient::REQ_UD2() {
|
|
||||||
m_sendBufferLen = 0;
|
|
||||||
// frame header
|
|
||||||
aSB((unsigned char)0x68);
|
|
||||||
aSB((unsigned char)0x00);
|
|
||||||
aSB((unsigned char)0x00);
|
|
||||||
aSB((unsigned char)0x68);
|
|
||||||
|
|
||||||
// C
|
|
||||||
aSB((unsigned char)0x08);
|
|
||||||
|
|
||||||
// A
|
|
||||||
aSB(getAddress());
|
|
||||||
|
|
||||||
// CI
|
|
||||||
aSB((unsigned char)0x72);
|
|
||||||
|
|
||||||
// Header
|
|
||||||
aSB((unsigned long)0); // Ident
|
|
||||||
aSB((unsigned int)0); // Manu.
|
|
||||||
aSB((unsigned char)1); // Version
|
|
||||||
aSB((unsigned char)0); // Medium: other
|
|
||||||
aSB(getAccessCnt()); // Access
|
|
||||||
aSB(getStatus()); // Status
|
|
||||||
aSB((unsigned int)0); // Signatur
|
|
||||||
|
|
||||||
// Uptime
|
|
||||||
// DIF
|
|
||||||
aSB((unsigned char)0x01);
|
|
||||||
// VIF
|
|
||||||
aSB((unsigned char)0x24);
|
|
||||||
aSB(m_uptime->getSeconds());
|
|
||||||
|
|
||||||
// DIF
|
|
||||||
aSB((unsigned char)0x01);
|
|
||||||
// VIF
|
|
||||||
aSB((unsigned char)0x25);
|
|
||||||
aSB(m_uptime->getMinutes());
|
|
||||||
|
|
||||||
// DIF
|
|
||||||
aSB((unsigned char)0x01);
|
|
||||||
// VIF
|
|
||||||
aSB((unsigned char)0x26);
|
|
||||||
aSB(m_uptime->getHours());
|
|
||||||
|
|
||||||
// DIF
|
|
||||||
aSB((unsigned char)0x02);
|
|
||||||
// VIF
|
|
||||||
aSB((unsigned char)0x27);
|
|
||||||
aSB((unsigned int)m_uptime->getDays());
|
|
||||||
|
|
||||||
|
|
||||||
// Temperatur 1
|
|
||||||
// DIF
|
|
||||||
aSB((unsigned char)0x05);
|
|
||||||
// VIF
|
|
||||||
aSB((unsigned char)0x67);
|
|
||||||
// value
|
|
||||||
aSB(m_thermometer->getTemperature(0));
|
|
||||||
|
|
||||||
// Temperatur 2
|
|
||||||
// DIF
|
|
||||||
aSB((unsigned char)0x05);
|
|
||||||
// VIF
|
|
||||||
aSB((unsigned char)0x67);
|
|
||||||
// value
|
|
||||||
aSB(m_thermometer->getTemperature(1));
|
|
||||||
|
|
||||||
// Temperatur 3
|
|
||||||
// DIF
|
|
||||||
aSB((unsigned char)0x05);
|
|
||||||
// VIF
|
|
||||||
aSB((unsigned char)0x67);
|
|
||||||
// value
|
|
||||||
aSB(m_thermometer->getTemperature(2));
|
|
||||||
|
|
||||||
// Temperatur 4
|
|
||||||
// DIF
|
|
||||||
aSB((unsigned char)0x05);
|
|
||||||
// VIF
|
|
||||||
aSB((unsigned char)0x67);
|
|
||||||
// value
|
|
||||||
aSB(m_thermometer->getTemperature(3));
|
|
||||||
|
|
||||||
// Structured Manufacturer Data
|
|
||||||
// DIF
|
|
||||||
aSB((unsigned char)0x0f);
|
|
||||||
aSB(m_frameCnt);
|
|
||||||
aSB(m_myFrameCnt);
|
|
||||||
aSB(m_invalidFrameCnt);
|
|
||||||
aSB(m_invalidChecksum);
|
|
||||||
aSB(m_collisionCnt);
|
|
||||||
aSB(m_thermometer->getCalibrateFactor(0));
|
|
||||||
aSB(m_thermometer->getCalibrateFactor(1));
|
|
||||||
aSB(m_thermometer->getCalibrateFactor(2));
|
|
||||||
aSB(m_thermometer->getCalibrateFactor(3));
|
|
||||||
aSB(m_thermometer->getAlpha());
|
|
||||||
aSB(m_thermometer->getPeriodMeasure());
|
|
||||||
|
|
||||||
|
|
||||||
aSB(calcSendChecksum());
|
|
||||||
aSB((unsigned char)0x16);
|
|
||||||
calcAndSetFrameLength();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -63,9 +63,8 @@ String ThermValues::exec(String params) {
|
|||||||
for (unsigned int i = 0; i < NUM_OF_CHANNELS; i++) {
|
for (unsigned int i = 0; i < NUM_OF_CHANNELS; i++) {
|
||||||
m_stream->print(getResource(INDEX_KEY)); m_stream->print(i); m_stream->print(getResource(COMMA_SPACE_KEY));
|
m_stream->print(getResource(INDEX_KEY)); m_stream->print(i); m_stream->print(getResource(COMMA_SPACE_KEY));
|
||||||
m_stream->print(getResource(CAL_KEY)); m_stream->print(m_thermometer->getCalibrateFactor(i), 6); m_stream->print(getResource(COMMA_SPACE_KEY));
|
m_stream->print(getResource(CAL_KEY)); m_stream->print(m_thermometer->getCalibrateFactor(i), 6); m_stream->print(getResource(COMMA_SPACE_KEY));
|
||||||
m_stream->print(getResource(R_KEY)); m_stream->print(m_thermometer->m_r[i], 2); m_stream->print(getResource(COMMA_SPACE_KEY));
|
m_stream->print(getResource(T_KEY)); m_stream->print(m_thermometer->m_temperature[i], 6); m_stream->print(getResource(COMMA_SPACE_KEY));
|
||||||
m_stream->print(getResource(T_KEY)); m_stream->print(m_thermometer->m_temperature[i], 2); m_stream->print(getResource(COMMA_SPACE_KEY));
|
m_stream->print(getResource(TS_KEY)); m_stream->print(m_thermometer->m_smoothedTemperature[i], 6);
|
||||||
m_stream->print(getResource(TS_KEY)); m_stream->print(m_thermometer->m_smoothedTemperature[i], 2);
|
|
||||||
m_stream->println();
|
m_stream->println();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,8 +97,13 @@ String ThermCalibrate::exec(String params) {
|
|||||||
m_stream->println(getResource(CALI_HELP_4_KEY));
|
m_stream->println(getResource(CALI_HELP_4_KEY));
|
||||||
m_stream->println(getResource(CALI_HELP_5_KEY));
|
m_stream->println(getResource(CALI_HELP_5_KEY));
|
||||||
m_stream->println(getResource(CALI_HELP_6_KEY));
|
m_stream->println(getResource(CALI_HELP_6_KEY));
|
||||||
} else if (params.startsWith("start") && m_enabled) {
|
} else if (params.startsWith("start ") && (space != -1) && m_enabled) {
|
||||||
|
m_channel = atoi(pb1);
|
||||||
|
if ((m_channel + 1) > NUM_OF_CHANNELS) {
|
||||||
|
res = "Invalid channel number";
|
||||||
|
} else {
|
||||||
m_start_highCalibration = true;
|
m_start_highCalibration = true;
|
||||||
|
}
|
||||||
} else if (params.startsWith("stop")) {
|
} else if (params.startsWith("stop")) {
|
||||||
m_start_highCalibration = false;
|
m_start_highCalibration = false;
|
||||||
} else if (params.startsWith("r ") && (space != -1)) {
|
} else if (params.startsWith("r ") && (space != -1)) {
|
||||||
@ -177,14 +181,6 @@ float pt1000(float r) {
|
|||||||
return (r / PT1000_R0 - 1) / PT1000_Coeff;
|
return (r / PT1000_R0 - 1) / PT1000_Coeff;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Thermometer::setR(unsigned int index, float r) {
|
|
||||||
m_r[index] = r;
|
|
||||||
if (getDebug() || getInfo()) {
|
|
||||||
Serial.print(getResource(SET_R_KEY)); Serial.print(index); Serial.print(getResource(COMMA_SPACE_KEY));
|
|
||||||
Serial.print(getResource(R_EQUALS_KEY)); Serial.print(r, 2); Serial.println();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Thermometer::setTemperature(unsigned int index, float t) {
|
void Thermometer::setTemperature(unsigned int index, float t) {
|
||||||
m_temperature[index] = t;
|
m_temperature[index] = t;
|
||||||
|
|
||||||
@ -202,10 +198,6 @@ void Thermometer::setTemperature(unsigned int index, float t) {
|
|||||||
m_lastSmoothedTemperature[index] = m_smoothedTemperature[index];
|
m_lastSmoothedTemperature[index] = m_smoothedTemperature[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
float Thermometer::getTemperature(unsigned int index) {
|
|
||||||
return m_temperature[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
void Thermometer::prepareAdc() {
|
void Thermometer::prepareAdc() {
|
||||||
unsigned long oldRegValue = AD7190_GetRegisterValue(AD7190_REG_CONF, 3, 1);
|
unsigned long oldRegValue = AD7190_GetRegisterValue(AD7190_REG_CONF, 3, 1);
|
||||||
oldRegValue &= ~(AD7190_CONF_CHAN(0xFF));
|
oldRegValue &= ~(AD7190_CONF_CHAN(0xFF));
|
||||||
@ -260,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_ZERO, AD7190_CH_AIN1P_AINCOM);
|
||||||
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));
|
||||||
@ -270,7 +274,12 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -349,7 +358,7 @@ void Thermometer::exec() {
|
|||||||
SPI_Disable(AD7190_SLAVE_ID);
|
SPI_Disable(AD7190_SLAVE_ID);
|
||||||
|
|
||||||
if (m_calibrationHighMode || thermCalibrate.m_start_highCalibration) {
|
if (m_calibrationHighMode || thermCalibrate.m_start_highCalibration) {
|
||||||
if (getDebug()) { Serial.println(getResource(CALIBRATION_MODE_HINT_KEY)); }
|
Serial.println(getResource(CALIBRATION_MODE_HINT_KEY));
|
||||||
state = 20;
|
state = 20;
|
||||||
} else if (m_calibrationZeroMode || thermCalibrate.m_start_zeroCalibration) {
|
} else if (m_calibrationZeroMode || thermCalibrate.m_start_zeroCalibration) {
|
||||||
Serial.println(getResource(CALIBRATION_ZEOR_MODE_HINT_KEY));
|
Serial.println(getResource(CALIBRATION_ZEOR_MODE_HINT_KEY));
|
||||||
@ -362,7 +371,6 @@ void Thermometer::exec() {
|
|||||||
if (COMPILE_TIME_DEBUG && getDebug()) { Serial.print("calibrateFactor="); Serial.print(getCalibrateFactor(i), 6); Serial.print(getResource(COMMA_SPACE_KEY)); }
|
if (COMPILE_TIME_DEBUG && getDebug()) { Serial.print("calibrateFactor="); Serial.print(getCalibrateFactor(i), 6); Serial.print(getResource(COMMA_SPACE_KEY)); }
|
||||||
float r = (((float)(m_n[i] - ((i == 3) ? 0 : m_n[i + 1]))) / ((float)N_MAX)) * R_REF * getCalibrateFactor(i);
|
float r = (((float)(m_n[i] - ((i == 3) ? 0 : m_n[i + 1]))) / ((float)N_MAX)) * R_REF * getCalibrateFactor(i);
|
||||||
if (COMPILE_TIME_DEBUG && getDebug()) { Serial.print("r="); Serial.print(r); Serial.print(getResource(COMMA_SPACE_KEY)); }
|
if (COMPILE_TIME_DEBUG && getDebug()) { Serial.print("r="); Serial.print(r); Serial.print(getResource(COMMA_SPACE_KEY)); }
|
||||||
setR(i, r);
|
|
||||||
float t = pt1000(r);
|
float t = pt1000(r);
|
||||||
if (COMPILE_TIME_DEBUG && getDebug()) { Serial.print("t="); Serial.print(t); Serial.print(getResource(COMMA_SPACE_KEY)); }
|
if (COMPILE_TIME_DEBUG && getDebug()) { Serial.print("t="); Serial.print(t); Serial.print(getResource(COMMA_SPACE_KEY)); }
|
||||||
if (COMPILE_TIME_DEBUG && getDebug()) { Serial.println(); }
|
if (COMPILE_TIME_DEBUG && getDebug()) { Serial.println(); }
|
||||||
@ -390,29 +398,25 @@ void Thermometer::exec() {
|
|||||||
if (thermCalibrate.m_start_highCalibration) {
|
if (thermCalibrate.m_start_highCalibration) {
|
||||||
if (m_calibrationHighMode) {
|
if (m_calibrationHighMode) {
|
||||||
// do the calibration stuff
|
// do the calibration stuff
|
||||||
(thermCalibrate.m_turn)++;
|
|
||||||
for (unsigned int i = 0; i < NUM_OF_CHANNELS; i++) {
|
for (unsigned int i = 0; i < NUM_OF_CHANNELS; i++) {
|
||||||
float r = (((float)(m_n[i] - ((i == 3) ? 0 : m_n[i + 1]))) / ((float)N_MAX)) * R_REF;
|
float r = (((float)(m_n[i] - ((i == 3) ? 0 : m_n[i + 1]))) / ((float)N_MAX)) * R_REF;
|
||||||
if (COMPILE_TIME_DEBUG && getDebug()) { Serial.print("t="); Serial.print(thermCalibrate.m_turn); Serial.print(", c="); Serial.print(i); }
|
Serial.print("t="); Serial.print(thermCalibrate.m_turn); Serial.print(", c="); Serial.print(i);
|
||||||
if (COMPILE_TIME_DEBUG && getDebug()) { Serial.print(", r="); Serial.print(r, 6); Serial.print(", n="); Serial.print(m_n[i]); }
|
Serial.print(", r="); Serial.print(r, 6); Serial.print(", n="); Serial.print(m_n[i]);
|
||||||
thermCalibrate.m_r_sum[i] += r;
|
if (i == thermCalibrate.m_channel) {
|
||||||
float r_avg = thermCalibrate.m_r_sum[i] / thermCalibrate.m_turn;
|
thermCalibrate.m_r_sum += r;
|
||||||
if (getDebug() || getInfo()) { Serial.print(thermCalibrate.m_turn); Serial.print(getResource(COMMA_SPACE_KEY)); Serial.print(getResource(STATE_20_MSG_1_KEY)); Serial.print(i); Serial.print(getResource(COLON_SPACE_KEY)); Serial.print(r_avg, 6); }
|
}
|
||||||
|
}
|
||||||
|
(thermCalibrate.m_turn)++;
|
||||||
|
float r_avg = thermCalibrate.m_r_sum / thermCalibrate.m_turn;
|
||||||
|
Serial.print(getResource(STATE_20_MSG_1_KEY)); Serial.print(thermCalibrate.m_channel); Serial.print(getResource(COLON_SPACE_KEY)); Serial.print(r_avg, 6);
|
||||||
float calFact = thermCalibrate.m_r_cal / r_avg;
|
float calFact = thermCalibrate.m_r_cal / r_avg;
|
||||||
if (getDebug() || getInfo()) { Serial.print(getResource(COMMA_SPACE_KEY)); Serial.print(getResource(STATE_20_MSG_2_KEY)); Serial.print(calFact, 6); Serial.println(); }
|
Serial.print(getResource(STATE_20_MSG_2_KEY)); Serial.print(calFact, 6); Serial.println();
|
||||||
}
|
|
||||||
|
|
||||||
if ((thermCalibrate.m_turn) >= NUM_OF_CALIBRATION_CYCLES) {
|
|
||||||
thermCalibrate.m_start_highCalibration = false;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
thermCalibrate.m_preserved_alpha = m_alpha;
|
thermCalibrate.m_preserved_alpha = m_alpha;
|
||||||
m_alpha = 1;
|
m_alpha = 1;
|
||||||
thermCalibrate.m_preserved_period = m_periodMillis;
|
thermCalibrate.m_preserved_period = m_periodMillis;
|
||||||
m_periodMillis = CALIBRATION_CYCLE_TIME;
|
m_periodMillis = 500;
|
||||||
for (unsigned int i = 0; i < NUM_OF_CHANNELS; i++) {
|
thermCalibrate.m_r_sum = 0.0;
|
||||||
thermCalibrate.m_r_sum[i] = 0.0;
|
|
||||||
}
|
|
||||||
thermCalibrate.m_turn = 0;
|
thermCalibrate.m_turn = 0;
|
||||||
m_calibrationHighMode = true;
|
m_calibrationHighMode = true;
|
||||||
}
|
}
|
||||||
@ -421,15 +425,12 @@ void Thermometer::exec() {
|
|||||||
m_calibrationHighMode = false;
|
m_calibrationHighMode = false;
|
||||||
m_alpha = thermCalibrate.m_preserved_alpha;
|
m_alpha = thermCalibrate.m_preserved_alpha;
|
||||||
m_periodMillis = thermCalibrate.m_preserved_period;
|
m_periodMillis = thermCalibrate.m_preserved_period;
|
||||||
for (unsigned int i = 0; i < NUM_OF_CHANNELS; i++) {
|
|
||||||
Serial.println(getResource(STATE_20_MSG_3_KEY));
|
Serial.println(getResource(STATE_20_MSG_3_KEY));
|
||||||
float r_avg = thermCalibrate.m_r_sum[i] / thermCalibrate.m_turn;
|
float r_avg = thermCalibrate.m_r_sum / thermCalibrate.m_turn;
|
||||||
float calFact = thermCalibrate.m_r_cal / r_avg;
|
float calFact = thermCalibrate.m_r_cal / r_avg;
|
||||||
|
Serial.print(getResource(STATE_20_MSG_4_KEY)); Serial.print(thermCalibrate.m_channel);
|
||||||
Serial.print(getResource(STATE_20_MSG_4_KEY)); Serial.print(i);
|
|
||||||
Serial.print(getResource(COLON_SPACE_KEY)); Serial.print(calFact, 6); Serial.println();
|
Serial.print(getResource(COLON_SPACE_KEY)); Serial.print(calFact, 6); Serial.println();
|
||||||
setCalibrateFactor(i, calFact);
|
setCalibrateFactor(thermCalibrate.m_channel, calFact);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
state = 11;
|
state = 11;
|
||||||
|
@ -21,8 +21,6 @@ const float R_REF = 6200.0;
|
|||||||
const float PT1000_R0 = 1000.0;
|
const float PT1000_R0 = 1000.0;
|
||||||
const float PT1000_Coeff = 3.85e-3;
|
const float PT1000_Coeff = 3.85e-3;
|
||||||
const unsigned long CONV_TIMEOUT = 0xfffff;
|
const unsigned long CONV_TIMEOUT = 0xfffff;
|
||||||
const unsigned long NUM_OF_CALIBRATION_CYCLES = 250;
|
|
||||||
const unsigned long CALIBRATION_CYCLE_TIME = 10; // ms
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -63,8 +61,9 @@ private:
|
|||||||
float m_r_cal;
|
float m_r_cal;
|
||||||
float m_preserved_alpha;
|
float m_preserved_alpha;
|
||||||
unsigned long m_preserved_period;
|
unsigned long m_preserved_period;
|
||||||
|
unsigned int m_channel;
|
||||||
unsigned int m_turn;
|
unsigned int m_turn;
|
||||||
float m_r_sum[NUM_OF_CHANNELS];
|
float m_r_sum;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Thermometer {
|
class Thermometer {
|
||||||
@ -74,10 +73,6 @@ public:
|
|||||||
void exec();
|
void exec();
|
||||||
friend class ThermConfig;
|
friend class ThermConfig;
|
||||||
friend class ThermValues;
|
friend class ThermValues;
|
||||||
float getTemperature(unsigned int index);
|
|
||||||
float getCalibrateFactor(unsigned int i);
|
|
||||||
unsigned long getPeriodMeasure();
|
|
||||||
float getAlpha();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned long m_periodMillis;
|
unsigned long m_periodMillis;
|
||||||
@ -90,7 +85,6 @@ private:
|
|||||||
|
|
||||||
unsigned long m_n[NUM_OF_CHANNELS];
|
unsigned long m_n[NUM_OF_CHANNELS];
|
||||||
float m_calibrateFactor[NUM_OF_CHANNELS];
|
float m_calibrateFactor[NUM_OF_CHANNELS];
|
||||||
float m_r[NUM_OF_CHANNELS];
|
|
||||||
float m_temperature[NUM_OF_CHANNELS];
|
float m_temperature[NUM_OF_CHANNELS];
|
||||||
float m_lastSmoothedTemperature[NUM_OF_CHANNELS];
|
float m_lastSmoothedTemperature[NUM_OF_CHANNELS];
|
||||||
float m_smoothedTemperature[NUM_OF_CHANNELS];
|
float m_smoothedTemperature[NUM_OF_CHANNELS];
|
||||||
@ -106,10 +100,12 @@ private:
|
|||||||
void prepareAdc();
|
void prepareAdc();
|
||||||
|
|
||||||
void setTemperature(unsigned int index, float t);
|
void setTemperature(unsigned int index, float t);
|
||||||
void setR(unsigned int index, float r);
|
|
||||||
void setPeriodMeasure(unsigned long p);
|
void setPeriodMeasure(unsigned long p);
|
||||||
|
unsigned long getPeriodMeasure();
|
||||||
void setAlpha(float a);
|
void setAlpha(float a);
|
||||||
|
float getAlpha();
|
||||||
void setCalibrateFactor(unsigned int i, float c);
|
void setCalibrateFactor(unsigned int i, float c);
|
||||||
|
float getCalibrateFactor(unsigned int i);
|
||||||
void setDebug(bool b);
|
void setDebug(bool b);
|
||||||
bool getDebug();
|
bool getDebug();
|
||||||
void setInfo(bool b);
|
void setInfo(bool b);
|
||||||
|
2
uptime.h
2
uptime.h
@ -26,7 +26,7 @@ public:
|
|||||||
uint8_t getSeconds() { return m_seconds; };
|
uint8_t getSeconds() { return m_seconds; };
|
||||||
uint8_t getMinutes() { return m_minutes; };
|
uint8_t getMinutes() { return m_minutes; };
|
||||||
uint8_t getHours() { return m_hours; };
|
uint8_t getHours() { return m_hours; };
|
||||||
uint16_t getDays() { return m_days; };
|
uint8_t getDays() { return m_days; };
|
||||||
private:
|
private:
|
||||||
UptimeCmd m_uptimeCmd;
|
UptimeCmd m_uptimeCmd;
|
||||||
uint8_t m_seconds;
|
uint8_t m_seconds;
|
||||||
|
Reference in New Issue
Block a user