PX4 Firmware
PX4 Autopilot Software http://px4.io
SF0X Class Reference
Inheritance diagram for SF0X:
Collaboration diagram for SF0X:

Public Member Functions

 SF0X (const char *port=SF0X_DEFAULT_PORT, uint8_t rotation=distance_sensor_s::ROTATION_DOWNWARD_FACING)
 
virtual ~SF0X ()
 
virtual int init () override
 
virtual ssize_t read (device::file_t *filp, char *buffer, size_t buflen) override
 Perform a read from the device. More...
 
virtual int ioctl (device::file_t *filp, int cmd, unsigned long arg) override
 Perform an ioctl operation on the device. More...
 
void print_info ()
 Diagnostics - print some basic information about the driver. More...
 
- Public Member Functions inherited from cdev::CDev
 CDev (const char *devname)
 Constructor. More...
 
 CDev (const CDev &)=delete
 
CDevoperator= (const CDev &)=delete
 
 CDev (CDev &&)=delete
 
CDevoperator= (CDev &&)=delete
 
virtual ~CDev ()
 
virtual int open (file_t *filep)
 Handle an open of the device. More...
 
virtual int close (file_t *filep)
 Handle a close of the device. More...
 
virtual ssize_t write (file_t *filep, const char *buffer, size_t buflen)
 Perform a write to the device. More...
 
virtual off_t seek (file_t *filep, off_t offset, int whence)
 Perform a logical seek operation on the device. More...
 
virtual int poll (file_t *filep, px4_pollfd_struct_t *fds, bool setup)
 Perform a poll setup/teardown operation. More...
 
const char * get_devname () const
 Get the device name. More...
 

Private Member Functions

void start ()
 Initialise the automatic measurement state machine and start it. More...
 
void stop ()
 Stop the automatic measurement state machine. More...
 
void set_minimum_distance (float min)
 Set the min and max distance thresholds if you want the end points of the sensors range to be brought in at all, otherwise it will use the defaults SF0X_MIN_DISTANCE and SF0X_MAX_DISTANCE. More...
 
void set_maximum_distance (float max)
 
float get_minimum_distance ()
 
float get_maximum_distance ()
 
void Run () override
 Perform a poll cycle; collect from the previous measurement and start a new one. More...
 
int measure ()
 
int collect ()
 

Private Attributes

char _port [20]
 
uint8_t _rotation
 
float _min_distance
 
float _max_distance
 
int _conversion_interval
 
ringbuffer::RingBuffer * _reports
 
int _measure_interval
 
bool _collect_phase
 
int _fd
 
char _linebuf [10]
 
unsigned _linebuf_index
 
enum SF0X_PARSE_STATE _parse_state
 
hrt_abstime _last_read
 
int _class_instance
 
int _orb_class_instance
 
orb_advert_t _distance_sensor_topic
 
unsigned _consecutive_fail_count
 
perf_counter_t _sample_perf
 
perf_counter_t _comms_errors
 

Additional Inherited Members

- Protected Member Functions inherited from cdev::CDev
virtual pollevent_t poll_state (file_t *filep)
 Check the current state of the device for poll events from the perspective of the file. More...
 
virtual void poll_notify (pollevent_t events)
 Report new poll events. More...
 
virtual void poll_notify_one (px4_pollfd_struct_t *fds, pollevent_t events)
 Internal implementation of poll_notify. More...
 
virtual int open_first (file_t *filep)
 Notification of the first open. More...
 
virtual int close_last (file_t *filep)
 Notification of the last close. More...
 
virtual int register_class_devname (const char *class_devname)
 Register a class device name, automatically adding device class instance suffix if need be. More...
 
virtual int unregister_class_devname (const char *class_devname, unsigned class_instance)
 Register a class device name, automatically adding device class instance suffix if need be. More...
 
void lock ()
 Take the driver lock. More...
 
void unlock ()
 Release the driver lock. More...
 
int unregister_driver_and_memory ()
 First, unregisters the driver. More...
 
- Protected Attributes inherited from cdev::CDev
px4_sem_t _lock
 lock to protect access to all class members (also for derived classes) More...
 
- Static Protected Attributes inherited from cdev::CDev
static const px4_file_operations_t fops = {}
 Pointer to the default cdev file operations table; useful for registering clone devices etc. More...
 

Detailed Description

Definition at line 80 of file sf0x.cpp.

Constructor & Destructor Documentation

◆ SF0X()

SF0X::SF0X ( const char *  port = SF0X_DEFAULT_PORT,
uint8_t  rotation = distance_sensor_s::ROTATION_DOWNWARD_FACING 
)

Definition at line 159 of file sf0x.cpp.

References _port.

Referenced by sf0x::start().

Here is the caller graph for this function:

◆ ~SF0X()

SF0X::~SF0X ( )
virtual

Definition at line 188 of file sf0x.cpp.

References _class_instance, _comms_errors, _reports, _sample_perf, perf_free(), RANGE_FINDER_BASE_DEVICE_PATH, stop(), and cdev::CDev::unregister_class_devname().

Here is the call graph for this function:

Member Function Documentation

◆ collect()

int SF0X::collect ( )
private

Definition at line 454 of file sf0x.cpp.

References _comms_errors, _conversion_interval, _distance_sensor_topic, _fd, _last_read, _linebuf, _linebuf_index, _parse_state, _reports, _rotation, _sample_perf, distance_sensor_s::current_distance, get_maximum_distance(), get_minimum_distance(), hrt_absolute_time(), hrt_elapsed_time(), distance_sensor_s::id, distance_sensor_s::max_distance, distance_sensor_s::min_distance, OK, ORB_ID, orb_publish(), distance_sensor_s::orientation, perf_begin(), perf_count(), perf_end(), cdev::CDev::poll_notify(), read(), sf0x_parser(), distance_sensor_s::signal_quality, distance_sensor_s::timestamp, distance_sensor_s::type, and distance_sensor_s::variance.

Referenced by read(), and Run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_maximum_distance()

float SF0X::get_maximum_distance ( )
private

Definition at line 305 of file sf0x.cpp.

References _max_distance.

Referenced by collect().

Here is the caller graph for this function:

◆ get_minimum_distance()

float SF0X::get_minimum_distance ( )
private

Definition at line 299 of file sf0x.cpp.

References _min_distance.

Referenced by collect().

Here is the caller graph for this function:

◆ init()

int SF0X::init ( )
overridevirtual

Reimplemented from cdev::CDev.

Definition at line 207 of file sf0x.cpp.

References _class_instance, _conversion_interval, _distance_sensor_topic, _max_distance, _min_distance, _orb_class_instance, _reports, ToneAlarmInterface::init(), OK, orb_advertise_multi(), ORB_ID, ORB_PRIO_HIGH, param_find(), param_get(), RANGE_FINDER_BASE_DEVICE_PATH, and cdev::CDev::register_class_devname().

Referenced by sf0x::start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ioctl()

int SF0X::ioctl ( device::file_t filep,
int  cmd,
unsigned long  arg 
)
overridevirtual

Perform an ioctl operation on the device.

The default implementation handles DIOC_GETPRIV, and otherwise returns -ENOTTY. Subclasses should call the default implementation for any command they do not handle themselves.

Parameters
filepPointer to the NuttX file structure.
cmdThe ioctl command value.
argThe ioctl argument value.
Returns
OK on success, or -errno otherwise.

Reimplemented from cdev::CDev.

Definition at line 311 of file sf0x.cpp.

References _conversion_interval, _measure_interval, OK, SENSOR_POLLRATE_DEFAULT, SENSORIOCSPOLLRATE, and start().

Referenced by sf0x::reset(), sf0x::start(), and sf0x::test().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ measure()

int SF0X::measure ( )
private

Definition at line 432 of file sf0x.cpp.

References _comms_errors, _fd, OK, perf_count(), SF0X_TAKE_RANGE_REG, and cdev::CDev::write().

Referenced by read(), and Run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_info()

void SF0X::print_info ( )

Diagnostics - print some basic information about the driver.

Definition at line 659 of file sf0x.cpp.

References _comms_errors, _measure_interval, _reports, _sample_perf, and perf_print_counter().

Referenced by sf0x::info().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read()

ssize_t SF0X::read ( device::file_t filep,
char *  buffer,
size_t  buflen 
)
overridevirtual

Perform a read from the device.

The default implementation returns -ENOSYS.

Parameters
filepPointer to the NuttX file structure.
bufferPointer to the buffer into which data should be placed.
buflenThe number of bytes to be read.
Returns
The number of bytes read or -errno otherwise.

Reimplemented from cdev::CDev.

Definition at line 372 of file sf0x.cpp.

References _conversion_interval, _measure_interval, _reports, collect(), measure(), and OK.

Referenced by collect(), and sf0x::test().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Run()

void SF0X::Run ( )
overrideprivate

Perform a poll cycle; collect from the previous measurement and start a new one.

Definition at line 547 of file sf0x.cpp.

References _collect_phase, _consecutive_fail_count, _conversion_interval, _fd, _measure_interval, _port, collect(), hrt_absolute_time(), measure(), OK, cdev::CDev::open(), param_find(), param_get(), and start().

Here is the call graph for this function:

◆ set_maximum_distance()

void SF0X::set_maximum_distance ( float  max)
private

Definition at line 293 of file sf0x.cpp.

References _max_distance, and math::max().

Here is the call graph for this function:

◆ set_minimum_distance()

void SF0X::set_minimum_distance ( float  min)
private

Set the min and max distance thresholds if you want the end points of the sensors range to be brought in at all, otherwise it will use the defaults SF0X_MIN_DISTANCE and SF0X_MAX_DISTANCE.

Definition at line 287 of file sf0x.cpp.

References _min_distance, and math::min().

Here is the call graph for this function:

◆ start()

void SF0X::start ( )
private

Initialise the automatic measurement state machine and start it.

Note
This function is called at open and error time. It might make sense to make it more aggressive about resetting the bus in case of errors.

Definition at line 530 of file sf0x.cpp.

References _collect_phase, and _reports.

Referenced by ioctl(), and Run().

Here is the caller graph for this function:

◆ stop()

void SF0X::stop ( )
private

Stop the automatic measurement state machine.

Definition at line 541 of file sf0x.cpp.

Referenced by ~SF0X().

Here is the caller graph for this function:

Member Data Documentation

◆ _class_instance

int SF0X::_class_instance
private

Definition at line 111 of file sf0x.cpp.

Referenced by init(), and ~SF0X().

◆ _collect_phase

bool SF0X::_collect_phase
private

Definition at line 104 of file sf0x.cpp.

Referenced by Run(), and start().

◆ _comms_errors

perf_counter_t SF0X::_comms_errors
private

Definition at line 119 of file sf0x.cpp.

Referenced by collect(), measure(), print_info(), and ~SF0X().

◆ _consecutive_fail_count

unsigned SF0X::_consecutive_fail_count
private

Definition at line 116 of file sf0x.cpp.

Referenced by Run().

◆ _conversion_interval

int SF0X::_conversion_interval
private

Definition at line 101 of file sf0x.cpp.

Referenced by collect(), init(), ioctl(), read(), and Run().

◆ _distance_sensor_topic

orb_advert_t SF0X::_distance_sensor_topic
private

Definition at line 114 of file sf0x.cpp.

Referenced by collect(), and init().

◆ _fd

int SF0X::_fd
private

Definition at line 105 of file sf0x.cpp.

Referenced by collect(), measure(), and Run().

◆ _last_read

hrt_abstime SF0X::_last_read
private

Definition at line 109 of file sf0x.cpp.

Referenced by collect().

◆ _linebuf

char SF0X::_linebuf[10]
private

Definition at line 106 of file sf0x.cpp.

Referenced by collect().

◆ _linebuf_index

unsigned SF0X::_linebuf_index
private

Definition at line 107 of file sf0x.cpp.

Referenced by collect().

◆ _max_distance

float SF0X::_max_distance
private

Definition at line 100 of file sf0x.cpp.

Referenced by get_maximum_distance(), init(), and set_maximum_distance().

◆ _measure_interval

int SF0X::_measure_interval
private

Definition at line 103 of file sf0x.cpp.

Referenced by ioctl(), print_info(), read(), and Run().

◆ _min_distance

float SF0X::_min_distance
private

Definition at line 99 of file sf0x.cpp.

Referenced by get_minimum_distance(), init(), and set_minimum_distance().

◆ _orb_class_instance

int SF0X::_orb_class_instance
private

Definition at line 112 of file sf0x.cpp.

Referenced by init().

◆ _parse_state

enum SF0X_PARSE_STATE SF0X::_parse_state
private

Definition at line 108 of file sf0x.cpp.

Referenced by collect().

◆ _port

char SF0X::_port[20]
private

Definition at line 97 of file sf0x.cpp.

Referenced by Run(), and SF0X().

◆ _reports

ringbuffer::RingBuffer* SF0X::_reports
private

Definition at line 102 of file sf0x.cpp.

Referenced by collect(), init(), print_info(), read(), start(), and ~SF0X().

◆ _rotation

uint8_t SF0X::_rotation
private

Definition at line 98 of file sf0x.cpp.

Referenced by collect().

◆ _sample_perf

perf_counter_t SF0X::_sample_perf
private

Definition at line 118 of file sf0x.cpp.

Referenced by collect(), print_info(), and ~SF0X().


The documentation for this class was generated from the following file: