add reboot message

This commit is contained in:
Kevin Hester 2021-03-27 10:19:59 +08:00
parent 7e9e33d462
commit 8ffd5a1d4f
8 changed files with 30 additions and 15 deletions

2
proto

@ -1 +1 @@
Subproject commit e8d2a96a00713608ba4a6a36c9bea4ce06886619 Subproject commit f9c4f875818c9aa6995e6e25803d52557a1779c7

View File

@ -16,7 +16,6 @@
int16_t updateResultHandle = -1; int16_t updateResultHandle = -1;
static CRC32 crc; 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 uint32_t updateExpectedSize, updateActualSize;
static uint8_t update_result; 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); 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 See bluetooth-api.md

View File

@ -4,8 +4,6 @@
void reinitUpdateService(); void reinitUpdateService();
void bluetoothRebootCheck();
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif

View File

@ -7,9 +7,9 @@
#include "sleep.h" #include "sleep.h"
#include "target_specific.h" #include "target_specific.h"
#include "utils.h" #include "utils.h"
#include <driver/rtc_io.h>
#include <nvs.h> #include <nvs.h>
#include <nvs_flash.h> #include <nvs_flash.h>
#include <driver/rtc_io.h>
void getMacAddr(uint8_t *dmac) void getMacAddr(uint8_t *dmac)
{ {
@ -84,7 +84,6 @@ void esp32Loop()
{ {
esp_task_wdt_reset(); // service our app level watchdog esp_task_wdt_reset(); // service our app level watchdog
loopBLE(); loopBLE();
bluetoothRebootCheck();
// for debug printing // for debug printing
// radio.radioIf.canSleep(); // radio.radioIf.canSleep();

View File

@ -576,6 +576,20 @@ Periodic axpDebugOutput(axpDebugRead);
axpDebugOutput.setup(); axpDebugOutput.setup();
#endif #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() void loop()
{ {
// axpDebugOutput.loop(); // axpDebugOutput.loop();
@ -588,6 +602,7 @@ void loop()
#ifdef NRF52_SERIES #ifdef NRF52_SERIES
nrf52Loop(); nrf52Loop();
#endif #endif
rebootCheck();
// For debugging // For debugging
// if (rIf) ((RadioLibInterface *)rIf)->isActivelyReceiving(); // if (rIf) ((RadioLibInterface *)rIf)->isActivelyReceiving();

View File

@ -20,4 +20,6 @@ extern graphics::Screen *screen;
// Return a human readable string of the form "Meshtastic_ab13" // Return a human readable string of the form "Meshtastic_ab13"
const char *getDeviceName(); const char *getDeviceName();
extern uint32_t rebootAtMsec;
void nrf52Setup(), esp32Setup(), nrf52Loop(), esp32Loop(); void nrf52Setup(), esp32Setup(), nrf52Loop(), esp32Loop();

View File

@ -26,6 +26,7 @@ typedef struct _AdminMessage {
bool confirm_set_channel; bool confirm_set_channel;
bool confirm_set_radio; bool confirm_set_radio;
bool exit_simulator; bool exit_simulator;
int32_t reboot_seconds;
}; };
} AdminMessage; } AdminMessage;
@ -49,6 +50,7 @@ extern "C" {
#define AdminMessage_confirm_set_channel_tag 32 #define AdminMessage_confirm_set_channel_tag 32
#define AdminMessage_confirm_set_radio_tag 33 #define AdminMessage_confirm_set_radio_tag 33
#define AdminMessage_exit_simulator_tag 34 #define AdminMessage_exit_simulator_tag 34
#define AdminMessage_reboot_seconds_tag 35
/* Struct field encoding specification for nanopb */ /* Struct field encoding specification for nanopb */
#define AdminMessage_FIELDLIST(X, a) \ #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, 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_channel,confirm_set_channel), 32) \
X(a, STATIC, ONEOF, BOOL, (variant,confirm_set_radio,confirm_set_radio), 33) \ 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_CALLBACK NULL
#define AdminMessage_DEFAULT NULL #define AdminMessage_DEFAULT NULL
#define AdminMessage_variant_set_radio_MSGTYPE RadioConfig #define AdminMessage_variant_set_radio_MSGTYPE RadioConfig

View File

@ -77,6 +77,13 @@ bool AdminPlugin::handleReceivedProtobuf(const MeshPacket &mp, const AdminMessag
handleGetRadio(mp); handleGetRadio(mp);
break; 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 #ifdef PORTDUINO
case AdminMessage_exit_simulator_tag: case AdminMessage_exit_simulator_tag:
DEBUG_MSG("Exiting simulator\n"); DEBUG_MSG("Exiting simulator\n");