2018-05-14 02:03:08 -03:00
|
|
|
/*
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2023-07-06 01:25:14 -03:00
|
|
|
#include "AP_RangeFinder_config.h"
|
2022-03-12 06:37:29 -04:00
|
|
|
|
|
|
|
#if AP_RANGEFINDER_NMEA_ENABLED
|
|
|
|
|
2023-07-06 01:25:14 -03:00
|
|
|
#include "AP_RangeFinder.h"
|
|
|
|
#include "AP_RangeFinder_Backend_Serial.h"
|
|
|
|
|
2019-11-01 03:19:39 -03:00
|
|
|
class AP_RangeFinder_NMEA : public AP_RangeFinder_Backend_Serial
|
2018-05-14 02:03:08 -03:00
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2022-06-22 08:03:22 -03:00
|
|
|
static AP_RangeFinder_Backend_Serial *create(
|
|
|
|
RangeFinder::RangeFinder_State &_state,
|
|
|
|
AP_RangeFinder_Params &_params) {
|
2024-05-26 22:24:14 -03:00
|
|
|
return NEW_NOTHROW AP_RangeFinder_NMEA(_state, _params);
|
2022-06-22 08:03:22 -03:00
|
|
|
}
|
2018-05-14 02:03:08 -03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2020-01-13 01:48:07 -04:00
|
|
|
MAV_DISTANCE_SENSOR _get_mav_distance_sensor_type() const override {
|
2018-05-14 02:03:08 -03:00
|
|
|
return MAV_DISTANCE_SENSOR_ULTRASOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2022-06-22 08:03:22 -03:00
|
|
|
using AP_RangeFinder_Backend_Serial::AP_RangeFinder_Backend_Serial;
|
|
|
|
|
2018-05-14 02:03:08 -03:00
|
|
|
/// enum for handled messages
|
|
|
|
enum sentence_types : uint8_t {
|
|
|
|
SONAR_UNKNOWN = 0,
|
|
|
|
SONAR_DBT,
|
2021-04-13 05:07:06 -03:00
|
|
|
SONAR_DPT,
|
2021-10-15 09:04:22 -03:00
|
|
|
SONAR_MTW, // mean water temperature
|
|
|
|
SONAR_HDED, // hondex custom sonar message
|
2018-05-14 02:03:08 -03:00
|
|
|
};
|
|
|
|
|
2021-04-13 05:07:06 -03:00
|
|
|
// get a distance reading
|
2021-10-18 02:45:33 -03:00
|
|
|
bool get_reading(float &reading_m) override;
|
2018-05-14 02:03:08 -03:00
|
|
|
|
2021-04-13 05:07:06 -03:00
|
|
|
// get temperature reading in C. returns true on success and populates temp argument
|
2021-09-29 14:45:33 -03:00
|
|
|
bool get_temp(float &temp) const override;
|
2021-04-13 05:07:06 -03:00
|
|
|
|
2019-11-01 08:00:04 -03:00
|
|
|
uint16_t read_timeout_ms() const override { return 3000; }
|
|
|
|
|
2018-05-14 02:03:08 -03:00
|
|
|
// add a single character to the buffer and attempt to decode
|
2021-04-13 05:07:06 -03:00
|
|
|
// returns true if a distance was successfully decoded
|
2018-05-14 02:03:08 -03:00
|
|
|
// distance should be pulled directly from _distance_m member
|
|
|
|
bool decode(char c);
|
|
|
|
|
|
|
|
// decode the just-completed term
|
|
|
|
// returns true if new sentence has just passed checksum test and is validated
|
|
|
|
bool decode_latest_term();
|
|
|
|
|
|
|
|
// message decoding related members
|
|
|
|
char _term[15]; // buffer for the current term within the current sentence
|
|
|
|
uint8_t _term_offset; // offset within the _term buffer where the next character should be placed
|
|
|
|
uint8_t _term_number; // term index within the current sentence
|
2020-07-20 19:33:39 -03:00
|
|
|
float _distance_m = -1.0f; // distance in meters parsed from a term, -1 if no distance
|
2021-04-13 05:07:06 -03:00
|
|
|
float _temp_unvalidated; // unvalidated temperature in C (may have failed checksum)
|
|
|
|
float _temp; // temperature in C (validated)
|
|
|
|
uint32_t _temp_readtime_ms; // system time we last read a validated temperature, 0 if never read
|
2018-05-14 02:03:08 -03:00
|
|
|
uint8_t _checksum; // checksum accumulator
|
|
|
|
bool _term_is_checksum; // current term is the checksum
|
|
|
|
sentence_types _sentence_type; // the sentence type currently being processed
|
2020-07-20 19:33:39 -03:00
|
|
|
bool _sentence_done; // true if this sentence has already been decoded
|
2018-05-14 02:03:08 -03:00
|
|
|
};
|
2022-03-12 06:37:29 -04:00
|
|
|
|
|
|
|
#endif // AP_RANGEFINDER_NMEA_ENABLED
|