upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
xbee.hpp
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2015 Intel Corporation.
4  *
5  * Thanks to Adafruit for supplying a google translated version of the
6  * Chinese datasheet and some clues in their code.
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining
9  * a copy of this software and associated documentation files (the
10  * "Software"), to deal in the Software without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sublicense, and/or sell copies of the Software, and to
13  * permit persons to whom the Software is furnished to do so, subject to
14  * the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be
17  * included in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  */
27 #pragma once
28 
29 #include <string>
30 #include <iostream>
31 
32 #include <stdlib.h>
33 #include <unistd.h>
34 #include <string.h>
35 
36 #include <mraa/common.hpp>
37 #include <mraa/uart.hpp>
38 
39 #define XBEE_DEFAULT_UART 0
40 
41 namespace upm {
81  class XBee {
82  public:
83 
89  XBee(int uart=XBEE_DEFAULT_UART);
90 
94  ~XBee();
95 
102  bool dataAvailable(unsigned int millis);
103 
114  int readData(char *buffer, unsigned int len);
115 
125  std::string readDataStr(int len);
126 
136  int writeData(char *buffer, unsigned len);
137 
145  int writeDataStr(std::string data);
146 
153  mraa::Result setBaudRate(int baud=9600);
154 
173  bool commandMode(std::string cmdChars="+++", int guardTimeMS=1000);
174 
184  std::string stringCR2LF(std::string str);
185 
186  protected:
187  mraa::Uart m_uart;
188 
189  private:
190  };
191 }
192 
193 
std::string stringCR2LF(std::string str)
Definition: xbee.cxx:95
~XBee()
Definition: xbee.cxx:40
bool dataAvailable(unsigned int millis)
Definition: xbee.cxx:44
bool commandMode(std::string cmdChars="+++", int guardTimeMS=1000)
Definition: xbee.cxx:76
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
mraa::Result setBaudRate(int baud=9600)
Definition: xbee.cxx:71
API for the XBee modules.
Definition: xbee.hpp:81
int writeData(char *buffer, unsigned len)
Definition: xbee.cxx:59
std::string readDataStr(int len)
Definition: xbee.cxx:54
int writeDataStr(std::string data)
Definition: xbee.cxx:65
XBee(int uart=XBEE_DEFAULT_UART)
Definition: xbee.cxx:35
int readData(char *buffer, unsigned int len)
Definition: xbee.cxx:49