Skip to content

Commit 7597998

Browse files
author
dingo35
committed
let compiler decide on size of EMConfig
1 parent e4baf94 commit 7597998

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

SmartEVSE-3/src/esp32.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ extern const char StrEnableC2[5][12];
149149
extern Single_Phase_t Switching_To_Single_Phase;
150150
extern uint8_t Nr_Of_Phases_Charging;
151151

152+
extern uint16_t EMConfigSize;
153+
152154
const struct {
153155
char LCD[10];
154156
char Desc[52];
@@ -169,7 +171,7 @@ const struct {
169171
{"SWITCH", "Switch function control on pin SW", 0, 7, SWITCH},
170172
{"RCMON", "Residual Current Monitor on pin RCM", 0, 1, RC_MON},
171173
{"RFID", "RFID reader, learn/remove cards", 0, 5 + (ENABLE_OCPP ? 1 : 0), RFID_READER},
172-
{"EV METER","Type of EV electric meter", 0, EM_CUSTOM, EV_METER},
174+
{"EV METER","Type of EV electric meter", 0, (uint16_t) (EMConfigSize / sizeof(EMConfig[0])-1), EV_METER},
173175
{"EV ADDR", "Address of EV electric meter", MIN_METER_ADDRESS, MAX_METER_ADDRESS, EV_METER_ADDRESS},
174176

175177
// System configuration
@@ -182,7 +184,7 @@ const struct {
182184
{"START", "Surplus energy start Current (sum of phases)", 0, 48, START_CURRENT},
183185
{"STOP", "Stop solar charging at 6A after this time", 0, 60, STOP_TIME},
184186
{"IMPORT", "Allow grid power when solar charging (sum of phase)",0, 48, IMPORT_CURRENT},
185-
{"MAINS MET","Type of mains electric meter", 0, EM_CUSTOM, MAINS_METER},
187+
{"MAINS MET","Type of mains electric meter", 0, (uint16_t) (EMConfigSize / sizeof(EMConfig[0])-1), MAINS_METER},
186188
{"MAINS ADR","Address of mains electric meter", MIN_METER_ADDRESS, MAX_METER_ADDRESS, MAINS_METER_ADDRESS},
187189
{"BYTE ORD","Byte order of custom electric meter", 0, 3, EMCUSTOM_ENDIANESS},
188190
{"DATA TYPE","Data type of custom electric meter", 0, MB_DATATYPE_MAX - 1, EMCUSTOM_DATATYPE},

SmartEVSE-3/src/meter.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ extern void RecomputeSoC(void);
1212
#define ENDIANESS_HBF_LWF 2
1313
#define ENDIANESS_HBF_HWF 3
1414

15-
struct EMstruct EMConfig[EM_CUSTOM + 1] = {
15+
// WARNING: ONLY ADD new meters to the END of this ARRAY. The row number is stored in the config of the user, if you change the order YOU WILL RUIN THE CONFIGS OF USERS !!!!!!!
16+
struct EMstruct EMConfig[] = {
1617
/* DESC, ENDIANNESS, FCT, DATATYPE, U_REG,DIV, I_REG,DIV, P_REG,DIV, E_REG_IMP,DIV, E_REG_EXP, DIV */
1718
{"Disabled", ENDIANESS_LBF_LWF, 0, MB_DATATYPE_INT32, 0, 0, 0, 0, 0, 0, 0, 0,0 , 0}, // First entry!
1819
{"Sensorbox", ENDIANESS_HBF_HWF, 4, MB_DATATYPE_FLOAT32, 0xFFFF, 0, 0, 0, 0xFFFF, 0, 0xFFFF, 0,0 , 0}, // Sensorbox (Own routine for request/receive)
@@ -34,6 +35,9 @@ struct EMstruct EMConfig[EM_CUSTOM + 1] = {
3435
{"Unused 4", ENDIANESS_LBF_LWF, 4, MB_DATATYPE_INT32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // unused slot for future new meters
3536
{"Custom", ENDIANESS_LBF_LWF, 4, MB_DATATYPE_INT32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} // Last entry!
3637
};
38+
// WARNING: ONLY ADD new meters to the END of this ARRAY. The row number is stored in the config of the user, if you change the order YOU WILL RUIN THE CONFIGS OF USERS !!!!!!!
39+
40+
uint16_t EMConfigSize = sizeof(EMConfig);
3741

3842
struct Sensorbox SB2;
3943

SmartEVSE-3/src/meter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ struct EMstruct {
7474
int8_t EDivisor_Exp; // 10^x
7575
};
7676

77-
extern struct EMstruct EMConfig[EM_CUSTOM + 1];
77+
extern struct EMstruct EMConfig[];
7878
extern struct Sensorbox SB2;
7979

8080
class Meter {

SmartEVSE-3/src/modbus.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extern "C" {
4343
#include "evse.h"
4444
}
4545
extern struct Sensorbox SB2;
46-
extern struct EMstruct EMConfig[EM_CUSTOM + 1];
46+
extern struct EMstruct EMConfig[];
4747
#endif
4848

4949
#include "modbus.h"

0 commit comments

Comments
 (0)