AP_ADSB: create frontend/backend split

This commit is contained in:
Tom Pittenger 2020-10-21 11:37:08 -07:00 committed by Tom Pittenger
parent fd9068de8a
commit f784fc7c5c
6 changed files with 141 additions and 0 deletions

View File

@ -23,6 +23,7 @@
#include "AP_ADSB.h"
#if HAL_ADSB_ENABLED
#include "AP_ADSB_uAvionix_MAVLink.h"
#include <GCS_MAVLink/GCS_MAVLink.h>
#include <stdio.h> // for sprintf
#include <limits.h>
@ -203,6 +204,16 @@ void AP_ADSB::init(void)
}
in_state.list_size_allocated = in_state.list_size_param;
}
if (_backend == nullptr) {
_backend = new AP_ADSB_uAvionix_MAVLink(*this);
if (_backend == nullptr) {
_init_failed = true;
gcs().send_text(MAV_SEVERITY_CRITICAL, "ADSB: Unable to initialize ADSB driver");
return;
}
}
}
/*

View File

@ -34,8 +34,13 @@
#include <AP_Common/Location.h>
#include <GCS_MAVLink/GCS_MAVLink.h>
class AP_ADSB_Backend;
class AP_ADSB {
public:
friend class AP_ADSB_Backend;
friend class AP_ADSB_uAvionix_MAVLink;
// constructor
AP_ADSB();
@ -235,6 +240,8 @@ private:
void update_uavionix();
// reference to backend
AP_ADSB_Backend *_backend;
};
namespace AP {

View File

@ -0,0 +1,29 @@
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "AP_ADSB_Backend.h"
#if HAL_ADSB_ENABLED
/*
base class constructor.
*/
AP_ADSB_Backend::AP_ADSB_Backend(AP_ADSB &frontend) :
_frontend(frontend)
{
}
#endif // HAL_ADSB_ENABLED

View File

@ -0,0 +1,36 @@
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "AP_ADSB.h"
#if HAL_ADSB_ENABLED
class AP_ADSB_Backend
{
public:
// constructor.
AP_ADSB_Backend(AP_ADSB &frontend);
virtual void update() = 0;
protected:
// references
AP_ADSB &_frontend;
private:
};
#endif // HAL_ADSB_ENABLED

View File

@ -0,0 +1,27 @@
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "AP_ADSB_uAvionix_MAVLink.h"
#if HAL_ADSB_ENABLED
extern const AP_HAL::HAL& hal;
void AP_ADSB_uAvionix_MAVLink::update()
{
}
#endif // HAL_ADSB_ENABLED

View File

@ -0,0 +1,31 @@
#pragma once
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "AP_ADSB_Backend.h"
#if HAL_ADSB_ENABLED
class AP_ADSB_uAvionix_MAVLink : public AP_ADSB_Backend {
public:
using AP_ADSB_Backend::AP_ADSB_Backend;
void update() override;
private:
};
#endif // HAL_ADSB_ENABLED