source: ctrl/firmware/Main/SES/Core/Inc/sysdata.h

Last change on this file was 82, checked in by Zed, 3 months ago

DMA transfer to µSD-card was implemented.

File size: 16.2 KB
Line 
1#ifndef __SYS_DATA_H
2#define __SYS_DATA_H
3
4#include <stdint.h>
5#include <stdbool.h>
6
7#include "charge_controller.h"
8#include "street_light.h"
9#include "common.h"
10#include "gps.h"
11
12#define CONCAT(a, b) CONCAT_INNER(a, b)                                                                                 // These three macros
13#define CONCAT_INNER(a, b) a ## b                                                                                               // generate unique variables
14#define UNIQUE_NAME(base) CONCAT(base, __COUNTER__)                                                             // according to template "baseX", like "base1", "base2" and etc.
15
16//---------- Constants ---------------------------------------------------------
17
18#define MAX_LIPRO_CELLS                           (16U)                                                                         // FÜR SPEICHERUNG AUF SD KARTE, damit Anzahl der Felder immer gleich ist und Reservierung Speicher für Lipro Daten, Achtung eine Änderung verschiebt MODBUS Adressen!!!
19#define MAX_LOG_MESSAGES                          (10U)
20#define MAX_TEMP_SENSOR_ID_SIZE           (8U)
21
22//---------- Enums -------------------------------------------------------------
23
24typedef enum soc_displaymode_enum
25{
26        SOC_DISPLAYMODE_VOLTAGE_BASED,                  //0
27        SOC_DISPLAYMODE_AH_COUNTER_BASED                //!
28
29} soc_displaymode_t;
30
31typedef enum ext_input_mode
32{
33        EXT_INPUT_MODE_DISABLED,
34        EXT_INPUT_CELL_OVP,
35        EXT_INPUT_CELL_UVP,
36        EXT_INPUT_CURRENT_LIM,
37        EXT_INPUT_MOTION_DETECTOR,
38        EXT_INPUT_ALARM,
39        EXT_INPUT_CURRENT_OUT_SENSOR_100A,
40        EXT_INPUT_CURRENT_OUT_SENSOR_200A,
41        EXT_INPUT_CURRENT_OUT_SENSOR_400A,
42        EXT_INPUT_CURRENT_IN_SENSOR_100A,
43        EXT_INPUT_CURRENT_IN_SENSOR_200A,
44        EXT_INPUT_CURRENT_IN_SENSOR_400A,
45        EXT_INPUT_ISOMETER_ALARM,
46        EXT_INPUT_ISOMETER_SHUTOFF
47} ext_input_mode_t;
48
49/*typedef enum mb_error_codes_enum
50{
51        MB_ERROR_NOTHING = 0,                   // 0
52        MB_ERROR_TIMEOUT,                               // 1
53        MB_ERROR_CRC,                                   // 2
54        MB_ERROR_SLAVE_ADRESS,                  // 3
55        MB_ERROR_FUNCTION_CODE,                 // 4
56        MB_ERROR_BYTE_COUNT,                    // 5
57        MB_ERROR_START_ADRESS,                  // 6
58} mb_error_codes_t;*/
59
60typedef enum output_state_enum
61{
62        OUTPUT_USER_OFF,
63        OUTPUT_USER_ON,
64        OUTPUT_REMOTE_ON,
65        OUTPUT_REMOTE_OFF,
66        OUTPUT_SL_ON,
67        OUTPUT_SL_OFF,
68        OUTPUT_DEEP_DISCHARGE_PROTECTION,
69        OUTPUT_CELL_DEEP_DISCHARGE_PROTECTION,
70        OUTPUT_OVER_CURRENT_PROTECTION,
71        OUTPUT_ISOMETER_SHUTOFF
72} output_state_t;
73
74//---------- Typedefs ----------------------------------------------------------
75
76typedef struct ext_output_config
77{
78        uint8_t   ext_output_mode;                      // 1
79        int8_t    inverted;                                     // 1
80        int16_t   v_high;                                       // 2
81        int16_t   v_low;                                        // 3
82        uint16_t  hold_time;                            // 4
83} ext_output_config_t;
84//8Byte, 4 Register
85
86typedef struct ext_input_config
87{
88        ext_input_mode_t  ext_input_mode;       // 1
89        bool                      inverted;                     // 1
90        uint8_t                   i_lim_min;            // 2
91        uint8_t                   reserved;                     // 2
92        uint16_t                  v_high;                       // 3
93        uint16_t                  v_low;                        // 4
94} ext_input_config_t;
95  //12Bytes , 6Register
96
97typedef struct
98{
99        uint8_t on_time;                                        // 1
100        uint8_t off_time;                                       // 1
101} ext_output_aux_config_t;
102  //2Byte, 1 Register
103
104typedef struct
105{
106        bword_t   device_id;
107        bword_t   sn;
108        bword_t   cell_voltage;
109        bword_t   cell_temp;
110        uint8_t   pwm;
111        uint8_t   mode;
112        bool      lvp_protection;
113        bool      ovp_protection;
114        bool      temp_protection;
115        bool      dummy;
116} lipro_data_t;
117  // gesamt 14 Bytes --7Register
118
119
120//! Struktur zur Aufnahme der RTC Zeit/Datum
121//! signed damit atoi korrekt funktioniert
122typedef struct
123{
124        int8_t year;
125        int8_t month;
126        int8_t day;
127        int8_t hour;
128        int8_t minute;
129        int8_t second;
130} time_t;
131
132typedef struct
133{
134        time_t    log_time;
135        uint16_t  message;
136} log_t;
137
138
139
140typedef struct
141{
142        //STATISCHE GERÄTE INFORMATIONEN
143        uint8_t                                 device_type[2];                                 //0
144        uint8_t                                 fw_revision[2];                                 //1
145        uint8_t                                 id[12];                                                 //2-7
146        uint8_t                                 UNIQUE_NAME(reserved)[2];               //8
147        uint16_t                                cell_absorption_exit_current;   //9
148
149        //BASIS DATEN AUSGEWÄHLTE ZELLE GELADEN AUS TABELLE
150        batt_type_t                             cell_type;                                              //10l           LiFEPO4, LIFEYPO4, PB
151        uint8_t                                 cell_current_limit;                             //10h           in c/x
152        uint8_t                                 cell_equalize_interval;                 //11l           in Tagen
153        uint8_t                                 cell_reserved0;                                 //11h
154        uint16_t                                cell_absorption_time;                   //12
155        uint16_t                                cell_float_exit_time;                   //13
156        uint16_t                                cell_equalize_time;                             //14
157        float                                   cell_absorption_voltage;                //15,16
158        float                                   cell_absorption_exit_voltage;   //17,18
159        float                                   cell_float_voltage;                             //19,20
160        float                                   cell_float_exit_voltage;                //21,22
161        float                                   cell_equalize_voltage;                  //23,24
162        float                                   cell_cut_off_voltage;                   //25,26
163        float                                   cell_cut_off_recovery_voltage;  //27,28
164        float                                   cell_temp_coefficient;                  //29,30
165        uint8_t                                 cell_peukert_exponent;                  //31l
166        uint8_t                                 cell_cef;                                               //31h
167        uint8_t                                 cell_lvp_ccf;                                   //32l
168
169        //BATT PARAMETER EINGESTELLT IM BATT BASIS MENÜ
170        soc_displaymode_t               batt_soc_displaymode;                   //32h
171        uint8_t                                 batt_cell_type_number;                  //33l           ausgewählter Batterie Typ Nr
172        uint8_t                                 batt_cells;                                             //33h           Batterie Zellen
173        uint16_t                                batt_capacity;                                  //34            in A/h
174        uint8_t                                 batt_cut_off_delay;                             //35l
175
176        //Equalize
177        bool                                    start_equalize;                                 //35h
178        uint8_t                                 equalize_reserved1[2];                  //36
179
180        //MPP Parameter
181        uint8_t                                 mpp_mode;                                               //37l
182        uint8_t                                 mpp_voltage;                                    //37h
183
184        //LOKALBUS PARAMETER
185        uint8_t                                 lb_slave_address;                               //38l
186        uint8_t                                 lb_mode;                                                //38h
187        uint8_t                                 lb_baudrate_mode;                               //39l
188        uint8_t                                 lb_parity_mode;                                 //39h
189        uint8_t                                 lb_stopbit_mode;                                //40l
190        int8_t                                  lb_number_of_gc;                                //40h
191        uint8_t                                 lb_bms_current;                                 //41l
192        uint8_t                                 lb_data_forwarding;                             //41h
193        uint8_t                                 lb_reserved[2];                                 //42
194
195        //STREETLIGHT PARAMETER
196        bool                                    sl_midnight_detection;                  //43l
197        uint8_t                                 sl_led_power_full;                              //43h
198        uint8_t                                 sl_led_power_red;                               //44l
199        uint8_t                                 sl_volt_on;                                             //44h
200        uint8_t                                 sl_volt_off;                                    //45l
201        uint8_t                                 sl_time_red_start_hours;                //45h
202        uint8_t                                 sl_time_red_stop_hours;                 //46l
203        uint8_t                                 sl_time_red_start_minutes;              //46h
204        uint8_t                                 sl_time_red_stop_minutes;               //47l
205        uint8_t                                 sl_dim_speed;                                   //47h
206        uint16_t                                sl_led_time_motion;                             //48
207        sl_mode_t                               sl_mode;                                                //49l
208        uint8_t                                 sl_reserved1[3];                                //49h,50
209
210        //GSM PARAMETER
211#ifdef GREEN_CONTROLLER_140_30
212        bool                                    gsm_module_enabled;                             //51l RAM Variable GPS/GSM Modul enabled/disabled
213        bool                                    gsm_reserved;                                   //51h
214        uint16_t                                gsm_heartbeat_intervall_time;   //52
215        uint8_t                                 gsm_reserved1[14];                              //53-59
216        char                                    apn_name[MAX_STRING_SIZE];              //60-84                 RAM Variable APN NAME
217        char                                    apn_user[MAX_STRING_SIZE];              //85-109                RAM Variable APN Benutzer Name
218        char                                    apn_pw[MAX_STRING_SIZE];                //110-134               RAM Variable APN Passwort
219        char                                    server_name[MAX_STRING_SIZE];   //135-159               RAM Variable Server Name als DNS Name
220        char                                    server_port[MAX_STRING_SIZE];   //160-184               RAM Variable Server Port
221#elif defined GREEN_CONTROLLER_75_40
222        bool                                    res_gsm_module_enabled;                         //51l RAM Variable GPS/GSM Modul enabled/disabled                       //GSM/GPS Modul entfällt
223        bool                                    res_gsm_reserved;                                       //51h                                                                                                           //GSM/GPS Modul entfällt
224        uint16_t                                res_gsm_heartbeat_intervall_time;       //52                                                                                                            //GSM/GPS Modul entfällt
225        uint8_t                                 res_gsm_reserved1[14];                          //53-59                                                                                                         //GSM/GPS Modul entfällt
226        char                                    res_apn_name[MAX_STRING_SIZE];          //60-84                 RAM Variable APN NAME                                           //GSM/GPS Modul entfällt
227        char                                    res_apn_user[MAX_STRING_SIZE];          //85-109                RAM Variable APN Benutzer Name                          //GSM/GPS Modul entfällt
228        char                                    res_apn_pw[MAX_STRING_SIZE];            //110-134               RAM Variable APN Passwort                                       //GSM/GPS Modul entfällt
229        char                                    res_server_name[MAX_STRING_SIZE];       //135-159               RAM Variable Server Name als DNS Name           //GSM/GPS Modul entfällt
230        char                                    res_server_port[MAX_STRING_SIZE];       //160-184               RAM Variable Server Port                                        //GSM/GPS Modul entfällt
231#endif
232        //INPUT UND OUTPUT CONFIG PARAMETER
233        ext_output_config_t             ext_output_config[4];                   //185+16
234        ext_input_config_t              ext_input_config[4];                    //201+16                Konfiguration der Eingänge
235        ext_output_aux_config_t ext_output_aux_config[4];               //217+4
236        uint16_t                                reserved6[4];                                   //221+4
237
238        //SMS Parameter
239#ifdef GREEN_CONTROLLER_140_30
240        uint8_t                                 sms_alarm_level;                                //225l
241        uint8_t                                 reserved2[3];                                   //225h, 226
242        char                                    phone_number[MAX_PHONE_NUMBER_SIZE];    //227-244
243#elif defined GREEN_CONTROLLER_75_40
244        uint8_t                                 res_sms_alarm_level;                            //225l                                                                                                          //GSM Modul nicht vorhanden
245        uint8_t                                 res_reserved2[3];                                       //225h, 226                                                                                                     //GSM Modul nicht vorhanden
246        char                                    res_phone_number[MAX_PHONE_NUMBER_SIZE];        //227-244                                                                                       //GSM Modul nicht vorhanden
247#endif
248        // System
249        uint16_t                                cmd;                                                    //245
250        uint16_t                                debug_mode;                                             //246
251
252        //Parameter Reserve
253        ext_output_config_t             main_output_config;                             //247+4
254        //Neu limit
255        float                   cell_v_limit_high;                      //251-252
256        uint8_t                                 buzzerEnabled;                                  //253l
257        mb_error_codes_t                error_bms_communication;                //253
258
259
260        // ES FOLGEN SICH ZUR LAUFZEIT ÄNDERNDE VARIABLEN
261
262        int16_t                                 last_cut_off_ah;                                //254
263        // GSM Data
264#ifdef GREEN_CONTROLLER_140_30
265        gsm_mode_t                              current_gsm_mode;                               //255l
266        bool                                    tcp_connection_online;                  //255h                  Ist True wenn Verbindung zum Server steht, schaltet zurück wenn Verbindung (automatisch) beendet wurde
267        bool                                    internet_online;                                //256l
268        uint8_t                                 gsm_tx_bytes;                                   //256h
269        uint8_t                                 myIP[4];                                                //257,258
270        time_t                                  gsm_time;                                               //259,260,261
271        uint8_t                                 modbus_gsm_data[256];                   //262+128
272#elif defined GREEN_CONTROLLER_75_40
273        uint8_t                                 res_reserved8;                                          //255l                  //alt: GSM mode
274        bool                                    res_tcp_connection_online;                      //255h                  Ist True wenn Verbindung zum Server steht, schaltet zurück wenn Verbindung (automatisch) beendet wurde
275        bool                                    res_internet_online;                            //256l
276        uint8_t                                 res_gsm_tx_bytes;                                       //256h
277        uint8_t                                 res_myIP[4];                                            //257,258
278        time_t                                  res_gsm_time;                                           //259,260,261
279        uint8_t                                 res_modbus_gsm_data[256];                       //262+128
280#endif
281        // LIPRO DATEN
282        lipro_data_t                    lipro_data[MAX_LIPRO_CELLS];    //390+112 = 502 // ACHTUNG LIPRO START ADRESS DEFINE ANPASSEN BEI ÄNDERUNG!!!!!
283
284        // BERECHNETE BATTERIE SYSTEM SETPOINTS
285        uint16_t                                batt_current_limit;                             //502
286        float                                   batt_absorption_voltage;                //503,504
287        float                                   batt_absorption_exit_voltage;   //505,506
288        float                                   batt_float_voltage;                             //507,508
289        float                                   batt_float_exit_voltage;                //509,510
290        float                                   batt_equalize_voltage;                  //511,512
291        float                                   batt_cut_off_voltage;                   //513,514
292        float                                   batt_cut_off_recovery_voltage;  //515,516 ---> ADRESSEN KORRIGIEREN
293
294        //SYSTEM STREETLIGHT
295        sl_mode_t                               sl_reserved2;                                   //517l
296        uint8_t                                 sl_current_led_pwm;                             //517h
297        bool                                    sl_low_batt_mode;                               //518l
298        bool                                    sl_reserved12;                                  //518h
299
300        // WICHTIGE PARAMTER die geloggt werden müssen
301        bool                                    error_master;                                   //519l
302        bool                                    error_hv_input;                                 //519h
303        uint8_t                                 error_hv_batt;                                  //520l
304        bool                                    error_temp_int;                                 //520h - Interne Spannung zu hoch
305        bool                                    error_lvp_batt;                                 //521l
306        bool                                    error_lvp_cell;                                 //521h
307        bool                                    error_uvp_batt;                                 //522l - Batteriespannung zu gering oder sense Kabel nicht angeschlossen
308        bool                                    error_ovp_cell;                                 //522h
309        bool                                    error_temp_batt;                                //523l
310        bool                                    warn_i_lim_active;                              //523h
311        mb_error_codes_t                error_gc_communication;                 //524l -
312        uint8_t                                 errorcode_temp_sensor_batt;             //524h
313        uint8_t                                 reset_status;                                   //525l
314        bool                                    bms_system_warning;                             //525h :Neu in V3.20 vorher reserved
315        uint8_t                                 i_lim_ext;                                              //526l -berehneter Strombegrenzungswert bei Stuerung via external input
316        uint8_t                                 error_sense;                                    //526h
317        uint8_t                                 diversion_pwm_out;                              //527l
318        uint8_t                                 reserved1;                                              //527h
319        uint8_t                                 reserved4;                                              //528l
320        output_state_t                  output_state;                                   //528h
321        charger_mode_t                  charger_state;                                  //529l
322        uint8_t                                 external_alarm;                                 //529h
323        uint16_t                                mpp_pwm;                                                //530 - MPP Punkt als PWM Wert
324        uint16_t                                act_pwm;                                                //531 - Aktuelle PWM
325        uint16_t                                p_input;                                                //532
326        uint16_t                                p_ouput;                                                //533
327        uint16_t                                abs_equalize_hold_counter;              //534 - Zählt die Minuten in der Absorption Phase, wird auch im Equalize Modus verwendet
328        uint16_t                                float_exit_counter;                             //535 - Zählt die Minuten die die Erhaltungsladespannung nicht erreicht werden kann
329        int16_t                                 internal_temp;                                  //536
330        int16_t                                 batt_temperature;                               //537
331        float                                   u_external_inputs[4];                   //538,539,540,541,542,543,544,545
332        float                                   u_batt;                                                 //546,547
333        float                                   u_input;                                                //548,549
334        float                                   u_buck;                                                 //550,551
335        float                                   i_batt_in_internal_mw;                  //552,553
336        float                                   i_out_internal;                                 //554,555
337        float                                   i_batt;                                                 //556,557
338#ifdef GREEN_CONTROLLER_140_30
339        float                                   longitude;                                              //558,559
340        float                                   latitude;                                               //560,561
341        float                                   altitude;                                               //562,563
342#elif defined GREEN_CONTROLLER_75_40
343        float                                   res_longitude;                                  //558,559
344        float                                   res_latitude;                                   //560,561
345        float                                   res_altitude;                                   //562,563
346#endif
347        float                                   counter_batt_ah;                                //564,565 - Ah Zähler
348        uint32_t                                counter_p_in;                                   //566,567 - !!!! KEIN INIT AB HIER !!!!
349        uint32_t                                counter_p_out;                                  //568,569
350        uint32_t                                counter_p_in_last_day;                  //570,571
351        uint32_t                                counter_p_out_last_Day;                 //572,573
352        uint32_t                                counter_p_in_total;                             //574,575
353        uint32_t                                counter_p_out_total;                    //576,577
354        lokal_time_t                    lokal_time;                                             //578,579,580,581
355        log_t                                   logs[MAX_LOG_MESSAGES];                 // jeweils 4 Register, 8 Bytes Array zum Aufnehmen der Log Nachrichten --80 Byte von 582 bis 621
356#ifdef GREEN_CONTROLLER_140_30
357        char                                    gps_signal_state;                               //622l Status der Signal intergrität ---- Ab hier neu in Neu in V2 -----
358        char                                    gps_valid;                                              //622h
359        uint8_t                                 gps_num_satelites;                              //623l
360        uint8_t                                 gps_last_packet_type;                   //623h
361#elif defined GREEN_CONTROLLER_75_40
362        char                                    res_gps_signal_state;                   //622l Status der Signal intergrität ---- Ab hier neu in Neu in V2 -----
363        char                                    res_gps_valid;                                  //622h
364        uint8_t                                 res_gps_num_satelites;                  //623l
365        uint8_t                                 res_gps_last_packet_type;               //623h
366#endif
367        uint8_t                                 external_output_states[4];              //624,625
368        float                                   v_in_scale_faktor;                              //626,627
369        float                                   v_batt_scale_faktor_1;                  //628,629
370#ifdef GREEN_CONTROLLER_140_30
371        float                                   v_batt_scale_faktor_2;                  //630,631
372#elif defined GREEN_CONTROLLER_75_40
373        float                                   reserved7;                                              //630,631 v_batt_scale_faktor_2 entfällt
374#endif
375        float                                   i_in_scale_faktor;                              //632,633
376        float                                   i_out_scale_faktor;                             //634,635
377#ifdef GREEN_CONTROLLER_140_30
378        uint8_t                                 gsm_rssi;                                               //636l
379        uint8_t                                 gsm_ber;                                                //636h
380#elif defined GREEN_CONTROLLER_75_40
381        uint8_t                                 res_gsm_rssi;                                   //636l
382        uint8_t                                 res_gsm_ber;                                    //636h
383#endif
384        float                                   i_batt_in_internal_fast;                //637,638
385        int16_t                                 soc;                                                    //639
386        uint16_t                                fw_sub_revision;                                //640
387        bool                                    error_isometer_alarm;                   //641l
388        bool                                    error_isometer_shutoff;                 //641h
389        uint8_t                                 internal_temp_sensor_id[MAX_TEMP_SENSOR_ID_SIZE];               // 642 - 645
390        uint16_t                                error_internal_temp_sensor;             //646
391        int16_t                                 sensors_found;                                  //647
392        int16_t                                 batt_temp_sensor_number;                //648
393        int16_t                                 internal_temp_sensor_number;    //649
394        float                                   u_external_inputs_fast[4];              //650,651 652,653 654,655 656,657
395        float                                   i_out_internal_fast;                    //658,659
396        float                                   i_batt_fast;                                    //660,661
397        float                                   u_input_fast;                                   //662,663
398
399        uint8_t                                 BMx_sensor_id;                                  // 664 - LO
400        bool                                    BMx_DewPointAlarm;                              // 664 - HI
401        int16_t                                 BMx_Temperature;                                // 665
402        uint16_t                                BMx_Pressure;                                   // 666
403        uint16_t                                BMx_Humidity;                                   // 667
404        int16_t                                 BMx_DewPoint;                                   // 668
405        uint8_t                                 BMx_step;                                               // 669 - LO
406        uint8_t                                 BMx_reserved;                                   // 669 - HI
407
408        uint8_t                                 remote_bus_baudrate;                    // 670 - LO
409        uint8_t                                 remote_bus_parity;                              // 670 - HI
410        uint8_t                                 remote_bus_stopbits;                    // 671 - LO
411        uint8_t                                 reserved8;                                              // 671 - HI
412
413        //int16_t                               ubatt_offset;                                   // 672                  Debugging. Later can be deleted.
414        //uint16_t                              adc_offset;                                             // 673                  Debugging. Later can be deleted.
415        //uint16_t                              current_out_offset;                             // 674                  Debugging. Later can be deleted.
416        //uint16_t                              mem_address;                                    // 675                  Debugging. Later can be deleted.
417        //uint16_t                              mem_value;                                              // 676                  Debugging. Later can be deleted.
418
419        uint16_t                                output_off_on_timeout_s;                // 672                  Seconds
420
421}sys_data_struct_t;
422
423
424typedef union sys_data_union
425{
426                sys_data_struct_t       s;
427                bword_t mb[sizeof(sys_data_struct_t) / 2];
428} sys_data_t;
429
430#ifdef __cplusplus
431extern "C"
432{
433#endif
434
435void sys_data_init(void);
436
437#ifdef __cplusplus
438} // extern "C"
439#endif
440
441#endif // __SYS_DATA_H
Note: See TracBrowser for help on using the repository browser.