ABL: enable/disable using amps instead of mode register (#1651)
This commit is contained in:
parent
f5a33411d8
commit
8e36a49024
1 changed files with 13 additions and 23 deletions
|
|
@ -31,25 +31,20 @@ import (
|
|||
type ABLeMH struct {
|
||||
log *util.Logger
|
||||
conn *modbus.Connection
|
||||
curr uint16
|
||||
}
|
||||
|
||||
const (
|
||||
ablRegFirmware = 0x01
|
||||
ablRegStatus = 0x04
|
||||
ablRegMode = 0x05
|
||||
ablRegAmpsConfig = 0x14
|
||||
ablRegStatusLong = 0x2E
|
||||
|
||||
ablStatusDisabled = 0xE0
|
||||
|
||||
ablAmpsDisabled uint16 = 0x03E8
|
||||
ablModeEnable uint16 = 0xA1A1
|
||||
ablModeDisable uint16 = 0xE0E0
|
||||
)
|
||||
|
||||
const ablStatusOutletDisabled = 0xE0
|
||||
|
||||
var ablStatus = map[byte]string{
|
||||
0xA1: "Waiting for EV",
|
||||
0xB1: "EV is asking for charging",
|
||||
0xB2: "EV has the permission to charge",
|
||||
0xC2: "EV is charged",
|
||||
|
|
@ -108,6 +103,7 @@ func NewABLeMH(uri, device, comset string, baudrate int, slaveID uint8) (api.Cha
|
|||
wb := &ABLeMH{
|
||||
log: log,
|
||||
conn: conn,
|
||||
curr: uint16(6 / 0.06),
|
||||
}
|
||||
|
||||
return wb, nil
|
||||
|
|
@ -127,11 +123,6 @@ func (wb *ABLeMH) Status() (api.ChargeStatus, error) {
|
|||
case 'A', 'B', 'C':
|
||||
return api.ChargeStatus(r), nil
|
||||
default:
|
||||
// treat outlet disabled as vehicle disconnected
|
||||
if b[1] == ablStatusOutletDisabled {
|
||||
return api.StatusA, nil
|
||||
}
|
||||
|
||||
status, ok := ablStatus[b[1]]
|
||||
if !ok {
|
||||
status = string(r)
|
||||
|
|
@ -143,29 +134,28 @@ func (wb *ABLeMH) Status() (api.ChargeStatus, error) {
|
|||
|
||||
// Enabled implements the api.Charger interface
|
||||
func (wb *ABLeMH) Enabled() (bool, error) {
|
||||
_, _ = wb.conn.ReadHoldingRegisters(ablRegStatus, 1)
|
||||
b, err := wb.conn.ReadHoldingRegisters(ablRegStatus, 1)
|
||||
_, _ = wb.conn.ReadHoldingRegisters(ablRegStatusLong, 5)
|
||||
b, err := wb.conn.ReadHoldingRegisters(ablRegStatusLong, 5)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
enabled := b[1] != ablStatusDisabled
|
||||
|
||||
return enabled, nil
|
||||
u := binary.BigEndian.Uint16(b[2:]) & 0x0FFF
|
||||
return u != ablAmpsDisabled, nil
|
||||
}
|
||||
|
||||
// Enable implements the api.Charger interface
|
||||
func (wb *ABLeMH) Enable(enable bool) error {
|
||||
u := ablModeDisable
|
||||
u := ablAmpsDisabled
|
||||
if enable {
|
||||
u = ablModeEnable
|
||||
u = wb.curr
|
||||
}
|
||||
|
||||
b := make([]byte, 2)
|
||||
binary.BigEndian.PutUint16(b, u)
|
||||
|
||||
_, _ = wb.conn.WriteMultipleRegisters(ablRegMode, 1, b)
|
||||
_, err := wb.conn.WriteMultipleRegisters(ablRegMode, 1, b)
|
||||
_, _ = wb.conn.WriteMultipleRegisters(ablRegAmpsConfig, 1, b)
|
||||
_, err := wb.conn.WriteMultipleRegisters(ablRegAmpsConfig, 1, b)
|
||||
|
||||
return err
|
||||
}
|
||||
|
|
@ -180,10 +170,10 @@ var _ api.ChargerEx = (*ABLeMH)(nil)
|
|||
// MaxCurrent implements the api.ChargerEx interface
|
||||
func (wb *ABLeMH) MaxCurrentMillis(current float64) error {
|
||||
// calculate duty cycle according to https://www.goingelectric.de/forum/viewtopic.php?p=1575287#p1575287
|
||||
u := uint16(current / 0.06)
|
||||
wb.curr = uint16(current / 0.06)
|
||||
|
||||
b := make([]byte, 2)
|
||||
binary.BigEndian.PutUint16(b, u)
|
||||
binary.BigEndian.PutUint16(b, wb.curr)
|
||||
|
||||
_, _ = wb.conn.WriteMultipleRegisters(ablRegAmpsConfig, 1, b)
|
||||
_, err := wb.conn.WriteMultipleRegisters(ablRegAmpsConfig, 1, b)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue