mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-17 02:00:35 +08:00
extensive orb_advert_t fixes
The calls to orb_advertise were being mishandled throughout the code. There were ::close() calls on memory pointers, there were checks against < 0 when it is a pointer to a object and values larger than 0x7ffffffff are valid. Some places orb_advert_t variables were being initialized as 0 other places as -1. The orb_advert_t type was changed to uintptr_t so the pointer value would not be wrapped as a negative number. This was causing a failure on ARM. Tests for < 0 were changed to == 0 since a null pointer is the valid representation for error, or uninitialized. Signed-off-by: Mark Charlebois <charlebm@gmail.com>
This commit is contained in:
committed by
Lorenz Meier
parent
9a67303416
commit
a734fc96d1
@@ -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(-1),
|
||||
_subsys_pub(-1),
|
||||
_airspeed_pub(0),
|
||||
_subsys_pub(0),
|
||||
_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 == 0)
|
||||
warnx("uORB started?");
|
||||
}
|
||||
|
||||
@@ -367,7 +367,7 @@ Airspeed::update_status()
|
||||
SUBSYSTEM_TYPE_DIFFPRESSURE
|
||||
};
|
||||
|
||||
if (_subsys_pub > 0) {
|
||||
if (_subsys_pub == 0) {
|
||||
orb_publish(ORB_ID(subsystem_info), _subsys_pub, &info);
|
||||
} else {
|
||||
_subsys_pub = orb_advertise(ORB_ID(subsystem_info), &info);
|
||||
|
||||
@@ -203,7 +203,7 @@ BATT_SMBUS::BATT_SMBUS(int bus, uint16_t batt_smbus_addr) :
|
||||
_enabled(false),
|
||||
_work{},
|
||||
_reports(nullptr),
|
||||
_batt_topic(-1),
|
||||
_batt_topic(0),
|
||||
_batt_orb_id(nullptr),
|
||||
_start_time(0),
|
||||
_batt_capacity(0)
|
||||
@@ -427,13 +427,13 @@ BATT_SMBUS::cycle()
|
||||
}
|
||||
|
||||
// publish to orb
|
||||
if (_batt_topic != -1) {
|
||||
if (_batt_topic != 0) {
|
||||
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 == 0) {
|
||||
errx(1, "ADVERT FAIL");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(-1),
|
||||
_accel_topic(0),
|
||||
_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 != 0 && !(_pub_blocked))
|
||||
orb_publish(ORB_ID(sensor_accel), _accel_topic, &report);
|
||||
|
||||
/* stop the perf counter */
|
||||
|
||||
@@ -180,7 +180,7 @@ Gimbal::Gimbal() :
|
||||
_attitude_compensation_pitch(true),
|
||||
_attitude_compensation_yaw(true),
|
||||
_initialized(false),
|
||||
_actuator_controls_2_topic(-1),
|
||||
_actuator_controls_2_topic(0),
|
||||
_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"))
|
||||
@@ -197,7 +197,6 @@ Gimbal::~Gimbal()
|
||||
/* make sure we are truly inactive */
|
||||
stop();
|
||||
|
||||
::close(_actuator_controls_2_topic);
|
||||
::close(_vehicle_command_sub);
|
||||
}
|
||||
|
||||
@@ -281,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 == 0) {
|
||||
warnx("advert err");
|
||||
}
|
||||
|
||||
|
||||
@@ -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(-1),
|
||||
_report_gps_pos_pub(0),
|
||||
_p_report_sat_info(nullptr),
|
||||
_report_sat_info_pub(-1),
|
||||
_report_sat_info_pub(0),
|
||||
_rate(0.0f),
|
||||
_fake_gps(fake_gps)
|
||||
{
|
||||
|
||||
@@ -805,7 +805,7 @@ fake(int argc, char *argv[])
|
||||
|
||||
orb_advert_t handle = orb_advertise(ORB_ID_VEHICLE_ATTITUDE_CONTROLS, &ac);
|
||||
|
||||
if (handle < 0) {
|
||||
if (handle == 0) {
|
||||
puts("advertise failed");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -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(-1),
|
||||
_mag_topic(0),
|
||||
_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 != -1) {
|
||||
if (_mag_topic != 0) {
|
||||
/* 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 == 0)
|
||||
debug("ADVERT FAIL");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
static orb_advert_t _esc_pub = 0;
|
||||
|
||||
static bool _home_position_set = false;
|
||||
static double _home_lat = 0.0d;
|
||||
|
||||
@@ -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(-1),
|
||||
_gyro_topic(0),
|
||||
_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 == 0) {
|
||||
debug("failed to create sensor_gyro publication");
|
||||
}
|
||||
|
||||
|
||||
@@ -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(-1),
|
||||
_accel_topic(0),
|
||||
_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 == 0) {
|
||||
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 == 0) {
|
||||
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(-1),
|
||||
_mag_topic(0),
|
||||
_mag_orb_class_instance(-1),
|
||||
_mag_class_instance(-1)
|
||||
{
|
||||
|
||||
@@ -211,7 +211,7 @@ MB12XX::MB12XX(int bus, int address) :
|
||||
_collect_phase(false),
|
||||
_class_instance(-1),
|
||||
_orb_class_instance(-1),
|
||||
_distance_sensor_topic(-1),
|
||||
_distance_sensor_topic(nullptr),
|
||||
_sample_perf(perf_alloc(PC_ELAPSED, "mb12xx_read")),
|
||||
_comms_errors(perf_alloc(PC_COUNT, "mb12xx_comms_errors")),
|
||||
_buffer_overflows(perf_alloc(PC_COUNT, "mb12xx_buffer_overflows")),
|
||||
@@ -276,7 +276,7 @@ MB12XX::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?");
|
||||
}
|
||||
}
|
||||
@@ -588,7 +588,7 @@ MB12XX::collect()
|
||||
report.id = 0;
|
||||
|
||||
/* publish it, if we are the primary */
|
||||
if (_distance_sensor_topic >= 0) {
|
||||
if (_distance_sensor_topic != nullptr) {
|
||||
orb_publish(ORB_ID(distance_sensor), _distance_sensor_topic, &report);
|
||||
}
|
||||
|
||||
|
||||
@@ -641,7 +641,6 @@ MK::task_main()
|
||||
|
||||
}
|
||||
|
||||
::close(_t_esc_status);
|
||||
::close(_t_actuators);
|
||||
::close(_t_actuator_armed);
|
||||
|
||||
|
||||
@@ -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(-1),
|
||||
_accel_topic(0),
|
||||
_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 == 0) {
|
||||
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 == 0) {
|
||||
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(-1),
|
||||
_gyro_topic(0),
|
||||
_gyro_orb_class_instance(-1),
|
||||
_gyro_class_instance(-1)
|
||||
{
|
||||
|
||||
@@ -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(-1),
|
||||
_baro_topic(0),
|
||||
_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 == 0) {
|
||||
warnx("failed to create sensor_baro publication");
|
||||
}
|
||||
|
||||
|
||||
@@ -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(-1),
|
||||
_baro_topic(0),
|
||||
_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 == (orb_advert_t)(-1)) {
|
||||
if (_baro_topic == 0) {
|
||||
warnx("failed to create sensor_baro publication");
|
||||
}
|
||||
//warnx("sensor_baro publication %ld", _baro_topic);
|
||||
|
||||
@@ -193,8 +193,8 @@ PX4FLOW::PX4FLOW(int bus, int address, enum Rotation rotation) :
|
||||
_collect_phase(false),
|
||||
_class_instance(-1),
|
||||
_orb_class_instance(-1),
|
||||
_px4flow_topic(-1),
|
||||
_distance_sensor_topic(-1),
|
||||
_px4flow_topic(nullptr),
|
||||
_distance_sensor_topic(nullptr),
|
||||
_sample_perf(perf_alloc(PC_ELAPSED, "px4flow_read")),
|
||||
_comms_errors(perf_alloc(PC_COUNT, "px4flow_comms_errors")),
|
||||
_buffer_overflows(perf_alloc(PC_COUNT, "px4flow_buffer_overflows")),
|
||||
@@ -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 == 0) {
|
||||
_px4flow_topic = orb_advertise(ORB_ID(optical_flow), &report);
|
||||
|
||||
} else {
|
||||
|
||||
@@ -200,7 +200,7 @@ SF0X::SF0X(const char *port) :
|
||||
_last_read(0),
|
||||
_class_instance(-1),
|
||||
_orb_class_instance(-1),
|
||||
_distance_sensor_topic(-1),
|
||||
_distance_sensor_topic(nullptr),
|
||||
_consecutive_fail_count(0),
|
||||
_sample_perf(perf_alloc(PC_ELAPSED, "sf0x_read")),
|
||||
_comms_errors(perf_alloc(PC_COUNT, "sf0x_comms_errors")),
|
||||
@@ -293,6 +293,7 @@ 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 = {};
|
||||
@@ -303,6 +304,10 @@ SF0X::init()
|
||||
if (_distance_sensor_topic < 0) {
|
||||
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);
|
||||
|
||||
@@ -238,7 +238,7 @@ TRONE::TRONE(int bus, int address) :
|
||||
_collect_phase(false),
|
||||
_class_instance(-1),
|
||||
_orb_class_instance(-1),
|
||||
_distance_sensor_topic(-1),
|
||||
_distance_sensor_topic(0),
|
||||
_sample_perf(perf_alloc(PC_ELAPSED, "trone_read")),
|
||||
_comms_errors(perf_alloc(PC_COUNT, "trone_comms_errors")),
|
||||
_buffer_overflows(perf_alloc(PC_COUNT, "trone_buffer_overflows"))
|
||||
@@ -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 == 0) {
|
||||
log("failed to create distance_sensor object. Did you start uOrb?");
|
||||
}
|
||||
}
|
||||
@@ -587,7 +587,7 @@ TRONE::collect()
|
||||
report.id = 0;
|
||||
|
||||
/* publish it, if we are the primary */
|
||||
if (_distance_sensor_topic >= 0) {
|
||||
if (_distance_sensor_topic != nullptr) {
|
||||
orb_publish(ORB_ID(distance_sensor), _distance_sensor_topic, &report);
|
||||
}
|
||||
|
||||
@@ -621,9 +621,9 @@ TRONE::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);
|
||||
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user