Update robocar-base dependencies

This commit is contained in:
2019-12-27 16:51:39 +01:00
parent a4c228ed94
commit 1f5f36a9cf
10 changed files with 101 additions and 47 deletions

View File

@ -1,8 +1,9 @@
package mqttdevice
import (
"encoding/json"
"fmt"
"github.com/cyrilix/robocar-base/mode"
"github.com/cyrilix/robocar-base/types"
MQTT "github.com/eclipse/paho.mqtt.golang"
"io"
"log"
@ -107,8 +108,12 @@ func NewMqttValue(v interface{}) MqttValue {
case MqttValue:
return val
default:
log.Printf("invalid mqtt value: %v", val)
return nil
jsonValue, err := json.Marshal(v)
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) {
return string(*m), nil
}
func (m *MqttValue) DriveModeValue() (mode.DriveMode, error) {
func (m *MqttValue) DriveModeValue() (types.DriveMode, error) {
val, err := m.IntValue()
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) {
return *m, nil