|
|
|
@ -501,6 +501,7 @@ struct PACKED PackedLocation {
@@ -501,6 +501,7 @@ struct PACKED PackedLocation {
|
|
|
|
|
int32_t alt:24; ///< param 2 - Altitude in centimeters (meters * 100) see LOCATION_ALT_MAX_M
|
|
|
|
|
int32_t lat; ///< param 3 - Latitude * 10**7
|
|
|
|
|
int32_t lng; ///< param 4 - Longitude * 10**7
|
|
|
|
|
uint8_t cam_enable_bit; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
union PackedContent { |
|
|
|
@ -509,11 +510,11 @@ union PackedContent {
@@ -509,11 +510,11 @@ union PackedContent {
|
|
|
|
|
|
|
|
|
|
// raw bytes, for reading/writing to eeprom. Note that only 10
|
|
|
|
|
// bytes are available if a 16 bit command ID is used
|
|
|
|
|
uint8_t bytes[12]; |
|
|
|
|
uint8_t bytes[13]; |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
assert_storage_size<PackedContent, 12> assert_storage_size_PackedContent; |
|
|
|
|
assert_storage_size<PackedContent, 13> assert_storage_size_PackedContent; |
|
|
|
|
|
|
|
|
|
/// load_cmd_from_storage - load command from storage
|
|
|
|
|
/// true is return if successful
|
|
|
|
@ -542,14 +543,14 @@ bool AP_Mission::read_cmd_from_storage(uint16_t index, Mission_Command& cmd) con
@@ -542,14 +543,14 @@ bool AP_Mission::read_cmd_from_storage(uint16_t index, Mission_Command& cmd) con
|
|
|
|
|
PackedContent packed_content {}; |
|
|
|
|
|
|
|
|
|
const uint8_t b1 = _storage.read_byte(pos_in_storage); |
|
|
|
|
if (b1 == 0) { |
|
|
|
|
if (b1 == 0) {//cmd id>=256
|
|
|
|
|
cmd.id = _storage.read_uint16(pos_in_storage+1); |
|
|
|
|
cmd.p1 = _storage.read_uint16(pos_in_storage+3); |
|
|
|
|
_storage.read_block(packed_content.bytes, pos_in_storage+5, 10); |
|
|
|
|
_storage.read_block(packed_content.bytes, pos_in_storage+5, 10); //last byte is not use
|
|
|
|
|
} else { |
|
|
|
|
cmd.id = b1; |
|
|
|
|
cmd.p1 = _storage.read_uint16(pos_in_storage+1); |
|
|
|
|
_storage.read_block(packed_content.bytes, pos_in_storage+3, 12); |
|
|
|
|
_storage.read_block(packed_content.bytes, pos_in_storage+3, 13);
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (stored_in_location(cmd.id)) { |
|
|
|
@ -570,12 +571,13 @@ bool AP_Mission::read_cmd_from_storage(uint16_t index, Mission_Command& cmd) con
@@ -570,12 +571,13 @@ bool AP_Mission::read_cmd_from_storage(uint16_t index, Mission_Command& cmd) con
|
|
|
|
|
cmd.content.location.alt = packed_content.location.alt; |
|
|
|
|
cmd.content.location.lat = packed_content.location.lat; |
|
|
|
|
cmd.content.location.lng = packed_content.location.lng; |
|
|
|
|
cmd.content.location.cams_enable_bit = packed_content.location.cam_enable_bit; |
|
|
|
|
} else { |
|
|
|
|
// all other options in Content are assumed to be packed:
|
|
|
|
|
static_assert(sizeof(cmd.content) >= 12, |
|
|
|
|
static_assert(sizeof(cmd.content) >= 13, |
|
|
|
|
"content is big enough to take bytes"); |
|
|
|
|
// (void *) cast to specify gcc that we know that we are copy byte into a non trivial type and leaving 4 bytes untouched
|
|
|
|
|
memcpy((void *)&cmd.content, packed_content.bytes, 12); |
|
|
|
|
memcpy((void *)&cmd.content, packed_content.bytes, 13); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// set command's index to it's position in eeprom
|
|
|
|
@ -625,6 +627,7 @@ bool AP_Mission::write_cmd_to_storage(uint16_t index, const Mission_Command& cmd
@@ -625,6 +627,7 @@ bool AP_Mission::write_cmd_to_storage(uint16_t index, const Mission_Command& cmd
|
|
|
|
|
|
|
|
|
|
PackedContent packed {}; |
|
|
|
|
if (stored_in_location(cmd.id)) { |
|
|
|
|
|
|
|
|
|
// Location is not PACKED; field-wise copy it:
|
|
|
|
|
packed.location.flags.relative_alt = cmd.content.location.relative_alt; |
|
|
|
|
packed.location.flags.loiter_ccw = cmd.content.location.loiter_ccw; |
|
|
|
@ -634,11 +637,20 @@ bool AP_Mission::write_cmd_to_storage(uint16_t index, const Mission_Command& cmd
@@ -634,11 +637,20 @@ bool AP_Mission::write_cmd_to_storage(uint16_t index, const Mission_Command& cmd
|
|
|
|
|
packed.location.alt = cmd.content.location.alt; |
|
|
|
|
packed.location.lat = cmd.content.location.lat; |
|
|
|
|
packed.location.lng = cmd.content.location.lng; |
|
|
|
|
if (cmd.id == MAV_CMD_NAV_WAYPOINT) |
|
|
|
|
{ |
|
|
|
|
packed.location.cam_enable_bit = cmd.content.location.cams_enable_bit; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
packed.location.cam_enable_bit = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
// all other options in Content are assumed to be packed:
|
|
|
|
|
static_assert(sizeof(packed.bytes) >= 12, |
|
|
|
|
static_assert(sizeof(packed.bytes) >= 13, |
|
|
|
|
"packed.bytes is big enough to take content"); |
|
|
|
|
memcpy(packed.bytes, &cmd.content, 12); |
|
|
|
|
memcpy(packed.bytes, &cmd.content, 13); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// calculate where in storage the command should be placed
|
|
|
|
@ -647,13 +659,14 @@ bool AP_Mission::write_cmd_to_storage(uint16_t index, const Mission_Command& cmd
@@ -647,13 +659,14 @@ bool AP_Mission::write_cmd_to_storage(uint16_t index, const Mission_Command& cmd
|
|
|
|
|
if (cmd.id < 256) { |
|
|
|
|
_storage.write_byte(pos_in_storage, cmd.id); |
|
|
|
|
_storage.write_uint16(pos_in_storage+1, cmd.p1); |
|
|
|
|
_storage.write_block(pos_in_storage+3, packed.bytes, 12); |
|
|
|
|
_storage.write_block(pos_in_storage+3, packed.bytes, 13);
|
|
|
|
|
} else { |
|
|
|
|
// if the command ID is above 256 we store a 0 followed by the 16 bit command ID
|
|
|
|
|
_storage.write_byte(pos_in_storage, 0); |
|
|
|
|
_storage.write_uint16(pos_in_storage+1, cmd.id); |
|
|
|
|
_storage.write_uint16(pos_in_storage+3, cmd.p1); |
|
|
|
|
_storage.write_block(pos_in_storage+5, packed.bytes, 10); |
|
|
|
|
_storage.write_byte(pos_in_storage+15, 0); //填充为0
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// remember when the mission last changed
|
|
|
|
@ -756,7 +769,7 @@ MAV_MISSION_RESULT AP_Mission::mavlink_int_to_mission_cmd(const mavlink_mission_
@@ -756,7 +769,7 @@ MAV_MISSION_RESULT AP_Mission::mavlink_int_to_mission_cmd(const mavlink_mission_
|
|
|
|
|
#else |
|
|
|
|
// delay at waypoint in seconds (this is for copters???)
|
|
|
|
|
cmd.p1 = packet.param1; |
|
|
|
|
cmd.content.location.camerasEnableBit = packet.param3; |
|
|
|
|
cmd.content.location.cams_enable_bit = (uint8_t)packet.param3; |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
@ -1012,7 +1025,10 @@ MAV_MISSION_RESULT AP_Mission::mavlink_int_to_mission_cmd(const mavlink_mission_
@@ -1012,7 +1025,10 @@ MAV_MISSION_RESULT AP_Mission::mavlink_int_to_mission_cmd(const mavlink_mission_
|
|
|
|
|
cmd.content.location.lng = packet.y; |
|
|
|
|
|
|
|
|
|
cmd.content.location.alt = packet.z * 100.0f; // convert packet's alt (m) to cmd alt (cm)
|
|
|
|
|
|
|
|
|
|
if (cmd.id == MAV_CMD_NAV_WAYPOINT) |
|
|
|
|
{ |
|
|
|
|
cmd.content.location.cams_enable_bit = (uint8_t)packet.param3; |
|
|
|
|
} |
|
|
|
|
switch (packet.frame) { |
|
|
|
|
|
|
|
|
|
case MAV_FRAME_MISSION: |
|
|
|
@ -1183,6 +1199,7 @@ bool AP_Mission::mission_cmd_to_mavlink_int(const AP_Mission::Mission_Command& c
@@ -1183,6 +1199,7 @@ bool AP_Mission::mission_cmd_to_mavlink_int(const AP_Mission::Mission_Command& c
|
|
|
|
|
#else |
|
|
|
|
// delay at waypoint in seconds
|
|
|
|
|
packet.param1 = cmd.p1; |
|
|
|
|
packet.param3 = (float)cmd.content.location.cams_enable_bit; |
|
|
|
|
#endif |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|