Compare commits
1 Commits
master
...
08f12ab5cb
Author | SHA1 | Date | |
---|---|---|---|
08f12ab5cb |
@@ -222,19 +222,18 @@ func (c *Client) GetModemConfiguration(ctx context.Context) (any, error) {
|
||||
return config, nil
|
||||
}
|
||||
|
||||
// GetModemConfiguration implements protocol.Operations.
|
||||
func (c *Client) GetModemAuthentication(ctx context.Context) (any, error) {
|
||||
// SetBase implements protocol.Operations.
|
||||
func (c *Client) SetBaseMode(ctx context.Context, funcs ...protocol.SetBaseOptionFunc) error {
|
||||
_, ops, err := c.getProtocol(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
config, err := ops.GetModemAuthentication(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
if err := ops.SetBaseMode(ctx, funcs...); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
return config, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
var _ protocol.Operations = &Client{}
|
||||
|
@@ -5,7 +5,6 @@ type SetModemOptions struct {
|
||||
Type *string
|
||||
Username *string
|
||||
Password *string
|
||||
Pin *string
|
||||
}
|
||||
|
||||
type SetModemOptionsFunc func(opts *SetModemOptions)
|
||||
@@ -35,15 +34,8 @@ func WithUsername(value string) SetModemOptionsFunc {
|
||||
opts.Username = &value
|
||||
}
|
||||
}
|
||||
|
||||
func WithPassword(value string) SetModemOptionsFunc {
|
||||
return func(opts *SetModemOptions) {
|
||||
opts.Password = &value
|
||||
}
|
||||
}
|
||||
|
||||
func WithPin(value string) SetModemOptionsFunc {
|
||||
return func(opts *SetModemOptions) {
|
||||
opts.Pin = &value
|
||||
}
|
||||
}
|
||||
|
@@ -65,6 +65,5 @@ type Operations interface {
|
||||
//GetModemConfiguration mobile data config
|
||||
GetModemConfiguration(ctx context.Context) (any, error)
|
||||
|
||||
//GetModemAuthentication mobile data config
|
||||
GetModemAuthentication(ctx context.Context) (any, error)
|
||||
SetBaseMode(ctx context.Context, funcs ...SetBaseOptionFunc) error
|
||||
}
|
||||
|
@@ -401,8 +401,9 @@ func (o *Operations) GetModemConfiguration(ctx context.Context) (any, error) {
|
||||
}
|
||||
|
||||
// Deprecated : is no longer maintained for modules in V1
|
||||
func (o *Operations) GetModemAuthentication(ctx context.Context) (any, error) {
|
||||
return nil, protocol.ErrUnimplemented
|
||||
func (o *Operations) SetBaseMode(ctx context.Context, funcs ...protocol.SetBaseOptionFunc) error {
|
||||
return protocol.ErrUnimplemented
|
||||
|
||||
}
|
||||
|
||||
var _ protocol.Operations = &Operations{}
|
||||
|
@@ -174,7 +174,7 @@ func (o *Operations) PostModem(ctx context.Context, config *model.ModemAuthentic
|
||||
return &updated, nil
|
||||
}
|
||||
|
||||
func (o *Operations) GetModemInfo(ctx context.Context) (*model.ModemConfiguration, error) {
|
||||
func (o *Operations) GetModem(ctx context.Context) (*model.ModemConfiguration, error) {
|
||||
config := &model.ModemConfiguration{}
|
||||
|
||||
if err := o.GetJSON("/modem/1/info", config); err != nil {
|
||||
@@ -184,12 +184,12 @@ func (o *Operations) GetModemInfo(ctx context.Context) (*model.ModemConfiguratio
|
||||
return config, nil
|
||||
}
|
||||
|
||||
func (o *Operations) GetModemSettings(ctx context.Context) (*model.ModemAuthentication, error) {
|
||||
config := &model.ModemAuthentication{}
|
||||
func (o *Operations) PostBaseMode(ctx context.Context, base *model.Base) (*model.Base, error) {
|
||||
var updated model.Base
|
||||
|
||||
if err := o.GetJSON("/modem/1/settings", config); err != nil {
|
||||
if err := o.PostJSON("/configuration/base_mode", base, &updated); err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return config, nil
|
||||
return &updated, nil
|
||||
}
|
||||
|
@@ -3,13 +3,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,omitempty"`
|
||||
Authentication struct {
|
||||
Apn string `json:"apn"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Username string `json:"username,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
} `json:"authentication,omitempty"`
|
||||
Pin string `json:"pin,omitempty"`
|
||||
} `json:"authentication"`
|
||||
}
|
||||
|
||||
type ModemConfiguration struct {
|
||||
@@ -18,10 +17,10 @@ type ModemConfiguration struct {
|
||||
AvailableAPNs []string `json:"available_apns,omitempty"`
|
||||
CurrentAPN string `json:"current_apn"`
|
||||
CurrentMode string `json:"current_mode"`
|
||||
FailReason string `json:"fail_reason,omitempty"`
|
||||
FailReason *string `json:"fail_reason,omitempty"`
|
||||
IMEI string `json:"imei"`
|
||||
InternetAvailable string `json:"internet_available,omitempty"`
|
||||
LockReason string `json:"lock_reason,omitempty"`
|
||||
LockReason *string `json:"lock_reason,omitempty"`
|
||||
OperatorName string `json:"operator_name"`
|
||||
PreferredMode string `json:"preferred_mode"`
|
||||
RegistrationState string `json:"registration_state"`
|
||||
|
@@ -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 {
|
||||
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
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
opts := protocol.NewSetModemOptions(funcs...)
|
||||
modem := &model.ModemAuthentication{}
|
||||
if opts.Pin != nil {
|
||||
modem.Pin = *opts.Pin
|
||||
if opts.Apn != nil {
|
||||
modem.Authentication.Apn = *opts.Apn
|
||||
}
|
||||
|
||||
if opts.Apn != nil || opts.Type != nil || opts.Username != nil || opts.Password != nil {
|
||||
modem.Authentication = &struct {
|
||||
Apn string `json:"apn,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Username string `json:"username,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
}{}
|
||||
if opts.Apn != nil {
|
||||
modem.Authentication.Apn = *opts.Apn
|
||||
}
|
||||
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 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 {
|
||||
@@ -397,9 +399,9 @@ func (o *Operations) SetModem(ctx context.Context, funcs ...protocol.SetModemOpt
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetModem implements protocol.Operations.
|
||||
// SetModem implements protocol.Operations.
|
||||
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)
|
||||
}
|
||||
@@ -408,15 +410,49 @@ func (o *Operations) GetModemConfiguration(ctx context.Context) (any, error) {
|
||||
|
||||
}
|
||||
|
||||
// GetModemSettings implements protocol.Operations.
|
||||
func (o *Operations) GetModemAuthentication(ctx context.Context) (any, error) {
|
||||
config, err := o.GetModemSettings(ctx)
|
||||
func (o *Operations) SetBaseMode(ctx context.Context, funcs ...protocol.SetBaseOptionFunc) error {
|
||||
config, err := o.GetConfiguration(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
return config, nil
|
||||
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{}
|
||||
|
Reference in New Issue
Block a user