Abstract base class for interfaces between sensors and computers. More...
#include <bosch_drivers_hardware_interface.hpp>
Public Member Functions | |
bosch_hardware_interface () | |
virtual std::string | getID ()=0 |
Return an identifier for this hardware interface. | |
virtual bool | initialize ()=0 |
Initialize the hardware interface. | |
virtual ssize_t | read (int device_address, interface_protocol protocol, int frequency, int *flags, uint8_t reg_address, uint8_t *data, size_t num_bytes)=0 |
Read a given number of bytes. | |
virtual bool | supportedProtocol (interface_protocol protocol)=0 |
Check if a communication protocol is supported by this hardware interface. | |
virtual ssize_t | write (int device_address, interface_protocol protocol, int frequency, int *flags, uint8_t reg_address, uint8_t *data, size_t num_bytes)=0 |
Write the provided data, as bytes. | |
virtual | ~bosch_hardware_interface () |
Abstract base class for interfaces between sensors and computers.
This abstract class provides the generic format so that devices and drivers can communicate over different physical hardware adapters. For example, if gumstix, Sub20, and Arduino all derive from this class, then a single sensor driver can be written independently of all. Concrete implementations of this class provide the actual commands to read and write from the specific hardware interface. Since most interfaces are 8-bit, we use the 8-bit byte as the fundamental unit or size. Commands ask for data in number of bytes.
Definition at line 60 of file bosch_drivers_hardware_interface.hpp.
Definition at line 66 of file bosch_drivers_hardware_interface.hpp.
virtual bosch_drivers_common::bosch_hardware_interface::~bosch_hardware_interface | ( | ) | [inline, virtual] |
Definition at line 68 of file bosch_drivers_hardware_interface.hpp.
virtual std::string bosch_drivers_common::bosch_hardware_interface::getID | ( | ) | [pure virtual] |
Return an identifier for this hardware interface.
This identifier should be able to uniquely identify this interface when multiple copies of this interface exist.
virtual bool bosch_drivers_common::bosch_hardware_interface::initialize | ( | ) | [pure virtual] |
Initialize the hardware interface.
Any initialization steps that need to be performed by the hardware interface and cannot be done in the constructor should be done here. Some things to configure include the clock/data polarity for SPI and the byte order: little endian or big endian.
virtual ssize_t bosch_drivers_common::bosch_hardware_interface::read | ( | int | device_address, |
interface_protocol | protocol, | ||
int | frequency, | ||
int * | flags, | ||
uint8_t | reg_address, | ||
uint8_t * | data, | ||
size_t | num_bytes | ||
) | [pure virtual] |
Read a given number of bytes.
Communication with a device requires reading from locations in that device's memory. This function retrieves a number of bytes starting at a known address in a device. If the particular device does not store measurements in memory then it needs to be properly configured in the initialize() function.
device_address | The starting register address in the device's memory. |
protocol | |
frequency | The protocol frequency |
flags | |
reg_address | The register address |
data | A pointer to the memory location in the host where the data will be stored. The user must make sure space is available. This data should be an array. |
num_bytes | The requested number of bytes to read from the device. |
device_address
is the chip select. If the device address is NULL_DEVICE
, then the hardware interface should read from the bus without changing any chip select lines. device_address
is the pin or port. virtual bool bosch_drivers_common::bosch_hardware_interface::supportedProtocol | ( | interface_protocol | protocol | ) | [pure virtual] |
Check if a communication protocol is supported by this hardware interface.
virtual ssize_t bosch_drivers_common::bosch_hardware_interface::write | ( | int | device_address, |
interface_protocol | protocol, | ||
int | frequency, | ||
int * | flags, | ||
uint8_t | reg_address, | ||
uint8_t * | data, | ||
size_t | num_bytes | ||
) | [pure virtual] |
Write the provided data, as bytes.
Communication with a device requires writing to locations in that device's memory. This function sends a number of bytes starting at a known address in a device. If the particular device does not store commands in memory then it needs to be properly configured in the initialize() function.
device_address | The starting register address in the device's memory. |
protocol | |
frequency | The protocol frequency |
flags | |
reg_address | The register address |
data | A pointer to the memory location in the host where the data will be stored. The user must make sure space is available. This data should be an array. |
num_bytes | The requested number of bytes to read from the device. |
num_bytes
is zero, then the hardware should just write the register as a single byte. In this case, the pointer data is irrelevant. This can be used to write single bytes. device_address
is the chip select. If the device address is NULL_DEVICE
, then the hardware interface should read from the bus without changing any chip select lines. device_address
is the pin or port.