Teleinfo, add stats and more checksum controls (#18052)

* added teleinfo config show_stats parameter

* Added new command and more checksum test
This commit is contained in:
Charles 2023-02-25 17:39:33 +01:00 committed by GitHub
parent 27de8b5c3e
commit 1545f02fb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -48,7 +48,7 @@
const char TELEINFO_COMMAND_SETTINGS[] PROGMEM = "TIC: Settings Mode:%s, RX:%s, EN:%s, Raw:%s, Skip:%d, Limit:%d"; const char TELEINFO_COMMAND_SETTINGS[] PROGMEM = "TIC: Settings Mode:%s, RX:%s, EN:%s, Raw:%s, Skip:%d, Limit:%d";
#define MAX_TINFO_COMMAND_NAME 16+1 // Change this if one of the following kTInfo_Commands is higher then 16 char #define MAX_TINFO_COMMAND_NAME 16+1 // Change this if one of the following kTInfo_Commands is higher then 16 char
const char kTInfo_Commands[] PROGMEM = "historique|standard|noraw|full|changed|skip|limit"; const char kTInfo_Commands[] PROGMEM = "historique|standard|noraw|full|changed|skip|limit|stats";
enum TInfoCommands { // commands for Console enum TInfoCommands { // commands for Console
CMND_TELEINFO_HISTORIQUE=0, // Set Legacy mode CMND_TELEINFO_HISTORIQUE=0, // Set Legacy mode
@ -57,7 +57,8 @@ enum TInfoCommands { // commands for Console
CMND_TELEINFO_RAW_FULL, // Enable all RAW frame send CMND_TELEINFO_RAW_FULL, // Enable all RAW frame send
CMND_TELEINFO_RAW_CHANGE, // Enable only changed values RAW frame send CMND_TELEINFO_RAW_CHANGE, // Enable only changed values RAW frame send
CMND_TELEINFO_SKIP, // Set number of frame to skip when raw mode is enabled CMND_TELEINFO_SKIP, // Set number of frame to skip when raw mode is enabled
CMND_TELEINFO_LIMIT // Limit RAW frame to values subject to fast change (Power, Current, ...), TBD CMND_TELEINFO_LIMIT, // Limit RAW frame to values subject to fast change (Power, Current, ...), TBD
CMND_TELEINFO_STATS // Show / clear / Enable TIC reception errors stats
}; };
@ -155,6 +156,7 @@ PROGMEM
= =
"|PJOURF+1" "|PJOURF+1"
"|MSG1" "|MSG1"
"|PPOINTE"
"|" "|"
; ;
@ -527,6 +529,9 @@ bool ResponseAppendTInfo(char sep, bool all)
if (me->name && me->value && *me->name && *me->value) { if (me->name && me->value && *me->name && *me->value) {
// Check back checksum in case of any memory corruption
if (me->checksum==tinfo.calcChecksum(me->name, me->value))) {
// Does this label blacklisted ? // Does this label blacklisted ?
if (!isBlacklistedLabel(me->name)) { if (!isBlacklistedLabel(me->name)) {
@ -575,6 +580,10 @@ bool ResponseAppendTInfo(char sep, bool all)
sep =','; sep =',';
} }
} }
} else {
AddLog(LOG_LEVEL_WARNING, PSTR("TIC: bad checksum for %s"), me->name);
}
} }
} }
@ -897,6 +906,34 @@ bool TInfoCmd(void) {
} }
break; break;
case CMND_TELEINFO_STATS: {
char stats_name[MAX_TINFO_COMMAND_NAME];
// Get the raw name
GetTextIndexed(statsname, MAX_TINFO_COMMAND_NAME, command_code, kTInfo_Commands);
int l = strlen(stats_name);
// At least "EnergyConfig Stats" plus one space and one (or more) digit
// so "EnergyConfig Stats" or "EnergyConfig Stats 0"
if ( pValue ) {
int value = atoi(pValue);
if (value==0 || value==1) {
Settings->teleinfo.show_stats = value ;
AddLog(LOG_LEVEL_INFO, PSTR("TIC: Show stats=%d"), value);
} else if (value == 2) {
tinfo.clearstats();
AddLog(LOG_LEVEL_INFO, PSTR("TIC: Stats cleared"));
} else {
AddLog(LOG_LEVEL_INFO, PSTR("TIC: bad Stats param '%d'"), value);
}
}
// Show stats
AddLog(LOG_LEVEL_INFO, PSTR("TIC: Frame error CheckSum:%d Size:%d Format:%d Interrupt:%d"),
tinfo.getChecksumErrorCount(),
tinfo.getFrameSizeErrorCount(),
tinfo.getFrameFormatErrorCount(),
tinfo.getFrameInterruptedCount() );
}
break;
default: default:
AddLog(LOG_LEVEL_INFO, PSTR("TIC: bad cmd param '%s'"), pParam); AddLog(LOG_LEVEL_INFO, PSTR("TIC: bad cmd param '%s'"), pParam);
break; break;