Merge pull request #15017 from gemu2015/sml_offsets

optional calibration offset
This commit is contained in:
Theo Arends 2022-03-03 10:00:39 +01:00 committed by GitHub
commit 725458013b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 5 deletions

View File

@ -1665,6 +1665,23 @@ uint32_t vbus_get_septet(uint8_t *cp) {
}
char *skip_double(char *cp) {
if (*cp == '+' || *cp == '-') {
cp++;
}
while (*cp) {
if (*cp == '.') {
cp++;
}
if (!isdigit(*cp)) {
return cp;
}
cp++;
}
return 0;
}
void SML_Decode(uint8_t index) {
const char *mp=(const char*)meter_p;
int8_t mindex;
@ -2168,6 +2185,12 @@ void SML_Decode(uint8_t index) {
//AddLog(LOG_LEVEL_INFO, PSTR(">> %s"),mp);
// get scaling factor
double fac = CharToDouble((char*)mp);
// get optional offset to calibrate meter
char *cp = skip_double((char*)mp);
if (cp && (*cp == '+' || *cp == '-')) {
double offset = CharToDouble(cp);
meter_vars[vindex] += offset;
}
meter_vars[vindex] /= fac;
SML_Immediate_MQTT((const char*)mp, vindex, mindex);
}