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

Fix/ocpp initial status 3 #18468

Open
wants to merge 4 commits into
base: fix/ocpp-initial-status-3
Choose a base branch
from
Open
Show file tree
Hide file tree
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
24 changes: 14 additions & 10 deletions charger/ocpp/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}
}
}
Expand All @@ -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 {
andig marked this conversation as resolved.
Show resolved Hide resolved
conn.TriggerMessageRequest(core.StatusNotificationFeatureName)
}

case <-timeout:
return api.ErrTimeout
Expand Down
3 changes: 1 addition & 2 deletions charger/ocpp/cs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 5 additions & 6 deletions charger/ocpp/cs_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,18 @@ 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()

// 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)
}

return new(core.StatusNotificationConfirmation), nil
}
Expand Down
Loading