mraa  1.5.1
Low Level Skeleton Library for Communication on GNU/Linux platforms
 All Data Structures Namespaces Files Functions Typedefs Enumerations Enumerator Macros Pages
Public Member Functions
UartOW Class Reference

Detailed Description

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

#include "uart_ow.hpp"
using namespace std;
int
main(int argc, char** argv)
{
mraa::UartOW* uart = new mraa::UartOW(0);
// Reset the ow bus and see if anything is present
if ((rv = uart->reset()) == mraa::SUCCESS) {
cout << "Reset succeeded, device(s) detected!" << endl;
} else {
cout << "Reset failed, returned " << int(rv) << ". No devices on bus?" << endl;
return 1;
}
cout << "Looking for devices..." << endl;
;
uint8_t count = 0;
// start the search from scratch
string id = uart->search(true);
if (id.empty()) {
cout << "No devices detected." << endl;
return 1;
}
while (!id.empty()) {
// hack so we don't need to cast each element of the romcode
// for printf purposes
uint8_t* 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.
printf("Device %02d Type 0x%02x ID %02x%02x%02x%02x%02x%02x CRC 0x%02x\n", count, ptr[0],
ptr[6], ptr[5], ptr[4], ptr[3], ptr[2], ptr[1], ptr[7]);
count++;
// continue the search with start argument set to false
id = uart->search(false);
}
cout << "Exiting..." << endl;
delete uart;
return 0;
}

Public Member Functions

 UartOW (int uart)
 
 UartOW (std::string path)
 
 ~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

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

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.

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

Here is the call graph for this function:

~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: