Add SkipUpdate() Updater method
Allow to skip the update step and reboot to ReachView
This commit is contained in:
@ -12,6 +12,8 @@ import (
|
||||
"forge.cadoles.com/Pyxis/orion/emlid/updater"
|
||||
)
|
||||
|
||||
const stepSleep = 5
|
||||
|
||||
const (
|
||||
phaseConfigureWifi = "configure-wifi"
|
||||
phaseUpdateThenReboot = "update-then-reboot"
|
||||
@ -97,6 +99,8 @@ func configureWifi() {
|
||||
log.Printf("stc activated ? %v", results.STC)
|
||||
log.Printf("ublox activated ? %v", results.UBlox)
|
||||
|
||||
sleep(stepSleep)
|
||||
|
||||
log.Printf("adding wifi network '%s'", ssid)
|
||||
|
||||
ctx, addWifiCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
@ -110,6 +114,8 @@ func configureWifi() {
|
||||
log.Fatal("couldnt add wifi network")
|
||||
}
|
||||
|
||||
sleep(stepSleep)
|
||||
|
||||
log.Println("connecting module to wifi network")
|
||||
ctx, joinWifiCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer joinWifiCancel()
|
||||
@ -125,47 +131,71 @@ func updateThenReboot() {
|
||||
c := connect()
|
||||
defer c.Close()
|
||||
|
||||
ctx := context.Background()
|
||||
log.Println("checking module status")
|
||||
ctx, testResultsCancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer testResultsCancel()
|
||||
results, err := c.TestResults(ctx)
|
||||
if err != nil {
|
||||
log.Fatalf("error while checking device state: %s", 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)
|
||||
|
||||
sleep(stepSleep)
|
||||
|
||||
log.Println("checking time sync")
|
||||
ctx, timeSyncedCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
ctx, timeSyncedCancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer timeSyncedCancel()
|
||||
synced, err := c.TimeSynced(ctx)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Fatalf("error while checking time sync status: %s", err)
|
||||
}
|
||||
log.Printf("time synced ? %v", synced)
|
||||
|
||||
sleep(stepSleep)
|
||||
|
||||
log.Println("checking for upgrade")
|
||||
ctx, upgradeAvailableCancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer upgradeAvailableCancel()
|
||||
_, _, err = c.ReceiverUpgradeAvailable(ctx)
|
||||
if err != nil {
|
||||
log.Fatalf("error while checking for upgrade: %s", err)
|
||||
}
|
||||
|
||||
sleep(stepSleep)
|
||||
|
||||
log.Println("checking reachview version")
|
||||
ctx, reachviewVersionCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
ctx, reachviewVersionCancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer reachviewVersionCancel()
|
||||
version, err := c.ReachViewVersion(ctx)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Fatalf("error while checking version: %s", 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)
|
||||
sleep(stepSleep)
|
||||
|
||||
log.Println("skipping update")
|
||||
if err := c.SkipUpdate(); err != nil {
|
||||
log.Fatalf("error while skipping update: %s", 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")
|
||||
}
|
||||
sleep(stepSleep)
|
||||
|
||||
log.Println("rebooting device")
|
||||
ctx, rebootCancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
ctx, rebootCancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer rebootCancel()
|
||||
if err := c.RebootNow(ctx, true); err != nil {
|
||||
log.Fatal(err)
|
||||
log.Fatalf("error while rebooting: %s", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func sleep(seconds int) {
|
||||
log.Printf("sleeping for %d seconds...", seconds)
|
||||
time.Sleep(time.Duration(seconds) * time.Second)
|
||||
}
|
||||
|
Reference in New Issue
Block a user