feat: initial commit
This commit is contained in:
7
reach/client/protocol/v2/init.go
Normal file
7
reach/client/protocol/v2/init.go
Normal file
@ -0,0 +1,7 @@
|
||||
package v2
|
||||
|
||||
import "forge.cadoles.com/cadoles/go-emlid/reach/client/protocol"
|
||||
|
||||
func init() {
|
||||
protocol.Register(&Protocol{})
|
||||
}
|
127
reach/client/protocol/v2/internal.go
Normal file
127
reach/client/protocol/v2/internal.go
Normal file
@ -0,0 +1,127 @@
|
||||
package v2
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"forge.cadoles.com/cadoles/go-emlid/reach/client/protocol/v2/model"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func (o *Operations) getURL(path string) string {
|
||||
return fmt.Sprintf("http://%s%s", o.addr, path)
|
||||
}
|
||||
|
||||
func (o *Operations) GetJSON(path string, dst any) error {
|
||||
var res *http.Response
|
||||
|
||||
url := o.getURL(path)
|
||||
res, err := http.Get(url)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
if res.StatusCode < http.StatusOK || res.StatusCode >= http.StatusBadRequest {
|
||||
return errors.Errorf("unexpected http status code %d (%s)", res.StatusCode, res.Status)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err := res.Body.Close(); err != nil {
|
||||
errors.WithStack(err)
|
||||
}
|
||||
}()
|
||||
|
||||
var body []byte
|
||||
|
||||
body, err = io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(body, dst); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Operations) PostJSON(path string, data any, dst any) error {
|
||||
var res *http.Response
|
||||
|
||||
var buf bytes.Buffer
|
||||
|
||||
encoder := json.NewEncoder(&buf)
|
||||
if err := encoder.Encode(data); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
url := o.getURL(path)
|
||||
res, err := http.Post(url, "application/json", &buf)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
if res.StatusCode < http.StatusOK || res.StatusCode >= http.StatusBadRequest {
|
||||
return errors.Errorf("unexpected http status code %d (%s)", res.StatusCode, res.Status)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err := res.Body.Close(); err != nil {
|
||||
errors.WithStack(err)
|
||||
}
|
||||
}()
|
||||
|
||||
var body []byte
|
||||
|
||||
body, err = io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(body, dst); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *Operations) PostBaseCoordinates(ctx context.Context, base *model.Base) (*model.Base, error) {
|
||||
var updated model.Base
|
||||
|
||||
if err := o.PostJSON("/configuration/base_mode/base_coordinates", base, &updated); err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return &updated, nil
|
||||
}
|
||||
|
||||
func (o *Operations) GetUpdater(ctx context.Context) (*model.Updater, error) {
|
||||
updater := &model.Updater{}
|
||||
if err := o.GetJSON("/updater", updater); err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return updater, nil
|
||||
}
|
||||
|
||||
func (o *Operations) GetInfo(ctx context.Context) (*model.Info, error) {
|
||||
info := &model.Info{}
|
||||
if err := o.GetJSON("/info", info); err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return info, nil
|
||||
}
|
||||
|
||||
func (o *Operations) GetConfiguration(ctx context.Context) (*model.Configuration, error) {
|
||||
config := &model.Configuration{}
|
||||
if err := o.GetJSON("/configuration", config); err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
5
reach/client/protocol/v2/model/action.go
Normal file
5
reach/client/protocol/v2/model/action.go
Normal file
@ -0,0 +1,5 @@
|
||||
package model
|
||||
|
||||
type Action struct {
|
||||
Name string `json:"name"`
|
||||
}
|
14
reach/client/protocol/v2/model/base.go
Normal file
14
reach/client/protocol/v2/model/base.go
Normal file
@ -0,0 +1,14 @@
|
||||
package model
|
||||
|
||||
type Base struct {
|
||||
Accumulation int `json:"accumulation,omitempty"`
|
||||
AntennaOffset float64 `json:"antenna_offset,omitempty"`
|
||||
Coordinates BaseCoordinates `json:"coordinates,omitempty"`
|
||||
Mode string `json:"mode,omitempty"`
|
||||
}
|
||||
|
||||
type BaseCoordinates struct {
|
||||
Height float64 `json:"height,omitempty"`
|
||||
Latitude float64 `json:"latitude,omitempty"`
|
||||
Longitude float64 `json:"longitude,omitempty"`
|
||||
}
|
563
reach/client/protocol/v2/model/configuration.go
Normal file
563
reach/client/protocol/v2/model/configuration.go
Normal file
@ -0,0 +1,563 @@
|
||||
package model
|
||||
|
||||
type Configuration struct {
|
||||
BaseMode struct {
|
||||
BaseCoordinates struct {
|
||||
Accumulation int `json:"accumulation,omitempty"`
|
||||
AntennaOffset float64 `json:"antenna_offset,omitempty"`
|
||||
Coordinates struct {
|
||||
Height float64 `json:"height,omitempty"`
|
||||
Latitude float64 `json:"latitude,omitempty"`
|
||||
Longitude float64 `json:"longitude,omitempty"`
|
||||
} `json:"coordinates,omitempty"`
|
||||
Mode string `json:"mode,omitempty"`
|
||||
} `json:"base_coordinates,omitempty"`
|
||||
Output struct {
|
||||
IoType string `json:"io_type,omitempty"`
|
||||
Settings struct {
|
||||
Lora struct {
|
||||
AirRate float64 `json:"air_rate,omitempty"`
|
||||
Frequency int `json:"frequency,omitempty"`
|
||||
OutputPower int `json:"output_power,omitempty"`
|
||||
} `json:"lora,omitempty"`
|
||||
Ntripcaster struct {
|
||||
MountPoint string `json:"mount_point,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
Port int `json:"port,omitempty"`
|
||||
Username string `json:"username,omitempty"`
|
||||
} `json:"ntripcaster,omitempty"`
|
||||
Ntripsvr struct {
|
||||
Address string `json:"address,omitempty"`
|
||||
MountPoint string `json:"mount_point,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
Port int `json:"port,omitempty"`
|
||||
} `json:"ntripsvr,omitempty"`
|
||||
Serial struct {
|
||||
BaudRate int `json:"baud_rate,omitempty"`
|
||||
Device string `json:"device,omitempty"`
|
||||
} `json:"serial,omitempty"`
|
||||
Tcpcli struct {
|
||||
Address string `json:"address,omitempty"`
|
||||
Port int `json:"port,omitempty"`
|
||||
} `json:"tcpcli,omitempty"`
|
||||
Tcpsvr struct {
|
||||
Port int `json:"port,omitempty"`
|
||||
} `json:"tcpsvr,omitempty"`
|
||||
} `json:"settings,omitempty"`
|
||||
} `json:"output,omitempty"`
|
||||
Rtcm3Messages struct {
|
||||
Num1004 struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
Frequency int `json:"frequency,omitempty"`
|
||||
} `json:"1004,omitempty"`
|
||||
Num1006 struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
Frequency float64 `json:"frequency,omitempty"`
|
||||
} `json:"1006,omitempty"`
|
||||
Num1008 struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
Frequency float64 `json:"frequency,omitempty"`
|
||||
} `json:"1008,omitempty"`
|
||||
Num1012 struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
Frequency int `json:"frequency,omitempty"`
|
||||
} `json:"1012,omitempty"`
|
||||
Num1033 struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
Frequency float64 `json:"frequency,omitempty"`
|
||||
} `json:"1033,omitempty"`
|
||||
Num1074 struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
Frequency float64 `json:"frequency,omitempty"`
|
||||
} `json:"1074,omitempty"`
|
||||
Num1084 struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
Frequency float64 `json:"frequency,omitempty"`
|
||||
} `json:"1084,omitempty"`
|
||||
Num1094 struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
Frequency float64 `json:"frequency,omitempty"`
|
||||
} `json:"1094,omitempty"`
|
||||
Num1124 struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
Frequency float64 `json:"frequency,omitempty"`
|
||||
} `json:"1124,omitempty"`
|
||||
Num1230 struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
Frequency float64 `json:"frequency,omitempty"`
|
||||
} `json:"1230,omitempty"`
|
||||
} `json:"rtcm3_messages,omitempty"`
|
||||
} `json:"base_mode,omitempty"`
|
||||
Bluetooth struct {
|
||||
BleEnabled bool `json:"ble_enabled,omitempty"`
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
Pairing struct {
|
||||
Discoverable bool `json:"discoverable,omitempty"`
|
||||
NoInputNoOutput bool `json:"no_input_no_output,omitempty"`
|
||||
Pin string `json:"pin,omitempty"`
|
||||
} `json:"pairing,omitempty"`
|
||||
} `json:"bluetooth,omitempty"`
|
||||
CorrectionInput struct {
|
||||
BaseCorrections struct {
|
||||
IoType string `json:"io_type,omitempty"`
|
||||
LastUsed struct {
|
||||
Ntrip string `json:"ntrip,omitempty"`
|
||||
Radio string `json:"radio,omitempty"`
|
||||
TCP string `json:"tcp,omitempty"`
|
||||
} `json:"last_used,omitempty"`
|
||||
Settings struct {
|
||||
Ble struct {
|
||||
Address string `json:"address,omitempty"`
|
||||
MountPoint string `json:"mount_point,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
Port int `json:"port,omitempty"`
|
||||
SendPositionToBase bool `json:"send_position_to_base,omitempty"`
|
||||
Username string `json:"username,omitempty"`
|
||||
} `json:"ble,omitempty"`
|
||||
Bluetooth struct {
|
||||
SendPositionToBase bool `json:"send_position_to_base,omitempty"`
|
||||
} `json:"bluetooth,omitempty"`
|
||||
Lora struct {
|
||||
AirRate float64 `json:"air_rate,omitempty"`
|
||||
Frequency int `json:"frequency,omitempty"`
|
||||
OutputPower int `json:"output_power,omitempty"`
|
||||
SendPositionToBase bool `json:"send_position_to_base,omitempty"`
|
||||
} `json:"lora,omitempty"`
|
||||
Ntripcli struct {
|
||||
Address string `json:"address,omitempty"`
|
||||
MountPoint string `json:"mount_point,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
Port int `json:"port,omitempty"`
|
||||
SendPositionToBase bool `json:"send_position_to_base,omitempty"`
|
||||
Username string `json:"username,omitempty"`
|
||||
} `json:"ntripcli,omitempty"`
|
||||
Serial struct {
|
||||
BaudRate int `json:"baud_rate,omitempty"`
|
||||
Device string `json:"device,omitempty"`
|
||||
SendPositionToBase bool `json:"send_position_to_base,omitempty"`
|
||||
} `json:"serial,omitempty"`
|
||||
Tcpcli struct {
|
||||
Address string `json:"address,omitempty"`
|
||||
Port int `json:"port,omitempty"`
|
||||
SendPositionToBase bool `json:"send_position_to_base,omitempty"`
|
||||
} `json:"tcpcli,omitempty"`
|
||||
Tcpsvr struct {
|
||||
Port int `json:"port,omitempty"`
|
||||
SendPositionToBase bool `json:"send_position_to_base,omitempty"`
|
||||
} `json:"tcpsvr,omitempty"`
|
||||
} `json:"settings,omitempty"`
|
||||
} `json:"base_corrections,omitempty"`
|
||||
} `json:"correction_input,omitempty"`
|
||||
Device struct {
|
||||
AntennaHeight float64 `json:"antenna_height,omitempty"`
|
||||
NightMode bool `json:"night_mode,omitempty"`
|
||||
OnboardingShown bool `json:"onboarding_shown,omitempty"`
|
||||
PowerOnBottomConnector bool `json:"power_on_bottom_connector,omitempty"`
|
||||
PrivacyPolicyAccepted bool `json:"privacy_policy_accepted,omitempty"`
|
||||
Role string `json:"role,omitempty"`
|
||||
UsageAnalysisAccepted bool `json:"usage_analysis_accepted,omitempty"`
|
||||
} `json:"device,omitempty"`
|
||||
Logging struct {
|
||||
Logs struct {
|
||||
Autostart bool `json:"autostart,omitempty"`
|
||||
Base struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
Format string `json:"format,omitempty"`
|
||||
} `json:"base,omitempty"`
|
||||
Raw struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
Format string `json:"format,omitempty"`
|
||||
RinexOptions struct {
|
||||
LoggingInterval int `json:"logging_interval,omitempty"`
|
||||
MarkerName any `json:"marker_name,omitempty"`
|
||||
Preset string `json:"preset,omitempty"`
|
||||
SatelliteSystems struct {
|
||||
Beidou bool `json:"beidou,omitempty"`
|
||||
Galileo bool `json:"galileo,omitempty"`
|
||||
Glonass bool `json:"glonass,omitempty"`
|
||||
Gps bool `json:"gps,omitempty"`
|
||||
Qzss bool `json:"qzss,omitempty"`
|
||||
Sbas bool `json:"sbas,omitempty"`
|
||||
} `json:"satellite_systems,omitempty"`
|
||||
TimeAdjustmentsEnabled bool `json:"time_adjustments_enabled,omitempty"`
|
||||
} `json:"rinex_options,omitempty"`
|
||||
Version string `json:"version,omitempty"`
|
||||
} `json:"raw,omitempty"`
|
||||
Solution struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
Format string `json:"format,omitempty"`
|
||||
} `json:"solution,omitempty"`
|
||||
Started bool `json:"started,omitempty"`
|
||||
} `json:"logs,omitempty"`
|
||||
Settings struct {
|
||||
ArchiveName any `json:"archive_name,omitempty"`
|
||||
Debug bool `json:"debug,omitempty"`
|
||||
Interval int `json:"interval,omitempty"`
|
||||
Overwrite bool `json:"overwrite,omitempty"`
|
||||
SimultaneousLogging bool `json:"simultaneous_logging,omitempty"`
|
||||
SplitAtMidnightUtc bool `json:"split_at_midnight_utc,omitempty"`
|
||||
} `json:"settings,omitempty"`
|
||||
} `json:"logging,omitempty"`
|
||||
Network struct {
|
||||
TCPOverModem bool `json:"tcp_over_modem,omitempty"`
|
||||
} `json:"network,omitempty"`
|
||||
PositionOutput struct {
|
||||
Output1 struct {
|
||||
IoType string `json:"io_type,omitempty"`
|
||||
LastUsed struct {
|
||||
TCP string `json:"tcp,omitempty"`
|
||||
} `json:"last_used,omitempty"`
|
||||
NmeaSettings struct {
|
||||
Bluetooth struct {
|
||||
Ebp struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"ebp,omitempty"`
|
||||
Gga struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"gga,omitempty"`
|
||||
Gsa struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"gsa,omitempty"`
|
||||
Gst struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"gst,omitempty"`
|
||||
Gsv struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"gsv,omitempty"`
|
||||
MainTalkerID string `json:"main_talker_id,omitempty"`
|
||||
Rmc struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"rmc,omitempty"`
|
||||
Vtg struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"vtg,omitempty"`
|
||||
Zda struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"zda,omitempty"`
|
||||
} `json:"bluetooth,omitempty"`
|
||||
Serial struct {
|
||||
Ebp struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"ebp,omitempty"`
|
||||
Gga struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"gga,omitempty"`
|
||||
Gsa struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"gsa,omitempty"`
|
||||
Gst struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"gst,omitempty"`
|
||||
Gsv struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"gsv,omitempty"`
|
||||
MainTalkerID string `json:"main_talker_id,omitempty"`
|
||||
Rmc struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"rmc,omitempty"`
|
||||
Vtg struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"vtg,omitempty"`
|
||||
Zda struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"zda,omitempty"`
|
||||
} `json:"serial,omitempty"`
|
||||
Tcpcli struct {
|
||||
Ebp struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"ebp,omitempty"`
|
||||
Gga struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"gga,omitempty"`
|
||||
Gsa struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"gsa,omitempty"`
|
||||
Gst struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"gst,omitempty"`
|
||||
Gsv struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"gsv,omitempty"`
|
||||
MainTalkerID string `json:"main_talker_id,omitempty"`
|
||||
Rmc struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"rmc,omitempty"`
|
||||
Vtg struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"vtg,omitempty"`
|
||||
Zda struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"zda,omitempty"`
|
||||
} `json:"tcpcli,omitempty"`
|
||||
Tcpsvr struct {
|
||||
Ebp struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"ebp,omitempty"`
|
||||
Gga struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"gga,omitempty"`
|
||||
Gsa struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"gsa,omitempty"`
|
||||
Gst struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"gst,omitempty"`
|
||||
Gsv struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"gsv,omitempty"`
|
||||
MainTalkerID string `json:"main_talker_id,omitempty"`
|
||||
Rmc struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"rmc,omitempty"`
|
||||
Vtg struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"vtg,omitempty"`
|
||||
Zda struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"zda,omitempty"`
|
||||
} `json:"tcpsvr,omitempty"`
|
||||
} `json:"nmea_settings,omitempty"`
|
||||
Settings struct {
|
||||
Bluetooth struct {
|
||||
Format string `json:"format,omitempty"`
|
||||
} `json:"bluetooth,omitempty"`
|
||||
Serial struct {
|
||||
BaudRate int `json:"baud_rate,omitempty"`
|
||||
Device string `json:"device,omitempty"`
|
||||
Format string `json:"format,omitempty"`
|
||||
} `json:"serial,omitempty"`
|
||||
Tcpcli struct {
|
||||
Address string `json:"address,omitempty"`
|
||||
Format string `json:"format,omitempty"`
|
||||
Port int `json:"port,omitempty"`
|
||||
} `json:"tcpcli,omitempty"`
|
||||
Tcpsvr struct {
|
||||
Format string `json:"format,omitempty"`
|
||||
Port int `json:"port,omitempty"`
|
||||
} `json:"tcpsvr,omitempty"`
|
||||
} `json:"settings,omitempty"`
|
||||
} `json:"output1,omitempty"`
|
||||
Output2 struct {
|
||||
IoType string `json:"io_type,omitempty"`
|
||||
LastUsed struct {
|
||||
TCP string `json:"tcp,omitempty"`
|
||||
} `json:"last_used,omitempty"`
|
||||
NmeaSettings struct {
|
||||
Bluetooth struct {
|
||||
Ebp struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"ebp,omitempty"`
|
||||
Gga struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"gga,omitempty"`
|
||||
Gsa struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"gsa,omitempty"`
|
||||
Gst struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"gst,omitempty"`
|
||||
Gsv struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"gsv,omitempty"`
|
||||
MainTalkerID string `json:"main_talker_id,omitempty"`
|
||||
Rmc struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"rmc,omitempty"`
|
||||
Vtg struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"vtg,omitempty"`
|
||||
Zda struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"zda,omitempty"`
|
||||
} `json:"bluetooth,omitempty"`
|
||||
Serial struct {
|
||||
Ebp struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"ebp,omitempty"`
|
||||
Gga struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"gga,omitempty"`
|
||||
Gsa struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"gsa,omitempty"`
|
||||
Gst struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"gst,omitempty"`
|
||||
Gsv struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"gsv,omitempty"`
|
||||
MainTalkerID string `json:"main_talker_id,omitempty"`
|
||||
Rmc struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"rmc,omitempty"`
|
||||
Vtg struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"vtg,omitempty"`
|
||||
Zda struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"zda,omitempty"`
|
||||
} `json:"serial,omitempty"`
|
||||
Tcpcli struct {
|
||||
Ebp struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"ebp,omitempty"`
|
||||
Gga struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"gga,omitempty"`
|
||||
Gsa struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"gsa,omitempty"`
|
||||
Gst struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"gst,omitempty"`
|
||||
Gsv struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"gsv,omitempty"`
|
||||
MainTalkerID string `json:"main_talker_id,omitempty"`
|
||||
Rmc struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"rmc,omitempty"`
|
||||
Vtg struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"vtg,omitempty"`
|
||||
Zda struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"zda,omitempty"`
|
||||
} `json:"tcpcli,omitempty"`
|
||||
Tcpsvr struct {
|
||||
Ebp struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"ebp,omitempty"`
|
||||
Gga struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"gga,omitempty"`
|
||||
Gsa struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"gsa,omitempty"`
|
||||
Gst struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"gst,omitempty"`
|
||||
Gsv struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"gsv,omitempty"`
|
||||
MainTalkerID string `json:"main_talker_id,omitempty"`
|
||||
Rmc struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"rmc,omitempty"`
|
||||
Vtg struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"vtg,omitempty"`
|
||||
Zda struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"zda,omitempty"`
|
||||
} `json:"tcpsvr,omitempty"`
|
||||
} `json:"nmea_settings,omitempty"`
|
||||
Settings struct {
|
||||
Bluetooth struct {
|
||||
Format string `json:"format,omitempty"`
|
||||
} `json:"bluetooth,omitempty"`
|
||||
Serial struct {
|
||||
BaudRate int `json:"baud_rate,omitempty"`
|
||||
Device string `json:"device,omitempty"`
|
||||
Format string `json:"format,omitempty"`
|
||||
} `json:"serial,omitempty"`
|
||||
Tcpcli struct {
|
||||
Address string `json:"address,omitempty"`
|
||||
Format string `json:"format,omitempty"`
|
||||
Port int `json:"port,omitempty"`
|
||||
} `json:"tcpcli,omitempty"`
|
||||
Tcpsvr struct {
|
||||
Format string `json:"format,omitempty"`
|
||||
Port int `json:"port,omitempty"`
|
||||
} `json:"tcpsvr,omitempty"`
|
||||
} `json:"settings,omitempty"`
|
||||
} `json:"output2,omitempty"`
|
||||
} `json:"position_output,omitempty"`
|
||||
PositioningSettings struct {
|
||||
ElevationMaskAngle int `json:"elevation_mask_angle,omitempty"`
|
||||
GlonassArMode bool `json:"glonass_ar_mode,omitempty"`
|
||||
GnssSettings struct {
|
||||
PositioningSystems struct {
|
||||
Beidou bool `json:"beidou,omitempty"`
|
||||
Galileo bool `json:"galileo,omitempty"`
|
||||
Glonass bool `json:"glonass,omitempty"`
|
||||
Gps bool `json:"gps,omitempty"`
|
||||
Qzss bool `json:"qzss,omitempty"`
|
||||
} `json:"positioning_systems,omitempty"`
|
||||
UpdateRate int `json:"update_rate,omitempty"`
|
||||
} `json:"gnss_settings,omitempty"`
|
||||
GpsArMode string `json:"gps_ar_mode,omitempty"`
|
||||
MaxHorizontalAcceleration int `json:"max_horizontal_acceleration,omitempty"`
|
||||
MaxVerticalAcceleration int `json:"max_vertical_acceleration,omitempty"`
|
||||
PositioningMode string `json:"positioning_mode,omitempty"`
|
||||
SnrMask int `json:"snr_mask,omitempty"`
|
||||
} `json:"positioning_settings,omitempty"`
|
||||
Sound struct {
|
||||
Mute bool `json:"mute,omitempty"`
|
||||
Volume int `json:"volume,omitempty"`
|
||||
} `json:"sound,omitempty"`
|
||||
}
|
166
reach/client/protocol/v2/model/info.go
Normal file
166
reach/client/protocol/v2/model/info.go
Normal file
@ -0,0 +1,166 @@
|
||||
package model
|
||||
|
||||
// GET http://<addr>/info
|
||||
// {
|
||||
// "device": {
|
||||
// "cloud": {
|
||||
// "supported": true,
|
||||
// "usage_analysis_accepted": false
|
||||
// },
|
||||
// "country_code": "FR",
|
||||
// "critical_self_tests_passed": true,
|
||||
// "is_first_time_setup": false,
|
||||
// "local_address": "Reach.local",
|
||||
// "manufacturing_timestamp": "1693633066",
|
||||
// "name": "Reach",
|
||||
// "privacy_policy_accepted": true,
|
||||
// "public_key": "378A5081F445771316A0563CFCC168C813261C6EE9C5C50DF70CC4503C6D8839BED7AA40146A9D8D72BFC4DB85382EEE51B90D03B6CC6DF34E860E15EFEA7D38",
|
||||
// "self_tests": {
|
||||
// "antenna_board_detected": true,
|
||||
// "audio": true,
|
||||
// "bluetooth_detected": true,
|
||||
// "crypto-chip": true,
|
||||
// "image_and_device": true,
|
||||
// "lora": true,
|
||||
// "modem": true,
|
||||
// "mpu": true,
|
||||
// "stm32": true,
|
||||
// "u-blox": true,
|
||||
// "wifi_detected": true
|
||||
// },
|
||||
// "serial_number": "8243276564AEA32D",
|
||||
// "statistics": {
|
||||
// "first_usage_timestamp": 4294967295
|
||||
// },
|
||||
// "time_sync_passed": true,
|
||||
// "type": "ReachRS2+",
|
||||
// "uptime": "2:50:57"
|
||||
// },
|
||||
// "firmware": {
|
||||
// "api_version": "10.2",
|
||||
// "app_mode": "default",
|
||||
// "onboarding_shown": false,
|
||||
// "version": "32.0",
|
||||
// "version_full": "32.0-r0"
|
||||
// },
|
||||
// "gnss_receiver": {
|
||||
// "firmware_version": "HPG_1.13"
|
||||
// },
|
||||
// "lora": {
|
||||
// "firmware_version": "F-0LR-1F-1912161"
|
||||
// },
|
||||
// "modem": {
|
||||
// "firmware_version": "MPSS.JO.2.0.2.c1.1-00098-9607_GENNS_PACK-1.402457.1 1 [May 18 2021 19:00:00]",
|
||||
// "imei": "350588283544948",
|
||||
// "modem_model": "\r\n^SYSSTART\r\n"
|
||||
// },
|
||||
// "pmu": {
|
||||
// "balancer_version": "190602",
|
||||
// "git_hash": "0a241756",
|
||||
// "version": "3.35"
|
||||
// },
|
||||
// "reachview": {
|
||||
// "api_version": "10.2",
|
||||
// "app_mode": "default",
|
||||
// "onboarding_shown": false,
|
||||
// "version": "32.0",
|
||||
// "version_full": "32.0-r0"
|
||||
// },
|
||||
// "storage": {
|
||||
// "free": 11682,
|
||||
// "total": 12374
|
||||
// }
|
||||
// }
|
||||
|
||||
type Info struct {
|
||||
Device Device `json:"device,omitempty"`
|
||||
Firmware Firmware `json:"firmware,omitempty"`
|
||||
GnssReceiver GnssReceiver `json:"gnss_receiver,omitempty"`
|
||||
Lora Lora `json:"lora,omitempty"`
|
||||
Modem Modem `json:"modem,omitempty"`
|
||||
Pmu Pmu `json:"pmu,omitempty"`
|
||||
Reachview Reachview `json:"reachview,omitempty"`
|
||||
Storage Storage `json:"storage,omitempty"`
|
||||
}
|
||||
|
||||
type Cloud struct {
|
||||
Supported bool `json:"supported,omitempty"`
|
||||
UsageAnalysisAccepted bool `json:"usage_analysis_accepted,omitempty"`
|
||||
}
|
||||
|
||||
type SelfTests struct {
|
||||
AntennaBoardDetected bool `json:"antenna_board_detected,omitempty"`
|
||||
Audio bool `json:"audio,omitempty"`
|
||||
BluetoothDetected bool `json:"bluetooth_detected,omitempty"`
|
||||
CryptoChip bool `json:"crypto-chip,omitempty"`
|
||||
ImageAndDevice bool `json:"image_and_device,omitempty"`
|
||||
Lora bool `json:"lora,omitempty"`
|
||||
Modem bool `json:"modem,omitempty"`
|
||||
Mpu bool `json:"mpu,omitempty"`
|
||||
Stm32 bool `json:"stm32,omitempty"`
|
||||
UBlox bool `json:"u-blox,omitempty"`
|
||||
WifiDetected bool `json:"wifi_detected,omitempty"`
|
||||
}
|
||||
|
||||
type Statistics struct {
|
||||
FirstUsageTimestamp int64 `json:"first_usage_timestamp,omitempty"`
|
||||
}
|
||||
|
||||
type Device struct {
|
||||
Cloud Cloud `json:"cloud,omitempty"`
|
||||
CountryCode string `json:"country_code,omitempty"`
|
||||
CriticalSelfTestsPassed bool `json:"critical_self_tests_passed,omitempty"`
|
||||
IsFirstTimeSetup bool `json:"is_first_time_setup,omitempty"`
|
||||
LocalAddress string `json:"local_address,omitempty"`
|
||||
ManufacturingTimestamp string `json:"manufacturing_timestamp,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
PrivacyPolicyAccepted bool `json:"privacy_policy_accepted,omitempty"`
|
||||
PublicKey string `json:"public_key,omitempty"`
|
||||
SelfTests SelfTests `json:"self_tests,omitempty"`
|
||||
SerialNumber string `json:"serial_number,omitempty"`
|
||||
Statistics Statistics `json:"statistics,omitempty"`
|
||||
TimeSyncPassed bool `json:"time_sync_passed,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Uptime string `json:"uptime,omitempty"`
|
||||
}
|
||||
|
||||
type Firmware struct {
|
||||
APIVersion string `json:"api_version,omitempty"`
|
||||
AppMode string `json:"app_mode,omitempty"`
|
||||
OnboardingShown bool `json:"onboarding_shown,omitempty"`
|
||||
Version string `json:"version,omitempty"`
|
||||
VersionFull string `json:"version_full,omitempty"`
|
||||
}
|
||||
|
||||
type GnssReceiver struct {
|
||||
FirmwareVersion string `json:"firmware_version,omitempty"`
|
||||
}
|
||||
|
||||
type Lora struct {
|
||||
FirmwareVersion string `json:"firmware_version,omitempty"`
|
||||
}
|
||||
|
||||
type Modem struct {
|
||||
FirmwareVersion string `json:"firmware_version,omitempty"`
|
||||
Imei string `json:"imei,omitempty"`
|
||||
ModemModel string `json:"modem_model,omitempty"`
|
||||
}
|
||||
|
||||
type Pmu struct {
|
||||
BalancerVersion string `json:"balancer_version,omitempty"`
|
||||
GitHash string `json:"git_hash,omitempty"`
|
||||
Version string `json:"version,omitempty"`
|
||||
}
|
||||
|
||||
type Reachview struct {
|
||||
APIVersion string `json:"api_version,omitempty"`
|
||||
AppMode string `json:"app_mode,omitempty"`
|
||||
OnboardingShown bool `json:"onboarding_shown,omitempty"`
|
||||
Version string `json:"version,omitempty"`
|
||||
VersionFull string `json:"version_full,omitempty"`
|
||||
}
|
||||
|
||||
type Storage struct {
|
||||
Free int `json:"free,omitempty"`
|
||||
Total int `json:"total,omitempty"`
|
||||
}
|
55
reach/client/protocol/v2/model/updater.go
Normal file
55
reach/client/protocol/v2/model/updater.go
Normal file
@ -0,0 +1,55 @@
|
||||
package model
|
||||
|
||||
// {
|
||||
// "allowance": {
|
||||
// "allowed": true,
|
||||
// "reason": null
|
||||
// },
|
||||
// "downgrade": {
|
||||
// "available": false,
|
||||
// "reason": "no_available_downgrades"
|
||||
// },
|
||||
// "release": {
|
||||
// "channel": "stable"
|
||||
// },
|
||||
// "update_server": {
|
||||
// "address": "https://update-provider.cloud.emlid.com/api/client/v1/firmware-available"
|
||||
// },
|
||||
// "upgrade": {
|
||||
// "available": false,
|
||||
// "reason": "up_to_date",
|
||||
// "required": false
|
||||
// }
|
||||
// }
|
||||
|
||||
type Updater struct {
|
||||
Allowance Allowance `json:"allowance,omitempty"`
|
||||
Downgrade Downgrade `json:"downgrade,omitempty"`
|
||||
Release Release `json:"release,omitempty"`
|
||||
UpdateServer UpdateServer `json:"update_server,omitempty"`
|
||||
Upgrade Upgrade `json:"upgrade,omitempty"`
|
||||
}
|
||||
|
||||
type Allowance struct {
|
||||
Allowed bool `json:"allowed,omitempty"`
|
||||
Reason any `json:"reason,omitempty"`
|
||||
}
|
||||
|
||||
type Downgrade struct {
|
||||
Available bool `json:"available,omitempty"`
|
||||
Reason string `json:"reason,omitempty"`
|
||||
}
|
||||
|
||||
type Release struct {
|
||||
Channel string `json:"channel,omitempty"`
|
||||
}
|
||||
|
||||
type UpdateServer struct {
|
||||
Address string `json:"address,omitempty"`
|
||||
}
|
||||
|
||||
type Upgrade struct {
|
||||
Available bool `json:"available,omitempty"`
|
||||
Reason string `json:"reason,omitempty"`
|
||||
Required bool `json:"required,omitempty"`
|
||||
}
|
234
reach/client/protocol/v2/operations.go
Normal file
234
reach/client/protocol/v2/operations.go
Normal file
@ -0,0 +1,234 @@
|
||||
package v2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"forge.cadoles.com/cadoles/go-emlid/reach/client/protocol"
|
||||
"forge.cadoles.com/cadoles/go-emlid/reach/client/protocol/v2/model"
|
||||
|
||||
"forge.cadoles.com/cadoles/go-emlid/reach/client/socketio"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type Operations struct {
|
||||
addr string
|
||||
client *socketio.Client
|
||||
mutex sync.RWMutex
|
||||
}
|
||||
|
||||
// Reboot implements protocol.Operations.
|
||||
func (o *Operations) Reboot(ctx context.Context) error {
|
||||
var err error
|
||||
var wg sync.WaitGroup
|
||||
|
||||
var once sync.Once
|
||||
|
||||
done := func() {
|
||||
o.client.Off(socketio.OnDisconnection)
|
||||
wg.Done()
|
||||
}
|
||||
|
||||
wg.Add(1)
|
||||
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
err = ctx.Err()
|
||||
once.Do(done)
|
||||
}()
|
||||
|
||||
err = o.client.On(socketio.OnDisconnection, func(h *socketio.Channel, data any) {
|
||||
once.Do(done)
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error while binding to '%s' event", socketio.OnDisconnection)
|
||||
}
|
||||
|
||||
if err = o.client.Emit("action", &model.Action{Name: "reboot"}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// SetBase implements protocol.Operations.
|
||||
func (o *Operations) SetBase(ctx context.Context, funcs ...protocol.SetBaseOptionFunc) error {
|
||||
config, err := o.GetConfiguration(ctx)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
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.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 opts.AntennaOffset != nil {
|
||||
base.AntennaOffset = *opts.AntennaOffset
|
||||
}
|
||||
|
||||
if _, err := o.PostBaseCoordinates(ctx, base); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Configuration implements protocol.Operations.
|
||||
func (o *Operations) Configuration(ctx context.Context) (any, error) {
|
||||
config, err := o.GetConfiguration(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
||||
// Alive implements protocol.Operations.
|
||||
func (o *Operations) Alive(ctx context.Context) (bool, error) {
|
||||
o.mutex.RLock()
|
||||
defer o.mutex.RUnlock()
|
||||
|
||||
return o.client.Alive(), nil
|
||||
}
|
||||
|
||||
// Version implements protocol.Operations.
|
||||
func (o *Operations) Version(ctx context.Context) (string, bool, error) {
|
||||
info, err := o.GetInfo(ctx)
|
||||
if err != nil {
|
||||
return "", false, errors.WithStack(err)
|
||||
}
|
||||
|
||||
updater, err := o.GetUpdater(ctx)
|
||||
if err != nil {
|
||||
return "", false, errors.WithStack(err)
|
||||
}
|
||||
|
||||
version := info.Reachview.Version
|
||||
stable := updater.Release.Channel == "stable"
|
||||
|
||||
return version, stable, nil
|
||||
}
|
||||
|
||||
// Close implements protocol.Operations.
|
||||
func (o *Operations) Close(ctx context.Context) error {
|
||||
o.mutex.Lock()
|
||||
defer o.mutex.Unlock()
|
||||
|
||||
if o.client == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
o.client.Close()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Connect implements protocol.Operations.
|
||||
func (o *Operations) Connect(ctx context.Context) error {
|
||||
o.mutex.Lock()
|
||||
defer o.mutex.Unlock()
|
||||
|
||||
if o.client != nil {
|
||||
o.client.Close()
|
||||
}
|
||||
|
||||
endpoint, err := socketio.EndpointFromHAddr(o.addr)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
client := socketio.NewClient(endpoint)
|
||||
|
||||
if err := client.Connect(); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
o.client = client
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Emit implements protocol.Operations.
|
||||
func (o *Operations) Emit(ctx context.Context, mType string, message any) error {
|
||||
o.mutex.RLock()
|
||||
defer o.mutex.RUnlock()
|
||||
|
||||
if o.client == nil || !o.client.Alive() {
|
||||
return errors.WithStack(protocol.ErrClosed)
|
||||
}
|
||||
|
||||
if err := o.client.Emit(mType, message); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// On implements protocol.Operations.
|
||||
func (o *Operations) On(ctx context.Context, event string) (chan any, error) {
|
||||
o.mutex.RLock()
|
||||
defer o.mutex.RUnlock()
|
||||
|
||||
if o.client == nil || !o.client.Alive() {
|
||||
return nil, errors.WithStack(protocol.ErrClosed)
|
||||
}
|
||||
|
||||
out := make(chan any)
|
||||
closer := new(sync.Once)
|
||||
|
||||
handler := func(ch *socketio.Channel, data any) {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
closer.Do(func() {
|
||||
o.mutex.RLock()
|
||||
defer o.mutex.RUnlock()
|
||||
|
||||
ch.Close()
|
||||
close(out)
|
||||
|
||||
if o.client == nil {
|
||||
return
|
||||
}
|
||||
})
|
||||
|
||||
return
|
||||
default:
|
||||
out <- data
|
||||
}
|
||||
}
|
||||
|
||||
if err := o.client.On(event, handler); err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return out, nil
|
||||
}
|
||||
|
||||
var _ protocol.Operations = &Operations{}
|
31
reach/client/protocol/v2/operations_test.go
Normal file
31
reach/client/protocol/v2/operations_test.go
Normal file
@ -0,0 +1,31 @@
|
||||
package v2
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"forge.cadoles.com/cadoles/go-emlid/reach/client/protocol"
|
||||
"forge.cadoles.com/cadoles/go-emlid/reach/client/protocol/testsuite"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func TestProtocolV2Operations(t *testing.T) {
|
||||
proto := &Protocol{}
|
||||
|
||||
factory := func(addr string) (protocol.Operations, error) {
|
||||
ctx := context.Background()
|
||||
|
||||
available, err := proto.Available(ctx, addr)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
if !available {
|
||||
return nil, errors.New("protocol is not available")
|
||||
}
|
||||
|
||||
return proto.Operations(addr), nil
|
||||
}
|
||||
|
||||
testsuite.TestOperations(t, factory)
|
||||
}
|
54
reach/client/protocol/v2/protocol.go
Normal file
54
reach/client/protocol/v2/protocol.go
Normal file
@ -0,0 +1,54 @@
|
||||
package v2
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"forge.cadoles.com/cadoles/go-emlid/reach/client/protocol"
|
||||
"github.com/Masterminds/semver/v3"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const Identifier protocol.Identifier = "v2"
|
||||
|
||||
const compatibleVersionConstraint = ">= 32"
|
||||
|
||||
type Protocol struct {
|
||||
}
|
||||
|
||||
// Available implements protocol.Protocol.
|
||||
func (p *Protocol) Available(ctx context.Context, addr string) (bool, error) {
|
||||
ops := p.Operations(addr).(*Operations)
|
||||
|
||||
info, err := ops.GetInfo(ctx)
|
||||
if err != nil {
|
||||
return false, errors.WithStack(err)
|
||||
}
|
||||
|
||||
versionConstraint, err := semver.NewConstraint(compatibleVersionConstraint)
|
||||
if err != nil {
|
||||
return false, errors.WithStack(err)
|
||||
}
|
||||
|
||||
version, err := semver.NewVersion(info.Reachview.Version)
|
||||
if err != nil {
|
||||
return false, errors.WithStack(err)
|
||||
}
|
||||
|
||||
if !versionConstraint.Check(version) {
|
||||
return false, errors.Errorf("reachview version '%s' does not match constraint '%s'", info.Reachview.Version, compatibleVersionConstraint)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// Identifier implements protocol.Protocol.
|
||||
func (p *Protocol) Identifier() protocol.Identifier {
|
||||
return Identifier
|
||||
}
|
||||
|
||||
// Operations implements protocol.Protocol.
|
||||
func (p *Protocol) Operations(addr string) protocol.Operations {
|
||||
return &Operations{addr: addr}
|
||||
}
|
||||
|
||||
var _ protocol.Protocol = &Protocol{}
|
Reference in New Issue
Block a user