Add release target to generate compiled version archive
This commit is contained in:
16
cmd/configurator/README.md
Normal file
16
cmd/configurator/README.md
Normal file
@ -0,0 +1,16 @@
|
||||
# Example: Configurator
|
||||
|
||||
A simple example of a ReachView client that can:
|
||||
|
||||
- Configure a ReachRS module as "base" or "rover"
|
||||
|
||||
## Usage
|
||||
|
||||
1. Boot your ReachRS module in "ReachView" mode
|
||||
|
||||
2. Launch the example:
|
||||
```shell
|
||||
go run cmd/configurator/main.go \
|
||||
-mode 'rover|base'\
|
||||
-host '<DEVICE_IP_ADDRESS'\
|
||||
```
|
228
cmd/configurator/main.go
Normal file
228
cmd/configurator/main.go
Normal file
@ -0,0 +1,228 @@
|
||||
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,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
41
cmd/discovery/main.go
Normal file
41
cmd/discovery/main.go
Normal file
@ -0,0 +1,41 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"forge.cadoles.com/Pyxis/orion/emlid"
|
||||
)
|
||||
|
||||
var (
|
||||
timeout = 10 * time.Second
|
||||
)
|
||||
|
||||
func init() {
|
||||
flag.DurationVar(&timeout, "timeout", timeout, "mDNS scan timeout")
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
flag.Parse()
|
||||
|
||||
log.Println("Searching for ReachRS services on network...")
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
defer cancel()
|
||||
|
||||
services, err := emlid.Discover(ctx)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
for _, s := range services {
|
||||
log.Println("Found:")
|
||||
log.Printf(" Name: '%s'", s.Name)
|
||||
log.Printf(" Hosts: %s", s.AddrV4)
|
||||
log.Printf(" Port: '%d'", s.Port)
|
||||
}
|
||||
|
||||
}
|
27
cmd/updater/README.md
Normal file
27
cmd/updater/README.md
Normal file
@ -0,0 +1,27 @@
|
||||
# Example: Updater
|
||||
|
||||
A simple example of an updater client wich can:
|
||||
|
||||
- Configure a ReachRS module to use the given WiFi network
|
||||
- Check for updates then reboot to "ReachView" mode
|
||||
|
||||
## Usage
|
||||
|
||||
1. Boot your ReachRS module in "Updater" mode. You can see a documentation on how to reset your device [here](https://forge.cadoles.com/Pyxis/orion/wiki/FlashIt).
|
||||
|
||||
2. Launch the example in `configure-wifi` phase and provides WiFi network informations.
|
||||
```shell
|
||||
go run cmd/updater/main.go \
|
||||
-phase 'configure-wifi'\
|
||||
-host '<DEVICE_IP_ADDRESS'\
|
||||
-ssid '<WIFI_SSID>'\
|
||||
-password '<WIFI_PASSWORD>'\
|
||||
-security '<WIFI_SECURITY>'
|
||||
```
|
||||
3. The device will switch to the provided WiFi network, as you should do.
|
||||
4. Launch the example in `update-then-reboot` phase.
|
||||
```shell
|
||||
go run cmd/updater/main.go \
|
||||
-phase 'update-and-reboot'\
|
||||
-host '<DEVICE_IP_ADDRESS'
|
||||
```
|
171
cmd/updater/main.go
Normal file
171
cmd/updater/main.go
Normal file
@ -0,0 +1,171 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"forge.cadoles.com/Pyxis/orion/emlid"
|
||||
"forge.cadoles.com/Pyxis/orion/emlid/updater"
|
||||
)
|
||||
|
||||
const (
|
||||
phaseConfigureWifi = "configure-wifi"
|
||||
phaseUpdateThenReboot = "update-then-reboot"
|
||||
)
|
||||
|
||||
var (
|
||||
phase = phaseConfigureWifi
|
||||
host = "192.168.42.1"
|
||||
ssid = ""
|
||||
security = string(updater.SecurityWPAPSK)
|
||||
password = ""
|
||||
)
|
||||
|
||||
func init() {
|
||||
phases := []string{phaseConfigureWifi, phaseUpdateThenReboot}
|
||||
flag.StringVar(
|
||||
&phase, "phase", phase,
|
||||
fmt.Sprintf("The configuration phase. Available: %v", strings.Join(phases, ", ")),
|
||||
)
|
||||
flag.StringVar(&host, "host", host, "ReachRS module host")
|
||||
flag.StringVar(&ssid, "ssid", ssid, "The WiFi SSID to connect the module to")
|
||||
flag.StringVar(&security, "security", security, "The WiFi security algorithm")
|
||||
flag.StringVar(&password, "password", password, "The WiFi password")
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
flag.Parse()
|
||||
|
||||
switch phase {
|
||||
case phaseConfigureWifi:
|
||||
configureWifi()
|
||||
case phaseUpdateThenReboot:
|
||||
updateThenReboot()
|
||||
default:
|
||||
log.Fatalf("unknown phase '%s'", phase)
|
||||
}
|
||||
|
||||
log.Println("done")
|
||||
|
||||
}
|
||||
|
||||
func connect() *updater.Client {
|
||||
|
||||
c := updater.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 configureWifi() {
|
||||
|
||||
if ssid == "" {
|
||||
log.Fatal("you must provide a WiFi SSID with the -ssid flag")
|
||||
}
|
||||
|
||||
c := connect()
|
||||
defer c.Close()
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
log.Println("checking module status")
|
||||
|
||||
ctx, testResultsCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer testResultsCancel()
|
||||
results, err := c.TestResults(ctx)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
log.Printf("device: '%s'", results.Device)
|
||||
log.Printf("lora activated ? %v", results.Lora)
|
||||
log.Printf("mpu activated ? %v", results.MPU)
|
||||
log.Printf("stc activated ? %v", results.STC)
|
||||
log.Printf("ublox activated ? %v", results.UBlox)
|
||||
|
||||
log.Printf("adding wifi network '%s'", ssid)
|
||||
|
||||
ctx, addWifiCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer addWifiCancel()
|
||||
done, err := c.AddWifiNetwork(ctx, ssid, updater.WifiSecurity(security), password)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if !done {
|
||||
log.Fatal("couldnt add wifi network")
|
||||
}
|
||||
|
||||
log.Println("connecting module to wifi network")
|
||||
ctx, joinWifiCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer joinWifiCancel()
|
||||
if err := c.JoinWifiNetwork(ctx, ssid, true); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Printf("you can now switch to the wifi network and start phase '%s'", phaseUpdateThenReboot)
|
||||
|
||||
}
|
||||
|
||||
func updateThenReboot() {
|
||||
|
||||
c := connect()
|
||||
defer c.Close()
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
log.Println("checking time sync")
|
||||
ctx, timeSyncedCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer timeSyncedCancel()
|
||||
synced, err := c.TimeSynced(ctx)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Printf("time synced ? %v", synced)
|
||||
|
||||
log.Println("checking reachview version")
|
||||
ctx, reachviewVersionCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer reachviewVersionCancel()
|
||||
version, err := c.ReachViewVersion(ctx)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Printf("reachview version ? '%s'", version)
|
||||
|
||||
log.Println("checking for update")
|
||||
ctx, updateCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer updateCancel()
|
||||
status, err := c.Update(ctx)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
log.Printf("is update running ? %v", status.Active)
|
||||
log.Printf("is update locked ? %v", status.Locked)
|
||||
log.Printf("last update state ? '%s'", status.State)
|
||||
|
||||
if status.Active {
|
||||
log.Fatal("cannot reboot while an update is active")
|
||||
}
|
||||
|
||||
log.Println("rebooting device")
|
||||
ctx, rebootCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer rebootCancel()
|
||||
if err := c.RebootNow(ctx, true); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user