Compare commits
1 Commits
c63ed31862
...
2ab245a4d1
Author | SHA1 | Date | |
---|---|---|---|
2ab245a4d1 |
@ -123,21 +123,6 @@ func (c *Client) SetBase(ctx context.Context, funcs ...protocol.SetBaseOptionFun
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBaseInfo implements protocol.Operations.
|
|
||||||
func (c *Client) GetBaseInfo(ctx context.Context) (*protocol.BaseInfo, error) {
|
|
||||||
_, ops, err := c.getProtocol(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.WithStack(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
baseInfo, err := ops.GetBaseInfo(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.WithStack(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return baseInfo, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reboot implements protocol.Operations.
|
// Reboot implements protocol.Operations.
|
||||||
func (c *Client) Reboot(ctx context.Context) error {
|
func (c *Client) Reboot(ctx context.Context) error {
|
||||||
_, ops, err := c.getProtocol(ctx)
|
_, ops, err := c.getProtocol(ctx)
|
||||||
|
@ -2,14 +2,6 @@ package protocol
|
|||||||
|
|
||||||
import "context"
|
import "context"
|
||||||
|
|
||||||
type BaseInfo struct {
|
|
||||||
Mode string
|
|
||||||
AntennaOffset float64
|
|
||||||
Latitude float64
|
|
||||||
Longitude float64
|
|
||||||
Height float64
|
|
||||||
}
|
|
||||||
|
|
||||||
type Operations interface {
|
type Operations interface {
|
||||||
// Connect initiates a new connection to the ReachView service
|
// Connect initiates a new connection to the ReachView service
|
||||||
// It should be called before any other operation
|
// It should be called before any other operation
|
||||||
@ -37,8 +29,6 @@ type Operations interface {
|
|||||||
// SetBase updates the base configuration
|
// SetBase updates the base configuration
|
||||||
SetBase(ctx context.Context, funcs ...SetBaseOptionFunc) error
|
SetBase(ctx context.Context, funcs ...SetBaseOptionFunc) error
|
||||||
|
|
||||||
GetBaseInfo(ctx context.Context) (*BaseInfo, error)
|
|
||||||
|
|
||||||
// Reboot restarts the module
|
// Reboot restarts the module
|
||||||
Reboot(ctx context.Context) error
|
Reboot(ctx context.Context) error
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package testsuite
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"math"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -157,7 +156,7 @@ var testCases = []operationTestCase{
|
|||||||
latitude := -90 + rand.Float64()*180
|
latitude := -90 + rand.Float64()*180
|
||||||
longitude := -180 + rand.Float64()*360
|
longitude := -180 + rand.Float64()*360
|
||||||
height := rand.Float64() * 1000
|
height := rand.Float64() * 1000
|
||||||
antennaOffset := toFixed(rand.Float64()*2, 3)
|
antennaOffset := rand.Float64() * 2
|
||||||
|
|
||||||
opts := []protocol.SetBaseOptionFunc{
|
opts := []protocol.SetBaseOptionFunc{
|
||||||
protocol.WithBaseLatitude(latitude),
|
protocol.WithBaseLatitude(latitude),
|
||||||
@ -174,30 +173,6 @@ var testCases = []operationTestCase{
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
baseInfo, err := ops.GetBaseInfo(ctx)
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("%+v", errors.WithStack(err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Logf("base info: %v", spew.Sdump(baseInfo))
|
|
||||||
|
|
||||||
if e, g := latitude, baseInfo.Latitude; e != g {
|
|
||||||
t.Errorf("baseInfo.Latitude: expected '%v', got '%v'", e, g)
|
|
||||||
}
|
|
||||||
|
|
||||||
if e, g := longitude, baseInfo.Longitude; e != g {
|
|
||||||
t.Errorf("baseInfo.Longitude: expected '%v', got '%v'", e, g)
|
|
||||||
}
|
|
||||||
|
|
||||||
if e, g := height, baseInfo.Height; e != g {
|
|
||||||
t.Errorf("baseInfo.Height: expected '%v', got '%v'", e, g)
|
|
||||||
}
|
|
||||||
|
|
||||||
if e, g := antennaOffset, baseInfo.AntennaOffset; e != g {
|
|
||||||
t.Errorf("baseInfo.AntennaOffset: expected '%v', got '%v'", e, g)
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -264,9 +239,3 @@ func TestOperations(t *testing.T, opsFactory OperationsFactoryFunc) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func toFixed(n float64, precision int) float64 {
|
|
||||||
scale := math.Pow(10, float64(precision))
|
|
||||||
|
|
||||||
return math.Round(n*scale) / scale
|
|
||||||
}
|
|
||||||
|
@ -297,52 +297,6 @@ func (o *Operations) SetBase(ctx context.Context, funcs ...protocol.SetBaseOptio
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBaseInfo implements protocol.Operations.
|
|
||||||
func (o *Operations) GetBaseInfo(ctx context.Context) (*protocol.BaseInfo, error) {
|
|
||||||
rawConfig, err := o.Configuration(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.WithStack(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
config := rawConfig.(*model.Configuration)
|
|
||||||
baseMode := config.BaseMode
|
|
||||||
|
|
||||||
var baseCoordinates *model.BaseCoordinates
|
|
||||||
if baseMode != nil && baseMode.BaseCoordinates != nil {
|
|
||||||
baseCoordinates = baseMode.BaseCoordinates
|
|
||||||
}
|
|
||||||
|
|
||||||
antennaOffset, err := strconv.ParseFloat(*baseCoordinates.AntennaOffset.Up, 64)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.WithStack(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
latitude, err := strconv.ParseFloat(*baseCoordinates.Coordinates[0], 64)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.WithStack(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
longitude, err := strconv.ParseFloat(*baseCoordinates.Coordinates[1], 64)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.WithStack(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
height, err := strconv.ParseFloat(*baseCoordinates.Coordinates[2], 64)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.WithStack(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
baseInfo := &protocol.BaseInfo{
|
|
||||||
Mode: *config.BaseMode.BaseCoordinates.Mode,
|
|
||||||
AntennaOffset: antennaOffset,
|
|
||||||
Height: height,
|
|
||||||
Latitude: latitude,
|
|
||||||
Longitude: longitude,
|
|
||||||
}
|
|
||||||
|
|
||||||
return baseInfo, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
eventGetReachViewVersion = "get reachview version"
|
eventGetReachViewVersion = "get reachview version"
|
||||||
eventReachViewVersionResults = "current reachview version"
|
eventReachViewVersionResults = "current reachview version"
|
||||||
|
@ -116,16 +116,6 @@ func (o *Operations) PostBaseCoordinates(ctx context.Context, base *model.Base)
|
|||||||
return &updated, nil
|
return &updated, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Operations) PostDevice(ctx context.Context, device *model.ConfigurationDevice) (*model.ConfigurationDevice, error) {
|
|
||||||
var updated model.ConfigurationDevice
|
|
||||||
|
|
||||||
if err := o.PostJSON("/configuration/device", device, &updated); err != nil {
|
|
||||||
return nil, errors.WithStack(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &updated, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o *Operations) GetUpdater(ctx context.Context) (*model.Updater, error) {
|
func (o *Operations) GetUpdater(ctx context.Context) (*model.Updater, error) {
|
||||||
updater := &model.Updater{}
|
updater := &model.Updater{}
|
||||||
if err := o.GetJSON("/updater", updater); err != nil {
|
if err := o.GetJSON("/updater", updater); err != nil {
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
type Base struct {
|
type Base struct {
|
||||||
Accumulation int `json:"accumulation"`
|
Accumulation int `json:"accumulation,omitempty"`
|
||||||
AntennaOffset float64 `json:"antenna_offset"`
|
AntennaOffset float64 `json:"antenna_offset,omitempty"`
|
||||||
Coordinates BaseCoordinates `json:"coordinates"`
|
Coordinates BaseCoordinates `json:"coordinates,omitempty"`
|
||||||
Mode string `json:"mode"`
|
Mode string `json:"mode,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type BaseCoordinates struct {
|
type BaseCoordinates struct {
|
||||||
Height float64 `json:"height"`
|
Height float64 `json:"height,omitempty"`
|
||||||
Latitude float64 `json:"latitude"`
|
Latitude float64 `json:"latitude,omitempty"`
|
||||||
Longitude float64 `json:"longitude"`
|
Longitude float64 `json:"longitude,omitempty"`
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,15 @@ type Configuration struct {
|
|||||||
} `json:"settings,omitempty"`
|
} `json:"settings,omitempty"`
|
||||||
} `json:"base_corrections,omitempty"`
|
} `json:"base_corrections,omitempty"`
|
||||||
} `json:"correction_input,omitempty"`
|
} `json:"correction_input,omitempty"`
|
||||||
Device ConfigurationDevice `json:"device,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 {
|
Logging struct {
|
||||||
Logs struct {
|
Logs struct {
|
||||||
Autostart bool `json:"autostart,omitempty"`
|
Autostart bool `json:"autostart,omitempty"`
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
package model
|
|
||||||
|
|
||||||
type ConfigurationDevice 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"`
|
|
||||||
}
|
|
@ -60,8 +60,6 @@ func (o *Operations) Reboot(ctx context.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
const DeviceHeight = 0.134
|
|
||||||
|
|
||||||
// SetBase implements protocol.Operations.
|
// SetBase implements protocol.Operations.
|
||||||
func (o *Operations) SetBase(ctx context.Context, funcs ...protocol.SetBaseOptionFunc) error {
|
func (o *Operations) SetBase(ctx context.Context, funcs ...protocol.SetBaseOptionFunc) error {
|
||||||
config, err := o.GetConfiguration(ctx)
|
config, err := o.GetConfiguration(ctx)
|
||||||
@ -98,41 +96,17 @@ func (o *Operations) SetBase(ctx context.Context, funcs ...protocol.SetBaseOptio
|
|||||||
base.Coordinates.Longitude = *opts.Longitude
|
base.Coordinates.Longitude = *opts.Longitude
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if opts.AntennaOffset != nil {
|
||||||
|
base.AntennaOffset = *opts.AntennaOffset
|
||||||
|
}
|
||||||
|
|
||||||
if _, err := o.PostBaseCoordinates(ctx, base); err != nil {
|
if _, err := o.PostBaseCoordinates(ctx, base); err != nil {
|
||||||
return errors.WithStack(err)
|
return errors.WithStack(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.AntennaOffset != nil {
|
|
||||||
device := &model.ConfigurationDevice{
|
|
||||||
AntennaHeight: *opts.AntennaOffset + DeviceHeight,
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := o.PostDevice(ctx, device); err != nil {
|
|
||||||
return errors.WithStack(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBaseInfo implements protocol.Operations.
|
|
||||||
func (o *Operations) GetBaseInfo(ctx context.Context) (*protocol.BaseInfo, error) {
|
|
||||||
config, err := o.GetConfiguration(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.WithStack(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
baseInfo := &protocol.BaseInfo{
|
|
||||||
Mode: config.BaseMode.BaseCoordinates.Mode,
|
|
||||||
AntennaOffset: config.BaseMode.BaseCoordinates.AntennaOffset - DeviceHeight,
|
|
||||||
Height: config.BaseMode.BaseCoordinates.Coordinates.Height,
|
|
||||||
Latitude: config.BaseMode.BaseCoordinates.Coordinates.Latitude,
|
|
||||||
Longitude: config.BaseMode.BaseCoordinates.Coordinates.Longitude,
|
|
||||||
}
|
|
||||||
|
|
||||||
return baseInfo, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configuration implements protocol.Operations.
|
// Configuration implements protocol.Operations.
|
||||||
func (o *Operations) Configuration(ctx context.Context) (any, error) {
|
func (o *Operations) Configuration(ctx context.Context) (any, error) {
|
||||||
config, err := o.GetConfiguration(ctx)
|
config, err := o.GetConfiguration(ctx)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user