Go to the source code of this file.
|
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) |
|
uartat_context uartat_init |
( |
unsigned int |
uart, |
|
|
unsigned int |
baudrate |
|
) |
| |
UARTAT Initializer for generic UART operation using a UART index.
- Parameters
-
uart | Specify which uart to use. |
baudrate | Specify the baudrate to use. |
- Returns
- an initialized device context on success, NULL on error.
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_tty | character string representing a filesystem path to a serial tty device. |
baudrate | Specify the baudrate to use. |
- Returns
- an initialized device context on success, NULL on error.
UARTAT sensor close function
- Parameters
-
int uartat_read |
( |
const uartat_context |
dev, |
|
|
char * |
buffer, |
|
|
size_t |
len |
|
) |
| |
Read character data from the device.
- Parameters
-
dev | Device context |
buffer | The character buffer to read data into. |
len | The maximum size of the buffer |
- Returns
- The number of bytes successfully read, or -1 on error
int uartat_write |
( |
const uartat_context |
dev, |
|
|
const char * |
buffer, |
|
|
size_t |
len |
|
) |
| |
Write character data to the device.
- Parameters
-
dev | Device context |
buffer | The character buffer containing data to write. |
len | The number of bytes to write. |
- Returns
- The number of bytes successfully written, or -1 on error.
upm_result_t uartat_set_baudrate |
( |
const uartat_context |
dev, |
|
|
unsigned int |
baudrate |
|
) |
| |
Set the baudrate of the device.
- Parameters
-
dev | Device context |
baudrate | The baud rate to set for the device. |
- Returns
- UPM result
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
-
dev | Device context |
wait_ms | The response delay to set, in milliseconds. |
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
-
dev | Device context |
millis | The number of milliseconds to wait for data to become available. |
- Returns
- true if data is available to be read, false otherwise.
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
-
dev | Device context |
cmd_chars | The character sequence to write, typically "+++". |
guard_ms | The 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.
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
-
- Returns
- true if AT command mode was detected, false otherwise.
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
-
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
-
dev | Device context |
cmd | A character string containing the AT command to send, including the "AT" prefix and a terminating carriage return ("\r"). |
resp | A 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_len | The 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.
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
-
dev | Device context |
cmd | The AT command to send, including the "AT" prefix and a terminating carriage return ("\r"). |
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
-
dev | Device context |
cmd | The command to send |
resp | The response character buffer |
resp_len | The maximum size of the response buffer |
wait_string | The string to search for |
millis | The maximum number of milliseconds to look for the wait_string. |
- Returns
- true if the wait_string was found in the response, false otherwise.
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
-
dev | Device context |
fc | One of the UARTAT_FLOW_CONTROL_T values. |
- Returns
- the UPM result.
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
-
dev | Device context |
buffer | The 0 teminated buffer in which to search. |
str | The 0 teminated string to search for. |
- Returns
- true if the string was found, false otherwise.