2013-05-29 20:52:21 -03:00
|
|
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
2013-08-29 02:34:34 -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/>.
|
|
|
|
*/
|
|
|
|
|
2010-09-06 17:00:57 -03:00
|
|
|
//
|
|
|
|
// DIYDrones Custom Mediatek GPS driver for ArduPilot and ArduPilotMega.
|
|
|
|
// Code by Michael Smith, Jordi Munoz and Jose Julio, DIYDrones.com
|
|
|
|
//
|
|
|
|
// GPS configuration : Custom protocol per "DIYDrones Custom Binary Sentence Specification V1.1"
|
|
|
|
//
|
2010-12-24 02:35:09 -04:00
|
|
|
// Note - see AP_GPS_MTK16.h for firmware 1.6 and later.
|
|
|
|
//
|
2016-02-17 21:25:23 -04:00
|
|
|
#pragma once
|
2010-08-24 01:13:27 -03:00
|
|
|
|
2015-08-11 03:28:43 -03:00
|
|
|
#include "AP_GPS.h"
|
2016-04-13 14:20:05 -03:00
|
|
|
#include "GPS_Backend.h"
|
2010-12-24 02:35:09 -04:00
|
|
|
#include "AP_GPS_MTK_Common.h"
|
2010-09-06 02:05:52 -03:00
|
|
|
|
2014-03-28 16:52:27 -03:00
|
|
|
class AP_GPS_MTK : public AP_GPS_Backend {
|
2010-09-06 17:00:57 -03:00
|
|
|
public:
|
2014-03-28 16:52:27 -03:00
|
|
|
AP_GPS_MTK(AP_GPS &_gps, AP_GPS::GPS_State &_state, AP_HAL::UARTDriver *_port);
|
2013-02-19 20:32:15 -04:00
|
|
|
|
2014-03-28 16:52:27 -03:00
|
|
|
bool read(void);
|
2014-03-28 00:50:44 -03:00
|
|
|
|
2014-03-28 16:52:27 -03:00
|
|
|
static bool _detect(struct MTK_detect_state &state, uint8_t data);
|
2014-03-31 06:48:22 -03:00
|
|
|
static void send_init_blob(uint8_t instance, AP_GPS &gps);
|
2010-09-06 17:00:57 -03:00
|
|
|
|
|
|
|
private:
|
2013-05-09 07:04:36 -03:00
|
|
|
struct PACKED diyd_mtk_msg {
|
2012-08-17 03:19:44 -03:00
|
|
|
int32_t latitude;
|
|
|
|
int32_t longitude;
|
|
|
|
int32_t altitude;
|
|
|
|
int32_t ground_speed;
|
|
|
|
int32_t ground_course;
|
|
|
|
uint8_t satellites;
|
|
|
|
uint8_t fix_type;
|
|
|
|
uint32_t utc_time;
|
2011-10-28 15:52:50 -03:00
|
|
|
};
|
|
|
|
enum diyd_mtk_fix_type {
|
|
|
|
FIX_NONE = 1,
|
|
|
|
FIX_2D = 2,
|
2012-12-14 22:47:35 -04:00
|
|
|
FIX_3D = 3
|
2011-10-28 15:52:50 -03:00
|
|
|
};
|
2010-09-06 17:00:57 -03:00
|
|
|
|
2011-10-28 15:52:50 -03:00
|
|
|
enum diyd_mtk_protocol_bytes {
|
|
|
|
PREAMBLE1 = 0xb5,
|
|
|
|
PREAMBLE2 = 0x62,
|
|
|
|
MESSAGE_CLASS = 1,
|
|
|
|
MESSAGE_ID = 5
|
|
|
|
};
|
2010-09-06 17:00:57 -03:00
|
|
|
|
2011-10-28 15:52:50 -03:00
|
|
|
// Packet checksum accumulators
|
2012-08-17 03:19:44 -03:00
|
|
|
uint8_t _ck_a;
|
|
|
|
uint8_t _ck_b;
|
2010-09-06 17:00:57 -03:00
|
|
|
|
2011-10-28 15:52:50 -03:00
|
|
|
// State machine state
|
2012-08-17 03:19:44 -03:00
|
|
|
uint8_t _step;
|
|
|
|
uint8_t _payload_counter;
|
2010-09-06 17:00:57 -03:00
|
|
|
|
2011-10-28 15:52:50 -03:00
|
|
|
// Receive buffer
|
2013-05-09 07:04:36 -03:00
|
|
|
union PACKED {
|
2012-08-17 03:19:44 -03:00
|
|
|
diyd_mtk_msg msg;
|
2016-05-16 13:46:33 -03:00
|
|
|
uint8_t bytes[1];
|
2011-10-28 15:52:50 -03:00
|
|
|
} _buffer;
|
2010-09-06 17:00:57 -03:00
|
|
|
|
2011-10-28 15:52:50 -03:00
|
|
|
// Buffer parse & GPS state update
|
2012-08-17 03:19:44 -03:00
|
|
|
void _parse_gps();
|
2014-03-31 06:48:22 -03:00
|
|
|
|
2015-10-26 08:25:44 -03:00
|
|
|
static const char _initialisation_blob[];
|
2010-08-24 01:13:27 -03:00
|
|
|
};
|