2017-04-02 11:56:26 -03:00
|
|
|
/*
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
//
|
|
|
|
// UAVCAN GPS driver
|
|
|
|
//
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AP_Common/AP_Common.h>
|
|
|
|
#include <AP_HAL/AP_HAL.h>
|
|
|
|
#include "AP_GPS.h"
|
|
|
|
#include "GPS_Backend.h"
|
2021-08-11 07:13:55 -03:00
|
|
|
#include "RTCM3_Parser.h"
|
2018-07-18 06:27:15 -03:00
|
|
|
#include <AP_UAVCAN/AP_UAVCAN.h>
|
|
|
|
|
|
|
|
class FixCb;
|
2019-11-06 06:32:25 -04:00
|
|
|
class Fix2Cb;
|
2018-07-18 06:27:15 -03:00
|
|
|
class AuxCb;
|
2020-10-30 01:39:01 -03:00
|
|
|
class HeadingCb;
|
2021-02-23 16:18:17 -04:00
|
|
|
class StatusCb;
|
2021-08-11 07:13:55 -03:00
|
|
|
#if GPS_MOVING_BASELINE
|
|
|
|
class MovingBaselineDataCb;
|
|
|
|
class RelPosHeadingCb;
|
|
|
|
#endif
|
2018-07-18 06:27:15 -03:00
|
|
|
|
2017-04-02 11:56:26 -03:00
|
|
|
class AP_GPS_UAVCAN : public AP_GPS_Backend {
|
|
|
|
public:
|
2021-08-11 07:13:55 -03:00
|
|
|
AP_GPS_UAVCAN(AP_GPS &_gps, AP_GPS::GPS_State &_state, AP_GPS::GPS_Role role);
|
2018-07-18 06:27:15 -03:00
|
|
|
~AP_GPS_UAVCAN();
|
2017-04-02 11:56:26 -03:00
|
|
|
|
|
|
|
bool read() override;
|
2016-08-01 08:58:23 -03:00
|
|
|
|
2021-02-23 16:18:17 -04:00
|
|
|
bool is_healthy(void) const override;
|
|
|
|
|
|
|
|
bool logging_healthy(void) const override;
|
|
|
|
|
|
|
|
bool is_configured(void) const override;
|
|
|
|
|
2020-12-28 10:30:41 -04:00
|
|
|
const char *name() const override { return _name; }
|
2016-08-01 08:58:23 -03:00
|
|
|
|
2018-07-18 06:27:15 -03:00
|
|
|
static void subscribe_msgs(AP_UAVCAN* ap_uavcan);
|
|
|
|
static AP_GPS_Backend* probe(AP_GPS &_gps, AP_GPS::GPS_State &_state);
|
|
|
|
|
|
|
|
static void handle_fix_msg_trampoline(AP_UAVCAN* ap_uavcan, uint8_t node_id, const FixCb &cb);
|
2019-11-06 06:32:25 -04:00
|
|
|
static void handle_fix2_msg_trampoline(AP_UAVCAN* ap_uavcan, uint8_t node_id, const Fix2Cb &cb);
|
2018-07-18 06:27:15 -03:00
|
|
|
static void handle_aux_msg_trampoline(AP_UAVCAN* ap_uavcan, uint8_t node_id, const AuxCb &cb);
|
2020-10-30 01:39:01 -03:00
|
|
|
static void handle_heading_msg_trampoline(AP_UAVCAN* ap_uavcan, uint8_t node_id, const HeadingCb &cb);
|
2021-02-23 16:18:17 -04:00
|
|
|
static void handle_status_msg_trampoline(AP_UAVCAN* ap_uavcan, uint8_t node_id, const StatusCb &cb);
|
2021-08-11 07:13:55 -03:00
|
|
|
#if GPS_MOVING_BASELINE
|
|
|
|
static void handle_moving_baseline_msg_trampoline(AP_UAVCAN* ap_uavcan, uint8_t node_id, const MovingBaselineDataCb &cb);
|
|
|
|
static void handle_relposheading_msg_trampoline(AP_UAVCAN* ap_uavcan, uint8_t node_id, const RelPosHeadingCb &cb);
|
|
|
|
#endif
|
2020-12-28 10:30:41 -04:00
|
|
|
static bool backends_healthy(char failure_msg[], uint16_t failure_msg_len);
|
2019-10-21 08:11:26 -03:00
|
|
|
void inject_data(const uint8_t *data, uint16_t len) override;
|
|
|
|
|
2021-02-23 16:18:17 -04:00
|
|
|
bool get_error_codes(uint32_t &error_codes) const override { error_codes = error_code; return seen_status; };
|
|
|
|
|
2021-08-11 07:13:55 -03:00
|
|
|
#if GPS_MOVING_BASELINE
|
|
|
|
bool get_RTCMV3(const uint8_t *&data, uint16_t &len) override;
|
|
|
|
void clear_RTCMV3() override;
|
|
|
|
#endif
|
2021-07-16 13:21:01 -03:00
|
|
|
|
2017-04-02 11:56:26 -03:00
|
|
|
private:
|
2021-07-16 13:21:01 -03:00
|
|
|
|
|
|
|
bool param_configured = true;
|
|
|
|
enum config_step {
|
|
|
|
STEP_SET_TYPE = 0,
|
|
|
|
STEP_SET_MB_CAN_TX,
|
|
|
|
STEP_SAVE_AND_REBOOT,
|
|
|
|
STEP_FINISHED
|
|
|
|
};
|
|
|
|
uint8_t cfg_step;
|
|
|
|
bool requires_save_and_reboot;
|
|
|
|
|
|
|
|
// returns true once configuration has finished
|
|
|
|
bool do_config(void);
|
|
|
|
|
2018-07-18 06:27:15 -03:00
|
|
|
void handle_fix_msg(const FixCb &cb);
|
2019-11-06 06:32:25 -04:00
|
|
|
void handle_fix2_msg(const Fix2Cb &cb);
|
2018-07-18 06:27:15 -03:00
|
|
|
void handle_aux_msg(const AuxCb &cb);
|
2020-10-30 01:39:01 -03:00
|
|
|
void handle_heading_msg(const HeadingCb &cb);
|
2021-02-23 16:18:17 -04:00
|
|
|
void handle_status_msg(const StatusCb &cb);
|
2018-07-18 06:27:15 -03:00
|
|
|
|
2021-08-11 07:13:55 -03:00
|
|
|
#if GPS_MOVING_BASELINE
|
2021-07-16 13:21:01 -03:00
|
|
|
void handle_moving_baseline_msg(const MovingBaselineDataCb &cb, uint8_t node_id);
|
|
|
|
void handle_relposheading_msg(const RelPosHeadingCb &cb, uint8_t node_id);
|
2021-08-11 07:13:55 -03:00
|
|
|
#endif
|
|
|
|
|
2018-07-18 06:27:15 -03:00
|
|
|
static bool take_registry();
|
|
|
|
static void give_registry();
|
|
|
|
static AP_GPS_UAVCAN* get_uavcan_backend(AP_UAVCAN* ap_uavcan, uint8_t node_id);
|
|
|
|
|
2017-04-02 11:56:26 -03:00
|
|
|
bool _new_data;
|
2018-07-18 06:27:15 -03:00
|
|
|
AP_GPS::GPS_State interim_state;
|
|
|
|
|
|
|
|
HAL_Semaphore sem;
|
|
|
|
|
|
|
|
uint8_t _detected_module;
|
2019-10-09 01:30:39 -03:00
|
|
|
bool seen_message;
|
2019-11-06 06:32:25 -04:00
|
|
|
bool seen_fix2;
|
2019-11-27 22:41:29 -04:00
|
|
|
bool seen_aux;
|
2021-02-23 16:18:17 -04:00
|
|
|
bool seen_status;
|
|
|
|
|
|
|
|
bool healthy;
|
|
|
|
uint32_t status_flags;
|
|
|
|
uint32_t error_code;
|
2020-12-28 10:30:41 -04:00
|
|
|
char _name[15];
|
2018-07-18 06:27:15 -03:00
|
|
|
|
|
|
|
// Module Detection Registry
|
|
|
|
static struct DetectedModules {
|
|
|
|
AP_UAVCAN* ap_uavcan;
|
|
|
|
uint8_t node_id;
|
2020-12-28 10:30:41 -04:00
|
|
|
uint8_t instance;
|
2018-07-18 06:27:15 -03:00
|
|
|
AP_GPS_UAVCAN* driver;
|
|
|
|
} _detected_modules[GPS_MAX_RECEIVERS];
|
2017-04-02 11:56:26 -03:00
|
|
|
|
2018-10-11 20:35:03 -03:00
|
|
|
static HAL_Semaphore _sem_registry;
|
2021-08-11 07:13:55 -03:00
|
|
|
|
|
|
|
#if GPS_MOVING_BASELINE
|
|
|
|
// RTCM3 parser for when in moving baseline base mode
|
|
|
|
RTCM3_Parser *rtcm3_parser;
|
|
|
|
#endif
|
|
|
|
// the role set from GPS_TYPE
|
|
|
|
AP_GPS::GPS_Role role;
|
|
|
|
|
2021-07-16 13:21:01 -03:00
|
|
|
FUNCTOR_DECLARE(param_int_cb, bool, AP_UAVCAN*, const uint8_t, const char*, int32_t &);
|
|
|
|
FUNCTOR_DECLARE(param_float_cb, bool, AP_UAVCAN*, const uint8_t, const char*, float &);
|
|
|
|
FUNCTOR_DECLARE(param_save_cb, void, AP_UAVCAN*, const uint8_t, bool);
|
|
|
|
|
|
|
|
bool handle_param_get_set_response_int(AP_UAVCAN* ap_uavcan, const uint8_t node_id, const char* name, int32_t &value);
|
|
|
|
bool handle_param_get_set_response_float(AP_UAVCAN* ap_uavcan, const uint8_t node_id, const char* name, float &value);
|
|
|
|
void handle_param_save_response(AP_UAVCAN* ap_uavcan, const uint8_t node_id, bool success);
|
2017-04-02 11:56:26 -03:00
|
|
|
};
|