refactor: rename part to controller
This commit is contained in:
parent
ee02b09657
commit
5a386de4ab
@ -3,7 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"github.com/cyrilix/robocar-base/cli"
|
"github.com/cyrilix/robocar-base/cli"
|
||||||
"github.com/cyrilix/robocar-steering/pkg/part"
|
"github.com/cyrilix/robocar-steering/pkg/steering"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
@ -57,7 +57,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
defer client.Disconnect(50)
|
defer client.Disconnect(50)
|
||||||
|
|
||||||
p := part.NewPart(client, steeringTopic, driveModeTopic, rcSteeringTopic, tfSteeringTopic, debug)
|
p := steering.NewController(client, steeringTopic, driveModeTopic, rcSteeringTopic, tfSteeringTopic, debug)
|
||||||
defer p.Stop()
|
defer p.Stop()
|
||||||
|
|
||||||
cli.HandleExit(p)
|
cli.HandleExit(p)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package part
|
package steering
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/cyrilix/robocar-base/service"
|
"github.com/cyrilix/robocar-base/service"
|
||||||
@ -9,8 +9,8 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewPart(client mqtt.Client, steeringTopic, driveModeTopic, rcSteeringTopic, tfSteeringTopic string, debug bool) *SteeringPart {
|
func NewController(client mqtt.Client, steeringTopic, driveModeTopic, rcSteeringTopic, tfSteeringTopic string, debug bool) *SteeringController {
|
||||||
return &SteeringPart{
|
return &SteeringController{
|
||||||
client: client,
|
client: client,
|
||||||
steeringTopic: steeringTopic,
|
steeringTopic: steeringTopic,
|
||||||
driveModeTopic: driveModeTopic,
|
driveModeTopic: driveModeTopic,
|
||||||
@ -21,7 +21,7 @@ func NewPart(client mqtt.Client, steeringTopic, driveModeTopic, rcSteeringTopic,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type SteeringPart struct {
|
type SteeringController struct {
|
||||||
client mqtt.Client
|
client mqtt.Client
|
||||||
steeringTopic string
|
steeringTopic string
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ type SteeringPart struct {
|
|||||||
debug bool
|
debug bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *SteeringPart) Start() error {
|
func (p *SteeringController) 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 *SteeringPart) Start() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *SteeringPart) Stop() {
|
func (p *SteeringController) 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 *SteeringPart) onDriveMode(_ mqtt.Client, message mqtt.Message) {
|
func (p *SteeringController) 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 *SteeringPart) onDriveMode(_ mqtt.Client, message mqtt.Message) {
|
|||||||
p.driveMode = msg.GetDriveMode()
|
p.driveMode = msg.GetDriveMode()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *SteeringPart) onRCSteering(_ mqtt.Client, message mqtt.Message) {
|
func (p *SteeringController) 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 *SteeringPart) onRCSteering(_ mqtt.Client, message mqtt.Message) {
|
|||||||
publish(p.client, p.steeringTopic, &payload)
|
publish(p.client, p.steeringTopic, &payload)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func (p *SteeringPart) onTFSteering(_ mqtt.Client, message mqtt.Message) {
|
func (p *SteeringController) 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 *SteeringPart) onTFSteering(_ mqtt.Client, message mqtt.Message) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var registerCallbacks = func(p *SteeringPart) error {
|
var registerCallbacks = func(p *SteeringController) 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
|
@ -1,4 +1,4 @@
|
|||||||
package part
|
package steering
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/cyrilix/robocar-base/testtools"
|
"github.com/cyrilix/robocar-base/testtools"
|
||||||
@ -17,7 +17,7 @@ func TestDefaultSteering(t *testing.T) {
|
|||||||
registerCallbacks = oldRegister
|
registerCallbacks = oldRegister
|
||||||
publish = oldPublish
|
publish = oldPublish
|
||||||
}()
|
}()
|
||||||
registerCallbacks = func(p *SteeringPart) error {
|
registerCallbacks = func(p *SteeringController) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ func TestDefaultSteering(t *testing.T) {
|
|||||||
rcSteeringTopic := "topic/rcSteering"
|
rcSteeringTopic := "topic/rcSteering"
|
||||||
tfSteeringTopic := "topic/tfSteering"
|
tfSteeringTopic := "topic/tfSteering"
|
||||||
|
|
||||||
p := NewPart(nil, steeringTopic, driveModeTopic, rcSteeringTopic, tfSteeringTopic, true)
|
p := NewController(nil, steeringTopic, driveModeTopic, rcSteeringTopic, tfSteeringTopic, true)
|
||||||
|
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
driveMode events.DriveModeMessage
|
driveMode events.DriveModeMessage
|
Loading…
Reference in New Issue
Block a user