Upgrade to ReachView v2.24.0
This commit is contained in:
@ -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{}) {
|
||||
err = mapstructure.WeakDecode(data, res)
|
||||
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
17
emlid/common/client.go
Normal 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...),
|
||||
}
|
||||
}
|
51
emlid/common/handle_version.go
Normal file
51
emlid/common/handle_version.go
Normal 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
|
||||
}
|
@ -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
|
||||
}
|
@ -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
13
emlid/common/util_test.go
Normal 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",
|
||||
)
|
@ -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...),
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,19 @@
|
||||
package reachview
|
||||
|
||||
import "context"
|
||||
import (
|
||||
"context"
|
||||
|
||||
"forge.cadoles.com/Pyxis/orion/emlid/common"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
eventGetConfiguration = "get configuration"
|
||||
eventCurrentConfiguration = "current configuration"
|
||||
eventApplyConfiguration = "apply configuration"
|
||||
eventConfigurationApplied = "configuration applied"
|
||||
eventResetConfiguration = "reset configuration to default"
|
||||
eventGetConfiguration = "get configuration"
|
||||
eventCurrentConfiguration = "current configuration"
|
||||
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) {
|
||||
res := &configurationApplied{}
|
||||
if err := r.ReqResp(ctx, eventResetConfiguration, nil, eventConfigurationApplied, res); err != nil {
|
||||
return ConfigurationApplyFailed, nil, err
|
||||
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 errors.WithStack(err)
|
||||
}
|
||||
|
||||
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 res.Result, res.Configuration, nil
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -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"`
|
||||
|
@ -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}
|
||||
}
|
||||
|
Reference in New Issue
Block a user