NUM_TAGS is used to check of overflow

This commit is contained in:
proddy
2023-01-07 14:39:30 +01:00
parent 8cd08fa765
commit c7628ac07f
2 changed files with 11 additions and 5 deletions

View File

@@ -107,9 +107,10 @@ DeviceValue::DeviceValue(uint8_t device_type,
// must be an int of 4 bytes, 32bit aligned // must be an int of 4 bytes, 32bit aligned
const char * DeviceValue::DeviceValueUOM_s[] = { const char * DeviceValue::DeviceValueUOM_s[] = {
F_(uom_blank), F_(uom_degrees), F_(uom_degrees), F_(uom_percent), F_(uom_lmin), F_(uom_kwh), F_(uom_wh), FL_(hours)[0], FL_(minutes)[0], F_(uom_blank), // 0
F_(uom_ua), F_(uom_bar), F_(uom_kw), F_(uom_w), F_(uom_kb), FL_(seconds)[0], F_(uom_dbm), F_(uom_fahrenheit), F_(uom_mv), F_(uom_degrees), F_(uom_degrees), F_(uom_percent), F_(uom_lmin), F_(uom_kwh), F_(uom_wh), FL_(hours)[0], FL_(minutes)[0],
F_(uom_sqm), F_(uom_m3), F_(uom_l), F_(uom_kmin), F_(uom_k), F_(uom_blank) F_(uom_ua), F_(uom_bar), F_(uom_kw), F_(uom_w), F_(uom_kb), FL_(seconds)[0], F_(uom_dbm), F_(uom_fahrenheit),
F_(uom_mv), F_(uom_sqm), F_(uom_m3), F_(uom_l), F_(uom_kmin), F_(uom_k), F_(uom_blank)
}; };
@@ -207,7 +208,7 @@ const char * const DeviceValue::DeviceValueTAG_mqtt[] = {
}; };
// count #tags once at compile time // count #tags once at compile time
size_t DeviceValue::tag_count = sizeof(DeviceValue::DeviceValueTAG_s) / sizeof(char * const *); uint8_t DeviceValue::NUM_TAGS = sizeof(DeviceValue::DeviceValueTAG_s) / sizeof(char * const *);
// checks whether the device value has an actual value // checks whether the device value has an actual value
// returns true if its valid // returns true if its valid

View File

@@ -178,7 +178,12 @@ class DeviceValue {
uint16_t max, uint16_t max,
uint8_t state); uint8_t state);
// has values
bool hasValue() const; bool hasValue() const;
bool has_tag() const {
return ((tag < DeviceValue::NUM_TAGS) && (tag != DeviceValue::DeviceValueTAG::TAG_NONE));
}
bool get_min_max(int16_t & dv_set_min, uint16_t & dv_set_max); bool get_min_max(int16_t & dv_set_min, uint16_t & dv_set_max);
void set_custom_minmax(); void set_custom_minmax();
@@ -204,7 +209,7 @@ class DeviceValue {
static const char * DeviceValueUOM_s[]; static const char * DeviceValueUOM_s[];
static const char * const * DeviceValueTAG_s[]; static const char * const * DeviceValueTAG_s[];
static const char * const DeviceValueTAG_mqtt[]; static const char * const DeviceValueTAG_mqtt[];
static size_t tag_count; // # tags static uint8_t NUM_TAGS; // # tags
}; };
}; // namespace emsesp }; // namespace emsesp