Upgrade robocar dependency
This commit is contained in:
parent
b3de5ca724
commit
3b228216fa
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module github.com/cyrilix/robocar-pca9685
|
|||||||
go 1.13
|
go 1.13
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/cyrilix/robocar-base v0.0.0-20191227154304-47d48c39b0a2
|
github.com/cyrilix/robocar-base v0.0.0-20191229155957-683a9d53e6b8
|
||||||
github.com/eclipse/paho.mqtt.golang v1.2.0
|
github.com/eclipse/paho.mqtt.golang v1.2.0
|
||||||
periph.io/x/periph v3.6.2+incompatible
|
periph.io/x/periph v3.6.2+incompatible
|
||||||
)
|
)
|
||||||
|
4
go.sum
4
go.sum
@ -10,8 +10,8 @@ github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QH
|
|||||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||||
github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc h1:TP+534wVlf61smEIq1nwLLAjQVEK2EADoW3CX9AuT+8=
|
github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc h1:TP+534wVlf61smEIq1nwLLAjQVEK2EADoW3CX9AuT+8=
|
||||||
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-20191227154304-47d48c39b0a2 h1:7E0P2+YXKtRM++vnBZtaNVlhKEMkp+X3qYdd0CzseJY=
|
github.com/cyrilix/robocar-base v0.0.0-20191229155957-683a9d53e6b8 h1:/UQf7jFGW3G3EgysANvJVjQofbHly8/VSoEwGc2xDVI=
|
||||||
github.com/cyrilix/robocar-base v0.0.0-20191227154304-47d48c39b0a2/go.mod h1:/KZidG8Y4sKxCCkTcswpKz20oFN3j62tJvamEHcSgLM=
|
github.com/cyrilix/robocar-base v0.0.0-20191229155957-683a9d53e6b8/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=
|
||||||
|
BIN
rc-pca9685
Executable file
BIN
rc-pca9685
Executable file
Binary file not shown.
156
vendor/github.com/cyrilix/robocar-base/mqttdevice/mqttdevice.go
generated
vendored
156
vendor/github.com/cyrilix/robocar-base/mqttdevice/mqttdevice.go
generated
vendored
@ -1,156 +0,0 @@
|
|||||||
package mqttdevice
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"github.com/cyrilix/robocar-base/types"
|
|
||||||
MQTT "github.com/eclipse/paho.mqtt.golang"
|
|
||||||
"io"
|
|
||||||
"log"
|
|
||||||
"strconv"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Publisher interface {
|
|
||||||
Publish(topic string, payload MqttValue)
|
|
||||||
}
|
|
||||||
|
|
||||||
type Subscriber interface {
|
|
||||||
Subscribe(topic string, mh MQTT.MessageHandler)
|
|
||||||
}
|
|
||||||
|
|
||||||
type MQTTPubSub interface {
|
|
||||||
Publisher
|
|
||||||
Subscriber
|
|
||||||
io.Closer
|
|
||||||
}
|
|
||||||
|
|
||||||
type pahoMqttPubSub struct {
|
|
||||||
Uri string
|
|
||||||
Username string
|
|
||||||
Password string
|
|
||||||
ClientId string
|
|
||||||
Qos int
|
|
||||||
Retain bool
|
|
||||||
client MQTT.Client
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewPahoMqttPubSub(uri string, username string, password string, clientId string, qos int, retain bool) MQTTPubSub {
|
|
||||||
p := pahoMqttPubSub{Uri: uri, Username: username, Password: password, ClientId: clientId, Qos: qos, Retain: retain}
|
|
||||||
p.Connect()
|
|
||||||
return &p
|
|
||||||
}
|
|
||||||
|
|
||||||
// Publish message to broker
|
|
||||||
func (p *pahoMqttPubSub) Publish(topic string, payload MqttValue) {
|
|
||||||
tokenResp := p.client.Publish(topic, byte(p.Qos), p.Retain, string(payload))
|
|
||||||
if tokenResp.Error() != nil {
|
|
||||||
log.Fatalf("%+v\n", tokenResp.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register func to execute on message
|
|
||||||
func (p *pahoMqttPubSub) Subscribe(topic string, callback MQTT.MessageHandler) {
|
|
||||||
tokenResp := p.client.Subscribe(topic, byte(p.Qos), callback)
|
|
||||||
if tokenResp.Error() != nil {
|
|
||||||
log.Fatalf("%+v\n", tokenResp.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close connection to broker
|
|
||||||
func (p *pahoMqttPubSub) Close() error {
|
|
||||||
p.client.Disconnect(500)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *pahoMqttPubSub) Connect() {
|
|
||||||
if p.client != nil && p.client.IsConnected() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
//create a ClientOptions struct setting the broker address, clientid, turn
|
|
||||||
//off trace output and set the default message handler
|
|
||||||
opts := MQTT.NewClientOptions().AddBroker(p.Uri)
|
|
||||||
opts.SetUsername(p.Username)
|
|
||||||
opts.SetPassword(p.Password)
|
|
||||||
opts.SetClientID(p.ClientId)
|
|
||||||
opts.SetAutoReconnect(true)
|
|
||||||
opts.SetDefaultPublishHandler(
|
|
||||||
//define a function for the default message handler
|
|
||||||
func(client MQTT.Client, msg MQTT.Message) {
|
|
||||||
fmt.Printf("TOPIC: %s\n", msg.Topic())
|
|
||||||
fmt.Printf("MSG: %s\n", msg.Payload())
|
|
||||||
})
|
|
||||||
|
|
||||||
//create and start a client using the above ClientOptions
|
|
||||||
p.client = MQTT.NewClient(opts)
|
|
||||||
if token := p.client.Connect(); token.Wait() && token.Error() != nil {
|
|
||||||
panic(token.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type MqttValue []byte
|
|
||||||
|
|
||||||
func NewMqttValue(v interface{}) MqttValue {
|
|
||||||
switch val := v.(type) {
|
|
||||||
case string:
|
|
||||||
return MqttValue(val)
|
|
||||||
case float32, float64:
|
|
||||||
return MqttValue(fmt.Sprintf("%0.2f", val))
|
|
||||||
case int, int8, int16, int32, int64:
|
|
||||||
return MqttValue(fmt.Sprintf("%d", val))
|
|
||||||
case bool:
|
|
||||||
if val {
|
|
||||||
return []byte("ON")
|
|
||||||
} else {
|
|
||||||
return []byte("OFF")
|
|
||||||
}
|
|
||||||
case []byte:
|
|
||||||
return val
|
|
||||||
case MqttValue:
|
|
||||||
return val
|
|
||||||
default:
|
|
||||||
jsonValue, err := json.Marshal(v)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("unable to mashall to json value '%v': %v", v, err)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return jsonValue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *MqttValue) IntValue() (int, error) {
|
|
||||||
return strconv.Atoi(string(*m))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *MqttValue) Float32Value() (float32, error) {
|
|
||||||
val := string(*m)
|
|
||||||
r, err := strconv.ParseFloat(val, 32)
|
|
||||||
return float32(r), err
|
|
||||||
}
|
|
||||||
func (m *MqttValue) Float64Value() (float64, error) {
|
|
||||||
val := string(*m)
|
|
||||||
return strconv.ParseFloat(val, 64)
|
|
||||||
}
|
|
||||||
func (m *MqttValue) StringValue() (string, error) {
|
|
||||||
return string(*m), nil
|
|
||||||
}
|
|
||||||
func (m *MqttValue) DriveModeValue() (types.DriveMode, error) {
|
|
||||||
val, err := m.IntValue()
|
|
||||||
if err != nil {
|
|
||||||
return types.DriveModeInvalid, err
|
|
||||||
}
|
|
||||||
return types.DriveMode(val), nil
|
|
||||||
}
|
|
||||||
func (m *MqttValue) ByteSliceValue() ([]byte, error) {
|
|
||||||
return *m, nil
|
|
||||||
}
|
|
||||||
func (m *MqttValue) BoolValue() (bool, error) {
|
|
||||||
val := string(*m)
|
|
||||||
switch val {
|
|
||||||
case "ON":
|
|
||||||
return true, nil
|
|
||||||
case "OFF":
|
|
||||||
return false, nil
|
|
||||||
default:
|
|
||||||
return false, fmt.Errorf("value %v can't be converted to bool", val)
|
|
||||||
}
|
|
||||||
}
|
|
5
vendor/github.com/cyrilix/robocar-base/types/types.go
generated
vendored
Normal file
5
vendor/github.com/cyrilix/robocar-base/types/types.go
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type BoundingBox struct {
|
||||||
|
Left, Top, Right, Bottom int
|
||||||
|
}
|
3
vendor/modules.txt
vendored
3
vendor/modules.txt
vendored
@ -1,6 +1,5 @@
|
|||||||
# github.com/cyrilix/robocar-base v0.0.0-20191227154304-47d48c39b0a2
|
# github.com/cyrilix/robocar-base v0.0.0-20191229155957-683a9d53e6b8
|
||||||
github.com/cyrilix/robocar-base/cli
|
github.com/cyrilix/robocar-base/cli
|
||||||
github.com/cyrilix/robocar-base/mqttdevice
|
|
||||||
github.com/cyrilix/robocar-base/service
|
github.com/cyrilix/robocar-base/service
|
||||||
github.com/cyrilix/robocar-base/types
|
github.com/cyrilix/robocar-base/types
|
||||||
# github.com/eclipse/paho.mqtt.golang v1.2.0
|
# github.com/eclipse/paho.mqtt.golang v1.2.0
|
||||||
|
Loading…
Reference in New Issue
Block a user