Merge branch 'feature/reachview-apply-conf' into develop
This commit is contained in:
commit
599c4cf1d5
|
@ -27,7 +27,7 @@ pipeline {
|
|||
steps {
|
||||
script {
|
||||
try {
|
||||
sh "make lint"
|
||||
sh 'make LINT_ARGS="--new-from-rev=HEAD~" lint'
|
||||
} catch(ex) {
|
||||
currentBuild.result = "UNSTABLE"
|
||||
}
|
||||
|
|
2
Makefile
2
Makefile
|
@ -14,7 +14,7 @@ test: tidy
|
|||
go test -mod=vendor -v ./...
|
||||
|
||||
lint:
|
||||
@golangci-lint run -e '.*/pkg/mod' -e ".*/go/src" --enable-all $(LINT_ARGS)
|
||||
@golangci-lint run -e '.*/pkg/mod' -e ".*/go/src" --enable-all --disable lll $(LINT_ARGS)
|
||||
|
||||
tidy:
|
||||
go mod tidy
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package emlid
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"forge.cadoles.com/Pyxis/golang-socketio"
|
||||
|
@ -98,23 +99,36 @@ func (c *Client) Off(event string) {
|
|||
}
|
||||
|
||||
// ReqResp emits an event with the given data and waits for a response
|
||||
func (c *Client) ReqResp(requestEvent string, requestData interface{}, responseEvent string, res interface{}) error {
|
||||
func (c *Client) ReqResp(ctx context.Context,
|
||||
requestEvent string, requestData interface{},
|
||||
responseEvent string, res interface{}) error {
|
||||
|
||||
var err error
|
||||
var wg sync.WaitGroup
|
||||
var once sync.Once
|
||||
|
||||
done := func() {
|
||||
c.conn.Off(responseEvent)
|
||||
wg.Done()
|
||||
}
|
||||
|
||||
wg.Add(1)
|
||||
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
err = ctx.Err()
|
||||
once.Do(done)
|
||||
}()
|
||||
|
||||
err = c.conn.On(responseEvent, func(_ *gosocketio.Channel, data interface{}) {
|
||||
err = mapstructure.Decode(data, res)
|
||||
c.conn.Off(responseEvent)
|
||||
wg.Done()
|
||||
err = mapstructure.WeakDecode(data, res)
|
||||
once.Do(done)
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error while binding to '%s' event", responseEvent)
|
||||
}
|
||||
|
||||
if err := c.Emit(requestEvent, requestData); err != nil {
|
||||
if err = c.Emit(requestEvent, requestData); err != nil {
|
||||
return errors.Wrapf(err, "error while emitting event '%s'", requestEvent)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,15 +1,51 @@
|
|||
package reachview
|
||||
|
||||
import "context"
|
||||
|
||||
const (
|
||||
eventGetConfiguration = "get configuration"
|
||||
eventCurrentConfiguration = "current configuration"
|
||||
eventApplyConfiguration = "apply configuration"
|
||||
eventConfigurationApplied = "configuration applied"
|
||||
eventResetConfiguration = "reset configuration to default"
|
||||
)
|
||||
|
||||
// Configuration fetches and return the current configuration of the ReachRS module
|
||||
func (r *Client) Configuration() (*Configuration, error) {
|
||||
func (r *Client) Configuration(ctx context.Context) (*Configuration, error) {
|
||||
configuration := &Configuration{}
|
||||
if err := r.ReqResp(eventGetConfiguration, nil, eventCurrentConfiguration, configuration); err != nil {
|
||||
if err := r.ReqResp(ctx, eventGetConfiguration, nil, eventCurrentConfiguration, configuration); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return configuration, nil
|
||||
}
|
||||
|
||||
type configurationApplied struct {
|
||||
Configuration *Configuration `mapstructure:"configuration,omitempty"`
|
||||
Result string `mapstructure:"result"`
|
||||
Constraints *Constraints `mapstructure:"Constraints,omitempty"`
|
||||
}
|
||||
|
||||
const (
|
||||
// ConfigurationApplySuccess -
|
||||
ConfigurationApplySuccess = "success"
|
||||
// ConfigurationApplyFailed -
|
||||
ConfigurationApplyFailed = "failed"
|
||||
)
|
||||
|
||||
// ApplyConfiguration applies the given configuration
|
||||
func (r *Client) ApplyConfiguration(ctx context.Context, config *Configuration) (string, *Configuration, error) {
|
||||
res := &configurationApplied{}
|
||||
if err := r.ReqResp(ctx, eventApplyConfiguration, config, eventConfigurationApplied, res); err != nil {
|
||||
return ConfigurationApplyFailed, nil, err
|
||||
}
|
||||
return res.Result, res.Configuration, nil
|
||||
}
|
||||
|
||||
// ResetConfiguration resets the module configuration to factory defaults
|
||||
func (r *Client) ResetConfiguration(ctx context.Context) (string, *Configuration, error) {
|
||||
res := &configurationApplied{}
|
||||
if err := r.ReqResp(ctx, eventResetConfiguration, nil, eventConfigurationApplied, res); err != nil {
|
||||
return ConfigurationApplyFailed, nil, err
|
||||
}
|
||||
return res.Result, res.Configuration, nil
|
||||
}
|
||||
|
|
|
@ -1,59 +1,124 @@
|
|||
package reachview
|
||||
|
||||
var (
|
||||
// On -
|
||||
On = String("on")
|
||||
// Off -
|
||||
Off = String("off")
|
||||
// True -
|
||||
True = Bool(true)
|
||||
// False -
|
||||
False = Bool(false)
|
||||
// GPSARModeFixAndHold -
|
||||
GPSARModeFixAndHold = String("fix-and-hold")
|
||||
// GPSARModeContinuous -
|
||||
GPSARModeContinuous = String("continuous")
|
||||
// PositionningModeKinematic -
|
||||
PositionningModeKinematic = String("kinematic")
|
||||
// PositionningModeSingle -
|
||||
PositionningModeSingle = String("single")
|
||||
// PositionningModeStatic -
|
||||
PositionningModeStatic = String("static")
|
||||
// IOFormatRTCM3 -
|
||||
IOFormatRTCM3 = String("rtcm3")
|
||||
// IOTypeLoRa -
|
||||
IOTypeLoRa = String("lora")
|
||||
// BaseCoordinatesModeManual -
|
||||
BaseCoordinatesModeManual = String("manual")
|
||||
// BaseCoordinatesModeAverageFix -
|
||||
BaseCoordinatesModeAverageFix = String("fix-and-hold")
|
||||
// BaseCoordinatesModeAverageSingle -
|
||||
BaseCoordinatesModeAverageSingle = String("single-and-hold")
|
||||
// BaseCoordinatesModeAverageFloat -
|
||||
BaseCoordinatesModeAverageFloat = String("float-and-hold")
|
||||
// BaseCoordinatesFormatLLH -
|
||||
BaseCoordinatesFormatLLH = String("llh")
|
||||
// BaseCoordinatesFormatXYZ -
|
||||
BaseCoordinatesFormatXYZ = String("xyz")
|
||||
)
|
||||
|
||||
// String returns an string pointer
|
||||
// This is a helper to constructs partials configations objects
|
||||
// for the ApplyConfiguration() method
|
||||
func String(v string) *string {
|
||||
return &v
|
||||
}
|
||||
|
||||
// Int returns an int pointer
|
||||
// This is a helper to constructs partials configations objects
|
||||
// for the ApplyConfiguration() method
|
||||
func Int(v int) *int {
|
||||
return &v
|
||||
}
|
||||
|
||||
// Bool returns a bool pointer
|
||||
// This is a helper to constructs partials configations objects
|
||||
// for the ApplyConfiguration() method
|
||||
func Bool(v bool) *bool {
|
||||
return &v
|
||||
}
|
||||
|
||||
// Float returns a float64 pointer
|
||||
// This is a helper to constructs partials configations objects
|
||||
// for the ApplyConfiguration() method
|
||||
func Float(v float64) *float64 {
|
||||
return &v
|
||||
}
|
||||
|
||||
// Configuration -
|
||||
type Configuration struct {
|
||||
RTKSettings *RTKSettings `mapstructure:"rtk settings,omitempty"`
|
||||
CorrectionInput *CorrectionInput `mapstructure:"correction input,omitempty"`
|
||||
PositionOutput *PositionOutput `mapstructure:"position output,omitempty"`
|
||||
BaseMode *BaseMode `mapstructure:"base mode,omitempty"`
|
||||
Logging *Logging `mapstructure:"logging,omitempty"`
|
||||
Bluetooth *Bluetooth `mapstructure:"bluetooth,omitempty"`
|
||||
LoRa *LoRa `mapstructure:"lora,omitempty"`
|
||||
Constraints *Constraints `mapstructure:"constraints,omitempty"`
|
||||
RTKSettings *RTKSettings `mapstructure:"rtk settings,omitempty" json:"rtk settings,omitempty"`
|
||||
CorrectionInput *CorrectionInput `mapstructure:"correction input,omitempty" json:"correction input,omitempty"`
|
||||
PositionOutput *PositionOutput `mapstructure:"position output,omitempty" json:"position output,omitempty"`
|
||||
BaseMode *BaseMode `mapstructure:"base mode,omitempty" json:"base mode,omitempty"`
|
||||
Logging *Logging `mapstructure:"logging,omitempty" json:"logging,omitempty"`
|
||||
Bluetooth *Bluetooth `mapstructure:"bluetooth,omitempty" json:"bluetooth,omitempty"`
|
||||
LoRa *LoRa `mapstructure:"lora,omitempty" json:"lora,omitempty"`
|
||||
Constraints *Constraints `mapstructure:"constraints,omitempty" json:"constraints,omitempty"`
|
||||
}
|
||||
|
||||
// RTKSettings -
|
||||
type RTKSettings struct {
|
||||
GLONASSARMode string `mapstructure:"glonass ar mode"`
|
||||
UpdateRate string `mapstructure:"update rate"`
|
||||
ElevationMaskAngle string `mapstructure:"elevation mask angle"`
|
||||
MaxHorizontalAcceleration string `mapstructure:"max horizontal acceleration"`
|
||||
SNRMask string `mapstructure:"snr mask"`
|
||||
GPSARMode string `mapstructure:"gps ar mode"`
|
||||
PositionningMode string `mapstructure:"positioning mode"`
|
||||
PositioningSystems *PositionningSystems `mapstructure:"positioning systems,omitempty"`
|
||||
MaxVerticalAcceleration string `mapstructure:"max vertical acceleration"`
|
||||
GLONASSARMode *string `mapstructure:"glonass ar mode,omitempty" json:"glonass ar mode,omitempty"`
|
||||
UpdateRate *string `mapstructure:"update rate,omitempty" json:"update rate,omitempty"`
|
||||
ElevationMaskAngle *string `mapstructure:"elevation mask angle,omitempty" json:"elevation mask angle,omitempty"`
|
||||
MaxHorizontalAcceleration *string `mapstructure:"max horizontal acceleration,omitempty" json:"max horizontal acceleration,omitempty"`
|
||||
SNRMask *string `mapstructure:"snr mask,omitempty" json:"snr mask,omitempty"`
|
||||
GPSARMode *string `mapstructure:"gps ar mode,omitempty" json:"gps ar mode,omitempty"`
|
||||
PositionningMode *string `mapstructure:"positioning mode,omitempty" json:"positioning mode,omitempty"`
|
||||
PositioningSystems *PositionningSystems `mapstructure:"positioning systems,omitempty" json:"positioning systems,omitempty"`
|
||||
MaxVerticalAcceleration *string `mapstructure:"max vertical acceleration,omitempty" json:"max vertical acceleration,omitempty"`
|
||||
}
|
||||
|
||||
// PositionningSystems -
|
||||
type PositionningSystems struct {
|
||||
GLONASS bool `mapstructure:"glonass"`
|
||||
SBAS bool `mapstructure:"sbas"`
|
||||
QZS bool `mapstructure:"qzs"`
|
||||
QZSS bool `mapstructure:"qzss"`
|
||||
Compass bool `mapstructure:"compass"`
|
||||
Galileo bool `mapstructure:"galileo"`
|
||||
GPS bool `mapstructure:"gps"`
|
||||
GLONASS *bool `mapstructure:"glonass,omitempty" json:"glonass,omitempty"`
|
||||
SBAS *bool `mapstructure:"sbas,omitempty" json:"sbas,omitempty"`
|
||||
QZS *bool `mapstructure:"qzs,omitempty" json:"qzs,omitempty"`
|
||||
QZSS *bool `mapstructure:"qzss,omitempty" json:"qzss,omitempty"`
|
||||
Compass *bool `mapstructure:"compass,omitempty" json:"compass,omitempty"`
|
||||
Galileo *bool `mapstructure:"galileo,omitempty" json:"galileo,omitempty"`
|
||||
GPS *bool `mapstructure:"gps,omitempty" json:"gps,omitempty"`
|
||||
}
|
||||
|
||||
// CorrectionInput -
|
||||
type CorrectionInput struct {
|
||||
Input2 *Input2 `mapstructure:"input2,omitempty"`
|
||||
Input3 *Input3 `mapstructure:"input3,omitempty"`
|
||||
Input2 *Input2 `mapstructure:"input2,omitempty" json:"input2,omitempty"`
|
||||
Input3 *Input3 `mapstructure:"input3,omitempty" json:"input3,omitempty"`
|
||||
}
|
||||
|
||||
// Input -
|
||||
type Input struct {
|
||||
Path string `mapstructure:"path"`
|
||||
Type string `mapstructure:"type"`
|
||||
Enabled bool `mapstructure:"enabled"`
|
||||
Format string `mapstructure:"format"`
|
||||
Path *string `mapstructure:"path,omitempty" json:"path,omitempty"`
|
||||
Type *string `mapstructure:"type,omitempty" json:"type,omitempty"`
|
||||
Enabled *bool `mapstructure:"enabled,omitempty" json:"enabled,omitempty"`
|
||||
Format *string `mapstructure:"format,omitempty" json:"format,omitempty"`
|
||||
}
|
||||
|
||||
// Input2 -
|
||||
type Input2 struct {
|
||||
Input `mapstructure:",squash"`
|
||||
SendPositionToBase string `mapstructure:"send position to base"`
|
||||
SendPositionToBase *string `mapstructure:"send position to base,omitempty" json:"send position to base,omitempty"`
|
||||
}
|
||||
|
||||
// Input3 -
|
||||
|
@ -63,116 +128,116 @@ type Input3 struct {
|
|||
|
||||
// PositionOutput -
|
||||
type PositionOutput struct {
|
||||
Output1 *Output `mapstructure:"output1,omitempty"`
|
||||
Output2 *Output `mapstructure:"output2,omitempty"`
|
||||
Output3 *Output `mapstructure:"output3,omitempty"`
|
||||
Output4 *Output `mapstructure:"output4,omitempty"`
|
||||
Output1 *Output `mapstructure:"output1,omitempty" json:"output1,omitempty"`
|
||||
Output2 *Output `mapstructure:"output2,omitempty" json:"output2,omitempty"`
|
||||
Output3 *Output `mapstructure:"output3,omitempty" json:"output3,omitempty"`
|
||||
Output4 *Output `mapstructure:"output4,omitempty" json:"output4,omitempty"`
|
||||
}
|
||||
|
||||
// Output -
|
||||
type Output struct {
|
||||
Path string `mapstructure:"path"`
|
||||
Type string `mapstructure:"type"`
|
||||
Enabled bool `mapstructure:"enabled"`
|
||||
Format string `mapstructure:"format"`
|
||||
Path *string `mapstructure:"path,omitempty" json:"path,omitempty"`
|
||||
Type *string `mapstructure:"type,omitempty" json:"type,omitempty"`
|
||||
Enabled *bool `mapstructure:"enabled,omitempty" json:"enabled,omitempty"`
|
||||
Format *string `mapstructure:"format,omitempty" json:"format,omitempty"`
|
||||
}
|
||||
|
||||
// BaseMode -
|
||||
type BaseMode struct {
|
||||
Output *Output `mapstructure:"output,omitempty"`
|
||||
BaseCoordinates *BaseCoordinates `mapstructure:"base coordinates,omitempty"`
|
||||
RTCM3Messages *RTCM3Messages `mapstructure:"rtcm3 messages,omitempty"`
|
||||
Output *Output `mapstructure:"output,omitempty" json:"output,omitempty"`
|
||||
BaseCoordinates *BaseCoordinates `mapstructure:"base coordinates,omitempty" json:"base coordinates,omitempty"`
|
||||
RTCM3Messages *RTCM3Messages `mapstructure:"rtcm3 messages,omitempty" json:"rtcm3 messages,omitempty"`
|
||||
}
|
||||
|
||||
// BaseCoordinates -
|
||||
type BaseCoordinates struct {
|
||||
Format string `mapstructure:"format"`
|
||||
AntennaOffset *AntennaOffset `mapstructure:"antenna offset,omitempty"`
|
||||
Accumulation string `mapstructure:"accumulation"`
|
||||
Coordinates []string `mapstructure:"coordinates"`
|
||||
Mode string `mapstructure:"mode"`
|
||||
Format *string `mapstructure:"format,omitempty" json:"format,omitempty"`
|
||||
AntennaOffset *AntennaOffset `mapstructure:"antenna offset,omitempty" json:"antenna offset,omitempty"`
|
||||
Accumulation *string `mapstructure:"accumulation,omitempty" json:"accumulation,omitempty"`
|
||||
Coordinates []*string `mapstructure:"coordinates,omitempty" json:"coordinates,omitempty"`
|
||||
Mode *string `mapstructure:"mode,omitempty" json:"mode,omitempty"`
|
||||
}
|
||||
|
||||
// AntennaOffset -
|
||||
type AntennaOffset struct {
|
||||
East string `mapstructure:"east"`
|
||||
North string `mapstructure:"north"`
|
||||
Up string `mapstructure:"up"`
|
||||
East *string `mapstructure:"east,omitempty" json:"east,omitempty"`
|
||||
North *string `mapstructure:"north,omitempty" json:"north,omitempty"`
|
||||
Up *string `mapstructure:"up,omitempty" json:"up,omitempty"`
|
||||
}
|
||||
|
||||
// RTCM3Messages -
|
||||
type RTCM3Messages struct {
|
||||
// GPS L1 code and phase and ambiguities and carrier-to-noise ratio
|
||||
Type1002 *RTCMMessageType `mapstructure:"1002,omitemtpy"`
|
||||
Type1002 *RTCMMessageType `mapstructure:"1002,omitemtpy" json:"1002,omitemtpy"`
|
||||
// Station coordinates XYZ for antenna reference point and antenna height.
|
||||
Type1006 *RTCMMessageType `mapstructure:"1006,omitemtpy"`
|
||||
Type1006 *RTCMMessageType `mapstructure:"1006,omitemtpy" json:"1006,omitemtpy"`
|
||||
// Antenna serial number.
|
||||
Type1008 *RTCMMessageType `mapstructure:"1008,omitemtpy"`
|
||||
Type1008 *RTCMMessageType `mapstructure:"1008,omitemtpy" json:"1008,omitemtpy"`
|
||||
// GLONASS L1 code and phase and ambiguities and carrier-to-noise ratio.
|
||||
Type1010 *RTCMMessageType `mapstructure:"1010,omitemtpy"`
|
||||
Type1010 *RTCMMessageType `mapstructure:"1010,omitemtpy" json:"1010,omitemtpy"`
|
||||
// GPS ephemeris.
|
||||
Type1019 *RTCMMessageType `mapstructure:"1019,omitemtpy"`
|
||||
Type1019 *RTCMMessageType `mapstructure:"1019,omitemtpy" json:"1019,omitemtpy"`
|
||||
// GLONASS ephemeris.
|
||||
Type1020 *RTCMMessageType `mapstructure:"1020,omitemtpy"`
|
||||
Type1020 *RTCMMessageType `mapstructure:"1020,omitemtpy" json:"1020,omitemtpy"`
|
||||
// The type 7 Multiple Signal Message format for Europe’s Galileo system
|
||||
Type1097 *RTCMMessageType `mapstructure:"1097,omitemtpy"`
|
||||
Type1097 *RTCMMessageType `mapstructure:"1097,omitemtpy" json:"1097,omitemtpy"`
|
||||
// Full SBAS pseudo-ranges, carrier phases, Doppler and signal strength (high resolution)
|
||||
Type1107 *RTCMMessageType `mapstructure:"1107,omitemtpy"`
|
||||
Type1107 *RTCMMessageType `mapstructure:"1107,omitemtpy" json:"1107,omitemtpy"`
|
||||
// Full QZSS pseudo-ranges, carrier phases, Doppler and signal strength (high resolution)
|
||||
Type1117 *RTCMMessageType `mapstructure:"1117,omitemtpy"`
|
||||
Type1117 *RTCMMessageType `mapstructure:"1117,omitemtpy" json:"1117,omitemtpy"`
|
||||
// Full BeiDou pseudo-ranges, carrier phases, Doppler and signal strength (high resolution)
|
||||
Type1127 *RTCMMessageType `mapstructure:"1127,omitemtpy"`
|
||||
Type1127 *RTCMMessageType `mapstructure:"1127,omitemtpy" json:"1127,omitemtpy"`
|
||||
}
|
||||
|
||||
// RTCMMessageType -
|
||||
type RTCMMessageType struct {
|
||||
Frequency string `mapstructure:"frequency"`
|
||||
Enabled bool `mapstructure:"enabled"`
|
||||
Frequency *string `mapstructure:"frequency,omitempty" json:"frequency,omitempty"`
|
||||
Enabled *bool `mapstructure:"enabled,omitempty" json:"enabled,omitempty"`
|
||||
}
|
||||
|
||||
// Logging -
|
||||
type Logging struct {
|
||||
Correction *LoggingService `mapstructure:"correction,omitempty"`
|
||||
Interval int `mapstructure:"interval"`
|
||||
Solution *LoggingService `mapstructure:"solution,omitempty"`
|
||||
Raw *LoggingService `mapstructure:"raw,omitempty"`
|
||||
Base *LoggingService `mapstructure:"base,omitempty"`
|
||||
Overwrite bool `mapstructure:"overwrite"`
|
||||
Correction *LoggingService `mapstructure:"correction,omitempty" json:"correction,omitempty"`
|
||||
Interval *int `mapstructure:"interval,omitempty" json:"interval,omitempty"`
|
||||
Solution *LoggingService `mapstructure:"solution,omitempty" json:"solution,omitempty"`
|
||||
Raw *LoggingService `mapstructure:"raw,omitempty" json:"raw,omitempty"`
|
||||
Base *LoggingService `mapstructure:"base,omitempty" json:"base,omitempty"`
|
||||
Overwrite *bool `mapstructure:"overwrite,omitempty" json:"overwrite,omitempty"`
|
||||
}
|
||||
|
||||
// LoggingService -
|
||||
type LoggingService struct {
|
||||
Started bool `mapstructure:"started"`
|
||||
Version string `mapstructure:"version"`
|
||||
Format string `mapstructure:"format"`
|
||||
Started *bool `mapstructure:"started,omitempty" json:"started,omitempty"`
|
||||
Version *string `mapstructure:"version,omitempty" json:"version,omitempty"`
|
||||
Format *string `mapstructure:"format,omitempty" json:"format,omitempty"`
|
||||
}
|
||||
|
||||
// Bluetooth -
|
||||
type Bluetooth struct {
|
||||
Enabled bool `mapstructure:"enabled"`
|
||||
Discoverable bool `mapstructure:"discoverable"`
|
||||
Pin int `mapstructure:"pin"`
|
||||
Enabled *bool `mapstructure:"enabled,omitempty" json:"enabled,omitempty"`
|
||||
Discoverable *bool `mapstructure:"discoverable,omitempty" json:"discoverable,omitempty"`
|
||||
Pin *int `mapstructure:"pin,omitempty" json:"pin,omitempty"`
|
||||
}
|
||||
|
||||
// LoRa -
|
||||
type LoRa struct {
|
||||
AirRate float64 `mapstructure:"air rate"`
|
||||
Frequency int `mapstructure:"frequency"`
|
||||
OutputPower int `mapstructure:"output power"`
|
||||
AirRate *string `mapstructure:"air rate,omitempty" json:"air rate,omitempty"`
|
||||
Frequency *float64 `mapstructure:"frequency,omitempty" json:"frequency,omitempty"`
|
||||
OutputPower *string `mapstructure:"output power,omitempty" json:"output power,omitempty"`
|
||||
}
|
||||
|
||||
// Constraints -
|
||||
type Constraints struct {
|
||||
LoRa *LoRaConstraints `mapstructure:"lora,omitempty"`
|
||||
LoRa *LoRaConstraints `mapstructure:"lora,omitempty" json:"lora,omitempty"`
|
||||
}
|
||||
|
||||
// LoRaConstraints -
|
||||
type LoRaConstraints struct {
|
||||
Frequency *LoRaFrequencyRange `mapstructure:"frequency,omitempty"`
|
||||
Frequency *LoRaFrequencyRange `mapstructure:"frequency,omitempty" json:"frequency,omitempty"`
|
||||
}
|
||||
|
||||
// LoRaFrequencyRange -
|
||||
type LoRaFrequencyRange struct {
|
||||
Min int `mapstructure:"min"`
|
||||
Max int `mapstructure:"max"`
|
||||
Min *int `mapstructure:"min,omitempty" json:"min,omitempty"`
|
||||
Max *int `mapstructure:"max,omitempty" json:"max,omitempty"`
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
package reachview
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"forge.cadoles.com/Pyxis/orion/emlid"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
)
|
||||
|
||||
func TestReachViewConfiguration(t *testing.T) {
|
||||
|
@ -21,7 +22,10 @@ func TestReachViewConfiguration(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
config, err := client.Configuration()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
config, err := client.Configuration(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -34,7 +38,53 @@ func TestReachViewConfiguration(t *testing.T) {
|
|||
t.Fatal("config.RTKSettings should not be nil")
|
||||
}
|
||||
|
||||
spew.Dump(config)
|
||||
defer client.Close()
|
||||
|
||||
}
|
||||
|
||||
func TestReachViewApplyConfiguration(t *testing.T) {
|
||||
|
||||
if !*runReachViewIntegrationTests {
|
||||
t.Skip("To run this test, use: go test -reachview-integration")
|
||||
}
|
||||
|
||||
client := NewClient(
|
||||
emlid.WithStandardLogger(),
|
||||
emlid.WithEndpoint(*reachHost, 80),
|
||||
)
|
||||
if err := client.Connect(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ctx, configurationCancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer configurationCancel()
|
||||
|
||||
config, err := client.Configuration(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
config.RTKSettings.PositionningMode = String("single")
|
||||
|
||||
ctx, applyConfCancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer applyConfCancel()
|
||||
|
||||
result, config, err := client.ApplyConfiguration(ctx, config)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if config == nil {
|
||||
t.Fatal("config should not be nil")
|
||||
}
|
||||
|
||||
if config.RTKSettings == nil {
|
||||
t.Fatal("config.RTKSettings should not be nil")
|
||||
}
|
||||
|
||||
if g, e := result, ConfigurationApplySuccess; g != e {
|
||||
t.Errorf("result: got '%s', expected '%s'", g, e)
|
||||
}
|
||||
|
||||
defer client.Close()
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package reachview
|
||||
|
||||
const (
|
||||
eventRestartRTKLib = "restart rtklib"
|
||||
)
|
||||
|
||||
// RestartRTKLib asks the ReachRS module to restart the RTKlib
|
||||
func (c *Client) RestartRTKLib() error {
|
||||
return c.Emit(eventRestartRTKLib, nil)
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
package updater
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"forge.cadoles.com/Pyxis/orion/emlid"
|
||||
)
|
||||
|
@ -17,7 +19,12 @@ func Example_usage() {
|
|||
log.Fatal(err)
|
||||
}
|
||||
|
||||
networks, err := updater.WifiNetworks()
|
||||
// We create a context for the API call with a 10 second delay
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
// Retrieve the Wifi networks
|
||||
networks, err := updater.WifiNetworks(ctx)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package updater
|
||||
|
||||
import "context"
|
||||
|
||||
const (
|
||||
eventGetReachViewVersion = "get reachview version"
|
||||
eventReachViewVersionResults = "current reachview version"
|
||||
|
@ -10,9 +12,9 @@ type reachViewVersion struct {
|
|||
}
|
||||
|
||||
// ReachViewVersion returns the ReachRS module ReachView version
|
||||
func (c *Client) ReachViewVersion() (string, error) {
|
||||
func (c *Client) ReachViewVersion(ctx context.Context) (string, error) {
|
||||
res := &reachViewVersion{}
|
||||
if err := c.ReqResp(eventGetReachViewVersion, nil, eventReachViewVersionResults, res); err != nil {
|
||||
if err := c.ReqResp(ctx, eventGetReachViewVersion, nil, eventReachViewVersionResults, res); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return res.Version, nil
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package updater
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"forge.cadoles.com/Pyxis/orion/emlid"
|
||||
)
|
||||
|
@ -19,8 +21,9 @@ func TestClientReachViewVersion(t *testing.T) {
|
|||
if err := client.Connect(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
version, err := client.ReachViewVersion()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
version, err := client.ReachViewVersion(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package updater
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"forge.cadoles.com/Pyxis/golang-socketio"
|
||||
|
@ -12,16 +13,30 @@ const (
|
|||
)
|
||||
|
||||
// RebootNow asks the ReachRS module to reboot now
|
||||
func (c *Client) RebootNow(waitDisconnect bool) error {
|
||||
func (c *Client) RebootNow(ctx context.Context, waitDisconnect bool) error {
|
||||
|
||||
var err error
|
||||
var wg sync.WaitGroup
|
||||
|
||||
if waitDisconnect {
|
||||
wg.Add(1)
|
||||
err = c.On(gosocketio.OnDisconnection, func(h *gosocketio.Channel) {
|
||||
|
||||
var once sync.Once
|
||||
|
||||
done := func() {
|
||||
c.Off(gosocketio.OnDisconnection)
|
||||
wg.Done()
|
||||
}
|
||||
|
||||
wg.Add(1)
|
||||
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
err = ctx.Err()
|
||||
once.Do(done)
|
||||
}()
|
||||
|
||||
err = c.On(gosocketio.OnDisconnection, func(h *gosocketio.Channel) {
|
||||
once.Do(done)
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error while binding to '%s' event", gosocketio.OnDisconnection)
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package updater
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"forge.cadoles.com/Pyxis/orion/emlid"
|
||||
)
|
||||
|
@ -24,7 +26,9 @@ func TestClientRebootNow(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := client.RebootNow(true); err != nil {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
if err := client.RebootNow(ctx, true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package updater
|
||||
|
||||
import "context"
|
||||
|
||||
const (
|
||||
eventIsReceiverUpgradeAvailable = "is receiver upgrade available"
|
||||
eventReceiverUpgradeAvailable = "receiver upgrade available"
|
||||
|
@ -11,9 +13,9 @@ type receiverUpgreAvailable struct {
|
|||
}
|
||||
|
||||
// ReceiverUpgradeAvailable checks if an upgrade is avaialable/running for the ReachRS module
|
||||
func (c *Client) ReceiverUpgradeAvailable() (bool, bool, error) {
|
||||
func (c *Client) ReceiverUpgradeAvailable(ctx context.Context) (bool, bool, error) {
|
||||
res := &receiverUpgreAvailable{}
|
||||
if err := c.ReqResp(eventIsReceiverUpgradeAvailable, nil, eventReceiverUpgradeAvailable, res); err != nil {
|
||||
if err := c.ReqResp(ctx, eventIsReceiverUpgradeAvailable, nil, eventReceiverUpgradeAvailable, res); err != nil {
|
||||
return false, false, err
|
||||
}
|
||||
c.Logf("receiver upgrade result: available: %v, running: %v", res.Available, res.Running)
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package updater
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"forge.cadoles.com/Pyxis/orion/emlid"
|
||||
)
|
||||
|
@ -20,7 +22,9 @@ func TestClientReceiverUpgradeAvailable(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, _, err := client.ReceiverUpgradeAvailable()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
_, _, err := client.ReceiverUpgradeAvailable(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package updater
|
||||
|
||||
import "context"
|
||||
|
||||
const (
|
||||
eventGetTestResults = "get test results"
|
||||
eventTestResults = "test results"
|
||||
|
@ -16,9 +18,9 @@ type TestResults struct {
|
|||
}
|
||||
|
||||
// TestResults returns the ReachRS module tests results
|
||||
func (c *Client) TestResults() (*TestResults, error) {
|
||||
func (c *Client) TestResults(ctx context.Context) (*TestResults, error) {
|
||||
res := &TestResults{}
|
||||
if err := c.ReqResp(eventGetTestResults, nil, eventTestResults, res); err != nil {
|
||||
if err := c.ReqResp(ctx, eventGetTestResults, nil, eventTestResults, res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return res, nil
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package updater
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"forge.cadoles.com/Pyxis/orion/emlid"
|
||||
)
|
||||
|
@ -20,7 +22,9 @@ func TestClientTestResults(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
results, err := client.TestResults()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
results, err := client.TestResults(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package updater
|
||||
|
||||
import "context"
|
||||
|
||||
const (
|
||||
eventGetTimeSyncStatus = "get time sync status"
|
||||
eventTimeSyncResults = "time sync status"
|
||||
|
@ -11,9 +13,9 @@ type timeSyncStatus struct {
|
|||
|
||||
// TimeSynced returns the ReachRS module time synchronization status.
|
||||
// A true response means that the module has synchronized its clock.
|
||||
func (c *Client) TimeSynced() (bool, error) {
|
||||
func (c *Client) TimeSynced(ctx context.Context) (bool, error) {
|
||||
res := &timeSyncStatus{}
|
||||
if err := c.ReqResp(eventGetTimeSyncStatus, nil, eventTimeSyncResults, res); err != nil {
|
||||
if err := c.ReqResp(ctx, eventGetTimeSyncStatus, nil, eventTimeSyncResults, res); err != nil {
|
||||
return false, err
|
||||
}
|
||||
c.Logf("time sync result: %v", res.Status)
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package updater
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"forge.cadoles.com/Pyxis/orion/emlid"
|
||||
)
|
||||
|
@ -20,7 +22,9 @@ func TestClientTimeSync(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err := client.TimeSynced()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
_, err := client.TimeSynced(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package updater
|
||||
|
||||
import "context"
|
||||
|
||||
const (
|
||||
eventUpdate = "update"
|
||||
eventOPKGUpdateResult = "opkg update result"
|
||||
|
@ -13,9 +15,9 @@ type UpdateStatus struct {
|
|||
}
|
||||
|
||||
// Update asks the ReachRS module to start an OPKG update
|
||||
func (c *Client) Update() (*UpdateStatus, error) {
|
||||
func (c *Client) Update(ctx context.Context) (*UpdateStatus, error) {
|
||||
res := &UpdateStatus{}
|
||||
if err := c.ReqResp(eventUpdate, nil, eventOPKGUpdateResult, res); err != nil {
|
||||
if err := c.ReqResp(ctx, eventUpdate, nil, eventOPKGUpdateResult, res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.Logf(
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package updater
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"forge.cadoles.com/Pyxis/orion/emlid"
|
||||
)
|
||||
|
@ -20,7 +22,9 @@ func TestClientOPKGUpdate(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err := client.Update()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
_, err := client.Update(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package updater
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"forge.cadoles.com/Pyxis/golang-socketio"
|
||||
|
@ -41,48 +42,62 @@ type WifiNetwork struct {
|
|||
}
|
||||
|
||||
// WifiNetworks returns the ReachRS module wifi networks
|
||||
func (c *Client) WifiNetworks() ([]WifiNetwork, error) {
|
||||
func (c *Client) WifiNetworks(ctx context.Context) ([]WifiNetwork, error) {
|
||||
res := make([]WifiNetwork, 0)
|
||||
if err := c.ReqResp(eventGetSavedWifiNetworks, nil, eventSavedWifiNetworkResults, &res); err != nil {
|
||||
if err := c.ReqResp(ctx, eventGetSavedWifiNetworks, nil, eventSavedWifiNetworkResults, &res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// AddWifiNetwork asks the ReachRS module to save the given wifi network informations
|
||||
func (c *Client) AddWifiNetwork(ssid string, security WifiSecurity, password string) (bool, error) {
|
||||
func (c *Client) AddWifiNetwork(ctx context.Context, ssid string, security WifiSecurity, password string) (bool, error) {
|
||||
res := false
|
||||
network := &WifiNetwork{
|
||||
SSID: ssid,
|
||||
Security: security,
|
||||
Password: password,
|
||||
}
|
||||
if err := c.ReqResp(eventAddWifiNetwork, network, eventAddWifiNetworkResults, &res); err != nil {
|
||||
if err := c.ReqResp(ctx, eventAddWifiNetwork, network, eventAddWifiNetworkResults, &res); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// RemoveWifiNetwork asks the ReachRS module to remove the given WiFi network
|
||||
func (c *Client) RemoveWifiNetwork(ssid string) (bool, error) {
|
||||
func (c *Client) RemoveWifiNetwork(ctx context.Context, ssid string) (bool, error) {
|
||||
res := false
|
||||
if err := c.ReqResp(eventRemoveWifiNetwork, ssid, eventRemoveWifiNetworkResults, &res); err != nil {
|
||||
if err := c.ReqResp(ctx, eventRemoveWifiNetwork, ssid, eventRemoveWifiNetworkResults, &res); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// JoinWifiNetwork asks the ReachRS module to join the given WiFi network
|
||||
func (c *Client) JoinWifiNetwork(ssid string, waitDisconnect bool) error {
|
||||
func (c *Client) JoinWifiNetwork(ctx context.Context, ssid string, waitDisconnect bool) error {
|
||||
|
||||
var err error
|
||||
var wg sync.WaitGroup
|
||||
|
||||
if waitDisconnect {
|
||||
wg.Add(1)
|
||||
err = c.On(gosocketio.OnDisconnection, func(h *gosocketio.Channel) {
|
||||
|
||||
var once sync.Once
|
||||
|
||||
done := func() {
|
||||
c.Off(gosocketio.OnDisconnection)
|
||||
wg.Done()
|
||||
}
|
||||
|
||||
wg.Add(1)
|
||||
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
err = ctx.Err()
|
||||
once.Do(done)
|
||||
}()
|
||||
|
||||
err = c.On(gosocketio.OnDisconnection, func(h *gosocketio.Channel) {
|
||||
once.Do(done)
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error while binding to '%s' event", gosocketio.OnDisconnection)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package updater
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
@ -23,7 +24,9 @@ func TestClientSavedWiFiNetworks(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err := client.WifiNetworks()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
_, err := client.WifiNetworks(ctx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -48,7 +51,11 @@ func TestClientCRUDWiFiNetwork(t *testing.T) {
|
|||
|
||||
ssid := fmt.Sprintf("wifi_test_%d", rand.Uint32())
|
||||
|
||||
done, err := client.AddWifiNetwork(ssid, SecurityOpen, "")
|
||||
ctx := context.Background()
|
||||
|
||||
addWifiContext, addWifiCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer addWifiCancel()
|
||||
done, err := client.AddWifiNetwork(addWifiContext, ssid, SecurityOpen, "")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -57,7 +64,9 @@ func TestClientCRUDWiFiNetwork(t *testing.T) {
|
|||
t.Errorf("AddWifiNetwork() -> done: got '%v', expected '%v'", g, e)
|
||||
}
|
||||
|
||||
networks, err := client.WifiNetworks()
|
||||
wifiContext, wifiCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer wifiCancel()
|
||||
networks, err := client.WifiNetworks(wifiContext)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -74,7 +83,9 @@ func TestClientCRUDWiFiNetwork(t *testing.T) {
|
|||
t.Errorf("wifi network '%s' should exists", ssid)
|
||||
}
|
||||
|
||||
done, err = client.RemoveWifiNetwork(ssid)
|
||||
removeWifiContext, removeWifiCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer removeWifiCancel()
|
||||
done, err = client.RemoveWifiNetwork(removeWifiContext, ssid)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -107,7 +118,12 @@ func TestClientWifiNetworkJoin(t *testing.T) {
|
|||
|
||||
ssid := fmt.Sprintf("wifi_test_%d", rand.Uint32())
|
||||
|
||||
done, err := client.AddWifiNetwork(ssid, SecurityOpen, "")
|
||||
ctx := context.Background()
|
||||
|
||||
addWifiContext, addWifiCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer addWifiCancel()
|
||||
|
||||
done, err := client.AddWifiNetwork(addWifiContext, ssid, SecurityOpen, "")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -116,7 +132,9 @@ func TestClientWifiNetworkJoin(t *testing.T) {
|
|||
t.Errorf("AddWifiNetwork() -> done: got '%v', expected '%v'", g, e)
|
||||
}
|
||||
|
||||
if err := client.JoinWifiNetwork(ssid, true); err != nil {
|
||||
joinWifiContext, joinWifiCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer joinWifiCancel()
|
||||
if err := client.JoinWifiNetwork(joinWifiContext, ssid, true); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
# Example: ReachView
|
||||
|
||||
A simple example of a ReachView client that can:
|
||||
|
||||
- Configure a ReachRS module as "base" or "rover"
|
||||
|
||||
## Usage
|
||||
|
||||
1. Boot your ReachRS module in "ReachView" mode
|
||||
|
||||
2. Launch the example:
|
||||
```shell
|
||||
go run example/reachview/main.go \
|
||||
-mode 'rover|base'\
|
||||
-host '<DEVICE_IP_ADDRESS'\
|
||||
```
|
|
@ -0,0 +1,228 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"forge.cadoles.com/Pyxis/orion/emlid"
|
||||
"forge.cadoles.com/Pyxis/orion/emlid/reachview"
|
||||
)
|
||||
|
||||
const (
|
||||
modeRover = "rover"
|
||||
modeBase = "base"
|
||||
)
|
||||
|
||||
var (
|
||||
mode = modeRover
|
||||
host = "192.168.42.1"
|
||||
)
|
||||
|
||||
func init() {
|
||||
modes := []string{modeRover, modeBase}
|
||||
flag.StringVar(
|
||||
&mode, "mode", mode,
|
||||
fmt.Sprintf("The configuration mode. Available: %v", strings.Join(modes, ", ")),
|
||||
)
|
||||
flag.StringVar(&host, "host", host, "ReachRS module host")
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
flag.Parse()
|
||||
|
||||
switch mode {
|
||||
case modeRover:
|
||||
configureRover()
|
||||
case modeBase:
|
||||
configureBase()
|
||||
default:
|
||||
log.Fatalf("unknown mode '%s'", mode)
|
||||
}
|
||||
|
||||
log.Println("done")
|
||||
|
||||
}
|
||||
|
||||
func connect() *reachview.Client {
|
||||
|
||||
c := reachview.NewClient(
|
||||
emlid.WithEndpoint(host, 80),
|
||||
)
|
||||
|
||||
log.Printf("connecting to module '%s'", host)
|
||||
if err := c.Connect(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
log.Println("connected")
|
||||
|
||||
return c
|
||||
|
||||
}
|
||||
|
||||
func configureRover() {
|
||||
|
||||
c := connect()
|
||||
defer c.Close()
|
||||
|
||||
resetConfiguration(c)
|
||||
|
||||
config := getCommonConfiguration()
|
||||
config.RTKSettings.GPSARMode = reachview.GPSARModeFixAndHold
|
||||
config.RTKSettings.GLONASSARMode = reachview.On
|
||||
config.RTKSettings.PositionningMode = reachview.PositionningModeKinematic
|
||||
config.RTKSettings.UpdateRate = reachview.String("5")
|
||||
config.CorrectionInput = &reachview.CorrectionInput{
|
||||
Input2: &reachview.Input2{
|
||||
Input: reachview.Input{
|
||||
Enabled: reachview.True,
|
||||
Format: reachview.IOFormatRTCM3,
|
||||
Type: reachview.IOTypeLoRa,
|
||||
Path: reachview.String("lora"),
|
||||
},
|
||||
SendPositionToBase: reachview.Off,
|
||||
},
|
||||
}
|
||||
|
||||
log.Println("configuring module as rover")
|
||||
|
||||
applyConfiguration(c, config)
|
||||
|
||||
}
|
||||
|
||||
func configureBase() {
|
||||
|
||||
c := connect()
|
||||
defer c.Close()
|
||||
|
||||
resetConfiguration(c)
|
||||
|
||||
log.Println("configuring module as base")
|
||||
|
||||
config := getCommonConfiguration()
|
||||
config.RTKSettings.UpdateRate = reachview.String("1")
|
||||
config.BaseMode = &reachview.BaseMode{
|
||||
Output: &reachview.Output{
|
||||
Enabled: reachview.True,
|
||||
Format: reachview.IOFormatRTCM3,
|
||||
Type: reachview.IOTypeLoRa,
|
||||
},
|
||||
BaseCoordinates: &reachview.BaseCoordinates{
|
||||
Accumulation: reachview.String("1"),
|
||||
AntennaOffset: &reachview.AntennaOffset{
|
||||
Up: reachview.String("2.20"),
|
||||
},
|
||||
Mode: reachview.BaseCoordinatesModeAverageSingle,
|
||||
Format: reachview.BaseCoordinatesFormatLLH,
|
||||
},
|
||||
RTCM3Messages: &reachview.RTCM3Messages{
|
||||
Type1002: &reachview.RTCMMessageType{
|
||||
Enabled: reachview.True,
|
||||
Frequency: reachview.String("0.1"),
|
||||
},
|
||||
Type1006: &reachview.RTCMMessageType{
|
||||
Enabled: reachview.True,
|
||||
Frequency: reachview.String("0.1"),
|
||||
},
|
||||
Type1010: &reachview.RTCMMessageType{
|
||||
Enabled: reachview.True,
|
||||
Frequency: reachview.String("0.5"),
|
||||
},
|
||||
Type1097: &reachview.RTCMMessageType{
|
||||
Enabled: reachview.True,
|
||||
Frequency: reachview.String("0.5"),
|
||||
},
|
||||
Type1008: &reachview.RTCMMessageType{
|
||||
Enabled: reachview.False,
|
||||
},
|
||||
Type1019: &reachview.RTCMMessageType{
|
||||
Enabled: reachview.False,
|
||||
},
|
||||
Type1020: &reachview.RTCMMessageType{
|
||||
Enabled: reachview.False,
|
||||
},
|
||||
Type1107: &reachview.RTCMMessageType{
|
||||
Enabled: reachview.False,
|
||||
},
|
||||
Type1117: &reachview.RTCMMessageType{
|
||||
Enabled: reachview.False,
|
||||
},
|
||||
Type1127: &reachview.RTCMMessageType{
|
||||
Enabled: reachview.False,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
applyConfiguration(c, config)
|
||||
|
||||
}
|
||||
|
||||
func applyConfiguration(c *reachview.Client, config *reachview.Configuration) {
|
||||
|
||||
ctx, applyConfCancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer applyConfCancel()
|
||||
|
||||
result, _, err := c.ApplyConfiguration(ctx, config)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if result != reachview.ConfigurationApplySuccess {
|
||||
log.Fatal("configuration update failed !")
|
||||
}
|
||||
|
||||
log.Println("restarting rtklib")
|
||||
if err := c.RestartRTKLib(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func resetConfiguration(c *reachview.Client) {
|
||||
|
||||
log.Println("resetting module configuration")
|
||||
ctx, resetCancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer resetCancel()
|
||||
result, _, err := c.ResetConfiguration(ctx)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if result != reachview.ConfigurationApplySuccess {
|
||||
log.Fatal("configuration reset failed !")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func getCommonConfiguration() *reachview.Configuration {
|
||||
return &reachview.Configuration{
|
||||
RTKSettings: &reachview.RTKSettings{
|
||||
PositioningSystems: &reachview.PositionningSystems{
|
||||
GPS: reachview.True,
|
||||
GLONASS: reachview.True,
|
||||
Galileo: reachview.True,
|
||||
SBAS: reachview.True,
|
||||
QZSS: reachview.True,
|
||||
},
|
||||
UpdateRate: reachview.String("5"),
|
||||
},
|
||||
LoRa: &reachview.LoRa{
|
||||
AirRate: reachview.String("9.11"),
|
||||
Frequency: reachview.Float(868000),
|
||||
OutputPower: reachview.String("20"),
|
||||
},
|
||||
PositionOutput: &reachview.PositionOutput{
|
||||
Output1: &reachview.Output{
|
||||
Enabled: reachview.False,
|
||||
},
|
||||
Output2: &reachview.Output{
|
||||
Enabled: reachview.False,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
|
@ -1,10 +1,12 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"forge.cadoles.com/Pyxis/orion/emlid"
|
||||
"forge.cadoles.com/Pyxis/orion/emlid/updater"
|
||||
|
@ -78,8 +80,13 @@ func configureWifi() {
|
|||
c := connect()
|
||||
defer c.Close()
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
log.Println("checking module status")
|
||||
results, err := c.TestResults()
|
||||
|
||||
ctx, testResultsCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer testResultsCancel()
|
||||
results, err := c.TestResults(ctx)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -92,7 +99,9 @@ func configureWifi() {
|
|||
|
||||
log.Printf("adding wifi network '%s'", ssid)
|
||||
|
||||
done, err := c.AddWifiNetwork(ssid, updater.WifiSecurity(security), password)
|
||||
ctx, addWifiCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer addWifiCancel()
|
||||
done, err := c.AddWifiNetwork(ctx, ssid, updater.WifiSecurity(security), password)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -102,7 +111,9 @@ func configureWifi() {
|
|||
}
|
||||
|
||||
log.Println("connecting module to wifi network")
|
||||
if err := c.JoinWifiNetwork(ssid, true); err != nil {
|
||||
ctx, joinWifiCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer joinWifiCancel()
|
||||
if err := c.JoinWifiNetwork(ctx, ssid, true); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Printf("you can now switch to the wifi network and start phase '%s'", phaseUpdateThenReboot)
|
||||
|
@ -114,22 +125,30 @@ func updateThenReboot() {
|
|||
c := connect()
|
||||
defer c.Close()
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
log.Println("checking time sync")
|
||||
synced, err := c.TimeSynced()
|
||||
ctx, timeSyncedCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer timeSyncedCancel()
|
||||
synced, err := c.TimeSynced(ctx)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Printf("time synced ? %v", synced)
|
||||
|
||||
log.Println("checking reachview version")
|
||||
version, err := c.ReachViewVersion()
|
||||
ctx, reachviewVersionCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer reachviewVersionCancel()
|
||||
version, err := c.ReachViewVersion(ctx)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Printf("reachview version ? '%s'", version)
|
||||
|
||||
log.Println("checking for update")
|
||||
status, err := c.Update()
|
||||
ctx, updateCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer updateCancel()
|
||||
status, err := c.Update(ctx)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -143,7 +162,9 @@ func updateThenReboot() {
|
|||
}
|
||||
|
||||
log.Println("rebooting device")
|
||||
if err := c.RebootNow(true); err != nil {
|
||||
ctx, rebootCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer rebootCancel()
|
||||
if err := c.RebootNow(ctx, true); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
|
|
2
go.mod
2
go.mod
|
@ -3,7 +3,7 @@ module forge.cadoles.com/Pyxis/orion
|
|||
require (
|
||||
forge.cadoles.com/Pyxis/golang-socketio v0.0.0-20180919100209-bb857ced6b95
|
||||
github.com/caarlos0/env v3.3.0+incompatible
|
||||
github.com/davecgh/go-spew v1.1.1
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/go-chi/chi v3.3.3+incompatible
|
||||
github.com/gorilla/websocket v1.4.0 // indirect
|
||||
github.com/mitchellh/mapstructure v1.0.0
|
||||
|
|
Reference in New Issue