-
Notifications
You must be signed in to change notification settings - Fork 159
Provide a method that can handle messages #362
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
base: master
Are you sure you want to change the base?
Conversation
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.
Thanks for the PR. I can accept it after the feedback was implemented as well.
ocppj/server.go
Outdated
@@ -41,7 +43,7 @@ type InvalidMessageHook func(client ws.Channel, err *ocpp.Error, rawJson string, | |||
// s := ocppj.NewServer(ws.NewServer(), nil, nil) | |||
// | |||
// The dispatcher's associated ClientState will be set during initialization. | |||
func NewServer(wsServer ws.Server, dispatcher ServerDispatcher, stateHandler ServerState, profiles ...*ocpp.Profile) *Server { | |||
func NewServer(wsServer ws.Server, dispatcher ServerDispatcher, stateHandler ServerState, msgHooks MessageHooks, profiles ...*ocpp.Profile) *Server { |
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.
This is a breaking change and several custom implementations may be affected. I believe the added SetMessageHooks
setter is good enough, so we don't have to also include it as a parameter in the constructor
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.
OK,have been modified。
example/1.6/cs/central_system_sim.go
Outdated
@@ -231,6 +232,10 @@ func main() { | |||
log.WithField("client", chargePoint.ID()).Info("charge point disconnected") | |||
delete(handler.chargePoints, chargePoint.ID()) | |||
}) | |||
// set message hook | |||
centralSystem.SetMessageHooks(func(direction, chargePointID, msgType string, payload []byte) { | |||
fmt.Printf("direction:%s \n cpid:%s \n msgType: %s \n payload: %s\n", direction, chargePointID, msgType, string(payload)) |
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.
chore: this should invoke the logger instead of fmt.Printf
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.
OK,have been modified。
2.It was modified to include it as a parameter in unnecessary constructors as well
@@ -66,7 +66,7 @@ func NewServer(wsServer ws.Server, dispatcher ServerDispatcher, stateHandler Ser | |||
for _, profile := range profiles { | |||
s.AddProfile(profile) | |||
} | |||
s.MessageHooks = msgHooks | |||
//s.MessageHooks = msgHooks |
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.
This can be removed entirely
|
||
// SetMessageHooks sets the hooks for logging incoming and outgoing messages. | ||
func (cs *centralSystem) SetMessageHooks(message func(direction, clientId, messageType string, payload []byte)) { | ||
cs.server.SetMessageHooks(message) |
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.
Maybe a nil check would be nice to prevent crashing in case someone decides to pass in a nil function
Proposed changes
Provide a message processing method. Databases or message forwarding, etc. can be used。
Types of changes
What types of changes does your code introduce?
Put an
x
in the boxes that applyChecklist
Put an
x
in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any ofthem, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before
merging your code.
Further comments
We want to record the messages of OCPP through a database such as mongodb. Or forward some instruction messages such as MeterValues and StatusNotification to the mobile terminal for display.