upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Data Structures | Functions | Typedefs
uartat.h File Reference
Include dependency graph for uartat.h:

Go to the source code of this file.

Data Structures

struct  _uartat_context
 

Functions

uartat_context uartat_init (unsigned int uart, unsigned int baudrate)
 
uartat_context uartat_init_tty (const char *uart_tty, unsigned int baudrate)
 
void uartat_close (uartat_context dev)
 
int uartat_read (const uartat_context dev, char *buffer, size_t len)
 
int uartat_write (const uartat_context dev, const char *buffer, size_t len)
 
upm_result_t uartat_set_baudrate (const uartat_context dev, unsigned int baudrate)
 
void uartat_set_response_wait_time (const uartat_context dev, unsigned int wait_ms)
 
bool uartat_data_available (const uartat_context dev, unsigned int millis)
 
bool uartat_command_mode (const uartat_context dev, const char *cmd_chars, unsigned int guard_ms)
 
bool uartat_in_command_mode (const uartat_context dev)
 
void uartat_drain (const uartat_context dev)
 
int uartat_command_with_response (const uartat_context dev, const char *cmd, char *resp, size_t resp_len)
 
void uartat_command (const uartat_context dev, const char *cmd)
 
bool uartat_command_waitfor (const uartat_context dev, const char *cmd, char *resp, size_t resp_len, const char *wait_string, unsigned int millis)
 
upm_result_t uartat_set_flow_control (const uartat_context dev, UARTAT_FLOW_CONTROL_T fc)
 
bool uartat_find (const uartat_context dev, const char *buffer, const char *str)
 
void uartat_filter_cr (const uartat_context dev, bool enable)
 

Typedefs

typedef struct _uartat_contextuartat_context
 

Function Documentation

uartat_context uartat_init ( unsigned int  uart,
unsigned int  baudrate 
)

UARTAT Initializer for generic UART operation using a UART index.

Parameters
uartSpecify which uart to use.
baudrateSpecify the baudrate to use.
Returns
an initialized device context on success, NULL on error.

Here is the call graph for this function:

uartat_context uartat_init_tty ( const char *  uart_tty,
unsigned int  baudrate 
)

UARTAT Initializer for generic UART operation using a filesystem tty path (eg. /dev/ttyUSB0).

Parameters
uart_ttycharacter string representing a filesystem path to a serial tty device.
baudrateSpecify the baudrate to use.
Returns
an initialized device context on success, NULL on error.

Here is the call graph for this function:

Here is the caller graph for this function:

void uartat_close ( uartat_context  dev)

UARTAT sensor close function

Parameters
devDevice context

Here is the caller graph for this function:

int uartat_read ( const uartat_context  dev,
char *  buffer,
size_t  len 
)

Read character data from the device.

Parameters
devDevice context
bufferThe character buffer to read data into.
lenThe maximum size of the buffer
Returns
The number of bytes successfully read, or -1 on error

Here is the caller graph for this function:

int uartat_write ( const uartat_context  dev,
const char *  buffer,
size_t  len 
)

Write character data to the device.

Parameters
devDevice context
bufferThe character buffer containing data to write.
lenThe number of bytes to write.
Returns
The number of bytes successfully written, or -1 on error.

Here is the caller graph for this function:

upm_result_t uartat_set_baudrate ( const uartat_context  dev,
unsigned int  baudrate 
)

Set the baudrate of the device.

Parameters
devDevice context
baudrateThe baud rate to set for the device.
Returns
UPM result

Here is the caller graph for this function:

void uartat_set_response_wait_time ( const uartat_context  dev,
unsigned int  wait_ms 
)

Set the default time, in milliseconds, to wait for data to arrive after sending a command.

Parameters
devDevice context
wait_msThe response delay to set, in milliseconds.

Here is the caller graph for this function:

bool uartat_data_available ( const uartat_context  dev,
unsigned int  millis 
)

Determine whether there is data available to be read. This function will wait up to "millis" milliseconds for data to become available.

Parameters
devDevice context
millisThe number of milliseconds to wait for data to become available.
Returns
true if data is available to be read, false otherwise.

Here is the caller graph for this function:

bool uartat_command_mode ( const uartat_context  dev,
const char *  cmd_chars,
unsigned int  guard_ms 
)

Place the device in AT command mode. Many devices operate in a transparent mode and an AT command mode. Command mode is required to issue AT based commands. When in transparent mode, the device will usually listen for a special sequence of characters and delays, indicating that AT command mode should be entered.

On most devices, the sequence is: <wait 1 second>+++<wait 1 second>

For most devices, the wait time is 1 second (1000 ms) and the character sequence is "+++". These options can often be configured on the device.

This function will wait millis milliseconds, write the command characters (typically "+++"), then wait millis milliseconds again. At this time a read will be attempted, looking for the "OK" response indicating command mode was successfully entered.

Parameters
devDevice context
cmd_charsThe character sequence to write, typically "+++".
guard_msThe number of milliseconds to delay before and after the cmd_chars are written.
Returns
true if AT command mode ("OK" detected) was successfully entered, false otherwise.

Here is the call graph for this function:

Here is the caller graph for this function:

bool uartat_in_command_mode ( const uartat_context  dev)

Check to see if the device is in command mode. This is accomplished by sending an "AT\r" command and seeing if "OK" or "0" is returned.

Parameters
devDevice context
Returns
true if AT command mode was detected, false otherwise.

Here is the call graph for this function:

Here is the caller graph for this function:

void uartat_drain ( const uartat_context  dev)

Read and throw away any data currently available to be read. This is useful to avoid reading data that might have been the result of a previous command interfering with data you currently want to read. This function is automatically called by uartat_command_with_response(), uartat_command(), and uartat_command_waitfor() prior to writing the requested command to the device.

Parameters
devDevice context

Here is the call graph for this function:

Here is the caller graph for this function:

int uartat_command_with_response ( const uartat_context  dev,
const char *  cmd,
char *  resp,
size_t  resp_len 
)

Send an AT command and optionally return a response.

Parameters
devDevice context
cmdA character string containing the AT command to send, including the "AT" prefix and a terminating carriage return ("\r").
respA pointer to a buffer that will contain the response. If NULL is specified, the response is ignored. The returned string buffer will be 0 terminated like any ordinary C string.
resp_lenThe length of the supplied response buffer. If 0, then any response will be ignored. No more than resp_len characters (including the trailing 0 byte) will be returned.
Returns
The number of bytes read, or -1 on error.

Here is the call graph for this function:

Here is the caller graph for this function:

void uartat_command ( const uartat_context  dev,
const char *  cmd 
)

Send an AT command and ignore any response. This is a shorthand version of uartat_command_with_response(), and is equivalent to calling uartat_command_with_response(dev, cmd, NULL, 0).

Parameters
devDevice context
cmdThe AT command to send, including the "AT" prefix and a terminating carriage return ("\r").

Here is the call graph for this function:

Here is the caller graph for this function:

bool uartat_command_waitfor ( const uartat_context  dev,
const char *  cmd,
char *  resp,
size_t  resp_len,
const char *  wait_string,
unsigned int  millis 
)

Read characters for up to millis milliseconds, returning as soon as the wait_string is found.

Parameters
devDevice context
cmdThe command to send
respThe response character buffer
resp_lenThe maximum size of the response buffer
wait_stringThe string to search for
millisThe maximum number of milliseconds to look for the wait_string.
Returns
true if the wait_string was found in the response, false otherwise.

Here is the call graph for this function:

Here is the caller graph for this function:

upm_result_t uartat_set_flow_control ( const uartat_context  dev,
UARTAT_FLOW_CONTROL_T  fc 
)

Set a flow control method for the UART. By default, during initialization, flow control is disabled.

Parameters
devDevice context
fcOne of the UARTAT_FLOW_CONTROL_T values.
Returns
the UPM result.

Here is the caller graph for this function:

bool uartat_find ( const uartat_context  dev,
const char *  buffer,
const char *  str 
)

Look for a string in a buffer. This is a utility function that can be used to indicate if a given string is present in a supplied buffer. The search is case sensitive.

Parameters
devDevice context
bufferThe 0 teminated buffer in which to search.
strThe 0 teminated string to search for.
Returns
true if the string was found, false otherwise.

Here is the caller graph for this function:

void uartat_filter_cr ( const uartat_context  dev,
bool  enable 
)

Filter out carriage returns (CR) from response buffers if enabled. This operates only on the response buffers returned from uartat_command_with_response(), uartat_command(), and uartat_command_waitfor().

Parameters
devDevice context
enabletrue to filter out CR's, false otherwise

Here is the caller graph for this function:

Typedef Documentation

typedef struct _uartat_context * uartat_context

Device context