mirror of https://github.com/ArduPilot/ardupilot
AP_OpticalFlow: optimize DroneCAN subscription process
* remove unnecessary nullptr check, these are always called from an initialized AP_DroneCAN so if it's nullptr something has gone horrifically wrong * pass in driver index instead of repeatedly calling function to get it * simplify error handling; knowing exactly which allocation failed is not super helpful and one failing likely means subsequent ones will too, as it can only fail due to being out of memory
This commit is contained in:
parent
01c6765b6f
commit
1c08119dd9
|
@ -26,15 +26,11 @@ AP_OpticalFlow_HereFlow::AP_OpticalFlow_HereFlow(AP_OpticalFlow &flow) :
|
|||
}
|
||||
|
||||
//links the HereFlow messages to the backend
|
||||
void AP_OpticalFlow_HereFlow::subscribe_msgs(AP_DroneCAN* ap_dronecan)
|
||||
bool AP_OpticalFlow_HereFlow::subscribe_msgs(AP_DroneCAN* ap_dronecan)
|
||||
{
|
||||
if (ap_dronecan == nullptr) {
|
||||
return;
|
||||
}
|
||||
const auto driver_index = ap_dronecan->get_driver_index();
|
||||
|
||||
if (Canard::allocate_sub_arg_callback(ap_dronecan, &handle_measurement, ap_dronecan->get_driver_index()) == nullptr) {
|
||||
AP_BoardConfig::allocation_error("measurement_sub");
|
||||
}
|
||||
return (Canard::allocate_sub_arg_callback(ap_dronecan, &handle_measurement, driver_index) != nullptr);
|
||||
}
|
||||
|
||||
//updates driver states based on received HereFlow messages
|
||||
|
|
|
@ -15,7 +15,7 @@ public:
|
|||
|
||||
void update() override;
|
||||
|
||||
static void subscribe_msgs(AP_DroneCAN* ap_dronecan);
|
||||
static bool subscribe_msgs(AP_DroneCAN* ap_dronecan);
|
||||
|
||||
static void handle_measurement(AP_DroneCAN *ap_dronecan, const CanardRxTransfer& transfer, const com_hex_equipment_flow_Measurement &msg);
|
||||
|
||||
|
|
Loading…
Reference in New Issue