changes
This commit is contained in:
parent
45bdbe0a57
commit
ebc835c794
@ -9,7 +9,7 @@
|
||||
#include "Resources.h"
|
||||
|
||||
|
||||
// #define USE_REAL_TEXTS 1
|
||||
#define USE_REAL_TEXTS 1
|
||||
|
||||
|
||||
#ifndef USE_REAL_TEXTS
|
||||
|
@ -33,7 +33,7 @@ void setup() {
|
||||
configInvalidateCmd.registerYourself(&cmdServer);
|
||||
uptime.begin(&cmdServer);
|
||||
thermometer.begin(&cmdServer);
|
||||
meterBusClient.begin(&cmdServer, &thermometer);
|
||||
meterBusClient.begin(&cmdServer, &thermometer, &uptime);
|
||||
|
||||
digitalWrite(OK_LED_PIN, HIGH);
|
||||
}
|
||||
|
@ -52,18 +52,19 @@ String MeterBusClientConfig::exec(String params) {
|
||||
|
||||
|
||||
MeterBusClient::MeterBusClient() : m_meterBusClientConfig(this), m_address(0),
|
||||
m_frameCnt(0), m_myFrameCnt(0), m_invalidFrameCnt(0), m_invalidChecksum(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) {
|
||||
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);
|
||||
@ -103,6 +104,13 @@ bool MeterBusClient::getInfo() {
|
||||
return m_info;
|
||||
}
|
||||
|
||||
unsigned char MeterBusClient::getStatus() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned char MeterBusClient::getAccessCnt() {
|
||||
return m_accessCnt;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@ -189,6 +197,7 @@ bool MeterBusClient::handleFrame() {
|
||||
SND_NKE();
|
||||
res = true;
|
||||
} else if (m_frame.cField == 0x5b) {
|
||||
m_accessCnt++;
|
||||
REQ_UD2();
|
||||
res = true;
|
||||
} else {
|
||||
@ -219,9 +228,9 @@ void MeterBusClient::exec() {
|
||||
static unsigned long receivedDoneTimestamp;
|
||||
|
||||
int chi = Serial3.read();
|
||||
if (chi != -1) {
|
||||
Serial.print("Received: "); Serial.println(chi, 16);
|
||||
}
|
||||
//if (chi != -1) {
|
||||
// Serial.print("Received: "); Serial.println(chi, 16);
|
||||
//}
|
||||
char ch = (char) chi;
|
||||
|
||||
switch (state) {
|
||||
@ -352,8 +361,8 @@ void MeterBusClient::exec() {
|
||||
break;
|
||||
|
||||
case STATE_DELAYED_RESPONSE:
|
||||
for (unsigned int i = 0; i < sendBufferLen; i++) {
|
||||
Serial3.write(sendBuffer[i]);
|
||||
for (unsigned int i = 0; i < m_sendBufferLen; i++) {
|
||||
Serial3.write(m_sendBuffer[i]);
|
||||
}
|
||||
echoReceiveCnt = 0;
|
||||
state = STATE_RECEIVE_ECHO;
|
||||
@ -361,10 +370,10 @@ void MeterBusClient::exec() {
|
||||
|
||||
case STATE_RECEIVE_ECHO:
|
||||
if (chi != -1) {
|
||||
Serial.println("echo character");
|
||||
if (ch == sendBuffer[echoReceiveCnt]) {
|
||||
//Serial.println("echo character");
|
||||
if (ch == m_sendBuffer[echoReceiveCnt]) {
|
||||
echoReceiveCnt++;
|
||||
if (echoReceiveCnt == sendBufferLen) {
|
||||
if (echoReceiveCnt == m_sendBufferLen) {
|
||||
state = STATE_DONE;
|
||||
}
|
||||
} else {
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "Config.h"
|
||||
#include "Resources.h"
|
||||
#include "Thermometer.h"
|
||||
#include "uptime.h"
|
||||
|
||||
|
||||
const unsigned long RESPONSE_DELAY = 50;
|
||||
@ -71,29 +72,38 @@ struct MeterBusFrame {
|
||||
class MeterBusClient {
|
||||
public:
|
||||
MeterBusClient();
|
||||
void begin(CmdServer *cmdServer, Thermometer *thermometer);
|
||||
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 sendBuffer[265];
|
||||
unsigned int sendBufferLen;
|
||||
void aSB(unsigned char c); // append to send buffer
|
||||
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);
|
||||
|
@ -7,34 +7,180 @@
|
||||
|
||||
#include "meterBusClient.h"
|
||||
|
||||
inline void MeterBusClient::aSB(unsigned char c) {
|
||||
sendBuffer[sendBufferLen++] = c;
|
||||
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 < sendBufferLen; i++) {
|
||||
checksum += sendBuffer[i];
|
||||
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() {
|
||||
sendBufferLen = 0;
|
||||
aSB(0xE5);
|
||||
m_sendBufferLen = 0;
|
||||
aSB((unsigned char)0xE5);
|
||||
}
|
||||
|
||||
void MeterBusClient::REQ_UD2() {
|
||||
sendBufferLen = 0;
|
||||
aSB(0x68);
|
||||
aSB(0x03);
|
||||
aSB(0x03);
|
||||
aSB(0x68);
|
||||
aSB(0x01);
|
||||
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());
|
||||
aSB(0x03);
|
||||
|
||||
// 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(0x16);
|
||||
aSB((unsigned char)0x16);
|
||||
calcAndSetFrameLength();
|
||||
}
|
||||
|
||||
|
||||
|
@ -202,6 +202,10 @@ void Thermometer::setTemperature(unsigned int index, float t) {
|
||||
m_lastSmoothedTemperature[index] = m_smoothedTemperature[index];
|
||||
}
|
||||
|
||||
float Thermometer::getTemperature(unsigned int index) {
|
||||
return m_temperature[index];
|
||||
}
|
||||
|
||||
void Thermometer::prepareAdc() {
|
||||
unsigned long oldRegValue = AD7190_GetRegisterValue(AD7190_REG_CONF, 3, 1);
|
||||
oldRegValue &= ~(AD7190_CONF_CHAN(0xFF));
|
||||
|
@ -74,6 +74,10 @@ public:
|
||||
void exec();
|
||||
friend class ThermConfig;
|
||||
friend class ThermValues;
|
||||
float getTemperature(unsigned int index);
|
||||
float getCalibrateFactor(unsigned int i);
|
||||
unsigned long getPeriodMeasure();
|
||||
float getAlpha();
|
||||
|
||||
private:
|
||||
unsigned long m_periodMillis;
|
||||
@ -104,11 +108,8 @@ private:
|
||||
void setTemperature(unsigned int index, float t);
|
||||
void setR(unsigned int index, float r);
|
||||
void setPeriodMeasure(unsigned long p);
|
||||
unsigned long getPeriodMeasure();
|
||||
void setAlpha(float a);
|
||||
float getAlpha();
|
||||
void setCalibrateFactor(unsigned int i, float c);
|
||||
float getCalibrateFactor(unsigned int i);
|
||||
void setDebug(bool b);
|
||||
bool getDebug();
|
||||
void setInfo(bool b);
|
||||
|
2
uptime.h
2
uptime.h
@ -26,7 +26,7 @@ public:
|
||||
uint8_t getSeconds() { return m_seconds; };
|
||||
uint8_t getMinutes() { return m_minutes; };
|
||||
uint8_t getHours() { return m_hours; };
|
||||
uint8_t getDays() { return m_days; };
|
||||
uint16_t getDays() { return m_days; };
|
||||
private:
|
||||
UptimeCmd m_uptimeCmd;
|
||||
uint8_t m_seconds;
|
||||
|
Loading…
x
Reference in New Issue
Block a user