Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed-rtos mbed EthernetInterface
xbee.h@0:671a7b7e4673, 2017-02-12 (annotated)
- Committer:
- libv2001
- Date:
- Sun Feb 12 16:07:11 2017 +0000
- Revision:
- 0:671a7b7e4673
- Child:
- 1:d5fc0c731f5d
Hello!
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
libv2001 | 0:671a7b7e4673 | 1 | #include "mbed.h" |
libv2001 | 0:671a7b7e4673 | 2 | |
libv2001 | 0:671a7b7e4673 | 3 | #ifndef XBEE_H |
libv2001 | 0:671a7b7e4673 | 4 | #define XBEE_H |
libv2001 | 0:671a7b7e4673 | 5 | |
libv2001 | 0:671a7b7e4673 | 6 | #define START 0x7E |
libv2001 | 0:671a7b7e4673 | 7 | |
libv2001 | 0:671a7b7e4673 | 8 | #define ADDR_64BIT_SIZE 8 |
libv2001 | 0:671a7b7e4673 | 9 | #define ADDR_16BIT_SIZE 2 |
libv2001 | 0:671a7b7e4673 | 10 | #define AT_CMD_ID_SIZE 2 |
libv2001 | 0:671a7b7e4673 | 11 | |
libv2001 | 0:671a7b7e4673 | 12 | // Présent dans tous les frames |
libv2001 | 0:671a7b7e4673 | 13 | #define START_IDX 0 |
libv2001 | 0:671a7b7e4673 | 14 | #define LENGTH_MSB_IDX 1 |
libv2001 | 0:671a7b7e4673 | 15 | #define LENGTH_LSB_IDX 2 |
libv2001 | 0:671a7b7e4673 | 16 | #define API_ID_IDX 3 |
libv2001 | 0:671a7b7e4673 | 17 | #define FRAME_MIN_SIZE 4 |
libv2001 | 0:671a7b7e4673 | 18 | |
libv2001 | 0:671a7b7e4673 | 19 | // Les API ID supportés2 |
libv2001 | 0:671a7b7e4673 | 20 | #define API_ID_AT_CMD 0x08 |
libv2001 | 0:671a7b7e4673 | 21 | #define API_ID_AT_CMD_QUEUE 0x09 |
libv2001 | 0:671a7b7e4673 | 22 | #define API_ID_TRANSMIT 0x10 |
libv2001 | 0:671a7b7e4673 | 23 | #define API_ID_REMOTE_AT_RQST 0x17 |
libv2001 | 0:671a7b7e4673 | 24 | #define API_ID_AT_CMD_RSP 0x88 |
libv2001 | 0:671a7b7e4673 | 25 | #define API_ID_MODEM_STATUS 0x8A |
libv2001 | 0:671a7b7e4673 | 26 | #define API_ID_TRANSMIT_STATUS 0x8B |
libv2001 | 0:671a7b7e4673 | 27 | #define API_ID_RECEIVED_PACKET 0x90 |
libv2001 | 0:671a7b7e4673 | 28 | |
libv2001 | 0:671a7b7e4673 | 29 | // Présent dans la majorité des frames |
libv2001 | 0:671a7b7e4673 | 30 | #define FRAME_ID_IDX 4 |
libv2001 | 0:671a7b7e4673 | 31 | |
libv2001 | 0:671a7b7e4673 | 32 | // Spécifique pour l'AT Command |
libv2001 | 0:671a7b7e4673 | 33 | #define AT_CMD_ID_IDX 5 |
libv2001 | 0:671a7b7e4673 | 34 | #define AT_PARAM_IDX 7 |
libv2001 | 0:671a7b7e4673 | 35 | #define AT_MIN_SIZE 4 |
libv2001 | 0:671a7b7e4673 | 36 | |
libv2001 | 0:671a7b7e4673 | 37 | // Spécifique pour l'AT Command Queue |
libv2001 | 0:671a7b7e4673 | 38 | #define AT_QUEUE_CMD_1_IDX 5 |
libv2001 | 0:671a7b7e4673 | 39 | #define AT_QUEUE_CMD_2_IDX 6 |
libv2001 | 0:671a7b7e4673 | 40 | #define AT_QUEUE_PARAM_IDX 7 |
libv2001 | 0:671a7b7e4673 | 41 | #define AT_QUEUE_MIN_SIZE 4 |
libv2001 | 0:671a7b7e4673 | 42 | |
libv2001 | 0:671a7b7e4673 | 43 | // Spécifique pour la Transmit Command |
libv2001 | 0:671a7b7e4673 | 44 | #define TRANSMIT_64BIT_MSB_IDX 5 |
libv2001 | 0:671a7b7e4673 | 45 | #define TRANSMIT_64BIT_LSB_IDX 12 |
libv2001 | 0:671a7b7e4673 | 46 | #define TRANSMIT_16BIT_MSB_IDX 13 |
libv2001 | 0:671a7b7e4673 | 47 | #define TRANSMIT_16BIT_LSB_IDX 14 |
libv2001 | 0:671a7b7e4673 | 48 | #define TRANSMIT_BROADCAST_IDX 15 |
libv2001 | 0:671a7b7e4673 | 49 | #define TRANSMIT_OPT_IDX 16 |
libv2001 | 0:671a7b7e4673 | 50 | #define TRANSMIT_DATA_IDX 17 |
libv2001 | 0:671a7b7e4673 | 51 | #define TRANSMIT_MIN_SIZE 14 |
libv2001 | 0:671a7b7e4673 | 52 | |
libv2001 | 0:671a7b7e4673 | 53 | // Les options de la Transmit Command |
libv2001 | 0:671a7b7e4673 | 54 | #define TRANSMIT_DEFAULT_BROADCAST 0x00 |
libv2001 | 0:671a7b7e4673 | 55 | #define TRANSMIT_DEFAULT_OPT 0x00 |
libv2001 | 0:671a7b7e4673 | 56 | |
libv2001 | 0:671a7b7e4673 | 57 | // Spécifique pour la Remote AT Request Command |
libv2001 | 0:671a7b7e4673 | 58 | #define REMOTE_AT_RQST_64BIT_MSB_IDX 5 |
libv2001 | 0:671a7b7e4673 | 59 | #define REMOTE_AT_RQST_64BIT_LSB_IDX 12 |
libv2001 | 0:671a7b7e4673 | 60 | #define REMOTE_AT_RQST_16BIT_MSB_IDX 13 |
libv2001 | 0:671a7b7e4673 | 61 | #define REMOTE_AT_RQST_16BIT_LSB_IDX 14 |
libv2001 | 0:671a7b7e4673 | 62 | #define REMOTE_AT_RQST_OPT_IDX 15 |
libv2001 | 0:671a7b7e4673 | 63 | #define REMOTE_AT_RQST_AT_CMD1_IDX 16 |
libv2001 | 0:671a7b7e4673 | 64 | #define REMOTE_AT_RQST_AT_CMD2_IDX 17 |
libv2001 | 0:671a7b7e4673 | 65 | #define REMOTE_AT_RQST_AT_PARAM_IDX 18 |
libv2001 | 0:671a7b7e4673 | 66 | #define REMOTE_AT_RQST_MIN_SIZE 15 |
libv2001 | 0:671a7b7e4673 | 67 | |
libv2001 | 0:671a7b7e4673 | 68 | // Les options pour la Remote AT Request Command |
libv2001 | 0:671a7b7e4673 | 69 | #define REMOTE_AT_RQST_DEFAULT_OPT 0x00 |
libv2001 | 0:671a7b7e4673 | 70 | #define REMOTE_AT_RQST_OPT_APPLY_CHANGE 0x02 |
libv2001 | 0:671a7b7e4673 | 71 | |
libv2001 | 0:671a7b7e4673 | 72 | // Spécifique pour la AT Command Response |
libv2001 | 0:671a7b7e4673 | 73 | #define AT_CMD_RSP_AT_CMD1_IDX 5 |
libv2001 | 0:671a7b7e4673 | 74 | #define AT_CMD_RSP_AT_CMD2_IDX 6 |
libv2001 | 0:671a7b7e4673 | 75 | #define AT_CMD_RSP_STATUS_IDX 7 |
libv2001 | 0:671a7b7e4673 | 76 | #define AT_CMD_RSP_DATA_IDX 8 |
libv2001 | 0:671a7b7e4673 | 77 | #define AT_CMD_RSP_MIN_SIZE 5 |
libv2001 | 0:671a7b7e4673 | 78 | |
libv2001 | 0:671a7b7e4673 | 79 | // Les status pour la AT Command Response |
libv2001 | 0:671a7b7e4673 | 80 | #define AT_CMD_RSP_STATUS_OK 0x00 |
libv2001 | 0:671a7b7e4673 | 81 | #define AT_CMD_RSP_STATUS_ERROR 0x01 |
libv2001 | 0:671a7b7e4673 | 82 | #define AT_CMD_RSP_STATUS_INVALID_CMD 0x02 |
libv2001 | 0:671a7b7e4673 | 83 | #define AT_CMD_RSP_STATUS_INVALID_PARAM 0x03 |
libv2001 | 0:671a7b7e4673 | 84 | #define AT_CMD_RSP_STATUS_TX_FAILURE 0x04 |
libv2001 | 0:671a7b7e4673 | 85 | |
libv2001 | 0:671a7b7e4673 | 86 | // Spécifique pour la Modem Status Command |
libv2001 | 0:671a7b7e4673 | 87 | #define MODEM_STATUS_STATUS_IDX 4 |
libv2001 | 0:671a7b7e4673 | 88 | |
libv2001 | 0:671a7b7e4673 | 89 | // Les status pour la Modem Status Command |
libv2001 | 0:671a7b7e4673 | 90 | #define MODEM_STATUS_HARDWARE_RST 0x00 |
libv2001 | 0:671a7b7e4673 | 91 | #define MODEM_STATUS_JOINED_NETWORK 0x02 |
libv2001 | 0:671a7b7e4673 | 92 | #define MODEM_STATUS_DISASSOCIATED 0x03 |
libv2001 | 0:671a7b7e4673 | 93 | #define MODEM_STATUS_COORDINATOR_STARTED 0x06 |
libv2001 | 0:671a7b7e4673 | 94 | |
libv2001 | 0:671a7b7e4673 | 95 | // Spécifique pour la Transit Status Command |
libv2001 | 0:671a7b7e4673 | 96 | #define TRANSMIT_STATUS_16BIT_MSB_IDX 5 |
libv2001 | 0:671a7b7e4673 | 97 | #define TRANSMIT_STATUS_16BIT_LSB_IDX 6 |
libv2001 | 0:671a7b7e4673 | 98 | #define TRANSMIT_STATUS_RETRY_COUNT_IDX 7 |
libv2001 | 0:671a7b7e4673 | 99 | #define TRANSMIT_STATUS_DELIVERY_STATUS_IDX 8 |
libv2001 | 0:671a7b7e4673 | 100 | #define TRANSMIT_STATUS_DISCOVERY_STATUS_IDX 9 |
libv2001 | 0:671a7b7e4673 | 101 | |
libv2001 | 0:671a7b7e4673 | 102 | #define TRANSMIT_STATUS_OK 0x00 |
libv2001 | 0:671a7b7e4673 | 103 | |
libv2001 | 0:671a7b7e4673 | 104 | // Spécifique pour la Received Packet Command |
libv2001 | 0:671a7b7e4673 | 105 | #define RECEIVED_PACKET_64BIT_MSB_IDX 4 |
libv2001 | 0:671a7b7e4673 | 106 | #define RECEIVED_PACKET_64BIT_LSB_IDX 11 |
libv2001 | 0:671a7b7e4673 | 107 | #define RECEIVED_PACKET_16BIT_MSB_IDX 12 |
libv2001 | 0:671a7b7e4673 | 108 | #define RECEIVED_PACKET_16BIT_LSB_IDX 13 |
libv2001 | 0:671a7b7e4673 | 109 | #define RECEIVED_PACKET_OPT_IDX 14 |
libv2001 | 0:671a7b7e4673 | 110 | #define RECEIVED_PACKET_DATA_IDX 15 |
libv2001 | 0:671a7b7e4673 | 111 | #define RECEIVED_PACKET_MIN_SIZE 12 |
libv2001 | 0:671a7b7e4673 | 112 | |
libv2001 | 0:671a7b7e4673 | 113 | inline uint16_t GetFrameLength(char * buffer){ |
libv2001 | 0:671a7b7e4673 | 114 | return (((uint16_t)buffer[LENGTH_MSB_IDX]) << 8) + buffer[LENGTH_LSB_IDX]; |
libv2001 | 0:671a7b7e4673 | 115 | } |
libv2001 | 0:671a7b7e4673 | 116 | |
libv2001 | 0:671a7b7e4673 | 117 | bool ValidateCheckSum(char * buffer){ |
libv2001 | 0:671a7b7e4673 | 118 | uint16_t length = GetFrameLength(buffer); |
libv2001 | 0:671a7b7e4673 | 119 | |
libv2001 | 0:671a7b7e4673 | 120 | char sum = 0; |
libv2001 | 0:671a7b7e4673 | 121 | for (int i = 0; i <= length; ++i){ |
libv2001 | 0:671a7b7e4673 | 122 | sum += buffer[i + API_ID_IDX]; |
libv2001 | 0:671a7b7e4673 | 123 | } |
libv2001 | 0:671a7b7e4673 | 124 | |
libv2001 | 0:671a7b7e4673 | 125 | return sum == 0xff; |
libv2001 | 0:671a7b7e4673 | 126 | } |
libv2001 | 0:671a7b7e4673 | 127 | |
libv2001 | 0:671a7b7e4673 | 128 | inline uint16_t GetAtParamLength(char * buffer){ |
libv2001 | 0:671a7b7e4673 | 129 | return GetFrameLength(buffer) - AT_MIN_SIZE; |
libv2001 | 0:671a7b7e4673 | 130 | } |
libv2001 | 0:671a7b7e4673 | 131 | |
libv2001 | 0:671a7b7e4673 | 132 | inline uint16_t GetAtQueueParamLength(char * buffer){ |
libv2001 | 0:671a7b7e4673 | 133 | return GetFrameLength(buffer) - AT_QUEUE_MIN_SIZE; |
libv2001 | 0:671a7b7e4673 | 134 | } |
libv2001 | 0:671a7b7e4673 | 135 | |
libv2001 | 0:671a7b7e4673 | 136 | inline uint16_t GetTransmitDataLength(char * buffer){ |
libv2001 | 0:671a7b7e4673 | 137 | return GetFrameLength(buffer) - TRANSMIT_MIN_SIZE; |
libv2001 | 0:671a7b7e4673 | 138 | } |
libv2001 | 0:671a7b7e4673 | 139 | |
libv2001 | 0:671a7b7e4673 | 140 | inline uint16_t GetRemoteAtRequestParamLength(char * buffer){ |
libv2001 | 0:671a7b7e4673 | 141 | return GetFrameLength(buffer) - REMOTE_AT_RQST_MIN_SIZE; |
libv2001 | 0:671a7b7e4673 | 142 | } |
libv2001 | 0:671a7b7e4673 | 143 | |
libv2001 | 0:671a7b7e4673 | 144 | inline uint16_t GetAtResponseParamLength(char * buffer){ |
libv2001 | 0:671a7b7e4673 | 145 | return GetFrameLength(buffer) - AT_CMD_RSP_MIN_SIZE; |
libv2001 | 0:671a7b7e4673 | 146 | } |
libv2001 | 0:671a7b7e4673 | 147 | |
libv2001 | 0:671a7b7e4673 | 148 | inline uint16_t GetReceivedPacketDataLength(char * buffer){ |
libv2001 | 0:671a7b7e4673 | 149 | return GetFrameLength(buffer) - RECEIVED_PACKET_MIN_SIZE; |
libv2001 | 0:671a7b7e4673 | 150 | } |
libv2001 | 0:671a7b7e4673 | 151 | |
libv2001 | 0:671a7b7e4673 | 152 | inline long long int Get64Addr(char * buffer, int start){ |
libv2001 | 0:671a7b7e4673 | 153 | long long int addr = 0; |
libv2001 | 0:671a7b7e4673 | 154 | memcpy(&addr, &buffer[start], ADDR_64BIT_SIZE); |
libv2001 | 0:671a7b7e4673 | 155 | |
libv2001 | 0:671a7b7e4673 | 156 | return addr; |
libv2001 | 0:671a7b7e4673 | 157 | } |
libv2001 | 0:671a7b7e4673 | 158 | |
libv2001 | 0:671a7b7e4673 | 159 | #endif |