mraa  2.0.0
Low Level Skeleton Library for Communication on GNU/Linux platforms
Public Member Functions
UartOW Class Reference

Detailed Description

This file defines the UartOW (UART to Dallas 1-wire) interface for libmraa

mraa::UartOW uart(0);
// Reset the ow bus and see if anything is present
if ((status = uart.reset()) == mraa::SUCCESS) {
std::cout << "Reset succeeded, device(s) detected!" << std::endl;
} else {
std::cout << "Reset failed, returned " << int(status) << ". No devices on bus?" << std::endl;
return EXIT_FAILURE;
}
std::cout << "Looking for devices..." << std::endl;
// start the search from scratch
id = uart.search(true);
if (id.empty()) {
std::cout << "No devices detected." << std::endl;
return EXIT_FAILURE;
}
while (!id.empty()) {
// hack so we don't need to cast each element of the romcode
// for printf purposes
ptr = (uint8_t*) id.data();
// The first byte (0) is the device type (family) code.
// The last byte (7) is the rom code CRC value. The
// intervening bytes are the unique 48 bit device ID.
std::cout << "Device %02d Type 0x%02x ID %02x%02x%02x%02x%02x%02x CRC 0x%02x" << count << ptr[0]
<< ptr[6] << ptr[5] << ptr[4] << ptr[3] << ptr[2] << ptr[1] << ptr[7] << std::endl;
count++;
// continue the search with start argument set to false
id = uart.search(false);
}
std::cout << "Exiting..." << std::endl;

Public Member Functions

 UartOW (int uart)
 
 UartOW (std::string path)
 
 UartOW (void *uart_ow_context)
 
 ~UartOW ()
 
std::string getDevicePath ()
 
uint8_t readByte ()
 
uint8_t writeByte (uint8_t byte)
 
bool writeBit (bool bit)
 
mraa::Result reset ()
 
mraa::Result search (bool start, uint8_t *id)
 
std::string search (bool start)
 
mraa::Result command (uint8_t command, uint8_t *id)
 
mraa::Result command (uint8_t command, std::string id)
 
uint8_t crc8 (uint8_t *buffer, uint16_t length)
 
uint8_t crc8 (std::string buffer)
 

Constructor & Destructor Documentation

UartOW ( int  uart)
inline

UartOW Constructor, takes a pin number which will map directly to the linux uart number, this 'enables' the uart, nothing more

Parameters
uartthe index of the uart to use
Exceptions
std::invalid_argumentin case of error

Here is the call graph for this function:

UartOW ( std::string  path)
inline

UartOW Constructor, takes a string to the path of the serial interface that is needed.

Parameters
paththe file path for the UART to use
Exceptions
std::invalid_argumentin case of error

Here is the call graph for this function:

UartOW ( void *  uart_ow_context)
inline

UartOW Constructor, takes a pointer to the UartOW context and initialises the UartOW class

Parameters
uart_ow_contextvoid * to a UartOW context
~UartOW ( )
inline

Uart destructor

Here is the call graph for this function:

Member Function Documentation

std::string getDevicePath ( )
inline

Get string with tty device path within Linux For example. Could point to "/dev/ttyS0"

Returns
char pointer of device path

Here is the call graph for this function:

uint8_t readByte ( )
inline

Read a byte from the 1-wire bus

Exceptions
std::invalid_argumentin case of error
Returns
the byte read

Here is the call graph for this function:

uint8_t writeByte ( uint8_t  byte)
inline

Write a byte to a 1-wire bus

Parameters
bytethe byte to write to the bus
Exceptions
std::invalid_argumentin case of error
Returns
the byte read back during the time slot

Here is the call graph for this function:

bool writeBit ( bool  bit)
inline

Write a bit to a 1-wire bus and read a bit corresponding to the time slot back. This is possible due to the way we wired the TX and RX together with a diode, forming a loopback.

Parameters
bitthe bit to write to the bus
Exceptions
std::invalid_argumentin case of error
Returns
the bit read back during the time slot

Here is the call graph for this function:

mraa::Result reset ( )
inline

Send a reset pulse to the 1-wire bus and test for device presence

Returns
one of the mraa::Result values

Here is the call graph for this function:

mraa::Result search ( bool  start,
uint8_t *  id 
)
inline

Begin a rom code search of the 1-wire bus. This function implements the 1-wire search algorithm. See the uart_ow.c example for an idea on how to use this function to identify all devices present on the bus.

Parameters
starttrue to start a search from scratch, false to continue a previously started search
idthe 8-byte rom code id of the current matched device when a device is found
Returns
one of the mraa::Result values

Here is the call graph for this function:

std::string search ( bool  start)
inline

Begin a rom code search of the 1-wire bus. This function implements the 1-wire search algorithm. See the UartOW.cpp example for an idea on how to use this function to identify all devices present on the bus.

Parameters
starttrue to start a search from scratch, false to continue a previously started search
Returns
an empty string if no [more] devices are found, or a string containing the 8-byte romcode of a detected device.

Here is the call graph for this function:

mraa::Result command ( uint8_t  command,
uint8_t *  id 
)
inline

Send a command byte to a device on the 1-wire bus

Parameters
commandthe command byte to send
idthe rom code id of the device to receive the command, NULL for all devices on the bus
Returns
one of the mraa::Result values

Here is the call graph for this function:

mraa::Result command ( uint8_t  command,
std::string  id 
)
inline

Send a command byte to a device on the 1-wire bus, supplying the id as a std::string

Parameters
commandthe command byte to send
idstd::string representing the code id of the device to receive the command, or an empty string for all devices on the bus. This string should be 8 bytes in size.
Returns
one of the mraa::Result values

Here is the call graph for this function:

uint8_t crc8 ( uint8_t *  buffer,
uint16_t  length 
)
inline

Perform a Dallas 1-wire compliant CRC8 computation on a buffer

Parameters
bufferthe buffer containing the data
lengththe length of the buffer
Returns
the computed CRC

Here is the call graph for this function:

uint8_t crc8 ( std::string  buffer)
inline

Perform a Dallas 1-wire compliant CRC8 computation on a std::string based buffer

Parameters
bufferstd::string buffer containing the data
Returns
the computed CRC

Here is the call graph for this function:


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