a

Dependents:   IOT_Sockets

Fork of xbee_api by Wiktor Grajkowski

Committer:
noname77
Date:
Sat Jan 25 16:29:44 2014 +0000
Revision:
7:8e5855f18ad3
Parent:
4:ede20c047d8b
Child:
10:61e607fa8621
first succes build, checking for errors

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tristanjph 4:ede20c047d8b 1 /* Copyright (c) 2012 Tristan Hughes, MIT License
tristanjph 4:ede20c047d8b 2 *
tristanjph 4:ede20c047d8b 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
tristanjph 4:ede20c047d8b 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
tristanjph 4:ede20c047d8b 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
tristanjph 4:ede20c047d8b 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
tristanjph 4:ede20c047d8b 7 * furnished to do so, subject to the following conditions:
tristanjph 4:ede20c047d8b 8 *
tristanjph 4:ede20c047d8b 9 * The above copyright notice and this permission notice shall be included in all copies or
tristanjph 4:ede20c047d8b 10 * substantial portions of the Software.
tristanjph 4:ede20c047d8b 11 *
tristanjph 4:ede20c047d8b 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
tristanjph 4:ede20c047d8b 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
tristanjph 4:ede20c047d8b 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
tristanjph 4:ede20c047d8b 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
tristanjph 4:ede20c047d8b 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
tristanjph 4:ede20c047d8b 17 */
tristanjph 0:2656fb225c5d 18 #include "mbed.h"
tristanjph 0:2656fb225c5d 19
noname77 7:8e5855f18ad3 20 #define FRAME_SIZE 127
noname77 7:8e5855f18ad3 21 #define STARTBYTE 0x7E
noname77 7:8e5855f18ad3 22 #define MAX_DATA_LEN 70
noname77 7:8e5855f18ad3 23
noname77 7:8e5855f18ad3 24 #define TX_STATUS 0x89
noname77 7:8e5855f18ad3 25 #define TX_REQUEST_64 000
noname77 7:8e5855f18ad3 26 #define RX_PACKET_64 0x80
noname77 7:8e5855f18ad3 27
tristanjph 1:c3d9bdcb0b03 28 /** Xbee interface class for configuring, sending and recieving data using an Xbee */
tristanjph 2:cb627ea9b817 29 class xbee
tristanjph 2:cb627ea9b817 30 {
tristanjph 0:2656fb225c5d 31 private:
tristanjph 0:2656fb225c5d 32 PinName _tx;
tristanjph 0:2656fb225c5d 33 PinName _rx;
tristanjph 3:682615a0717e 34 PinName _reset;
noname77 7:8e5855f18ad3 35
tristanjph 0:2656fb225c5d 36 public:
tristanjph 2:cb627ea9b817 37 /** Configure serial data pin.
tristanjph 2:cb627ea9b817 38 * @param tx The serial tx pin the xbee is conected to.
tristanjph 2:cb627ea9b817 39 * @param rx The serial rx pin the xbee is conected to.
tristanjph 3:682615a0717e 40 * @param reset The pin connected to the Xbee reset pin.
tristanjph 1:c3d9bdcb0b03 41 */
tristanjph 3:682615a0717e 42 xbee(PinName tx, PinName rx, PinName reset);
tristanjph 0:2656fb225c5d 43 ~xbee();
tristanjph 2:cb627ea9b817 44 /** Puts the Xbee into config mode.
tristanjph 2:cb627ea9b817 45 * @return Returns 1 on success.
tristanjph 1:c3d9bdcb0b03 46 */
tristanjph 0:2656fb225c5d 47 int ConfigMode();
tristanjph 2:cb627ea9b817 48 /** Gets the serial number/mac address of the Xbee and places it into serial_no.
tristanjph 2:cb627ea9b817 49 * @param serial_no array to store the serial of Xbee (must be 8 long).
tristanjph 2:cb627ea9b817 50 * @return Returns 1 on success.
tristanjph 2:cb627ea9b817 51 */
tristanjph 2:cb627ea9b817 52 int GetSerial(int*);
tristanjph 2:cb627ea9b817 53 /** Sets the encryption key to the one stored in security_key.
tristanjph 2:cb627ea9b817 54 * @param key Pointer to the network key to set.
tristanjph 2:cb627ea9b817 55 * @return Returns 1 on success.
tristanjph 1:c3d9bdcb0b03 56 */
tristanjph 3:682615a0717e 57 int SetKey(int*);
tristanjph 2:cb627ea9b817 58 /** Sets the id of the PAN network for the Xbee to use
tristanjph 2:cb627ea9b817 59 * @param pan_id The id of the PAN for the Xbee to use.
tristanjph 2:cb627ea9b817 60 * @return Returns 1 on success.
tristanjph 1:c3d9bdcb0b03 61 */
tristanjph 2:cb627ea9b817 62 int SetPanId(int);
tristanjph 2:cb627ea9b817 63 /** Writes the settings to the Non volatile memory on the Xbee
tristanjph 2:cb627ea9b817 64 * @param key Pointer to the network key to set.
tristanjph 2:cb627ea9b817 65 * @return Returns 1 on success.
tristanjph 1:c3d9bdcb0b03 66 */
tristanjph 0:2656fb225c5d 67 int WriteSettings();
tristanjph 1:c3d9bdcb0b03 68 /** Exits config mode
tristanjph 2:cb627ea9b817 69 * @return Returns 1 on success.
tristanjph 1:c3d9bdcb0b03 70 */
tristanjph 0:2656fb225c5d 71 int ExitConfigMode();
tristanjph 2:cb627ea9b817 72 /** Sends data in the send_Data buffer.
tristanjph 2:cb627ea9b817 73 * @param data_buf Pointer to the buffer of data to send.
tristanjph 2:cb627ea9b817 74 * @returns 1 on success.
tristanjph 1:c3d9bdcb0b03 75 */
tristanjph 2:cb627ea9b817 76 int SendData(char*);
tristanjph 2:cb627ea9b817 77 /** Recieves data sent to the xbee.
tristanjph 2:cb627ea9b817 78 * @param data_buf Pointer to the buffer to put recieved data into.
tristanjph 2:cb627ea9b817 79 * @param numchar Number of characters to read. If 0, will use the size of data_buf.
tristanjph 2:cb627ea9b817 80 */
tristanjph 2:cb627ea9b817 81 void RecieveData(char*, int);
tristanjph 3:682615a0717e 82 /** Resets the Xbee.
tristanjph 3:682615a0717e 83 */
tristanjph 3:682615a0717e 84 void Reset();
tristanjph 0:2656fb225c5d 85 };