feat(AveragePosition/GetNTRIPMountPoint): change return type, update cmd average_position
This commit is contained in:
parent
2c5d1442fe
commit
1fcf748310
@ -11,7 +11,7 @@ Utilitaire permettant de faire le scénario de paramétrage de la base automatiq
|
|||||||
## Utilisation
|
## Utilisation
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
go run ./cmd/average_position -host <HOST>
|
go run ./cmd/average_position -host <HOST> -baseAccuracy <fix|float|single>
|
||||||
```
|
```
|
||||||
|
|
||||||
Où:
|
Où:
|
||||||
|
@ -2,12 +2,10 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
|
||||||
|
|
||||||
reach "forge.cadoles.com/cadoles/go-emlid/reach/client"
|
reach "forge.cadoles.com/cadoles/go-emlid/reach/client"
|
||||||
"forge.cadoles.com/cadoles/go-emlid/reach/client/logger"
|
"forge.cadoles.com/cadoles/go-emlid/reach/client/logger"
|
||||||
@ -18,24 +16,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
host string = "192.168.42.1"
|
host string = "192.168.42.1"
|
||||||
rawLogLevel string = "ERROR"
|
rawLogLevel string = "ERROR"
|
||||||
|
baseAccuracy string = "fix"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
flag.StringVar(&rawLogLevel, "log-level", rawLogLevel, "log level")
|
flag.StringVar(&rawLogLevel, "log-level", rawLogLevel, "log level")
|
||||||
flag.StringVar(&host, "host", host, "the reachrs module host")
|
flag.StringVar(&host, "host", host, "the reachrs module host")
|
||||||
}
|
flag.StringVar(&baseAccuracy, "baseAccuracy", baseAccuracy, "precision required for average position")
|
||||||
|
|
||||||
type Coordinates struct {
|
|
||||||
Latitude float64 `json:"latitude"`
|
|
||||||
Longitude float64 `json:"longitude"`
|
|
||||||
Height float64 `json:"height"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Payload struct {
|
|
||||||
Coordinates Coordinates `json:"coordinates"`
|
|
||||||
AntennaOffset float64 `json:"antenna_offset"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -64,25 +53,17 @@ func main() {
|
|||||||
fmt.Printf("Configuration actuelle de la base :\n lat=%v\n lon=%v\n height=%v\n antenna_offset=%v\n accumulation=%v\n\n NTRIPSettings: \n address:%s\n port:%d \n username: %s\n password:%s\n sendPositionToBase:%t\n",
|
fmt.Printf("Configuration actuelle de la base :\n lat=%v\n lon=%v\n height=%v\n antenna_offset=%v\n accumulation=%v\n\n NTRIPSettings: \n address:%s\n port:%d \n username: %s\n password:%s\n sendPositionToBase:%t\n",
|
||||||
config.BaseMode.BaseCoordinates.Coordinates.Latitude, config.BaseMode.BaseCoordinates.Coordinates.Longitude, config.BaseMode.BaseCoordinates.Coordinates.Height, config.BaseMode.BaseCoordinates.AntennaOffset, config.BaseMode.BaseCoordinates.Accumulation, config.CorrectionInput.BaseCorrections.Settings.Ntripcli.Address, config.CorrectionInput.BaseCorrections.Settings.Ntripcli.Port, config.CorrectionInput.BaseCorrections.Settings.Ntripcli.Username, config.CorrectionInput.BaseCorrections.Settings.Ntripcli.Password, config.CorrectionInput.BaseCorrections.Settings.Ntripcli.SendPositionToBase)
|
config.BaseMode.BaseCoordinates.Coordinates.Latitude, config.BaseMode.BaseCoordinates.Coordinates.Longitude, config.BaseMode.BaseCoordinates.Coordinates.Height, config.BaseMode.BaseCoordinates.AntennaOffset, config.BaseMode.BaseCoordinates.Accumulation, config.CorrectionInput.BaseCorrections.Settings.Ntripcli.Address, config.CorrectionInput.BaseCorrections.Settings.Ntripcli.Port, config.CorrectionInput.BaseCorrections.Settings.Ntripcli.Username, config.CorrectionInput.BaseCorrections.Settings.Ntripcli.Password, config.CorrectionInput.BaseCorrections.Settings.Ntripcli.SendPositionToBase)
|
||||||
|
|
||||||
// Configuration des corrections NTRIP
|
//NTRIP Correction
|
||||||
if err := setupNTRIPCorrections(ctx, client, config); err != nil {
|
processNTRIPCorrection(ctx, client, config)
|
||||||
|
|
||||||
|
//Base configuration
|
||||||
|
if err := setBaseToModeAndHold(ctx, client, config, baseAccuracy, 30); err != nil {
|
||||||
fmt.Printf("[FATAL] %+v", err)
|
fmt.Printf("[FATAL] %+v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Configuration de la base
|
// AveragePosition
|
||||||
if err := setBaseToModeAndHold(ctx, client, config, "float", 30); err != nil {
|
processAveragePosition(ctx, client)
|
||||||
fmt.Printf("[FATAL] %+v", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collecte des données de positions
|
|
||||||
if err := averagePositionAndSave(ctx, client); err != nil {
|
|
||||||
fmt.Printf("[FATAL] %+v", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println("Configuration terminée avec succès")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func initializeClient(ctx context.Context) (*reach.Client, error) {
|
func initializeClient(ctx context.Context) (*reach.Client, error) {
|
||||||
@ -121,58 +102,32 @@ func retrieveAndProcessConfig(ctx context.Context, client *reach.Client) (*model
|
|||||||
return &config, nil
|
return &config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupNTRIPCorrections(ctx context.Context, client *reach.Client, config *model.Configuration) error {
|
func processNTRIPCorrection(ctx context.Context, client *reach.Client, config *model.Configuration) {
|
||||||
|
// Configuration des corrections NTRIP
|
||||||
|
ntripMsg, err := setupNTRIPCorrections(ctx, client)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("[FATAL] %+v", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
displayAvailableMountPoint(ntripMsg)
|
||||||
|
updateNTRIPMountPoint(ctx, client, config)
|
||||||
|
}
|
||||||
|
|
||||||
|
func setupNTRIPCorrections(ctx context.Context, client *reach.Client) (*protocol.TaskMessage[protocol.NTRIPPayload], error) {
|
||||||
fmt.Println("\nConfiguration des corrections NTRIP...")
|
fmt.Println("\nConfiguration des corrections NTRIP...")
|
||||||
|
|
||||||
// Recherche de points de montage
|
// Recherche de points de montage
|
||||||
if err := client.GetNTRIPMountPoint(ctx); err != nil {
|
ntripMsg, err := client.GetNTRIPMountPoint(ctx)
|
||||||
return errors.WithStack(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return processNTRIPStreams(ctx, client, config)
|
|
||||||
}
|
|
||||||
|
|
||||||
func processNTRIPStreams(ctx context.Context, client *reach.Client, config *model.Configuration) error {
|
|
||||||
messages, err := reach.OnMessageType(ctx, client, "task_status")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithStack(err)
|
return nil, errors.WithStack(err)
|
||||||
}
|
|
||||||
|
|
||||||
timeout := time.NewTimer(30 * time.Second)
|
|
||||||
defer timeout.Stop()
|
|
||||||
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case b := <-messages:
|
|
||||||
if b.State == "completed" {
|
|
||||||
return handleNTRIPResponse(ctx, client, config, b)
|
|
||||||
}
|
|
||||||
|
|
||||||
case <-timeout.C:
|
|
||||||
return errors.New("timeout lors de la récupération des streams NTRIP")
|
|
||||||
|
|
||||||
case <-ctx.Done():
|
|
||||||
return ctx.Err()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return ntripMsg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleNTRIPResponse(ctx context.Context, client *reach.Client, config *model.Configuration, message reach.Broadcast) error {
|
func displayAvailableMountPoint(response *protocol.TaskMessage[protocol.NTRIPPayload]) {
|
||||||
var response model.NTRIPResponse
|
|
||||||
if err := mapstructure.Decode(message, &response); err != nil {
|
|
||||||
return errors.WithStack(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
displayAvailableStreams(response)
|
|
||||||
|
|
||||||
return updateNTRIPMountPoint(ctx, client, config)
|
|
||||||
}
|
|
||||||
|
|
||||||
func displayAvailableStreams(response model.NTRIPResponse) {
|
|
||||||
streams := response.Payload.Str
|
streams := response.Payload.Str
|
||||||
fmt.Printf("=== %d Streams disponibles ===\n", len(streams))
|
fmt.Printf("=== %d Streams disponibles ===\n", len(streams))
|
||||||
fmt.Printf("=== Base < 50 km disponibles ===\n")
|
fmt.Printf("=== Base < 50 km disponibles ===\n")
|
||||||
|
|
||||||
for i, stream := range streams {
|
for i, stream := range streams {
|
||||||
if stream.Distance < 50 {
|
if stream.Distance < 50 {
|
||||||
fmt.Printf("%d. %-15s | %s (%s) | %.1fkm\n",
|
fmt.Printf("%d. %-15s | %s (%s) | %.1fkm\n",
|
||||||
@ -205,7 +160,8 @@ func updateNTRIPMountPoint(ctx context.Context, client *reach.Client, config *mo
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setBaseToModeAndHold(ctx context.Context, client *reach.Client, baseConfig *model.Configuration, mode string, accumulation int) error {
|
func setBaseToModeAndHold(ctx context.Context, client *reach.Client, baseConfig *model.Configuration, mode string, accumulation int) error {
|
||||||
fmt.Println("Configuration de la base en mode float-and-hold...")
|
fmt.Printf("Configuration de la base en mode %s-and-hold...\n", baseAccuracy)
|
||||||
|
|
||||||
opts := []protocol.SetBaseOptionFunc{
|
opts := []protocol.SetBaseOptionFunc{
|
||||||
protocol.WithBaseLatitude(baseConfig.BaseMode.BaseCoordinates.Coordinates.Latitude),
|
protocol.WithBaseLatitude(baseConfig.BaseMode.BaseCoordinates.Coordinates.Latitude),
|
||||||
protocol.WithBaseLongitude(baseConfig.BaseMode.BaseCoordinates.Coordinates.Longitude),
|
protocol.WithBaseLongitude(baseConfig.BaseMode.BaseCoordinates.Coordinates.Longitude),
|
||||||
@ -219,50 +175,46 @@ func setBaseToModeAndHold(ctx context.Context, client *reach.Client, baseConfig
|
|||||||
return errors.WithStack(err)
|
return errors.WithStack(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Base configurée en mode float-and-hold")
|
fmt.Printf("Base configurée en mode %s-and-hold\n", baseAccuracy)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func averagePositionAndSave(ctx context.Context, client *reach.Client) error {
|
func processAveragePosition(ctx context.Context, client *reach.Client) {
|
||||||
fmt.Println("Démarrage de la moyenne des position...")
|
// Collecte des données de positions
|
||||||
|
messageTask, err := averagePosition(ctx, client)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("[FATAL] %+v", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
displayAveragePositionMessage(messageTask)
|
||||||
|
saveAveragedPosition(ctx, client, messageTask)
|
||||||
|
|
||||||
|
fmt.Println("Configuration terminée avec succès")
|
||||||
|
}
|
||||||
|
|
||||||
|
func averagePosition(ctx context.Context, client *reach.Client) (*protocol.TaskMessage[protocol.AveragePositionPayload], error) {
|
||||||
|
fmt.Println("Démarrage de la moyenne des position...")
|
||||||
messageTask, err := client.AveragePosition(ctx)
|
messageTask, err := client.AveragePosition(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithStack(err)
|
return nil, errors.WithStack(err)
|
||||||
}
|
}
|
||||||
logTaskProgress(messageTask)
|
return messageTask, nil
|
||||||
return handleAverageCompletion(ctx, client, messageTask)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func logTaskProgress(message *protocol.TaskMessage) error {
|
func displayAveragePositionMessage(message *protocol.TaskMessage[protocol.AveragePositionPayload]) error {
|
||||||
data, err := json.MarshalIndent(message, "", " ")
|
|
||||||
if err != nil {
|
|
||||||
return errors.WithStack(err)
|
|
||||||
}
|
|
||||||
fmt.Println(string(data))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleAverageCompletion(ctx context.Context, client *reach.Client, message *protocol.TaskMessage) error {
|
|
||||||
var payload Payload
|
|
||||||
if err := mapstructure.Decode(message.Payload, &payload); err != nil {
|
|
||||||
return errors.WithStack(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
coords := payload.Coordinates
|
|
||||||
fmt.Printf("Position moyennée: lat=%g, lon=%g, altitude=%g\n",
|
fmt.Printf("Position moyennée: lat=%g, lon=%g, altitude=%g\n",
|
||||||
coords.Latitude, coords.Longitude, coords.Height)
|
message.Payload.Coordinates.Latitude, message.Payload.Coordinates.Longitude, message.Payload.Coordinates.Height)
|
||||||
|
return nil
|
||||||
|
|
||||||
return saveAveragedPosition(ctx, client, payload)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveAveragedPosition(ctx context.Context, client *reach.Client, payload Payload) error {
|
func saveAveragedPosition(ctx context.Context, client *reach.Client, message *protocol.TaskMessage[protocol.AveragePositionPayload]) error {
|
||||||
opts := []protocol.SetBaseOptionFunc{
|
opts := []protocol.SetBaseOptionFunc{
|
||||||
protocol.WithBaseLatitude(payload.Coordinates.Latitude),
|
protocol.WithBaseLatitude(message.Payload.Coordinates.Latitude),
|
||||||
protocol.WithBaseLongitude(payload.Coordinates.Longitude),
|
protocol.WithBaseLongitude(message.Payload.Coordinates.Longitude),
|
||||||
protocol.WithBaseHeight(payload.Coordinates.Height),
|
protocol.WithBaseHeight(message.Payload.Coordinates.Height),
|
||||||
protocol.WithBaseAntennaOffset(payload.AntennaOffset),
|
protocol.WithBaseAntennaOffset(message.Payload.AntennaOffset),
|
||||||
protocol.WithBaseMode("manual"),
|
protocol.WithBaseMode("manual"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ func (c *Client) Reboot(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AveragePosition implements protocol.Operations.
|
// AveragePosition implements protocol.Operations.
|
||||||
func (c *Client) AveragePosition(ctx context.Context) (*protocol.TaskMessage, error) {
|
func (c *Client) AveragePosition(ctx context.Context) (*protocol.TaskMessage[protocol.AveragePositionPayload], error) {
|
||||||
_, ops, err := c.getProtocol(ctx)
|
_, ops, err := c.getProtocol(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithStack(err)
|
return nil, errors.WithStack(err)
|
||||||
@ -168,17 +168,17 @@ func (c *Client) AveragePosition(ctx context.Context) (*protocol.TaskMessage, er
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetNTRIPMountPoint implements protocol.Operations.
|
// GetNTRIPMountPoint implements protocol.Operations.
|
||||||
func (c *Client) GetNTRIPMountPoint(ctx context.Context) error {
|
func (c *Client) GetNTRIPMountPoint(ctx context.Context) (*protocol.TaskMessage[protocol.NTRIPPayload], error) {
|
||||||
_, ops, err := c.getProtocol(ctx)
|
_, ops, err := c.getProtocol(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithStack(err)
|
return nil, errors.WithStack(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ops.GetNTRIPMountPoint(ctx); err != nil {
|
ntripMsg, err := ops.GetNTRIPMountPoint(ctx)
|
||||||
return errors.WithStack(err)
|
if err != nil {
|
||||||
|
return nil, errors.WithStack(err)
|
||||||
}
|
}
|
||||||
|
return ntripMsg, nil
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetBaseCorrections implements protocol.Operations.
|
// SetBaseCorrections implements protocol.Operations.
|
||||||
|
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 {
|
type IOConfig struct {
|
||||||
IOType string `json:"io_type"`
|
IOType string `json:"io_type"`
|
||||||
@ -18,12 +18,6 @@ type NTRIPCliConfig struct {
|
|||||||
SendPositionToBase bool `json:"send_position_to_base"`
|
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 {
|
type NTRIPPayload struct {
|
||||||
CAS []CasterInfo `json:"cas"`
|
CAS []CasterInfo `json:"cas"`
|
||||||
Net []NetworkInfo `json:"net"`
|
Net []NetworkInfo `json:"net"`
|
@ -12,10 +12,10 @@ type BaseInfo struct {
|
|||||||
Height float64
|
Height float64
|
||||||
Accumulation int
|
Accumulation int
|
||||||
}
|
}
|
||||||
type TaskMessage struct {
|
type TaskMessage[T any] struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
State string `json:"state"`
|
State string `json:"state"`
|
||||||
Payload map[string]interface{} `json:"payload"`
|
Payload T `json:"payload"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Operations interface {
|
type Operations interface {
|
||||||
@ -51,10 +51,10 @@ type Operations interface {
|
|||||||
Reboot(ctx context.Context) error
|
Reboot(ctx context.Context) error
|
||||||
|
|
||||||
// AveragePosition gathers data and computes the average position
|
// 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 retrieves availables mount point
|
||||||
GetNTRIPMountPoint(ctx context.Context) error
|
GetNTRIPMountPoint(ctx context.Context) (*TaskMessage[NTRIPPayload], error)
|
||||||
|
|
||||||
//SetBaseCorrections updates the corrections obtaining station
|
//SetBaseCorrections updates the corrections obtaining station
|
||||||
SetBaseCorrections(ctx context.Context, funcs ...SetBaseCorrectionsFunc) error
|
SetBaseCorrections(ctx context.Context, funcs ...SetBaseCorrectionsFunc) error
|
||||||
|
@ -237,31 +237,6 @@ var testCases = []operationTestCase{
|
|||||||
t.Errorf("%+v", errors.WithStack(err))
|
t.Errorf("%+v", errors.WithStack(err))
|
||||||
return
|
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) {
|
Run: func(t *testing.T, ops protocol.Operations) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
@ -371,29 +346,35 @@ var testCases = []operationTestCase{
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if err := ops.GetNTRIPMountPoint(ctx); err != nil {
|
taskmessage, err := ops.AveragePosition(ctx)
|
||||||
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 {
|
if err != nil {
|
||||||
t.Errorf("%+v", errors.WithStack(err))
|
t.Errorf("%+v", errors.WithStack(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
t.Logf("Task Message : %+v", taskmessage)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "GetNTRIPMountPoint",
|
||||||
|
Run: func(t *testing.T, ops protocol.Operations) {
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
count := 0
|
if err := ops.Connect(ctx); err != nil {
|
||||||
|
t.Errorf("%+v", errors.WithStack(err))
|
||||||
for m := range messages {
|
return
|
||||||
t.Logf("new message: %s", spew.Sdump(m))
|
|
||||||
count++
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if e, g := 1, count; g < e {
|
defer func() {
|
||||||
t.Errorf("expected total messages > %d, got %d", e, g)
|
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
|
// 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
|
return nil, protocol.ErrUnimplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated : is no longer maintained for modules in V1
|
// Deprecated : is no longer maintained for modules in V1
|
||||||
func (o *Operations) GetNTRIPMountPoint(ctx context.Context) error {
|
func (o *Operations) GetNTRIPMountPoint(ctx context.Context) (*protocol.TaskMessage[protocol.NTRIPPayload], error) {
|
||||||
return protocol.ErrUnimplemented
|
return nil, protocol.ErrUnimplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated : is no longer maintained for modules in V1
|
// Deprecated : is no longer maintained for modules in V1
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"forge.cadoles.com/cadoles/go-emlid/reach/client/protocol"
|
||||||
"forge.cadoles.com/cadoles/go-emlid/reach/client/protocol/v2/model"
|
"forge.cadoles.com/cadoles/go-emlid/reach/client/protocol/v2/model"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
@ -126,8 +127,8 @@ func (o *Operations) PostDevice(ctx context.Context, device *model.Configuration
|
|||||||
return &updated, nil
|
return &updated, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Operations) PostBaseCorrection(ctx context.Context, base *model.IOConfig) (*model.IOConfig, error) {
|
func (o *Operations) PostBaseCorrection(ctx context.Context, base *protocol.IOConfig) (*protocol.IOConfig, error) {
|
||||||
var updated model.IOConfig
|
var updated protocol.IOConfig
|
||||||
|
|
||||||
if err := o.PostJSON("/configuration/correction_input/base_corrections", base, &updated); err != nil {
|
if err := o.PostJSON("/configuration/correction_input/base_corrections", base, &updated); err != nil {
|
||||||
return nil, errors.WithStack(err)
|
return nil, errors.WithStack(err)
|
||||||
|
@ -2,7 +2,6 @@ package v2
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
"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/protocol/v2/model"
|
||||||
|
|
||||||
"forge.cadoles.com/cadoles/go-emlid/reach/client/socketio"
|
"forge.cadoles.com/cadoles/go-emlid/reach/client/socketio"
|
||||||
|
"github.com/mitchellh/mapstructure"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -270,7 +270,7 @@ func (o *Operations) On(ctx context.Context, event string) (chan any, error) {
|
|||||||
return out, nil
|
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
|
var err error
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
@ -283,15 +283,9 @@ func (o *Operations) AveragePosition(ctx context.Context) (*protocol.TaskMessage
|
|||||||
}
|
}
|
||||||
ch, err := o.On(ctx, "task_status")
|
ch, err := o.On(ctx, "task_status")
|
||||||
for message := range ch {
|
for message := range ch {
|
||||||
// Convertir vers notre struct
|
var taskMsg protocol.TaskMessage[protocol.AveragePositionPayload]
|
||||||
jsonData, err := json.Marshal(message)
|
if err := mapstructure.Decode(message, &taskMsg); err != nil {
|
||||||
if err != nil {
|
return nil, errors.WithStack(err)
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
var taskMsg protocol.TaskMessage
|
|
||||||
if err := json.Unmarshal(jsonData, &taskMsg); err != nil {
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if taskMsg.State == "completed" {
|
if taskMsg.State == "completed" {
|
||||||
@ -302,12 +296,12 @@ func (o *Operations) AveragePosition(ctx context.Context) (*protocol.TaskMessage
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetNTRIPMountPoint implements protocol.Operations.
|
// 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
|
var err error
|
||||||
|
|
||||||
config, err := o.GetConfiguration(ctx)
|
config, err := o.GetConfiguration(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithStack(err)
|
return nil, errors.WithStack(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
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 {
|
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.
|
// 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")
|
return errors.New("NTRIP mount point is required")
|
||||||
}
|
}
|
||||||
|
|
||||||
config := &model.IOConfig{
|
config := &protocol.IOConfig{
|
||||||
// todo parametrage du type
|
// todo parametrage du type
|
||||||
IOType: "ntripcli",
|
IOType: "ntripcli",
|
||||||
Settings: model.IOConfigSettings{
|
Settings: protocol.IOConfigSettings{
|
||||||
NTRIPCli: model.NTRIPCliConfig{
|
NTRIPCli: protocol.NTRIPCliConfig{
|
||||||
Address: *opts.Address,
|
Address: *opts.Address,
|
||||||
Port: *opts.Port,
|
Port: *opts.Port,
|
||||||
Username: *opts.Username,
|
Username: *opts.Username,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user