wip
This commit is contained in:
@ -153,17 +153,18 @@ func (c *Client) Reboot(ctx context.Context) error {
|
||||
}
|
||||
|
||||
// AveragePosition implements protocol.Operations.
|
||||
func (c *Client) AveragePosition(ctx context.Context) error {
|
||||
func (c *Client) AveragePosition(ctx context.Context) (*protocol.TaskMessage, error) {
|
||||
_, ops, err := c.getProtocol(ctx)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
if err := ops.AveragePosition(ctx); err != nil {
|
||||
return errors.WithStack(err)
|
||||
taskMsg, err := ops.AveragePosition(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
return taskMsg, err
|
||||
}
|
||||
|
||||
// GetNTRIPMountPoint implements protocol.Operations.
|
||||
|
@ -1,6 +1,8 @@
|
||||
package protocol
|
||||
|
||||
import "context"
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type BaseInfo struct {
|
||||
Mode string
|
||||
@ -9,6 +11,11 @@ type BaseInfo struct {
|
||||
Longitude float64
|
||||
Height float64
|
||||
}
|
||||
type TaskMessage struct {
|
||||
Name string `json:"name"`
|
||||
State string `json:"state"`
|
||||
Payload map[string]interface{} `json:"payload"`
|
||||
}
|
||||
|
||||
type Operations interface {
|
||||
// Connect initiates a new connection to the ReachView service
|
||||
@ -43,7 +50,7 @@ type Operations interface {
|
||||
Reboot(ctx context.Context) error
|
||||
|
||||
// AveragePosition gathers data and computes the average position
|
||||
AveragePosition(ctx context.Context) error
|
||||
AveragePosition(ctx context.Context) (*TaskMessage, error)
|
||||
|
||||
//GetNTRIPMountPoint retrieves availables mount point
|
||||
GetNTRIPMountPoint(ctx context.Context) error
|
||||
|
@ -2,6 +2,7 @@ package testsuite
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
"math/rand"
|
||||
"os"
|
||||
@ -240,6 +241,105 @@ var testCases = []operationTestCase{
|
||||
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "SetBaseModeAveragePosition",
|
||||
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))
|
||||
}
|
||||
}()
|
||||
latitude := -90 + rand.Float64()*180
|
||||
longitude := -180 + rand.Float64()*360
|
||||
height := rand.Float64() * 1000
|
||||
antennaOffset := toFixed(rand.Float64()*2, 3)
|
||||
|
||||
opts := []protocol.SetBaseOptionFunc{
|
||||
protocol.WithBaseLatitude(latitude),
|
||||
protocol.WithBaseLongitude(longitude),
|
||||
protocol.WithBaseHeight(height),
|
||||
protocol.WithBaseAntennaOffset(antennaOffset),
|
||||
protocol.WithBaseMode(fmt.Sprintf("%s-and-hold", "fix")),
|
||||
}
|
||||
|
||||
if err := ops.SetBase(ctx, opts...); err != nil {
|
||||
t.Errorf("%+v", errors.WithStack(err))
|
||||
}
|
||||
|
||||
},
|
||||
},
|
||||
{
|
||||
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
|
||||
}
|
||||
fmt.Println(taskmessage)
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "GetNTRIPMountPoint",
|
||||
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))
|
||||
}
|
||||
}()
|
||||
|
||||
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")
|
||||
if err != nil {
|
||||
t.Errorf("%+v", errors.WithStack(err))
|
||||
return
|
||||
}
|
||||
|
||||
count := 0
|
||||
|
||||
for m := range messages {
|
||||
t.Logf("new message: %s", spew.Sdump(m))
|
||||
count++
|
||||
}
|
||||
|
||||
if e, g := 1, count; g < e {
|
||||
t.Errorf("expected total messages > %d, got %d", e, g)
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestOperations(t *testing.T, opsFactory OperationsFactoryFunc) {
|
||||
|
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)
|
||||
}
|
7
reach/client/protocol/v1/model/message.go
Normal file
7
reach/client/protocol/v1/model/message.go
Normal file
@ -0,0 +1,7 @@
|
||||
package model
|
||||
|
||||
type TaskMessage struct {
|
||||
Name string `json:"name"`
|
||||
State string `json:"state"`
|
||||
Payload map[string]interface{} `json:"payload"`
|
||||
}
|
@ -364,7 +364,7 @@ func (o *Operations) Version(ctx context.Context) (string, bool, error) {
|
||||
return strings.TrimSpace(res.Version), res.Stable, nil
|
||||
}
|
||||
|
||||
func (o *Operations) AveragePosition(ctx context.Context) error {
|
||||
func (o *Operations) AveragePosition(ctx context.Context) (*protocol.TaskMessage, error) {
|
||||
var err error
|
||||
|
||||
go func() {
|
||||
@ -373,10 +373,27 @@ func (o *Operations) AveragePosition(ctx context.Context) error {
|
||||
}()
|
||||
|
||||
if err = o.client.Emit("task", map[string]string{"name": "average_base_coordinates"}); err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
if taskMsg.State == "completed" {
|
||||
return &taskMsg, nil
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO À VOIR POUR LES VERSION 1
|
||||
|
@ -1,6 +1,6 @@
|
||||
package model
|
||||
|
||||
type Action struct {
|
||||
Name string `json:"name"`
|
||||
Paylaod map[string]interface{} `json:"payload"`
|
||||
Name string `json:"name"`
|
||||
Paylaod map[string]any `json:"payload"`
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package v2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
@ -264,7 +265,7 @@ func (o *Operations) On(ctx context.Context, event string) (chan any, error) {
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (o *Operations) AveragePosition(ctx context.Context) error {
|
||||
func (o *Operations) AveragePosition(ctx context.Context) (*protocol.TaskMessage, error) {
|
||||
var err error
|
||||
|
||||
go func() {
|
||||
@ -273,10 +274,26 @@ func (o *Operations) AveragePosition(ctx context.Context) error {
|
||||
}()
|
||||
|
||||
if err = o.client.Emit("task", &model.Action{Name: "average_base_coordinates"}); err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
ch, err := o.On(ctx, "task_status")
|
||||
for message := range ch {
|
||||
// Convertir vers notre struct
|
||||
jsonData, err := json.Marshal(message)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
return err
|
||||
var taskMsg protocol.TaskMessage
|
||||
if err := json.Unmarshal(jsonData, &taskMsg); err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if taskMsg.State == "completed" {
|
||||
return &taskMsg, nil
|
||||
}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// GetNTRIPMountPoint implements protocol.Operations.
|
||||
|
Reference in New Issue
Block a user