Wallbe: remove SDM float decoding workaround (#2110)
This commit is contained in:
parent
d698434868
commit
575915c6fc
7 changed files with 18 additions and 68 deletions
|
|
@ -3,8 +3,6 @@ package charger
|
|||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"math"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/evcc-io/evcc/api"
|
||||
|
|
@ -26,8 +24,6 @@ const (
|
|||
wbRegPower = 120 // power reading
|
||||
wbRegEnergy = 128 // energy reading
|
||||
wbRegEnergyDecimals = 904 // energy reading decimals
|
||||
|
||||
encodingSDM = "sdm"
|
||||
)
|
||||
|
||||
var wbRegCurrents = []uint16{114, 116, 118} // current readings
|
||||
|
|
@ -37,9 +33,8 @@ var wbRegCurrents = []uint16{114, 116, 118} // current readings
|
|||
// Phoenix EV-CC-AC1-M3-CBC-RCM-ETH controller.
|
||||
// It uses Modbus TCP to communicate with the wallbox at modbus client id 255.
|
||||
type Wallbe struct {
|
||||
conn *modbus.Connection
|
||||
factor int64
|
||||
encoding string
|
||||
conn *modbus.Connection
|
||||
factor int64
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
|
@ -55,11 +50,12 @@ func NewWallbeFromConfig(other map[string]interface{}) (api.Charger, error) {
|
|||
Legacy bool
|
||||
Meter struct {
|
||||
Power, Energy, Currents bool
|
||||
Encoding string
|
||||
Encoding interface{}
|
||||
}
|
||||
}{
|
||||
URI: "192.168.0.8:502",
|
||||
}
|
||||
|
||||
if err := util.DecodeOther(other, &cc); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -69,6 +65,10 @@ func NewWallbeFromConfig(other map[string]interface{}) (api.Charger, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if cc.Meter.Encoding != nil {
|
||||
util.NewLogger("wallbe").WARN.Printf("encoding is deprecated and will be removed in a future release. Use firmware 01.04.21 instead.")
|
||||
}
|
||||
|
||||
if cc.Legacy {
|
||||
wb.factor = 1
|
||||
}
|
||||
|
|
@ -93,11 +93,6 @@ func NewWallbeFromConfig(other map[string]interface{}) (api.Charger, error) {
|
|||
maxCurrentMillis = wb.maxCurrentMillis
|
||||
}
|
||||
|
||||
// special case for SDM meters
|
||||
if encoding := strings.ToLower(cc.Meter.Encoding); strings.HasPrefix(encoding, encodingSDM) {
|
||||
wb.encoding = encodingSDM
|
||||
}
|
||||
|
||||
return decorateWallbe(wb, currentPower, totalEnergy, currents, maxCurrentMillis), nil
|
||||
}
|
||||
|
||||
|
|
@ -189,19 +184,6 @@ func (wb *Wallbe) ChargingTime() (time.Duration, error) {
|
|||
return time.Duration(secs) * time.Second, nil
|
||||
}
|
||||
|
||||
func (wb *Wallbe) decodeReading(b []byte) float64 {
|
||||
switch wb.encoding {
|
||||
case encodingSDM:
|
||||
// high word first
|
||||
bits := uint32(b[3]) | uint32(b[2])<<8 | uint32(b[1])<<16 | uint32(b[0])<<24
|
||||
return float64(math.Float32frombits(bits))
|
||||
|
||||
default:
|
||||
// low word first
|
||||
return rs485.RTUUint32ToFloat64Swapped(b)
|
||||
}
|
||||
}
|
||||
|
||||
// currentPower implements the api.Meter interface
|
||||
func (wb *Wallbe) currentPower() (float64, error) {
|
||||
b, err := wb.conn.ReadInputRegisters(wbRegPower, 2)
|
||||
|
|
@ -209,7 +191,7 @@ func (wb *Wallbe) currentPower() (float64, error) {
|
|||
return 0, err
|
||||
}
|
||||
|
||||
return wb.decodeReading(b), nil
|
||||
return rs485.RTUUint32ToFloat64Swapped(b), nil
|
||||
}
|
||||
|
||||
// totalEnergy implements the api.MeterEnergy interface
|
||||
|
|
@ -219,17 +201,15 @@ func (wb *Wallbe) totalEnergy() (float64, error) {
|
|||
return 0, err
|
||||
}
|
||||
|
||||
res := wb.decodeReading(b)
|
||||
res := rs485.RTUUint32ToFloat64Swapped(b)
|
||||
|
||||
if wb.encoding != encodingSDM {
|
||||
b, err := wb.conn.ReadHoldingRegisters(wbRegEnergyDecimals, 1)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
res += float64(binary.BigEndian.Uint16(b)) / 1e3
|
||||
d, err := wb.conn.ReadHoldingRegisters(wbRegEnergyDecimals, 1)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
res += float64(binary.BigEndian.Uint16(d)) / 1e3
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
|
|
@ -242,7 +222,7 @@ func (wb *Wallbe) currents() (float64, float64, float64, error) {
|
|||
return 0, 0, 0, err
|
||||
}
|
||||
|
||||
currents = append(currents, wb.decodeReading(b))
|
||||
currents = append(currents, rs485.RTUUint32ToFloat64Swapped(b))
|
||||
}
|
||||
|
||||
return currents[0], currents[1], currents[2], nil
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ params:
|
|||
render: |
|
||||
type: wallbe
|
||||
uri: {{ .host }}:{{ .port }}
|
||||
legacy: false # set only for older Wallbe devices (pre ~2019, old controller firmware)
|
||||
meter: # only if a charge meter is connected to the controller
|
||||
power: true
|
||||
energy: true
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ params:
|
|||
render: |
|
||||
type: wallbe
|
||||
uri: {{ .host }}:{{ .port }}
|
||||
legacy: true # set only for older Wallbe devices (pre ~2019, old controller firmware)
|
||||
legacy: true # set only for older Wallbe devices (pre ~2019, old controller firmware)
|
||||
meter: # only if a charge meter is connected to the controller
|
||||
power: true
|
||||
energy: true
|
||||
|
|
|
|||
|
|
@ -14,4 +14,4 @@ params:
|
|||
render: |
|
||||
type: wallbe
|
||||
uri: {{ .host }}:{{ .port }}
|
||||
legacy: true # set only for older Wallbe devices (pre ~2019, old controller firmware)
|
||||
legacy: true # set only for older Wallbe devices (pre ~2019, old controller firmware)
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
template: wallbe-sdm
|
||||
description: Wallbe (Eco, Pro) with SDM Meter
|
||||
requirements:
|
||||
description:
|
||||
en: The Wallbe must be connected using Ethernet and the DIP switch 10 must be set to 'ON'.
|
||||
de: Die Wallbox muss über ein Netzwerkkabel angebunden sein und im Gerät muss der DIP Schalter 10 auf 'ON' gestellt sein.
|
||||
uri: https://docs.evcc.io/docs/devices/chargers#wallbe-ecopro
|
||||
params:
|
||||
- name: host
|
||||
required: true
|
||||
example: 192.0.2.2
|
||||
- name: port
|
||||
default: 502
|
||||
render: |
|
||||
type: wallbe
|
||||
uri: {{ .host }}:{{ .port }}
|
||||
legacy: false # set only for older Wallbe devices (pre ~2019, old controller firmware)
|
||||
meter: # only if a charge meter is connected to the controller
|
||||
power: true
|
||||
energy: true
|
||||
currents: true
|
||||
encoding: sdm # add only when SDM meter is connected, see https://github.com/evcc-io/evcc/discussions/1398
|
||||
|
||||
|
|
@ -14,4 +14,3 @@ params:
|
|||
render: |
|
||||
type: wallbe
|
||||
uri: {{ .host }}:{{ .port }}
|
||||
legacy: false # set only for older Wallbe devices (pre ~2019, old controller firmware)
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
type: template
|
||||
template: wallbe-sdm
|
||||
description: Wallbe (Eco, Pro) with SDM Meter
|
||||
host: 192.0.2.2
|
||||
port: 502
|
||||
Loading…
Add table
Add a link
Reference in a new issue