upm  1.5.0
Sensor/Actuator repository for libmraa (v1.8.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 {
54  class UARTAT {
55  public:
56 
63  UARTAT(unsigned int uart, unsigned int baudrate);
64 
72  UARTAT(std::string uart_path, unsigned int baudrate);
73 
77  ~UARTAT();
78 
85  std::string readStr(size_t size);
86 
93  int writeStr(std::string buffer);
94 
100  void setBaudrate(unsigned int baudrate);
101 
108  void setResponseWaitTime(unsigned int wait_time);
109 
121  bool dataAvailable(unsigned int millis);
122 
149  bool commandMode(const std::string cmd_chars, unsigned int guard_ms);
150 
158  bool inCommandMode();
159 
170  void drain();
171 
182  std::string commandWithResponse(const std::string cmd, size_t resp_len);
183 
203  std::string commandWaitFor(const std::string cmd, size_t resp_len,
204  const std::string waitString,
205  unsigned int millis);
206 
213  void command(const std::string cmd);
214 
224  std::string stringCR2LF(std::string str);
225 
232  void setFlowControl(UARTAT_FLOW_CONTROL_T fc);
233 
243  bool find(const std::string buffer, const std::string str);
244 
253  void filterCR(bool enable);
254 
255  protected:
256  // uartat device context
257  uartat_context m_uartat;
258 
259  private:
260  /* Disable implicit copy and assignment operators */
261  UARTAT(const UARTAT&) = delete;
262  UARTAT &operator=(const UARTAT&) = delete;
263  };
264 }
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
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:54
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