wip
This commit is contained in:
21
cmd/average_position/README.md
Normal file
21
cmd/average_position/README.md
Normal file
@ -0,0 +1,21 @@
|
||||
# `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>
|
||||
```
|
||||
|
||||
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.
|
@ -65,7 +65,7 @@ func main() {
|
||||
}
|
||||
|
||||
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",
|
||||
fmt.Printf("Configuration actuelle de la base :\n lat=%v\n lon=%v\n height=%v\n antenna_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)
|
||||
|
||||
// Configuration des corrections NTRIP
|
||||
@ -75,7 +75,7 @@ func main() {
|
||||
}
|
||||
|
||||
//Configuration de la base
|
||||
if err := setBaseToSingleAndHold(ctx, client, baseConfig); err != nil {
|
||||
if err := setBaseToModeAndHold(ctx, client, baseConfig, "float"); err != nil {
|
||||
fmt.Printf("[FATAL] %+v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
@ -135,7 +135,7 @@ func extractBaseConfig(config *model.Configuration) BaseConfig {
|
||||
}
|
||||
|
||||
func setupNTRIPCorrections(ctx context.Context, client *reach.Client, config *model.Configuration) error {
|
||||
fmt.Println("Configuration des corrections NTRIP...")
|
||||
fmt.Println("\nConfiguration des corrections NTRIP...")
|
||||
|
||||
// Recherche de points de montage
|
||||
if err := client.GetNTRIPMountPoint(ctx); err != nil {
|
||||
@ -184,6 +184,8 @@ func handleNTRIPResponse(ctx context.Context, client *reach.Client, config *mode
|
||||
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",
|
||||
@ -215,66 +217,67 @@ func updateNTRIPMountPoint(ctx context.Context, client *reach.Client, config *mo
|
||||
return nil
|
||||
}
|
||||
|
||||
func setBaseToSingleAndHold(ctx context.Context, client *reach.Client, baseConfig BaseConfig) error {
|
||||
fmt.Println("Configuration de la base en mode single-and-hold...")
|
||||
|
||||
func setBaseToModeAndHold(ctx context.Context, client *reach.Client, baseConfig BaseConfig, mode string) error {
|
||||
fmt.Println("Configuration de la base en mode float-and-hold...")
|
||||
opts := []protocol.SetBaseOptionFunc{
|
||||
protocol.WithBaseLatitude(baseConfig.Latitude),
|
||||
protocol.WithBaseLongitude(baseConfig.Longitude),
|
||||
protocol.WithBaseHeight(baseConfig.Height),
|
||||
protocol.WithBaseAntennaOffset(baseConfig.AntennaOffset),
|
||||
protocol.WithBaseMode("single-and-hold"),
|
||||
protocol.WithBaseMode(fmt.Sprintf("%s-and-hold", mode)),
|
||||
}
|
||||
|
||||
if err := client.SetBase(ctx, opts...); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
fmt.Println("Base configurée en mode single-and-hold")
|
||||
fmt.Println("Base configurée en mode float-and-hold")
|
||||
return nil
|
||||
}
|
||||
|
||||
func averagePositionAndSave(ctx context.Context, client *reach.Client) error {
|
||||
fmt.Println("Démarrage du moyennage de position...")
|
||||
fmt.Println("Démarrage de la moyenne des position...")
|
||||
|
||||
if err := client.AveragePosition(ctx); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
return waitForAverageCompletion(ctx, client)
|
||||
}
|
||||
|
||||
func waitForAverageCompletion(ctx context.Context, client *reach.Client) error {
|
||||
broadcasts, err := reach.OnMessageType(ctx, client, "task_status")
|
||||
messageTask, err := client.AveragePosition(ctx)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
logTaskProgress(messageTask)
|
||||
return handleAverageCompletion(ctx, client, messageTask)
|
||||
|
||||
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 logTaskProgress(message reach.Broadcast) error {
|
||||
// func waitForAverageCompletion(ctx context.Context, client *reach.Client) error {
|
||||
// broadcasts, err := reach.OnMessageType(ctx, client, "task_status")
|
||||
// if err != nil {
|
||||
// return errors.WithStack(err)
|
||||
// }
|
||||
|
||||
// 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 logTaskProgress(message *protocol.TaskMessage) error {
|
||||
data, err := json.MarshalIndent(message, "", " ")
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
@ -283,7 +286,7 @@ func logTaskProgress(message reach.Broadcast) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleAverageCompletion(ctx context.Context, client *reach.Client, message reach.Broadcast) error {
|
||||
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)
|
||||
|
Reference in New Issue
Block a user