AP_GPS_MTK.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. //
  14. // DIYDrones Custom Mediatek GPS driver for ArduPilot and ArduPilotMega.
  15. // Code by Michael Smith, Jordi Munoz and Jose Julio, DIYDrones.com
  16. //
  17. // GPS configuration : Custom protocol per "DIYDrones Custom Binary Sentence Specification V1.1"
  18. //
  19. // Note - see AP_GPS_MTK16.h for firmware 1.6 and later.
  20. //
  21. #pragma once
  22. #include "AP_GPS.h"
  23. #include "GPS_Backend.h"
  24. #include "AP_GPS_MTK_Common.h"
  25. class AP_GPS_MTK : public AP_GPS_Backend {
  26. public:
  27. AP_GPS_MTK(AP_GPS &_gps, AP_GPS::GPS_State &_state, AP_HAL::UARTDriver *_port);
  28. bool read(void) override;
  29. static bool _detect(struct MTK_detect_state &state, uint8_t data);
  30. static void send_init_blob(uint8_t instance, AP_GPS &gps);
  31. const char *name() const override { return "MTK"; }
  32. private:
  33. struct PACKED diyd_mtk_msg {
  34. int32_t latitude;
  35. int32_t longitude;
  36. int32_t altitude;
  37. int32_t ground_speed;
  38. int32_t ground_course;
  39. uint8_t satellites;
  40. uint8_t fix_type;
  41. uint32_t utc_time;
  42. };
  43. enum diyd_mtk_fix_type {
  44. FIX_NONE = 1,
  45. FIX_2D = 2,
  46. FIX_3D = 3
  47. };
  48. enum diyd_mtk_protocol_bytes {
  49. PREAMBLE1 = 0xb5,
  50. PREAMBLE2 = 0x62,
  51. MESSAGE_CLASS = 1,
  52. MESSAGE_ID = 5
  53. };
  54. // Packet checksum accumulators
  55. uint8_t _ck_a;
  56. uint8_t _ck_b;
  57. // State machine state
  58. uint8_t _step;
  59. uint8_t _payload_counter;
  60. // Receive buffer
  61. union PACKED {
  62. DEFINE_BYTE_ARRAY_METHODS
  63. diyd_mtk_msg msg;
  64. } _buffer;
  65. // Buffer parse & GPS state update
  66. void _parse_gps();
  67. static const char _initialisation_blob[];
  68. };