AP_AIS: add dummy methods

This commit is contained in:
Iampete1 2022-03-04 21:12:08 +00:00 committed by Andrew Tridgell
parent 28989f1838
commit faa414fbdb
2 changed files with 47 additions and 8 deletions

View File

@ -21,6 +21,12 @@
#if AP_AIS_ENABLED
#include <AP_Vehicle/AP_Vehicle_Type.h>
#define AP_AIS_DUMMY_METHODS_ENABLED ((AP_AIS_ENABLED == 2) && !APM_BUILD_TYPE(APM_BUILD_Rover))
#if !AP_AIS_DUMMY_METHODS_ENABLED
#include <AP_Logger/AP_Logger.h>
#include <GCS_MAVLink/GCS_MAVLink.h>
#include <GCS_MAVLink/GCS.h>
@ -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

View File

@ -17,10 +17,17 @@
#include <AP_HAL/AP_HAL_Boards.h>
#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 <AP_Param/AP_Param.h>
#include <AP_SerialManager/AP_SerialManager.h>
@ -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();