A libery to connect to telegesis zigbee module. Bassed on implemtation of XBEE
Fork of xbee_lib by
telegesis.h@11:18ff088287ea, 2013-10-15 (annotated)
- Committer:
- gert_lauritsen
- Date:
- Tue Oct 15 09:55:41 2013 +0000
- Revision:
- 11:18ff088287ea
- Parent:
- 10:263f7251c111
- Child:
- 12:debf76f0c0bf
starting to work
Who changed what in which revision?
User | Revision | Line number | New 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 | 8:4682155753ec | 69 | /** Sends data using the ascii mode |
gert_lauritsen | 10:263f7251c111 | 70 | */ |
gert_lauritsen | 9:c8e4339ccc29 | 71 | int UniCast(char *adr,char *payload); |
gert_lauritsen | 8:4682155753ec | 72 | /** Sends data using the binary mode |
gert_lauritsen | 8:4682155753ec | 73 | */ |
gert_lauritsen | 9:c8e4339ccc29 | 74 | int UniCastb(char *adr,char *payload, char payloadSize); |
gert_lauritsen | 11:18ff088287ea | 75 | |
gert_lauritsen | 10:263f7251c111 | 76 | |
gert_lauritsen | 9:c8e4339ccc29 | 77 | /** converts a string to a long |
gert_lauritsen | 9:c8e4339ccc29 | 78 | */ |
gert_lauritsen | 11:18ff088287ea | 79 | unsigned long hextolong(const char *hex); |
gert_lauritsen | 8:4682155753ec | 80 | /** convertes a string to a int |
gert_lauritsen | 8:4682155753ec | 81 | */ |
gert_lauritsen | 11:18ff088287ea | 82 | unsigned int hextoint(const char *hex); |
gert_lauritsen | 9:c8e4339ccc29 | 83 | /** |
gert_lauritsen | 9:c8e4339ccc29 | 84 | */ |
gert_lauritsen | 7:45511c3d2950 | 85 | int EUI64; |
gert_lauritsen | 9:c8e4339ccc29 | 86 | /** COO or FBB |
gert_lauritsen | 9:c8e4339ccc29 | 87 | */ |
gert_lauritsen | 7:45511c3d2950 | 88 | char Devicetype[3]; |
gert_lauritsen | 9:c8e4339ccc29 | 89 | /** Gives type of HW |
gert_lauritsen | 9:c8e4339ccc29 | 90 | */ |
gert_lauritsen | 9:c8e4339ccc29 | 91 | char HWType[15]; |
gert_lauritsen | 9:c8e4339ccc29 | 92 | /** incomming data |
gert_lauritsen | 9:c8e4339ccc29 | 93 | */ |
gert_lauritsen | 9:c8e4339ccc29 | 94 | char Zdata[100]; |
gert_lauritsen | 11:18ff088287ea | 95 | /** |
gert_lauritsen | 11:18ff088287ea | 96 | |
gert_lauritsen | 11:18ff088287ea | 97 | */ |
gert_lauritsen | 11:18ff088287ea | 98 | char LocalID[17]; |
gert_lauritsen | 11:18ff088287ea | 99 | /** |
gert_lauritsen | 11:18ff088287ea | 100 | * indication of incoming data |
gert_lauritsen | 11:18ff088287ea | 101 | */ |
gert_lauritsen | 11:18ff088287ea | 102 | uint8_t Zdat; |
gert_lauritsen | 11:18ff088287ea | 103 | /** |
gert_lauritsen | 11:18ff088287ea | 104 | * Indicator on that we have got a ack on a packet |
gert_lauritsen | 11:18ff088287ea | 105 | */ |
gert_lauritsen | 11:18ff088287ea | 106 | uint8_t PacketAck; |
gert_lauritsen | 11:18ff088287ea | 107 | |
gert_lauritsen | 11:18ff088287ea | 108 | int channel, NodeID, EPID,framesize, PanOnline; |
gert_lauritsen | 11:18ff088287ea | 109 | /** |
gert_lauritsen | 11:18ff088287ea | 110 | * Reads all available serial bytes until a packet is parsed, an error occurs, or the buffer is empty. |
gert_lauritsen | 11:18ff088287ea | 111 | * You may call <i>xbee</i>.getResponse().isAvailable() after calling this method to determine if |
gert_lauritsen | 11:18ff088287ea | 112 | * a packet is ready, or <i>xbee</i>.getResponse().isError() to determine if |
gert_lauritsen | 11:18ff088287ea | 113 | * a error occurred. |
gert_lauritsen | 11:18ff088287ea | 114 | * <p/> |
gert_lauritsen | 11:18ff088287ea | 115 | * This method should always return quickly since it does not wait for serial data to arrive. |
gert_lauritsen | 11:18ff088287ea | 116 | * You will want to use this method if you are doing other timely stuff in your loop, where |
gert_lauritsen | 11:18ff088287ea | 117 | * a delay would cause problems. |
gert_lauritsen | 11:18ff088287ea | 118 | * NOTE: calling this method resets the current response, so make sure you first consume the |
gert_lauritsen | 11:18ff088287ea | 119 | * current response |
gert_lauritsen | 11:18ff088287ea | 120 | */ |
gert_lauritsen | 11:18ff088287ea | 121 | void readPacket(); |
gert_lauritsen | 11:18ff088287ea | 122 | /**Looks for a packet but dont wait |
gert_lauritsen | 11:18ff088287ea | 123 | */ |
gert_lauritsen | 11:18ff088287ea | 124 | uint8_t SeePacket(); |
gert_lauritsen | 11:18ff088287ea | 125 | |
gert_lauritsen | 11:18ff088287ea | 126 | |
gert_lauritsen | 11:18ff088287ea | 127 | private: |
gert_lauritsen | 11:18ff088287ea | 128 | uint8_t _pos; |
gert_lauritsen | 11:18ff088287ea | 129 | // last byte read |
gert_lauritsen | 11:18ff088287ea | 130 | uint8_t b; |
gert_lauritsen | 11:18ff088287ea | 131 | uint8_t _checksumTotal; |
gert_lauritsen | 11:18ff088287ea | 132 | uint8_t _nextFrameId; |
gert_lauritsen | 11:18ff088287ea | 133 | int SeqNumber; |
gert_lauritsen | 11:18ff088287ea | 134 | // 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 | 135 | uint8_t _responseFrameData[MAX_FRAME_DATA_SIZE]; |
gert_lauritsen | 11:18ff088287ea | 136 | char _responseFrameString[MAX_FRAME_DATA_SIZE]; |
gert_lauritsen | 11:18ff088287ea | 137 | |
gert_lauritsen | 11:18ff088287ea | 138 | Serial _zbee; |
gert_lauritsen | 11:18ff088287ea | 139 | int wait4OK(); |
gert_lauritsen | 11:18ff088287ea | 140 | }; |
gert_lauritsen | 11:18ff088287ea | 141 | |
gert_lauritsen | 11:18ff088287ea | 142 | #endif |