From 8b79fc58c073df2d2dbf95f545043ff2a1b0a5c6 Mon Sep 17 00:00:00 2001 From: Cyrille Nofficial Date: Fri, 5 Nov 2021 19:48:26 +0100 Subject: [PATCH] debug: unmarshal msg when debug is enabled --- cmd/rc-steering/rc-steering.go | 2 +- pkg/part/part.go | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/cmd/rc-steering/rc-steering.go b/cmd/rc-steering/rc-steering.go index bf7d002..7c6cbb0 100644 --- a/cmd/rc-steering/rc-steering.go +++ b/cmd/rc-steering/rc-steering.go @@ -59,7 +59,7 @@ func main() { } defer client.Disconnect(50) - p := part.NewPart(client, steeringTopic, driveModeTopic, rcSteeringTopic, tfSteeringTopic) + p := part.NewPart(client, steeringTopic, driveModeTopic, rcSteeringTopic, tfSteeringTopic, debug) defer p.Stop() cli.HandleExit(p) diff --git a/pkg/part/part.go b/pkg/part/part.go index 8eb478f..0bbbe20 100644 --- a/pkg/part/part.go +++ b/pkg/part/part.go @@ -9,7 +9,7 @@ import ( "sync" ) -func NewPart(client mqtt.Client, steeringTopic, driveModeTopic, rcSteeringTopic, tfSteeringTopic string) *SteeringPart { +func NewPart(client mqtt.Client, steeringTopic, driveModeTopic, rcSteeringTopic, tfSteeringTopic string, debug bool) *SteeringPart { return &SteeringPart{ client: client, steeringTopic: steeringTopic, @@ -17,6 +17,7 @@ func NewPart(client mqtt.Client, steeringTopic, driveModeTopic, rcSteeringTopic, rcSteeringTopic: rcSteeringTopic, tfSteeringTopic: tfSteeringTopic, driveMode: events.DriveMode_USER, + debug: debug, } } @@ -30,6 +31,8 @@ type SteeringPart struct { cancel chan interface{} driveModeTopic, rcSteeringTopic, tfSteeringTopic string + + debug bool } func (p *SteeringPart) Start() error { @@ -64,7 +67,15 @@ func (p *SteeringPart) onDriveMode(_ mqtt.Client, message mqtt.Message) { func (p *SteeringPart) onRCSteering(_ mqtt.Client, message mqtt.Message) { p.muDriveMode.RLock() defer p.muDriveMode.RUnlock() - zap.S().Debugf("receive steering message from radio command: %v",message) + if p.debug { + var evt events.SteeringMessage + err := proto.Unmarshal(message.Payload(), &evt) + if err != nil { + zap.S().Debugf("unable to unmarshal rc event: %v", err) + }else { + zap.S().Debugf("receive steering message from radio command: %0.00f", evt.GetSteering()) + } + } if p.driveMode == events.DriveMode_USER { // Republish same content payload := message.Payload() @@ -74,7 +85,15 @@ func (p *SteeringPart) onRCSteering(_ mqtt.Client, message mqtt.Message) { func (p *SteeringPart) onTFSteering(_ mqtt.Client, message mqtt.Message) { p.muDriveMode.RLock() defer p.muDriveMode.RUnlock() - zap.S().Debugf("receive steering message from tensorflow: %v",message) + if p.debug { + var evt events.SteeringMessage + err := proto.Unmarshal(message.Payload(), &evt) + if err != nil { + zap.S().Debugf("unable to unmarshal tensorflow event: %v", err) + }else { + zap.S().Debugf("receive steering message from tensorflow: %0.00f", evt.GetSteering()) + } + } if p.driveMode == events.DriveMode_PILOT { // Republish same content payload := message.Payload()