fix: protocol v1
This commit is contained in:
@ -6,6 +6,7 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"forge.cadoles.com/cadoles/go-emlid/reach/client/logger"
|
||||
"forge.cadoles.com/cadoles/go-emlid/reach/client/protocol"
|
||||
"forge.cadoles.com/cadoles/go-emlid/reach/client/protocol/v1/model"
|
||||
"forge.cadoles.com/cadoles/go-emlid/reach/client/socketio"
|
||||
@ -16,6 +17,7 @@ type Operations struct {
|
||||
addr string
|
||||
client *socketio.Client
|
||||
mutex sync.RWMutex
|
||||
logger logger.Logger
|
||||
}
|
||||
|
||||
// Close implements protocol.Operations.
|
||||
@ -54,6 +56,8 @@ func (o *Operations) Connect(ctx context.Context) error {
|
||||
|
||||
client := socketio.NewClient(endpoint)
|
||||
|
||||
o.logger.Debug("connecting", logger.Attr("endpoint", endpoint))
|
||||
|
||||
if err := client.Connect(); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
@ -67,6 +71,8 @@ func (o *Operations) Connect(ctx context.Context) error {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
o.logger.Debug("connected")
|
||||
|
||||
o.client = client
|
||||
|
||||
return nil
|
||||
@ -206,29 +212,58 @@ const (
|
||||
|
||||
// SetBase implements protocol.Operations.
|
||||
func (o *Operations) SetBase(ctx context.Context, funcs ...protocol.SetBaseOptionFunc) error {
|
||||
rawConfig, err := o.Configuration(ctx)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
config := rawConfig.(*model.Configuration)
|
||||
baseMode := config.BaseMode
|
||||
|
||||
var baseCoordinates *model.BaseCoordinates
|
||||
if baseMode != nil && baseMode.BaseCoordinates != nil {
|
||||
baseCoordinates = baseMode.BaseCoordinates
|
||||
}
|
||||
|
||||
opts := protocol.NewSetBaseOptions(funcs...)
|
||||
|
||||
var lat string
|
||||
if opts.Latitude != nil {
|
||||
lat = strconv.FormatFloat(*opts.Latitude, 'f', -1, 64)
|
||||
} else if baseCoordinates != nil && baseCoordinates.Coordinates != nil && len(baseCoordinates.Coordinates) > 1 {
|
||||
lat = *baseCoordinates.Coordinates[0]
|
||||
} else {
|
||||
lat = "0"
|
||||
}
|
||||
|
||||
var lon string
|
||||
if opts.Longitude != nil {
|
||||
lon = strconv.FormatFloat(*opts.Longitude, 'f', -1, 64)
|
||||
} else if baseCoordinates != nil && baseCoordinates.Coordinates != nil && len(baseCoordinates.Coordinates) > 1 {
|
||||
lon = *baseCoordinates.Coordinates[1]
|
||||
} else {
|
||||
lon = "0"
|
||||
}
|
||||
|
||||
var alt string
|
||||
if opts.Height != nil {
|
||||
alt = strconv.FormatFloat(*opts.Height, 'f', -1, 64)
|
||||
} else if baseCoordinates != nil && baseCoordinates.Coordinates != nil && len(baseCoordinates.Coordinates) > 1 {
|
||||
alt = *baseCoordinates.Coordinates[2]
|
||||
} else {
|
||||
alt = "0"
|
||||
}
|
||||
|
||||
var antennaHeight string
|
||||
if opts.AntennaOffset != nil {
|
||||
antennaHeight = strconv.FormatFloat(*opts.AntennaOffset, 'f', -1, 64)
|
||||
} else if baseCoordinates != nil && baseCoordinates.AntennaOffset != nil && baseCoordinates.AntennaOffset.Up != nil {
|
||||
antennaHeight = *baseCoordinates.AntennaOffset.Up
|
||||
} else {
|
||||
antennaHeight = "0"
|
||||
}
|
||||
|
||||
config := &model.Configuration{
|
||||
newConfig := &model.Configuration{
|
||||
BaseMode: &model.BaseMode{
|
||||
BaseCoordinates: &model.BaseCoordinates{
|
||||
Accumulation: model.String("1"),
|
||||
@ -248,7 +283,7 @@ func (o *Operations) SetBase(ctx context.Context, funcs ...protocol.SetBaseOptio
|
||||
},
|
||||
}
|
||||
|
||||
result, _, err := o.ApplyConfiguration(ctx, config)
|
||||
result, _, err := o.ApplyConfiguration(ctx, newConfig)
|
||||
if err != nil {
|
||||
return errors.New("configuration update failed")
|
||||
}
|
||||
|
Reference in New Issue
Block a user