forked from alekslt/HANToMQTT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDlmsReader.h
61 lines (48 loc) · 1.4 KB
/
DlmsReader.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef _DLMSREADER_h
#define _DLMSREADER_h
#include "Crc16.h"
#if defined(ARDUINO) && ARDUINO >= 100
#include "arduino.h"
#else
#include "WProgram.h"
#endif
typedef void(*LOG_FN)(const char* fmt, ...);
typedef void(*SENDBUFFER_FN)(byte* buf, int len);
typedef unsigned long(*GETEPOCHTIME_FN)(void);
#define DLMS_READER_BUFFER_SIZE 512
#define DLMS_READER_MAX_ADDRESS_SIZE 5
enum HDLCState { kHDLCState_Waiting, kHDLCState_Data, kHDLCState_Escaped };
class DlmsReader
{
public:
uint8_t debugLevel;
Stream *debug;
GETEPOCHTIME_FN getEpochTime;
LOG_FN netLog;
SENDBUFFER_FN sendBuffer;
unsigned long messageTimestamp;
DlmsReader();
bool Read(byte data);
bool ReadOld(byte data);
bool GetUserDataBuffer(byte *&dataBuffer, int& length);
//int GetRawData(byte *buffer, int start, int length);
protected:
Crc16Class Crc16;
private:
byte buffer[DLMS_READER_BUFFER_SIZE];
int position;
int dataLength;
HDLCState state;
byte frameFormatType;
byte destinationAddress[DLMS_READER_MAX_ADDRESS_SIZE];
byte destinationAddressLength;
byte sourceAddress[DLMS_READER_MAX_ADDRESS_SIZE];
byte sourceAddressLength;
void Clear();
int GetAddress(int addressPosition, byte* buffer, int start, int length);
unsigned short GetChecksum(int checksumPosition);
bool IsValidFrameFormat(byte frameFormatType);
void WriteBuffer();
void debugPrint(byte *buffer, int start, int length);
};
#endif