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
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetModemConfiguration implements protocol.Operations.
|
// SetBase implements protocol.Operations.
|
||||||
func (c *Client) GetModemAuthentication(ctx context.Context) (any, error) {
|
func (c *Client) SetBaseMode(ctx context.Context, funcs ...protocol.SetBaseOptionFunc) error {
|
||||||
_, ops, err := c.getProtocol(ctx)
|
_, ops, err := c.getProtocol(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithStack(err)
|
return errors.WithStack(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
config, err := ops.GetModemAuthentication(ctx)
|
if err := ops.SetBaseMode(ctx, funcs...); err != nil {
|
||||||
if err != nil {
|
return errors.WithStack(err)
|
||||||
return nil, errors.WithStack(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return config, nil
|
return 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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@@ -65,6 +65,5 @@ 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
|
SetBaseMode(ctx context.Context, funcs ...SetBaseOptionFunc) error
|
||||||
GetModemAuthentication(ctx context.Context) (any, error)
|
|
||||||
}
|
}
|
||||||
|
@@ -401,8 +401,9 @@ func (o *Operations) GetModemConfiguration(ctx context.Context) (any, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated : is no longer maintained for modules in V1
|
// Deprecated : is no longer maintained for modules in V1
|
||||||
func (o *Operations) GetModemAuthentication(ctx context.Context) (any, error) {
|
func (o *Operations) SetBaseMode(ctx context.Context, funcs ...protocol.SetBaseOptionFunc) error {
|
||||||
return nil, protocol.ErrUnimplemented
|
return protocol.ErrUnimplemented
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ protocol.Operations = &Operations{}
|
var _ protocol.Operations = &Operations{}
|
||||||
|
@@ -174,7 +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.ModemConfiguration, error) {
|
||||||
config := &model.ModemConfiguration{}
|
config := &model.ModemConfiguration{}
|
||||||
|
|
||||||
if err := o.GetJSON("/modem/1/info", config); err != nil {
|
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
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Operations) GetModemSettings(ctx context.Context) (*model.ModemAuthentication, error) {
|
func (o *Operations) PostBaseMode(ctx context.Context, base *model.Base) (*model.Base, error) {
|
||||||
config := &model.ModemAuthentication{}
|
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 nil, errors.WithStack(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return config, nil
|
return &updated, nil
|
||||||
}
|
}
|
||||||
|
@@ -3,13 +3,12 @@ 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 {
|
type ModemConfiguration struct {
|
||||||
@@ -18,10 +17,10 @@ type ModemConfiguration struct {
|
|||||||
AvailableAPNs []string `json:"available_apns,omitempty"`
|
AvailableAPNs []string `json:"available_apns,omitempty"`
|
||||||
CurrentAPN string `json:"current_apn"`
|
CurrentAPN string `json:"current_apn"`
|
||||||
CurrentMode string `json:"current_mode"`
|
CurrentMode string `json:"current_mode"`
|
||||||
FailReason string `json:"fail_reason,omitempty"`
|
FailReason *string `json:"fail_reason,omitempty"`
|
||||||
IMEI string `json:"imei"`
|
IMEI string `json:"imei"`
|
||||||
InternetAvailable string `json:"internet_available,omitempty"`
|
InternetAvailable string `json:"internet_available,omitempty"`
|
||||||
LockReason string `json:"lock_reason,omitempty"`
|
LockReason *string `json:"lock_reason,omitempty"`
|
||||||
OperatorName string `json:"operator_name"`
|
OperatorName string `json:"operator_name"`
|
||||||
PreferredMode string `json:"preferred_mode"`
|
PreferredMode string `json:"preferred_mode"`
|
||||||
RegistrationState string `json:"registration_state"`
|
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 {
|
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 {
|
|
||||||
modem.Pin = *opts.Pin
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
if opts.Apn != nil {
|
||||||
modem.Authentication.Apn = *opts.Apn
|
modem.Authentication.Apn = *opts.Apn
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.Type != nil {
|
if opts.Type != nil {
|
||||||
modem.Authentication.Type = *opts.Type
|
modem.Authentication.Type = *opts.Type
|
||||||
}
|
}
|
||||||
if opts.Username != nil {
|
|
||||||
modem.Authentication.Username = *opts.Username
|
|
||||||
}
|
|
||||||
if opts.Password != nil {
|
if opts.Password != nil {
|
||||||
modem.Authentication.Password = *opts.Password
|
modem.Authentication.Password = *opts.Password
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if opts.Username != nil {
|
||||||
|
modem.Authentication.Username = *opts.Username
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := o.PostModem(ctx, modem); err != nil {
|
if _, err := o.PostModem(ctx, modem); err != nil {
|
||||||
@@ -397,9 +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 {
|
if err != nil {
|
||||||
return nil, errors.WithStack(err)
|
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) SetBaseMode(ctx context.Context, funcs ...protocol.SetBaseOptionFunc) error {
|
||||||
func (o *Operations) GetModemAuthentication(ctx context.Context) (any, error) {
|
config, err := o.GetConfiguration(ctx)
|
||||||
config, err := o.GetModemSettings(ctx)
|
|
||||||
if err != nil {
|
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{}
|
var _ protocol.Operations = &Operations{}
|
||||||
|
Reference in New Issue
Block a user