2016-02-17 21:25:44 -04:00
|
|
|
#pragma once
|
2015-09-07 02:32:06 -03:00
|
|
|
|
2019-11-10 22:47:38 -04:00
|
|
|
#include "AP_RangeFinder.h"
|
|
|
|
#include "AP_RangeFinder_Backend_Serial.h"
|
2015-09-07 02:32:06 -03:00
|
|
|
|
2019-11-01 03:12:26 -03:00
|
|
|
class AP_RangeFinder_LightWareSerial : public AP_RangeFinder_Backend_Serial
|
2015-09-07 02:32:06 -03:00
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2019-11-01 03:12:26 -03:00
|
|
|
using AP_RangeFinder_Backend_Serial::AP_RangeFinder_Backend_Serial;
|
2015-09-07 02:32:06 -03:00
|
|
|
|
2017-08-08 04:32:53 -03:00
|
|
|
protected:
|
|
|
|
|
2020-01-13 01:48:07 -04:00
|
|
|
MAV_DISTANCE_SENSOR _get_mav_distance_sensor_type() const override {
|
2017-08-08 04:32:53 -03:00
|
|
|
return MAV_DISTANCE_SENSOR_LASER;
|
|
|
|
}
|
|
|
|
|
2015-09-07 02:32:06 -03:00
|
|
|
private:
|
|
|
|
// get a reading
|
2019-11-01 07:59:50 -03:00
|
|
|
bool get_reading(uint16_t &reading_cm) override;
|
2015-09-07 02:32:06 -03:00
|
|
|
|
2020-06-29 08:16:54 -03:00
|
|
|
char linebuf[10]; // legacy protocol buffer
|
2020-06-30 09:06:46 -03:00
|
|
|
uint8_t linebuf_len; // legacy protocol buffer length
|
2020-06-29 08:16:54 -03:00
|
|
|
uint32_t last_init_ms; // init time used to switch lw20 to serial mode
|
|
|
|
uint8_t high_byte; // binary protocol high byte
|
|
|
|
bool high_byte_received; // true if high byte has been received
|
|
|
|
|
|
|
|
// automatic protocol decision variables
|
|
|
|
enum class ProtocolState {
|
2020-07-01 02:51:45 -03:00
|
|
|
UNKNOWN, // the protocol used is not yet known
|
|
|
|
LEGACY, // legacy protocol, distances are sent as strings
|
|
|
|
BINARY // binary protocol, distances are sent using two bytes
|
2020-06-29 08:16:54 -03:00
|
|
|
} protocol_state;
|
|
|
|
uint8_t legacy_valid_count;
|
|
|
|
uint8_t binary_valid_count;
|
2015-09-07 02:32:06 -03:00
|
|
|
};
|