ThermometerPro/meterBusClient.h

121 lines
2.3 KiB
C
Raw Normal View History

2014-03-08 13:23:09 +01:00
/*
* meterBusClient.h
*
* Created on: 08.03.2014
* Author: wn
*/
#ifndef METERBUSCLIENT_H_
#define METERBUSCLIENT_H_
2014-03-08 19:24:27 +01:00
2014-03-08 13:23:09 +01:00
#include "cmd.h"
#include "Config.h"
#include "Resources.h"
#include "Thermometer.h"
2014-05-04 20:56:03 +02:00
#include "uptime.h"
2014-03-08 13:23:09 +01:00
2014-03-09 21:12:17 +01:00
const unsigned long RESPONSE_DELAY = 50;
2014-03-08 13:23:09 +01:00
class MeterBusClient;
class MeterBusClientConfig : public Cmd {
public:
2014-04-04 20:38:11 +02:00
MeterBusClientConfig(MeterBusClient *meterBusClient) : m_meterBusClient(meterBusClient) { };
2014-03-08 13:23:09 +01:00
virtual String getCmdName() { return "MBCC"; }
virtual String getHelp() { return getResource(MBC_CONFIG_HELP_KEY); }
virtual String exec(String params);
private:
MeterBusClient *m_meterBusClient;
};
2014-03-08 19:24:27 +01:00
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;
};
2014-03-08 13:23:09 +01:00
class MeterBusClient {
public:
MeterBusClient();
2014-05-04 20:56:03 +02:00
void begin(CmdServer *cmdServer, Thermometer *thermometer, Uptime *uptime);
2014-03-08 13:23:09 +01:00
void exec();
friend class MeterBusClientConfig;
private:
2014-03-08 20:57:17 +01:00
MeterBusClientConfig m_meterBusClientConfig;
Thermometer *m_thermometer;
2014-05-04 20:56:03 +02:00
Uptime *m_uptime;
2014-03-08 13:23:09 +01:00
unsigned char m_address;
void setAddress(unsigned char address);
unsigned char getAddress();
2014-04-02 22:50:17 +02:00
bool handleFrame();
2014-03-08 19:24:27 +01:00
MeterBusFrame m_frame;
2014-05-04 20:56:03 +02:00
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);
2014-04-02 22:50:17 +02:00
unsigned char calcSendChecksum();
2014-05-04 20:56:03 +02:00
void calcAndSetFrameLength();
2014-04-02 22:50:17 +02:00
unsigned long m_frameCnt;
2014-05-04 20:56:03 +02:00
unsigned char m_accessCnt;
unsigned long m_myFrameCnt;
unsigned long m_invalidFrameCnt;
unsigned long m_invalidChecksum;
2014-04-02 22:50:17 +02:00
unsigned long m_collisionCnt;
2014-05-04 20:56:03 +02:00
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();
2014-03-08 13:23:09 +01:00
};
2014-03-08 19:24:27 +01:00
2014-03-08 13:23:09 +01:00
#endif /* METERBUSCLIENT_H_ */