From 3224e1ef0f997fd8ee3df6fc579fa1077b6fdaff Mon Sep 17 00:00:00 2001 From: cmsassot Date: Wed, 11 Jun 2025 12:11:17 +0200 Subject: [PATCH] feat(modem): method to configure APN/authentication --- reach/client/operations.go | 14 +++++++ reach/client/protocol/modem.go | 41 +++++++++++++++++++ reach/client/protocol/operations.go | 3 ++ reach/client/protocol/testsuite/operations.go | 26 ++++++++++++ reach/client/protocol/v2/internal.go | 10 +++++ reach/client/protocol/v2/model/modem.go | 12 ++++++ reach/client/protocol/v2/operations.go | 27 ++++++++++++ 7 files changed, 133 insertions(+) create mode 100644 reach/client/protocol/modem.go create mode 100644 reach/client/protocol/v2/model/modem.go diff --git a/reach/client/operations.go b/reach/client/operations.go index 5e12c31..0d72f80 100644 --- a/reach/client/operations.go +++ b/reach/client/operations.go @@ -193,4 +193,18 @@ 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 +} + var _ protocol.Operations = &Client{} diff --git a/reach/client/protocol/modem.go b/reach/client/protocol/modem.go new file mode 100644 index 0000000..a58ca5d --- /dev/null +++ b/reach/client/protocol/modem.go @@ -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 + } +} diff --git a/reach/client/protocol/operations.go b/reach/client/protocol/operations.go index 0a029ea..97f35b1 100644 --- a/reach/client/protocol/operations.go +++ b/reach/client/protocol/operations.go @@ -58,4 +58,7 @@ type Operations interface { //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 } diff --git a/reach/client/protocol/testsuite/operations.go b/reach/client/protocol/testsuite/operations.go index f249c12..00a105b 100644 --- a/reach/client/protocol/testsuite/operations.go +++ b/reach/client/protocol/testsuite/operations.go @@ -329,6 +329,32 @@ var testCases = []operationTestCase{ }, }, + { + 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: "GetNTRIPMountPoint", Run: func(t *testing.T, ops protocol.Operations) { diff --git a/reach/client/protocol/v2/internal.go b/reach/client/protocol/v2/internal.go index fa9cb88..cf85c2f 100644 --- a/reach/client/protocol/v2/internal.go +++ b/reach/client/protocol/v2/internal.go @@ -162,3 +162,13 @@ 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 +} diff --git a/reach/client/protocol/v2/model/modem.go b/reach/client/protocol/v2/model/modem.go new file mode 100644 index 0000000..bfcf7da --- /dev/null +++ b/reach/client/protocol/v2/model/modem.go @@ -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"` +} diff --git a/reach/client/protocol/v2/operations.go b/reach/client/protocol/v2/operations.go index beb920a..2fd2c7a 100644 --- a/reach/client/protocol/v2/operations.go +++ b/reach/client/protocol/v2/operations.go @@ -362,4 +362,31 @@ 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 +} + var _ protocol.Operations = &Operations{}