1
0

antfsmessage.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /*
  2. This software is subject to the license described in the License.txt file
  3. included with this software distribution. You may not use this file except
  4. in compliance with this license.
  5. Copyright (c) Dynastream Innovations Inc. 2016
  6. All rights reserved.
  7. */
  8. #if !defined(ANTFS_MESSAGES_H)
  9. #define ANTFS_MESSAGES_H
  10. //////////////////////////////////////////////////////////////////////////////////
  11. // Private ANT-FS Definitions for both Host and Client
  12. //////////////////////////////////////////////////////////////////////////////////
  13. // ANT Application Configuration
  14. #define ANTFS_NETWORK ((UCHAR) 0)
  15. #define ANTFS_CHANNEL ((UCHAR) 0)
  16. #define NETWORK_KEY {0xA8, 0xA4, 0x23, 0xB9, 0xF5, 0x5E, 0x63, 0xC1} // ANTFS Network Key
  17. // Default Link Configuration
  18. #define ANTFS_DEVICE_TYPE ((UCHAR) 1)
  19. #define ANTFS_TRANSMISSION_TYPE ((UCHAR) 5)
  20. #define ANTFS_DEVICE_NUMBER ((USHORT) 0) // 0 for searching (host)
  21. #define ANTFS_CLIENT_NUMBER ((USHORT) 0x0F0F) // if serial number's two LSB are zero (client)
  22. //#define ANTFS_MESSAGE_PERIOD ((USHORT) 65535) // 0.5Hz
  23. #define ANTFS_MESSAGE_PERIOD ((USHORT) 4096) // 8 Hz
  24. #define ANTFS_RF_FREQ ((UCHAR) 50) // 2450 MHz for ANT FS
  25. #define ANTFS_SEARCH_TIMEOUT ((UCHAR) 255) // Longest search timeout.
  26. ///////////////////////////////////////////////////////////////////////
  27. // Always On / Transport Layer Command/Response definitions
  28. ///////////////////////////////////////////////////////////////////////
  29. #define ANTFS_BEACON_ID ((UCHAR) 0x43)
  30. #define ANTFS_COMMAND_RESPONSE_ID ((UCHAR) 0x44)
  31. #define ANTFS_COMMAND_ID ((UCHAR) 0x44)
  32. #define ANTFS_RESPONSE_ID ((UCHAR) 0x44)
  33. #define ANTFS_REQUEST_PAGE_ID ((UCHAR) 0x46)
  34. // Commands
  35. #define ANTFS_CMD_NONE ((UCHAR) 0x00)
  36. #define ANTFS_STATUS_ID ((UCHAR) 0x01)
  37. #define ANTFS_LINK_ID ((UCHAR) 0x02)
  38. #define ANTFS_CONNECT_ID ((UCHAR) 0x02)
  39. #define ANTFS_DISCONNECT_ID ((UCHAR) 0x03)
  40. #define ANTFS_AUTHENTICATE_ID ((UCHAR) 0x04)
  41. #define ANTFS_PING_ID ((UCHAR) 0x05)
  42. #define ANTFS_DOWNLOAD_SMALL_ID ((UCHAR) 0x06)
  43. #define ANTFS_UPLOAD_SMALL_ID ((UCHAR) 0x07)
  44. #define ANTFS_DOWNLOAD_BIG_ID ((UCHAR) 0x09)
  45. #define ANTFS_DOWNLOAD_ID ((UCHAR) 0x09)
  46. #define ANTFS_UPLOAD_BIG_ID ((UCHAR) 0x0A)
  47. #define ANTFS_UPLOAD_REQUEST_ID ((UCHAR) 0x0A)
  48. #define ANTFS_ERASE_ID ((UCHAR) 0x0B)
  49. #define ANTFS_UPLOAD_DATA_ID ((UCHAR) 0x0C)
  50. #define ANTFS_SEND_DIRECT_ID ((UCHAR) 0x0D)
  51. // Responses
  52. #define ANTFS_RESPONSE_AUTH_ID ((UCHAR) 0x84)
  53. #define ANTFS_RESPONSE_DOWNLOAD_SMALL_ID ((UCHAR) 0x86)
  54. #define ANTFS_RESPONSE_DOWNLOAD_BIG_ID ((UCHAR) 0x89)
  55. #define ANTFS_RESPONSE_DOWNLOAD_ID ((UCHAR) 0x89)
  56. #define ANTFS_RESPONSE_UPLOAD_ID ((UCHAR) 0x8A)
  57. #define ANTFS_RESPONSE_ERASE_ID ((UCHAR) 0x8B)
  58. #define ANTFS_RESPONSE_UPLOAD_COMPLETE_ID ((UCHAR) 0x8C)
  59. #define ANTFS_RESPONSE_SEND_DIRECT_ID ((UCHAR) 0x8D)
  60. // Request
  61. #define ANTFS_REQUEST_SESSION ((UCHAR) 0x02)
  62. // Message offsets
  63. #define ANTFS_CONNECTION_OFFSET 0
  64. #define ANTFS_COMMAND_OFFSET 1
  65. #define ANTFS_RESPONSE_OFFSET 1
  66. // Beacon definitions
  67. #define STATUS1_OFFSET 1
  68. #define BEACON_PERIOD_SHIFT ((UCHAR) 0x00)
  69. #define BEACON_PERIOD_MASK ((UCHAR) (0x07 << BEACON_PERIOD_SHIFT))
  70. #define BEACON_PERIOD_0_5_HZ ((UCHAR) (0x00 << BEACON_PERIOD_SHIFT))
  71. #define BEACON_PERIOD_1_HZ ((UCHAR) (0x01 << BEACON_PERIOD_SHIFT))
  72. #define BEACON_PERIOD_2_HZ ((UCHAR) (0x02 << BEACON_PERIOD_SHIFT))
  73. #define BEACON_PERIOD_4_HZ ((UCHAR) (0x03 << BEACON_PERIOD_SHIFT))
  74. #define BEACON_PERIOD_8_HZ ((UCHAR) (0x04 << BEACON_PERIOD_SHIFT))
  75. #define BEACON_PERIOD_KEEP ((UCHAR) (0x07 << BEACON_PERIOD_SHIFT))
  76. #define PAIRING_AVAILABLE_FLAG_SHIFT 3
  77. #define PAIRING_AVAILABLE_FLAG_MASK ((UCHAR) (0x01 << PAIRING_AVAILABLE_FLAG_SHIFT))
  78. #define UPLOAD_ENABLED_FLAG_SHIFT 4
  79. #define UPLOAD_ENABLED_FLAG_MASK ((UCHAR) (0x01 << UPLOAD_ENABLED_FLAG_SHIFT))
  80. #define DATA_AVAILABLE_FLAG_SHIFT 5
  81. #define DATA_AVAILABLE_FLAG_MASK ((UCHAR) (0x01 << DATA_AVAILABLE_FLAG_SHIFT))
  82. #define REQUEST_TO_SEND_FLAG_SHIFT 6
  83. #define REQUEST_TO_SEND_FLAG_MASK ((UCHAR) (0x01 << REQUEST_TO_SEND_FLAG_SHIFT))
  84. #define STATUS2_OFFSET 2
  85. #define REMOTE_DEVICE_STATE_SHIFT 0
  86. #define REMOTE_DEVICE_STATE_MASK ((UCHAR) (0x0F << REMOTE_DEVICE_STATE_SHIFT))
  87. #define REMOTE_DEVICE_STATE_LINK ((UCHAR) 0x00)
  88. #define REMOTE_DEVICE_STATE_AUTH ((UCHAR) 0x01)
  89. #define REMOTE_DEVICE_STATE_TRANS ((UCHAR) 0x02)
  90. #define REMOTE_DEVICE_STATE_BUSY ((UCHAR) 0x03)
  91. #define REMOTE_DEVICE_STATE_LAST_VALID REMOTE_DEVICE_STATE_BUSY
  92. #define REMOTE_DEVICE_BEACON_NOT_FOUND ((UCHAR) 0x80) //Valid states are in range 0x0F, so this avoids all valid states
  93. #define AUTHENTICATION_TYPE_OFFSET 3
  94. #define DEVICE_TYPE_OFFSET_LOW 4
  95. #define DEVICE_TYPE_OFFSET_HIGH 5
  96. #define MANUFACTURER_ID_OFFSET_LOW 6
  97. #define MANUFACTURER_ID_OFFSET_HIGH 7
  98. #define HOST_ID_OFFSET 4
  99. // Connect Command
  100. #define TRANSPORT_CHANNEL_FREQ_OFFSET 2
  101. #define TRANSPORT_CHANNEL_PERIOD 3
  102. // Disconnect Command
  103. #define DISCONNECT_COMMAND_TYPE_OFFSET 2
  104. #define DISCONNECT_TIME_DURATION_OFFSET 3
  105. #define DISCONNECT_APP_DURATION_OFFSET 4
  106. #define DISCONNECT_COMMAND_LINK ((UCHAR) 0x00)
  107. #define DISCONNECT_COMMAND_BROADCAST ((UCHAR) 0x01)
  108. // Authenticate Command & Auth Types
  109. #define AUTH_COMMAND_TYPE_OFFSET 2
  110. #define AUTH_COMMAND_GOTO_TRANSPORT ((UCHAR) 0x00)
  111. #define AUTH_COMMAND_REQ_SERIAL_NUM ((UCHAR) 0x01)
  112. #define AUTH_COMMAND_PAIR ((UCHAR) 0x02)
  113. #define AUTH_COMMAND_PASSKEY ((UCHAR) 0x03)
  114. #define AUTH_FRIENDLY_NAME_LENGTH_OFFSET 3
  115. #define AUTH_HOST_SERIAL_NUMBER_OFFSET 4
  116. // Auth Response
  117. #define AUTH_RESPONSE_OFFSET 2
  118. #define AUTH_RESPONSE_NA ((UCHAR) 0x00)
  119. #define AUTH_RESPONSE_ACCEPT ((UCHAR) 0x01)
  120. #define AUTH_RESPONSE_REJECT ((UCHAR) 0x02)
  121. #define AUTH_PASSWORD_LENGTH_OFFSET 3
  122. #define AUTH_REMOTE_SERIAL_NUMBER_OFFSET 4
  123. // Download/Upload/Erase Commands
  124. #define DATA_INDEX_OFFSET 2
  125. #define DATA_OFFSET_SMALL_OFFSET 4
  126. #define MAX_BLOCK_SIZE_SMALL_OFFSET 6
  127. #define BYTES_REMAINING_SMALL_OFFSET 6
  128. // Download
  129. #define DOWNLOAD_DATA_OFFSET_OFFSET 4
  130. #define DOWNLOAD_DATA_INITIAL_OFFSET 1
  131. #define DOWNLOAD_DATA_CRC_OFFSET 2
  132. #define DOWNLOAD_DATA_SIZE_OFFSET 4
  133. #define DOWNLOAD_INITIAL_REQUEST_OFFSET (DOWNLOAD_DATA_INITIAL_OFFSET + 8)
  134. #define DOWNLOAD_CRC_SEED_OFFSET (DOWNLOAD_DATA_CRC_OFFSET + 8)
  135. #define DOWNLOAD_MAX_BLOCK_SIZE_OFFSET (DOWNLOAD_DATA_SIZE_OFFSET + 8)
  136. // Download Response
  137. #define DOWNLOAD_RESPONSE_OFFSET 2
  138. #define DOWNLOAD_RESPONSE_OK ((UCHAR) 0x00)
  139. #define DOWNLOAD_RESPONSE_DOES_NOT_EXIST ((UCHAR) 0x01)
  140. #define DOWNLOAD_RESPONSE_NOT_DOWNLOADABLE ((UCHAR) 0x02)
  141. #define DOWNLOAD_RESPONSE_NOT_READY ((UCHAR) 0x03)
  142. #define DOWNLOAD_RESPONSE_REQUEST_INVALID ((UCHAR) 0x04)
  143. #define DOWNLOAD_RESPONSE_CRC_FAILED ((UCHAR) 0x05)
  144. #define DOWNLOAD_RESPONSE_BLOCK_SIZE_OFFSET 4
  145. #define DOWNLOAD_RESPONSE_DATA_OFFSET_OFFSET 0 //This is really 8 but is set to 0 because we are reading it from the rx buffer from the second packet of the transfer
  146. #define DOWNLOAD_RESPONSE_FILE_SIZE_OFFSET 4 //This is really 12 but is set to 4 because we are reading it from the rx buffer from the second packet of the transfer
  147. #define DOWNLOAD_RESPONSE_CRC_OFFSET 6
  148. // Upload
  149. #define UPLOAD_MAX_SIZE_OFFSET 4
  150. #define UPLOAD_DATA_OFFSET_OFFSET 12
  151. // Upload Response
  152. #define UPLOAD_RESPONSE_OFFSET 2
  153. #define UPLOAD_RESPONSE_OK ((UCHAR) 0x00)
  154. #define UPLOAD_RESPONSE_DOES_NOT_EXIST ((UCHAR) 0x01)
  155. #define UPLOAD_RESPONSE_NOT_WRITEABLE ((UCHAR) 0x02)
  156. #define UPLOAD_RESPONSE_INSUFFICIENT_SPACE ((UCHAR) 0x03)
  157. #define UPLOAD_RESPONSE_REQUEST_INVALID ((UCHAR) 0x04)
  158. #define UPLOAD_RESPONSE_NOT_READY ((UCHAR) 0x05)
  159. #define UPLOAD_RESPONSE_LAST_OFFSET_OFFSET 4
  160. #define UPLOAD_RESPONSE_MAX_SIZE_OFFSET 8
  161. #define UPLOAD_RESPONSE_BLOCK_SIZE_OFFSET 12
  162. #define UPLOAD_RESPONSE_CRC_OFFSET 22
  163. // Upload Data
  164. #define UPLOAD_DATA_CRC_SEED_OFFSET 2
  165. #define UPLOAD_DATA_DATA_OFFSET_OFFSET 4
  166. #define UPLOAD_DATA_CRC_OFFSET 6 //This is set to 6 because the CRC starts on byte 6 of the last packet
  167. #define UPLOAD_DATA_MESG_OVERHEAD 16 //Number of bytes of overhead contained in the upload data message
  168. // Erase Response
  169. #define ERASE_RESPONSE_OFFSET 2
  170. #define ERASE_RESPONSE_OK ((UCHAR) 0x00)
  171. #define ERASE_RESPONSE_REJECT ((UCHAR) 0x01)
  172. // ANT-FS Request Page
  173. #define REQUEST_COMMAND_TYPE_OFFSET 7
  174. #define REQUEST_PAGE_NUMBER_OFFSET 6
  175. #define REQUEST_TX_RESPONSE_OFFSET 5
  176. #define REQUEST_PAGE_INVALID ((UCHAR) 0xFF)
  177. // Timeouts are in milliseconds
  178. // NOTE: Some of these values are runtime-configurable; check with ANTFS_CONFIG_PARAMETERS definition and ANTFSHost::cfgParams.
  179. // If a value is in ANTFS_CONFIG_PARAMETERS, do not use its value defined here. Instead use the current value in ANTFSHost::cfgParams.
  180. #define MESSAGE_TIMEOUT ((ULONG) 1000) // 1 second
  181. #define ACKNOWLEDGED_TIMEOUT ((ULONG) 10000) // 10 seconds, 2 seconds to drop to search and 7.5 (max) seconds for transport search timeout.
  182. #define PING_TIMEOUT ((ULONG) 3000)
  183. #define DISCONNECT_TIMEOUT ((ULONG) 3000)
  184. #define CONNECT_TIMEOUT ((ULONG) 3000)
  185. #define BROADCAST_TIMEOUT ((ULONG) 3000)
  186. #define BURST_TIMEOUT ((ULONG) 100)
  187. #define ANT_CLOSE_TIMEOUT ((ULONG) 2100) // Longest channel period + some margin.
  188. #define PAIRING_TIMEOUT ((ULONG) 60000) // 60 Seconds.
  189. #define AUTH_TIMEOUT ((ULONG) 5000) // May be too short for some devices
  190. #define ERASE_TIMEOUT ((ULONG) 60000) // 60 seconds.
  191. #define ID_TIMEOUT ((ULONG) 5000) // 5 seconds.
  192. #define DOWNLOAD_RESYNC_TIMEOUT ((ULONG) 10000) // 10 seconds.
  193. #define UPLOAD_REQUEST_TIMEOUT ((ULONG) 3000) // 3 seconds. //changed to 3s to be longer than 2s drop to search
  194. #define UPLOAD_RESPONSE_TIMEOUT ((ULONG) 60000) // 60 seconds. //allow the device to take up to 60 seconds as long as it's beacon remains busy
  195. #define BURST_CHECK_TIMEOUT ((ULONG) 10000) // 10 seconds.
  196. #define ERASE_WAIT_TIMEOUT ((ULONG) 5000) // 5 seconds.
  197. #define SEARCH_STATUS_CHECK_TIMEOUT ((ULONG) 60000) // 60 seconds.
  198. #define BURST_FAIL_STATUS_CHECK_TIMEOUT ((ULONG) 2500) // 2.5 seconds.
  199. #define DOWNLOAD_LOOP_TIMEOUT ((ULONG) 10000) // 10 seconds.
  200. #define UPLOAD_LOOP_TIMEOUT ((ULONG) 15000) // 15 seconds.
  201. #define COMMAND_TIMEOUT ((ULONG) 60000) // 60 Seconds, drop to link if no commands received from host
  202. #define ANTFS_SERIAL_WATCHDOG_COUNT ((USHORT)15) // 15 seconds
  203. #define CMD_TIMEOUT_DISABLED ((UCHAR) 0xFF)
  204. #define REQUEST_TIMEOUT ((ULONG) 3000) // 3 seconds
  205. #endif // ANTFS_MESSAGES_H