Add error handling to OTA process
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
8f052ecb37
commit
24f5e4398d
6 changed files with 119 additions and 51 deletions
|
|
@ -215,38 +215,48 @@ struct fw_check {
|
|||
void websocket_cb(struct tcp_pcb *pcb, char *data, u16_t data_len,
|
||||
uint8_t /*mode*/) { //mode should be WS_BIN_MODE or WS_TEXT_MODE
|
||||
|
||||
uint8_t response[3];
|
||||
uint16_t val = 0;
|
||||
char cmd = '0';
|
||||
uint8_t response[4];
|
||||
auto &cmd = (char &) response[0];
|
||||
auto &ret = response[1];
|
||||
auto &val = (uint16_t &) response[2];
|
||||
cmd = '0';
|
||||
ret = ERROR;
|
||||
val = 0;
|
||||
|
||||
bool togl = 0;
|
||||
bool togl = false;
|
||||
|
||||
switch (data[0]) {
|
||||
case 'R': // Restart
|
||||
cmd = 'R';
|
||||
ret = OK;
|
||||
break;
|
||||
case 'X': // Clear Config
|
||||
cmd = 'X';
|
||||
ret = OK;
|
||||
break;
|
||||
case 'D': // Disable LED
|
||||
signal_led(false);
|
||||
val = 1;
|
||||
cmd = 'G';
|
||||
ret = OK;
|
||||
val = 1;
|
||||
break;
|
||||
case 'E': // Enable LED
|
||||
signal_led(true);
|
||||
val = 0;
|
||||
cmd = 'G';
|
||||
ret = OK;
|
||||
val = 0;
|
||||
break;
|
||||
case 'F':
|
||||
togl = ~togl;
|
||||
togl = !togl;
|
||||
signal_led(togl);
|
||||
{
|
||||
auto *f = (fw_frame *) data;
|
||||
if(f->seq == 0) {
|
||||
system_otaflash_init();
|
||||
}
|
||||
val = system_otaflash_chunk(f->data, ntohs(f->len), ntohs(f->seq), ntohl(f->hash));
|
||||
uint16_t ack = 0;
|
||||
ret = system_otaflash_chunk(f->data, ntohs(f->len), ntohs(f->seq), ntohl(f->hash), &ack);
|
||||
val = htons(ack);
|
||||
}
|
||||
cmd = 'F';
|
||||
break;
|
||||
|
|
@ -254,32 +264,31 @@ void websocket_cb(struct tcp_pcb *pcb, char *data, u16_t data_len,
|
|||
signal_led(false);
|
||||
{
|
||||
auto *f = (fw_check *) data;
|
||||
val = system_otaflash_verify_and_switch(ntohl(f->len), ntohl(f->hash));
|
||||
ret = system_otaflash_verify_and_switch(ntohl(f->len), ntohl(f->hash));
|
||||
}
|
||||
cmd = 'C';
|
||||
break;
|
||||
default:
|
||||
printf("[websocket_callback]:\n%.*s\n", (int) data_len, (char *) data);
|
||||
printf("Unknown command %c\n", data[0]);
|
||||
val = 0;
|
||||
ret = ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
response[2] = (uint8_t) val;
|
||||
response[1] = val >> 8;
|
||||
response[0] = cmd;
|
||||
|
||||
LOCK_TCPIP_CORE();
|
||||
websocket_write(pcb, response, 3, WS_BIN_MODE);
|
||||
websocket_write(pcb, response, 4, WS_BIN_MODE);
|
||||
UNLOCK_TCPIP_CORE();
|
||||
|
||||
if(data[0] == 'R') { // Restart
|
||||
vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||
vPortEnterCritical();
|
||||
sdk_system_restart();
|
||||
} else if(data[0] == 'X') { // Clear Config
|
||||
vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||
system_clear_config();
|
||||
if(ret == OK) {
|
||||
if(cmd == 'R' || cmd == 'C') { // Restart
|
||||
printf("rebooting now");
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
vPortEnterCritical();
|
||||
sdk_system_restart();
|
||||
} else if(cmd == 'X') { // Clear Config
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
system_clear_config();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue