From 030bb818e119b90d8d17d9160a91f137dfdb454d Mon Sep 17 00:00:00 2001 From: William Petit Date: Thu, 6 Dec 2018 16:33:04 +0100 Subject: [PATCH] Add base manual position update example --- example/base-pos/main.go | 93 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 example/base-pos/main.go diff --git a/example/base-pos/main.go b/example/base-pos/main.go new file mode 100644 index 0000000..3bd6e3a --- /dev/null +++ b/example/base-pos/main.go @@ -0,0 +1,93 @@ +package main + +import ( + "context" + "flag" + "log" + "time" + + "forge.cadoles.com/Pyxis/orion/emlid" + "forge.cadoles.com/Pyxis/orion/emlid/reachview" +) + +var ( + host = "192.168.42.1" +) + +func init() { + flag.StringVar(&host, "host", host, "ReachRS module host") +} + +func main() { + + flag.Parse() + + c := connect() + defer c.Close() + + log.Println("updating base manual position") + + // 42["apply configuration",{"base mode":{"base coordinates":{"coordinates":["0","0","0"],"antenna offset":{"up":"0","east":"0","north":"0"},"format":"llh","mode":"fix-and-hold","accumulation":"2"}}}] + + config := &reachview.Configuration{ + BaseMode: &reachview.BaseMode{ + BaseCoordinates: &reachview.BaseCoordinates{ + Coordinates: []*string{ + reachview.String("2"), + reachview.String("0"), + reachview.String("0"), + }, + AntennaOffset: &reachview.AntennaOffset{ + East: reachview.String("0"), + North: reachview.String("0"), + Up: reachview.String("2"), + }, + Format: reachview.BaseCoordinatesFormatLLH, + Mode: reachview.String("manual"), + }, + }, + } + + applyConfiguration(c, config) + + 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 applyConfiguration(c *reachview.Client, config *reachview.Configuration) { + + ctx, applyConfCancel := context.WithTimeout(context.Background(), 20*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) + } + +}