From 58044c34aa16d1ffa08e935d0c5fe3c1261e104b Mon Sep 17 00:00:00 2001 From: Wusaweki Date: Sun, 3 Dec 2023 15:51:33 +0100 Subject: [PATCH] remove redundant check for nullpointer (cherry picked from commit a1de637793bdc14627c68fc1b03d61d5189758cd) (cherry picked from commit 7ba88180c50d7d0b6c971a477987bb5ded5aa9d8) (cherry picked from commit 6888d571834ad5cf4b32a00536501e88112f7049) (cherry picked from commit 8a8b8a61f354992823a77feca3a5193f8c53880e) --- src/hm/hmInverter.h | 50 ++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/src/hm/hmInverter.h b/src/hm/hmInverter.h index 1890d142..4252800d 100644 --- a/src/hm/hmInverter.h +++ b/src/hm/hmInverter.h @@ -288,32 +288,30 @@ class Inverter { uint8_t end = ptr + rec->assign[pos].num; uint16_t div = rec->assign[pos].div; - if(NULL != rec) { - if(CMD_CALC != div) { - uint32_t val = 0; - do { - val <<= 8; - val |= buf[ptr]; - } while(++ptr != end); - - if ((FLD_T == rec->assign[pos].fieldId) || (FLD_Q == rec->assign[pos].fieldId) || (FLD_PF == rec->assign[pos].fieldId)) { - // temperature, Qvar, and power factor are a signed values - rec->record[pos] = ((REC_TYP)((int16_t)val)) / (REC_TYP)(div); - } else if (FLD_YT == rec->assign[pos].fieldId) { - rec->record[pos] = ((REC_TYP)(val) / (REC_TYP)(div)) + ((REC_TYP)config->yieldCor[rec->assign[pos].ch-1]); - } else if (FLD_YD == rec->assign[pos].fieldId) { - float actYD = (REC_TYP)(val) / (REC_TYP)(div); - uint8_t idx = rec->assign[pos].ch - 1; - if (mLastYD[idx] > actYD) - mOffYD[idx] += mLastYD[idx]; - mLastYD[idx] = actYD; - rec->record[pos] = mOffYD[idx] + actYD; - } else { - if ((REC_TYP)(div) > 1) - rec->record[pos] = (REC_TYP)(val) / (REC_TYP)(div); - else - rec->record[pos] = (REC_TYP)(val); - } + if(CMD_CALC != div) { + uint32_t val = 0; + do { + val <<= 8; + val |= buf[ptr]; + } while(++ptr != end); + + if ((FLD_T == rec->assign[pos].fieldId) || (FLD_Q == rec->assign[pos].fieldId) || (FLD_PF == rec->assign[pos].fieldId)) { + // temperature, Qvar, and power factor are a signed values + rec->record[pos] = ((REC_TYP)((int16_t)val)) / (REC_TYP)(div); + } else if (FLD_YT == rec->assign[pos].fieldId) { + rec->record[pos] = ((REC_TYP)(val) / (REC_TYP)(div)) + ((REC_TYP)config->yieldCor[rec->assign[pos].ch-1]); + } else if (FLD_YD == rec->assign[pos].fieldId) { + float actYD = (REC_TYP)(val) / (REC_TYP)(div); + uint8_t idx = rec->assign[pos].ch - 1; + if (mLastYD[idx] > actYD) + mOffYD[idx] += mLastYD[idx]; + mLastYD[idx] = actYD; + rec->record[pos] = mOffYD[idx] + actYD; + } else { + if ((REC_TYP)(div) > 1) + rec->record[pos] = (REC_TYP)(val) / (REC_TYP)(div); + else + rec->record[pos] = (REC_TYP)(val); } }