-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathespdm_obis.h
182 lines (153 loc) · 2.54 KB
/
espdm_obis.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
* Data types as per specification
*/
enum DataType
{
NullData = 0x00,
Boolean = 0x03,
BitString = 0x04,
DoubleLong = 0x05,
DoubleLongUnsigned = 0x06,
OctetString = 0x09,
VisibleString = 0x0A,
Utf8String = 0x0C,
BinaryCodedDecimal = 0x0D,
Integer = 0x0F,
Long = 0x10,
Unsigned = 0x11,
LongUnsigned = 0x12,
Long64 = 0x14,
Long64Unsigned = 0x15,
Enum = 0x16,
Float32 = 0x17,
Float64 = 0x18,
DateTime = 0x19,
Date = 0x1A,
Time = 0x1B,
Array = 0x01,
Structure = 0x02,
CompactArray = 0x13
};
enum Medium
{
Abstract = 0x00,
Electricity = 0x01,
Heat = 0x06,
Gas = 0x07,
Water = 0x08
};
enum CodeType
{
Unknown,
Timestamp,
SerialNumber,
DeviceName,
VoltageL1,
VoltageL2,
VoltageL3,
CurrentL1,
CurrentL2,
CurrentL3,
ActivePowerPlus,
ActivePowerMinus,
ActiveEnergyPlus,
ActiveEnergyMinus,
ReactiveEnergyPlus,
ReactiveEnergyMinus
};
enum Accuracy
{
SingleDigit = 0xFF,
DoubleDigit = 0xFE
};
/*
* Data structure
*/
static const int DECODER_START_OFFSET = 20; // Offset for start of OBIS decoding, skip header, timestamp and break block
static const int OBIS_TYPE_OFFSET = 0;
static const int OBIS_LENGTH_OFFSET = 1;
static const int OBIS_CODE_OFFSET = 2;
static const int OBIS_A = 0;
static const int OBIS_B = 1;
static const int OBIS_C = 2;
static const int OBIS_D = 3;
static const int OBIS_E = 4;
static const int OBIS_F = 5;
/*
* Metadata
*/
static uint8_t ESPDM_TIMESTAMP[]
{
0x01, 0x00
};
static const uint8_t ESPDM_SERIAL_NUMBER[]
{
0x60, 0x01
};
static const uint8_t ESPDM_DEVICE_NAME[]
{
0x2A, 0x00
};
/*
* Voltage
*/
static uint8_t ESPDM_VOLTAGE_L1[]
{
0x20, 0x07
};
static const uint8_t ESPDM_VOLTAGE_L2[]
{
0x34, 0x07
};
static const uint8_t ESPDM_VOLTAGE_L3[]
{
0x48, 0x07
};
/*
* Current
*/
static const uint8_t ESPDM_CURRENT_L1[]
{
0x1F, 0x07
};
static const uint8_t ESPDM_CURRENT_L2[]
{
0x33, 0x07
};
static const uint8_t ESPDM_CURRENT_L3[]
{
0x47, 0x07
};
/*
* Power
*/
static const uint8_t ESPDM_ACTIVE_POWER_PLUS[]
{
0x01, 0x07
};
static const uint8_t ESPDM_ACTIVE_POWER_MINUS[]
{
0x02, 0x07
};
/*
* Active energy
*/
static const uint8_t ESPDM_ACTIVE_ENERGY_PLUS[]
{
0x01, 0x08
};
static const uint8_t ESPDM_ACTIVE_ENERGY_MINUS[]
{
0x02, 0x08
};
/*
* Reactive energy
*/
static const uint8_t ESPDM_REACTIVE_ENERGY_PLUS[]
{
0x03, 0x08
};
static const uint8_t ESPDM_REACTIVE_ENERGY_MINUS[]
{
0x04, 0x08
};