Line data Source code
1 : /* 2 : This program is free software: you can redistribute it and/or modify 3 : it under the terms of the GNU General Public License as published by 4 : the Free Software Foundation, either version 3 of the License, or 5 : (at your option) any later version. 6 : 7 : This program is distributed in the hope that it will be useful, 8 : but WITHOUT ANY WARRANTY; without even the implied warranty of 9 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 : GNU General Public License for more details. 11 : 12 : You should have received a copy of the GNU General Public License 13 : along with this program. If not, see <http://www.gnu.org/licenses/>. 14 : */ 15 : 16 : // 17 : // SiRF Binary GPS driver for ArduPilot and ArduPilotMega. 18 : // Code by Michael Smith. 19 : // 20 : #pragma once 21 : 22 : #include <AP_Common/AP_Common.h> 23 : #include <AP_HAL/AP_HAL.h> 24 : 25 : #include "AP_GPS.h" 26 : #include "GPS_Backend.h" 27 : 28 : #if AP_GPS_SIRF_ENABLED 29 : 30 : #define SIRF_SET_BINARY "$PSRF100,0,38400,8,1,0*3C\r\n" 31 : 32 : class AP_GPS_SIRF : public AP_GPS_Backend { 33 : public: 34 : AP_GPS_SIRF(AP_GPS &_gps, AP_GPS::Params &_params, AP_GPS::GPS_State &_state, AP_HAL::UARTDriver *_port); 35 : 36 : bool read() override; 37 : 38 : static bool _detect(struct SIRF_detect_state &state, uint8_t data); 39 : 40 0 : const char *name() const override { return "SIRF"; } 41 : 42 : private: 43 : struct PACKED sirf_geonav { 44 : uint16_t fix_invalid; 45 : uint16_t fix_type; 46 : uint16_t week; 47 : uint32_t time; 48 : uint16_t year; 49 : uint8_t month; 50 : uint8_t day; 51 : uint8_t hour; 52 : uint8_t minute; 53 : uint16_t second; 54 : uint32_t satellites_used; 55 : int32_t latitude; 56 : int32_t longitude; 57 : int32_t altitude_ellipsoid; 58 : int32_t altitude_msl; 59 : int8_t map_datum; 60 : int16_t ground_speed; 61 : int16_t ground_course; 62 : int16_t res1; 63 : int16_t climb_rate; 64 : uint16_t heading_rate; 65 : uint32_t horizontal_position_error; 66 : uint32_t vertical_position_error; 67 : uint32_t time_error; 68 : int16_t horizontal_velocity_error; 69 : int32_t clock_bias; 70 : uint32_t clock_bias_error; 71 : int32_t clock_drift; 72 : uint32_t clock_drift_error; 73 : uint32_t distance; 74 : uint16_t distance_error; 75 : uint16_t heading_error; 76 : uint8_t satellites; 77 : uint8_t hdop; 78 : uint8_t mode_info; 79 : }; 80 : enum sirf_protocol_bytes { 81 : PREAMBLE1 = 0xa0, 82 : PREAMBLE2 = 0xa2, 83 : POSTAMBLE1 = 0xb0, 84 : POSTAMBLE2 = 0xb3, 85 : MSG_GEONAV = 0x29 86 : }; 87 : enum sirf_fix_type { 88 : FIX_3D = 0x6, 89 : FIX_MASK = 0x7 90 : }; 91 : 92 : 93 : // State machine state 94 : uint8_t _step; 95 : uint16_t _checksum; 96 : bool _gather; 97 : uint16_t _payload_length; 98 : uint16_t _payload_counter; 99 : uint8_t _msg_id; 100 : 101 : // Message buffer 102 : union { 103 0 : DEFINE_BYTE_ARRAY_METHODS 104 : sirf_geonav nav; 105 : } _buffer; 106 : 107 : bool _parse_gps(void); 108 : void _accumulate(uint8_t val); 109 : 110 : static const uint8_t _initialisation_blob[]; 111 : }; 112 : #endif