Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weidmüller: Fix uint32 and status encoding #15071

Merged
merged 1 commit into from
Jul 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions charger/weidmüller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/modbus"
"github.com/evcc-io/evcc/util/sponsor"
"github.com/volkszaehler/mbmd/encoding"
)

// Weidmüller charger implementation
Expand Down Expand Up @@ -122,7 +123,7 @@ func (wb *Weidmüller) getPhaseValues(reg uint16) (float64, float64, float64, er

var res [3]float64
for i := range res {
res[i] = float64(binary.BigEndian.Uint32(b[4*i:])) / 1e3
res[i] = float64(encoding.Uint32LswFirst(b[4*i:])) / 1e3
}

return res[0], res[1], res[2], nil
Expand All @@ -135,7 +136,7 @@ func (wb *Weidmüller) Status() (api.ChargeStatus, error) {
return api.StatusNone, err
}

switch s := string(b[0]); s {
switch s := string(b); s {
case "A", "B", "C":
return api.ChargeStatus(s), nil
default:
Expand Down Expand Up @@ -180,7 +181,7 @@ func (wb *Weidmüller) CurrentPower() (float64, error) {
return 0, err
}

return float64(binary.BigEndian.Uint32(b)) / 1e3, err
return float64(encoding.Uint32LswFirst(b)) / 1e3, err
}

var _ api.MeterEnergy = (*Weidmüller)(nil)
Expand All @@ -192,7 +193,7 @@ func (wb *Weidmüller) TotalEnergy() (float64, error) {
return 0, err
}

return float64(binary.BigEndian.Uint32(b)) / 1e3, err
return float64(encoding.Uint32LswFirst(b)) / 1e3, err
}

var _ api.PhaseCurrents = (*Weidmüller)(nil)
Expand Down