upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
uartat.hpp
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 #pragma once
25 
26 #include <string>
27 #include <iostream>
28 
29 #include "uartat.h"
30 
31 namespace upm {
55  class UARTAT {
56  public:
57 
64  UARTAT(unsigned int uart, unsigned int baudrate);
65 
73  UARTAT(std::string uart_path, unsigned int baudrate);
74 
78  ~UARTAT();
79 
86  std::string readStr(size_t size);
87 
94  int writeStr(std::string buffer);
95 
101  void setBaudrate(unsigned int baudrate);
102 
109  void setResponseWaitTime(unsigned int wait_time);
110 
122  bool dataAvailable(unsigned int millis);
123 
150  bool commandMode(const std::string cmd_chars, unsigned int guard_ms);
151 
159  bool inCommandMode();
160 
171  void drain();
172 
183  std::string commandWithResponse(const std::string cmd, size_t resp_len);
184 
204  std::string commandWaitFor(const std::string cmd, size_t resp_len,
205  const std::string waitString,
206  unsigned int millis);
207 
214  void command(const std::string cmd);
215 
225  std::string stringCR2LF(std::string str);
226 
233  void setFlowControl(UARTAT_FLOW_CONTROL_T fc);
234 
244  bool find(const std::string buffer, const std::string str);
245 
254  void filterCR(bool enable);
255 
256  protected:
257  // uartat device context
258  uartat_context m_uartat;
259 
260  private:
261  /* Disable implicit copy and assignment operators */
262  UARTAT(const UARTAT&) = delete;
263  UARTAT &operator=(const UARTAT&) = delete;
264  };
265 }
void setResponseWaitTime(unsigned int wait_time)
Definition: uartat.cxx:87
void drain()
Definition: uartat.cxx:107
bool commandMode(const std::string cmd_chars, unsigned int guard_ms)
Definition: uartat.cxx:97
std::string commandWithResponse(const std::string cmd, size_t resp_len)
Definition: uartat.cxx:113
bool inCommandMode()
Definition: uartat.cxx:102
bool dataAvailable(unsigned int millis)
Definition: uartat.cxx:92
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
Generic API for AT command based UART devices.
UARTAT(unsigned int uart, unsigned int baudrate)
Definition: uartat.cxx:34
void filterCR(bool enable)
Definition: uartat.cxx:170
bool find(const std::string buffer, const std::string str)
Definition: uartat.cxx:165
std::string stringCR2LF(std::string str)
Definition: uartat.cxx:147
std::string commandWaitFor(const std::string cmd, size_t resp_len, const std::string waitString, unsigned int millis)
Definition: uartat.cxx:127
void setFlowControl(UARTAT_FLOW_CONTROL_T fc)
Definition: uartat.cxx:156
std::string readStr(size_t size)
Definition: uartat.cxx:55
API for a Generic AT command based UART device.
Definition: uartat.hpp:55
void setBaudrate(unsigned int baudrate)
Definition: uartat.cxx:80
void command(const std::string cmd)
Definition: uartat.cxx:140
Definition: uartat.h:50
~UARTAT()
Definition: uartat.cxx:50
int writeStr(std::string buffer)
Definition: uartat.cxx:68