mirror of
https://github.com/BotChain-Robots/firmware.git
synced 2026-07-08 09:37:21 +02:00
Fix generic UDP frame type
This commit is contained in:
@@ -106,23 +106,23 @@ DataLinkManager::~DataLinkManager(){
|
||||
|
||||
vTaskDelay(pdMS_TO_TICKS(100)); //delay to allow tasks to be killed
|
||||
|
||||
if (rip_broadcast_task == NULL){
|
||||
if (rip_broadcast_task != NULL){
|
||||
vTaskDelete(rip_broadcast_task);
|
||||
rip_broadcast_task = NULL;
|
||||
}
|
||||
if (rip_ttl_task == NULL){
|
||||
if (rip_ttl_task != NULL){
|
||||
vTaskDelete(rip_ttl_task);
|
||||
rip_ttl_task = NULL;
|
||||
}
|
||||
if (scheduler_task == NULL){
|
||||
if (scheduler_task != NULL){
|
||||
vTaskDelete(scheduler_task);
|
||||
scheduler_task = NULL;
|
||||
}
|
||||
if (receive_task == NULL){
|
||||
if (receive_task != NULL){
|
||||
vTaskDelete(receive_task);
|
||||
receive_task = NULL;
|
||||
}
|
||||
if (send_ack_task == NULL){
|
||||
if (send_ack_task != NULL){
|
||||
vTaskDelete(send_ack_task);
|
||||
send_ack_task = NULL;
|
||||
}
|
||||
@@ -378,11 +378,11 @@ esp_err_t DataLinkManager::send(uint8_t dest_board, std::unique_ptr<std::vector<
|
||||
//calculate number of fragments required (for generic frames only)
|
||||
uint32_t frag_info = 0;
|
||||
if (!isControlFrame){
|
||||
if (buffer->size() <= MAX_CONTROL_DATA_LEN){
|
||||
frag_info = (1 << 16); //1 total fragment required
|
||||
if (buffer->size() <= MAX_GENERIC_DATA_LEN){
|
||||
frag_info = (1 << 16) | 1; //1 total fragment, frag_num=1 (1-indexed)
|
||||
} else {
|
||||
uint32_t total_frags = (buffer->size() + MAX_GENERIC_DATA_LEN - 1) / MAX_GENERIC_DATA_LEN;
|
||||
frag_info = (total_frags) << 16;
|
||||
frag_info = (total_frags) << 16; //frag_num starts at 0 and is incremented to 1 before first send in scheduler
|
||||
}
|
||||
}
|
||||
|
||||
@@ -570,22 +570,18 @@ esp_err_t DataLinkManager::get_data_from_frame(uint8_t* data, size_t data_len, u
|
||||
|
||||
*message_size = header->data_len;
|
||||
|
||||
if ((*message_size > MAX_GENERIC_DATA_LEN && total_frag != 1) || (14 + *message_size > data_len)){
|
||||
if (*message_size > MAX_GENERIC_DATA_LEN || (14 + *message_size > data_len)){
|
||||
ESP_LOGE(DEBUG_LINK_TAG, "Invalid payload length: %u", *message_size);
|
||||
return ESP_ERR_INVALID_SIZE;
|
||||
}
|
||||
|
||||
memcpy(message, &data[12], *message_size);
|
||||
|
||||
if (total_frag != 1){
|
||||
geneate_crc_16(data, 12*sizeof(uint8_t) + *message_size, &header->crc_16);
|
||||
} else {
|
||||
header->crc_16 = 0;
|
||||
}
|
||||
geneate_crc_16(data, 12*sizeof(uint8_t) + *message_size, &header->crc_16);
|
||||
|
||||
uint16_t crc_calc = ((uint16_t)data[12 + *message_size] | ((uint16_t)data[13 + *message_size] << 8));
|
||||
|
||||
if (crc_calc != header->crc_16 && total_frag != 1){
|
||||
if (crc_calc != header->crc_16){
|
||||
//CRC mismatch
|
||||
ESP_LOGE(DEBUG_LINK_TAG, "CRC Mismatch - Generic Frame");
|
||||
ESP_LOGE(DEBUG_LINK_TAG, "Got 0x%04X but calculated 0x%04X\n", crc_calc, header->crc_16);
|
||||
|
||||
Reference in New Issue
Block a user