Fix some calculation

This commit is contained in:
Charles 2021-12-13 12:18:47 +01:00
parent 161c97892b
commit 637f456e00
1 changed files with 27 additions and 28 deletions

View File

@ -327,62 +327,61 @@ void DataCallback(struct _ValueList * me, uint8_t flags)
else if ( ilabel == LABEL_HCHC || ilabel == LABEL_HCHP || ilabel == LABEL_BASE)
{
char value[32];
uint32_t hc = 0;
uint32_t hp = 0;
uint32_t total = 0;
long hc = 0;
long hp = 0;
long total = 0;
// Base, un seul index
if (ilabel == LABEL_BASE) {
total = atoi(me->value);
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: Base:%u"), total);
total = atol(me->value);
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: Base:%ld"), total);
// Heures creuses/pleines calculer total
} else {
// Heures creuses get heures pleines
if (ilabel == LABEL_HCHC) {
hc = atoi(me->value);
hc = atol(me->value);
if ( getValueFromLabelIndex(LABEL_HCHP, value) ) {
hp = atoi(value);
hp = atol(value) ;
}
// Heures pleines, get heures creuses
} else if (ilabel == LABEL_HCHP) {
hp = atoi(me->value);
hp = atol(me->value);
if ( getValueFromLabelIndex(LABEL_HCHC, value) ) {
hc = atoi(value);
hc = atol(value) ;
}
}
total = hc + hp;
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: HC:%u HP:%u Total:%u"), hc, hp, total);
if (hc>0 && hp>0) {
total = hc + hp;
}
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: HC:%ld HP:%ld Total:%ld"), hc, hp, total);
}
Energy.import_active[0] = total/1000.0f;
EnergyUpdateTotal();
AddLog (LOG_LEVEL_INFO, PSTR ("TIC: Total counter updated to %u Wh"), total);
AddLog (LOG_LEVEL_INFO, PSTR ("TIC: Total counter updated to %ld Wh"), total);
if (total>0) {
Energy.import_active[0] = (float)total/1000.0f;
EnergyUpdateTotal();
AddLog (LOG_LEVEL_DEBUG_MORE, PSTR ("TIC: import_active[0]=%.3fKWh"), Energy.import_active[0] );
}
}
// Wh total index (standard)
// Wh total index (all contract)
else if ( ilabel == LABEL_EAST)
{
uint32_t total = atoi(me->value);
if (contrat != CONTRAT_BAS) {
Energy.import_active[0] = total/1000.0f;
EnergyUpdateTotal();
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: Total:%uWh"), total);
}
long total = atol(me->value);
Energy.import_active[0] = (float)total/1000.0f;
EnergyUpdateTotal();
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: Total:%ldWh"), total);
}
// Wh indexes (standard)
else if ( ilabel == LABEL_EASF01)
{
if (contrat == CONTRAT_BAS) {
Energy.import_active[0] = atoi(me->value)/1000.0f;
EnergyUpdateTotal();
}
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: HC:%u"), atoi(me->value));
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: HC:%ld"), atol(me->value));
}
else if ( ilabel == LABEL_EASF02)
{
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: HP:%u"), atoi(me->value));
AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: HP:%ld"), atol(me->value));
}
// Contract subscribed (legacy)
@ -504,7 +503,7 @@ bool ResponseAppendTInfo(char sep, bool all)
if (!isNumber) {
ResponseAppend_P( PSTR("\"%s\""), me->value );
} else {
ResponseAppend_P( PSTR("%d"), atoi(me->value));
ResponseAppend_P( PSTR("%ld"), atol(me->value));
}
// Now JSON separator is needed