feat(AveragePosition/GetNTRIPMountPoint): change return type, update cmd average_position
This commit is contained in:
@ -8,6 +8,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"forge.cadoles.com/cadoles/go-emlid/reach/client/protocol"
|
||||
"forge.cadoles.com/cadoles/go-emlid/reach/client/protocol/v2/model"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
@ -126,8 +127,8 @@ func (o *Operations) PostDevice(ctx context.Context, device *model.Configuration
|
||||
return &updated, nil
|
||||
}
|
||||
|
||||
func (o *Operations) PostBaseCorrection(ctx context.Context, base *model.IOConfig) (*model.IOConfig, error) {
|
||||
var updated model.IOConfig
|
||||
func (o *Operations) PostBaseCorrection(ctx context.Context, base *protocol.IOConfig) (*protocol.IOConfig, error) {
|
||||
var updated protocol.IOConfig
|
||||
|
||||
if err := o.PostJSON("/configuration/correction_input/base_corrections", base, &updated); err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
|
@ -1,81 +0,0 @@
|
||||
package model
|
||||
|
||||
type IOConfig struct {
|
||||
IOType string `json:"io_type"`
|
||||
Settings IOConfigSettings `json:"settings"`
|
||||
}
|
||||
|
||||
type IOConfigSettings struct {
|
||||
NTRIPCli NTRIPCliConfig `json:"ntripcli"`
|
||||
}
|
||||
|
||||
type NTRIPCliConfig struct {
|
||||
Address string `json:"address"`
|
||||
Port int `json:"port"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
MountPoint string `json:"mount_point"`
|
||||
SendPositionToBase bool `json:"send_position_to_base"`
|
||||
}
|
||||
|
||||
type NTRIPResponse struct {
|
||||
Name string `json:"name"`
|
||||
Payload NTRIPPayload `json:"payload"`
|
||||
State string `json:"state"`
|
||||
}
|
||||
|
||||
type NTRIPPayload struct {
|
||||
CAS []CasterInfo `json:"cas"`
|
||||
Net []NetworkInfo `json:"net"`
|
||||
Str []StreamInfo `json:"str"`
|
||||
}
|
||||
|
||||
type CasterInfo struct {
|
||||
Country string `json:"country"`
|
||||
Distance float64 `json:"distance"`
|
||||
FallbackHost string `json:"fallback_host"`
|
||||
FallbackPort string `json:"fallback_port"`
|
||||
Host string `json:"host"`
|
||||
ID string `json:"id"`
|
||||
Latitude string `json:"latitude"`
|
||||
Longitude string `json:"longitude"`
|
||||
NMEA string `json:"nmea"`
|
||||
Operator string `json:"operator"`
|
||||
OtherDetails *string `json:"other_details"`
|
||||
Port string `json:"port"`
|
||||
Site string `json:"site"`
|
||||
}
|
||||
|
||||
type NetworkInfo struct {
|
||||
Authentication string `json:"authentication"`
|
||||
Distance *float64 `json:"distance"`
|
||||
Fee string `json:"fee"`
|
||||
ID string `json:"id"`
|
||||
Operator string `json:"operator"`
|
||||
OtherDetails string `json:"other_details"`
|
||||
WebNet string `json:"web_net"`
|
||||
WebReg string `json:"web_reg"`
|
||||
WebStr string `json:"web_str"`
|
||||
}
|
||||
|
||||
type StreamInfo struct {
|
||||
Authentication string `json:"authentication"`
|
||||
Bitrate string `json:"bitrate"`
|
||||
Carrier string `json:"carrier"`
|
||||
ComprEncryp string `json:"compr_encryp"`
|
||||
Country string `json:"country"`
|
||||
Distance float64 `json:"distance"`
|
||||
Fee string `json:"fee"`
|
||||
Format string `json:"format"`
|
||||
FormatDetails string `json:"format_details"`
|
||||
Generator string `json:"generator"`
|
||||
ID string `json:"id"`
|
||||
Latitude string `json:"latitude"`
|
||||
Longitude string `json:"longitude"`
|
||||
Mountpoint string `json:"mountpoint"`
|
||||
NavSystem string `json:"nav_system"`
|
||||
Network string `json:"network"`
|
||||
NMEA string `json:"nmea"`
|
||||
OtherDetails string `json:"other_details"`
|
||||
Solution string `json:"solution"`
|
||||
}
|
@ -2,7 +2,6 @@ package v2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
@ -11,6 +10,7 @@ import (
|
||||
"forge.cadoles.com/cadoles/go-emlid/reach/client/protocol/v2/model"
|
||||
|
||||
"forge.cadoles.com/cadoles/go-emlid/reach/client/socketio"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@ -270,7 +270,7 @@ func (o *Operations) On(ctx context.Context, event string) (chan any, error) {
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (o *Operations) AveragePosition(ctx context.Context) (*protocol.TaskMessage, error) {
|
||||
func (o *Operations) AveragePosition(ctx context.Context) (*protocol.TaskMessage[protocol.AveragePositionPayload], error) {
|
||||
var err error
|
||||
|
||||
go func() {
|
||||
@ -283,15 +283,9 @@ func (o *Operations) AveragePosition(ctx context.Context) (*protocol.TaskMessage
|
||||
}
|
||||
ch, err := o.On(ctx, "task_status")
|
||||
for message := range ch {
|
||||
// Convertir vers notre struct
|
||||
jsonData, err := json.Marshal(message)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
var taskMsg protocol.TaskMessage
|
||||
if err := json.Unmarshal(jsonData, &taskMsg); err != nil {
|
||||
continue
|
||||
var taskMsg protocol.TaskMessage[protocol.AveragePositionPayload]
|
||||
if err := mapstructure.Decode(message, &taskMsg); err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
if taskMsg.State == "completed" {
|
||||
@ -302,12 +296,12 @@ func (o *Operations) AveragePosition(ctx context.Context) (*protocol.TaskMessage
|
||||
}
|
||||
|
||||
// GetNTRIPMountPoint implements protocol.Operations.
|
||||
func (o *Operations) GetNTRIPMountPoint(ctx context.Context) error {
|
||||
func (o *Operations) GetNTRIPMountPoint(ctx context.Context) (*protocol.TaskMessage[protocol.NTRIPPayload], error) {
|
||||
var err error
|
||||
|
||||
config, err := o.GetConfiguration(ctx)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
go func() {
|
||||
@ -321,10 +315,21 @@ func (o *Operations) GetNTRIPMountPoint(ctx context.Context) error {
|
||||
}
|
||||
|
||||
if err = o.client.Emit("task", &model.Action{Name: "get_ntrip_mountpoints", Paylaod: payload}); err != nil {
|
||||
return err
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return err
|
||||
ch, err := o.On(ctx, "task_status")
|
||||
for message := range ch {
|
||||
var taskMsg protocol.TaskMessage[protocol.NTRIPPayload]
|
||||
if err := mapstructure.Decode(message, &taskMsg); err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
if taskMsg.State == "completed" {
|
||||
return &taskMsg, nil
|
||||
}
|
||||
}
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
// SetBaseCorrections implements protocol.Operations.
|
||||
@ -346,11 +351,11 @@ func (o *Operations) SetBaseCorrections(ctx context.Context, funcs ...protocol.S
|
||||
return errors.New("NTRIP mount point is required")
|
||||
}
|
||||
|
||||
config := &model.IOConfig{
|
||||
config := &protocol.IOConfig{
|
||||
// todo parametrage du type
|
||||
IOType: "ntripcli",
|
||||
Settings: model.IOConfigSettings{
|
||||
NTRIPCli: model.NTRIPCliConfig{
|
||||
Settings: protocol.IOConfigSettings{
|
||||
NTRIPCli: protocol.NTRIPCliConfig{
|
||||
Address: *opts.Address,
|
||||
Port: *opts.Port,
|
||||
Username: *opts.Username,
|
||||
|
Reference in New Issue
Block a user