AP_CANSensor: create a separate register driver method

This commit is contained in:
bugobliterator 2021-07-22 22:21:08 +05:30 committed by Andrew Tridgell
parent f472da8e90
commit 6e61867e7f
2 changed files with 14 additions and 5 deletions

View File

@ -30,20 +30,26 @@ extern const AP_HAL::HAL& hal;
#define debug_can(level_debug, fmt, args...)
#endif
CANSensor::CANSensor(const char *driver_name, AP_CANManager::Driver_Type dtype, uint16_t stack_size) :
CANSensor::CANSensor(const char *driver_name, uint16_t stack_size) :
_driver_name(driver_name),
_stack_size(stack_size)
{}
void CANSensor::register_driver(AP_CANManager::Driver_Type dtype)
{
#if HAL_CANMANAGER_ENABLED
if (!AP::can().register_driver(dtype, this)) {
debug_can(AP_CANManager::LOG_ERROR, "Failed to register CANSensor %s", driver_name);
debug_can(AP_CANManager::LOG_ERROR, "Failed to register CANSensor %s", _driver_name);
} else {
debug_can(AP_CANManager::LOG_INFO, "%s: constructed", driver_name);
debug_can(AP_CANManager::LOG_INFO, "%s: constructed", _driver_name);
}
#elif defined(HAL_BUILD_AP_PERIPH)
register_driver_periph(dtype);
#endif
}
#ifdef HAL_BUILD_AP_PERIPH
CANSensor::CANSensor_Periph CANSensor::_periph[HAL_NUM_CAN_IFACES];

View File

@ -24,8 +24,8 @@
class CANSensor : public AP_CANDriver {
public:
CANSensor(const char *driver_name, AP_CANManager::Driver_Type dtype, uint16_t stack_size=2048);
CANSensor(const char *driver_name, uint16_t stack_size=2048);
/* Do not allow copies */
CANSensor(const CANSensor &other) = delete;
CANSensor &operator=(const CANSensor&) = delete;
@ -48,6 +48,9 @@ public:
}
#endif
protected:
void register_driver(AP_CANManager::Driver_Type dtype);
private:
void loop();