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.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, }, } 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.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"), }, 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, 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, }, }, }, } }