00001 /*! \file WaspXBee.h 00002 \brief Library for managing the UART related with the XBee 00003 00004 Copyright (C) 2009 Libelium Comunicaciones Distribuidas S.L. 00005 http://www.libelium.com 00006 00007 This program is free software: you can redistribute it and/or modify 00008 it under the terms of the GNU Lesser General Public License as published by 00009 the Free Software Foundation, either version 2.1 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. 00019 00020 Version: 0.1 00021 00022 Design: David Gascón 00023 00024 Implementation: David Cuartielles, Alberto Bielsa 00025 00026 */ 00027 00028 00029 /*! \def XBee_h 00030 \brief The library flag 00031 00032 */ 00033 #ifndef XBee_h 00034 #define XBee_h 00035 00036 /****************************************************************************** 00037 * Includes 00038 ******************************************************************************/ 00039 00040 #include <inttypes.h> 00041 00042 /****************************************************************************** 00043 * Definitions & Declarations 00044 ******************************************************************************/ 00045 00046 /*! \def XBEE_ON 00047 \brief XBee Power Mode. OFF in this case 00048 00049 */ 00050 /*! \def XBEE_HIBERNATE 00051 \brief XBee Power Mode. HIBERNATE in this case 00052 00053 */ 00054 /*! \def XBEE_OFF 00055 \brief XBee Power Mode. OFF in this case 00056 00057 */ 00058 #define XBEE_ON 1 00059 #define XBEE_HIBERNATE 2 00060 #define XBEE_OFF 3 00061 00062 /*! \def XBEE_RATE 00063 \brief XBee Baud Rate 00064 00065 */ 00066 #define XBEE_RATE 38400 00067 00068 /****************************************************************************** 00069 * Class 00070 ******************************************************************************/ 00071 00072 //! WaspXBee Class 00073 /*! 00074 WaspXBee Class defines all the variables and functions used to manage the UART related with the XBee 00075 */ 00076 class WaspXBee 00077 { 00078 private: 00079 00080 //! Variable : specifies the UART where the USB is connected 00081 /*! 00082 */ 00083 uint8_t _uart; 00084 00085 //! Variable : specifies the power mode, enabling or disabling the XBee switch or setting the XBee to sleep 00086 /*! 00087 */ 00088 uint8_t _pwrMode; 00089 00090 //! It prints a number in the specified base 00091 /*! 00092 \param unsigned long n : the number to print 00093 \param uint8_t base : the base for printing the number 00094 \return void 00095 */ 00096 void printNumber(unsigned long n, uint8_t base); 00097 00098 //! It prints a 'float' number 00099 /*! 00100 \param double number : the number to print 00101 \param uint8_t digits : the number of non-integer part digits 00102 \return void 00103 */ 00104 void printFloat(double number, uint8_t digits); 00105 public: 00106 00107 //! class constructor 00108 /*! 00109 It initializes some variables 00110 \param void 00111 \return void 00112 */ 00113 WaspXBee(); 00114 00115 //! It opens UART to be able to communicate with the XBee 00116 /*! 00117 It gets the baud rate from 'XBEE_RATE' 00118 \param void 00119 \return void 00120 */ 00121 void begin(); 00122 00123 //! It opens UART to be able to communicate with the XBee 00124 /*! 00125 \param uint16_t speed : the baud rate to set to the UART 00126 \return void 00127 */ 00128 void begin(uint16_t speed); 00129 00130 //! It closes the previously opened UART 00131 /*! 00132 \param void 00133 \return void 00134 */ 00135 void close(); 00136 00137 //! It sets ON/OFF the XBee switch or sets the XBee to sleep 00138 /*! 00139 \param uint8_t mode : XBEE_ON, XBEE_OFF, XBEE_HIBERNATE 00140 \return void 00141 */ 00142 void setMode(uint8_t mode); 00143 00144 00145 //! It checks if there is available data waiting to be read 00146 /*! 00147 \param void 00148 \return '1' if there is available data, '0' otherwise 00149 */ 00150 uint8_t available(); 00151 00152 //! It reads a byte from the UART 00153 /*! 00154 \param void 00155 \return the read byte or '-1' if no data is available 00156 */ 00157 int read(); 00158 00159 //! It clears the UART buffer 00160 /*! 00161 \param void 00162 \return void 00163 */ 00164 void flush(); 00165 00166 //! It prints a character 00167 /*! 00168 \param char c : the character to print 00169 \return void 00170 */ 00171 void print(char c); 00172 00173 //! It prints a string 00174 /*! 00175 \param const char[] c : the string to print 00176 \return void 00177 */ 00178 void print(const char[]); 00179 00180 //! It prints an unsigned 8-bit integer 00181 /*! 00182 \param uint8_t b : the number to print 00183 \return void 00184 */ 00185 void print(uint8_t b); 00186 00187 //! It prints an integer 00188 /*! 00189 \param int n : the number to print 00190 \return void 00191 */ 00192 void print(int n); 00193 00194 //! It prints an unsigned integer 00195 /*! 00196 \param unsigned int n : the number to print 00197 \return void 00198 */ 00199 void print(unsigned int n); 00200 00201 //! It prints a long integer 00202 /*! 00203 \param long n : the number to print 00204 \return void 00205 */ 00206 void print(long n); 00207 00208 //! It prints an unsigned long integer 00209 /*! 00210 \param unsigned long n : the number to print 00211 \return void 00212 */ 00213 void print(unsigned long n); 00214 00215 //! It prints a long number in the specified base 00216 /*! 00217 \param long n : the number to print 00218 \param int base : the base for printing the number 00219 \return void 00220 */ 00221 void print(long n, int base); 00222 00223 //! It prints a double number 00224 /*! 00225 \param double n : the number to print 00226 \return void 00227 */ 00228 void print(double n); 00229 00230 //! It prints an EOL and a carriage return 00231 /*! 00232 \param void 00233 \return void 00234 */ 00235 void println(); 00236 00237 //! It prints a character adding an EOL and a carriage return 00238 /*! 00239 \param char c : the character to print 00240 \return void 00241 */ 00242 void println(char c); 00243 00244 //! It prints a string adding an EOL and a carriage return 00245 /*! 00246 \param const char[] c : the string to print 00247 \return void 00248 */ 00249 void println(const char[]); 00250 00251 //! It prints an unsigned 8-bit integer adding an EOL and a carriage return 00252 /*! 00253 \param uint8_t b : the number to print 00254 \return void 00255 */ 00256 void println(uint8_t b); 00257 00258 //! It prints an integer adding an EOL and a carriage return 00259 /*! 00260 \param int n : the number to print 00261 \return void 00262 */ 00263 void println(int n); 00264 00265 //! It prints a long integer adding an EOL and a carriage return 00266 /*! 00267 \param long n : the number to print 00268 \return void 00269 */ 00270 void println(long n); 00271 00272 //! It prints an unsigned long integer adding an EOL and a carriage return 00273 /*! 00274 \param unsigned long n : the number to print 00275 \return void 00276 */ 00277 void println(unsigned long n); 00278 00279 //! It prints a long number in the specified base adding an EOL and a carriage return 00280 /*! 00281 \param long n : the number to print 00282 \param int base : the base for printing the number 00283 \return void 00284 */ 00285 void println(long n, int base); 00286 00287 //! It prints a double number adding an EOL and a carriage return 00288 /*! 00289 \param double n : the number to print 00290 \return void 00291 */ 00292 void println(double n); 00293 }; 00294 00295 extern WaspXBee XBee; 00296 00297 #endif 00298
1.5.6