Skip to content

Commit

Permalink
Fixed MSPv2 parsing bug
Browse files Browse the repository at this point in the history
Updated release build script

Co-Authored-By: Iasen Kostov <[email protected]>
  • Loading branch information
seeul8er and TByte007 committed Mar 7, 2024
1 parent 48ae2b5 commit ca6aa5b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
8 changes: 4 additions & 4 deletions create_release_zip.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cp .\flashing_instructions.txt $release_foldername
rm -Recurse .\build
idf.py set-target esp32 build
mkdir $release_foldername\esp32
cp .\build\flash_args $release_foldername\esp32
cp .\build\flash_args $release_foldername\esp32\flash_args.txt
cp .\build\db_esp32.bin $release_foldername\esp32
cp .\build\bootloader\bootloader.bin $release_foldername\esp32
cp .\build\www.bin $release_foldername\esp32
Expand All @@ -19,7 +19,7 @@ cp .\build\partition_table\partition-table.bin $release_foldername\esp32
rm -Recurse .\build
idf.py set-target esp32s2 build
mkdir $release_foldername\esp32s2
cp .\build\flash_args $release_foldername\esp32s2
cp .\build\flash_args $release_foldername\esp32s2\flash_args.txt
cp .\build\db_esp32.bin $release_foldername\esp32s2
cp .\build\bootloader\bootloader.bin $release_foldername\esp32s2
cp .\build\www.bin $release_foldername\esp32s2
Expand All @@ -28,7 +28,7 @@ cp .\build\partition_table\partition-table.bin $release_foldername\esp32s2
rm -Recurse .\build
idf.py set-target esp32s3 build
mkdir $release_foldername\esp32s3
cp .\build\flash_args $release_foldername\esp32s3
cp .\build\flash_args $release_foldername\esp32s3\flash_args.txt
cp .\build\db_esp32.bin $release_foldername\esp32s3
cp .\build\bootloader\bootloader.bin $release_foldername\esp32s3
cp .\build\www.bin $release_foldername\esp32s3
Expand All @@ -37,7 +37,7 @@ cp .\build\partition_table\partition-table.bin $release_foldername\esp32s3
rm -Recurse .\build
idf.py set-target esp32c3 build
mkdir $release_foldername\esp32c3
cp .\build\flash_args $release_foldername\esp32c3
cp .\build\flash_args $release_foldername\esp32c3\flash_args.txt
cp .\build\db_esp32.bin $release_foldername\esp32c3
cp .\build\bootloader\bootloader.bin $release_foldername\esp32c3
cp .\build\www.bin $release_foldername\esp32c3
Expand Down
4 changes: 3 additions & 1 deletion main/db_esp32_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void send_to_all_clients(int tcp_clients[], struct udp_conn_list_t *n_udp_conn_l
void write_to_uart(const char data_buffer[], const size_t data_length) {
int written = uart_write_bytes(UART_NUM, data_buffer, data_length);
if (written > 0)
ESP_LOGD(TAG, "Wrote %i bytes", written);
ESP_LOGD(TAG, "Wrote %i bytes to UART", written);
else
ESP_LOGE(TAG, "Error writing to UART %s", esp_err_to_name(errno));
}
Expand Down Expand Up @@ -174,6 +174,8 @@ void parse_msp_ltm(int tcp_clients[], struct udp_conn_list_t *udp_connection, ui
*serial_read_bytes = 0;
}
}
} else { // XXX Leads to crashes of the ESP32 without it!
*serial_read_bytes = 0;
}
}
}
Expand Down
17 changes: 10 additions & 7 deletions main/msp_ltm_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ bool parse_msp_ltm_byte(msp_ltm_port_t *msp_ltm_port, uint8_t new_byte) {
break;
default:
msp_ltm_port->parse_state = IDLE;
break;
return false;
}
break;

Expand Down Expand Up @@ -125,7 +125,7 @@ bool parse_msp_ltm_byte(msp_ltm_port_t *msp_ltm_port, uint8_t new_byte) {
break;
default:
msp_ltm_port->parse_state = IDLE;
break;
return false;
}
break;

Expand Down Expand Up @@ -165,15 +165,15 @@ bool parse_msp_ltm_byte(msp_ltm_port_t *msp_ltm_port, uint8_t new_byte) {
msp_ltm_port->checksum1 ^= new_byte;
if (msp_ltm_port->offset == sizeof(mspHeaderV1_t)) {
mspHeaderV1_t *hdr = (mspHeaderV1_t *) &msp_ltm_port->inBuf[0];
// Check incoming buffer size limit
if (hdr->size > MSP_PORT_INBUF_SIZE) {
msp_ltm_port->parse_state = IDLE;
} else if (hdr->cmd == MSP_V2_FRAME_ID) {
// No need to check incoming buffer size limit for V1
// because the buffer is 512 which is bigger than the INTMAX for byte
if (hdr->cmd == MSP_V2_FRAME_ID) {
if (hdr->size >= sizeof(mspHeaderV2_t) + 1) {
msp_ltm_port->mspVersion = MSP_V2_OVER_V1;
msp_ltm_port->parse_state = MSP_HEADER_V2_OVER_V1;
} else {
msp_ltm_port->parse_state = IDLE;
return false;
}
} else {
msp_ltm_port->dataSize = hdr->size;
Expand Down Expand Up @@ -210,6 +210,7 @@ bool parse_msp_ltm_byte(msp_ltm_port_t *msp_ltm_port, uint8_t new_byte) {
msp_ltm_port->dataSize = hdrv2->size;
if (hdrv2->size > MSP_PORT_INBUF_SIZE) {
msp_ltm_port->parse_state = IDLE;
return false;
} else {
msp_ltm_port->cmdMSP = hdrv2->cmd;
msp_ltm_port->cmdFlags = hdrv2->flags;
Expand All @@ -236,6 +237,7 @@ bool parse_msp_ltm_byte(msp_ltm_port_t *msp_ltm_port, uint8_t new_byte) {
msp_ltm_port->parse_state = MSP_CHECKSUM_V1;
} else {
msp_ltm_port->parse_state = IDLE;
return false;
}
break;

Expand Down Expand Up @@ -271,8 +273,9 @@ bool parse_msp_ltm_byte(msp_ltm_port_t *msp_ltm_port, uint8_t new_byte) {
msp_ltm_port->parse_state = MSP_PACKET_RECEIVED;
} else {
msp_ltm_port->parse_state = IDLE;
return false;
}
break;
}
return true;
}
}
2 changes: 1 addition & 1 deletion main/msp_ltm_serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#define MSP_MAX_HEADER_SIZE 9
#define MSP_V2_FRAME_ID 255
#define MSP_PORT_INBUF_SIZE 192
#define MSP_PORT_INBUF_SIZE 512
#define MAX_MSP_PORT_COUNT 3
#define MSP_PORT_DATAFLASH_BUFFER_SIZE 4096
#define MSP_PORT_OUTBUF_SIZE 512
Expand Down

0 comments on commit ca6aa5b

Please sign in to comment.