-
Notifications
You must be signed in to change notification settings - Fork 5
/
Aurora.h
332 lines (246 loc) · 8.33 KB
/
Aurora.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#ifndef Aurora_h
#define Aurora_h
#include <Arduino.h>
#define ADD_SOFTWARE_SERIAL
#ifdef ADD_SOFTWARE_SERIAL
#include <SoftwareSerial.h>
#endif
#include <Wire.h>
#include <include/names.h>
#include <include/statesNaming.h>
#include <include/utils.h>
// Define where debug output will be printed.
#define DEBUG_PRINTER Serial
//#define AURORA_CP_DEBUG
// Setup debug printing macros.
#ifdef AURORA_CP_DEBUG
#define DEBUG_PRINT(...) { DEBUG_PRINTER.print(__VA_ARGS__); }
#define DEBUG_PRINTLN(...) { DEBUG_PRINTER.println(__VA_ARGS__); }
#else
#define DEBUG_PRINT(...) {}
#define DEBUG_PRINTLN(...) {}
#endif
//RS485 control
#define SERIAL_COMMUNICATION_CONTROL_PIN 5
#define RS485_TX_PIN_VALUE HIGH
#define RS485_RX_PIN_VALUE LOW
#define MAX_ATTEMP 1
class Aurora {
private:
HardwareSerial* hs;
#ifdef ADD_SOFTWARE_SERIAL
SoftwareSerial* ss;
#endif
bool isSoftwareSerial = true;
struct NeedsStream{
template< typename T >
void begin( T &t, int baud ){
DEBUG_PRINTLN("Begin ");
t.setTimeout(500);
t.begin(baud);
stream = &t;
}
void listen(){
}
Stream *stream;
};
NeedsStream serialDef;
byte inverterAddress = 0;
byte serialCommunicationControlPin;
byte rxPin;
byte txPin;
void clearData(byte *data, byte len);
int crc16(byte *data, int offset, int count);
bool send(byte address, byte param0, byte param1, byte param2, byte param3, byte param4, byte param5, byte param6);
union {
byte asBytes[4];
float asFloat;
} foo;
union {
byte asBytes[4];
unsigned long asUlong;
} ulo;
String _getAlarmState(byte id);
public:
bool sendStatus = false;
bool receiveStatus = false;
byte receiveData[8];
#ifdef ADD_SOFTWARE_SERIAL
Aurora(byte inverterAddress, byte rxPin, byte txPin, byte serialCommunicationControlPin = SERIAL_COMMUNICATION_CONTROL_PIN);
#endif
Aurora(byte inverterAddress, HardwareSerial* serial = &Serial, byte serialCommunicationControlPin = SERIAL_COMMUNICATION_CONTROL_PIN);
#ifdef ADD_SOFTWARE_SERIAL
Aurora(byte inverterAddress, SoftwareSerial* serial, byte serialCommunicationControlPin = SERIAL_COMMUNICATION_CONTROL_PIN);
#endif
void begin();
void setInverterAddress(byte);
byte getInverterAddress();
void clearReceiveData();
typedef struct {
byte transmissionState;
byte globalState;
bool readState;
String getTransmissionState() {
return getTransmissionStateByParams(this->transmissionState);
}
String getGlobalState() {
return getGlobalStateByParams(this->globalState);
}
} OutcomeState;
typedef struct {
byte inverterState;
byte channel1State;
byte channel2State;
byte alarmState;
const String getDcDcChannel1State(){
return getDcDcStateByParams(this->channel1State);
}
const String getDcDcChannel2State(){
return getDcDcStateByParams(this->channel2State);
}
const String getInverterState() {
return getInverterStateByParams(this->inverterState);
}
const String getAlarmState() {
return getAlarmDescription(this->alarmState);
}
OutcomeState state;
} DataState;
DataState readState();
typedef struct {
char par1;
char par2;
char par3;
char par4;
InverterModel getModelName(){
return getModelNameByParams(this->par1);
}
const String getIndoorOutdoorAndType(){
return getIndoorOutdoorAndTypeByParams(this->par1);
}
const String getGridStandard(){
return getGridStandardByParams(this->par2);
}
const String getGridStandardInt(){
return getGridStandardByParams(this->par2);
}
const String getTrafoOrNonTrafo(){
return getTrafoOrNonTrafoByParams(this->par3);
}
const String getWindOrPV(){
return getWindOrPVByParams(this->par4);
}
OutcomeState state;
} DataVersion;
DataVersion readVersion();
typedef struct {
float value;
OutcomeState state;
} DataDSP;
DataDSP readDSP(byte type, byte global = (byte)1);
typedef struct {
unsigned long seconds;
unsigned long epochTime;
String getDateTimeString(){
return getEpochStringByParams(this->epochTime);
}
tm getDateTime(){
return getDateTimeByParams(this->epochTime);
}
OutcomeState state;
} DataTimeDate;
DataTimeDate readTimeDate();
bool writeTimeDate(unsigned long epochTime);
typedef struct {
byte alarm1;
byte alarm2;
byte alarm3;
byte alarm4;
String getAlarm1State() {
return getAlarmDescription(this->alarm1);
}
String getAlarm2State() {
return getAlarmDescription(this->alarm2);
}
String getAlarm3State() {
return getAlarmDescription(this->alarm3);
}
String getAlarm4State() {
return getAlarmDescription(this->alarm4);
}
OutcomeState state;
} DataLastFourAlarms;
DataLastFourAlarms readLastFourAlarms();
typedef struct {
bool burnFuseOnJBox;
bool jBoxOvertemperature;
bool jBoxOvervoltage;
bool unbalancedStringCurrent;
bool jBoxOvercurrent;
bool powerOff;
bool noCommunication;
bool jBoxNotCalibrated;
} JBoxState;
typedef struct {
JBoxState jBoxState;
bool fuseBurnt[21] = {false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false};
bool stringCurrentUnbalanced[11] = {false,false,false,false,false,false,false,false,false,false,false} ;
OutcomeState state;
} DataJunctionBoxState;
DataJunctionBoxState readJunctionBoxState(byte nj);
bool readJunctionBoxVal(byte nj, byte par);
// Inverters
typedef struct {
String PN;
bool readState;
} DataSystemPN;
DataSystemPN readSystemPN();
typedef struct {
String SerialNumber;
bool readState;
} DataSystemSerialNumber;
DataSystemSerialNumber readSystemSerialNumber();
typedef struct {
String Week;
String Year;
OutcomeState state;
} DataManufacturingWeekYear;
DataManufacturingWeekYear readManufacturingWeekYear();
typedef struct {
String release;
OutcomeState state;
} DataFirmwareRelease;
DataFirmwareRelease readFirmwareRelease();
typedef struct {
unsigned long energy;
OutcomeState state;
} DataCumulatedEnergy;
DataCumulatedEnergy readCumulatedEnergy(byte par);
bool writeBaudRateSetting(byte baudcode);
typedef struct {
byte configStatus;
String getConfigStatus() {
return getConfigFlagByParams(this->configStatus);
}
OutcomeState state;
} DataConfigStatus;
DataConfigStatus readConfig();
typedef struct {
unsigned long upTimeInSec;
int * getSecondsInDateElements() {
return getSecondsInDateElementsByParams(this->upTimeInSec);
}
OutcomeState state;
} DataTimeCounter;
DataTimeCounter readTimeCounter(byte param);
// Central
bool readFlagsSwitchCentral();
bool readCumulatedEnergyCentral(byte var, byte ndays_h, byte ndays_l, byte global);
bool readFirmwareReleaseCentral(byte var);
bool readBaudRateSettingCentral(byte baudcode, byte serialline);
bool readSystemInfoCentral(byte var);
bool readJunctionBoxMonitoringCentral(byte cf, byte rn, byte njt, byte jal, byte jah);
bool readSystemPNCentral();
bool readSystemSerialNumberCentral();
};
#endif