Compare commits
1 Commits
master
...
c9c6115bf3
Author | SHA1 | Date | |
---|---|---|---|
c9c6115bf3 |
@@ -207,7 +207,7 @@ func (c *Client) SetModem(ctx context.Context, funcs ...protocol.SetModemOptions
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetModemConfiguration implements protocol.Operations.
|
// SetModem implements protocol.Operations.
|
||||||
func (c *Client) GetModemConfiguration(ctx context.Context) (any, error) {
|
func (c *Client) GetModemConfiguration(ctx context.Context) (any, error) {
|
||||||
_, ops, err := c.getProtocol(ctx)
|
_, ops, err := c.getProtocol(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -222,19 +222,4 @@ func (c *Client) GetModemConfiguration(ctx context.Context) (any, error) {
|
|||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetModemConfiguration implements protocol.Operations.
|
|
||||||
func (c *Client) GetModemAuthentication(ctx context.Context) (any, error) {
|
|
||||||
_, ops, err := c.getProtocol(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.WithStack(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
config, err := ops.GetModemAuthentication(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.WithStack(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return config, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ protocol.Operations = &Client{}
|
var _ protocol.Operations = &Client{}
|
||||||
|
@@ -5,7 +5,6 @@ type SetModemOptions struct {
|
|||||||
Type *string
|
Type *string
|
||||||
Username *string
|
Username *string
|
||||||
Password *string
|
Password *string
|
||||||
Pin *string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type SetModemOptionsFunc func(opts *SetModemOptions)
|
type SetModemOptionsFunc func(opts *SetModemOptions)
|
||||||
@@ -35,15 +34,8 @@ func WithUsername(value string) SetModemOptionsFunc {
|
|||||||
opts.Username = &value
|
opts.Username = &value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithPassword(value string) SetModemOptionsFunc {
|
func WithPassword(value string) SetModemOptionsFunc {
|
||||||
return func(opts *SetModemOptions) {
|
return func(opts *SetModemOptions) {
|
||||||
opts.Password = &value
|
opts.Password = &value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithPin(value string) SetModemOptionsFunc {
|
|
||||||
return func(opts *SetModemOptions) {
|
|
||||||
opts.Pin = &value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@@ -64,7 +64,4 @@ type Operations interface {
|
|||||||
|
|
||||||
//GetModemConfiguration mobile data config
|
//GetModemConfiguration mobile data config
|
||||||
GetModemConfiguration(ctx context.Context) (any, error)
|
GetModemConfiguration(ctx context.Context) (any, error)
|
||||||
|
|
||||||
//GetModemAuthentication mobile data config
|
|
||||||
GetModemAuthentication(ctx context.Context) (any, error)
|
|
||||||
}
|
}
|
||||||
|
@@ -377,29 +377,6 @@ var testCases = []operationTestCase{
|
|||||||
t.Logf("Message : %+v", taskMsg)
|
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)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOperations(t *testing.T, opsFactory OperationsFactoryFunc) {
|
func TestOperations(t *testing.T, opsFactory OperationsFactoryFunc) {
|
||||||
|
@@ -400,9 +400,4 @@ func (o *Operations) GetModemConfiguration(ctx context.Context) (any, error) {
|
|||||||
return nil, protocol.ErrUnimplemented
|
return nil, protocol.ErrUnimplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated : is no longer maintained for modules in V1
|
|
||||||
func (o *Operations) GetModemAuthentication(ctx context.Context) (any, error) {
|
|
||||||
return nil, protocol.ErrUnimplemented
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ protocol.Operations = &Operations{}
|
var _ protocol.Operations = &Operations{}
|
||||||
|
@@ -174,17 +174,7 @@ func (o *Operations) PostModem(ctx context.Context, config *model.ModemAuthentic
|
|||||||
return &updated, nil
|
return &updated, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Operations) GetModemInfo(ctx context.Context) (*model.ModemConfiguration, error) {
|
func (o *Operations) GetModem(ctx context.Context) (*model.ModemAuthentication, error) {
|
||||||
config := &model.ModemConfiguration{}
|
|
||||||
|
|
||||||
if err := o.GetJSON("/modem/1/info", config); err != nil {
|
|
||||||
return nil, errors.WithStack(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return config, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o *Operations) GetModemSettings(ctx context.Context) (*model.ModemAuthentication, error) {
|
|
||||||
config := &model.ModemAuthentication{}
|
config := &model.ModemAuthentication{}
|
||||||
|
|
||||||
if err := o.GetJSON("/modem/1/settings", config); err != nil {
|
if err := o.GetJSON("/modem/1/settings", config); err != nil {
|
||||||
|
@@ -3,33 +3,10 @@ package model
|
|||||||
// type : null, pap_chap, pap, chap
|
// type : null, pap_chap, pap, chap
|
||||||
// if type selected, username and password are mandatory
|
// if type selected, username and password are mandatory
|
||||||
type ModemAuthentication struct {
|
type ModemAuthentication struct {
|
||||||
Authentication *struct {
|
Authentication struct {
|
||||||
Apn string `json:"apn,omitempty"`
|
Apn string `json:"apn"`
|
||||||
Type string `json:"type,omitempty"`
|
Type string `json:"type,omitempty"`
|
||||||
Username string `json:"username,omitempty"`
|
Username string `json:"username,omitempty"`
|
||||||
Password string `json:"password,omitempty"`
|
Password string `json:"password,omitempty"`
|
||||||
} `json:"authentication,omitempty"`
|
} `json:"authentication"`
|
||||||
Pin string `json:"pin,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
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"`
|
|
||||||
}
|
}
|
||||||
|
@@ -281,6 +281,17 @@ func (o *Operations) AveragePosition(ctx context.Context) (*protocol.TaskMessage
|
|||||||
if err = o.client.Emit("task", &model.Action{Name: "average_base_coordinates"}); err != nil {
|
if err = o.client.Emit("task", &model.Action{Name: "average_base_coordinates"}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
ch, err := o.On(ctx, "task_status")
|
||||||
|
for message := range ch {
|
||||||
|
var taskMsg protocol.TaskMessage[protocol.AveragePositionPayload]
|
||||||
|
if err := mapstructure.Decode(message, &taskMsg); err != nil {
|
||||||
|
return nil, errors.WithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if taskMsg.State == "completed" {
|
||||||
|
return &taskMsg, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -366,29 +377,20 @@ func (o *Operations) SetBaseCorrections(ctx context.Context, funcs ...protocol.S
|
|||||||
func (o *Operations) SetModem(ctx context.Context, funcs ...protocol.SetModemOptionsFunc) error {
|
func (o *Operations) SetModem(ctx context.Context, funcs ...protocol.SetModemOptionsFunc) error {
|
||||||
opts := protocol.NewSetModemOptions(funcs...)
|
opts := protocol.NewSetModemOptions(funcs...)
|
||||||
modem := &model.ModemAuthentication{}
|
modem := &model.ModemAuthentication{}
|
||||||
if opts.Pin != nil {
|
if opts.Apn != nil {
|
||||||
modem.Pin = *opts.Pin
|
modem.Authentication.Apn = *opts.Apn
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.Apn != nil || opts.Type != nil || opts.Username != nil || opts.Password != nil {
|
if opts.Type != nil {
|
||||||
modem.Authentication = &struct {
|
modem.Authentication.Type = *opts.Type
|
||||||
Apn string `json:"apn,omitempty"`
|
}
|
||||||
Type string `json:"type,omitempty"`
|
|
||||||
Username string `json:"username,omitempty"`
|
if opts.Password != nil {
|
||||||
Password string `json:"password,omitempty"`
|
modem.Authentication.Password = *opts.Password
|
||||||
}{}
|
}
|
||||||
if opts.Apn != nil {
|
|
||||||
modem.Authentication.Apn = *opts.Apn
|
if opts.Username != nil {
|
||||||
}
|
modem.Authentication.Username = *opts.Username
|
||||||
if opts.Type != nil {
|
|
||||||
modem.Authentication.Type = *opts.Type
|
|
||||||
}
|
|
||||||
if opts.Username != nil {
|
|
||||||
modem.Authentication.Username = *opts.Username
|
|
||||||
}
|
|
||||||
if opts.Password != nil {
|
|
||||||
modem.Authentication.Password = *opts.Password
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := o.PostModem(ctx, modem); err != nil {
|
if _, err := o.PostModem(ctx, modem); err != nil {
|
||||||
@@ -397,20 +399,9 @@ func (o *Operations) SetModem(ctx context.Context, funcs ...protocol.SetModemOpt
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetModem implements protocol.Operations.
|
// SetModem implements protocol.Operations.
|
||||||
func (o *Operations) GetModemConfiguration(ctx context.Context) (any, error) {
|
func (o *Operations) GetModemConfiguration(ctx context.Context) (any, error) {
|
||||||
config, err := o.GetModemInfo(ctx)
|
config, err := o.GetModem(ctx)
|
||||||
if err != nil {
|
|
||||||
return nil, errors.WithStack(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return config, nil
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetModemSettings implements protocol.Operations.
|
|
||||||
func (o *Operations) GetModemAuthentication(ctx context.Context) (any, error) {
|
|
||||||
config, err := o.GetModemSettings(ctx)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithStack(err)
|
return nil, errors.WithStack(err)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user