Add frequency clip check
Add check to ensure frequency value is set to 0 when period counter hits maximum or minimum Closes #31
This commit is contained in:
@@ -346,7 +346,7 @@ func (m *mk2Ser) dcDecode(frame []byte) {
|
||||
chargeC := m.applyScale(getUnsigned(frame[10:13]), ramVarIBat)
|
||||
m.info.BatCurrent = usedC - chargeC
|
||||
|
||||
m.info.OutFrequency = 10 / (m.applyScale(float64(frame[13]), ramVarInverterPeriod))
|
||||
m.info.OutFrequency = m.calcFreq(frame[13], ramVarInverterPeriod)
|
||||
logrus.Debugf("dcDecode %#v", m.info)
|
||||
|
||||
// Send L1 status request
|
||||
@@ -362,12 +362,8 @@ func (m *mk2Ser) acDecode(frame []byte) {
|
||||
m.info.InCurrent = m.applyScale(getSigned(frame[7:9]), ramVarIMains)
|
||||
m.info.OutVoltage = m.applyScale(getSigned(frame[9:11]), ramVarVInverter)
|
||||
m.info.OutCurrent = m.applyScale(getSigned(frame[11:13]), ramVarIInverter)
|
||||
m.info.InFrequency = m.calcFreq(frame[13], ramVarMainPeriod)
|
||||
|
||||
if frame[13] == 0xff {
|
||||
m.info.InFrequency = 0
|
||||
} else {
|
||||
m.info.InFrequency = 10 / (m.applyScale(float64(frame[13]), ramVarMainPeriod))
|
||||
}
|
||||
logrus.Debugf("acDecode %#v", m.info)
|
||||
|
||||
// Send status request
|
||||
@@ -376,6 +372,13 @@ func (m *mk2Ser) acDecode(frame []byte) {
|
||||
m.sendCommand(cmd)
|
||||
}
|
||||
|
||||
func (m *mk2Ser) calcFreq(data byte, scaleIndex int) float64 {
|
||||
if data == 0xff || data == 0x00 {
|
||||
return 0
|
||||
}
|
||||
return 10 / (m.applyScale(float64(data), scaleIndex))
|
||||
}
|
||||
|
||||
// Decode charge state of battery.
|
||||
func (m *mk2Ser) stateDecode(frame []byte) {
|
||||
m.info.ChargeState = m.applyScaleAndSign(frame[1:3], ramVarChargeState)
|
||||
|
||||
Reference in New Issue
Block a user