mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-31 12:51:35 +08:00
sensors/vehicle_gps_position: only register callbacks once topic published
- this avoids creating unnecessary uORB device nodes for GPS instances that might never exist
This commit is contained in:
@@ -59,16 +59,9 @@ bool VehicleGPSPosition::Start()
|
|||||||
// force initial updates
|
// force initial updates
|
||||||
ParametersUpdate(true);
|
ParametersUpdate(true);
|
||||||
|
|
||||||
// needed to change the active sensor if the primary stops updating
|
ScheduleNow();
|
||||||
bool anyGpsRegistered = false;
|
|
||||||
bool registered[GPS_MAX_RECEIVERS];
|
|
||||||
|
|
||||||
for (uint8_t i = 0; i < GPS_MAX_RECEIVERS; i++) {
|
return true;
|
||||||
registered[i] = _sensor_gps_sub[i].registerCallback();
|
|
||||||
anyGpsRegistered |= registered[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
return anyGpsRegistered;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void VehicleGPSPosition::Stop()
|
void VehicleGPSPosition::Stop()
|
||||||
@@ -98,21 +91,26 @@ void VehicleGPSPosition::Run()
|
|||||||
perf_begin(_cycle_perf);
|
perf_begin(_cycle_perf);
|
||||||
ParametersUpdate();
|
ParametersUpdate();
|
||||||
|
|
||||||
|
// backup schedule
|
||||||
|
ScheduleDelayed(500_ms);
|
||||||
|
|
||||||
// Check all GPS instance
|
// Check all GPS instance
|
||||||
bool any_gps_updated = false;
|
bool any_gps_updated = false;
|
||||||
bool gps_updated[GPS_MAX_RECEIVERS];
|
bool gps_updated[GPS_MAX_RECEIVERS];
|
||||||
|
|
||||||
for (uint8_t i = 0; i < GPS_MAX_RECEIVERS; i++) {
|
for (uint8_t i = 0; i < GPS_MAX_RECEIVERS; i++) {
|
||||||
|
|
||||||
gps_updated[i] = _sensor_gps_sub[i].updated();
|
gps_updated[i] = _sensor_gps_sub[i].updated();
|
||||||
|
|
||||||
if (gps_updated[i]) {
|
if (gps_updated[i]) {
|
||||||
any_gps_updated = true;
|
any_gps_updated = true;
|
||||||
_sensor_gps_sub[i].copy(&_gps_state[i]);
|
_sensor_gps_sub[i].copy(&_gps_state[i]);
|
||||||
|
|
||||||
|
if (!_sensor_gps_sub[i].registered()) {
|
||||||
|
_sensor_gps_sub[i].registerCallback();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ((_param_sens_gps_mask.get() == 0) && gps_updated[0]) {
|
if ((_param_sens_gps_mask.get() == 0) && gps_updated[0]) {
|
||||||
// When GPS blending is disabled we always use the first receiver instance
|
// When GPS blending is disabled we always use the first receiver instance
|
||||||
Publish(_gps_state[0]);
|
Publish(_gps_state[0]);
|
||||||
|
|||||||
@@ -68,22 +68,24 @@ public:
|
|||||||
|
|
||||||
bool registerCallback()
|
bool registerCallback()
|
||||||
{
|
{
|
||||||
if (_subscription.get_node() && _subscription.get_node()->register_callback(this)) {
|
if (!_registered) {
|
||||||
// registered
|
if (_subscription.get_node() && _subscription.get_node()->register_callback(this)) {
|
||||||
_registered = true;
|
// registered
|
||||||
|
_registered = true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// force topic creation by subscribing with old API
|
// force topic creation by subscribing with old API
|
||||||
int fd = orb_subscribe_multi(_subscription.get_topic(), _subscription.get_instance());
|
int fd = orb_subscribe_multi(_subscription.get_topic(), _subscription.get_instance());
|
||||||
|
|
||||||
// try to register callback again
|
// try to register callback again
|
||||||
if (_subscription.subscribe()) {
|
if (_subscription.subscribe()) {
|
||||||
if (_subscription.get_node() && _subscription.get_node()->register_callback(this)) {
|
if (_subscription.get_node() && _subscription.get_node()->register_callback(this)) {
|
||||||
_registered = true;
|
_registered = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
orb_unsubscribe(fd);
|
orb_unsubscribe(fd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return _registered;
|
return _registered;
|
||||||
@@ -131,6 +133,8 @@ public:
|
|||||||
|
|
||||||
virtual void call() = 0;
|
virtual void call() = 0;
|
||||||
|
|
||||||
|
bool registered() const { return _registered; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
bool _registered{false};
|
bool _registered{false};
|
||||||
|
|||||||
Reference in New Issue
Block a user