antfs_client_channel.hpp 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  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 in compliance
  4. with this license.
  5. Copyright (c) Dynastream Innovations Inc. 2013
  6. All rights reserved.
  7. */
  8. #if !defined(ANTFS_CLIENT_CHANNEL_HPP)
  9. #define ANTFS_CLIENT_CHANNEL_HPP
  10. #include "types.h"
  11. #include "dsi_thread.h"
  12. #include "dsi_timer.hpp"
  13. #include "dsi_framer_ant.hpp"
  14. #include "dsi_debug.hpp"
  15. #include "dsi_response_queue.hpp"
  16. #include "dsi_ant_message_processor.hpp"
  17. #include "antfs_client_interface.hpp"
  18. //////////////////////////////////////////////////////////////////////////////////
  19. // Public Definitions
  20. //////////////////////////////////////////////////////////////////////////////////
  21. typedef struct
  22. {
  23. char acFriendlyName[FRIENDLY_NAME_MAX_LENGTH];
  24. BOOL bNameSet;
  25. UCHAR ucIndex;
  26. UCHAR ucSize;
  27. } ANTFS_FRIENDLY_NAME;
  28. /////////////////////////////////////////////////////////////////
  29. // This class implements the ANT-FS Client specification.
  30. // It is intended to be used together with another class that manages
  31. // the connection to an ANT USB stick (e.g. DSIANTDevice or
  32. // .NET ANT_Device).
  33. /////////////////////////////////////////////////////////////////
  34. class ANTFSClientChannel : public ANTFSClientInterface, public DSIANTMessageProcessor
  35. {
  36. private:
  37. //////////////////////////////////////////////////////////////////////////////////
  38. // Private Definitions
  39. //////////////////////////////////////////////////////////////////////////////////
  40. enum ENUM_ANTFS_REQUEST
  41. {
  42. ANTFS_REQUEST_NONE = 0,
  43. ANTFS_REQUEST_INIT, // Init()
  44. ANTFS_REQUEST_OPEN_BEACON, // OpenBeacon()
  45. ANTFS_REQUEST_CLOSE_BEACON, // CloseBeacon()
  46. ANTFS_REQUEST_CONNECT, // From Host: Switch to Authenticate
  47. ANTFS_REQUEST_DISCONNECT, // From Host: End session
  48. ANTFS_REQUEST_PING, // From Host: Keep session alive
  49. ANTFS_REQUEST_AUTHENTICATE, // From Host: Send authentication Response
  50. ANTFS_REQUEST_PAIR, // From Host: Send pairing request to application
  51. ANTFS_REQUEST_CHANGE_LINK, // From Host: Switch frequency/period
  52. ANTFS_REQUEST_DOWNLOAD, // From Host: Download requested
  53. ANTFS_REQUEST_DOWNLOAD_RESPONSE, // SendDownloadResponse();
  54. ANTFS_REQUEST_UPLOAD, // From Host: Upload requested
  55. ANTFS_REQUEST_UPLOAD_RESPONSE, // SendUploadResponse()
  56. ANTFS_REQUEST_ERASE, // From Host: Erase request
  57. ANTFS_REQUEST_ERASE_RESPONSE, // SendEraseResponse()
  58. ANTFS_REQUEST_CONNECTION_LOST, // Internal, keep these at the end of the list order is important
  59. ANTFS_REQUEST_HANDLE_SERIAL_ERROR, // Internal
  60. ANTFS_REQUEST_SERIAL_ERROR_HANDLED // Internal
  61. };
  62. enum RETURN_STATUS
  63. {
  64. RETURN_FAIL = 0,
  65. RETURN_PASS,
  66. RETURN_STOP,
  67. RETURN_REJECT,
  68. RETURN_NA,
  69. RETURN_SERIAL_ERROR
  70. };
  71. //////////////////////////////////////////////////////////////////////////////////
  72. // Private Variables
  73. //////////////////////////////////////////////////////////////////////////////////
  74. DSIResponseQueue<ANTFS_CLIENT_RESPONSE> clResponseQueue;
  75. BOOL bInitFailed;
  76. UCHAR aucResponseBuf[MESG_MAX_SIZE_VALUE];
  77. UCHAR aucRxBuf[MESG_MAX_SIZE_VALUE];
  78. DSI_THREAD_ID hANTFSThread; // Handle for the ANTFS thread.
  79. DSI_MUTEX stMutexResponseQueue; // Mutex used with the response queue
  80. DSI_MUTEX stMutexCriticalSection; // Mutex used with the wait condition
  81. DSI_MUTEX stMutexPairingTimeout; // Mutex used with the pairing timeouts
  82. DSI_CONDITION_VAR stCondANTFSThreadExit; // Event to signal the ANTFS thread has ended
  83. DSI_CONDITION_VAR stCondRequest; // Event to signal there is a new request
  84. DSI_CONDITION_VAR stCondRxEvent; // Event to signal there is a new Rx message or failure
  85. DSI_CONDITION_VAR stCondWaitForResponse; // Event to signal there is a new response to the application
  86. DSITimer *pclTimer;
  87. volatile BOOL bTimerRunning;
  88. volatile BOOL bANTFSThreadRunning;
  89. volatile BOOL bKillThread;
  90. volatile BOOL bCancel; // Internal cancel parameter to use if not configured
  91. volatile BOOL *pbCancel;
  92. DSIFramerANT *pclANT;
  93. // ANT Channel parameters
  94. UCHAR ucNetworkNumber;
  95. //UCHAR ucChannelNumber;
  96. USHORT usRadioChannelID; // ANT Channel Device ID
  97. UCHAR ucTheDeviceType;
  98. UCHAR ucTheTransmissionType;
  99. USHORT usTheMessagePeriod;
  100. UCHAR aucTheNetworkkey[8];
  101. UCHAR ucLinkTxPower;
  102. UCHAR ucSessionTxPower;
  103. BOOL bCustomTxPower;
  104. // Bursting
  105. volatile ULONG ulPacketCount;
  106. volatile BOOL bTxError;
  107. volatile BOOL bRxError;
  108. volatile BOOL bReceivedBurst;
  109. volatile BOOL bReceivedCommand;
  110. volatile BOOL bNewRxEvent;
  111. // Beacon parameters
  112. ANTFS_CLIENT_PARAMS stInitParams; // Initial parameters
  113. UCHAR aucFriendlyName[FRIENDLY_NAME_MAX_LENGTH]; // Cache application defined friendly name
  114. UCHAR aucPassKey[PASSWORD_MAX_LENGTH]; // Cache application defined passkey
  115. UCHAR ucPassKeySize; // PassKey length
  116. UCHAR ucFriendlyNameSize; // Friendly name length
  117. UCHAR ucActiveBeaconFrequency; // Active radio frequency for the beacon
  118. UCHAR ucActiveBeaconStatus1; // Beacon Status 1 byte
  119. UCHAR aucBeacon[8]; // Beacon buffer
  120. USHORT usBeaconChannelPeriod; // If custom period (not defined by ANT-FS)
  121. // ANT-FS Broadcast
  122. BOOL bReturnToBroadcast; // Default action when closing the beacon
  123. // Link state
  124. ULONG ulHostSerialNumber;
  125. // Authentication state
  126. ANTFS_FRIENDLY_NAME stHostFriendlyName; // Host Friendly Name
  127. UCHAR ucPassKeyIndex; // Current location of auth string Tx block
  128. UCHAR ucAuthCommandType; // Authentication command type in progress
  129. BOOL bAcceptRequest; // Accept/reject authentication request
  130. // Pairing
  131. UCHAR ucPairingTimeout;
  132. volatile BOOL bTimeoutEvent;
  133. // Disconnect
  134. ANTFS_DISCONNECT_PARAMS stHostDisconnectParams; // Parameters received from the hsot on a disconnect request
  135. // Transport state
  136. ANTFS_REQUEST_PARAMS stHostRequestParams; // Parameters received from the host on a file transfer request
  137. UCHAR ucRequestResponse; // Response from the application to the request
  138. // Data transfer
  139. USHORT usTransferDataFileIndex; // Index of current file being transferred
  140. volatile ULONG ulTransferFileSize; // File size of current transfer, in bytes
  141. volatile ULONG ulTransferBurstIndex; // Current location within the burst block, in bytes
  142. volatile ULONG ulTransferBytesRemaining; // Total remaining data length of the current block, in bytes
  143. volatile ULONG ulTransferMaxIndex; // Upper limit of the current transmitted burst block, in bytes
  144. volatile ULONG ulTransferBlockSize; // Maximum block size, limited by client device
  145. volatile USHORT usTransferCrc; // Data CRC
  146. volatile ULONG ulDownloadProgress; // Current download progress (number of bytes transferred)
  147. volatile ULONG ulTransferBlockOffset; // Offset, in bytes, of the data block provided by the application
  148. volatile ULONG ulTransferBufferSize;
  149. UCHAR *pucDownloadData; // Buffer with data to download
  150. UCHAR *pucTransferBufferDynamic; // Dynamic buffer for uploads
  151. volatile ENUM_ANTFS_REQUEST eANTFSRequest;
  152. volatile ANTFS_CLIENT_STATE eANTFSState;
  153. volatile UCHAR ucLinkCommandInProgress;
  154. //////////////////////////////////////////////////////////////////////////////////
  155. // Private Function Prototypes
  156. //////////////////////////////////////////////////////////////////////////////////
  157. void ANTFSThread(void);
  158. static DSI_THREAD_RETURN ANTFSThreadStart(void *pvParameter_);
  159. void TimerCallback(void);
  160. static DSI_THREAD_RETURN TimerStart(void *pvParameter_);
  161. void SetDefaultBeacon(void);
  162. void ResetClientState(void);
  163. BOOL ReInitDevice(void);
  164. void HandleSerialError(void);
  165. BOOL FilterANTMessages(ANT_MESSAGE* pstMessage_, UCHAR ucANTChannel_);
  166. BOOL ANTProtocolEventProcess(UCHAR ucChannel_, UCHAR ucMessageCode_);
  167. BOOL ANTChannelEventProcess(UCHAR ucChannel_, UCHAR ucMessageCode_);
  168. void AddResponse(ANTFS_CLIENT_RESPONSE eResponse_);
  169. void LoadBeacon(void);
  170. RETURN_STATUS AttemptOpenBeacon(void);
  171. RETURN_STATUS AttemptCloseBeacon(void);
  172. RETURN_STATUS AttemptAuthenticateResponse(void);
  173. RETURN_STATUS AttemptEraseResponse(void);
  174. RETURN_STATUS AttemptDownloadResponse(void);
  175. RETURN_STATUS AttemptUploadResponse(void);
  176. void DecodeLinkCommand(UCHAR *pucLinkCommand_);
  177. void DecodeAuthenticateCommand(UCHAR ucControlByte_, UCHAR *pucAuthCommand_);
  178. void DecodeTransportCommand(UCHAR ucControlByte_, UCHAR *pucTransCommand_);
  179. void UploadInputData(UCHAR ucControlByte_, UCHAR* pucMesg_);
  180. RETURN_STATUS SwitchToLink(void);
  181. RETURN_STATUS SwitchToAuthenticate(void);
  182. RETURN_STATUS SwitchToTransport(void);
  183. RETURN_STATUS SwitchLinkParameters(void);
  184. void SetANTChannelPeriod(UCHAR ucLinkPeriod_);
  185. public:
  186. //////////////////////////////////////////////////////////////////////////////////
  187. // Public Function Prototypes
  188. //////////////////////////////////////////////////////////////////////////////////
  189. ANTFSClientChannel();
  190. ~ANTFSClientChannel();
  191. BOOL Init(DSIFramerANT* pclANT_, UCHAR ucChannel_);
  192. /////////////////////////////////////////////////////////////////
  193. // Begins to initialize the ANTFSClientChannel object.
  194. // Returns TRUE if successful. Otherwise, it returns FALSE.
  195. // Parameters:
  196. // *pclANT_: Pointer to a DSIFramerANT object.
  197. // ucChannel_: Channel number to use for the ANT-FS host
  198. // Operation:
  199. // This function is used from a class managing the connection
  200. // to ANT (e.g. DSIANTDevice or .NET ANT_Device), to
  201. // initialize the ANTFSClientChannel object. It is not possible
  202. // to change the channel number once ANT-FS is running.
  203. // The function returns immediately, and the ANTFSHostChannel object
  204. // will send a response of ANTFS_HOST_RESPONSE_INIT_PASS.
  205. // IT IS NOT NECESSARY TO CALL THIS FUNCTION DIRECTLY FROM USER APPLICATIONS.
  206. /////////////////////////////////////////////////////////////////
  207. void Close(void);
  208. /////////////////////////////////////////////////////////////////
  209. // Stops any pending actions, closes all threads and cleans
  210. // up any dynamic memory being used by the library.
  211. // Operation:
  212. // This function is used from a class managing the connection
  213. // to ANT (e.g. DSIANTDevice or .NET ANT_Device), to
  214. // clean up any resources in use by the ANT-FS host.
  215. // IT IS NOT NECESSARY TO CALL THIS FUNCTION DIRECTLY FROM USER APPLICATIONS.
  216. /////////////////////////////////////////////////////////////////
  217. void ProcessMessage(ANT_MESSAGE* pstMessage_, USHORT usMesgSize_);
  218. /////////////////////////////////////////////////////////////////
  219. // Processes incoming ANT messages as per the ANT-FS Technology
  220. // Specification
  221. // Parameters:
  222. // pstMessage_: Pointer to an ANT message structure
  223. // usMesgSize_: ANT message size
  224. // Operation:
  225. // This function is used from a class managing the connection
  226. // to ANT (e.g. DSIANTDevice or .NET ANT_Device).
  227. // IT IS NOT NECESSARY TO CALL THIS FUNCTION DIRECTLY FROM USER APPLICATIONS.
  228. /////////////////////////////////////////////////////////////////
  229. void ProcessDeviceNotification(ANT_DEVICE_NOTIFICATION eCode_, void* pvParameter_);
  230. /////////////////////////////////////////////////////////////////
  231. // Processes device level notifications
  232. // Parameters:
  233. // eCode_: Device notification event code
  234. // pvParameter_: Pointer to struct defining specific parameters related
  235. // to the event code
  236. // Operation:
  237. // This function is used from a class managing the connection
  238. // to ANT (e.g. DSIANTDevice or .NET ANT_Device).
  239. // IT IS NOT NECESSARY TO CALL THIS FUNCTION DIRECTLY FROM USER APPLICATIONS.
  240. /////////////////////////////////////////////////////////////////
  241. void Cancel(void);
  242. /////////////////////////////////////////////////////////////////
  243. // Cancels any pending actions and returns the library to the
  244. // appropriate ANTFS layer if possible. ie if the library was
  245. // executing a download command in the transport layer, the
  246. // library would be returned to ANTFS_CLIENT_STATE_TRANSPORT after
  247. // execution of this function.
  248. /////////////////////////////////////////////////////////////////
  249. // TODO: Serial number is configured within InitParams. Should it be a
  250. // separate SetSerialNumber function for consistency with the host, or
  251. // should the host be configured with a struct as in this function?
  252. ANTFS_RETURN ConfigureClientParameters(ANTFS_CLIENT_PARAMS* pstInitParams_);
  253. /////////////////////////////////////////////////////////////////
  254. // Set up the ANTFS Client configuration parameters.
  255. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  256. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  257. // ANTFS_RETURN_BUSY if the library is busy with another request.
  258. // Parameters:
  259. // *pstInitParams_: A pointer to an
  260. // ANTFS_PARAMS structure that defines the
  261. // configuration parameters of the client
  262. // device
  263. // Operation:
  264. // This function can only be used before the beacon is open;
  265. // Changes are only applied when calling OpenBeacon().
  266. // Certain parameters can be changed at any time, see
  267. // SetPairingEnabled
  268. // SetUploadEnabled
  269. // SetDataAvailable
  270. // SetBeaconTimeout
  271. // SetPairingTimeout
  272. // If the client is not configured prior to opening the
  273. // beacon, the default ANT-FS PC beacon configuration is used.
  274. /////////////////////////////////////////////////////////////////
  275. ANTFS_RETURN SetPairingEnabled(BOOL bEnable_);
  276. /////////////////////////////////////////////////////////////////
  277. // Enable handling of pairing authentication requests, and indicate
  278. // so in the beacon.
  279. // Parameters:
  280. // bEnable_: Set to TRUE to enable pairing and FALSE
  281. // to disable.
  282. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  283. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  284. // ANTFS_RETURN_BUSY if the library is busy with another request.
  285. // Operation:
  286. // This function can be used at any time, except while handling
  287. // an authentication request
  288. /////////////////////////////////////////////////////////////////
  289. ANTFS_RETURN SetUploadEnabled(BOOL bEnable_);
  290. /////////////////////////////////////////////////////////////////
  291. // Enable uploads, indicating so in the beacon.
  292. // Parameters:
  293. // bEnable_: Set to TRUE to enable pairing and FALSE
  294. // to disable.
  295. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  296. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  297. // ANTFS_RETURN_BUSY if the library is busy with another request.
  298. // Operation:
  299. // This function can be used at any time, except while handling
  300. // a transport request (i.e. during an upload)
  301. /////////////////////////////////////////////////////////////////
  302. ANTFS_RETURN SetDataAvailable(BOOL bDataAvailable_);
  303. /////////////////////////////////////////////////////////////////
  304. // Indicate in the beacon whether data is available for download.
  305. // Parameters:
  306. // bDataAvailable_: Set to TRUE if data is available and
  307. // FALSE if not.
  308. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  309. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  310. // ANTFS_RETURN_BUSY if the library is busy with another request.
  311. // Operation:
  312. // This function can be used at any time, except while handling
  313. // a transport request (i.e. during a download)
  314. /////////////////////////////////////////////////////////////////
  315. // TODO: SetState (Status1 byte, consistent with integrated FS interface)?
  316. void SetBeaconTimeout(UCHAR ucTimeout_);
  317. /////////////////////////////////////////////////////////////////
  318. // Set up the time the client will wait without receiving any
  319. // commands from the host before dropping back to the link state
  320. // Parameters:
  321. // ucTimeout_: Timeout, in seconds. Set to 0xFF to
  322. // disable (infinite timeout).
  323. // Zero is not an allowed value.
  324. /////////////////////////////////////////////////////////////////
  325. void SetPairingTimeout(UCHAR ucTimeout_);
  326. /////////////////////////////////////////////////////////////////
  327. // Set up the time the client will wait without receiving any
  328. // response from the application to a pairing request before
  329. // rejecting it
  330. // Parameters:
  331. // ucTimeout_: Timeout, in seconds. Set to 0xFF to
  332. // disable (infinite timeout).
  333. // Zero is not an allowed value.
  334. /////////////////////////////////////////////////////////////////
  335. ANTFS_RETURN SetFriendlyName(UCHAR* pucFriendlyName_, UCHAR ucFriendlyNameSize_);
  336. /////////////////////////////////////////////////////////////////
  337. // Set up a friendly name for the ANT-FS client
  338. // Parameters:
  339. // *pucFriendlyName: A pointer to a character string
  340. // containing the friendly name of the client.
  341. // Set to NULL to disable
  342. // ucFriendlyNameSize: Size of the friendly name string (max 255)
  343. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  344. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  345. // ANTFS_RETURN_BUSY if the library is busy with another request.
  346. // Operation:
  347. // This function can be used at any time, except while handling
  348. // an authentication request.
  349. // No friendly name will be sent with authentication responses
  350. // unless configured with this command.
  351. // The friendly name is cached by the client library.
  352. /////////////////////////////////////////////////////////////////
  353. ANTFS_RETURN SetPassKey(UCHAR* pucPassKey_, UCHAR ucPassKeySize_);
  354. /////////////////////////////////////////////////////////////////
  355. // Set up the pass key for the client to establish authenticated
  356. // sessions with a host device
  357. // Parameters:
  358. // *pucPassKey: Array containing the pass key
  359. // Set to NULL to disable
  360. // ucPassKeySize: Size of the passkey (max 255)
  361. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  362. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  363. // ANTFS_RETURN_BUSY if the library is busy with another request.
  364. // Operation:
  365. // This function can be used at any time, except while handling
  366. // an authentication request.
  367. // PassKey authentication is disabled by default, unless
  368. // this command is called to configure a key.
  369. // The passkey is cached by the client library.
  370. /////////////////////////////////////////////////////////////////
  371. void SetChannelID(UCHAR ucDeviceType_, UCHAR ucTransmissionType_);
  372. /////////////////////////////////////////////////////////////////
  373. // Set up the ANT Channel ID for the ANT-FS Client
  374. // Parameters:
  375. // ucDeviceType_: ANT Channel Device Type
  376. // ucTransmissionType_: ANT Channel Transmission Type
  377. // Operation:
  378. // Configuration changes are applied when the beacon is opened
  379. /////////////////////////////////////////////////////////////////
  380. void SetChannelPeriod(USHORT usChannelPeriod_);
  381. /////////////////////////////////////////////////////////////////
  382. // Set up a custom ANT channel period
  383. // Parameters:
  384. // usChannelPeriod_: Message count, in seconds * 32768.
  385. // For example, for 4Hz, set to 8192.
  386. // Operation:
  387. // Use this function if using ANT-FS broadcast and configuring a
  388. // beacon period not defined in the ANT-FS Technology Specification
  389. // When using this option, set the Link Period beacon parameter to
  390. // BEACON_PERIOD_KEEP. This is the channel period the client will
  391. // use when in LINK state or when it returns to broadcast.
  392. /////////////////////////////////////////////////////////////////
  393. void SetNetworkKey(UCHAR ucNetwork_, UCHAR ucNetworkKey[]);
  394. /////////////////////////////////////////////////////////////////
  395. // Set up the network key to use with the ANT-FS Client
  396. // Parameters:
  397. // ucNetwork_: Network number
  398. // ucNetorkKey_: Array containing the 8-byte network key
  399. // Operation:
  400. // Configuration changes are applied when the beacon is opened
  401. /////////////////////////////////////////////////////////////////
  402. void SetTxPower(UCHAR ucPairingLv_, UCHAR ucConnectedLv_);
  403. /////////////////////////////////////////////////////////////////
  404. // Set up the transmit power for the ANT-FS Channel.
  405. // Parameters:
  406. // ucPairingLv_: Power level to use while beaconing (link)
  407. // ucConnectedLv_: Power level to use during a session
  408. // Operation:
  409. // This command can be used to facilitate pairing when
  410. // proximity search is used in the host device.
  411. // If the ANT part does not support setting the transmit power
  412. // on a per channel basis, it is set for all channels
  413. // Configuration changes are applied when the client switches
  414. // to the link and authentication states.
  415. /////////////////////////////////////////////////////////////////
  416. ANTFS_RETURN OpenBeacon(void);
  417. /////////////////////////////////////////////////////////////////
  418. // Begins the channel configuration to transmit the ANT-FS beacon
  419. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  420. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  421. // ANTFS_RETURN_BUSY if the library is busy with another request.
  422. // Operation:
  423. // This function will configure the beacon and start broadcasting.
  424. // If the channel is already open (i.e. broadcast mode), only the
  425. // contents of the beacon will change, not the channel configuration.
  426. // Once the channel is successfully configured and opened,
  427. // a response of ANTFS_CLIENT_RESPONSE_BEACON_OPEN will be sent.
  428. /////////////////////////////////////////////////////////////////
  429. ANTFS_RETURN CloseBeacon(BOOL bReturnToBroadcast_ = FALSE);
  430. /////////////////////////////////////////////////////////////////
  431. // Closes the ANT-FS beacon.
  432. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  433. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  434. // ANTFS_RETURN_BUSY if the library is busy with another request.
  435. // Parameters:
  436. // bReturnToBroadcast_: If TRUE, the channel will remain
  437. // open, and the application can continue
  438. // to process messages. If FALSE,
  439. // the channel will be closed.
  440. // Operation:
  441. // Once the channel is successfully closed, a response of
  442. // ANTFS_CLIENT_RESPONSE_BEACON_CLOSED will be sent,
  443. // and the ANTFSClient will be in the ANTFS_STATE_IDLE state.
  444. // If the ReturnToBroadcast parameter is not used, the default
  445. // behavior will be to close the channel and stop broadcasting.
  446. /////////////////////////////////////////////////////////////////
  447. BOOL GetEnabled(void);
  448. /////////////////////////////////////////////////////////////////
  449. // Returns the current status of ANT-FS message processing
  450. // Returns TRUE if ANT-FS is enabled. Otherwise, it returns FALSE.
  451. // Operation:
  452. // This function is used from a class managing the connection
  453. // to ANT (e.g. DSIANTDevice or .NET ANT_Device).
  454. // IT IS NOT NECESSARY TO CALL THIS FUNCTION DIRECTLY FROM USER APPLICATIONS.
  455. /////////////////////////////////////////////////////////////////
  456. ANTFS_CLIENT_STATE GetStatus(void);
  457. /////////////////////////////////////////////////////////////////
  458. // Returns the current library status.
  459. /////////////////////////////////////////////////////////////////
  460. BOOL GetHostName(UCHAR *aucHostFriendlyName_, UCHAR *pucBufferSize_);
  461. /////////////////////////////////////////////////////////////////
  462. // Copies at most ucBufferSize_ characters from the host's
  463. // friendly name string (for the most recent session) into the
  464. // supplied pucHostFriendlyName_ buffer.
  465. // Parameters:
  466. // *aucFriendlyName_: A pointer to a buffer where the remote
  467. // device friendly name will be copied.
  468. // *pucBufferSize_: Pointer to a UCHAR variable that should contain the
  469. // maximum size of the buffer pointed to by
  470. // aucHostFriendlyName_.
  471. // After the function returns, the UCHAR variable
  472. // will be set to reflect the size of the friendly
  473. // name string that has been copied to the buffer.
  474. // Returns TRUE if successful. Otherwise, it returns FALSE.
  475. // Operation:
  476. // If the host's friendly name string has fewer than ucBufferSize_
  477. // characters, the *aucFriendlyName_ buffer will be padded with
  478. // zeroes.
  479. /////////////////////////////////////////////////////////////////
  480. BOOL GetRequestParameters(ANTFS_REQUEST_PARAMS* pstRequestParams_);
  481. /////////////////////////////////////////////////////////////////
  482. // Gets the full parameters for a download, upload or erase request
  483. // received from the host.
  484. //
  485. // Parameters:
  486. // *pstRequestParams_: Pointer to an ANTFS_REQUEST_PARAMS
  487. // structure that will receive the details
  488. // of the download, upload or erase request.
  489. // Returns TRUE if successful. Otherwise, it returns FALSE.
  490. // Operation:
  491. // This function makes available all of the parameters received
  492. // from the host when requesting a data transfer. These
  493. // parameters are available for information purposes; the client
  494. // application only needs to process the index to handle the
  495. // request.
  496. // This information is valid while a download, upload or erase
  497. // request is in progress.
  498. /////////////////////////////////////////////////////////////////
  499. BOOL GetRequestedFileIndex(USHORT *pusIndex_);
  500. /////////////////////////////////////////////////////////////////
  501. // Gets the index requested for a download, upload or erase request
  502. // Parameters:
  503. // *pulByteProgress_: Pointer to a USHORT that will receive
  504. // the current fle index requested
  505. // Returns TRUE if successful. Otherwise, it returns FALSE.
  506. // Operation:
  507. // This information is valid while a download, upload or erase
  508. // request is in progress.
  509. /////////////////////////////////////////////////////////////////
  510. BOOL GetDownloadStatus(ULONG *pulByteProgress_, ULONG *pulTotalLength_);
  511. /////////////////////////////////////////////////////////////////
  512. // Gets the transfer progress of a pending or a complete
  513. // download.
  514. // Parameters:
  515. // *pulByteProgress_: Pointer to a ULONG that will receive
  516. // the current byte progress of a pending or
  517. // complete download.
  518. // *pulTotalLength_: Pointer to a ULONG that will receive the
  519. // total expected length of the download.
  520. // Returns TRUE if successful. Otherwise, it returns FALSE.
  521. // Operation:
  522. // A data download occurs when information is requested from a
  523. // remote device. This function may be called at any point
  524. // during a download as a progress indicator. After the transfer
  525. // is complete, this information is valid until another request
  526. // for a data transfer is made.
  527. /////////////////////////////////////////////////////////////////
  528. BOOL GetUploadStatus(ULONG *pulByteProgress_, ULONG *pulTotalLength_);
  529. /////////////////////////////////////////////////////////////////
  530. // Gets the transfer progress of a pending or a complete
  531. // upload.
  532. // Parameters:
  533. // *pulByteProgress_: Pointer to a ULONG that will receive
  534. // the current byte progress of a pending or
  535. // complete upload.
  536. // *pulTotalLength_: Pointer to a ULONG that will receive the
  537. // total expected length of the upload.
  538. // Returns TRUE if successful. Otherwise, it returns FALSE.
  539. // Operation:
  540. // A data upload occurs when information is sent to a
  541. // remote device. This function may be called at any point
  542. // during an upload as a progress indicator. After the transfer
  543. // is complete, this information is valid until another request
  544. // for a data transfer is made.
  545. /////////////////////////////////////////////////////////////////
  546. BOOL GetTransferData(ULONG *pulDataSize_ , void *pvData_ = NULL);
  547. /////////////////////////////////////////////////////////////////
  548. // Gets the received data from a transfer (upload).
  549. //
  550. // Parameters:
  551. // *ulDataSize_: Pointer to a ULONG that will receive
  552. // the size of the data available in bytes.
  553. // *pvData_: Pointer to a buffer where the received data
  554. // will be copied. NULL can be passed to this
  555. // parameter so that the size can be retrieved
  556. // without copying any data. The application
  557. // can then call this function again to after it
  558. // has allocated a buffer of sufficient size to
  559. // handle the data.
  560. // Returns TRUE if successful. Otherwise, it returns FALSE.
  561. /////////////////////////////////////////////////////////////////
  562. BOOL GetDisconnectParameters(ANTFS_DISCONNECT_PARAMS* pstDisconnectParams_);
  563. /////////////////////////////////////////////////////////////////
  564. // Gets the full parameters for a disconnect command
  565. // received from the host.
  566. //
  567. // Parameters:
  568. // *pstRequestParams_: Pointer to an ANTFS_DISCONNECT_PARAMS
  569. // structure that will receive the details
  570. // of the disconnect request.
  571. // Returns TRUE if successful. Otherwise, it returns FALSE.
  572. // Operation:
  573. // This function makes available all of the parameters received
  574. // from the host when requesting to disconnect from the client.
  575. // These parameters can let the client know whether it is
  576. // returning to broadcast/link state, as well as if it needs
  577. // to make itself undiscoverable for a period of time.
  578. // This information is valid after an ANTFS_RESPONSE_DISCONNECT_PASS
  579. // is received
  580. /////////////////////////////////////////////////////////////////
  581. ANTFS_RETURN SendPairingResponse(BOOL bAccept_);
  582. /////////////////////////////////////////////////////////////////
  583. // Sends a response to a pairing request.
  584. // Parameters:
  585. // bAccept_: Set this value to TRUE to accept the
  586. // pairing request, and FALSE to reject it.
  587. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  588. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  589. // ANTFS_RETURN_BUSY if the library is busy with another request.
  590. // Operation:
  591. // A pairing request will automatically be rejected if no
  592. // response is sent within the pairing timeout, and the
  593. // application will receive an ANTFS_CLIENT_RESPONSE_PAIRING_TIMEOUT
  594. // response.
  595. /////////////////////////////////////////////////////////////////
  596. ANTFS_RETURN SendDownloadResponse(UCHAR ucResponse_, ANTFS_DOWNLOAD_PARAMS* pstDownloadInfo_, ULONG ulDataLength_, void *pvData_);
  597. /////////////////////////////////////////////////////////////////
  598. // Sends the response to a download request from an authenticated
  599. // device.
  600. // Parameters:
  601. // ucResponse_: The response to the download request.
  602. // stDownloadInfo_: Pointer to an ANTFS_CLIENT_DOWNLOAD_PARAMS
  603. // structure holding the parameters of the
  604. // download response.
  605. // ulDataLength_: The byte length of the data block to be
  606. // downloaded to the host device. This is the
  607. // size of the entire file, as specified in
  608. // the directory. Set to zero if no data
  609. // is to be downloaded.
  610. // *pvData_: Pointer to the location where the data
  611. // to be downloaded is stored. The pointer
  612. // should correspond with the beginning of the
  613. // file, without applying any offsets.
  614. // Set to NULL if no data is to be
  615. // downloaded (response rejected).
  616. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  617. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  618. // ANTFS_RETURN_BUSY if the library is busy with another request.
  619. // Operation:
  620. // The data block provided to this function should be the entire
  621. // file. Handling of offsets and CRC calculations is done
  622. // internally within the library.
  623. // Once the request is posted, the application must wait for the
  624. // response from the library. Possible responses are:
  625. // ANTFS_CLIENT_RESPONSE_DOWNLOAD_PASS
  626. // ANTFS_CLIENT_RESPONSE_DOwNLOAD_REJECT
  627. // ANTFS_CLIENT_RESPONSE_DOWNLOAD_FAIL
  628. // ANTFS_CLIENT_RESPONSE_SERIAL_FAIL
  629. /////////////////////////////////////////////////////////////////
  630. ANTFS_RETURN SendUploadResponse(UCHAR ucResponse_, ANTFS_UPLOAD_PARAMS* pstUploadInfo_, ULONG ulDataLength_, void *pvData_);
  631. /////////////////////////////////////////////////////////////////
  632. // Sends the response to an upload request from an authenticated
  633. // device.
  634. // Parameters:
  635. // ucResponse_: The response to the upload request.
  636. // pstUploadInfo_: Pointer to an ANTFS_UPLOAD_PARAMS
  637. // structure holding the parameters of the
  638. // upload response.
  639. // ulDataLength_: The byte length of the data that is
  640. // currently stored at the requested upload
  641. // location. Set to zero if uploading to a
  642. // new index or if the uploaded data will
  643. // overwrite all existing data
  644. // *pvData_: Pointer to the location of the data at the
  645. // requested upload index. Set to NULL
  646. // if no data is available or if the uploaded
  647. // data will overwrite the existing file.
  648. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  649. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  650. // ANTFS_RETURN_BUSY if the library is busy with another request.
  651. // Operation:
  652. // The data block provided to this function should be the entire
  653. // file. Handling of offsets and CRC calculations is done
  654. // internally within the library.
  655. // Once the request is posted, the application must wait for the
  656. // response from the library. Possible responses are:
  657. // ANTFS_CLIENT_RESPONSE_UPLOAD_PASS
  658. // ANTFS_CLIENT_RESPONSE_UPLOAD_REJECT
  659. // ANTFS_CLIENT_RESPONSE_UPLOAD_FAIL
  660. // ANTFS_CLIENT_RESPONSE_SERIAL_FAIL
  661. // Upon receiving ANTFS_CLIENT_RESPONSE_UPLOAD_PASS the uploaded data
  662. // will be available in the transfer buffer. See GetTransferData().
  663. /////////////////////////////////////////////////////////////////
  664. ANTFS_RETURN SendEraseResponse(UCHAR ucResponse_);
  665. /////////////////////////////////////////////////////////////////
  666. // Sends a response to a request to erase a file from an
  667. // authenticated remote device
  668. // Parameters:
  669. // ucResponse_: The response to the erase request.
  670. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  671. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  672. // ANTFS_RETURN_BUSY if the library is busy with another request.
  673. /////////////////////////////////////////////////////////////////
  674. ANTFS_CLIENT_RESPONSE WaitForResponse(ULONG ulMilliseconds_);
  675. /////////////////////////////////////////////////////////////////
  676. // Wait for a response from the ANTFS client library
  677. // Parameters:
  678. // ulMilliseconds_: Set this value to the minimum time to
  679. // wait before returning. If the value is
  680. // 0, the function will return immediately.
  681. // If the value is DSI_THREAD_INFINITE, the
  682. // function will not time out.
  683. // If one or more responses are pending before the timeout
  684. // expires the function will return the first response that
  685. // occurred. If no response is pending at the time the timeout
  686. // expires, ANTFS_CLIENT_RESPONSE_NONE is returned.
  687. // Operation:
  688. // Some of the events return parameters associated with the event.
  689. // Possible events and parameters:
  690. // ANTFS_CLIENT_RESPONSE_PAIRING_REQUEST - GetHostName()
  691. // ANTFS_CLIENT_RESPONSE_DOWNLOAD_REQUEST - GetRequestParameters()
  692. // ANTFS_CLIENT_RESPONSE_UPLOAD_REQUEST - GetRequestParameters()
  693. // ANTFS_CLIENT_RESPONSE_ERASE_REQUEST - GetRequestParameters()
  694. // ANTFS_CLIENT_RESPONSE_UPLOAD_PASS - GetTransferData()
  695. /////////////////////////////////////////////////////////////////
  696. };
  697. #endif // ANTFS_CLIENT_CHANNEL_HPP