QuadroCopter  0.1.4
quadro::analog::LVMaxSonarEZ Class Reference

#include <LVMaxSonarEZ.h>

Inheritance diagram for quadro::analog::LVMaxSonarEZ:
quadro::analog::analogBase quadro::IDevice quadro::IDevice

Public Types

enum  deviceMode { Inches = 0, Cm = 1 }
 
enum  deviceStatus { On = 1, Off = 0, Error = 2 }
 
- Public Types inherited from quadro::analog::analogBase
enum  analogPort {
  PORT0 = 0, PORT1 = 1, PORT2 = 2, PORT3 = 3,
  PORT4 = 4, PORT5 = 5, PORT6 = 6
}
 

Public Member Functions

 LVMaxSonarEZ ()
 
int start ()
 
int stop ()
 
double getDistance ()
 Storage of the timer for the sensors main thread, based on the data rate of the sensor. More...
 
void setMode (deviceMode _mode)
 
int getStatus ()
 
void setStatus (deviceStatus _status)
 
- Public Member Functions inherited from quadro::analog::analogBase
 ~analogBase ()
 
 analogBase ()
 
int getCurrentReading ()
 
void setDevicePort (analogPort _AP)
 
- Public Member Functions inherited from quadro::IDevice
virtual ~IDevice ()
 

Public Attributes

__useconds_t dataTimer = SONIC_DATATIMER
 
deviceMode currentMode
 

Member Enumeration Documentation

Select a deviceMode, changes the returned distance value to the selected type.

Enumerator
Inches 
Cm 
75  {
76  Inches = 0,
77  Cm = 1
78  };
Definition: LVMaxSonarEZ.h:76
Definition: LVMaxSonarEZ.h:77

Stores the current deviceStatus for easy reference fro other objects

Enumerator
On 

Status On (thread is active)

Off 

Status Off (thread is disabled)

Error 

Status Error (thread is disabled)

83  {
84  On = 1,
85  Off = 0,
86  Error = 2
87  };
Status Off (thread is disabled)
Definition: LVMaxSonarEZ.h:85
Status Error (thread is disabled)
Definition: LVMaxSonarEZ.h:86
Status On (thread is active)
Definition: LVMaxSonarEZ.h:84

Constructor & Destructor Documentation

LVMaxSonarEZ::LVMaxSonarEZ ( )

Class constructor - by default this constructor sets the height mode to CM and the devices status to off.

See also
start() for initialising the sensors main thread.
24 {
25  //Set device startup settings
26  setMode( deviceMode::Cm );
28 }
Off
Status Off (thread is disabled)
Definition: LVMaxSonarEZ.h:91
void setMode(deviceMode _mode)
Definition: LVMaxSonarEZ.cpp:120
void setStatus(deviceStatus _status)
Definition: LVMaxSonarEZ.cpp:125

Member Function Documentation

double LVMaxSonarEZ::getDistance ( )

Storage of the timer for the sensors main thread, based on the data rate of the sensor.

This method provides access to the private calculate distance result.

Returns
double
136 {
137  return convertReadingToDistance( reading );
138 }
int LVMaxSonarEZ::getStatus ( )

getStatus returns the current status of the sensor

Returns
int
131 {
132  return currentStatus;
133 }
void LVMaxSonarEZ::setMode ( deviceMode  _mode)

setMode allows the mode of the sensor to be changed to one of the values set in deviceModes

Parameters
_mode
121 {
122  currentMode = _mode;
123 }
deviceMode currentMode
Definition: LVMaxSonarEZ.h:92
void LVMaxSonarEZ::setStatus ( deviceStatus  _status)

setStatus allows the status of the sensor to be changed to one of the values set in deviceStatus

Parameters
_status
126 {
127  currentStatus = _status;
128 }
int LVMaxSonarEZ::start ( )

start() - Allows the independent control to start the thread that updates the Sonic Sensor readings.

Parameters
none
Exceptions
analogSetupException
Returns
int deviceStatus : 1 = on, 0 = off or 2 = error
31 {
32 
33  //pthread_create doesn't throw an exception, only returns error codes - these are handled below.
34  threadRet = pthread_create( &threadHandle, NULL, LVMaxSonarEZ::runMainSensorUpdateThread, this );
35 
36  //Thread returned 0 (Success Code)
37  if ( threadRet != 0 ) {
38  //The sonic sensor thread failed, set the status to "Error" and throw an appropriate exception.
40  if ( threadRet == EAGAIN ) {
41  //Failed because of resource unavailability, try once more and then throw an exception on failure
42  threadRet = pthread_create( &threadHandle, NULL, LVMaxSonarEZ::runMainSensorUpdateThread, this );
43  if ( threadRet != 0 ) {
44  throw new analogSetupException(
45  "(LVMaxSonarEZ) " + analog::THREAD_FATAL + " : errorNumber = "
46  + to_string( threadRet ) );
47  }
48  }
49  else if ( threadRet == EPERM ) {
50  //Thread creation failed because of invalid permissions on the system to create threads.
51  throw new analogSetupException(
52  "(LVMaxSonarEZ) " + analog::THREAD_PERMISSIONS + " : errorNumber = " + to_string( threadRet ) );
53  }
54  else if ( threadRet == EINVAL ) {
55  //Thread creation failed because the argument used is invalid.
56  throw new analogSetupException(
57  "(LVMaxSonarEZ) " + analog::THREAD_INVALID_ARG + " : errorNumber = " + to_string( threadRet ) );
58  }
59  else {
60  //An unknown error occurred - unknown error code.
61  throw new analogSetupException(
62  "(LVMaxSonarEZ) " + analog::THREAD_UNKNOWN + " : errorNumber = " + to_string( threadRet ) );
63  }
64  }
65 
66  //The thread started correctly, so set the status of the Sonic Sensor to "On".
68 
69  //return the device status - realistically it should always be "On" if we get this far...
70  return getStatus();
71 
72 }
Definition: analogSetupException.h:40
const string THREAD_INVALID_ARG
Definition: analogSetupException.h:35
Error
Status Error (thread is disabled)
Definition: LVMaxSonarEZ.h:92
const string THREAD_FATAL
Definition: analogSetupException.h:33
int getStatus()
Definition: LVMaxSonarEZ.cpp:130
On
Status On (thread is active)
Definition: LVMaxSonarEZ.h:90
const string THREAD_PERMISSIONS
Definition: analogSetupException.h:34
const string THREAD_UNKNOWN
Definition: analogSetupException.h:32
void setStatus(deviceStatus _status)
Definition: LVMaxSonarEZ.cpp:125
int LVMaxSonarEZ::stop ( )

stop() - Allows the independent control to stop the current thread.

Parameters
none
Exceptions
analogRuntimeException
Returns
enum deviceStatus : 1 = on, 0 = off or 2 = error
75 {
76  //pthread_cancel doesn't throw an exception, only returns error codes - these are handled below.
77  threadRet = pthread_cancel( threadHandle );
78 
79  if ( threadRet != 0 ) {
80  //The sonic sensor thread cancellation failed, set the status to "Error" and throw an appropriate exception.
82  if ( threadRet == ESRCH ) {
83  //Unable to locate process to cancel.
85  }
86  else {
87  //An unknown error occurred - unknown error code.
89  }
90  }
91 
92  //The thread was cancelled successfully - set the device status to "Off".
94 
95  return getStatus();
96 
97 }
Off
Status Off (thread is disabled)
Definition: LVMaxSonarEZ.h:91
const string THREAD_CANCELLATION_FAILURE
Definition: analogRuntimeException.h:16
Error
Status Error (thread is disabled)
Definition: LVMaxSonarEZ.h:92
Definition: analogRuntimeException.h:21
const string THREAD_CANCELLATION_UNKNOWN
Definition: analogRuntimeException.h:17
int getStatus()
Definition: LVMaxSonarEZ.cpp:130
void setStatus(deviceStatus _status)
Definition: LVMaxSonarEZ.cpp:125

Member Data Documentation

deviceMode quadro::analog::LVMaxSonarEZ::currentMode
__useconds_t quadro::analog::LVMaxSonarEZ::dataTimer = SONIC_DATATIMER

The documentation for this class was generated from the following files:
  • /Users/michaelbrookes/ClionProjects/Quadro/lib/analog/devices/LVMaxSonarEZ/LVMaxSonarEZ.h
  • /Users/michaelbrookes/ClionProjects/Quadro/lib/analog/devices/LVMaxSonarEZ/LVMaxSonarEZ.cpp