wip getModem
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))
|
||||||
|
}
|
||||||
|
}
|
@ -61,4 +61,7 @@ type Operations interface {
|
|||||||
|
|
||||||
//SetModem updates mobile data config
|
//SetModem updates mobile data config
|
||||||
SetModem(ctx context.Context, funcs ...SetModemOptionsFunc) error
|
SetModem(ctx context.Context, funcs ...SetModemOptionsFunc) error
|
||||||
|
|
||||||
|
//GetModemConfiguration mobile data config
|
||||||
|
GetModemConfiguration(ctx context.Context, funcs ...SetModemOptionsFunc) (any, error)
|
||||||
}
|
}
|
||||||
|
@ -395,4 +395,9 @@ func (o *Operations) SetModem(ctx context.Context, funcs ...protocol.SetModemOpt
|
|||||||
return protocol.ErrUnimplemented
|
return protocol.ErrUnimplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated : is no longer maintained for modules in V1
|
||||||
|
func (o *Operations) GetModemConfiguration(ctx context.Context, funcs ...protocol.SetModemOptionsFunc) (*model.ModemAuthentication, error) {
|
||||||
|
return nil, protocol.ErrUnimplemented
|
||||||
|
}
|
||||||
|
|
||||||
var _ protocol.Operations = &Operations{}
|
var _ protocol.Operations = &Operations{}
|
||||||
|
@ -173,3 +173,13 @@ func (o *Operations) PostModem(ctx context.Context, config *model.ModemAuthentic
|
|||||||
|
|
||||||
return &updated, nil
|
return &updated, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (o *Operations) GetModem(ctx context.Context) (*model.ModemAuthentication, error) {
|
||||||
|
config := &model.ModemAuthentication{}
|
||||||
|
|
||||||
|
if err := o.GetJSON("/modem/1/settings", config); err != nil {
|
||||||
|
return nil, errors.WithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return config, nil
|
||||||
|
}
|
||||||
|
@ -2,5 +2,5 @@ package model
|
|||||||
|
|
||||||
type Action struct {
|
type Action struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Paylaod map[string]any `json:"payload"`
|
Paylaod map[string]any `json:"payload,omitempty"`
|
||||||
}
|
}
|
||||||
|
@ -399,4 +399,15 @@ func (o *Operations) SetModem(ctx context.Context, funcs ...protocol.SetModemOpt
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetModem implements protocol.Operations.
|
||||||
|
func (o *Operations) GetModemConfiguration(ctx context.Context, funcs ...protocol.SetModemOptionsFunc) (any, error) {
|
||||||
|
config, err := o.GetModem(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return config, nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
var _ protocol.Operations = &Operations{}
|
var _ protocol.Operations = &Operations{}
|
||||||
|
Reference in New Issue
Block a user