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, }, }, } }