121 lines
2.3 KiB
C++
121 lines
2.3 KiB
C++
/*
|
|
* 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_ */
|