Update robocar-base dependencies
This commit is contained in:
parent
a4c228ed94
commit
1f5f36a9cf
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module github.com/cyrilix/robocar-led
|
|||||||
go 1.13
|
go 1.13
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/cyrilix/robocar-base v0.0.0-20191218200846-a0dedb056b1a
|
github.com/cyrilix/robocar-base v0.0.0-20191227154304-47d48c39b0a2
|
||||||
github.com/eclipse/paho.mqtt.golang v1.2.0
|
github.com/eclipse/paho.mqtt.golang v1.2.0
|
||||||
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 // indirect
|
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 // indirect
|
||||||
periph.io/x/periph v3.6.2+incompatible
|
periph.io/x/periph v3.6.2+incompatible
|
||||||
|
4
go.sum
4
go.sum
@ -12,6 +12,10 @@ github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc h1:TP+534wVl
|
|||||||
github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
|
github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
|
||||||
github.com/cyrilix/robocar-base v0.0.0-20191218200846-a0dedb056b1a h1:SGF8hqFYFNqebPn+F7xFx8riwGgVEGOADhmlEAhoNEQ=
|
github.com/cyrilix/robocar-base v0.0.0-20191218200846-a0dedb056b1a h1:SGF8hqFYFNqebPn+F7xFx8riwGgVEGOADhmlEAhoNEQ=
|
||||||
github.com/cyrilix/robocar-base v0.0.0-20191218200846-a0dedb056b1a/go.mod h1:/KZidG8Y4sKxCCkTcswpKz20oFN3j62tJvamEHcSgLM=
|
github.com/cyrilix/robocar-base v0.0.0-20191218200846-a0dedb056b1a/go.mod h1:/KZidG8Y4sKxCCkTcswpKz20oFN3j62tJvamEHcSgLM=
|
||||||
|
github.com/cyrilix/robocar-base v0.0.0-20191227142243-e35d6f13814e h1:g7pMRmVOpaP71VcXE7JNQCjGp6/Wx3GKUASX8hhO4+Q=
|
||||||
|
github.com/cyrilix/robocar-base v0.0.0-20191227142243-e35d6f13814e/go.mod h1:/KZidG8Y4sKxCCkTcswpKz20oFN3j62tJvamEHcSgLM=
|
||||||
|
github.com/cyrilix/robocar-base v0.0.0-20191227154304-47d48c39b0a2 h1:7E0P2+YXKtRM++vnBZtaNVlhKEMkp+X3qYdd0CzseJY=
|
||||||
|
github.com/cyrilix/robocar-base v0.0.0-20191227154304-47d48c39b0a2/go.mod h1:/KZidG8Y4sKxCCkTcswpKz20oFN3j62tJvamEHcSgLM=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/docker/distribution v2.7.1-0.20190205005809-0d3efadf0154+incompatible h1:dvc1KSkIYTVjZgHf/CTC2diTYC8PzhaA5sFISRfNVrE=
|
github.com/docker/distribution v2.7.1-0.20190205005809-0d3efadf0154+incompatible h1:dvc1KSkIYTVjZgHf/CTC2diTYC8PzhaA5sFISRfNVrE=
|
||||||
|
36
part/part.go
36
part/part.go
@ -2,8 +2,9 @@ package part
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/cyrilix/robocar-base/mode"
|
|
||||||
"github.com/cyrilix/robocar-base/mqttdevice"
|
"github.com/cyrilix/robocar-base/mqttdevice"
|
||||||
|
"github.com/cyrilix/robocar-base/service"
|
||||||
|
"github.com/cyrilix/robocar-base/types"
|
||||||
"github.com/cyrilix/robocar-led/led"
|
"github.com/cyrilix/robocar-led/led"
|
||||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||||
"log"
|
"log"
|
||||||
@ -18,7 +19,7 @@ func NewPart(client mqtt.Client, driveModeTopic, recordTopic string) *LedPart {
|
|||||||
onDriveModeTopic: driveModeTopic,
|
onDriveModeTopic: driveModeTopic,
|
||||||
onRecordTopic: recordTopic,
|
onRecordTopic: recordTopic,
|
||||||
muDriveMode: sync.Mutex{},
|
muDriveMode: sync.Mutex{},
|
||||||
m: mode.DriveModeInvalid,
|
m: types.DriveModeInvalid,
|
||||||
muRecord: sync.Mutex{},
|
muRecord: sync.Mutex{},
|
||||||
recordEnabled: false,
|
recordEnabled: false,
|
||||||
}
|
}
|
||||||
@ -32,7 +33,7 @@ type LedPart struct {
|
|||||||
onRecordTopic string
|
onRecordTopic string
|
||||||
|
|
||||||
muDriveMode sync.Mutex
|
muDriveMode sync.Mutex
|
||||||
m mode.DriveMode
|
m types.DriveMode
|
||||||
muRecord sync.Mutex
|
muRecord sync.Mutex
|
||||||
recordEnabled bool
|
recordEnabled bool
|
||||||
}
|
}
|
||||||
@ -51,7 +52,7 @@ func (p *LedPart) Stop() {
|
|||||||
defer p.led.SetGreen(0)
|
defer p.led.SetGreen(0)
|
||||||
defer p.led.SetBlue(0)
|
defer p.led.SetBlue(0)
|
||||||
defer p.led.SetRed(0)
|
defer p.led.SetRed(0)
|
||||||
StopService("led", p.client, p.onDriveModeTopic, p.onRecordTopic)
|
service.StopService("led", p.client, p.onDriveModeTopic, p.onRecordTopic)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *LedPart) onDriveMode(_ mqtt.Client, message mqtt.Message) {
|
func (p *LedPart) onDriveMode(_ mqtt.Client, message mqtt.Message) {
|
||||||
@ -63,11 +64,11 @@ func (p *LedPart) onDriveMode(_ mqtt.Client, message mqtt.Message) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch m {
|
switch m {
|
||||||
case mode.DriveModeUser:
|
case types.DriveModeUser:
|
||||||
p.led.SetRed(0)
|
p.led.SetRed(0)
|
||||||
p.led.SetGreen(255)
|
p.led.SetGreen(255)
|
||||||
p.led.SetBlue(0)
|
p.led.SetBlue(0)
|
||||||
case mode.DriveModePilot:
|
case types.DriveModePilot:
|
||||||
p.led.SetRed(0)
|
p.led.SetRed(0)
|
||||||
p.led.SetGreen(0)
|
p.led.SetGreen(0)
|
||||||
p.led.SetBlue(255)
|
p.led.SetBlue(255)
|
||||||
@ -89,34 +90,15 @@ func (p *LedPart) onRecord(client mqtt.Client, message mqtt.Message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *LedPart) registerCallbacks() error {
|
func (p *LedPart) registerCallbacks() error {
|
||||||
err := RegisterCallback(p.client, p.onDriveModeTopic, p.onDriveMode)
|
err := service.RegisterCallback(p.client, p.onDriveModeTopic, p.onDriveMode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = RegisterCallback(p.client, p.onRecordTopic, p.onRecord)
|
err = service.RegisterCallback(p.client, p.onRecordTopic, p.onRecord)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func StopService(name string, client mqtt.Client, topics ...string) {
|
|
||||||
log.Printf("Stop %s service", name)
|
|
||||||
token := client.Unsubscribe(topics...)
|
|
||||||
token.Wait()
|
|
||||||
if token.Error() != nil {
|
|
||||||
log.Printf("unable to unsubscribe service: %v", token.Error())
|
|
||||||
}
|
|
||||||
client.Disconnect(50)
|
|
||||||
}
|
|
||||||
|
|
||||||
func RegisterCallback(client mqtt.Client, topic string, callback mqtt.MessageHandler) error {
|
|
||||||
log.Printf("Register callback on topic %v", topic)
|
|
||||||
token := client.Subscribe(topic, 0, callback)
|
|
||||||
token.Wait()
|
|
||||||
if token.Error() != nil {
|
|
||||||
return fmt.Errorf("unable to register callback on topic %s: %v", topic, token.Error())
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package part
|
package part
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/cyrilix/robocar-base/mode"
|
|
||||||
"github.com/cyrilix/robocar-base/mqttdevice"
|
"github.com/cyrilix/robocar-base/mqttdevice"
|
||||||
"github.com/cyrilix/robocar-base/testtools"
|
"github.com/cyrilix/robocar-base/testtools"
|
||||||
|
"github.com/cyrilix/robocar-base/types"
|
||||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -42,9 +42,9 @@ func TestLedPart_OnDriveMode(t *testing.T) {
|
|||||||
msg mqtt.Message
|
msg mqtt.Message
|
||||||
red, green, blue int
|
red, green, blue int
|
||||||
}{
|
}{
|
||||||
{testtools.NewFakeMessage("drive", mqttdevice.NewMqttValue(mode.DriveModeUser)), 0, 255, 0},
|
{testtools.NewFakeMessage("drive", mqttdevice.NewMqttValue(types.DriveModeUser)), 0, 255, 0},
|
||||||
{testtools.NewFakeMessage("drive", mqttdevice.NewMqttValue(mode.DriveModePilot)), 0, 0, 255},
|
{testtools.NewFakeMessage("drive", mqttdevice.NewMqttValue(types.DriveModePilot)), 0, 0, 255},
|
||||||
{testtools.NewFakeMessage("drive", mqttdevice.NewMqttValue(mode.DriveModeInvalid)), 0, 0, 255},
|
{testtools.NewFakeMessage("drive", mqttdevice.NewMqttValue(types.DriveModeInvalid)), 0, 0, 255},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
|
30
vendor/github.com/cyrilix/robocar-base/cli/cli.go
generated
vendored
30
vendor/github.com/cyrilix/robocar-base/cli/cli.go
generated
vendored
@ -3,6 +3,7 @@ package cli
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/cyrilix/robocar-base/service"
|
||||||
MQTT "github.com/eclipse/paho.mqtt.golang"
|
MQTT "github.com/eclipse/paho.mqtt.golang"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
@ -33,13 +34,23 @@ func SetIntDefaultValueFromEnv(value *int, key string, defaultValue int) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
func SetFloat64DefaultValueFromEnv(value *float64, key string, defaultValue float64) error {
|
||||||
type Part interface {
|
var sVal string
|
||||||
Start() error
|
if os.Getenv(key) != "" {
|
||||||
Stop()
|
sVal = os.Getenv(key)
|
||||||
|
val, err := strconv.ParseFloat(sVal, 64)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("unable to convert string to float: %v", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*value = val
|
||||||
|
} else {
|
||||||
|
*value = defaultValue
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func HandleExit(p Part) {
|
func HandleExit(p service.Part) {
|
||||||
signals := make(chan os.Signal, 1)
|
signals := make(chan os.Signal, 1)
|
||||||
signal.Notify(signals, os.Kill, os.Interrupt, syscall.SIGTERM)
|
signal.Notify(signals, os.Kill, os.Interrupt, syscall.SIGTERM)
|
||||||
|
|
||||||
@ -71,6 +82,15 @@ func InitIntFlag(key string, defValue int) int {
|
|||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func InitFloat64Flag(key string, defValue float64) float64 {
|
||||||
|
var value float64
|
||||||
|
err := SetFloat64DefaultValueFromEnv(&value, key, defValue)
|
||||||
|
if err != nil {
|
||||||
|
log.Panicf("invalid value: %v", err)
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
func Connect(uri, username, password, clientId string) (MQTT.Client, error) {
|
func Connect(uri, username, password, clientId string) (MQTT.Client, error) {
|
||||||
//create a ClientOptions struct setting the broker address, clientid, turn
|
//create a ClientOptions struct setting the broker address, clientid, turn
|
||||||
//off trace output and set the default message handler
|
//off trace output and set the default message handler
|
||||||
|
17
vendor/github.com/cyrilix/robocar-base/mqttdevice/mqttdevice.go
generated
vendored
17
vendor/github.com/cyrilix/robocar-base/mqttdevice/mqttdevice.go
generated
vendored
@ -1,8 +1,9 @@
|
|||||||
package mqttdevice
|
package mqttdevice
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/cyrilix/robocar-base/mode"
|
"github.com/cyrilix/robocar-base/types"
|
||||||
MQTT "github.com/eclipse/paho.mqtt.golang"
|
MQTT "github.com/eclipse/paho.mqtt.golang"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
@ -107,8 +108,12 @@ func NewMqttValue(v interface{}) MqttValue {
|
|||||||
case MqttValue:
|
case MqttValue:
|
||||||
return val
|
return val
|
||||||
default:
|
default:
|
||||||
log.Printf("invalid mqtt value: %v", val)
|
jsonValue, err := json.Marshal(v)
|
||||||
return nil
|
if err != nil {
|
||||||
|
log.Printf("unable to mashall to json value '%v': %v", v, err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return jsonValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,12 +133,12 @@ func (m *MqttValue) Float64Value() (float64, error) {
|
|||||||
func (m *MqttValue) StringValue() (string, error) {
|
func (m *MqttValue) StringValue() (string, error) {
|
||||||
return string(*m), nil
|
return string(*m), nil
|
||||||
}
|
}
|
||||||
func (m *MqttValue) DriveModeValue() (mode.DriveMode, error) {
|
func (m *MqttValue) DriveModeValue() (types.DriveMode, error) {
|
||||||
val, err := m.IntValue()
|
val, err := m.IntValue()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return mode.DriveModeInvalid, err
|
return types.DriveModeInvalid, err
|
||||||
}
|
}
|
||||||
return mode.DriveMode(val), nil
|
return types.DriveMode(val), nil
|
||||||
}
|
}
|
||||||
func (m *MqttValue) ByteSliceValue() ([]byte, error) {
|
func (m *MqttValue) ByteSliceValue() ([]byte, error) {
|
||||||
return *m, nil
|
return *m, nil
|
||||||
|
33
vendor/github.com/cyrilix/robocar-base/service/part.go
generated
vendored
Normal file
33
vendor/github.com/cyrilix/robocar-base/service/part.go
generated
vendored
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func StopService(name string, client mqtt.Client, topics ...string) {
|
||||||
|
log.Printf("Stop %s service", name)
|
||||||
|
token := client.Unsubscribe(topics...)
|
||||||
|
token.Wait()
|
||||||
|
if token.Error() != nil {
|
||||||
|
log.Printf("unable to unsubscribe service: %v", token.Error())
|
||||||
|
}
|
||||||
|
client.Disconnect(50)
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterCallback(client mqtt.Client, topic string, callback mqtt.MessageHandler) error {
|
||||||
|
log.Printf("Register callback on topic %v", topic)
|
||||||
|
token := client.Subscribe(topic, 0, callback)
|
||||||
|
token.Wait()
|
||||||
|
if token.Error() != nil {
|
||||||
|
return fmt.Errorf("unable to register callback on topic %s: %v", topic, token.Error())
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type Part interface {
|
||||||
|
Start() error
|
||||||
|
Stop()
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package mode
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
@ -32,6 +32,5 @@ func ParseString(val string) DriveMode {
|
|||||||
default:
|
default:
|
||||||
log.Printf("invalid DriveMode: %v", val)
|
log.Printf("invalid DriveMode: %v", val)
|
||||||
return DriveModeInvalid
|
return DriveModeInvalid
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
10
vendor/github.com/cyrilix/robocar-base/types/rc.go
generated
vendored
Normal file
10
vendor/github.com/cyrilix/robocar-base/types/rc.go
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
/* Radio control value */
|
||||||
|
type RCValue struct {
|
||||||
|
Value float64
|
||||||
|
Confidence float64
|
||||||
|
}
|
||||||
|
|
||||||
|
type Steering RCValue
|
||||||
|
type Throttle RCValue
|
5
vendor/modules.txt
vendored
5
vendor/modules.txt
vendored
@ -1,8 +1,9 @@
|
|||||||
# github.com/cyrilix/robocar-base v0.0.0-20191218200846-a0dedb056b1a
|
# github.com/cyrilix/robocar-base v0.0.0-20191227154304-47d48c39b0a2
|
||||||
github.com/cyrilix/robocar-base/cli
|
github.com/cyrilix/robocar-base/cli
|
||||||
github.com/cyrilix/robocar-base/mode
|
|
||||||
github.com/cyrilix/robocar-base/mqttdevice
|
github.com/cyrilix/robocar-base/mqttdevice
|
||||||
|
github.com/cyrilix/robocar-base/service
|
||||||
github.com/cyrilix/robocar-base/testtools
|
github.com/cyrilix/robocar-base/testtools
|
||||||
|
github.com/cyrilix/robocar-base/types
|
||||||
# github.com/eclipse/paho.mqtt.golang v1.2.0
|
# github.com/eclipse/paho.mqtt.golang v1.2.0
|
||||||
github.com/eclipse/paho.mqtt.golang
|
github.com/eclipse/paho.mqtt.golang
|
||||||
github.com/eclipse/paho.mqtt.golang/packets
|
github.com/eclipse/paho.mqtt.golang/packets
|
||||||
|
Loading…
Reference in New Issue
Block a user