Browse Source

AP_AIS: add singleton

apm_2208
Iampete1 4 years ago committed by Andrew Tridgell
parent
commit
b94e1c5027
  1. 11
      libraries/AP_AIS/AP_AIS.cpp
  2. 23
      libraries/AP_AIS/AP_AIS.h

11
libraries/AP_AIS/AP_AIS.cpp

@ -19,7 +19,7 @@
#include "AP_AIS.h" #include "AP_AIS.h"
#if HAL_AIS_ENABLED #if AP_AIS_ENABLED
#include <AP_Logger/AP_Logger.h> #include <AP_Logger/AP_Logger.h>
#include <GCS_MAVLink/GCS_MAVLink.h> #include <GCS_MAVLink/GCS_MAVLink.h>
@ -63,6 +63,11 @@ const AP_Param::GroupInfo AP_AIS::var_info[] = {
// constructor // constructor
AP_AIS::AP_AIS() AP_AIS::AP_AIS()
{ {
if (_singleton != nullptr) {
AP_HAL::panic("AIS must be singleton");
}
_singleton = this;
AP_Param::setup_object_defaults(this, var_info); AP_Param::setup_object_defaults(this, var_info);
} }
@ -804,4 +809,6 @@ bool AP_AIS::decode_latest_term()
return false; return false;
} }
#endif // HAL_AIS_ENABLED AP_AIS *AP_AIS::_singleton;
#endif // AP_AIS_ENABLED

23
libraries/AP_AIS/AP_AIS.h

@ -14,15 +14,17 @@
*/ */
#pragma once #pragma once
#include <AP_Param/AP_Param.h> #include <AP_HAL/AP_HAL_Boards.h>
#include <AP_SerialManager/AP_SerialManager.h>
#include <AP_Common/AP_ExpandingArray.h>
#ifndef HAL_AIS_ENABLED #ifndef AP_AIS_ENABLED
#define HAL_AIS_ENABLED !HAL_MINIMIZE_FEATURES #define AP_AIS_ENABLED !HAL_MINIMIZE_FEATURES
#endif #endif
#if HAL_AIS_ENABLED #if AP_AIS_ENABLED
#include <AP_Param/AP_Param.h>
#include <AP_SerialManager/AP_SerialManager.h>
#include <AP_Common/AP_ExpandingArray.h>
#define AIVDM_BUFFER_SIZE 10 #define AIVDM_BUFFER_SIZE 10
#define AIVDM_PAYLOAD_SIZE 65 #define AIVDM_PAYLOAD_SIZE 65
@ -36,6 +38,11 @@ public:
AP_AIS(const AP_AIS &other) = delete; AP_AIS(const AP_AIS &other) = delete;
AP_AIS &operator=(const AP_AIS&) = delete; AP_AIS &operator=(const AP_AIS&) = delete;
// get singleton instance
static AP_AIS *get_singleton() {
return _singleton;
}
// return true if AIS is enabled // return true if AIS is enabled
bool enabled() const { return AISType(_type.get()) != AISType::NONE; } bool enabled() const { return AISType(_type.get()) != AISType::NONE; }
@ -131,6 +138,8 @@ private:
bool _term_is_checksum; // current term is the checksum bool _term_is_checksum; // current term is the checksum
bool _sentence_valid; // is current sentence valid so far bool _sentence_valid; // is current sentence valid so far
bool _sentence_done; // true if this sentence has already been decoded bool _sentence_done; // true if this sentence has already been decoded
static AP_AIS *_singleton;
}; };
#endif // HAL_AIS_ENABLED #endif // AP_AIS_ENABLED

Loading…
Cancel
Save