refactor: remove redounded naming
This commit is contained in:
parent
5a386de4ab
commit
4be2f5e6e2
@ -9,8 +9,8 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewController(client mqtt.Client, steeringTopic, driveModeTopic, rcSteeringTopic, tfSteeringTopic string, debug bool) *SteeringController {
|
func NewController(client mqtt.Client, steeringTopic, driveModeTopic, rcSteeringTopic, tfSteeringTopic string, debug bool) *Controller {
|
||||||
return &SteeringController{
|
return &Controller{
|
||||||
client: client,
|
client: client,
|
||||||
steeringTopic: steeringTopic,
|
steeringTopic: steeringTopic,
|
||||||
driveModeTopic: driveModeTopic,
|
driveModeTopic: driveModeTopic,
|
||||||
@ -21,7 +21,7 @@ func NewController(client mqtt.Client, steeringTopic, driveModeTopic, rcSteering
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type SteeringController struct {
|
type Controller struct {
|
||||||
client mqtt.Client
|
client mqtt.Client
|
||||||
steeringTopic string
|
steeringTopic string
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ type SteeringController struct {
|
|||||||
debug bool
|
debug bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *SteeringController) Start() error {
|
func (p *Controller) Start() error {
|
||||||
if err := registerCallbacks(p); err != nil {
|
if err := registerCallbacks(p); err != nil {
|
||||||
zap.S().Errorf("unable to rgeister callbacks: %v", err)
|
zap.S().Errorf("unable to rgeister callbacks: %v", err)
|
||||||
return err
|
return err
|
||||||
@ -45,12 +45,12 @@ func (p *SteeringController) Start() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *SteeringController) Stop() {
|
func (p *Controller) Stop() {
|
||||||
close(p.cancel)
|
close(p.cancel)
|
||||||
service.StopService("throttle", p.client, p.driveModeTopic, p.rcSteeringTopic, p.tfSteeringTopic)
|
service.StopService("throttle", p.client, p.driveModeTopic, p.rcSteeringTopic, p.tfSteeringTopic)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *SteeringController) onDriveMode(_ mqtt.Client, message mqtt.Message) {
|
func (p *Controller) onDriveMode(_ mqtt.Client, message mqtt.Message) {
|
||||||
var msg events.DriveModeMessage
|
var msg events.DriveModeMessage
|
||||||
err := proto.Unmarshal(message.Payload(), &msg)
|
err := proto.Unmarshal(message.Payload(), &msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -63,7 +63,7 @@ func (p *SteeringController) onDriveMode(_ mqtt.Client, message mqtt.Message) {
|
|||||||
p.driveMode = msg.GetDriveMode()
|
p.driveMode = msg.GetDriveMode()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *SteeringController) onRCSteering(_ mqtt.Client, message mqtt.Message) {
|
func (p *Controller) onRCSteering(_ mqtt.Client, message mqtt.Message) {
|
||||||
p.muDriveMode.RLock()
|
p.muDriveMode.RLock()
|
||||||
defer p.muDriveMode.RUnlock()
|
defer p.muDriveMode.RUnlock()
|
||||||
if p.debug {
|
if p.debug {
|
||||||
@ -81,7 +81,7 @@ func (p *SteeringController) onRCSteering(_ mqtt.Client, message mqtt.Message) {
|
|||||||
publish(p.client, p.steeringTopic, &payload)
|
publish(p.client, p.steeringTopic, &payload)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func (p *SteeringController) onTFSteering(_ mqtt.Client, message mqtt.Message) {
|
func (p *Controller) onTFSteering(_ mqtt.Client, message mqtt.Message) {
|
||||||
p.muDriveMode.RLock()
|
p.muDriveMode.RLock()
|
||||||
defer p.muDriveMode.RUnlock()
|
defer p.muDriveMode.RUnlock()
|
||||||
if p.debug {
|
if p.debug {
|
||||||
@ -100,7 +100,7 @@ func (p *SteeringController) onTFSteering(_ mqtt.Client, message mqtt.Message) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var registerCallbacks = func(p *SteeringController) error {
|
var registerCallbacks = func(p *Controller) error {
|
||||||
err := service.RegisterCallback(p.client, p.driveModeTopic, p.onDriveMode)
|
err := service.RegisterCallback(p.client, p.driveModeTopic, p.onDriveMode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -17,7 +17,7 @@ func TestDefaultSteering(t *testing.T) {
|
|||||||
registerCallbacks = oldRegister
|
registerCallbacks = oldRegister
|
||||||
publish = oldPublish
|
publish = oldPublish
|
||||||
}()
|
}()
|
||||||
registerCallbacks = func(p *SteeringController) error {
|
registerCallbacks = func(p *Controller) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,7 +104,7 @@ func TestDefaultSteering(t *testing.T) {
|
|||||||
|
|
||||||
if msg.GetSteering() != c.expectedSteering.GetSteering() {
|
if msg.GetSteering() != c.expectedSteering.GetSteering() {
|
||||||
t.Errorf("bad msg value for mode %v: %v, wants %v",
|
t.Errorf("bad msg value for mode %v: %v, wants %v",
|
||||||
c.driveMode, msg.GetSteering(), c.expectedSteering.GetSteering())
|
c.driveMode.String(), msg.GetSteering(), c.expectedSteering.GetSteering())
|
||||||
}
|
}
|
||||||
if msg.GetConfidence() != 1. {
|
if msg.GetConfidence() != 1. {
|
||||||
t.Errorf("bad throtlle confidence: %v, wants %v", msg.GetConfidence(), 1.)
|
t.Errorf("bad throtlle confidence: %v, wants %v", msg.GetConfidence(), 1.)
|
||||||
|
Loading…
Reference in New Issue
Block a user