diff --git a/libraries/AP_AIS/AP_AIS.cpp b/libraries/AP_AIS/AP_AIS.cpp index d6f8e655a6..628ea79a5f 100644 --- a/libraries/AP_AIS/AP_AIS.cpp +++ b/libraries/AP_AIS/AP_AIS.cpp @@ -21,6 +21,12 @@ #if AP_AIS_ENABLED +#include + +#define AP_AIS_DUMMY_METHODS_ENABLED ((AP_AIS_ENABLED == 2) && !APM_BUILD_TYPE(APM_BUILD_Rover)) + +#if !AP_AIS_DUMMY_METHODS_ENABLED + #include #include #include @@ -71,6 +77,12 @@ AP_AIS::AP_AIS() AP_Param::setup_object_defaults(this, var_info); } +// return true if AIS is enabled +bool AP_AIS::enabled() const +{ + return AISType(_type.get()) != AISType::NONE; +} + // Initialize the AIS object and prepare it for use void AP_AIS::init() { @@ -809,6 +821,30 @@ bool AP_AIS::decode_latest_term() return false; } +// get singleton instance +AP_AIS *AP_AIS::get_singleton() { + return _singleton; +} + +#else +// Dummy methods are required to allow functionality to be enabled for Rover. +// It is not posible to compile in or out the full code based on vehicle type due to limitations +// of the handling of `APM_BUILD_TYPE` define. +// These dummy methods minimise flash cost in that case. + +const AP_Param::GroupInfo AP_AIS::var_info[] = { AP_GROUPEND }; +AP_AIS::AP_AIS() {}; + +bool AP_AIS::enabled() const { return false; } + +void AP_AIS::init() {}; +void AP_AIS::update() {}; +void AP_AIS::send(mavlink_channel_t chan) {}; + +AP_AIS *AP_AIS::get_singleton() { return nullptr; } + +#endif // AP_AIS_DUMMY_METHODS_ENABLED + AP_AIS *AP_AIS::_singleton; #endif // AP_AIS_ENABLED diff --git a/libraries/AP_AIS/AP_AIS.h b/libraries/AP_AIS/AP_AIS.h index c84a660f53..fa1f7795dc 100644 --- a/libraries/AP_AIS/AP_AIS.h +++ b/libraries/AP_AIS/AP_AIS.h @@ -17,10 +17,17 @@ #include #ifndef AP_AIS_ENABLED -#define AP_AIS_ENABLED !HAL_MINIMIZE_FEATURES +#if BOARD_FLASH_SIZE <= 1024 + #define AP_AIS_ENABLED 0 +#else + #define AP_AIS_ENABLED 2 +#endif #endif #if AP_AIS_ENABLED +// 0 fully disabled and compiled out +// 1 compiled in and enabled +// 2 compiled in with dummy methods, none functional, except rover which never uses dummy methods functionality #include #include @@ -34,17 +41,13 @@ class AP_AIS public: AP_AIS(); - /* Do not allow copies */ - AP_AIS(const AP_AIS &other) = delete; - AP_AIS &operator=(const AP_AIS&) = delete; + CLASS_NO_COPY(AP_AIS); // get singleton instance - static AP_AIS *get_singleton() { - return _singleton; - } + static AP_AIS *get_singleton(); // return true if AIS is enabled - bool enabled() const { return AISType(_type.get()) != AISType::NONE; } + bool enabled() const; // Initialize the AIS object and prepare it for use void init();