A libery to connect to telegesis zigbee module. Bassed on implemtation of XBEE

Fork of xbee_lib by Tristan Hughes

Committer:
gert_lauritsen
Date:
Tue Oct 15 14:10:08 2013 +0000
Revision:
12:debf76f0c0bf
Parent:
11:18ff088287ea
Child:
13:1b557befdeff
Child:
14:dcf2390f89e2
Now with ISR on the serial

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gert_lauritsen 11:18ff088287ea 1 #ifndef telegesis_h
gert_lauritsen 11:18ff088287ea 2 #define telegesis_h
gert_lauritsen 11:18ff088287ea 3
tristanjph 0:2656fb225c5d 4 #include "mbed.h"
tristanjph 0:2656fb225c5d 5
gert_lauritsen 7:45511c3d2950 6 /** Zigbee interface class for configuring, sending and recieving data using an telegesis zigbee */
gert_lauritsen 11:18ff088287ea 7 #define START_BYTE 0x7e
gert_lauritsen 11:18ff088287ea 8 #define ESCAPE 0x7d
gert_lauritsen 11:18ff088287ea 9 #define CR 0x0D
gert_lauritsen 11:18ff088287ea 10 #define LF 0x0A
gert_lauritsen 11:18ff088287ea 11 #define MAX_FRAME_DATA_SIZE 110
gert_lauritsen 11:18ff088287ea 12
gert_lauritsen 7:45511c3d2950 13 class zigbee
tristanjph 2:cb627ea9b817 14 {
tristanjph 0:2656fb225c5d 15 private:
tristanjph 0:2656fb225c5d 16 PinName _tx;
tristanjph 0:2656fb225c5d 17 PinName _rx;
tristanjph 3:682615a0717e 18 PinName _reset;
tristanjph 0:2656fb225c5d 19 public:
gert_lauritsen 7:45511c3d2950 20
gert_lauritsen 11:18ff088287ea 21 zigbee(PinName tx, PinName rx);
gert_lauritsen 7:45511c3d2950 22 ~zigbee();
gert_lauritsen 7:45511c3d2950 23
gert_lauritsen 7:45511c3d2950 24
gert_lauritsen 7:45511c3d2950 25 /** Gets the serial number/mac address of the zigbee and places it into serial_no.
gert_lauritsen 7:45511c3d2950 26 * @param serial_no array to store the serial of zigbee (must be 8 long).
tristanjph 2:cb627ea9b817 27 * @return Returns 1 on success.
tristanjph 2:cb627ea9b817 28 */
gert_lauritsen 11:18ff088287ea 29 int GetSerial();
tristanjph 6:6455a079bdb3 30 /** Sets the encryption key. This should be a 128-bit key.
tristanjph 2:cb627ea9b817 31 * @param key Pointer to the network key to set.
tristanjph 2:cb627ea9b817 32 * @return Returns 1 on success.
tristanjph 1:c3d9bdcb0b03 33 */
tristanjph 5:714651141a83 34 int SetKey(char*);
gert_lauritsen 7:45511c3d2950 35
tristanjph 2:cb627ea9b817 36 /** Recieves data sent to the xbee.
tristanjph 2:cb627ea9b817 37 * @param data_buf Pointer to the buffer to put recieved data into.
tristanjph 2:cb627ea9b817 38 * @param numchar Number of characters to read. If 0, will use the size of data_buf.
tristanjph 2:cb627ea9b817 39 */
tristanjph 2:cb627ea9b817 40 void RecieveData(char*, int);
gert_lauritsen 10:263f7251c111 41 /** Get hw version and local ID (64bit uniq number)
gert_lauritsen 10:263f7251c111 42 *
gert_lauritsen 10:263f7251c111 43 */
gert_lauritsen 7:45511c3d2950 44 int ATI();
gert_lauritsen 10:263f7251c111 45 /** Sends a ping to Coo or any other adresse
gert_lauritsen 8:4682155753ec 46 *
gert_lauritsen 7:45511c3d2950 47 */
gert_lauritsen 7:45511c3d2950 48 int PingOut();
gert_lauritsen 10:263f7251c111 49 /** Scan the Pan for nodes
gert_lauritsen 7:45511c3d2950 50 */
gert_lauritsen 7:45511c3d2950 51 int PanScan();
gert_lauritsen 10:263f7251c111 52 /** Make a new network. It then gets the role as coordinator
gert_lauritsen 7:45511c3d2950 53 */
gert_lauritsen 7:45511c3d2950 54 int Establish_Network();
gert_lauritsen 10:263f7251c111 55 /** Join a pan
gert_lauritsen 7:45511c3d2950 56 */
gert_lauritsen 7:45511c3d2950 57 int JoinNetwork();
gert_lauritsen 10:263f7251c111 58 /**
gert_lauritsen 10:263f7251c111 59 * Scan network
gert_lauritsen 7:45511c3d2950 60 */
gert_lauritsen 7:45511c3d2950 61 int ScanNetwork();
gert_lauritsen 10:263f7251c111 62 /**
gert_lauritsen 10:263f7251c111 63 *Give info on what role the modem has in the network
gert_lauritsen 7:45511c3d2950 64 */
gert_lauritsen 10:263f7251c111 65
gert_lauritsen 7:45511c3d2950 66 int NetworkInfo();
gert_lauritsen 10:263f7251c111 67 /**
gert_lauritsen 7:45511c3d2950 68 */
gert_lauritsen 12:debf76f0c0bf 69 int Reset();
gert_lauritsen 8:4682155753ec 70 /** Sends data using the ascii mode
gert_lauritsen 10:263f7251c111 71 */
gert_lauritsen 9:c8e4339ccc29 72 int UniCast(char *adr,char *payload);
gert_lauritsen 8:4682155753ec 73 /** Sends data using the binary mode
gert_lauritsen 8:4682155753ec 74 */
gert_lauritsen 9:c8e4339ccc29 75 int UniCastb(char *adr,char *payload, char payloadSize);
gert_lauritsen 11:18ff088287ea 76
gert_lauritsen 10:263f7251c111 77
gert_lauritsen 9:c8e4339ccc29 78 /** converts a string to a long
gert_lauritsen 9:c8e4339ccc29 79 */
gert_lauritsen 11:18ff088287ea 80 unsigned long hextolong(const char *hex);
gert_lauritsen 8:4682155753ec 81 /** convertes a string to a int
gert_lauritsen 8:4682155753ec 82 */
gert_lauritsen 11:18ff088287ea 83 unsigned int hextoint(const char *hex);
gert_lauritsen 9:c8e4339ccc29 84 /**
gert_lauritsen 9:c8e4339ccc29 85 */
gert_lauritsen 7:45511c3d2950 86 int EUI64;
gert_lauritsen 9:c8e4339ccc29 87 /** COO or FBB
gert_lauritsen 9:c8e4339ccc29 88 */
gert_lauritsen 7:45511c3d2950 89 char Devicetype[3];
gert_lauritsen 9:c8e4339ccc29 90 /** Gives type of HW
gert_lauritsen 9:c8e4339ccc29 91 */
gert_lauritsen 9:c8e4339ccc29 92 char HWType[15];
gert_lauritsen 9:c8e4339ccc29 93 /** incomming data
gert_lauritsen 9:c8e4339ccc29 94 */
gert_lauritsen 9:c8e4339ccc29 95 char Zdata[100];
gert_lauritsen 11:18ff088287ea 96 /**
gert_lauritsen 11:18ff088287ea 97
gert_lauritsen 11:18ff088287ea 98 */
gert_lauritsen 12:debf76f0c0bf 99 uint64_t LocalID;
gert_lauritsen 11:18ff088287ea 100 /**
gert_lauritsen 11:18ff088287ea 101 * indication of incoming data
gert_lauritsen 11:18ff088287ea 102 */
gert_lauritsen 11:18ff088287ea 103 uint8_t Zdat;
gert_lauritsen 11:18ff088287ea 104 /**
gert_lauritsen 11:18ff088287ea 105 * Indicator on that we have got a ack on a packet
gert_lauritsen 11:18ff088287ea 106 */
gert_lauritsen 11:18ff088287ea 107 uint8_t PacketAck;
gert_lauritsen 11:18ff088287ea 108
gert_lauritsen 11:18ff088287ea 109 int channel, NodeID, EPID,framesize, PanOnline;
gert_lauritsen 11:18ff088287ea 110 /**
gert_lauritsen 11:18ff088287ea 111 * Reads all available serial bytes until a packet is parsed, an error occurs, or the buffer is empty.
gert_lauritsen 11:18ff088287ea 112 * You may call <i>xbee</i>.getResponse().isAvailable() after calling this method to determine if
gert_lauritsen 11:18ff088287ea 113 * a packet is ready, or <i>xbee</i>.getResponse().isError() to determine if
gert_lauritsen 11:18ff088287ea 114 * a error occurred.
gert_lauritsen 11:18ff088287ea 115 * <p/>
gert_lauritsen 11:18ff088287ea 116 * This method should always return quickly since it does not wait for serial data to arrive.
gert_lauritsen 11:18ff088287ea 117 * You will want to use this method if you are doing other timely stuff in your loop, where
gert_lauritsen 11:18ff088287ea 118 * a delay would cause problems.
gert_lauritsen 11:18ff088287ea 119 * NOTE: calling this method resets the current response, so make sure you first consume the
gert_lauritsen 11:18ff088287ea 120 * current response
gert_lauritsen 11:18ff088287ea 121 */
gert_lauritsen 11:18ff088287ea 122 void readPacket();
gert_lauritsen 11:18ff088287ea 123 /**Looks for a packet but dont wait
gert_lauritsen 11:18ff088287ea 124 */
gert_lauritsen 12:debf76f0c0bf 125 void SeePacket();
gert_lauritsen 11:18ff088287ea 126
gert_lauritsen 11:18ff088287ea 127
gert_lauritsen 11:18ff088287ea 128 private:
gert_lauritsen 11:18ff088287ea 129 uint8_t _pos;
gert_lauritsen 11:18ff088287ea 130 // last byte read
gert_lauritsen 11:18ff088287ea 131 uint8_t b;
gert_lauritsen 11:18ff088287ea 132 uint8_t _checksumTotal;
gert_lauritsen 11:18ff088287ea 133 uint8_t _nextFrameId;
gert_lauritsen 11:18ff088287ea 134 int SeqNumber;
gert_lauritsen 12:debf76f0c0bf 135 uint8_t GotFrame; //indicate that a frame has been recieved
gert_lauritsen 11:18ff088287ea 136 // buffer for incoming RX packets. holds only the api specific frame data, starting after the api id byte and prior to checksum
gert_lauritsen 11:18ff088287ea 137 uint8_t _responseFrameData[MAX_FRAME_DATA_SIZE];
gert_lauritsen 11:18ff088287ea 138 char _responseFrameString[MAX_FRAME_DATA_SIZE];
gert_lauritsen 11:18ff088287ea 139
gert_lauritsen 11:18ff088287ea 140 Serial _zbee;
gert_lauritsen 12:debf76f0c0bf 141 bool wait4OK();
gert_lauritsen 11:18ff088287ea 142 };
gert_lauritsen 11:18ff088287ea 143
gert_lauritsen 11:18ff088287ea 144 #endif