Skip to content

Commit

Permalink
mavlink-mission: use mavlink_mission_item for crc calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasDebrunner committed Nov 23, 2021
1 parent 4e85014 commit 151c1cb
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/modules/mavlink/mavlink_mission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static constexpr int MISSION_ITEM_CRC_SIZE = 32;
(_msg.target_component == MAV_COMP_ID_ALL)))


static uint32_t crc32_for_mission_item(const mission_item_s &mission_item, uint32_t prev_crc32)
static uint32_t crc32_for_mission_item(const mavlink_mission_item_t &mission_item, uint32_t prev_crc32)
{
union {
struct __attribute__((packed)) {
Expand All @@ -88,12 +88,15 @@ static uint32_t crc32_for_mission_item(const mission_item_s &mission_item, uint3
} u;

u.item.frame = mission_item.frame;
u.item.command = mission_item.nav_cmd;
u.item.command = mission_item.command;
u.item.autocontinue = mission_item.autocontinue;

for (int i = 0; i < 7; i++) {
u.item.params[i] = mission_item.params[i];
}
u.item.params[0] = mission_item.param1;
u.item.params[1] = mission_item.param2;
u.item.params[2] = mission_item.param3;
u.item.params[3] = mission_item.param4;
u.item.params[4] = mission_item.x;
u.item.params[5] = mission_item.y;
u.item.params[6] = mission_item.z;

return crc32part(u.raw, sizeof(u), prev_crc32);
}
Expand Down Expand Up @@ -325,7 +328,12 @@ MavlinkMissionManager::send_mission_current(int32_t seq)
}
}


/**
* Combines two independently computed CRC32 checksums to a single checksum
* that is the same as if the checksum was computed over the concatenation
* of both blocks.
* Reference: https://stackoverflow.com/questions/23122312/crc-calculation-of-a-mostly-static-data-stream
*/
uint32_t crc32combine(uint32_t crc_a, uint32_t crc_b, size_t len_b)
{
size_t i;
Expand Down Expand Up @@ -679,7 +687,6 @@ MavlinkMissionManager::handle_message(const mavlink_message_t *msg)
break;

case MAVLINK_MSG_ID_COMMAND_INT:
printf("GOT A COMMAND\n");
break;

default:
Expand Down Expand Up @@ -1192,7 +1199,7 @@ MavlinkMissionManager::handle_mission_item_both(const mavlink_message_t *msg)
return;
}

_transfer_current_crc32 = crc32_for_mission_item(mission_item, _transfer_current_crc32);
_transfer_current_crc32 = crc32_for_mission_item(wp, _transfer_current_crc32);

bool write_failed = false;
bool check_failed = false;
Expand Down

0 comments on commit 151c1cb

Please sign in to comment.