AP_GPS_MTK19.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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, Craig Elder, DIYDrones.com
  16. //
  17. // GPS configuration : Custom protocol per "Customize Function Specification, 3D Robotics, v1.6, v1.7, v1.8, v1.9"
  18. //
  19. #pragma once
  20. #include "AP_GPS.h"
  21. #include "GPS_Backend.h"
  22. #include "AP_GPS_MTK_Common.h"
  23. #define MTK_GPS_REVISION_V16 16
  24. #define MTK_GPS_REVISION_V19 19
  25. class AP_GPS_MTK19 : public AP_GPS_Backend {
  26. public:
  27. AP_GPS_MTK19(AP_GPS &_gps, AP_GPS::GPS_State &_state, AP_HAL::UARTDriver *_port);
  28. bool read(void) override;
  29. static bool _detect(struct MTK19_detect_state &state, uint8_t data);
  30. const char *name() const override { return "MTK19"; }
  31. private:
  32. struct PACKED diyd_mtk_msg {
  33. int32_t latitude;
  34. int32_t longitude;
  35. int32_t altitude;
  36. int32_t ground_speed;
  37. int32_t ground_course;
  38. uint8_t satellites;
  39. uint8_t fix_type;
  40. uint32_t utc_date;
  41. uint32_t utc_time;
  42. uint16_t hdop;
  43. };
  44. enum diyd_mtk_fix_type {
  45. FIX_NONE = 1,
  46. FIX_2D = 2,
  47. FIX_3D = 3,
  48. FIX_2D_SBAS = 6,
  49. FIX_3D_SBAS = 7
  50. };
  51. enum diyd_mtk_protocol_bytes {
  52. PREAMBLE1_V16 = 0xd0,
  53. PREAMBLE1_V19 = 0xd1,
  54. PREAMBLE2 = 0xdd,
  55. };
  56. // Packet checksum accumulators
  57. uint8_t _ck_a;
  58. uint8_t _ck_b;
  59. // State machine state
  60. uint8_t _step;
  61. uint8_t _payload_counter;
  62. uint8_t _mtk_revision;
  63. uint8_t _fix_counter;
  64. // Receive buffer
  65. union {
  66. DEFINE_BYTE_ARRAY_METHODS
  67. diyd_mtk_msg msg;
  68. } _buffer;
  69. };