From 236ed2a57ccc62cf5ced9a2a4822b38b6b5c3073 Mon Sep 17 00:00:00 2001 From: Manuel Fuchs Date: Wed, 22 Jan 2025 14:32:22 +0100 Subject: [PATCH 1/4] OCPP: use cached status when no remote trigger is supported --- charger/ocpp/connector.go | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/charger/ocpp/connector.go b/charger/ocpp/connector.go index e0348123d5..3f24bb60b5 100644 --- a/charger/ocpp/connector.go +++ b/charger/ocpp/connector.go @@ -50,16 +50,16 @@ func NewConnector(log *util.Logger, id int, cp *CP, idTag string) (*Connector, e } // trigger status for all connectors - if cp.HasRemoteTriggerFeature { - var ok bool - // apply cached status if available - instance.WithConnectorStatus(cp.ID(), id, func(status *core.StatusNotificationRequest) { - if _, err := cp.OnStatusNotification(status); err == nil { - ok = true - } - }) + var ok bool + // apply cached status if available + instance.WithConnectorStatus(cp.ID(), id, func(status *core.StatusNotificationRequest) { + if _, err := cp.OnStatusNotification(status); err == nil { + ok = true + } + }) + if cp.HasRemoteTriggerFeature { // only trigger if we don't already have a status if !ok { if err := cp.TriggerMessageRequest(0, core.StatusNotificationFeatureName); err != nil { @@ -110,7 +110,9 @@ func (conn *Connector) WatchDog(timeout time.Duration) { conn.mu.Unlock() if update { - conn.TriggerMessageRequest(core.MeterValuesFeatureName) + if conn.cp.HasRemoteTriggerFeature { + conn.TriggerMessageRequest(core.MeterValuesFeatureName) + } } } } @@ -125,7 +127,9 @@ func (conn *Connector) Initialized() error { return nil case <-trigger: // try to trigger StatusNotification again as last resort - conn.TriggerMessageRequest(core.StatusNotificationFeatureName) + if conn.cp.HasRemoteTriggerFeature { + conn.TriggerMessageRequest(core.StatusNotificationFeatureName) + } case <-timeout: return api.ErrTimeout From 8adb8feb6e94775a046f23fc042ef2dcfae0c4fe Mon Sep 17 00:00:00 2001 From: Manuel Fuchs Date: Mon, 27 Jan 2025 15:33:43 +0100 Subject: [PATCH 2/4] fix panic --- charger/ocpp/cs.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/charger/ocpp/cs.go b/charger/ocpp/cs.go index 59ddd656fc..677e14ddf5 100644 --- a/charger/ocpp/cs.go +++ b/charger/ocpp/cs.go @@ -133,8 +133,7 @@ func (cs *CS) NewChargePoint(chargePoint ocpp16.ChargePointConnection) { // update id cp.RegisterID(chargePoint.ID()) - - cs.regs[chargePoint.ID()].cp = cp + cs.regs[chargePoint.ID()] = reg delete(cs.regs, "") cp.connect(true) From 67fe2696190b5890fb4213fc6b1b313002d679dc Mon Sep 17 00:00:00 2001 From: Manuel Fuchs Date: Mon, 27 Jan 2025 16:10:16 +0100 Subject: [PATCH 3/4] wip --- charger/ocpp/cs_core.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/charger/ocpp/cs_core.go b/charger/ocpp/cs_core.go index 9801280f42..71c509aeca 100644 --- a/charger/ocpp/cs_core.go +++ b/charger/ocpp/cs_core.go @@ -62,10 +62,6 @@ func (cs *CS) OnMeterValues(id string, request *core.MeterValuesRequest) (*core. } func (cs *CS) OnStatusNotification(id string, request *core.StatusNotificationRequest) (*core.StatusNotificationConfirmation, error) { - if cp, err := cs.ChargepointByID(id); err == nil { - return cp.OnStatusNotification(request) - } - cs.mu.Lock() defer cs.mu.Unlock() @@ -76,6 +72,10 @@ func (cs *CS) OnStatusNotification(id string, request *core.StatusNotificationRe reg.mu.Unlock() } + if cp, err := cs.ChargepointByID(id); err == nil { + return cp.OnStatusNotification(request) + } + return new(core.StatusNotificationConfirmation), nil } From 5c3fb4aaa797cf94bdabb6dfe43ab7781515172e Mon Sep 17 00:00:00 2001 From: Manuel Fuchs Date: Mon, 27 Jan 2025 20:32:41 +0100 Subject: [PATCH 4/4] fix mutex deadlock --- charger/ocpp/cs_core.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/charger/ocpp/cs_core.go b/charger/ocpp/cs_core.go index 71c509aeca..d56e7e325c 100644 --- a/charger/ocpp/cs_core.go +++ b/charger/ocpp/cs_core.go @@ -63,14 +63,13 @@ func (cs *CS) OnMeterValues(id string, request *core.MeterValuesRequest) (*core. func (cs *CS) OnStatusNotification(id string, request *core.StatusNotificationRequest) (*core.StatusNotificationConfirmation, error) { cs.mu.Lock() - defer cs.mu.Unlock() - // cache status for future cp connection if reg, ok := cs.regs[id]; ok && request != nil { reg.mu.Lock() reg.status[request.ConnectorId] = request reg.mu.Unlock() } + cs.mu.Unlock() if cp, err := cs.ChargepointByID(id); err == nil { return cp.OnStatusNotification(request)