feat(reachview): GetModemConfiguration func
This commit is contained in:
70
cmd/message/main.go
Normal file
70
cmd/message/main.go
Normal file
@ -0,0 +1,70 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
|
||||
reach "forge.cadoles.com/cadoles/go-emlid/reach/client"
|
||||
"forge.cadoles.com/cadoles/go-emlid/reach/client/logger"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
host string = "192.168.42.1"
|
||||
filter string = "task"
|
||||
rawLogLevel string = "ERROR"
|
||||
)
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&rawLogLevel, "log-level", rawLogLevel, "log level")
|
||||
flag.StringVar(&host, "host", host, "the reachrs module host")
|
||||
flag.StringVar(&filter, "filter", filter, "filter the type messages by name")
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
ctx := context.Background()
|
||||
client := reach.NewClient(host)
|
||||
|
||||
logLevel, err := logger.ParseLevel(rawLogLevel)
|
||||
if err != nil {
|
||||
fmt.Printf("[FATAL] %+v", errors.WithStack(err))
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
slog.SetLogLoggerLevel(logLevel)
|
||||
|
||||
if err := client.Connect(ctx); err != nil {
|
||||
fmt.Printf("[FATAL] %+v", errors.WithStack(err))
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err := client.Close(ctx); err != nil {
|
||||
fmt.Printf("[FATAL] %+v", errors.WithStack(err))
|
||||
os.Exit(1)
|
||||
}
|
||||
}()
|
||||
fmt.Println(filter)
|
||||
messages, err := reach.OnMessageType(ctx, client, filter)
|
||||
if err != nil {
|
||||
fmt.Printf("[FATAL] %+v", errors.WithStack(err))
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
for b := range messages {
|
||||
|
||||
data, err := json.MarshalIndent(b, "", " ")
|
||||
if err != nil {
|
||||
fmt.Printf("[ERROR] %+v", errors.WithStack(err))
|
||||
continue
|
||||
}
|
||||
|
||||
fmt.Println(string(data))
|
||||
}
|
||||
}
|
@ -207,4 +207,19 @@ func (c *Client) SetModem(ctx context.Context, funcs ...protocol.SetModemOptions
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetModemConfiguration implements protocol.Operations.
|
||||
func (c *Client) GetModemConfiguration(ctx context.Context) (any, error) {
|
||||
_, ops, err := c.getProtocol(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
config, err := ops.GetModemConfiguration(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
||||
var _ protocol.Operations = &Client{}
|
||||
|
@ -61,4 +61,7 @@ type Operations interface {
|
||||
|
||||
//SetModem updates mobile data config
|
||||
SetModem(ctx context.Context, funcs ...SetModemOptionsFunc) error
|
||||
|
||||
//GetModemConfiguration mobile data config
|
||||
GetModemConfiguration(ctx context.Context) (any, error)
|
||||
}
|
||||
|
@ -377,6 +377,29 @@ var testCases = []operationTestCase{
|
||||
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) {
|
||||
|
@ -1,16 +0,0 @@
|
||||
package testsuite
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"forge.cadoles.com/cadoles/go-emlid/reach/client"
|
||||
"forge.cadoles.com/cadoles/go-emlid/reach/client/protocol"
|
||||
)
|
||||
|
||||
func TestReachOperations(t *testing.T) {
|
||||
opsFactory := func(addr string) (protocol.Operations, error) {
|
||||
return client.NewClient(addr), nil
|
||||
}
|
||||
|
||||
TestOperations(t, opsFactory)
|
||||
}
|
@ -395,4 +395,9 @@ func (o *Operations) SetModem(ctx context.Context, funcs ...protocol.SetModemOpt
|
||||
return protocol.ErrUnimplemented
|
||||
}
|
||||
|
||||
// Deprecated : is no longer maintained for modules in V1
|
||||
func (o *Operations) GetModemConfiguration(ctx context.Context) (any, error) {
|
||||
return nil, protocol.ErrUnimplemented
|
||||
}
|
||||
|
||||
var _ protocol.Operations = &Operations{}
|
||||
|
@ -173,3 +173,13 @@ func (o *Operations) PostModem(ctx context.Context, config *model.ModemAuthentic
|
||||
|
||||
return &updated, nil
|
||||
}
|
||||
|
||||
func (o *Operations) GetModem(ctx context.Context) (*model.ModemConfiguration, error) {
|
||||
config := &model.ModemConfiguration{}
|
||||
|
||||
if err := o.GetJSON("/modem/1/info", config); err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
@ -2,5 +2,5 @@ package model
|
||||
|
||||
type Action struct {
|
||||
Name string `json:"name"`
|
||||
Paylaod map[string]any `json:"payload"`
|
||||
Paylaod map[string]any `json:"payload,omitempty"`
|
||||
}
|
||||
|
@ -10,3 +10,25 @@ type ModemAuthentication struct {
|
||||
Password string `json:"password,omitempty"`
|
||||
} `json:"authentication"`
|
||||
}
|
||||
|
||||
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"`
|
||||
}
|
||||
|
@ -399,4 +399,15 @@ func (o *Operations) SetModem(ctx context.Context, funcs ...protocol.SetModemOpt
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetModem implements protocol.Operations.
|
||||
func (o *Operations) GetModemConfiguration(ctx context.Context) (any, error) {
|
||||
config, err := o.GetModem(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return config, nil
|
||||
|
||||
}
|
||||
|
||||
var _ protocol.Operations = &Operations{}
|
||||
|
Reference in New Issue
Block a user