message.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. //
  2. // Created by macheng on 2018/5/2.
  3. //
  4. #ifndef _INSTANCE_MESSAGE_H
  5. #define _INSTANCE_MESSAGE_H
  6. #include "deca_types.h"
  7. //DecaRTLS frame function codes
  8. #define RTLS_DEMO_MSG_TAG_POLL (0x81) // Tag poll message
  9. #define RTLS_DEMO_MSG_ANCH_RESP (0x70) // Anchor response to poll
  10. #define RTLS_DEMO_MSG_ANCH_POLL (0x71) // Anchor to anchor poll message
  11. #define RTLS_DEMO_MSG_ANCH_RESP2 (0x72) // Anchor response to poll from anchor
  12. #define RTLS_DEMO_MSG_ANCH_FINAL (0x73) // Anchor final massage back to Anchor
  13. #define RTLS_DEMO_MSG_TAG_FINAL (0x82) // Tag final massage back to Anchor
  14. //application data message byte offsets
  15. #define FCODE 0 // Function code is 1st byte of messageData
  16. #define PTXT 2 // Poll TX time
  17. #define RRXT0ADDR 7 // A0 Response RX address
  18. #define RRXT0 9 // A0 Response RX time
  19. #define RRXT1ADDR 14 // A1 Response RX address
  20. #define RRXT1 16 // A1 Response RX time
  21. #define RRXT2ADDR 21 // A2 Response RX address
  22. #define RRXT2 23 // A2 Response RX time
  23. #define RRXT3ADDR 28 // A3 Response RX address
  24. #define RRXT3 30 // A3 Response RX time
  25. #define FTXT 35 // Final TX time
  26. #define RES_TAG_SLP0 1 // Response tag sleep correction LSB
  27. #define RES_TAG_SLP1 2 // Response tag sleep correction MSB
  28. #define TOFR 3 // ToF (n-1) 4 bytes
  29. #define TOFRN 7 // range number 1 byte
  30. #define TAGADDR 8
  31. #define RESP_CONTROL 10 // Control byte
  32. #define RESP_CMD 11 // Command byte
  33. #define RESP_TIME1 12 // Time 1 byte
  34. #define RESP_TIME2 13 // Time 1 byte
  35. #define RESP_TIME3 14 // Time 1 byte
  36. #define RESP_TIME4 15 // Time 1 byte
  37. #define POLL_RNUM 1 // Poll message range number
  38. #define POLL_TAG_STATUS 2 // Poll tag current status
  39. #define POLL_TAG_POWER 3 // Poll tag power
  40. #define POLL_TAG_HEARTBEAT 4 // Poll tag heart beat
  41. #define POLL_TAG_RESV1 5 // Poll tag reserved 1
  42. #define POLL_TAG_RESV2 6 // Poll tag reserved 2
  43. #define POLL_TAG_RESV3 7 // Poll tag reserved 3
  44. #define POLL_TAG_RESV4 8 // Poll tag reserved 4
  45. #define POLL_TAG_RESV5 9 // Poll tag reserved 5
  46. #define TIMESTAME_LENGTH 5
  47. #define TIMEOFFLY_LENGTH 4
  48. //lengths including the Decaranging Message Function Code byte
  49. #if 0
  50. #define TAG_POLL_MSG_LEN 2 // FunctionCode(1), Range Num (1)
  51. #define ANCH_RESPONSE_MSG_LEN 8 // FunctionCode(1), Sleep Correction Time (2), Measured_TOF_Time(4), Range Num (1) (previous)
  52. #define TAG_FINAL_MSG_LEN 33 // FunctionCode(1), Range Num (1), Poll_TxTime(5),
  53. // Resp0_RxTime(5), Resp1_RxTime(5), Resp2_RxTime(5), Resp3_RxTime(5), Final_TxTime(5), Valid Response Mask (1)
  54. #else
  55. #define TAG_POLL_MSG_LEN 10 // FunctionCode(1), Range Num (1)
  56. #define ANCH_RESPONSE_MSG_LEN 16 // FunctionCode(1), Sleep Correction Time (2), Measured_TOF_Time(4), Range Num (1) (previous)
  57. #define TAG_FINAL_MSG_LEN 40 // FunctionCode(1), Range Num (1), Poll_TxTime(5),
  58. // Resp0_RxTime(5), Resp1_RxTime(5), Resp2_RxTime(5), Resp3_RxTime(5), Final_TxTime(5), Valid Response Mask (1)
  59. #endif
  60. #define MAX_MAC_MSG_DATA_LEN (TAG_FINAL_MSG_LEN) //max message len of the above
  61. #define ADDR_BYTE_SIZE_L (8)
  62. #define ADDR_BYTE_SIZE_S (2)
  63. #define STANDARD_FRAME_SIZE 127
  64. //#define STANDARD_FRAME_SIZE 80
  65. #define FRAME_CONTROL_BYTES 2
  66. #define FRAME_SEQ_NUM_BYTES 1
  67. #define FRAME_PANID 2
  68. #define FRAME_CRC 2
  69. #define FRAME_SOURCE_ADDRESS_S (ADDR_BYTE_SIZE_S)
  70. #define FRAME_DEST_ADDRESS_S (ADDR_BYTE_SIZE_S)
  71. #define FRAME_SOURCE_ADDRESS_L (ADDR_BYTE_SIZE_L)
  72. #define FRAME_DEST_ADDRESS_L (ADDR_BYTE_SIZE_L)
  73. #define FRAME_CTRLP (FRAME_CONTROL_BYTES + FRAME_SEQ_NUM_BYTES + FRAME_PANID) //5
  74. #define FRAME_CRTL_AND_ADDRESS_L (FRAME_DEST_ADDRESS_L + FRAME_SOURCE_ADDRESS_L + FRAME_CTRLP) //21 bytes for 64-bit addresses)
  75. #define FRAME_CRTL_AND_ADDRESS_S (FRAME_DEST_ADDRESS_S + FRAME_SOURCE_ADDRESS_S + FRAME_CTRLP) //9 bytes for 16-bit addresses)
  76. #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)
  77. #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
  78. #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
  79. #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
  80. //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)
  81. #define MAX_USER_PAYLOAD_STRING MAX_USER_PAYLOAD_STRING_LL
  82. // This file defines data and functions for access to Parameters in the Device
  83. //message structure for Poll, Response and Final message
  84. typedef enum _ext_cmd_type_
  85. {
  86. EXTCMD_NONE = 0,
  87. EXTCMD_ANCFRAMEPEROID = 1,
  88. EXTCMD_TIMESET = 2,
  89. EXTCMD_ACKSOS = 3,
  90. EXTCMD_SHOWTXTIN = 4,
  91. EXTCMD_SHOWTXTOUT = 5,
  92. EXTCMD_MODADDR = 6,
  93. EXTCMD_MODTXPOWER = 7,
  94. EXTCMD_RESTART = 8,
  95. EXTCMD_MASK = 0xf,
  96. }eExtandCommandType;
  97. typedef struct _ext_command_
  98. {
  99. eExtandCommandType command;
  100. uint32_t param;
  101. }stExtandCommand;
  102. typedef struct
  103. {
  104. uint8_t frameCtrl[2]; // frame control bytes 00-01
  105. uint8_t seqNum; // sequence_number 02
  106. uint8_t panID[2]; // PAN ID 03-04
  107. uint8_t dstAddr[ADDR_BYTE_SIZE_L]; // 05-12 using 64 bit addresses
  108. uint8_t srcAddr[ADDR_BYTE_SIZE_L]; // 13-20 using 64 bit addresses
  109. uint8_t messageData[MAX_USER_PAYLOAD_STRING_LL] ; // 22-124 (application data and any user payload)
  110. 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.
  111. } srd_msg_dlsl ;
  112. typedef struct
  113. {
  114. uint8_t frameCtrl[2]; // frame control bytes 00-01
  115. uint8_t seqNum; // sequence_number 02
  116. uint8_t panID[2]; // PAN ID 03-04
  117. uint8_t dstAddr[ADDR_BYTE_SIZE_S]; // 05-06
  118. uint8_t srcAddr[ADDR_BYTE_SIZE_S]; // 07-08
  119. uint8_t messageData[MAX_USER_PAYLOAD_STRING_SS] ; // 09-124 (application data and any user payload)
  120. 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.
  121. } srd_msg_dsss ;
  122. typedef struct
  123. {
  124. uint8_t frameCtrl[2]; // frame control bytes 00-01
  125. uint8_t seqNum; // sequence_number 02
  126. uint8_t panID[2]; // PAN ID 03-04
  127. uint8_t dstAddr[ADDR_BYTE_SIZE_L]; // 05-12 using 64 bit addresses
  128. uint8_t srcAddr[ADDR_BYTE_SIZE_S]; // 13-14
  129. uint8_t messageData[MAX_USER_PAYLOAD_STRING_LS] ; // 15-124 (application data and any user payload)
  130. 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.
  131. } srd_msg_dlss ;
  132. typedef struct
  133. {
  134. uint8_t frameCtrl[2]; // frame control bytes 00-01
  135. uint8_t seqNum; // sequence_number 02
  136. uint8_t panID[2]; // PAN ID 03-04
  137. uint8_t dstAddr[ADDR_BYTE_SIZE_S]; // 05-06
  138. uint8_t srcAddr[ADDR_BYTE_SIZE_L]; // 07-14 using 64 bit addresses
  139. uint8_t messageData[MAX_USER_PAYLOAD_STRING_LS] ; // 15-124 (application data and any user payload)
  140. 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.
  141. } srd_msg_dssl ;
  142. typedef struct {
  143. srd_msg_dsss content; // ranging message frame with 16-bit addresses
  144. uint16_t psduLength ; // used for storing the TX frame length
  145. uint8_t frameSN; // modulo 256 frame sequence number - it is incremented for each new frame transmission
  146. } message_frame;
  147. #endif //MESSAGE_H