Upgrade to ReachView v2.24.0

This commit is contained in:
wpetit 2020-11-23 11:15:30 +01:00
parent b8a07953dd
commit e06aa5129a
16 changed files with 260 additions and 103 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
/bin
/.env
/release
*.log

View File

@ -39,4 +39,7 @@ doc:
release:
scripts/release
spy-websocket:
echo > websocket.log && sudo tshark -Y websocket.payload -Tfields -e text | tee -a websocket.log
.PHONY: test clean generate vendor install-devtools lint watch tidy doc release

View File

@ -76,7 +76,7 @@ func configureRover() {
config.RTKSettings.GPSARMode = reachview.GPSARModeFixAndHold
config.RTKSettings.GLONASSARMode = reachview.On
config.RTKSettings.PositionningMode = reachview.PositionningModeKinematic
config.RTKSettings.UpdateRate = reachview.String("5")
config.RTKSettings.UpdateRate = reachview.Float(5)
config.CorrectionInput = &reachview.CorrectionInput{
Input2: &reachview.Input2{
Input: reachview.Input{
@ -105,21 +105,91 @@ func configureBase() {
log.Println("configuring module as base")
config := getCommonConfiguration()
config.RTKSettings.UpdateRate = reachview.String("1")
config.BaseMode = &reachview.BaseMode{
Output: &reachview.Output{
config.RTKSettings.UpdateRate = reachview.Float(1)
config.BaseMode.Output = &reachview.Output{
Enabled: reachview.True,
Format: reachview.IOFormatRTCM3,
Type: reachview.IOTypeLoRa,
},
BaseCoordinates: &reachview.BaseCoordinates{
}
config.BaseMode.BaseCoordinates = &reachview.BaseCoordinates{
Accumulation: reachview.String("1"),
AntennaOffset: &reachview.AntennaOffset{
East: reachview.String("0"),
North: reachview.String("0"),
Up: reachview.String("2.20"),
},
Mode: reachview.BaseCoordinatesModeAverageSingle,
Mode: reachview.BaseCoordinatesModeManual,
Format: reachview.BaseCoordinatesFormatLLH,
Coordinates: []*string{
reachview.String("0"),
reachview.String("0"),
reachview.String("0"),
},
}
applyConfiguration(c, config)
}
func applyConfiguration(c *reachview.Client, config *reachview.Configuration) {
ctx, applyConfCancel := context.WithTimeout(context.Background(), 60*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 !")
}
}
func resetConfiguration(c *reachview.Client) {
log.Println("resetting module configuration")
ctx, resetCancel := context.WithTimeout(context.Background(), 10*time.Second)
defer resetCancel()
if err := c.ResetConfiguration(ctx); err != nil {
log.Fatal(err)
}
}
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,
Compass: reachview.False,
},
MaxHorizontalAcceleration: reachview.String("1"),
GPSARMode: reachview.String("fix-and-hold"),
SNRMask: reachview.String("35"),
GLONASSARMode: reachview.String("off"),
UpdateRate: reachview.Float(5),
ElevationMaskAngle: reachview.String("15"),
PositionningMode: reachview.String("kinematic"),
MaxVerticalAcceleration: reachview.String("1"),
},
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,
},
},
BaseMode: &reachview.BaseMode{
RTCM3Messages: &reachview.RTCM3Messages{
Type1002: &reachview.RTCMMessageType{
Enabled: reachview.True,
@ -156,73 +226,6 @@ func configureBase() {
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,
},
},
}
}

View File

@ -139,7 +139,7 @@ func updateThenReboot() {
log.Println("checking reachview version")
ctx, reachviewVersionCancel := context.WithTimeout(ctx, 5*time.Second)
defer reachviewVersionCancel()
version, err := c.ReachViewVersion(ctx)
version, _, err := c.ReachViewVersion(ctx)
if err != nil {
log.Fatal(err)
}

View File

@ -4,7 +4,7 @@ import (
"context"
"sync"
"forge.cadoles.com/Pyxis/golang-socketio"
gosocketio "forge.cadoles.com/Pyxis/golang-socketio"
"forge.cadoles.com/Pyxis/golang-socketio/transport"
"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
@ -80,6 +80,9 @@ func (c *Client) Close() {
// Emit a new event with the given data
func (c *Client) Emit(event string, data interface{}) error {
// enc := json.NewEncoder(os.Stdout)
// enc.SetIndent("", " ")
// enc.Encode(data)
c.Logf("emit '%s' event", event)
if err := c.conn.Emit(event, data); err != nil {
return errors.Wrapf(err, "error while emitting '%s' event", event)
@ -121,7 +124,13 @@ func (c *Client) ReqResp(ctx context.Context,
}()
err = c.conn.On(responseEvent, func(_ *gosocketio.Channel, data interface{}) {
if res != nil {
// enc := json.NewEncoder(os.Stdout)
// enc.SetIndent("", " ")
// enc.Encode(data)
err = mapstructure.WeakDecode(data, res)
}
once.Do(done)
})
if err != nil {

17
emlid/common/client.go Normal file
View File

@ -0,0 +1,17 @@
package common
import (
"forge.cadoles.com/Pyxis/orion/emlid"
)
// Client is a ReachRS Updater client
type Client struct {
*emlid.Client
}
// NewClient returns a new ReachRS ReachView client
func NewClient(opts ...emlid.OptionFunc) *Client {
return &Client{
Client: emlid.NewClient(opts...),
}
}

View File

@ -0,0 +1,51 @@
package common
import (
"context"
"github.com/blang/semver/v4"
"github.com/pkg/errors"
)
type VersionHandlerFunc func(ctx context.Context, version string, stable bool) error
type VersionHandler struct {
Range string
Handler VersionHandlerFunc
}
func NewVersionHandler(versionRange string, h VersionHandlerFunc) *VersionHandler {
return &VersionHandler{
Range: versionRange,
Handler: h,
}
}
func (c *Client) HandleVersion(ctx context.Context, handlers ...*VersionHandler) error {
rawVersion, stable, err := c.ReachViewVersion(ctx)
if err != nil {
return errors.Wrap(err, "could not retrieve reachview version")
}
version, err := semver.ParseTolerant(rawVersion)
if err != nil {
return errors.Wrap(err, "could not parse reachview version")
}
for _, h := range handlers {
versionRange, err := semver.ParseRange(h.Range)
if err != nil {
return errors.Wrap(err, "could not parse handler version range")
}
if !versionRange(version) {
continue
}
if err := h.Handler(ctx, rawVersion, stable); err != nil {
return errors.WithStack(err)
}
}
return nil
}

View File

@ -1,6 +1,9 @@
package updater
package common
import "context"
import (
"context"
"strings"
)
const (
eventGetReachViewVersion = "get reachview version"
@ -9,13 +12,15 @@ const (
type reachViewVersion struct {
Version string `json:"version"`
Stable bool `json:"bool"`
}
// ReachViewVersion returns the ReachRS module ReachView version
func (c *Client) ReachViewVersion(ctx context.Context) (string, error) {
func (c *Client) ReachViewVersion(ctx context.Context) (string, bool, error) {
res := &reachViewVersion{}
if err := c.ReqResp(ctx, eventGetReachViewVersion, nil, eventReachViewVersionResults, res); err != nil {
return "", err
return "", false, err
}
return res.Version, nil
return strings.TrimSpace(res.Version), res.Stable, nil
}

View File

@ -1,4 +1,4 @@
package updater
package common
import (
"context"
@ -10,7 +10,7 @@ import (
func TestClientReachViewVersion(t *testing.T) {
if !*runUpdaterIntegrationTests {
if !*runCommonIntegrationTests {
t.Skip("To run this test, use: go test -updater-integration")
}
@ -21,9 +21,11 @@ func TestClientReachViewVersion(t *testing.T) {
if err := client.Connect(); err != nil {
t.Fatal(err)
}
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
version, err := client.ReachViewVersion(ctx)
version, _, err := client.ReachViewVersion(ctx)
if err != nil {
t.Error(err)
}

13
emlid/common/util_test.go Normal file
View File

@ -0,0 +1,13 @@
package common
import "flag"
var runCommonIntegrationTests = flag.Bool(
"common-integration", false,
"Run the 'Common' integration tests (in addition to the unit tests)",
)
var reachHost = flag.String(
"reach-host", "192.168.42.1",
"The Reach module host to use in integration tests",
)

View File

@ -1,14 +1,18 @@
package reachview
import "forge.cadoles.com/Pyxis/orion/emlid"
import (
"forge.cadoles.com/Pyxis/orion/emlid"
"forge.cadoles.com/Pyxis/orion/emlid/common"
)
// Client is a ReachRS Updater client
type Client struct {
*emlid.Client
*common.Client
}
// NewClient returns a new ReachRS ReachView client
func NewClient(opts ...emlid.OptionFunc) *Client {
client := emlid.NewClient(opts...)
return &Client{client}
return &Client{
Client: common.NewClient(opts...),
}
}

View File

@ -1,6 +1,11 @@
package reachview
import "context"
import (
"context"
"forge.cadoles.com/Pyxis/orion/emlid/common"
"github.com/pkg/errors"
)
const (
eventGetConfiguration = "get configuration"
@ -8,6 +13,7 @@ const (
eventApplyConfiguration = "apply configuration"
eventConfigurationApplied = "configuration applied"
eventResetConfiguration = "reset configuration to default"
eventSettingsResetToDefault = "settings reset to default"
)
// Configuration fetches and return the current configuration of the ReachRS module
@ -42,10 +48,32 @@ func (r *Client) ApplyConfiguration(ctx context.Context, config *Configuration)
}
// ResetConfiguration resets the module configuration to factory defaults
func (r *Client) ResetConfiguration(ctx context.Context) (string, *Configuration, error) {
func (r *Client) ResetConfiguration(ctx context.Context) error {
err := r.HandleVersion(
ctx,
common.NewVersionHandler("< 2.24.0", func(ctx context.Context, version string, stable bool) error {
res := &configurationApplied{}
if err := r.ReqResp(ctx, eventResetConfiguration, nil, eventConfigurationApplied, res); err != nil {
return ConfigurationApplyFailed, nil, err
return errors.WithStack(err)
}
return res.Result, res.Configuration, nil
if res.Result != ConfigurationApplySuccess {
return errors.New(res.Result)
}
return nil
}),
common.NewVersionHandler(">= 2.24.0", func(ctx context.Context, version string, stable bool) error {
if err := r.ReqResp(ctx, eventResetConfiguration, nil, eventSettingsResetToDefault, nil); err != nil {
return errors.WithStack(err)
}
return nil
}),
)
if err != nil {
return errors.WithStack(err)
}
return nil
}

View File

@ -80,7 +80,7 @@ type Configuration struct {
// RTKSettings -
type RTKSettings struct {
GLONASSARMode *string `mapstructure:"glonass ar mode,omitempty" json:"glonass ar mode,omitempty"`
UpdateRate *string `mapstructure:"update rate,omitempty" json:"update rate,omitempty"`
UpdateRate *float64 `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"`

View File

@ -1,15 +1,18 @@
// Package updater provides an API to communicate with the ReachRS modules "Updater" application
package updater
import "forge.cadoles.com/Pyxis/orion/emlid"
import (
"forge.cadoles.com/Pyxis/orion/emlid"
"forge.cadoles.com/Pyxis/orion/emlid/common"
)
// Client is a ReachRS Updater client
type Client struct {
*emlid.Client
*common.Client
}
// NewClient returns a new ReachRS Updater client
func NewClient(opts ...emlid.OptionFunc) *Client {
client := emlid.NewClient(opts...)
client := common.NewClient(opts...)
return &Client{client}
}

11
go.mod
View File

@ -1,21 +1,22 @@
module forge.cadoles.com/Pyxis/orion
go 1.15
require (
forge.cadoles.com/Pyxis/golang-socketio v0.0.0-20180919100209-bb857ced6b95
github.com/caarlos0/env v3.4.0+incompatible
github.com/blang/semver/v4 v4.0.0
github.com/caarlos0/env v3.5.0+incompatible
github.com/cenkalti/backoff v2.0.0+incompatible // indirect
github.com/davecgh/go-spew v1.1.1
github.com/go-chi/chi v3.3.3+incompatible
github.com/gorilla/websocket v1.4.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/grandcat/zeroconf v0.0.0-20180329153754-df75bb3ccae1
github.com/miekg/dns v1.0.12 // indirect
github.com/mitchellh/mapstructure v1.1.2
github.com/pkg/errors v0.8.0
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v1.2.2 // indirect
golang.org/x/crypto v0.0.0-20181001203147-e3636079e1a4 // indirect
golang.org/x/net v0.0.0-20180911220305-26e67e76b6c3 // indirect
golang.org/x/crypto v0.0.0-20201117144127-c1f2f97bffc9 // indirect
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f // indirect
golang.org/x/sys v0.0.0-20181005133103-4497e2df6f9e // indirect
golang.org/x/text v0.3.0 // indirect
)

17
go.sum
View File

@ -1,7 +1,13 @@
forge.cadoles.com/Pyxis/golang-socketio v0.0.0-20180919100209-bb857ced6b95 h1:o3G5+9RjczCK1xAYFaRMknk1kY9Ule6PNfiW6N6hEpg=
forge.cadoles.com/Pyxis/golang-socketio v0.0.0-20180919100209-bb857ced6b95/go.mod h1:I6kYOFWNkFlNeQLI7ZqfTRz4NdPHZxX0Bzizmzgchs0=
github.com/blang/semver v1.1.0 h1:ol1rO7QQB5uy7umSNV7VAmLugfLRD+17sYJujRNYPhg=
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
github.com/caarlos0/env v3.4.0+incompatible h1:FRwBdvENjLHZoUbFnULnFss9wKtcapdaM35DfxiTjeM=
github.com/caarlos0/env v3.4.0+incompatible/go.mod h1:tdCsowwCzMLdkqRYDlHpZCp2UooDD3MspDBjZ2AD02Y=
github.com/caarlos0/env v3.5.0+incompatible h1:Yy0UN8o9Wtr/jGHZDpCBLpNrzcFLLM2yixi/rBrKyJs=
github.com/caarlos0/env v3.5.0+incompatible/go.mod h1:tdCsowwCzMLdkqRYDlHpZCp2UooDD3MspDBjZ2AD02Y=
github.com/cenkalti/backoff v2.0.0+incompatible h1:5IIPUHhlnUZbcHQsQou5k1Tn58nJkeJL9U+ig5CHJbY=
github.com/cenkalti/backoff v2.0.0+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
@ -10,6 +16,8 @@ github.com/go-chi/chi v3.3.3+incompatible h1:KHkmBEMNkwKuK4FdQL7N2wOeB9jnIx7jR5w
github.com/go-chi/chi v3.3.3+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ=
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grandcat/zeroconf v0.0.0-20180329153754-df75bb3ccae1 h1:VSELJSxQlpi1bz4ZwT+93hPpzNLRcgytLr77iVRJpcE=
github.com/grandcat/zeroconf v0.0.0-20180329153754-df75bb3ccae1/go.mod h1:YjKB0WsLXlMkO9p+wGTCoPIDGRJH0mz7E526PxkQVxI=
github.com/miekg/dns v1.0.12 h1:814rTNaw7Q7pGncpSEDT06YS8rdGmpUEnKgpQzctJsk=
@ -24,11 +32,20 @@ github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
golang.org/x/crypto v0.0.0-20181001203147-e3636079e1a4 h1:Vk3wNqEZwyGyei9yq5ekj7frek2u7HUfffJ1/opblzc=
golang.org/x/crypto v0.0.0-20181001203147-e3636079e1a4/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20201117144127-c1f2f97bffc9 h1:phUcVbl53swtrUN8kQEXFhUxPlIlWyBfKmidCu7P95o=
golang.org/x/crypto v0.0.0-20201117144127-c1f2f97bffc9/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/net v0.0.0-20180911220305-26e67e76b6c3 h1:czFLhve3vsQetD6JOJ8NZZvGQIXlnN3/yXxbT6/awxI=
golang.org/x/net v0.0.0-20180911220305-26e67e76b6c3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20181005133103-4497e2df6f9e h1:EfdBzeKbFSvOjoIqSZcfS8wp0FBLokGBEs9lz1OtSg0=
golang.org/x/sys v0.0.0-20181005133103-4497e2df6f9e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=