AP_Bootloader: added reboot button

This commit is contained in:
Andrew Tridgell 2024-01-17 09:33:40 +11:00
parent 1bee4630cc
commit 29876f649a
3 changed files with 19 additions and 3 deletions

View File

@ -16,6 +16,7 @@
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload" name="submit">
<input type="button" onclick="location.href='/REBOOT';" value="Reboot" />
</form>
</BODY>

View File

@ -467,6 +467,10 @@ void BL_Network::handle_request(SocketAPM *sock)
}
}
if (strncmp(headers, "GET /REBOOT", 11) == 0) {
need_reboot = true;
}
uint32_t size = 0;
/*
we only need one URL in the bootloader
@ -477,9 +481,14 @@ void BL_Network::handle_request(SocketAPM *sock)
"\r\n";
const auto *msg = AP_ROMFS::find_decompress("index.html", size);
sock->send(header, strlen(header));
if (need_reboot) {
const char *str = "<html><head><meta http-equiv=\"refresh\" content=\"2; url=/\"></head></html>";
sock->send(str, strlen(str));
} else {
char *msg2 = substitute_vars((const char *)msg, size);
sock->send(msg2, strlen(msg2));
delete msg2;
}
delete headers;
AP_ROMFS::free(msg);
}
@ -495,6 +504,10 @@ void BL_Network::web_server(void)
while (true) {
auto *sock = listen_socket->accept(20);
if (need_reboot) {
need_reboot = false;
NVIC_SystemReset();
}
if (sock == nullptr) {
continue;
}

View File

@ -43,6 +43,8 @@ private:
struct {
uint32_t ip, gateway, netmask;
} addr;
bool need_reboot;
};
#endif // AP_BOOTLOADER_NETWORK_ENABLED