From 8ffd5a1d4f78728f2eaaa7ed7b3b935b7d2daa45 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sat, 27 Mar 2021 10:19:59 +0800 Subject: [PATCH] add reboot message --- proto | 2 +- src/esp32/BluetoothSoftwareUpdate.cpp | 9 --------- src/esp32/BluetoothSoftwareUpdate.h | 2 -- src/esp32/main-esp32.cpp | 3 +-- src/main.cpp | 15 +++++++++++++++ src/main.h | 2 ++ src/mesh/generated/admin.pb.h | 5 ++++- src/plugins/AdminPlugin.cpp | 7 +++++++ 8 files changed, 30 insertions(+), 15 deletions(-) diff --git a/proto b/proto index e8d2a96a0..f9c4f8758 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit e8d2a96a00713608ba4a6a36c9bea4ce06886619 +Subproject commit f9c4f875818c9aa6995e6e25803d52557a1779c7 diff --git a/src/esp32/BluetoothSoftwareUpdate.cpp b/src/esp32/BluetoothSoftwareUpdate.cpp index 843b14cf6..870d20ffd 100644 --- a/src/esp32/BluetoothSoftwareUpdate.cpp +++ b/src/esp32/BluetoothSoftwareUpdate.cpp @@ -16,7 +16,6 @@ int16_t updateResultHandle = -1; static CRC32 crc; -static uint32_t rebootAtMsec = 0; // If not zero we will reboot at this time (used to reboot shortly after the update completes) static uint32_t updateExpectedSize, updateActualSize; static uint8_t update_result; @@ -139,14 +138,6 @@ int update_region_callback(uint16_t conn_handle, uint16_t attr_handle, struct bl return chr_readwrite8(&update_region, sizeof(update_region), ctxt); } -void bluetoothRebootCheck() -{ - if (rebootAtMsec && millis() > rebootAtMsec) { - DEBUG_MSG("Rebooting for update\n"); - ESP.restart(); - } -} - /* See bluetooth-api.md diff --git a/src/esp32/BluetoothSoftwareUpdate.h b/src/esp32/BluetoothSoftwareUpdate.h index f5e1a1ded..478d478d5 100644 --- a/src/esp32/BluetoothSoftwareUpdate.h +++ b/src/esp32/BluetoothSoftwareUpdate.h @@ -4,8 +4,6 @@ void reinitUpdateService(); -void bluetoothRebootCheck(); - #ifdef __cplusplus extern "C" { #endif diff --git a/src/esp32/main-esp32.cpp b/src/esp32/main-esp32.cpp index 0e60fba83..856f89cc6 100644 --- a/src/esp32/main-esp32.cpp +++ b/src/esp32/main-esp32.cpp @@ -7,9 +7,9 @@ #include "sleep.h" #include "target_specific.h" #include "utils.h" +#include #include #include -#include void getMacAddr(uint8_t *dmac) { @@ -84,7 +84,6 @@ void esp32Loop() { esp_task_wdt_reset(); // service our app level watchdog loopBLE(); - bluetoothRebootCheck(); // for debug printing // radio.radioIf.canSleep(); diff --git a/src/main.cpp b/src/main.cpp index 1621d081f..7ce86ffc0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -576,6 +576,20 @@ Periodic axpDebugOutput(axpDebugRead); axpDebugOutput.setup(); #endif +uint32_t rebootAtMsec; // If not zero we will reboot at this time (used to reboot shortly after the update completes) + +void rebootCheck() +{ + if (rebootAtMsec && millis() > rebootAtMsec) { +#ifndef NO_ESP32 + DEBUG_MSG("Rebooting for update\n"); + ESP.restart(); +#else + DEBUG_MSG("FIXME implement reboot for this platform"); +#endif + } +} + void loop() { // axpDebugOutput.loop(); @@ -588,6 +602,7 @@ void loop() #ifdef NRF52_SERIES nrf52Loop(); #endif + rebootCheck(); // For debugging // if (rIf) ((RadioLibInterface *)rIf)->isActivelyReceiving(); diff --git a/src/main.h b/src/main.h index edb50d0d7..1a6dfe439 100644 --- a/src/main.h +++ b/src/main.h @@ -20,4 +20,6 @@ extern graphics::Screen *screen; // Return a human readable string of the form "Meshtastic_ab13" const char *getDeviceName(); +extern uint32_t rebootAtMsec; + void nrf52Setup(), esp32Setup(), nrf52Loop(), esp32Loop(); diff --git a/src/mesh/generated/admin.pb.h b/src/mesh/generated/admin.pb.h index cf71a9cb2..a2e753546 100644 --- a/src/mesh/generated/admin.pb.h +++ b/src/mesh/generated/admin.pb.h @@ -26,6 +26,7 @@ typedef struct _AdminMessage { bool confirm_set_channel; bool confirm_set_radio; bool exit_simulator; + int32_t reboot_seconds; }; } AdminMessage; @@ -49,6 +50,7 @@ extern "C" { #define AdminMessage_confirm_set_channel_tag 32 #define AdminMessage_confirm_set_radio_tag 33 #define AdminMessage_exit_simulator_tag 34 +#define AdminMessage_reboot_seconds_tag 35 /* Struct field encoding specification for nanopb */ #define AdminMessage_FIELDLIST(X, a) \ @@ -61,7 +63,8 @@ X(a, STATIC, ONEOF, UINT32, (variant,get_channel_request,get_channel_requ X(a, STATIC, ONEOF, MESSAGE, (variant,get_channel_response,get_channel_response), 7) \ X(a, STATIC, ONEOF, BOOL, (variant,confirm_set_channel,confirm_set_channel), 32) \ X(a, STATIC, ONEOF, BOOL, (variant,confirm_set_radio,confirm_set_radio), 33) \ -X(a, STATIC, ONEOF, BOOL, (variant,exit_simulator,exit_simulator), 34) +X(a, STATIC, ONEOF, BOOL, (variant,exit_simulator,exit_simulator), 34) \ +X(a, STATIC, ONEOF, INT32, (variant,reboot_seconds,reboot_seconds), 35) #define AdminMessage_CALLBACK NULL #define AdminMessage_DEFAULT NULL #define AdminMessage_variant_set_radio_MSGTYPE RadioConfig diff --git a/src/plugins/AdminPlugin.cpp b/src/plugins/AdminPlugin.cpp index 69e96875c..30016484e 100644 --- a/src/plugins/AdminPlugin.cpp +++ b/src/plugins/AdminPlugin.cpp @@ -77,6 +77,13 @@ bool AdminPlugin::handleReceivedProtobuf(const MeshPacket &mp, const AdminMessag handleGetRadio(mp); break; + case AdminMessage_reboot_seconds_tag: { + int32_t s = r->reboot_seconds; + DEBUG_MSG("Rebooting in %d seconds\n", s); + rebootAtMsec = (s < 0) ? 0 : (millis() + s * 1000); + break; + } + #ifdef PORTDUINO case AdminMessage_exit_simulator_tag: DEBUG_MSG("Exiting simulator\n");