orb_advert_t changed to void * and checks changed to nullptr

The existing orb_advert_t use thoughout the code sometimes tries
to treat it as a file descriptor and there are checks for < 0
and ::close calls on orb_advert_t types which is an invalid use
of an object pointer, which is what orb_advert_t really is.

Initially I had changed the -1 initializations to 0 but it was
suggested that this should be nullptr. That was a good recommendation
but the definition of orb_advert_t had to change to void * because
you cannot initialize a uintptr_t as nullptr.

Signed-off-by: Mark Charlebois <charlebm@gmail.com>
This commit is contained in:
Mark Charlebois
2015-05-27 14:42:49 -07:00
committed by Lorenz Meier
parent 180c8b0cb0
commit 1ca05aaa64
59 changed files with 263 additions and 269 deletions
+4 -4
View File
@@ -86,8 +86,8 @@ Airspeed::Airspeed(int bus, int address, unsigned conversion_interval, const cha
_measure_ticks(0),
_collect_phase(false),
_diff_pres_offset(0.0f),
_airspeed_pub(0),
_subsys_pub(0),
_airspeed_pub(nullptr),
_subsys_pub(nullptr),
_class_instance(-1),
_conversion_interval(conversion_interval),
_sample_perf(perf_alloc(PC_ELAPSED, "airspeed_read")),
@@ -146,7 +146,7 @@ Airspeed::init()
/* measurement will have generated a report, publish */
_airspeed_pub = orb_advertise(ORB_ID(differential_pressure), &arp);
if (_airspeed_pub == 0)
if (_airspeed_pub == nullptr)
warnx("uORB started?");
}
@@ -367,7 +367,7 @@ Airspeed::update_status()
SUBSYSTEM_TYPE_DIFFPRESSURE
};
if (_subsys_pub == 0) {
if (_subsys_pub == nullptr) {
orb_publish(ORB_ID(subsystem_info), _subsys_pub, &info);
} else {
_subsys_pub = orb_advertise(ORB_ID(subsystem_info), &info);
+3 -3
View File
@@ -203,7 +203,7 @@ BATT_SMBUS::BATT_SMBUS(int bus, uint16_t batt_smbus_addr) :
_enabled(false),
_work{},
_reports(nullptr),
_batt_topic(0),
_batt_topic(nullptr),
_batt_orb_id(nullptr),
_start_time(0),
_batt_capacity(0)
@@ -427,13 +427,13 @@ BATT_SMBUS::cycle()
}
// publish to orb
if (_batt_topic != 0) {
if (_batt_topic != nullptr) {
orb_publish(_batt_orb_id, _batt_topic, &new_report);
} else {
_batt_topic = orb_advertise(_batt_orb_id, &new_report);
if (_batt_topic == 0) {
if (_batt_topic == nullptr) {
errx(1, "ADVERT FAIL");
}
}
+2 -2
View File
@@ -238,7 +238,7 @@ BMA180::BMA180(int bus, spi_dev_e device) :
_reports(nullptr),
_accel_range_scale(0.0f),
_accel_range_m_s2(0.0f),
_accel_topic(0),
_accel_topic(nullptr),
_class_instance(-1),
_current_lowpass(0),
_current_range(0),
@@ -733,7 +733,7 @@ BMA180::measure()
poll_notify(POLLIN);
/* publish for subscribers */
if (_accel_topic != 0 && !(_pub_blocked))
if (_accel_topic != nullptr && !(_pub_blocked))
orb_publish(ORB_ID(sensor_accel), _accel_topic, &report);
/* stop the perf counter */
+1 -1
View File
@@ -183,7 +183,7 @@ ETSAirspeed::collect()
report.temperature = -1000.0f;
report.max_differential_pressure_pa = _max_differential_pressure_pa;
if (_airspeed_pub > 0 && !(_pub_blocked)) {
if (_airspeed_pub != nullptr && !(_pub_blocked)) {
/* publish it */
orb_publish(ORB_ID(differential_pressure), _airspeed_pub, &report);
}
+2 -2
View File
@@ -180,7 +180,7 @@ Gimbal::Gimbal() :
_attitude_compensation_pitch(true),
_attitude_compensation_yaw(true),
_initialized(false),
_actuator_controls_2_topic(0),
_actuator_controls_2_topic(nullptr),
_sample_perf(perf_alloc(PC_ELAPSED, "gimbal_read")),
_comms_errors(perf_alloc(PC_COUNT, "gimbal_comms_errors")),
_buffer_overflows(perf_alloc(PC_COUNT, "gimbal_buffer_overflows"))
@@ -280,7 +280,7 @@ Gimbal::cycle()
zero_report.timestamp = hrt_absolute_time();
_actuator_controls_2_topic = orb_advertise(ORB_ID(actuator_controls_2), &zero_report);
if (_actuator_controls_2_topic == 0) {
if (_actuator_controls_2_topic == nullptr) {
warnx("advert err");
}
+5 -5
View File
@@ -175,9 +175,9 @@ GPS::GPS(const char *uart_path, bool fake_gps, bool enable_sat_info) :
_mode(GPS_DRIVER_MODE_UBX),
_Helper(nullptr),
_Sat_Info(nullptr),
_report_gps_pos_pub(0),
_report_gps_pos_pub(nullptr),
_p_report_sat_info(nullptr),
_report_sat_info_pub(0),
_report_sat_info_pub(nullptr),
_rate(0.0f),
_fake_gps(fake_gps)
{
@@ -314,7 +314,7 @@ GPS::task_main()
if (!(_pub_blocked)) {
if (_report_gps_pos_pub > 0) {
if (_report_gps_pos_pub != nullptr) {
orb_publish(ORB_ID(vehicle_gps_position), _report_gps_pos_pub, &_report_gps_pos);
} else {
@@ -361,7 +361,7 @@ GPS::task_main()
_report_gps_pos.timestamp_variance = hrt_absolute_time();
_report_gps_pos.timestamp_velocity = hrt_absolute_time();
_report_gps_pos.timestamp_time = hrt_absolute_time();
if (_report_gps_pos_pub > 0) {
if (_report_gps_pos_pub != nullptr) {
orb_publish(ORB_ID(vehicle_gps_position), _report_gps_pos_pub, &_report_gps_pos);
} else {
@@ -381,7 +381,7 @@ GPS::task_main()
orb_publish(ORB_ID(vehicle_gps_position), _report_gps_pos_pub, &_report_gps_pos);
}
if (_p_report_sat_info && (helper_ret & 2)) {
if (_report_sat_info_pub > 0) {
if (_report_sat_info_pub != nullptr) {
orb_publish(ORB_ID(satellite_info), _report_sat_info_pub, _p_report_sat_info);
} else {
+3 -3
View File
@@ -360,7 +360,7 @@ HMC5883::HMC5883(device::Device *interface, const char *path, enum Rotation rota
_collect_phase(false),
_class_instance(-1),
_orb_class_instance(-1),
_mag_topic(0),
_mag_topic(nullptr),
_sample_perf(perf_alloc(PC_ELAPSED, "hmc5883_read")),
_comms_errors(perf_alloc(PC_COUNT, "hmc5883_comms_errors")),
_buffer_overflows(perf_alloc(PC_COUNT, "hmc5883_buffer_overflows")),
@@ -986,14 +986,14 @@ HMC5883::collect()
if (!(_pub_blocked)) {
if (_mag_topic != 0) {
if (_mag_topic != nullptr) {
/* publish it */
orb_publish(ORB_ID(sensor_mag), _mag_topic, &new_report);
} else {
_mag_topic = orb_advertise_multi(ORB_ID(sensor_mag), &new_report,
&_orb_class_instance, (sensor_is_onboard) ? ORB_PRIO_HIGH : ORB_PRIO_MAX);
if (_mag_topic == 0)
if (_mag_topic == nullptr)
debug("ADVERT FAIL");
}
}
+2 -2
View File
@@ -63,7 +63,7 @@ static int _sensor_sub = -1;
static int _airspeed_sub = -1;
static int _esc_sub = -1;
static orb_advert_t _esc_pub = 0;
static orb_advert_t _esc_pub = nullptr;
static bool _home_position_set = false;
static double _home_lat = 0.0d;
@@ -120,7 +120,7 @@ publish_gam_message(const uint8_t *buffer)
esc.esc[0].esc_current = static_cast<float>((msg.current_H << 8) | (msg.current_L & 0xff)) * 0.1F;
/* announce the esc if needed, just publish else */
if (_esc_pub > 0) {
if (_esc_pub != nullptr) {
orb_publish(ORB_ID(esc_status), _esc_pub, &esc);
} else {
_esc_pub = orb_advertise(ORB_ID(esc_status), &esc);
+2 -2
View File
@@ -411,7 +411,7 @@ L3GD20::L3GD20(int bus, const char* path, spi_dev_e device, enum Rotation rotati
_gyro_scale{},
_gyro_range_scale(0.0f),
_gyro_range_rad_s(0.0f),
_gyro_topic(0),
_gyro_topic(nullptr),
_orb_class_instance(-1),
_class_instance(-1),
_current_rate(0),
@@ -490,7 +490,7 @@ L3GD20::init()
_gyro_topic = orb_advertise_multi(ORB_ID(sensor_gyro), &grp,
&_orb_class_instance, (is_external()) ? ORB_PRIO_VERY_HIGH : ORB_PRIO_DEFAULT);
if (_gyro_topic == 0) {
if (_gyro_topic == nullptr) {
debug("failed to create sensor_gyro publication");
}
+4 -4
View File
@@ -563,7 +563,7 @@ LSM303D::LSM303D(int bus, const char* path, spi_dev_e device, enum Rotation rota
_mag_range_ga(0.0f),
_mag_range_scale(0.0f),
_mag_samplerate(0),
_accel_topic(0),
_accel_topic(nullptr),
_accel_orb_class_instance(-1),
_accel_class_instance(-1),
_accel_read(0),
@@ -676,7 +676,7 @@ LSM303D::init()
_mag->_mag_topic = orb_advertise_multi(ORB_ID(sensor_mag), &mrp,
&_mag->_mag_orb_class_instance, ORB_PRIO_LOW);
if (_mag->_mag_topic == 0) {
if (_mag->_mag_topic == nullptr) {
warnx("ADVERT ERR");
}
@@ -691,7 +691,7 @@ LSM303D::init()
_accel_topic = orb_advertise_multi(ORB_ID(sensor_accel), &arp,
&_accel_orb_class_instance, (is_external()) ? ORB_PRIO_VERY_HIGH : ORB_PRIO_DEFAULT);
if (_accel_topic == 0) {
if (_accel_topic == nullptr) {
warnx("ADVERT ERR");
}
@@ -1770,7 +1770,7 @@ LSM303D::test_error()
LSM303D_mag::LSM303D_mag(LSM303D *parent) :
CDev("LSM303D_mag", LSM303D_DEVICE_PATH_MAG),
_parent(parent),
_mag_topic(0),
_mag_topic(nullptr),
_mag_orb_class_instance(-1),
_mag_class_instance(-1)
{
+2 -2
View File
@@ -623,9 +623,9 @@ MB12XX::start()
true,
SUBSYSTEM_TYPE_RANGEFINDER
};
static orb_advert_t pub = -1;
static orb_advert_t pub = nullptr;
if (pub > 0) {
if (pub != nullptr) {
orb_publish(ORB_ID(subsystem_info), pub, &info);
+1 -1
View File
@@ -249,7 +249,7 @@ MEASAirspeed::collect()
report.differential_pressure_raw_pa = diff_press_pa_raw;
report.max_differential_pressure_pa = _max_differential_pressure_pa;
if (_airspeed_pub > 0 && !(_pub_blocked)) {
if (_airspeed_pub != nullptr && !(_pub_blocked)) {
/* publish it */
orb_publish(ORB_ID(differential_pressure), _airspeed_pub, &report);
}
+4 -4
View File
@@ -507,7 +507,7 @@ MPU6000::MPU6000(int bus, const char *path_accel, const char *path_gyro, spi_dev
_accel_scale{},
_accel_range_scale(0.0f),
_accel_range_m_s2(0.0f),
_accel_topic(0),
_accel_topic(nullptr),
_accel_orb_class_instance(-1),
_accel_class_instance(-1),
_gyro_reports(nullptr),
@@ -658,7 +658,7 @@ MPU6000::init()
_accel_topic = orb_advertise_multi(ORB_ID(sensor_accel), &arp,
&_accel_orb_class_instance, (is_external()) ? ORB_PRIO_MAX : ORB_PRIO_HIGH);
if (_accel_topic == 0) {
if (_accel_topic == nullptr) {
warnx("ADVERT FAIL");
}
@@ -670,7 +670,7 @@ MPU6000::init()
_gyro->_gyro_topic = orb_advertise_multi(ORB_ID(sensor_gyro), &grp,
&_gyro->_gyro_orb_class_instance, (is_external()) ? ORB_PRIO_MAX : ORB_PRIO_HIGH);
if (_gyro->_gyro_topic == 0) {
if (_gyro->_gyro_topic == nullptr) {
warnx("ADVERT FAIL");
}
@@ -1847,7 +1847,7 @@ MPU6000::print_registers()
MPU6000_gyro::MPU6000_gyro(MPU6000 *parent, const char *path) :
CDev("MPU6000_gyro", path),
_parent(parent),
_gyro_topic(0),
_gyro_topic(nullptr),
_gyro_orb_class_instance(-1),
_gyro_class_instance(-1)
{
+2 -2
View File
@@ -224,7 +224,7 @@ MS5611::MS5611(device::Device *interface, ms5611::prom_u &prom_buf, const char*
_OFF(0),
_SENS(0),
_msl_pressure(101325),
_baro_topic(0),
_baro_topic(nullptr),
_orb_class_instance(-1),
_class_instance(-1),
_sample_perf(perf_alloc(PC_ELAPSED, "ms5611_read")),
@@ -322,7 +322,7 @@ MS5611::init()
&_orb_class_instance, (is_external()) ? ORB_PRIO_HIGH : ORB_PRIO_DEFAULT);
if (_baro_topic == 0) {
if (_baro_topic == nullptr) {
warnx("failed to create sensor_baro publication");
}
+2 -2
View File
@@ -223,7 +223,7 @@ MS5611::MS5611(device::Device *interface, ms5611::prom_u &prom_buf, const char*
_OFF(0),
_SENS(0),
_msl_pressure(101325),
_baro_topic(0),
_baro_topic(nullptr),
_orb_class_instance(-1),
_class_instance(-1),
_sample_perf(perf_alloc(PC_ELAPSED, "ms5611_read")),
@@ -325,7 +325,7 @@ MS5611::init()
_baro_topic = orb_advertise_multi(ORB_ID(sensor_baro), &brp,
&_orb_class_instance, (is_external()) ? ORB_PRIO_HIGH : ORB_PRIO_DEFAULT);
if (_baro_topic == 0) {
if (_baro_topic == nullptr) {
warnx("failed to create sensor_baro publication");
}
//warnx("sensor_baro publication %ld", _baro_topic);
+3 -3
View File
@@ -517,7 +517,7 @@ PX4FLOW::collect()
float zeroval = 0.0f;
rotate_3f(_sensor_rotation, report.pixel_flow_x_integral, report.pixel_flow_y_integral, zeroval);
if (_px4flow_topic == 0) {
if (_px4flow_topic == nullptr) {
_px4flow_topic = orb_advertise(ORB_ID(optical_flow), &report);
} else {
@@ -570,9 +570,9 @@ PX4FLOW::start()
true,
SUBSYSTEM_TYPE_OPTICALFLOW
};
static orb_advert_t pub = -1;
static orb_advert_t pub = nullptr;
if (pub > 0) {
if (pub != nullptr) {
orb_publish(ORB_ID(subsystem_info), pub, &info);
} else {
+4 -4
View File
@@ -253,7 +253,7 @@ PX4FMU::PX4FMU() :
_current_update_rate(0),
_task(-1),
_armed_sub(-1),
_outputs_pub(-1),
_outputs_pub(nullptr),
_armed{},
_num_outputs(0),
_class_instance(0),
@@ -692,7 +692,7 @@ PX4FMU::task_main()
}
/* publish mixed control outputs */
if (_outputs_pub < 0) {
if (_outputs_pub != nullptr) {
_outputs_pub = orb_advertise_multi(ORB_ID(actuator_outputs), &outputs, &_actuator_output_topic_instance, ORB_PRIO_DEFAULT);
} else {
@@ -1837,7 +1837,7 @@ fake(int argc, char *argv[])
orb_advert_t handle = orb_advertise(ORB_ID_VEHICLE_ATTITUDE_CONTROLS, &ac);
if (handle < 0)
if (handle == nullptr)
errx(1, "advertise failed");
actuator_armed_s aa;
@@ -1847,7 +1847,7 @@ fake(int argc, char *argv[])
handle = orb_advertise(ORB_ID(actuator_armed), &aa);
if (handle < 0)
if (handle == nullptr)
errx(1, "advertise failed 2");
exit(0);
+12 -12
View File
@@ -515,12 +515,12 @@ PX4IO::PX4IO(device::Device *interface) :
_t_vehicle_control_mode(-1),
_t_param(-1),
_t_vehicle_command(-1),
_to_input_rc(0),
_to_outputs(0),
_to_battery(0),
_to_servorail(0),
_to_safety(0),
_to_mixer_status(0),
_to_input_rc(nullptr),
_to_outputs(nullptr),
_to_battery(nullptr),
_to_servorail(nullptr),
_to_safety(nullptr),
_to_mixer_status(nullptr),
_outputs{},
_servorail_status{},
_primary_pwm_device(false),
@@ -1474,7 +1474,7 @@ PX4IO::io_handle_status(uint16_t status)
}
/* lazily publish the safety status */
if (_to_safety > 0) {
if (_to_safety != nullptr) {
orb_publish(ORB_ID(safety), _to_safety, &safety);
} else {
@@ -1549,7 +1549,7 @@ PX4IO::io_handle_battery(uint16_t vbatt, uint16_t ibatt)
/* the announced battery status would conflict with the simulated battery status in HIL */
if (!(_pub_blocked)) {
/* lazily publish the battery voltage */
if (_to_battery > 0) {
if (_to_battery != nullptr) {
orb_publish(ORB_ID(battery_status), _to_battery, &battery_status);
} else {
@@ -1568,7 +1568,7 @@ PX4IO::io_handle_vservo(uint16_t vservo, uint16_t vrssi)
_servorail_status.rssi_v = vrssi * 0.001f;
/* lazily publish the servorail voltages */
if (_to_servorail > 0) {
if (_to_servorail != nullptr) {
orb_publish(ORB_ID(servorail_status), _to_servorail, &_servorail_status);
} else {
@@ -1723,7 +1723,7 @@ PX4IO::io_publish_raw_rc()
}
/* lazily advertise on first publication */
if (_to_input_rc == 0) {
if (_to_input_rc == nullptr) {
_to_input_rc = orb_advertise(ORB_ID(input_rc), &rc_val);
} else {
@@ -1756,7 +1756,7 @@ PX4IO::io_publish_pwm_outputs()
outputs.noutputs = _max_actuators;
/* lazily advertise on first publication */
if (_to_outputs == 0) {
if (_to_outputs == nullptr) {
int instance;
_to_outputs = orb_advertise_multi(ORB_ID(actuator_outputs),
&outputs, &instance, ORB_PRIO_MAX);
@@ -1774,7 +1774,7 @@ PX4IO::io_publish_pwm_outputs()
return ret;
/* publish mixer status */
if(_to_mixer_status == 0) {
if(_to_mixer_status == nullptr) {
_to_mixer_status = orb_advertise(ORB_ID(multirotor_motor_limits), &motor_limits);
} else {
orb_publish(ORB_ID(multirotor_motor_limits),_to_mixer_status, &motor_limits);
+1 -6
View File
@@ -293,7 +293,6 @@ SF0X::init()
_class_instance = register_class_devname(RANGE_FINDER_BASE_DEVICE_PATH);
<<<<<<< HEAD
if (_class_instance == CLASS_DEVICE_PRIMARY) {
/* get a publish handle on the range finder topic */
struct distance_sensor_s ds_report = {};
@@ -301,13 +300,9 @@ SF0X::init()
_distance_sensor_topic = orb_advertise_multi(ORB_ID(distance_sensor), &ds_report,
&_orb_class_instance, ORB_PRIO_HIGH);
if (_distance_sensor_topic < 0) {
if (_distance_sensor_topic == nullptr) {
log("failed to create distance_sensor object. Did you start uOrb?");
}
=======
if (_range_finder_topic == 0) {
warnx("advert err");
>>>>>>> extensive orb_advert_t fixes
}
} while(0);
+2 -2
View File
@@ -148,7 +148,7 @@ ADC::ADC(uint32_t channels) :
_sample_perf(perf_alloc(PC_ELAPSED, "adc_samples")),
_channel_count(0),
_samples(nullptr),
_to_system_power(0)
_to_system_power(nullptr)
{
_debug_enabled = true;
@@ -329,7 +329,7 @@ ADC::update_system_power(void)
system_power.hipower_5V_OC = !stm32_gpioread(GPIO_VDD_5V_HIPOWER_OC);
/* lazily publish */
if (_to_system_power > 0) {
if (_to_system_power != nullptr) {
orb_publish(ORB_ID(system_power), _to_system_power, &system_power);
} else {
_to_system_power = orb_advertise(ORB_ID(system_power), &system_power);
+1 -1
View File
@@ -301,7 +301,7 @@ TRONE::init()
_distance_sensor_topic = orb_advertise_multi(ORB_ID(distance_sensor), &ds_report,
&_orb_class_instance, ORB_PRIO_LOW);
if (_distance_sensor_topic == 0) {
if (_distance_sensor_topic == nullptr) {
log("failed to create distance_sensor object. Did you start uOrb?");
}
}