feat(AveragePosition/GetNTRIPMountPoint): change return type, update cmd average_position
This commit is contained in:
12
reach/client/protocol/average_postion.go
Normal file
12
reach/client/protocol/average_postion.go
Normal file
@ -0,0 +1,12 @@
|
||||
package protocol
|
||||
|
||||
type Coordinates struct {
|
||||
Latitude float64 `json:"latitude"`
|
||||
Longitude float64 `json:"longitude"`
|
||||
Height float64 `json:"height"`
|
||||
}
|
||||
|
||||
type AveragePositionPayload struct {
|
||||
Coordinates Coordinates `json:"coordinates"`
|
||||
AntennaOffset float64 `json:"antenna_offset"`
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package model
|
||||
package protocol
|
||||
|
||||
type IOConfig struct {
|
||||
IOType string `json:"io_type"`
|
||||
@ -18,12 +18,6 @@ type NTRIPCliConfig struct {
|
||||
SendPositionToBase bool `json:"send_position_to_base"`
|
||||
}
|
||||
|
||||
type NTRIPResponse struct {
|
||||
Name string `json:"name"`
|
||||
Payload NTRIPPayload `json:"payload"`
|
||||
State string `json:"state"`
|
||||
}
|
||||
|
||||
type NTRIPPayload struct {
|
||||
CAS []CasterInfo `json:"cas"`
|
||||
Net []NetworkInfo `json:"net"`
|
@ -12,10 +12,10 @@ type BaseInfo struct {
|
||||
Height float64
|
||||
Accumulation int
|
||||
}
|
||||
type TaskMessage struct {
|
||||
Name string `json:"name"`
|
||||
State string `json:"state"`
|
||||
Payload map[string]interface{} `json:"payload"`
|
||||
type TaskMessage[T any] struct {
|
||||
Name string `json:"name"`
|
||||
State string `json:"state"`
|
||||
Payload T `json:"payload"`
|
||||
}
|
||||
|
||||
type Operations interface {
|
||||
@ -51,10 +51,10 @@ type Operations interface {
|
||||
Reboot(ctx context.Context) error
|
||||
|
||||
// AveragePosition gathers data and computes the average position
|
||||
AveragePosition(ctx context.Context) (*TaskMessage, error)
|
||||
AveragePosition(ctx context.Context) (*TaskMessage[AveragePositionPayload], error)
|
||||
|
||||
//GetNTRIPMountPoint retrieves availables mount point
|
||||
GetNTRIPMountPoint(ctx context.Context) error
|
||||
GetNTRIPMountPoint(ctx context.Context) (*TaskMessage[NTRIPPayload], error)
|
||||
|
||||
//SetBaseCorrections updates the corrections obtaining station
|
||||
SetBaseCorrections(ctx context.Context, funcs ...SetBaseCorrectionsFunc) error
|
||||
|
@ -237,31 +237,6 @@ var testCases = []operationTestCase{
|
||||
t.Errorf("%+v", errors.WithStack(err))
|
||||
return
|
||||
}
|
||||
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "AveragePosition",
|
||||
Run: func(t *testing.T, ops protocol.Operations) {
|
||||
ctx := context.Background()
|
||||
|
||||
if err := ops.Connect(ctx); err != nil {
|
||||
t.Errorf("%+v", errors.WithStack(err))
|
||||
return
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err := ops.Close(ctx); err != nil {
|
||||
t.Errorf("%+v", errors.WithStack(err))
|
||||
}
|
||||
}()
|
||||
|
||||
taskmessage, err := ops.AveragePosition(ctx)
|
||||
if err != nil {
|
||||
t.Errorf("%+v", errors.WithStack(err))
|
||||
return
|
||||
}
|
||||
t.Logf("Task Message : %s", taskmessage)
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -356,7 +331,7 @@ var testCases = []operationTestCase{
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "GetNTRIPMountPoint",
|
||||
Name: "AveragePosition",
|
||||
Run: func(t *testing.T, ops protocol.Operations) {
|
||||
ctx := context.Background()
|
||||
|
||||
@ -371,29 +346,35 @@ var testCases = []operationTestCase{
|
||||
}
|
||||
}()
|
||||
|
||||
if err := ops.GetNTRIPMountPoint(ctx); err != nil {
|
||||
t.Errorf("%+v", errors.WithStack(err))
|
||||
return
|
||||
}
|
||||
broadcastCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
messages, err := ops.On(broadcastCtx, "task_status")
|
||||
taskmessage, err := ops.AveragePosition(ctx)
|
||||
if err != nil {
|
||||
t.Errorf("%+v", errors.WithStack(err))
|
||||
return
|
||||
}
|
||||
t.Logf("Task Message : %+v", taskmessage)
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "GetNTRIPMountPoint",
|
||||
Run: func(t *testing.T, ops protocol.Operations) {
|
||||
ctx := context.Background()
|
||||
|
||||
count := 0
|
||||
|
||||
for m := range messages {
|
||||
t.Logf("new message: %s", spew.Sdump(m))
|
||||
count++
|
||||
if err := ops.Connect(ctx); err != nil {
|
||||
t.Errorf("%+v", errors.WithStack(err))
|
||||
return
|
||||
}
|
||||
|
||||
if e, g := 1, count; g < e {
|
||||
t.Errorf("expected total messages > %d, got %d", e, g)
|
||||
defer func() {
|
||||
if err := ops.Close(ctx); err != nil {
|
||||
t.Errorf("%+v", errors.WithStack(err))
|
||||
}
|
||||
}()
|
||||
taskMsg, err := ops.GetNTRIPMountPoint(ctx)
|
||||
if err != nil {
|
||||
t.Errorf("%+v", errors.WithStack(err))
|
||||
return
|
||||
}
|
||||
t.Logf("Message : %+v", taskMsg)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
16
reach/client/protocol/testsuite/operations_test.go
Normal file
16
reach/client/protocol/testsuite/operations_test.go
Normal file
@ -0,0 +1,16 @@
|
||||
package testsuite
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"forge.cadoles.com/cadoles/go-emlid/reach/client"
|
||||
"forge.cadoles.com/cadoles/go-emlid/reach/client/protocol"
|
||||
)
|
||||
|
||||
func TestReachOperations(t *testing.T) {
|
||||
opsFactory := func(addr string) (protocol.Operations, error) {
|
||||
return client.NewClient(addr), nil
|
||||
}
|
||||
|
||||
TestOperations(t, opsFactory)
|
||||
}
|
@ -376,13 +376,13 @@ func (o *Operations) Version(ctx context.Context) (string, bool, error) {
|
||||
}
|
||||
|
||||
// Deprecated : is no longer maintained for modules in V1
|
||||
func (o *Operations) AveragePosition(ctx context.Context) (*protocol.TaskMessage, error) {
|
||||
func (o *Operations) AveragePosition(ctx context.Context) (*protocol.TaskMessage[protocol.AveragePositionPayload], error) {
|
||||
return nil, protocol.ErrUnimplemented
|
||||
}
|
||||
|
||||
// Deprecated : is no longer maintained for modules in V1
|
||||
func (o *Operations) GetNTRIPMountPoint(ctx context.Context) error {
|
||||
return protocol.ErrUnimplemented
|
||||
func (o *Operations) GetNTRIPMountPoint(ctx context.Context) (*protocol.TaskMessage[protocol.NTRIPPayload], error) {
|
||||
return nil, protocol.ErrUnimplemented
|
||||
}
|
||||
|
||||
// Deprecated : is no longer maintained for modules in V1
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"forge.cadoles.com/cadoles/go-emlid/reach/client/protocol"
|
||||
"forge.cadoles.com/cadoles/go-emlid/reach/client/protocol/v2/model"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
@ -126,8 +127,8 @@ func (o *Operations) PostDevice(ctx context.Context, device *model.Configuration
|
||||
return &updated, nil
|
||||
}
|
||||
|
||||
func (o *Operations) PostBaseCorrection(ctx context.Context, base *model.IOConfig) (*model.IOConfig, error) {
|
||||
var updated model.IOConfig
|
||||
func (o *Operations) PostBaseCorrection(ctx context.Context, base *protocol.IOConfig) (*protocol.IOConfig, error) {
|
||||
var updated protocol.IOConfig
|
||||
|
||||
if err := o.PostJSON("/configuration/correction_input/base_corrections", base, &updated); err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
|
@ -2,7 +2,6 @@ package v2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
@ -11,6 +10,7 @@ import (
|
||||
"forge.cadoles.com/cadoles/go-emlid/reach/client/protocol/v2/model"
|
||||
|
||||
"forge.cadoles.com/cadoles/go-emlid/reach/client/socketio"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@ -270,7 +270,7 @@ func (o *Operations) On(ctx context.Context, event string) (chan any, error) {
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (o *Operations) AveragePosition(ctx context.Context) (*protocol.TaskMessage, error) {
|
||||
func (o *Operations) AveragePosition(ctx context.Context) (*protocol.TaskMessage[protocol.AveragePositionPayload], error) {
|
||||
var err error
|
||||
|
||||
go func() {
|
||||
@ -283,15 +283,9 @@ func (o *Operations) AveragePosition(ctx context.Context) (*protocol.TaskMessage
|
||||
}
|
||||
ch, err := o.On(ctx, "task_status")
|
||||
for message := range ch {
|
||||
// Convertir vers notre struct
|
||||
jsonData, err := json.Marshal(message)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
var taskMsg protocol.TaskMessage
|
||||
if err := json.Unmarshal(jsonData, &taskMsg); err != nil {
|
||||
continue
|
||||
var taskMsg protocol.TaskMessage[protocol.AveragePositionPayload]
|
||||
if err := mapstructure.Decode(message, &taskMsg); err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
if taskMsg.State == "completed" {
|
||||
@ -302,12 +296,12 @@ func (o *Operations) AveragePosition(ctx context.Context) (*protocol.TaskMessage
|
||||
}
|
||||
|
||||
// GetNTRIPMountPoint implements protocol.Operations.
|
||||
func (o *Operations) GetNTRIPMountPoint(ctx context.Context) error {
|
||||
func (o *Operations) GetNTRIPMountPoint(ctx context.Context) (*protocol.TaskMessage[protocol.NTRIPPayload], error) {
|
||||
var err error
|
||||
|
||||
config, err := o.GetConfiguration(ctx)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
go func() {
|
||||
@ -321,10 +315,21 @@ func (o *Operations) GetNTRIPMountPoint(ctx context.Context) error {
|
||||
}
|
||||
|
||||
if err = o.client.Emit("task", &model.Action{Name: "get_ntrip_mountpoints", Paylaod: payload}); err != nil {
|
||||
return err
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return err
|
||||
ch, err := o.On(ctx, "task_status")
|
||||
for message := range ch {
|
||||
var taskMsg protocol.TaskMessage[protocol.NTRIPPayload]
|
||||
if err := mapstructure.Decode(message, &taskMsg); err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
if taskMsg.State == "completed" {
|
||||
return &taskMsg, nil
|
||||
}
|
||||
}
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
// SetBaseCorrections implements protocol.Operations.
|
||||
@ -346,11 +351,11 @@ func (o *Operations) SetBaseCorrections(ctx context.Context, funcs ...protocol.S
|
||||
return errors.New("NTRIP mount point is required")
|
||||
}
|
||||
|
||||
config := &model.IOConfig{
|
||||
config := &protocol.IOConfig{
|
||||
// todo parametrage du type
|
||||
IOType: "ntripcli",
|
||||
Settings: model.IOConfigSettings{
|
||||
NTRIPCli: model.NTRIPCliConfig{
|
||||
Settings: protocol.IOConfigSettings{
|
||||
NTRIPCli: protocol.NTRIPCliConfig{
|
||||
Address: *opts.Address,
|
||||
Port: *opts.Port,
|
||||
Username: *opts.Username,
|
||||
|
Reference in New Issue
Block a user