This repository has been archived on 2024-08-02. You can view files and clone it, but cannot push or open issues or pull requests.
orion/cmd/configurator/main.go

246 lines
5.7 KiB
Go
Raw Permalink Normal View History

package main
import (
"context"
"flag"
"fmt"
"log"
"strings"
"time"
"forge.cadoles.com/Pyxis/orion/emlid"
"forge.cadoles.com/Pyxis/orion/emlid/reachview"
2020-11-26 16:59:17 +01:00
"github.com/pkg/errors"
)
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
2020-11-23 11:15:30 +01:00
config.RTKSettings.UpdateRate = reachview.Float(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,
},
}
2020-11-23 16:27:02 +01:00
config.BaseMode.Output = &reachview.Output{
Enabled: reachview.False,
}
log.Println("configuring module as rover")
applyConfiguration(c, config)
2020-11-26 16:59:17 +01:00
log.Println("rebooting module")
if err := c.Reboot(context.Background(), true); err != nil {
log.Fatal(errors.Wrap(err, "could not reboot module"))
}
}
func configureBase() {
c := connect()
defer c.Close()
resetConfiguration(c)
log.Println("configuring module as base")
config := getCommonConfiguration()
2020-11-23 11:15:30 +01:00
config.RTKSettings.UpdateRate = reachview.Float(1)
config.BaseMode.Output = &reachview.Output{
Enabled: reachview.True,
Format: reachview.IOFormatRTCM3,
Type: reachview.IOTypeLoRa,
}
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"),
},
2020-11-23 11:15:30 +01:00
Mode: reachview.BaseCoordinatesModeManual,
Format: reachview.BaseCoordinatesFormatLLH,
Coordinates: []*string{
reachview.String("0"),
reachview.String("0"),
reachview.String("0"),
},
}
applyConfiguration(c, config)
2020-11-26 16:59:17 +01:00
log.Println("rebooting module")
if err := c.Reboot(context.Background(), true); err != nil {
log.Fatal(errors.Wrap(err, "could not reboot module"))
}
}
func applyConfiguration(c *reachview.Client, config *reachview.Configuration) {
2020-11-23 11:15:30 +01:00
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")
2020-11-23 11:15:30 +01:00
ctx, resetCancel := context.WithTimeout(context.Background(), 10*time.Second)
defer resetCancel()
2020-11-23 11:15:30 +01:00
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,
2020-11-23 11:15:30 +01:00
Compass: reachview.False,
},
2020-11-23 11:15:30 +01:00
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,
},
},
2020-11-23 11:15:30 +01:00
BaseMode: &reachview.BaseMode{
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,
},
},
},
}
}