// // Created by macheng on 2018/5/2. // #ifndef _INSTANCE_MESSAGE_H #define _INSTANCE_MESSAGE_H #include "deca_types.h" //DecaRTLS frame function codes #define RTLS_DEMO_MSG_TAG_POLL (0x81) // Tag poll message #define RTLS_DEMO_MSG_ANCH_RESP (0x70) // Anchor response to poll #define RTLS_DEMO_MSG_ANCH_POLL (0x71) // Anchor to anchor poll message #define RTLS_DEMO_MSG_ANCH_RESP2 (0x72) // Anchor response to poll from anchor #define RTLS_DEMO_MSG_ANCH_FINAL (0x73) // Anchor final massage back to Anchor #define RTLS_DEMO_MSG_TAG_FINAL (0x82) // Tag final massage back to Anchor //application data message byte offsets #define FCODE 0 // Function code is 1st byte of messageData #define PTXT 2 // Poll TX time #define RRXT0ADDR 7 // A0 Response RX address #define RRXT0 9 // A0 Response RX time #define RRXT1ADDR 14 // A1 Response RX address #define RRXT1 16 // A1 Response RX time #define RRXT2ADDR 21 // A2 Response RX address #define RRXT2 23 // A2 Response RX time #define RRXT3ADDR 28 // A3 Response RX address #define RRXT3 30 // A3 Response RX time #define FTXT 35 // Final TX time #define RES_TAG_SLP0 1 // Response tag sleep correction LSB #define RES_TAG_SLP1 2 // Response tag sleep correction MSB #define TOFR 3 // ToF (n-1) 4 bytes #define TOFRN 7 // range number 1 byte #define TAGADDR 8 #define RESP_CONTROL 10 // Control byte #define RESP_CMD 11 // Command byte #define RESP_TIME1 12 // Time 1 byte #define RESP_TIME2 13 // Time 1 byte #define RESP_TIME3 14 // Time 1 byte #define RESP_TIME4 15 // Time 1 byte #define POLL_RNUM 1 // Poll message range number #define POLL_TAG_STATUS 2 // Poll tag current status #define POLL_TAG_POWER 3 // Poll tag power #define POLL_TAG_HEARTBEAT 4 // Poll tag heart beat #define POLL_TAG_RESV1 5 // Poll tag reserved 1 #define POLL_TAG_RESV2 6 // Poll tag reserved 2 #define POLL_TAG_RESV3 7 // Poll tag reserved 3 #define POLL_TAG_RESV4 8 // Poll tag reserved 4 #define POLL_TAG_RESV5 9 // Poll tag reserved 5 #define TIMESTAME_LENGTH 5 #define TIMEOFFLY_LENGTH 4 //lengths including the Decaranging Message Function Code byte #if 0 #define TAG_POLL_MSG_LEN 2 // FunctionCode(1), Range Num (1) #define ANCH_RESPONSE_MSG_LEN 8 // FunctionCode(1), Sleep Correction Time (2), Measured_TOF_Time(4), Range Num (1) (previous) #define TAG_FINAL_MSG_LEN 33 // FunctionCode(1), Range Num (1), Poll_TxTime(5), // Resp0_RxTime(5), Resp1_RxTime(5), Resp2_RxTime(5), Resp3_RxTime(5), Final_TxTime(5), Valid Response Mask (1) #else #define TAG_POLL_MSG_LEN 10 // FunctionCode(1), Range Num (1) #define ANCH_RESPONSE_MSG_LEN 16 // FunctionCode(1), Sleep Correction Time (2), Measured_TOF_Time(4), Range Num (1) (previous) #define TAG_FINAL_MSG_LEN 40 // FunctionCode(1), Range Num (1), Poll_TxTime(5), // Resp0_RxTime(5), Resp1_RxTime(5), Resp2_RxTime(5), Resp3_RxTime(5), Final_TxTime(5), Valid Response Mask (1) #endif #define MAX_MAC_MSG_DATA_LEN (TAG_FINAL_MSG_LEN) //max message len of the above #define ADDR_BYTE_SIZE_L (8) #define ADDR_BYTE_SIZE_S (2) #define STANDARD_FRAME_SIZE 127 //#define STANDARD_FRAME_SIZE 80 #define FRAME_CONTROL_BYTES 2 #define FRAME_SEQ_NUM_BYTES 1 #define FRAME_PANID 2 #define FRAME_CRC 2 #define FRAME_SOURCE_ADDRESS_S (ADDR_BYTE_SIZE_S) #define FRAME_DEST_ADDRESS_S (ADDR_BYTE_SIZE_S) #define FRAME_SOURCE_ADDRESS_L (ADDR_BYTE_SIZE_L) #define FRAME_DEST_ADDRESS_L (ADDR_BYTE_SIZE_L) #define FRAME_CTRLP (FRAME_CONTROL_BYTES + FRAME_SEQ_NUM_BYTES + FRAME_PANID) //5 #define FRAME_CRTL_AND_ADDRESS_L (FRAME_DEST_ADDRESS_L + FRAME_SOURCE_ADDRESS_L + FRAME_CTRLP) //21 bytes for 64-bit addresses) #define FRAME_CRTL_AND_ADDRESS_S (FRAME_DEST_ADDRESS_S + FRAME_SOURCE_ADDRESS_S + FRAME_CTRLP) //9 bytes for 16-bit addresses) #define FRAME_CRTL_AND_ADDRESS_LS (FRAME_DEST_ADDRESS_L + FRAME_SOURCE_ADDRESS_S + FRAME_CTRLP) //15 bytes for 1 16-bit address and 1 64-bit address) #define MAX_USER_PAYLOAD_STRING_LL (STANDARD_FRAME_SIZE-FRAME_CRTL_AND_ADDRESS_L-TAG_FINAL_MSG_LEN-FRAME_CRC) //127 - 21 - 16 - 2 = 88 #define MAX_USER_PAYLOAD_STRING_SS (STANDARD_FRAME_SIZE-FRAME_CRTL_AND_ADDRESS_S-TAG_FINAL_MSG_LEN-FRAME_CRC) //127 - 9 - 16 - 2 = 100 #define MAX_USER_PAYLOAD_STRING_LS (STANDARD_FRAME_SIZE-FRAME_CRTL_AND_ADDRESS_LS-TAG_FINAL_MSG_LEN-FRAME_CRC) //127 - 15 - 16 - 2 = 94 //NOTE: the user payload assumes that there are only 88 "free" bytes to be used for the user message (it does not scale according to the addressing modes) #define MAX_USER_PAYLOAD_STRING MAX_USER_PAYLOAD_STRING_LL // This file defines data and functions for access to Parameters in the Device //message structure for Poll, Response and Final message typedef enum _ext_cmd_type_ { EXTCMD_NONE = 0, EXTCMD_ANCFRAMEPEROID = 1, EXTCMD_TIMESET = 2, EXTCMD_ACKSOS = 3, EXTCMD_SHOWTXTIN = 4, EXTCMD_SHOWTXTOUT = 5, EXTCMD_MODADDR = 6, EXTCMD_MODTXPOWER = 7, EXTCMD_RESTART = 8, EXTCMD_MASK = 0xf, }eExtandCommandType; typedef struct _ext_command_ { eExtandCommandType command; uint32_t param; }stExtandCommand; typedef struct { uint8_t frameCtrl[2]; // frame control bytes 00-01 uint8_t seqNum; // sequence_number 02 uint8_t panID[2]; // PAN ID 03-04 uint8_t dstAddr[ADDR_BYTE_SIZE_L]; // 05-12 using 64 bit addresses uint8_t srcAddr[ADDR_BYTE_SIZE_L]; // 13-20 using 64 bit addresses uint8_t messageData[MAX_USER_PAYLOAD_STRING_LL] ; // 22-124 (application data and any user payload) uint8_t fcs[2] ; // 125-126 we allow space for the CRC as it is logically part of the message. However ScenSor TX calculates and adds these bytes. } srd_msg_dlsl ; typedef struct { uint8_t frameCtrl[2]; // frame control bytes 00-01 uint8_t seqNum; // sequence_number 02 uint8_t panID[2]; // PAN ID 03-04 uint8_t dstAddr[ADDR_BYTE_SIZE_S]; // 05-06 uint8_t srcAddr[ADDR_BYTE_SIZE_S]; // 07-08 uint8_t messageData[MAX_USER_PAYLOAD_STRING_SS] ; // 09-124 (application data and any user payload) uint8_t fcs[2] ; // 125-126 we allow space for the CRC as it is logically part of the message. However ScenSor TX calculates and adds these bytes. } srd_msg_dsss ; typedef struct { uint8_t frameCtrl[2]; // frame control bytes 00-01 uint8_t seqNum; // sequence_number 02 uint8_t panID[2]; // PAN ID 03-04 uint8_t dstAddr[ADDR_BYTE_SIZE_L]; // 05-12 using 64 bit addresses uint8_t srcAddr[ADDR_BYTE_SIZE_S]; // 13-14 uint8_t messageData[MAX_USER_PAYLOAD_STRING_LS] ; // 15-124 (application data and any user payload) uint8_t fcs[2] ; // 125-126 we allow space for the CRC as it is logically part of the message. However ScenSor TX calculates and adds these bytes. } srd_msg_dlss ; typedef struct { uint8_t frameCtrl[2]; // frame control bytes 00-01 uint8_t seqNum; // sequence_number 02 uint8_t panID[2]; // PAN ID 03-04 uint8_t dstAddr[ADDR_BYTE_SIZE_S]; // 05-06 uint8_t srcAddr[ADDR_BYTE_SIZE_L]; // 07-14 using 64 bit addresses uint8_t messageData[MAX_USER_PAYLOAD_STRING_LS] ; // 15-124 (application data and any user payload) uint8_t fcs[2] ; // 125-126 we allow space for the CRC as it is logically part of the message. However ScenSor TX calculates and adds these bytes. } srd_msg_dssl ; typedef struct { srd_msg_dsss content; // ranging message frame with 16-bit addresses uint16_t psduLength ; // used for storing the TX frame length uint8_t frameSN; // modulo 256 frame sequence number - it is incremented for each new frame transmission } message_frame; #endif //MESSAGE_H