upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
uartat.h
Go to the documentation of this file.
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2017 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
25 #pragma once
26 
27 #include <stdint.h>
28 #include <stdlib.h>
29 #include <unistd.h>
30 
31 #include <upm.h>
32 #include <mraa/uart.h>
33 
34 #include "uartat_defs.h"
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
50  typedef struct _uartat_context {
51  mraa_uart_context uart;
52 
53  // wait time for reading results after sending a command. The
54  // default is 250ms.
55  unsigned int cmd_resp_wait_ms;
56 
57  // filter carriage returns (CR) out of responses?
58  bool filter_cr;
59  } *uartat_context;
60 
68  uartat_context uartat_init(unsigned int uart, unsigned int baudrate);
69 
79  uartat_context uartat_init_tty(const char *uart_tty, unsigned int baudrate);
80 
86  void uartat_close(uartat_context dev);
87 
96  int uartat_read(const uartat_context dev, char *buffer, size_t len);
97 
106  int uartat_write(const uartat_context dev, const char *buffer, size_t len);
107 
115  upm_result_t uartat_set_baudrate(const uartat_context dev,
116  unsigned int baudrate);
117 
126  unsigned int wait_ms);
127 
138  bool uartat_data_available(const uartat_context dev,
139  unsigned int millis);
140 
168  bool uartat_command_mode(const uartat_context dev, const char *cmd_chars,
169  unsigned int guard_ms);
170 
179  bool uartat_in_command_mode(const uartat_context dev);
180 
192  void uartat_drain(const uartat_context dev);
193 
211  const char *cmd, char *resp,
212  size_t resp_len);
213 
224  void uartat_command(const uartat_context dev, const char *cmd);
225 
240  bool uartat_command_waitfor(const uartat_context dev, const char *cmd,
241  char *resp, size_t resp_len,
242  const char *wait_string,
243  unsigned int millis);
244 
253  upm_result_t uartat_set_flow_control(const uartat_context dev,
254  UARTAT_FLOW_CONTROL_T fc);
255 
266  bool uartat_find(const uartat_context dev, const char *buffer,
267  const char *str);
268 
278  void uartat_filter_cr(const uartat_context dev, bool enable);
279 
280 #ifdef __cplusplus
281 }
282 #endif
upm_result_t uartat_set_flow_control(const uartat_context dev, UARTAT_FLOW_CONTROL_T fc)
Definition: uartat.c:365
upm_result_t uartat_set_baudrate(const uartat_context dev, unsigned int baudrate)
Definition: uartat.c:166
bool uartat_find(const uartat_context dev, const char *buffer, const char *str)
Definition: uartat.c:396
uartat_context uartat_init_tty(const char *uart_tty, unsigned int baudrate)
Definition: uartat.c:108
void uartat_drain(const uartat_context dev)
Definition: uartat.c:230
void uartat_command(const uartat_context dev, const char *cmd)
Definition: uartat.c:357
int uartat_command_with_response(const uartat_context dev, const char *cmd, char *resp, size_t resp_len)
Definition: uartat.c:250
void uartat_set_response_wait_time(const uartat_context dev, unsigned int wait_ms)
Definition: uartat.c:180
struct _uartat_context * uartat_context
int uartat_write(const uartat_context dev, const char *buffer, size_t len)
Definition: uartat.c:146
bool uartat_data_available(const uartat_context dev, unsigned int millis)
Definition: uartat.c:156
uartat_context uartat_init(unsigned int uart, unsigned int baudrate)
Definition: uartat.c:87
bool uartat_command_mode(const uartat_context dev, const char *cmd_chars, unsigned int guard_ms)
Definition: uartat.c:188
bool uartat_command_waitfor(const uartat_context dev, const char *cmd, char *resp, size_t resp_len, const char *wait_string, unsigned int millis)
Definition: uartat.c:302
void uartat_filter_cr(const uartat_context dev, bool enable)
Definition: uartat.c:405
int uartat_read(const uartat_context dev, char *buffer, size_t len)
Definition: uartat.c:138
void uartat_close(uartat_context dev)
Definition: uartat.c:128
bool uartat_in_command_mode(const uartat_context dev)
Definition: uartat.c:213
Definition: uartat.h:50