wip modem/tests
This commit is contained in:
parent
ecf5fb46a0
commit
49a4642db2
@ -38,13 +38,6 @@ type Payload struct {
|
|||||||
AntennaOffset float64 `json:"antenna_offset"`
|
AntennaOffset float64 `json:"antenna_offset"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type BaseConfig struct {
|
|
||||||
Latitude float64
|
|
||||||
Longitude float64
|
|
||||||
Height float64
|
|
||||||
AntennaOffset float64
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
@ -56,7 +49,11 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
defer closeClient(ctx, client)
|
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
|
// Récupération de la configuration
|
||||||
config, err := retrieveAndProcessConfig(ctx, client)
|
config, err := retrieveAndProcessConfig(ctx, client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -64,9 +61,8 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
baseConfig := extractBaseConfig(config)
|
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\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.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
|
// Configuration des corrections NTRIP
|
||||||
if err := setupNTRIPCorrections(ctx, client, config); err != nil {
|
if err := setupNTRIPCorrections(ctx, client, config); err != nil {
|
||||||
@ -75,7 +71,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Configuration de la base
|
//Configuration de la base
|
||||||
if err := setBaseToModeAndHold(ctx, client, baseConfig, "float"); err != nil {
|
if err := setBaseToModeAndHold(ctx, client, config, "float", 30); err != nil {
|
||||||
fmt.Printf("[FATAL] %+v", err)
|
fmt.Printf("[FATAL] %+v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
@ -125,15 +121,6 @@ func retrieveAndProcessConfig(ctx context.Context, client *reach.Client) (*model
|
|||||||
return &config, nil
|
return &config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func setupNTRIPCorrections(ctx context.Context, client *reach.Client, config *model.Configuration) error {
|
func setupNTRIPCorrections(ctx context.Context, client *reach.Client, config *model.Configuration) error {
|
||||||
fmt.Println("\nConfiguration des corrections NTRIP...")
|
fmt.Println("\nConfiguration des corrections NTRIP...")
|
||||||
|
|
||||||
@ -217,14 +204,15 @@ func updateNTRIPMountPoint(ctx context.Context, client *reach.Client, config *mo
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func setBaseToModeAndHold(ctx context.Context, client *reach.Client, baseConfig BaseConfig, mode string) 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.Println("Configuration de la base en mode float-and-hold...")
|
||||||
opts := []protocol.SetBaseOptionFunc{
|
opts := []protocol.SetBaseOptionFunc{
|
||||||
protocol.WithBaseLatitude(baseConfig.Latitude),
|
protocol.WithBaseLatitude(baseConfig.BaseMode.BaseCoordinates.Coordinates.Latitude),
|
||||||
protocol.WithBaseLongitude(baseConfig.Longitude),
|
protocol.WithBaseLongitude(baseConfig.BaseMode.BaseCoordinates.Coordinates.Longitude),
|
||||||
protocol.WithBaseHeight(baseConfig.Height),
|
protocol.WithBaseHeight(baseConfig.BaseMode.BaseCoordinates.Coordinates.Height),
|
||||||
protocol.WithBaseAntennaOffset(baseConfig.AntennaOffset),
|
protocol.WithBaseAntennaOffset(baseConfig.BaseMode.BaseCoordinates.AntennaOffset),
|
||||||
protocol.WithBaseMode(fmt.Sprintf("%s-and-hold", mode)),
|
protocol.WithBaseMode(fmt.Sprintf("%s-and-hold", mode)),
|
||||||
|
protocol.WithAccumulation(accumulation),
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := client.SetBase(ctx, opts...); err != nil {
|
if err := client.SetBase(ctx, opts...); err != nil {
|
||||||
@ -247,36 +235,6 @@ func averagePositionAndSave(ctx context.Context, client *reach.Client) 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 {
|
func logTaskProgress(message *protocol.TaskMessage) error {
|
||||||
data, err := json.MarshalIndent(message, "", " ")
|
data, err := json.MarshalIndent(message, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -315,3 +273,16 @@ func saveAveragedPosition(ctx context.Context, client *reach.Client, payload Pay
|
|||||||
fmt.Println("Position sauvegardée en configuration")
|
fmt.Println("Position sauvegardée en configuration")
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
@ -181,7 +181,7 @@ func (c *Client) GetNTRIPMountPoint(ctx context.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetNTRIPMountPoint implements protocol.Operations.
|
// SetBaseCorrections implements protocol.Operations.
|
||||||
func (c *Client) SetBaseCorrections(ctx context.Context, funcs ...protocol.SetBaseCorrectionsFunc) error {
|
func (c *Client) SetBaseCorrections(ctx context.Context, funcs ...protocol.SetBaseCorrectionsFunc) error {
|
||||||
_, ops, err := c.getProtocol(ctx)
|
_, ops, err := c.getProtocol(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -194,4 +194,17 @@ func (c *Client) SetBaseCorrections(ctx context.Context, funcs ...protocol.SetBa
|
|||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
|
||||||
var _ protocol.Operations = &Client{}
|
var _ protocol.Operations = &Client{}
|
||||||
|
41
reach/client/protocol/modem.go
Normal file
41
reach/client/protocol/modem.go
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
@ -10,6 +10,7 @@ type BaseInfo struct {
|
|||||||
Latitude float64
|
Latitude float64
|
||||||
Longitude float64
|
Longitude float64
|
||||||
Height float64
|
Height float64
|
||||||
|
Accumulation int
|
||||||
}
|
}
|
||||||
type TaskMessage struct {
|
type TaskMessage struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
@ -57,4 +58,7 @@ type Operations interface {
|
|||||||
|
|
||||||
//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
|
||||||
|
|
||||||
|
//SetModem updates mobile data config
|
||||||
|
SetModem(ctx context.Context, funcs ...SetModemOptionsFunc) error
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ type SetBaseOptions struct {
|
|||||||
Latitude *float64
|
Latitude *float64
|
||||||
Longitude *float64
|
Longitude *float64
|
||||||
Height *float64
|
Height *float64
|
||||||
|
Accumulation *int
|
||||||
}
|
}
|
||||||
|
|
||||||
type SetBaseOptionFunc func(opts *SetBaseOptions)
|
type SetBaseOptionFunc func(opts *SetBaseOptions)
|
||||||
@ -47,3 +48,9 @@ func WithBaseHeight(value float64) SetBaseOptionFunc {
|
|||||||
opts.Height = &value
|
opts.Height = &value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WithAccumulation(value int) SetBaseOptionFunc {
|
||||||
|
return func(opts *SetBaseOptions) {
|
||||||
|
opts.Accumulation = &value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -275,6 +275,63 @@ var testCases = []operationTestCase{
|
|||||||
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
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",
|
Name: "AveragePosition",
|
||||||
Run: func(t *testing.T, ops protocol.Operations) {
|
Run: func(t *testing.T, ops protocol.Operations) {
|
||||||
|
@ -434,5 +434,9 @@ func (o *Operations) SetBaseCorrections(ctx context.Context, funcs ...protocol.S
|
|||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
func (o *Operations) SetModem(ctx context.Context, funcs ...protocol.SetModemOptionsFunc) error {
|
||||||
|
var err error
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
var _ protocol.Operations = &Operations{}
|
var _ protocol.Operations = &Operations{}
|
||||||
|
@ -162,3 +162,13 @@ func (o *Operations) GetConfiguration(ctx context.Context) (*model.Configuration
|
|||||||
|
|
||||||
return config, nil
|
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
|
||||||
|
}
|
||||||
|
12
reach/client/protocol/v2/model/modem.go
Normal file
12
reach/client/protocol/v2/model/modem.go
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
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"`
|
||||||
|
}
|
@ -87,6 +87,10 @@ func (o *Operations) SetBase(ctx context.Context, funcs ...protocol.SetBaseOptio
|
|||||||
base.Mode = *opts.Mode
|
base.Mode = *opts.Mode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if opts.Accumulation != nil {
|
||||||
|
base.Accumulation = *opts.Accumulation
|
||||||
|
}
|
||||||
|
|
||||||
if opts.Height != nil {
|
if opts.Height != nil {
|
||||||
base.Coordinates.Height = *opts.Height
|
base.Coordinates.Height = *opts.Height
|
||||||
}
|
}
|
||||||
@ -129,6 +133,7 @@ func (o *Operations) GetBaseInfo(ctx context.Context) (*protocol.BaseInfo, error
|
|||||||
Height: config.BaseMode.BaseCoordinates.Coordinates.Height,
|
Height: config.BaseMode.BaseCoordinates.Coordinates.Height,
|
||||||
Latitude: config.BaseMode.BaseCoordinates.Coordinates.Latitude,
|
Latitude: config.BaseMode.BaseCoordinates.Coordinates.Latitude,
|
||||||
Longitude: config.BaseMode.BaseCoordinates.Coordinates.Longitude,
|
Longitude: config.BaseMode.BaseCoordinates.Coordinates.Longitude,
|
||||||
|
Accumulation: config.BaseMode.BaseCoordinates.Accumulation,
|
||||||
}
|
}
|
||||||
|
|
||||||
return baseInfo, nil
|
return baseInfo, nil
|
||||||
@ -363,4 +368,30 @@ func (o *Operations) SetBaseCorrections(ctx context.Context, funcs ...protocol.S
|
|||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
|
||||||
var _ protocol.Operations = &Operations{}
|
var _ protocol.Operations = &Operations{}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user