Initialize all outgoing vehicle_command_ack_s and vehicle_command_s

This will initialize those structs with zero in all fields not set
and all fields set will only be change once to the final value not
wasting CPU time zeroing it.

This will guarantee that no non-unitialized structs will have
a trash value on from_external causing it to be sent to the
MAVLink channel without need it.
This commit is contained in:
José Roberto de Souza
2017-08-08 21:46:30 +02:00
committed by Lorenz Meier
parent 7c268f4fa1
commit 925efe990d
17 changed files with 267 additions and 261 deletions
+18 -18
View File
@@ -122,7 +122,6 @@ void SendEvent::cycle()
void SendEvent::process_commands()
{
struct vehicle_command_s cmd;
bool updated;
orb_check(_vehicle_command_sub, &updated);
@@ -130,6 +129,8 @@ void SendEvent::process_commands()
return;
}
struct vehicle_command_s cmd;
orb_copy(ORB_ID(vehicle_command), _vehicle_command_sub, &cmd);
bool got_temperature_calibration_command = false, accel = false, baro = false, gyro = false;
@@ -167,12 +168,12 @@ void SendEvent::process_commands()
void SendEvent::answer_command(const vehicle_command_s &cmd, unsigned result)
{
struct vehicle_command_ack_s command_ack;
/* publish ACK */
command_ack.command = cmd.command;
command_ack.result = result;
command_ack.timestamp = hrt_absolute_time();
struct vehicle_command_ack_s command_ack = {
.timestamp = hrt_absolute_time(),
.command = cmd.command,
.result = (uint8_t)result,
};
if (_command_ack_pub != nullptr) {
orb_publish(ORB_ID(vehicle_command_ack), _command_ack_pub, &command_ack);
@@ -256,18 +257,17 @@ int SendEvent::custom_command(int argc, char *argv[])
}
}
vehicle_command_s cmd = {};
cmd.target_system = 0;
cmd.target_component = 0;
cmd.command = vehicle_command_s::VEHICLE_CMD_PREFLIGHT_CALIBRATION;
cmd.param1 = (gyro_calib || calib_all) ? vehicle_command_s::PREFLIGHT_CALIBRATION_TEMPERATURE_CALIBRATION : NAN;
cmd.param2 = NAN;
cmd.param3 = NAN;
cmd.param4 = NAN;
cmd.param5 = (accel_calib || calib_all) ? vehicle_command_s::PREFLIGHT_CALIBRATION_TEMPERATURE_CALIBRATION : NAN;
cmd.param6 = NAN;
cmd.param7 = (baro_calib || calib_all) ? vehicle_command_s::PREFLIGHT_CALIBRATION_TEMPERATURE_CALIBRATION : NAN;
struct vehicle_command_s cmd = {
.timestamp = 0,
.param5 = (float)((accel_calib || calib_all) ? vehicle_command_s::PREFLIGHT_CALIBRATION_TEMPERATURE_CALIBRATION : NAN),
.param6 = NAN,
.param1 = (float)((gyro_calib || calib_all) ? vehicle_command_s::PREFLIGHT_CALIBRATION_TEMPERATURE_CALIBRATION : NAN),
.param2 = NAN,
.param3 = NAN,
.param4 = NAN,
.param7 = (float)((baro_calib || calib_all) ? vehicle_command_s::PREFLIGHT_CALIBRATION_TEMPERATURE_CALIBRATION : NAN),
.command = vehicle_command_s::VEHICLE_CMD_PREFLIGHT_CALIBRATION
};
orb_advert_t h = orb_advertise_queue(ORB_ID(vehicle_command), &cmd, vehicle_command_s::ORB_QUEUE_LENGTH);
(void)orb_unadvertise(h);