2019-11-01 03:11:59 -03:00
|
|
|
#pragma once
|
|
|
|
|
2019-11-10 22:47:38 -04:00
|
|
|
#include "AP_RangeFinder_Backend.h"
|
2019-11-01 03:11:59 -03:00
|
|
|
|
|
|
|
class AP_RangeFinder_Backend_Serial : public AP_RangeFinder_Backend
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// constructor
|
|
|
|
AP_RangeFinder_Backend_Serial(RangeFinder::RangeFinder_State &_state,
|
2021-06-04 18:36:24 -03:00
|
|
|
AP_RangeFinder_Params &_params);
|
2019-11-01 03:11:59 -03:00
|
|
|
|
2021-06-04 18:36:24 -03:00
|
|
|
void init_serial(uint8_t serial_instance) override;
|
2019-11-01 03:11:59 -03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2019-11-01 07:10:57 -03:00
|
|
|
// baudrate used during object construction:
|
|
|
|
virtual uint32_t initial_baudrate(uint8_t serial_instance) const;
|
|
|
|
|
2019-11-01 07:35:23 -03:00
|
|
|
// the value 0 is special to the UARTDriver - it's "use default"
|
|
|
|
virtual uint16_t rx_bufsize() const { return 0; }
|
|
|
|
virtual uint16_t tx_bufsize() const { return 0; }
|
|
|
|
|
2019-11-01 03:11:59 -03:00
|
|
|
AP_HAL::UARTDriver *uart = nullptr;
|
2019-11-01 07:59:50 -03:00
|
|
|
|
|
|
|
// update state; not all backends call this!
|
|
|
|
virtual void update(void) override;
|
|
|
|
|
|
|
|
// it is essential that anyone relying on the base-class update to
|
|
|
|
// implement this:
|
2021-10-18 02:45:33 -03:00
|
|
|
virtual bool get_reading(float &reading_m) = 0;
|
2019-11-01 08:00:04 -03:00
|
|
|
|
2023-11-15 00:07:34 -04:00
|
|
|
// returns 0-100 or -1. This virtual method is for
|
|
|
|
// serial drivers and is a companion to the previous method get_reading().
|
|
|
|
// Like get_reading() this method is called in the base-class update() method.
|
|
|
|
virtual int8_t get_signal_quality_pct() const WARN_IF_UNUSED
|
|
|
|
{ return RangeFinder::SIGNAL_QUALITY_UNKNOWN; }
|
|
|
|
|
2019-11-01 08:00:04 -03:00
|
|
|
// maximum time between readings before we change state to NoData:
|
|
|
|
virtual uint16_t read_timeout_ms() const { return 200; }
|
2019-11-01 03:11:59 -03:00
|
|
|
};
|