diff --git a/libraries/AP_AIS/AP_AIS.cpp b/libraries/AP_AIS/AP_AIS.cpp index 84e6367c10..d6f8e655a6 100644 --- a/libraries/AP_AIS/AP_AIS.cpp +++ b/libraries/AP_AIS/AP_AIS.cpp @@ -19,7 +19,7 @@ #include "AP_AIS.h" -#if HAL_AIS_ENABLED +#if AP_AIS_ENABLED #include #include @@ -63,6 +63,11 @@ const AP_Param::GroupInfo AP_AIS::var_info[] = { // constructor AP_AIS::AP_AIS() { + if (_singleton != nullptr) { + AP_HAL::panic("AIS must be singleton"); + } + _singleton = this; + AP_Param::setup_object_defaults(this, var_info); } @@ -804,4 +809,6 @@ bool AP_AIS::decode_latest_term() return false; } -#endif // HAL_AIS_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 e7507f35bf..c84a660f53 100644 --- a/libraries/AP_AIS/AP_AIS.h +++ b/libraries/AP_AIS/AP_AIS.h @@ -14,16 +14,18 @@ */ #pragma once +#include + +#ifndef AP_AIS_ENABLED +#define AP_AIS_ENABLED !HAL_MINIMIZE_FEATURES +#endif + +#if AP_AIS_ENABLED + #include #include #include -#ifndef HAL_AIS_ENABLED -#define HAL_AIS_ENABLED !HAL_MINIMIZE_FEATURES -#endif - -#if HAL_AIS_ENABLED - #define AIVDM_BUFFER_SIZE 10 #define AIVDM_PAYLOAD_SIZE 65 @@ -36,6 +38,11 @@ public: AP_AIS(const AP_AIS &other) = delete; AP_AIS &operator=(const AP_AIS&) = delete; + // get singleton instance + static AP_AIS *get_singleton() { + return _singleton; + } + // return true if AIS is enabled bool enabled() const { return AISType(_type.get()) != AISType::NONE; } @@ -131,6 +138,8 @@ private: bool _term_is_checksum; // current term is the checksum bool _sentence_valid; // is current sentence valid so far bool _sentence_done; // true if this sentence has already been decoded + + static AP_AIS *_singleton; }; -#endif // HAL_AIS_ENABLED +#endif // AP_AIS_ENABLED