-
Notifications
You must be signed in to change notification settings - Fork 10
fix(ocpp): periodic dispatch, Lua allowlist, HTTP timeouts #1176
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "ftw": patch | ||
| --- | ||
|
|
||
| Route periodic EV dispatch through OCPP, keep Lua loadpoint names off the OCPP allowlist, and bound HTTP read/write/idle time. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/srcfl/ftw/go/internal/config" | ||
| "github.com/srcfl/ftw/go/internal/loadpoint" | ||
| "github.com/srcfl/ftw/go/internal/ocpp" | ||
| ) | ||
|
|
||
| // ocppApprovedIDs is the OCPP allowlist. Lua loadpoint names are not charge-point | ||
| // identities: anyone holding the shared basic-auth secret could otherwise connect | ||
| // as "easee" and steal DerEV plus commands. Adopted OCPP loadpoints (driver names | ||
| // that are not Lua drivers) and ids listed under ocpp.chargers stay approved. | ||
| func ocppApprovedIDs(cfg *config.Config) []string { | ||
| if cfg == nil { | ||
| return nil | ||
| } | ||
| lua := make(map[string]struct{}, len(cfg.Drivers)) | ||
| for _, d := range cfg.Drivers { | ||
| if d.Name != "" { | ||
| lua[d.Name] = struct{}{} | ||
| } | ||
| } | ||
| seen := make(map[string]struct{}) | ||
| var out []string | ||
| add := func(id string) { | ||
| if id == "" { | ||
| return | ||
| } | ||
| if _, ok := seen[id]; ok { | ||
| return | ||
| } | ||
| seen[id] = struct{}{} | ||
| out = append(out, id) | ||
| } | ||
| if cfg.OCPP != nil { | ||
| for _, c := range cfg.OCPP.Chargers { | ||
| add(c.ID) | ||
| } | ||
| } | ||
| for _, lp := range cfg.Loadpoints { | ||
| if _, isLua := lua[lp.DriverName]; isLua { | ||
| continue | ||
| } | ||
| add(lp.DriverName) | ||
| } | ||
| return out | ||
| } | ||
|
|
||
| // evCommandRouter sends EV commands to an online, adopted OCPP charger, or falls | ||
| // through to the Lua registry. Periodic dispatch uses SendWithOutcome / SendCycle; | ||
| // those must take the same route as the API's SenderFunc or planner ticks never | ||
| // reach a charger that has no Lua driver. | ||
| type evCommandRouter struct { | ||
| ocpp *ocpp.Server | ||
| send loadpoint.SenderFunc | ||
| sendOutcome loadpoint.OutcomeSenderFunc | ||
| sendCycle loadpoint.CycleSenderFunc | ||
| } | ||
|
|
||
| func newEVCommandRouter( | ||
| srv *ocpp.Server, | ||
| send loadpoint.SenderFunc, | ||
| sendOutcome loadpoint.OutcomeSenderFunc, | ||
| sendCycle loadpoint.CycleSenderFunc, | ||
| ) evCommandRouter { | ||
| return evCommandRouter{ocpp: srv, send: send, sendOutcome: sendOutcome, sendCycle: sendCycle} | ||
| } | ||
|
|
||
| func (r evCommandRouter) ocppRoute(name string) bool { | ||
| return r.ocpp != nil && r.ocpp.Handler().IsOnline(name) && r.ocpp.Handler().IsApproved(name) | ||
| } | ||
|
|
||
| func (r evCommandRouter) Send(ctx context.Context, name string, payload []byte) error { | ||
| if r.ocppRoute(name) { | ||
| return r.ocpp.Command(ctx, name, payload) | ||
| } | ||
| if r.send == nil { | ||
| return nil | ||
| } | ||
| return r.send(ctx, name, payload) | ||
| } | ||
|
|
||
| func (r evCommandRouter) SendWithOutcome(ctx context.Context, name string, payload []byte, outcome func(error)) error { | ||
| if r.ocppRoute(name) { | ||
| err := r.ocpp.Command(ctx, name, payload) | ||
| if outcome != nil { | ||
| outcome(err) | ||
| } | ||
| return err | ||
| } | ||
| if r.sendOutcome != nil { | ||
| return r.sendOutcome(ctx, name, payload, outcome) | ||
| } | ||
| err := r.Send(ctx, name, payload) | ||
| if outcome != nil { | ||
| outcome(err) | ||
| } | ||
| return err | ||
| } | ||
|
|
||
| func (r evCommandRouter) SendCycle(ctx context.Context, name string, payload []byte, cycleID uint64) error { | ||
| if r.ocppRoute(name) { | ||
| return r.ocpp.Command(ctx, name, payload) | ||
| } | ||
| if r.sendCycle != nil { | ||
| return r.sendCycle(ctx, name, payload, cycleID) | ||
| } | ||
| return r.Send(ctx, name, payload) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preserve the
cycleIDsequencing when routing OCPP pause/resume commands instead of callingocpp.Commanddirectly. If a wallbox cycle pauses and a subsequent tick sends 0 W during the three-second gap—particularly because the site meter became stale—the laterev_resumestill runs and restoresHandler.LastAmps; unlikeRegistry.SendEVContinuation, this path cannot detect that the intervening command superseded the cycle, so charging can restart after the safety standdown.AGENTS.md reference: AGENTS.md:L34-L35
Useful? React with 👍 / 👎.