desloges-libioulle / Mbed 2 deprecated app3_router

Dependencies:   mbed-rtos mbed

Committer:
libv2001
Date:
Sun Feb 12 16:06:13 2017 +0000
Revision:
0:0545bc9f81e0
Hello

Who changed what in which revision?

UserRevisionLine numberNew contents of line
libv2001 0:0545bc9f81e0 1 #include "mbed.h"
libv2001 0:0545bc9f81e0 2
libv2001 0:0545bc9f81e0 3 #ifndef XBEE_H
libv2001 0:0545bc9f81e0 4 #define XBEE_H
libv2001 0:0545bc9f81e0 5
libv2001 0:0545bc9f81e0 6 #define START 0x7E
libv2001 0:0545bc9f81e0 7
libv2001 0:0545bc9f81e0 8 #define ADDR_64BIT_SIZE 8
libv2001 0:0545bc9f81e0 9 #define ADDR_16BIT_SIZE 2
libv2001 0:0545bc9f81e0 10 #define AT_CMD_ID_SIZE 2
libv2001 0:0545bc9f81e0 11
libv2001 0:0545bc9f81e0 12 // Présent dans tous les frames
libv2001 0:0545bc9f81e0 13 #define START_IDX 0
libv2001 0:0545bc9f81e0 14 #define LENGTH_MSB_IDX 1
libv2001 0:0545bc9f81e0 15 #define LENGTH_LSB_IDX 2
libv2001 0:0545bc9f81e0 16 #define API_ID_IDX 3
libv2001 0:0545bc9f81e0 17 #define FRAME_MIN_SIZE 4
libv2001 0:0545bc9f81e0 18
libv2001 0:0545bc9f81e0 19 // Les API ID supportés2
libv2001 0:0545bc9f81e0 20 #define API_ID_AT_CMD 0x08
libv2001 0:0545bc9f81e0 21 #define API_ID_AT_CMD_QUEUE 0x09
libv2001 0:0545bc9f81e0 22 #define API_ID_TRANSMIT 0x10
libv2001 0:0545bc9f81e0 23 #define API_ID_REMOTE_AT_RQST 0x17
libv2001 0:0545bc9f81e0 24 #define API_ID_AT_CMD_RSP 0x88
libv2001 0:0545bc9f81e0 25 #define API_ID_MODEM_STATUS 0x8A
libv2001 0:0545bc9f81e0 26 #define API_ID_TRANSMIT_STATUS 0x8B
libv2001 0:0545bc9f81e0 27 #define API_ID_RECEIVED_PACKET 0x90
libv2001 0:0545bc9f81e0 28
libv2001 0:0545bc9f81e0 29 // Présent dans la majorité des frames
libv2001 0:0545bc9f81e0 30 #define FRAME_ID_IDX 4
libv2001 0:0545bc9f81e0 31
libv2001 0:0545bc9f81e0 32 // Spécifique pour l'AT Command
libv2001 0:0545bc9f81e0 33 #define AT_CMD_ID_IDX 5
libv2001 0:0545bc9f81e0 34 #define AT_PARAM_IDX 7
libv2001 0:0545bc9f81e0 35 #define AT_MIN_SIZE 4
libv2001 0:0545bc9f81e0 36
libv2001 0:0545bc9f81e0 37 // Spécifique pour l'AT Command Queue
libv2001 0:0545bc9f81e0 38 #define AT_QUEUE_CMD_1_IDX 5
libv2001 0:0545bc9f81e0 39 #define AT_QUEUE_CMD_2_IDX 6
libv2001 0:0545bc9f81e0 40 #define AT_QUEUE_PARAM_IDX 7
libv2001 0:0545bc9f81e0 41 #define AT_QUEUE_MIN_SIZE 4
libv2001 0:0545bc9f81e0 42
libv2001 0:0545bc9f81e0 43 // Spécifique pour la Transmit Command
libv2001 0:0545bc9f81e0 44 #define TRANSMIT_64BIT_MSB_IDX 5
libv2001 0:0545bc9f81e0 45 #define TRANSMIT_64BIT_LSB_IDX 12
libv2001 0:0545bc9f81e0 46 #define TRANSMIT_16BIT_MSB_IDX 13
libv2001 0:0545bc9f81e0 47 #define TRANSMIT_16BIT_LSB_IDX 14
libv2001 0:0545bc9f81e0 48 #define TRANSMIT_BROADCAST_IDX 15
libv2001 0:0545bc9f81e0 49 #define TRANSMIT_OPT_IDX 16
libv2001 0:0545bc9f81e0 50 #define TRANSMIT_DATA_IDX 17
libv2001 0:0545bc9f81e0 51 #define TRANSMIT_MIN_SIZE 14
libv2001 0:0545bc9f81e0 52
libv2001 0:0545bc9f81e0 53 // Les options de la Transmit Command
libv2001 0:0545bc9f81e0 54 #define TRANSMIT_DEFAULT_BROADCAST 0x00
libv2001 0:0545bc9f81e0 55 #define TRANSMIT_DEFAULT_OPT 0x00
libv2001 0:0545bc9f81e0 56
libv2001 0:0545bc9f81e0 57 // Spécifique pour la Remote AT Request Command
libv2001 0:0545bc9f81e0 58 #define REMOTE_AT_RQST_64BIT_MSB_IDX 5
libv2001 0:0545bc9f81e0 59 #define REMOTE_AT_RQST_64BIT_LSB_IDX 12
libv2001 0:0545bc9f81e0 60 #define REMOTE_AT_RQST_16BIT_MSB_IDX 13
libv2001 0:0545bc9f81e0 61 #define REMOTE_AT_RQST_16BIT_LSB_IDX 14
libv2001 0:0545bc9f81e0 62 #define REMOTE_AT_RQST_OPT_IDX 15
libv2001 0:0545bc9f81e0 63 #define REMOTE_AT_RQST_AT_CMD1_IDX 16
libv2001 0:0545bc9f81e0 64 #define REMOTE_AT_RQST_AT_CMD2_IDX 17
libv2001 0:0545bc9f81e0 65 #define REMOTE_AT_RQST_AT_PARAM_IDX 18
libv2001 0:0545bc9f81e0 66 #define REMOTE_AT_RQST_MIN_SIZE 15
libv2001 0:0545bc9f81e0 67
libv2001 0:0545bc9f81e0 68 // Les options pour la Remote AT Request Command
libv2001 0:0545bc9f81e0 69 #define REMOTE_AT_RQST_DEFAULT_OPT 0x00
libv2001 0:0545bc9f81e0 70 #define REMOTE_AT_RQST_OPT_APPLY_CHANGE 0x02
libv2001 0:0545bc9f81e0 71
libv2001 0:0545bc9f81e0 72 // Spécifique pour la AT Command Response
libv2001 0:0545bc9f81e0 73 #define AT_CMD_RSP_AT_CMD1_IDX 5
libv2001 0:0545bc9f81e0 74 #define AT_CMD_RSP_AT_CMD2_IDX 6
libv2001 0:0545bc9f81e0 75 #define AT_CMD_RSP_STATUS_IDX 7
libv2001 0:0545bc9f81e0 76 #define AT_CMD_RSP_DATA_IDX 8
libv2001 0:0545bc9f81e0 77 #define AT_CMD_RSP_MIN_SIZE 5
libv2001 0:0545bc9f81e0 78
libv2001 0:0545bc9f81e0 79 // Les status pour la AT Command Response
libv2001 0:0545bc9f81e0 80 #define AT_CMD_RSP_STATUS_OK 0x00
libv2001 0:0545bc9f81e0 81 #define AT_CMD_RSP_STATUS_ERROR 0x01
libv2001 0:0545bc9f81e0 82 #define AT_CMD_RSP_STATUS_INVALID_CMD 0x02
libv2001 0:0545bc9f81e0 83 #define AT_CMD_RSP_STATUS_INVALID_PARAM 0x03
libv2001 0:0545bc9f81e0 84 #define AT_CMD_RSP_STATUS_TX_FAILURE 0x04
libv2001 0:0545bc9f81e0 85
libv2001 0:0545bc9f81e0 86 // Spécifique pour la Modem Status Command
libv2001 0:0545bc9f81e0 87 #define MODEM_STATUS_STATUS_IDX 4
libv2001 0:0545bc9f81e0 88
libv2001 0:0545bc9f81e0 89 // Les status pour la Modem Status Command
libv2001 0:0545bc9f81e0 90 #define MODEM_STATUS_HARDWARE_RST 0x00
libv2001 0:0545bc9f81e0 91 #define MODEM_STATUS_JOINED_NETWORK 0x02
libv2001 0:0545bc9f81e0 92 #define MODEM_STATUS_DISASSOCIATED 0x03
libv2001 0:0545bc9f81e0 93 #define MODEM_STATUS_COORDINATOR_STARTED 0x06
libv2001 0:0545bc9f81e0 94
libv2001 0:0545bc9f81e0 95 // Spécifique pour la Transit Status Command
libv2001 0:0545bc9f81e0 96 #define TRANSMIT_STATUS_16BIT_MSB_IDX 5
libv2001 0:0545bc9f81e0 97 #define TRANSMIT_STATUS_16BIT_LSB_IDX 6
libv2001 0:0545bc9f81e0 98 #define TRANSMIT_STATUS_RETRY_COUNT_IDX 7
libv2001 0:0545bc9f81e0 99 #define TRANSMIT_STATUS_DELIVERY_STATUS_IDX 8
libv2001 0:0545bc9f81e0 100 #define TRANSMIT_STATUS_DISCOVERY_STATUS_IDX 9
libv2001 0:0545bc9f81e0 101
libv2001 0:0545bc9f81e0 102 #define TRANSMIT_STATUS_OK 0x00
libv2001 0:0545bc9f81e0 103
libv2001 0:0545bc9f81e0 104 // Spécifique pour la Received Packet Command
libv2001 0:0545bc9f81e0 105 #define RECEIVED_PACKET_64BIT_MSB_IDX 4
libv2001 0:0545bc9f81e0 106 #define RECEIVED_PACKET_64BIT_LSB_IDX 11
libv2001 0:0545bc9f81e0 107 #define RECEIVED_PACKET_16BIT_MSB_IDX 12
libv2001 0:0545bc9f81e0 108 #define RECEIVED_PACKET_16BIT_LSB_IDX 13
libv2001 0:0545bc9f81e0 109 #define RECEIVED_PACKET_OPT_IDX 14
libv2001 0:0545bc9f81e0 110 #define RECEIVED_PACKET_DATA_IDX 15
libv2001 0:0545bc9f81e0 111 #define RECEIVED_PACKET_MIN_SIZE 12
libv2001 0:0545bc9f81e0 112
libv2001 0:0545bc9f81e0 113 inline uint16_t GetFrameLength(char * buffer){
libv2001 0:0545bc9f81e0 114 return (((uint16_t)buffer[LENGTH_MSB_IDX]) << 8) + buffer[LENGTH_LSB_IDX];
libv2001 0:0545bc9f81e0 115 }
libv2001 0:0545bc9f81e0 116
libv2001 0:0545bc9f81e0 117 bool ValidateCheckSum(char * buffer){
libv2001 0:0545bc9f81e0 118 uint16_t length = GetFrameLength(buffer);
libv2001 0:0545bc9f81e0 119
libv2001 0:0545bc9f81e0 120 char sum = 0;
libv2001 0:0545bc9f81e0 121 for (int i = 0; i <= length; ++i){
libv2001 0:0545bc9f81e0 122 sum += buffer[i + API_ID_IDX];
libv2001 0:0545bc9f81e0 123 }
libv2001 0:0545bc9f81e0 124
libv2001 0:0545bc9f81e0 125 return sum == 0xff;
libv2001 0:0545bc9f81e0 126 }
libv2001 0:0545bc9f81e0 127
libv2001 0:0545bc9f81e0 128 inline uint16_t GetAtParamLength(char * buffer){
libv2001 0:0545bc9f81e0 129 return GetFrameLength(buffer) - AT_MIN_SIZE;
libv2001 0:0545bc9f81e0 130 }
libv2001 0:0545bc9f81e0 131
libv2001 0:0545bc9f81e0 132 inline uint16_t GetAtQueueParamLength(char * buffer){
libv2001 0:0545bc9f81e0 133 return GetFrameLength(buffer) - AT_QUEUE_MIN_SIZE;
libv2001 0:0545bc9f81e0 134 }
libv2001 0:0545bc9f81e0 135
libv2001 0:0545bc9f81e0 136 inline uint16_t GetTransmitDataLength(char * buffer){
libv2001 0:0545bc9f81e0 137 return GetFrameLength(buffer) - TRANSMIT_MIN_SIZE;
libv2001 0:0545bc9f81e0 138 }
libv2001 0:0545bc9f81e0 139
libv2001 0:0545bc9f81e0 140 inline uint16_t GetRemoteAtRequestParamLength(char * buffer){
libv2001 0:0545bc9f81e0 141 return GetFrameLength(buffer) - REMOTE_AT_RQST_MIN_SIZE;
libv2001 0:0545bc9f81e0 142 }
libv2001 0:0545bc9f81e0 143
libv2001 0:0545bc9f81e0 144 inline uint16_t GetAtResponseParamLength(char * buffer){
libv2001 0:0545bc9f81e0 145 return GetFrameLength(buffer) - AT_CMD_RSP_MIN_SIZE;
libv2001 0:0545bc9f81e0 146 }
libv2001 0:0545bc9f81e0 147
libv2001 0:0545bc9f81e0 148 inline uint16_t GetReceivedPacketDataLength(char * buffer){
libv2001 0:0545bc9f81e0 149 return GetFrameLength(buffer) - RECEIVED_PACKET_MIN_SIZE;
libv2001 0:0545bc9f81e0 150 }
libv2001 0:0545bc9f81e0 151
libv2001 0:0545bc9f81e0 152 #endif