From 08f12ab5cb55b486a2586e80af28a9898a86a489 Mon Sep 17 00:00:00 2001 From: cmsassot Date: Tue, 8 Jul 2025 16:16:33 +0200 Subject: [PATCH] wip SetBaseMode --- reach/client/operations.go | 14 ++++++++ reach/client/protocol/operations.go | 2 ++ reach/client/protocol/v1/operations.go | 6 ++++ reach/client/protocol/v2/internal.go | 10 ++++++ reach/client/protocol/v2/operations.go | 45 ++++++++++++++++++++++++++ 5 files changed, 77 insertions(+) diff --git a/reach/client/operations.go b/reach/client/operations.go index c98b675..c3f473e 100644 --- a/reach/client/operations.go +++ b/reach/client/operations.go @@ -222,4 +222,18 @@ func (c *Client) GetModemConfiguration(ctx context.Context) (any, error) { return config, nil } +// SetBase implements protocol.Operations. +func (c *Client) SetBaseMode(ctx context.Context, funcs ...protocol.SetBaseOptionFunc) error { + _, ops, err := c.getProtocol(ctx) + if err != nil { + return errors.WithStack(err) + } + + if err := ops.SetBaseMode(ctx, funcs...); err != nil { + return errors.WithStack(err) + } + + return nil +} + var _ protocol.Operations = &Client{} diff --git a/reach/client/protocol/operations.go b/reach/client/protocol/operations.go index 8c9fe1c..446bfbf 100644 --- a/reach/client/protocol/operations.go +++ b/reach/client/protocol/operations.go @@ -64,4 +64,6 @@ type Operations interface { //GetModemConfiguration mobile data config GetModemConfiguration(ctx context.Context) (any, error) + + SetBaseMode(ctx context.Context, funcs ...SetBaseOptionFunc) error } diff --git a/reach/client/protocol/v1/operations.go b/reach/client/protocol/v1/operations.go index 1db989a..ebe1a87 100644 --- a/reach/client/protocol/v1/operations.go +++ b/reach/client/protocol/v1/operations.go @@ -400,4 +400,10 @@ func (o *Operations) GetModemConfiguration(ctx context.Context) (any, error) { return nil, protocol.ErrUnimplemented } +// Deprecated : is no longer maintained for modules in V1 +func (o *Operations) SetBaseMode(ctx context.Context, funcs ...protocol.SetBaseOptionFunc) error { + return protocol.ErrUnimplemented + +} + var _ protocol.Operations = &Operations{} diff --git a/reach/client/protocol/v2/internal.go b/reach/client/protocol/v2/internal.go index 083b404..5edeef5 100644 --- a/reach/client/protocol/v2/internal.go +++ b/reach/client/protocol/v2/internal.go @@ -183,3 +183,13 @@ func (o *Operations) GetModem(ctx context.Context) (*model.ModemConfiguration, e return config, nil } + +func (o *Operations) PostBaseMode(ctx context.Context, base *model.Base) (*model.Base, error) { + var updated model.Base + + if err := o.PostJSON("/configuration/base_mode", base, &updated); err != nil { + return nil, errors.WithStack(err) + } + + return &updated, nil +} diff --git a/reach/client/protocol/v2/operations.go b/reach/client/protocol/v2/operations.go index 5deeb39..ecb6ae9 100644 --- a/reach/client/protocol/v2/operations.go +++ b/reach/client/protocol/v2/operations.go @@ -410,4 +410,49 @@ func (o *Operations) GetModemConfiguration(ctx context.Context) (any, error) { } +func (o *Operations) SetBaseMode(ctx context.Context, funcs ...protocol.SetBaseOptionFunc) error { + config, err := o.GetConfiguration(ctx) + if err != nil { + return errors.WithStack(err) + } + + opts := protocol.NewSetBaseOptions(funcs...) + + base := &model.Base{ + Accumulation: config.BaseMode.BaseCoordinates.Accumulation, + AntennaOffset: config.BaseMode.BaseCoordinates.AntennaOffset, + Coordinates: model.BaseCoordinates{ + Height: config.BaseMode.BaseCoordinates.Coordinates.Height, + Latitude: config.BaseMode.BaseCoordinates.Coordinates.Latitude, + Longitude: config.BaseMode.BaseCoordinates.Coordinates.Longitude, + }, + Mode: config.BaseMode.BaseCoordinates.Mode, + } + + if opts.Mode != nil { + base.Mode = *opts.Mode + } + + if opts.Accumulation != nil { + base.Accumulation = *opts.Accumulation + } + + if opts.Height != nil { + base.Coordinates.Height = *opts.Height + } + + if opts.Latitude != nil { + base.Coordinates.Latitude = *opts.Latitude + } + + if opts.Longitude != nil { + base.Coordinates.Longitude = *opts.Longitude + } + + if _, err := o.PostBaseMode(ctx, base); err != nil { + return errors.WithStack(err) + } + return nil +} + var _ protocol.Operations = &Operations{}