AP_WindVane_NMEA.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. #pragma once
  14. #include "AP_WindVane_Backend.h"
  15. class AP_WindVane_NMEA : public AP_WindVane_Backend
  16. {
  17. public:
  18. // constructor
  19. AP_WindVane_NMEA(AP_WindVane &frontend);
  20. // initialization
  21. void init(const AP_SerialManager& serial_manager) override;
  22. // update state
  23. void update_direction() override;
  24. void update_speed() override;
  25. private:
  26. // pointer to serial uart
  27. AP_HAL::UARTDriver *uart = nullptr;
  28. // See if we can read in some data
  29. void update();
  30. // try and decode NMEA message
  31. bool decode(char c);
  32. // decode each term
  33. bool decode_latest_term();
  34. // convert from char to hex value for checksum
  35. int16_t char_to_hex(char a);
  36. // latest values read in
  37. float _speed_ms;
  38. float _wind_dir_deg;
  39. char _term[15]; // buffer for the current term within the current sentence
  40. uint8_t _term_offset; // offset within the _term buffer where the next character should be placed
  41. uint8_t _term_number; // term index within the current sentence
  42. uint8_t _checksum; // checksum accumulator
  43. bool _term_is_checksum; // current term is the checksum
  44. bool _sentence_valid; // is current sentence valid so far
  45. };