APM:Libraries
AP_RangeFinder_NMEA.h
Go to the documentation of this file.
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 #pragma once
17 
18 #include "RangeFinder.h"
19 #include "RangeFinder_Backend.h"
20 
22 {
23 
24 public:
25  // constructor
28  uint8_t serial_instance);
29 
30  // static detection function
31  static bool detect(AP_SerialManager &serial_manager, uint8_t serial_instance);
32 
33  // update state
34  void update(void) override;
35 
36 protected:
37 
38  virtual MAV_DISTANCE_SENSOR _get_mav_distance_sensor_type() const override {
39  return MAV_DISTANCE_SENSOR_ULTRASOUND;
40  }
41 
42 private:
43 
45  enum sentence_types : uint8_t {
49  };
50 
51  // get a reading
52  bool get_reading(uint16_t &reading_cm);
53 
54  // add a single character to the buffer and attempt to decode
55  // returns true if a complete sentence was successfully decoded
56  // distance should be pulled directly from _distance_m member
57  bool decode(char c);
58 
59  // decode the just-completed term
60  // returns true if new sentence has just passed checksum test and is validated
61  bool decode_latest_term();
62 
63  // return the numeric value of an ascii hex character
64  static int16_t char_to_hex(char a);
65 
66  AP_HAL::UARTDriver *uart = nullptr; // pointer to serial uart
67  uint32_t _last_reading_ms; // system time of last successful reading
68 
69  // message decoding related members
70  char _term[15]; // buffer for the current term within the current sentence
71  uint8_t _term_offset; // offset within the _term buffer where the next character should be placed
72  uint8_t _term_number; // term index within the current sentence
73  float _distance_m; // distance in meters parsed from a term, -1 if no distance
74  uint8_t _checksum; // checksum accumulator
75  bool _term_is_checksum; // current term is the checksum
76  sentence_types _sentence_type; // the sentence type currently being processed
77 };
static AP_SerialManager serial_manager
Definition: AHRS_Test.cpp:24
sentence_types
enum for handled messages
void update(void) override
sentence_types _sentence_type
bool get_reading(uint16_t &reading_cm)
static int16_t char_to_hex(char a)
virtual MAV_DISTANCE_SENSOR _get_mav_distance_sensor_type() const override
AP_HAL::UARTDriver * uart
AP_RangeFinder_NMEA(RangeFinder::RangeFinder_State &_state, AP_SerialManager &serial_manager, uint8_t serial_instance)
static bool detect(AP_SerialManager &serial_manager, uint8_t serial_instance)