Compare commits

..

2 Commits

Author SHA1 Message Date
38a1d5a2c6 wip 2025-05-27 12:05:43 +02:00
9cbf5b1cde wip 2025-05-26 14:32:43 +02:00
21 changed files with 241 additions and 621 deletions

View File

@ -1,21 +0,0 @@
# `configuration`
Utilitaire permettant de faire le scénario de paramétrage de la base automatique :
- Récupération de la configuration
- Configuration de la base pour avoir des corrections NTRIP
- Changement de mode de la balise (passage de `manuel` à `fix-and-hold`)
- Collecte des positions pour obtenir la moyenne
- Configuration de la base avec les nouvelles coordonées
## Utilisation
```shell
go run ./cmd/average_position -host <HOST> -baseAccuracy <fix|float|single>
```
Où:
- `<HOST>` est l'adresse IP du module Reach sur le réseau (par défaut `192.168.42.1`).
> **Info** Utiliser le flag `-h` pour voir les autres options disponibles.

View File

@ -2,10 +2,12 @@ package main
import (
"context"
"encoding/json"
"flag"
"fmt"
"log/slog"
"os"
"time"
reach "forge.cadoles.com/cadoles/go-emlid/reach/client"
"forge.cadoles.com/cadoles/go-emlid/reach/client/logger"
@ -16,15 +18,31 @@ import (
)
var (
host string = "192.168.42.1"
rawLogLevel string = "ERROR"
baseAccuracy string = "fix"
host string = "192.168.42.1"
rawLogLevel string = "ERROR"
)
func init() {
flag.StringVar(&rawLogLevel, "log-level", rawLogLevel, "log level")
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"`
}
type BaseConfig struct {
Latitude float64
Longitude float64
Height float64
AntennaOffset float64
}
func main() {
@ -38,11 +56,7 @@ func main() {
os.Exit(1)
}
defer closeClient(ctx, client)
/// setModem
if err := updateModem(ctx, client); err != nil {
fmt.Printf("[FATAL] %+v", err)
os.Exit(1)
}
// Récupération de la configuration
config, err := retrieveAndProcessConfig(ctx, client)
if err != nil {
@ -50,20 +64,29 @@ func main() {
os.Exit(1)
}
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)
baseConfig := extractBaseConfig(config)
fmt.Printf("Configuration base actuelle: lat=%v, lon=%v, height=%v, offset=%v\n\n NTRIPSettings: \n address:%s\n port:%d \n username: %s\n password:%s\n sendPositionToBase:%t\n",
baseConfig.Latitude, baseConfig.Longitude, baseConfig.Height, baseConfig.AntennaOffset, 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)
//NTRIP Correction
processNTRIPCorrection(ctx, client, config)
//Base configuration
if err := setBaseToModeAndHold(ctx, client, config, baseAccuracy, 30); err != nil {
// Configuration des corrections NTRIP
if err := setupNTRIPCorrections(ctx, client, config); err != nil {
fmt.Printf("[FATAL] %+v", err)
os.Exit(1)
}
// AveragePosition
processAveragePosition(ctx, client)
//Configuration de la base
if err := setBaseToSingleAndHold(ctx, client, baseConfig); err != nil {
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) {
@ -102,32 +125,65 @@ func retrieveAndProcessConfig(ctx context.Context, client *reach.Client) (*model
return &config, nil
}
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)
func extractBaseConfig(config *model.Configuration) BaseConfig {
return BaseConfig{
Latitude: config.BaseMode.BaseCoordinates.Coordinates.Latitude,
Longitude: config.BaseMode.BaseCoordinates.Coordinates.Longitude,
Height: config.BaseMode.BaseCoordinates.Coordinates.Height,
AntennaOffset: config.BaseMode.BaseCoordinates.AntennaOffset,
}
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...")
func setupNTRIPCorrections(ctx context.Context, client *reach.Client, config *model.Configuration) error {
fmt.Println("Configuration des corrections NTRIP...")
// Recherche de points de montage
ntripMsg, err := client.GetNTRIPMountPoint(ctx)
if err != nil {
return nil, errors.WithStack(err)
if err := client.GetNTRIPMountPoint(ctx); err != nil {
return errors.WithStack(err)
}
return ntripMsg, nil
return processNTRIPStreams(ctx, client, config)
}
func displayAvailableMountPoint(response *protocol.TaskMessage[protocol.NTRIPPayload]) {
func processNTRIPStreams(ctx context.Context, client *reach.Client, config *model.Configuration) error {
messages, err := reach.OnMessageType(ctx, client, "task_status")
if err != nil {
return 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()
}
}
}
func handleNTRIPResponse(ctx context.Context, client *reach.Client, config *model.Configuration, message reach.Broadcast) error {
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
fmt.Printf("=== %d Streams disponibles ===\n", len(streams))
fmt.Printf("=== Base < 50 km disponibles ===\n")
for i, stream := range streams {
if stream.Distance < 50 {
fmt.Printf("%d. %-15s | %s (%s) | %.1fkm\n",
@ -159,62 +215,93 @@ func updateNTRIPMountPoint(ctx context.Context, client *reach.Client, config *mo
return nil
}
func setBaseToModeAndHold(ctx context.Context, client *reach.Client, baseConfig *model.Configuration, mode string, accumulation int) error {
fmt.Printf("Configuration de la base en mode %s-and-hold...\n", baseAccuracy)
func setBaseToSingleAndHold(ctx context.Context, client *reach.Client, baseConfig BaseConfig) error {
fmt.Println("Configuration de la base en mode single-and-hold...")
opts := []protocol.SetBaseOptionFunc{
protocol.WithBaseLatitude(baseConfig.BaseMode.BaseCoordinates.Coordinates.Latitude),
protocol.WithBaseLongitude(baseConfig.BaseMode.BaseCoordinates.Coordinates.Longitude),
protocol.WithBaseHeight(baseConfig.BaseMode.BaseCoordinates.Coordinates.Height),
protocol.WithBaseAntennaOffset(baseConfig.BaseMode.BaseCoordinates.AntennaOffset),
protocol.WithBaseMode(fmt.Sprintf("%s-and-hold", mode)),
protocol.WithAccumulation(accumulation),
protocol.WithBaseLatitude(baseConfig.Latitude),
protocol.WithBaseLongitude(baseConfig.Longitude),
protocol.WithBaseHeight(baseConfig.Height),
protocol.WithBaseAntennaOffset(baseConfig.AntennaOffset),
protocol.WithBaseMode("single-and-hold"),
}
if err := client.SetBase(ctx, opts...); err != nil {
return errors.WithStack(err)
}
fmt.Printf("Base configurée en mode %s-and-hold\n", baseAccuracy)
fmt.Println("Base configurée en mode single-and-hold")
return nil
}
func processAveragePosition(ctx context.Context, client *reach.Client) {
// 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)
func averagePositionAndSave(ctx context.Context, client *reach.Client) error {
fmt.Println("Démarrage du moyennage de position...")
fmt.Println("Configuration terminée avec succès")
if err := client.AveragePosition(ctx); err != nil {
return errors.WithStack(err)
}
return waitForAverageCompletion(ctx, client)
}
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)
func waitForAverageCompletion(ctx context.Context, client *reach.Client) error {
broadcasts, err := reach.OnMessageType(ctx, client, "task_status")
if err != nil {
return nil, errors.WithStack(err)
return errors.WithStack(err)
}
return messageTask, nil
timeout := time.NewTimer(5 * time.Minute)
defer timeout.Stop()
for {
select {
case b := <-broadcasts:
if err := logTaskProgress(b); err != nil {
fmt.Printf("[WARNING] %+v", err)
continue
}
if b.State == "completed" {
return handleAverageCompletion(ctx, client, b)
}
case <-timeout.C:
return errors.New("timeout lors du moyennage de position")
case <-ctx.Done():
return ctx.Err()
}
}
}
func displayAveragePositionMessage(message *protocol.TaskMessage[protocol.AveragePositionPayload]) error {
func logTaskProgress(message reach.Broadcast) 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 reach.Broadcast) 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",
message.Payload.Coordinates.Latitude, message.Payload.Coordinates.Longitude, message.Payload.Coordinates.Height)
return nil
coords.Latitude, coords.Longitude, coords.Height)
return saveAveragedPosition(ctx, client, payload)
}
func saveAveragedPosition(ctx context.Context, client *reach.Client, message *protocol.TaskMessage[protocol.AveragePositionPayload]) error {
func saveAveragedPosition(ctx context.Context, client *reach.Client, payload Payload) error {
opts := []protocol.SetBaseOptionFunc{
protocol.WithBaseLatitude(message.Payload.Coordinates.Latitude),
protocol.WithBaseLongitude(message.Payload.Coordinates.Longitude),
protocol.WithBaseHeight(message.Payload.Coordinates.Height),
protocol.WithBaseAntennaOffset(message.Payload.AntennaOffset),
protocol.WithBaseLatitude(payload.Coordinates.Latitude),
protocol.WithBaseLongitude(payload.Coordinates.Longitude),
protocol.WithBaseHeight(payload.Coordinates.Height),
protocol.WithBaseAntennaOffset(payload.AntennaOffset),
protocol.WithBaseMode("manual"),
}
@ -225,16 +312,3 @@ func saveAveragedPosition(ctx context.Context, client *reach.Client, message *pr
fmt.Println("Position sauvegardée en configuration")
return nil
}
func updateModem(ctx context.Context, client *reach.Client) error {
opts := []protocol.SetModemOptionsFunc{
protocol.WithApn("mmsbouygtel.com"),
}
if err := client.SetModem(ctx, opts...); err != nil {
return errors.WithStack(err)
}
fmt.Println("Modem mis à jour")
return nil
}

View File

@ -17,12 +17,14 @@ var (
host string = "192.168.42.1"
filter string = ""
rawLogLevel string = "ERROR"
messageType string = "broadcast"
)
func init() {
flag.StringVar(&rawLogLevel, "log-level", rawLogLevel, "log level")
flag.StringVar(&host, "host", host, "the reachrs module host")
flag.StringVar(&filter, "filter", filter, "filter the broadcast messages by name")
flag.StringVar(&filter, "filter", filter, "filter the socket messages by name")
flag.StringVar(&messageType, "messageType", messageType, "socket messages by name")
}
func main() {
@ -51,7 +53,7 @@ func main() {
}
}()
broadcasts, err := reach.OnBroadcast(ctx, client)
broadcasts, err := reach.OnMessageType(ctx, client, messageType)
if err != nil {
fmt.Printf("[FATAL] %+v", errors.WithStack(err))
os.Exit(1)

View File

@ -1,70 +0,0 @@
package main
import (
"context"
"encoding/json"
"flag"
"fmt"
"log/slog"
"os"
reach "forge.cadoles.com/cadoles/go-emlid/reach/client"
"forge.cadoles.com/cadoles/go-emlid/reach/client/logger"
"github.com/pkg/errors"
)
var (
host string = "192.168.42.1"
filter string = "task"
rawLogLevel string = "ERROR"
)
func init() {
flag.StringVar(&rawLogLevel, "log-level", rawLogLevel, "log level")
flag.StringVar(&host, "host", host, "the reachrs module host")
flag.StringVar(&filter, "filter", filter, "filter the type messages by name")
}
func main() {
flag.Parse()
ctx := context.Background()
client := reach.NewClient(host)
logLevel, err := logger.ParseLevel(rawLogLevel)
if err != nil {
fmt.Printf("[FATAL] %+v", errors.WithStack(err))
os.Exit(1)
}
slog.SetLogLoggerLevel(logLevel)
if err := client.Connect(ctx); err != nil {
fmt.Printf("[FATAL] %+v", errors.WithStack(err))
os.Exit(1)
}
defer func() {
if err := client.Close(ctx); err != nil {
fmt.Printf("[FATAL] %+v", errors.WithStack(err))
os.Exit(1)
}
}()
fmt.Println(filter)
messages, err := reach.OnMessageType(ctx, client, filter)
if err != nil {
fmt.Printf("[FATAL] %+v", errors.WithStack(err))
os.Exit(1)
}
for b := range messages {
data, err := json.MarshalIndent(b, "", " ")
if err != nil {
fmt.Printf("[ERROR] %+v", errors.WithStack(err))
continue
}
fmt.Println(string(data))
}
}

View File

@ -153,35 +153,34 @@ func (c *Client) Reboot(ctx context.Context) error {
}
// AveragePosition implements protocol.Operations.
func (c *Client) AveragePosition(ctx context.Context) (*protocol.TaskMessage[protocol.AveragePositionPayload], error) {
func (c *Client) AveragePosition(ctx context.Context) error {
_, ops, err := c.getProtocol(ctx)
if err != nil {
return nil, errors.WithStack(err)
return errors.WithStack(err)
}
taskMsg, err := ops.AveragePosition(ctx)
if err != nil {
return nil, errors.WithStack(err)
if err := ops.AveragePosition(ctx); err != nil {
return errors.WithStack(err)
}
return taskMsg, err
return nil
}
// GetNTRIPMountPoint implements protocol.Operations.
func (c *Client) GetNTRIPMountPoint(ctx context.Context) (*protocol.TaskMessage[protocol.NTRIPPayload], error) {
func (c *Client) GetNTRIPMountPoint(ctx context.Context) error {
_, ops, err := c.getProtocol(ctx)
if err != nil {
return nil, errors.WithStack(err)
return errors.WithStack(err)
}
ntripMsg, err := ops.GetNTRIPMountPoint(ctx)
if err != nil {
return nil, errors.WithStack(err)
if err := ops.GetNTRIPMountPoint(ctx); err != nil {
return errors.WithStack(err)
}
return ntripMsg, nil
return nil
}
// SetBaseCorrections implements protocol.Operations.
// GetNTRIPMountPoint implements protocol.Operations.
func (c *Client) SetBaseCorrections(ctx context.Context, funcs ...protocol.SetBaseCorrectionsFunc) error {
_, ops, err := c.getProtocol(ctx)
if err != nil {
@ -194,32 +193,4 @@ func (c *Client) SetBaseCorrections(ctx context.Context, funcs ...protocol.SetBa
return nil
}
// SetModem implements protocol.Operations.
func (c *Client) SetModem(ctx context.Context, funcs ...protocol.SetModemOptionsFunc) error {
_, ops, err := c.getProtocol(ctx)
if err != nil {
return errors.WithStack(err)
}
if err := ops.SetModem(ctx, funcs...); err != nil {
return errors.WithStack(err)
}
return nil
}
// GetModemConfiguration implements protocol.Operations.
func (c *Client) GetModemConfiguration(ctx context.Context) (any, error) {
_, ops, err := c.getProtocol(ctx)
if err != nil {
return nil, errors.WithStack(err)
}
config, err := ops.GetModemConfiguration(ctx)
if err != nil {
return nil, errors.WithStack(err)
}
return config, nil
}
var _ protocol.Operations = &Client{}

View File

@ -1,12 +0,0 @@
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"`
}

View File

@ -1,41 +0,0 @@
package protocol
type SetModemOptions struct {
Apn *string
Type *string
Username *string
Password *string
}
type SetModemOptionsFunc func(opts *SetModemOptions)
func NewSetModemOptions(funcs ...SetModemOptionsFunc) *SetModemOptions {
opts := &SetModemOptions{}
for _, fn := range funcs {
fn(opts)
}
return opts
}
func WithApn(value string) SetModemOptionsFunc {
return func(opts *SetModemOptions) {
opts.Apn = &value
}
}
func WithType(value string) SetModemOptionsFunc {
return func(opts *SetModemOptions) {
opts.Type = &value
}
}
func WithUsername(value string) SetModemOptionsFunc {
return func(opts *SetModemOptions) {
opts.Username = &value
}
}
func WithPassword(value string) SetModemOptionsFunc {
return func(opts *SetModemOptions) {
opts.Password = &value
}
}

View File

@ -1,8 +1,6 @@
package protocol
import (
"context"
)
import "context"
type BaseInfo struct {
Mode string
@ -10,12 +8,6 @@ type BaseInfo struct {
Latitude float64
Longitude float64
Height float64
Accumulation int
}
type TaskMessage[T any] struct {
Name string `json:"name"`
State string `json:"state"`
Payload T `json:"payload"`
}
type Operations interface {
@ -51,17 +43,11 @@ type Operations interface {
Reboot(ctx context.Context) error
// AveragePosition gathers data and computes the average position
AveragePosition(ctx context.Context) (*TaskMessage[AveragePositionPayload], error)
AveragePosition(ctx context.Context) error
//GetNTRIPMountPoint retrieves availables mount point
GetNTRIPMountPoint(ctx context.Context) (*TaskMessage[NTRIPPayload], error)
GetNTRIPMountPoint(ctx context.Context) error
//SetBaseCorrections updates the corrections obtaining station
SetBaseCorrections(ctx context.Context, funcs ...SetBaseCorrectionsFunc) error
//SetModem updates mobile data config
SetModem(ctx context.Context, funcs ...SetModemOptionsFunc) error
//GetModemConfiguration mobile data config
GetModemConfiguration(ctx context.Context) (any, error)
}

View File

@ -6,7 +6,6 @@ type SetBaseOptions struct {
Latitude *float64
Longitude *float64
Height *float64
Accumulation *int
}
type SetBaseOptionFunc func(opts *SetBaseOptions)
@ -48,9 +47,3 @@ func WithBaseHeight(value float64) SetBaseOptionFunc {
opts.Height = &value
}
}
func WithAccumulation(value int) SetBaseOptionFunc {
return func(opts *SetBaseOptions) {
opts.Accumulation = &value
}
}

View File

@ -237,167 +237,7 @@ var testCases = []operationTestCase{
t.Errorf("%+v", errors.WithStack(err))
return
}
},
},
{
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("fix-and-hold"),
}
if err := ops.SetBase(ctx, opts...); err != nil {
t.Errorf("%+v", errors.WithStack(err))
}
},
},
{
Name: "SetBaseCorrections",
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))
}
}()
opts := []protocol.SetBaseCorrectionsFunc{
protocol.WithNTRIPAddress("crtk.net"),
protocol.WithNTRIPPort(2101),
protocol.WithNTRIPUsername("centipede"),
protocol.WithNTRIPPassword("centipede"),
protocol.WithNTRIPMountPoint("EPI21"),
protocol.WithSendPositionToBase(true),
}
if err := ops.SetBaseCorrections(ctx, opts...); err != nil {
t.Errorf("%+v", errors.WithStack(err))
return
}
t.Logf("BaseCorrection Update")
},
},
{
Name: "SetModem",
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))
}
}()
opts := []protocol.SetModemOptionsFunc{
protocol.WithApn("mmsbouygtel.com"),
}
if err := ops.SetModem(ctx, opts...); err != nil {
t.Errorf("%+v", errors.WithStack(err))
return
}
t.Logf("Modem Update")
},
},
{
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 : %+v", 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))
}
}()
taskMsg, err := ops.GetNTRIPMountPoint(ctx)
if err != nil {
t.Errorf("%+v", errors.WithStack(err))
return
}
t.Logf("Message : %+v", taskMsg)
},
},
{
Name: "GetModemConfiguration",
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))
}
}()
config, err := ops.GetModemConfiguration(ctx)
if err != nil {
t.Errorf("%+v", errors.WithStack(err))
return
}
t.Logf("Modem configuration : %+v", config)
},
},
}

View File

@ -2,7 +2,6 @@ package v1
import "forge.cadoles.com/cadoles/go-emlid/reach/client/protocol"
// Deprecated : is no longer maintained for modules in V1
func init() {
protocol.Register(Identifier, func(opts *protocol.ProtocolOptions) (protocol.Protocol, error) {
return &Protocol{

View File

@ -22,14 +22,12 @@ const (
eventSettingsResetToDefault = "settings reset to default"
)
// Deprecated : is no longer maintained for modules in V1
type configurationApplied struct {
Configuration *model.Configuration `mapstructure:"configuration,omitempty"`
Result string `mapstructure:"result"`
Constraints *model.Constraints `mapstructure:"constraints,omitempty"`
}
// Deprecated : is no longer maintained for modules in V1
func (o *Operations) ApplyConfiguration(ctx context.Context, config *model.Configuration) (string, *model.Configuration, error) {
o.logger.Debug("applying configuration", logger.Attr("configuration", spew.Sdump(config)))
@ -43,7 +41,6 @@ func (o *Operations) ApplyConfiguration(ctx context.Context, config *model.Confi
return res.Result, res.Configuration, nil
}
// Deprecated : is no longer maintained for modules in V1
func (o *Operations) RequestConfiguration(ctx context.Context) (*model.Configuration, error) {
configuration := &model.Configuration{}
if err := o.ReqResp(ctx, eventGetConfiguration, nil, eventCurrentConfiguration, configuration); err != nil {
@ -52,7 +49,6 @@ func (o *Operations) RequestConfiguration(ctx context.Context) (*model.Configura
return configuration, nil
}
// Deprecated : is no longer maintained for modules in V1
// ReqResp emits an event with the given data and waits for a response
func (o *Operations) ReqResp(ctx context.Context,
requestEvent string, requestData any,

View File

@ -1,6 +1,5 @@
package model
// Deprecated : is no longer maintained for modules in V1
var (
// On -
On = String("on")

View File

@ -1,8 +0,0 @@
package model
// Deprecated : is no longer maintained for modules in V1
type TaskMessage struct {
Name string `json:"name"`
State string `json:"state"`
Payload map[string]interface{} `json:"payload"`
}

View File

@ -2,6 +2,7 @@ package v1
import (
"context"
"encoding/json"
"strconv"
"strings"
"sync"
@ -13,7 +14,6 @@ import (
"github.com/pkg/errors"
)
// Deprecated : is no longer maintained for modules in V1
type Operations struct {
addr string
client *socketio.Client
@ -23,7 +23,6 @@ type Operations struct {
dial protocol.DialFunc
}
// Deprecated : is no longer maintained for modules in V1
// Close implements protocol.Operations.
func (o *Operations) Close(ctx context.Context) error {
o.mutex.Lock()
@ -38,14 +37,12 @@ func (o *Operations) Close(ctx context.Context) error {
return nil
}
// Deprecated : is no longer maintained for modules in V1
const (
// EventBrowserConnected is emitted after the initial connection to the
// ReachView endpoint
eventBrowserConnected = "browser connected"
)
// Deprecated : is no longer maintained for modules in V1
// Connect implements protocol.Operations.
func (o *Operations) Connect(ctx context.Context) error {
o.mutex.Lock()
@ -84,7 +81,6 @@ func (o *Operations) Connect(ctx context.Context) error {
return nil
}
// Deprecated : is no longer maintained for modules in V1
// Emit implements protocol.Operations.
func (o *Operations) Emit(ctx context.Context, mType string, message any) error {
o.mutex.RLock()
@ -101,7 +97,6 @@ func (o *Operations) Emit(ctx context.Context, mType string, message any) error
return nil
}
// Deprecated : is no longer maintained for modules in V1
// On implements protocol.Operations.
func (o *Operations) On(ctx context.Context, event string) (chan any, error) {
o.mutex.RLock()
@ -142,7 +137,6 @@ func (o *Operations) On(ctx context.Context, event string) (chan any, error) {
return out, nil
}
// Deprecated : is no longer maintained for modules in V1
// Alive implements protocol.Operations.
func (o *Operations) Alive(ctx context.Context) (bool, error) {
o.mutex.RLock()
@ -155,7 +149,6 @@ func (o *Operations) Alive(ctx context.Context) (bool, error) {
return o.client.Alive(), nil
}
// Deprecated : is no longer maintained for modules in V1
// Configuration implements protocol.Operations.
func (o *Operations) Configuration(ctx context.Context) (any, error) {
config, err := o.RequestConfiguration(ctx)
@ -170,7 +163,6 @@ const (
eventReboot = "reboot"
)
// Deprecated : is no longer maintained for modules in V1
// Reboot implements protocol.Operations.
func (o *Operations) Reboot(ctx context.Context) error {
o.mutex.RLock()
@ -221,7 +213,6 @@ const (
configurationApplyFailed = "failed"
)
// Deprecated : is no longer maintained for modules in V1
// SetBase implements protocol.Operations.
func (o *Operations) SetBase(ctx context.Context, funcs ...protocol.SetBaseOptionFunc) error {
rawConfig, err := o.Configuration(ctx)
@ -307,7 +298,6 @@ func (o *Operations) SetBase(ctx context.Context, funcs ...protocol.SetBaseOptio
return nil
}
// Deprecated : is no longer maintained for modules in V1
// GetBaseInfo implements protocol.Operations.
func (o *Operations) GetBaseInfo(ctx context.Context) (*protocol.BaseInfo, error) {
rawConfig, err := o.Configuration(ctx)
@ -364,7 +354,6 @@ type reachViewVersion struct {
Stable bool `json:"bool"`
}
// Deprecated : is no longer maintained for modules in V1
// Version implements protocol.Operations.
func (o *Operations) Version(ctx context.Context) (string, bool, error) {
res := &reachViewVersion{}
@ -375,29 +364,58 @@ func (o *Operations) Version(ctx context.Context) (string, bool, error) {
return strings.TrimSpace(res.Version), res.Stable, nil
}
// Deprecated : is no longer maintained for modules in V1
func (o *Operations) AveragePosition(ctx context.Context) (*protocol.TaskMessage[protocol.AveragePositionPayload], error) {
return nil, protocol.ErrUnimplemented
func (o *Operations) AveragePosition(ctx context.Context) error {
var err error
go func() {
<-ctx.Done()
err = ctx.Err()
}()
if err = o.client.Emit("task", map[string]string{"name": "average_base_coordinates"}); err != nil {
return err
}
return err
}
// Deprecated : is no longer maintained for modules in V1
func (o *Operations) GetNTRIPMountPoint(ctx context.Context) (*protocol.TaskMessage[protocol.NTRIPPayload], error) {
return nil, protocol.ErrUnimplemented
// TODO À VOIR POUR LES VERSION 1
func (o *Operations) GetNTRIPMountPoint(ctx context.Context) error {
var err error
go func() {
<-ctx.Done()
err = ctx.Err()
}()
payloadJSON, err := json.Marshal(map[string]interface{}{
"address": "crtk.net",
"port": 2101,
})
if err = o.client.Emit("task", map[string]string{"name": "get_ntrip_mountpoints", "payload": string(payloadJSON)}); err != nil {
return err
}
return err
}
// Deprecated : is no longer maintained for modules in V1
// todo
func (o *Operations) SetBaseCorrections(ctx context.Context, funcs ...protocol.SetBaseCorrectionsFunc) error {
return protocol.ErrUnimplemented
}
var err error
// Deprecated : is no longer maintained for modules in V1
func (o *Operations) SetModem(ctx context.Context, funcs ...protocol.SetModemOptionsFunc) error {
return protocol.ErrUnimplemented
}
go func() {
<-ctx.Done()
err = ctx.Err()
}()
// todo
payloadJSON, err := json.Marshal(map[string]interface{}{
"address": "crtk.net",
"port": 2101,
})
if err = o.client.Emit("task", map[string]string{"name": "get_ntrip_mountpoints", "payload": string(payloadJSON)}); err != nil {
return err
}
// Deprecated : is no longer maintained for modules in V1
func (o *Operations) GetModemConfiguration(ctx context.Context) (any, error) {
return nil, protocol.ErrUnimplemented
return err
}
var _ protocol.Operations = &Operations{}

View File

@ -10,7 +10,6 @@ import (
"github.com/pkg/errors"
)
// Deprecated : is no longer maintained for modules in V1
const Identifier protocol.Identifier = "v1"
const compatibleVersionConstraint = "^2.24"
@ -20,7 +19,6 @@ type Protocol struct {
dial protocol.DialFunc
}
// Deprecated : is no longer maintained for modules in V1
// Available implements protocol.Protocol.
func (p *Protocol) Available(ctx context.Context, addr string) (bool, error) {
ops := p.Operations(addr).(*Operations)
@ -55,13 +53,11 @@ func (p *Protocol) Available(ctx context.Context, addr string) (bool, error) {
return true, nil
}
// Deprecated : is no longer maintained for modules in V1
// Identifier implements protocol.Protocol.
func (p *Protocol) Identifier() protocol.Identifier {
return Identifier
}
// Deprecated : is no longer maintained for modules in V1
// Operations implements protocol.Protocol.
func (p *Protocol) Operations(addr string) protocol.Operations {
return &Operations{addr: addr, logger: p.logger, dial: p.dial}

View File

@ -8,7 +8,6 @@ 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"
)
@ -127,8 +126,8 @@ func (o *Operations) PostDevice(ctx context.Context, device *model.Configuration
return &updated, nil
}
func (o *Operations) PostBaseCorrection(ctx context.Context, base *protocol.IOConfig) (*protocol.IOConfig, error) {
var updated protocol.IOConfig
func (o *Operations) PostBaseCorrection(ctx context.Context, base *model.IOConfig) (*model.IOConfig, error) {
var updated model.IOConfig
if err := o.PostJSON("/configuration/correction_input/base_corrections", base, &updated); err != nil {
return nil, errors.WithStack(err)
@ -163,23 +162,3 @@ func (o *Operations) GetConfiguration(ctx context.Context) (*model.Configuration
return config, nil
}
func (o *Operations) PostModem(ctx context.Context, config *model.ModemAuthentication) (*model.ModemAuthentication, error) {
var updated model.ModemAuthentication
if err := o.PostJSON("/modem/1/settings", config, &updated); err != nil {
return nil, errors.WithStack(err)
}
return &updated, nil
}
func (o *Operations) GetModem(ctx context.Context) (*model.ModemConfiguration, error) {
config := &model.ModemConfiguration{}
if err := o.GetJSON("/modem/1/info", config); err != nil {
return nil, errors.WithStack(err)
}
return config, nil
}

View File

@ -1,6 +1,6 @@
package model
type Action struct {
Name string `json:"name"`
Paylaod map[string]any `json:"payload,omitempty"`
Name string `json:"name"`
Paylaod map[string]interface{} `json:"payload"`
}

View File

@ -1,4 +1,4 @@
package protocol
package model
type IOConfig struct {
IOType string `json:"io_type"`
@ -18,6 +18,12 @@ 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"`

View File

@ -1,34 +0,0 @@
package model
// type : null, pap_chap, pap, chap
// if type selected, username and password are mandatory
type ModemAuthentication struct {
Authentication struct {
Apn string `json:"apn"`
Type string `json:"type,omitempty"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
} `json:"authentication"`
}
type ModemConfiguration struct {
AccessTechnology string `json:"access_technology"`
AllowedModes []string `json:"allowed_modes"`
AvailableAPNs []string `json:"available_apns,omitempty"`
CurrentAPN string `json:"current_apn"`
CurrentMode string `json:"current_mode"`
FailReason *string `json:"fail_reason,omitempty"`
IMEI string `json:"imei"`
InternetAvailable string `json:"internet_available,omitempty"`
LockReason *string `json:"lock_reason,omitempty"`
OperatorName string `json:"operator_name"`
PreferredMode string `json:"preferred_mode"`
RegistrationState string `json:"registration_state"`
RSSI int `json:"rssi"`
State string `json:"state"`
Stats struct {
Since string `json:"since"`
UsageMB string `json:"usage_mb"`
} `json:"stats"`
UnlockRetries int `json:"unlock_retries"`
}

View File

@ -10,7 +10,6 @@ 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"
)
@ -87,10 +86,6 @@ func (o *Operations) SetBase(ctx context.Context, funcs ...protocol.SetBaseOptio
base.Mode = *opts.Mode
}
if opts.Accumulation != nil {
base.Accumulation = *opts.Accumulation
}
if opts.Height != nil {
base.Coordinates.Height = *opts.Height
}
@ -133,7 +128,6 @@ func (o *Operations) GetBaseInfo(ctx context.Context) (*protocol.BaseInfo, error
Height: config.BaseMode.BaseCoordinates.Coordinates.Height,
Latitude: config.BaseMode.BaseCoordinates.Coordinates.Latitude,
Longitude: config.BaseMode.BaseCoordinates.Coordinates.Longitude,
Accumulation: config.BaseMode.BaseCoordinates.Accumulation,
}
return baseInfo, nil
@ -270,7 +264,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[protocol.AveragePositionPayload], error) {
func (o *Operations) AveragePosition(ctx context.Context) error {
var err error
go func() {
@ -279,18 +273,19 @@ func (o *Operations) AveragePosition(ctx context.Context) (*protocol.TaskMessage
}()
if err = o.client.Emit("task", &model.Action{Name: "average_base_coordinates"}); err != nil {
return nil, err
return err
}
return nil, err
return err
}
// GetNTRIPMountPoint implements protocol.Operations.
func (o *Operations) GetNTRIPMountPoint(ctx context.Context) (*protocol.TaskMessage[protocol.NTRIPPayload], error) {
func (o *Operations) GetNTRIPMountPoint(ctx context.Context) error {
var err error
config, err := o.GetConfiguration(ctx)
if err != nil {
return nil, errors.WithStack(err)
return errors.WithStack(err)
}
go func() {
@ -304,21 +299,10 @@ func (o *Operations) GetNTRIPMountPoint(ctx context.Context) (*protocol.TaskMess
}
if err = o.client.Emit("task", &model.Action{Name: "get_ntrip_mountpoints", Paylaod: payload}); err != nil {
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)
return err
}
// SetBaseCorrections implements protocol.Operations.
@ -340,11 +324,11 @@ func (o *Operations) SetBaseCorrections(ctx context.Context, funcs ...protocol.S
return errors.New("NTRIP mount point is required")
}
config := &protocol.IOConfig{
// todo parametrage du type
config := &model.IOConfig{
// todo parametrage du type ????
IOType: "ntripcli",
Settings: protocol.IOConfigSettings{
NTRIPCli: protocol.NTRIPCliConfig{
Settings: model.IOConfigSettings{
NTRIPCli: model.NTRIPCliConfig{
Address: *opts.Address,
Port: *opts.Port,
Username: *opts.Username,
@ -362,41 +346,4 @@ func (o *Operations) SetBaseCorrections(ctx context.Context, funcs ...protocol.S
return nil
}
// SetModem implements protocol.Operations.
func (o *Operations) SetModem(ctx context.Context, funcs ...protocol.SetModemOptionsFunc) error {
opts := protocol.NewSetModemOptions(funcs...)
modem := &model.ModemAuthentication{}
if opts.Apn != nil {
modem.Authentication.Apn = *opts.Apn
}
if opts.Type != nil {
modem.Authentication.Type = *opts.Type
}
if opts.Password != nil {
modem.Authentication.Password = *opts.Password
}
if opts.Username != nil {
modem.Authentication.Username = *opts.Username
}
if _, err := o.PostModem(ctx, modem); err != nil {
return errors.WithStack(err)
}
return nil
}
// SetModem implements protocol.Operations.
func (o *Operations) GetModemConfiguration(ctx context.Context) (any, error) {
config, err := o.GetModem(ctx)
if err != nil {
return nil, errors.WithStack(err)
}
return config, nil
}
var _ protocol.Operations = &Operations{}