antfs_host.hpp 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  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. 2014
  6. All rights reserved.
  7. */
  8. #if !defined(ANTFS_HOST_H)
  9. #define ANTFS_HOST_H
  10. #include "types.h"
  11. #include "dsi_debug.hpp"
  12. #include "antfs_host_channel.hpp"
  13. #include "dsi_ant_device.hpp"
  14. //////////////////////////////////////////////////////////////////////////////////
  15. // This class is a wrapper for ANTFSHostChannel.
  16. // It manages the connection to the ANT USB device (via DSIANTDevice)
  17. // and handles the ANT-FS host state machine (via ANTFSHostChannel).
  18. // Events and states from those two classes are mapped into the ANTFS_RESPONSE
  19. // and ANTFS_STATE enums, which are maintained for backwards compatibility.
  20. //////////////////////////////////////////////////////////////////////////////////
  21. //////////////////////////////////////////////////////////////////////////////////
  22. // Public Definitions
  23. //////////////////////////////////////////////////////////////////////////////////
  24. typedef enum
  25. {
  26. ANTFS_RESPONSE_NONE = 0,
  27. ANTFS_RESPONSE_OPEN_PASS,
  28. ANTFS_RESPONSE_SERIAL_FAIL,
  29. ANTFS_RESPONSE_REQUEST_SESSION_FAIL,
  30. ANTFS_RESPONSE_CONNECT_PASS,
  31. ANTFS_RESPONSE_DISCONNECT_PASS,
  32. ANTFS_RESPONSE_CONNECTION_LOST,
  33. ANTFS_RESPONSE_AUTHENTICATE_NA,
  34. ANTFS_RESPONSE_AUTHENTICATE_PASS,
  35. ANTFS_RESPONSE_AUTHENTICATE_REJECT,
  36. ANTFS_RESPONSE_AUTHENTICATE_FAIL,
  37. ANTFS_RESPONSE_DOWNLOAD_PASS,
  38. ANTFS_RESPONSE_DOWNLOAD_REJECT,
  39. ANTFS_RESPONSE_DOWNLOAD_INVALID_INDEX,
  40. ANTFS_RESPONSE_DOWNLOAD_FILE_NOT_READABLE,
  41. ANTFS_RESPONSE_DOWNLOAD_NOT_READY,
  42. ANTFS_RESPONSE_DOWNLOAD_CRC_REJECTED,
  43. ANTFS_RESPONSE_DOWNLOAD_FAIL,
  44. ANTFS_RESPONSE_UPLOAD_PASS,
  45. ANTFS_RESPONSE_UPLOAD_REJECT,
  46. ANTFS_RESPONSE_UPLOAD_INVALID_INDEX,
  47. ANTFS_RESPONSE_UPLOAD_FILE_NOT_WRITEABLE,
  48. ANTFS_RESPONSE_UPLOAD_INSUFFICIENT_SPACE,
  49. ANTFS_RESPONSE_UPLOAD_FAIL,
  50. ANTFS_RESPONSE_ERASE_PASS,
  51. ANTFS_RESPONSE_ERASE_FAIL,
  52. ANTFS_RESPONSE_MANUAL_TRANSFER_PASS,
  53. ANTFS_RESPONSE_MANUAL_TRANSFER_TRANSMIT_FAIL,
  54. ANTFS_RESPONSE_MANUAL_TRANSFER_RESPONSE_FAIL,
  55. ANTFS_RESPONSE_CANCEL_DONE
  56. } ANTFS_RESPONSE;
  57. typedef enum
  58. {
  59. ANTFS_STATE_IDLE = 0,
  60. ANTFS_STATE_IDLE_POLLING_USB,
  61. ANTFS_STATE_OPEN,
  62. ANTFS_STATE_DISCONNECTING,
  63. ANTFS_STATE_SEARCHING, // LINK
  64. ANTFS_STATE_CONNECTED, // AUTH
  65. ANTFS_STATE_AUTHENTICATING,
  66. ANTFS_STATE_TRANSPORT,
  67. ANTFS_STATE_DOWNLOADING,
  68. ANTFS_STATE_UPLOADING,
  69. ANTFS_STATE_ERASING,
  70. ANTFS_STATE_SENDING,
  71. ANTFS_STATE_RECEIVING
  72. } ANTFS_STATE;
  73. //////////////////////////////////////////////////////////////////////////////////
  74. // Public Function Prototypes
  75. //////////////////////////////////////////////////////////////////////////////////
  76. class ANTFSHost
  77. {
  78. private:
  79. //////////////////////////////////////////////////////////////////////////////////
  80. // Private Definitions
  81. //////////////////////////////////////////////////////////////////////////////////
  82. //////////////////////////////////////////////////////////////////////////////////
  83. // Private Variables
  84. //////////////////////////////////////////////////////////////////////////////////
  85. DSIANTDevice* pclMsgHandler;
  86. ANTFSHostChannel* pclHost;
  87. DSIResponseQueue<ANTFS_RESPONSE> clResponseQueue;
  88. volatile BOOL bOpen;
  89. BOOL bInitFailed;
  90. ANTFS_STATE eWrappedState;
  91. ULONG ulHostSerialNumber;
  92. DSI_THREAD_ID hANTFSThread; // Handle for the ANTFS thread.
  93. DSI_MUTEX stMutexResponseQueue; // Mutex used with the response queue
  94. DSI_MUTEX stMutexCriticalSection; // Mutex used with the wait condition
  95. DSI_CONDITION_VAR stCondANTFSThreadExit; // Event to signal the ANTFS thread has ended.
  96. DSI_CONDITION_VAR stCondWaitForResponse; // Event to signal there is a new response to the application
  97. volatile BOOL bKillThread;
  98. volatile BOOL bANTFSThreadRunning;
  99. //////////////////////////////////////////////////////////////////////////////////
  100. // Private Function Prototypes
  101. //////////////////////////////////////////////////////////////////////////////////
  102. BOOL InitHost(UCHAR ucUSBDeviceNum_, USHORT usBaudRate_, BOOL bAutoInit_);
  103. void ANTFSThread(void);
  104. static DSI_THREAD_RETURN ANTFSThreadStart(void *pvParameter_);
  105. void AddResponse(ANTFS_RESPONSE eResponse_);
  106. public:
  107. ANTFSHost();
  108. ~ANTFSHost();
  109. UCHAR GetVersion(UCHAR *pucVersionString_, UCHAR ucBufferSize_);
  110. /////////////////////////////////////////////////////////////////
  111. // Copies at most ucBufferSize_ characters from the version
  112. // string into the supplied pucVersionString_ buffer.
  113. // Parameters:
  114. // *pucVersionString_ Pointer to a buffer of characters into
  115. // which to receive the version string.
  116. // ucBufferSize_ The maximum number of characters to
  117. // copy into *pucVersionString_.
  118. // Returns the number of characters copied to *pucVersionString_.
  119. // Operation:
  120. // If the version string has fewer than ucBufferSize_
  121. // characters, the *pucVersionString_ will be padded with a
  122. // '\n'.
  123. /////////////////////////////////////////////////////////////////
  124. BOOL Init(void);
  125. /////////////////////////////////////////////////////////////////
  126. // Begins to initialize the ANTFSHost object.
  127. // Returns TRUE if successful. Otherwise, it returns FALSE.
  128. // Operation:
  129. // If ANTFSHost fails to initialize the USBstick, It will
  130. // continue to retry the intitialization once a second until
  131. // it is sucessful. Once everything has be sucessfully initialized
  132. // a response of ANTFS_RESPONSE_CONNECT_PASS will be sent.
  133. //
  134. // This version of Init will only work for the ANT USB stick with
  135. // USB device descriptor "ANT USB Stick"
  136. /////////////////////////////////////////////////////////////////
  137. BOOL Init(UCHAR ucUSBDeviceNum_, USHORT usBaudRate_);
  138. /////////////////////////////////////////////////////////////////
  139. // Begins to initialize the ANTFSHost object.
  140. // Returns TRUE if successful. Otherwise, it returns FALSE.
  141. // Parameters:
  142. // ucUSBDeviceNum_: USB port number
  143. // usBaudRate_: Serial baud rate
  144. // Operation:
  145. // If ANTFSHost fails to initialize the USBstick, It will
  146. // continue to retry the intitialization once a second until
  147. // it is sucessful. Once everything has be sucessfully initialized
  148. // a response of ANTFS_RESPONSE_CONNECT_PASS will be sent.
  149. /////////////////////////////////////////////////////////////////
  150. void SetChannelID(UCHAR ucDeviceType_, UCHAR ucTransmissionType_);
  151. void SetMessagePeriod(USHORT usMessagePeriod_);
  152. void SetNetworkkey(UCHAR ucNetworkkey[]);
  153. void SetProximitySearch(UCHAR ucSearchThreshold_);
  154. /////////////////////////////////////////////////////////////////
  155. // Sets the value for the proximity bin setting for searching.
  156. // Note: If applying this value fails when attempting to start search,
  157. // it is ignored to maintain compatibility with devices that
  158. // do not support this feature. This means that a real failure can occur
  159. // on a device that actually does support it, and it will be missed. The
  160. // debug log will show if this command fails.
  161. // Parameters:
  162. // ucSearchThreshold_ Desired proximity bin from 0-10 (If value is
  163. // set higher then 10, it is automatically capped at 10)
  164. /////////////////////////////////////////////////////////////////
  165. void Close(void);
  166. /////////////////////////////////////////////////////////////////
  167. // Stops any pending actions, closes all devices down and cleans
  168. // up any dynamic memory being used by the library.
  169. /////////////////////////////////////////////////////////////////
  170. ANTFS_STATE GetStatus(void);
  171. /////////////////////////////////////////////////////////////////
  172. // Returns the current library status.
  173. /////////////////////////////////////////////////////////////////
  174. ANTFS_RESPONSE WaitForResponse(ULONG ulMilliseconds_);
  175. /////////////////////////////////////////////////////////////////
  176. // Wait for a response from the ANTFSHost object.
  177. // Parameters:
  178. // ulMilliseconds_: Set this value to the minimum time to
  179. // wait before returning. If the value is
  180. // 0, the function will return immediately.
  181. // If the value is DSI_THREAD_INFINITE, the
  182. // function will not time out.
  183. // If one or more responses are pending before the timeout
  184. // expires the function will return the first response that
  185. // occured. If no response is pending at the time the timeout
  186. // expires, ANTFS_RESPONSE_NONE is returned.
  187. /////////////////////////////////////////////////////////////////
  188. void Cancel(void);
  189. /////////////////////////////////////////////////////////////////
  190. // Cancels any pending actions and returns the library to the
  191. // appropriate ANTFS layer if possible. ie if the library was
  192. // executing a download command in the transport layer, the
  193. // library would be returned to ANTFS_STATE_TRANSPORT after
  194. // execution of this function.
  195. /////////////////////////////////////////////////////////////////
  196. USHORT AddSearchDevice(ANTFS_DEVICE_PARAMETERS *pstDeviceSearchMask_, ANTFS_DEVICE_PARAMETERS *pstDeviceParameters_);
  197. /////////////////////////////////////////////////////////////////
  198. // Adds a set of parameters for which to search to the internal
  199. // search device list.
  200. // Parameters:
  201. // *pstDeviceSearchMask_: A pointer to an
  202. // ANTFS_DEVICE_PARAMETERS structure. Set a
  203. // member to zero (0) to wildcard search for
  204. // it. Otherwise, set the bits that you want
  205. // to be matched to 1 in each member. Members
  206. // that are integer values will be treated the
  207. // same as bit fields for the purposes for the mask.
  208. // *pstDeviceParameters_: A pointer to an
  209. // ANTFS_DEVICE_PARAMETERS structure. Set
  210. // the member to the desired search value.
  211. // A member in this structure is ignored if
  212. // the associated member in the
  213. // *pstDeviceSearchMask_ parameter is set
  214. // to zero (0) for wildcard.
  215. // Returns a handle the the search device entry. If the return
  216. // value is 0, the function failed adding the device entry.
  217. // This means that the device list is already full.
  218. // Operation:
  219. // Note that the default search masks should normally be applied
  220. // to the ucStatusByte1 and ucStatusByte2 members of the
  221. // *pstDeviceSearchMask_ parameter. Eg;
  222. // pstMyDeviceSearchMask->ucStatusByte1 =
  223. // ANTFS_STATUS1_DEFAULT_SEARCH_MASK & ucMyStatus1Criteria;
  224. // Setting bits outside the masks, especially reserved bits, may
  225. // lead to undesired behaviour.
  226. /////////////////////////////////////////////////////////////////
  227. void RemoveSearchDevice(USHORT usHandle_);
  228. /////////////////////////////////////////////////////////////////
  229. // Removes a device entry from the internal search list.
  230. // Parameters:
  231. // usHandle_: Handle to the device entry to be removed
  232. // from the list.
  233. /////////////////////////////////////////////////////////////////
  234. void ClearSearchDeviceList(void);
  235. /////////////////////////////////////////////////////////////////
  236. // Clears the internal search device list.
  237. /////////////////////////////////////////////////////////////////
  238. ANTFS_RETURN SearchForDevice(UCHAR ucSearchRadioFrequency_ = ANTFS_RF_FREQ, UCHAR ucConnectRadioFrequency_ = ANTFS_DEFAULT_TRANSPORT_FREQ, USHORT usRadioChannelID_ = 0, BOOL bUseRequestPage_ = FALSE);
  239. /////////////////////////////////////////////////////////////////
  240. // Begins a search for ANTFS remote devices.
  241. // Parameters:
  242. // ucSearchRadioFrequency_: This specifies the frequency on
  243. // which to search for devices. This
  244. // frequency is calculated as
  245. // (ucSearchRadioFrequency_ * 1 MHz +
  246. // 2400 MHz). MAX_UCHAR (0xFF) is reserved.
  247. // ucConnectRadioFrequency_: This specifies the frequency
  248. // on which the connection communication
  249. // will occur. This frequency is calculated
  250. // as (ucConnectRadioFrequency_ * 1 MHz +
  251. // 2400 MHz). If ucConnectRadioFrequency_
  252. // is set to ANTFS_AUTO_FREQUENCY_SELECTION
  253. // (0xFF), then the library will use an
  254. // adaptive frequency-hopping scheme.
  255. // usRadioChannelID_: This specifies the channel ID for the
  256. // the ANT channel search. Set to zero to
  257. // wildcard.
  258. // bUseRequestPage_: Specifies whether the search will include
  259. // ANT-FS broadcast devices, using a request
  260. // page to begin an ANT-FS session
  261. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  262. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  263. // ANTFS_RETURN_BUSY if the library is busy with another request.
  264. // Operation:
  265. // Once this function is called successfully, the application
  266. // must wait for the response from the ANTFSHost object.
  267. // Possible responses are:
  268. // ANTFS_RESPONSE_CONNECT_PASS
  269. // ANTFS_RESPONSE_SERIAL_FAIL
  270. // The library will continue to search for devices until a device
  271. // is found, the Cancel() function is called, an error occurs, or
  272. // the library is closed.
  273. /////////////////////////////////////////////////////////////////
  274. BOOL GetFoundDeviceParameters(ANTFS_DEVICE_PARAMETERS *pstDeviceParameters_, UCHAR *aucFriendlyName_, UCHAR *pucBufferSize_);
  275. /////////////////////////////////////////////////////////////////
  276. // Copies the parameters of the most recently found device to the
  277. // supplied parameter.
  278. // Parameters:
  279. // *ptsDeviceParameters_: A pointer to a structure that will
  280. // receive a copy of the device parameters.
  281. // *aucFriendlyName_: A pointer to a buffer where the remote
  282. // device friendly name will be copied.
  283. // *pucBufferSize_: Pointer to a UCHAR variable that should contain the
  284. // maximum size of the buffer pointed to by aucFriendlyName_.
  285. // aucFriendlyName will receive a copy of min(pucBufferSize, actualSize) length.
  286. // After the function returns, this variable
  287. // will be set to reflect the actual size of friendly name string.
  288. // Returns TRUE if successful. Otherwise, it returns FALSE.
  289. /////////////////////////////////////////////////////////////////
  290. BOOL GetFoundDeviceChannelID(USHORT *pusDeviceNumber_ = (USHORT *)NULL, UCHAR *pucDeviceType_ = (UCHAR *)NULL, UCHAR *pucTransmitType_ = (UCHAR *)NULL);
  291. /////////////////////////////////////////////////////////////////
  292. // Copies the ANT channel ID of the most recently found device to
  293. // the supplied parameters.
  294. // Parameters:
  295. // *pusDeviceNumber_: A pointer to a USHORT variable that will
  296. // receive the ANT device number of the device.
  297. // *pucDeviceType_: A pointer to a UCHAR variable that will
  298. // hold the =device type of the found device.
  299. // *pucTransmitType_: Pointer to a UCHAR variable that will
  300. // receive the transmission type of the found
  301. // device
  302. // Returns TRUE if successful. Otherwise, it returns FALSE.
  303. /////////////////////////////////////////////////////////////////
  304. BOOL GetUploadStatus(ULONG *pulByteProgress_, ULONG *pulTotalLength_);
  305. /////////////////////////////////////////////////////////////////
  306. // Gets the transfer progress of a pending or a complete
  307. // upload.
  308. // Parameters:
  309. // *pulByteProgress_: Pointer to a ULONG that will receive
  310. // the current byte progress of a pending or
  311. // complete upload.
  312. // *pulTotalLength_: Pointer to a ULONG that will receive the
  313. // total length of the file being uploaded.
  314. // Returns TRUE if successful. Otherwise, it returns FALSE.
  315. // Operation:
  316. // A data upload occurs when information is requested to be sent to
  317. // a remote device. This function may be called at any point
  318. // during an upload as a progress indicator. After the upload
  319. // is complete, this information is valid until another request
  320. // for a data transfer is made.
  321. /////////////////////////////////////////////////////////////////
  322. BOOL GetDownloadStatus(ULONG *pulByteProgress_, ULONG *pulTotalLength_);
  323. /////////////////////////////////////////////////////////////////
  324. // Gets the transfer progress of a pending or a complete
  325. // download.
  326. // Parameters:
  327. // *pulByteProgress_: Pointer to a ULONG that will receive
  328. // the current byte progress of a pending or
  329. // complete download.
  330. // *pulTotalLength_: Pointer to a ULONG that will receive the
  331. // total expected length of the download.
  332. // Returns TRUE if successful. Otherwise, it returns FALSE.
  333. // Operation:
  334. // A data download occurs when information is requested from a
  335. // remote device. This function may be called at any point
  336. // during a download as a progress indicator. After the transfer
  337. // is complete, this information is valid until another request
  338. // for a data transfer is made.
  339. /////////////////////////////////////////////////////////////////
  340. BOOL GetTransferData(ULONG *pulDataSize_ , void *pvData_ = NULL);
  341. /////////////////////////////////////////////////////////////////
  342. // Gets the received data from a transfer (download/manual transfer).
  343. //
  344. // Parameters:
  345. // *ulDataSize_ : Pointer to a ULONG that will receive
  346. // the size of the data available in bytes.
  347. // *pvData_ : Pointer to a buffer where the received data
  348. // will be copied. NULL can be passed to this
  349. // parameter so that the size can be retried
  350. // without copying any data. The application
  351. // can then call this function again to after it
  352. // has allocated a buffer of sufficient size to
  353. // handle the data.
  354. // Returns TRUE if successful. Otherwise, it returns FALSE.
  355. /////////////////////////////////////////////////////////////////
  356. BOOL RecoverTransferData(ULONG *pulDataSize_ , void *pvData_ = NULL);
  357. /////////////////////////////////////////////////////////////////
  358. // Gets the partially received data from a failed transfer (download/manual transfer).
  359. //
  360. // Parameters:
  361. // *ulDataSize_ : Pointer to a ULONG that will receive
  362. // the size of the data available in bytes.
  363. // *pvData_ : Pointer to a buffer where the received data
  364. // will be copied. NULL can be passed to this
  365. // parameter so that the size can be retried
  366. // without copying any data. The application
  367. // can then call this function again to after it
  368. // has allocated a buffer of sufficient size to
  369. // handle the data.
  370. // Returns TRUE if successful. Otherwise, it returns FALSE.
  371. /////////////////////////////////////////////////////////////////
  372. ANTFS_RETURN Authenticate(UCHAR ucAuthenticationType_, UCHAR *pucAuthenticationString_, UCHAR ucLength_, UCHAR *aucResponseBuffer_, UCHAR *pucResponseBufferSize_, ULONG ulResponseTimeout_);
  373. /////////////////////////////////////////////////////////////////
  374. // Request to pair with the connected remote device.
  375. // Parameters:
  376. // ucAuthenticationType_: The type of authentication to
  377. // execute on the remote device.
  378. // *pucAuthenticationString_: A string that may be used in
  379. // conjunction with the particular
  380. // authentication type in use (e.g. a
  381. // password or a friendly name.
  382. // ucLength_: The length of the authentication string,
  383. // including any '\n' terminator. This
  384. // parameter may be set to zero if an
  385. // authentication string is not required.
  386. // *pucResponseBuffer_: Pointer to the buffer where additional
  387. // data from the response will be saved. This will
  388. // include data such as passwords and friendly names.
  389. // This memory must be allocated by the application.
  390. // *pucResponseBufferSize_: Pointer to UCHAR varible that contains the
  391. // size of the buffer pointed to by pucResponseBuffer_.
  392. // After the response has be recived, the UCHAR variable
  393. // will be set to reflect the size of the new data received
  394. // in pucResponseBuffer_.
  395. // ulResponseTimeout_: Number of miliseconds to wait for a response after
  396. // the authenticate command is sent.
  397. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  398. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  399. // ANTFS_RETURN_BUSY if the library is busy with another request.
  400. // Operation:
  401. // Once the request is posted, the application must wait for the
  402. // response from the ANTFSHost object. Possible responses are:
  403. // ANTFS_RESPONSE_AUTHENTICATE_NA
  404. // ANTFS_RESPONSE_AUTHENTICATE_PASS
  405. // ANTFS_RESPONSE_AUTHENTICATE_REJECT
  406. // ANTFS_RESPONSE_AUTHENTICATE_FAIL
  407. // ANTFS_RESPONSE_CONNECTION_LOST
  408. // ANTFS_RESPONSE_SERIAL_FAIL
  409. // Upon receiving the ANTFS_RESPONSE_AUTHENTICATE_PASS, an
  410. // authentication string provided by the remoted device may be
  411. // available in the response buffer. This depends on the
  412. // authentication type used. The transport
  413. // layer connection is also only established after receiving
  414. // ANTFS_RESPONSE_AUTHENTICATE_PASS .
  415. /////////////////////////////////////////////////////////////////
  416. ANTFS_RETURN Disconnect(USHORT usBlackoutTime_, UCHAR ucDisconnectType_ = 0, UCHAR ucTimeDuration_ = 0, UCHAR ucAppSpecificDuration_ = 0);
  417. /////////////////////////////////////////////////////////////////
  418. // Disconnect from a remote device. Optionally put that device
  419. // on a blackout list for a period of time. The application can
  420. // also request the remote device to become undiscoverable for a
  421. // specified time/application specific duration.
  422. // Parameters:
  423. // usBlackoutTime_: The number of seconds the device ID
  424. // should remain on the blackout list. If
  425. // set to zero (0), then the device will
  426. // not be put on the blackout list. If set
  427. // to MAX_USHORT (0xFFFF), the device will
  428. // remain on the blackout list until
  429. // explicitly removed, or until the blackout
  430. // list is reset.
  431. // ucDisconnectType_: Specifies whether the client should
  432. // return to LINK state or broadcast mode
  433. // (ANT-FS broadcast)
  434. // ucTimeDuration_: Time, in 30 seconds increments, the client
  435. // device will remain undiscoverable after
  436. // disconnect has been requested. Set to 0 to
  437. // disable.
  438. // ucAppSpecificDuration_: Application specific duration the client
  439. // shall remain undiscoverable after disconnection.
  440. // This field is left to the developer, or defined
  441. // in an ANT+ Device Profile. Set to 0 to disable.
  442. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  443. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  444. // ANTFS_RETURN_BUSY if the library is busy with another request.
  445. // Operation:
  446. // Once the request is posted, the application must wait for the
  447. // response from the ANTFSHost object. Possible responses are:
  448. // ANTFS_RESPONSE_DISCONNECT_PASS
  449. // ANTFS_RESPONSE_CONNECTION_LOST
  450. // ANTFS_RESPONSE_SERIAL_FAIL
  451. // The remote device will not show up in any search results for
  452. // the duration specified in usBlackoutTime_. This allows the
  453. // host to more easily find other devices in crowded
  454. // environments. The host can also request the remote device to
  455. // become undiscoverable, to more easily find other devices, however
  456. // not all client devices might implement this feature. Not all
  457. // client devices support a broadcast mode.
  458. /////////////////////////////////////////////////////////////////
  459. BOOL Blackout(ULONG ulDeviceID_, USHORT usManufacturerID_, USHORT usDeviceType_, USHORT usBlackoutTime_);
  460. /////////////////////////////////////////////////////////////////
  461. // Put the device on a blackout list for a period of time.
  462. // Parameters:
  463. // ulDeviceID_: The device ID of a specific device.
  464. // usManufacturerID_: The specific manufacturer ID.
  465. // usDeviceType_: The specific device type.
  466. // usBlackoutTime_: The number of seconds the device ID
  467. // should remain on the blackout list. If
  468. // set to zero (0), then the device will
  469. // not be put on the blackout list. If set
  470. // to MAX_USHORT (0xFFFF), the device will
  471. // remain on the blackout list until
  472. // explicitly removed, or until the blackout
  473. // list is reset.
  474. // Returns TRUE if successful. Otherwise, it returns FALSE.
  475. // A wildcard parameter (0) is not allowed in any of the device
  476. // ID parameters and will result in returning FALSE.
  477. // Operation:
  478. // The remote device will not show up in any search results for
  479. // the duration specified in usBlackoutTime_. This allows the
  480. // host to more easily find other devices in crowded
  481. // environments.
  482. /////////////////////////////////////////////////////////////////
  483. BOOL RemoveBlackout(ULONG ulDeviceID_, USHORT usManufacturerID_, USHORT usDeviceType_);
  484. /////////////////////////////////////////////////////////////////
  485. // Remove the device from the blackout list.
  486. // Parameters:
  487. // ulDeviceID_: The device ID of a specific device.
  488. // usManufacturerID_: The specific manufacturer ID.
  489. // usDeviceType_: The specific device type.
  490. // Returns TRUE if successful. Returns FALSE if the device is
  491. // not found in the blackout list. A wildcard parameter (0) is
  492. // not allowed in any of the device ID parameters and will result
  493. // in returning FALSE.
  494. /////////////////////////////////////////////////////////////////
  495. void ClearBlackoutList(void);
  496. /////////////////////////////////////////////////////////////////
  497. // Clears the blackout list.
  498. /////////////////////////////////////////////////////////////////
  499. ANTFS_RETURN Download(USHORT usFileIndex_, ULONG ulDataOffset_, ULONG ulMaxDataLength_, ULONG ulMaxBlockSize_ = 0);
  500. /////////////////////////////////////////////////////////////////
  501. // Request a download of a file from the authenticated device.
  502. // Parameters:
  503. // usFileIndex_: The file number to be downloaded. Some
  504. // file numbers are reserved for special
  505. // purposes, such as the device directory
  506. // (0). Consult the ANT_FS specification
  507. // and any docs for specific device types.
  508. // ulDataOffset_: The byte offset from where to begin
  509. // transferring the data.
  510. // ulMaxDataLength_: ULONG varible that contains the maximum
  511. // number of bytes to download.
  512. // ulMaxBlockSize_: Maximum number of bytes that the host
  513. // wishes to download in a single block.
  514. // Set to zero to disable.
  515. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  516. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  517. // ANTFS_RETURN_BUSY if the library is busy with another request.
  518. // Operation:
  519. // Once the request is posted, the application must wait for the
  520. // response from the ANTFSHost object. Possible responses are:
  521. // ANTFS_RESPONSE_DOWNLOAD_PASS
  522. // ANTFS_RESPONSE_DOWNLOAD_REJECT
  523. // ANTFS_RESPONSE_DOWNLOAD_FAIL
  524. // ANTFS_RESPONSE_CONNECTION_LOST
  525. // ANTFS_RESPONSE_SERIAL_FAIL
  526. // Upon receiving ANTFS_RESPONSE_DOWNLOAD_PASS the downloaed data
  527. // will be available in the transfer buffer. See GetTransferData().
  528. /////////////////////////////////////////////////////////////////
  529. ANTFS_RETURN Upload(USHORT usFileIndex_, ULONG ulDataOffset_, ULONG ulDataLength_, void *pvData_, BOOL bForceOffset_ = TRUE, ULONG ulMaxBlockSize_ = 0);
  530. /////////////////////////////////////////////////////////////////
  531. // Request an upload of a file to the authenticated device.
  532. // Parameters:
  533. // usFileIndex_: The file number to be uploaded. Some
  534. // file numbers are reserved for special
  535. // purposes, such as the device directory
  536. // (0). Consult the ANT_FS specification
  537. // and any docs for specific device types.
  538. // ulDataOffset_: The byte offset from where to begin
  539. // transferring the data.
  540. // ulDataLength_: The byte length of data to be uploaded
  541. // to the remote device.
  542. // Return value:
  543. // *pvData_: Pointer to the location where the data
  544. // to be uploaded is stored. This pointer must be valid
  545. // throughout the entire transfer.
  546. // bForceOffset_: Set to TRUE (default) to enforce the
  547. // provided byte data offset. Set to FALSE
  548. // to continue a transfer, indicating that
  549. // the host will continue the upload at the
  550. // last data offset specified by the client
  551. // in the Upload Response.
  552. // ulMaxBlockSize_: Maximum block size that the host can send
  553. // in a single block of data. Set to zero
  554. // to disable
  555. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  556. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  557. // ANTFS_RETURN_BUSY if the library is busy with another request.
  558. // Operation:
  559. // Once the request is posted, the application must wait for the
  560. // response from the ANTFSHost object. Possible responses are:
  561. // ANTFS_RESPONSE_UPLOAD_PASS
  562. // ANTFS_RESPONSE_UPLOAD_REJECT
  563. // ANTFS_RESPONSE_UPLOAD_FAIL
  564. // ANTFS_RESPONSE_CONNECTION_LOST
  565. // ANTFS_RESPONSE_SERIAL_FAIL
  566. /////////////////////////////////////////////////////////////////
  567. ANTFS_RETURN ManualTransfer(USHORT usFileIndex_, ULONG ulDataOffset_, ULONG ulDataLength_, void *pvData_);
  568. /////////////////////////////////////////////////////////////////
  569. // Send data directly to the device without requesting first.
  570. // This is especially useful for communicating small pieces of
  571. // data to the device. Another use is the implementation of a
  572. // higher-level communication protocol. Care must be taken to
  573. // ensure the device can handle the amount of data being sent
  574. // using this method.
  575. // usFileIndex_: The file number to be uploaded. Some
  576. // file numbers are reserved for special
  577. // purposes, such as the device directory
  578. // (0). Consult the ANT_FS specification
  579. // and any docs for specific device types.
  580. // ulDataOffset_: The byte offset from where to begin
  581. // transferring the data. Note that this
  582. // value will always get rounded up to the
  583. // next higher multiple of 8. Under normal
  584. // use, this parameter should always be set
  585. // to zero, and the only time it would be
  586. // non-zero is for retrying ManualTransfer()
  587. // from a known offset.
  588. // ulDataLength_: The byte length of data to be sent to
  589. // the remote device.
  590. // *pvData_: The Pointer to a buffer where the
  591. // data to be sent is stored.
  592. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  593. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  594. // ANTFS_RETURN_BUSY if the library is busy with another request.
  595. // Operation:
  596. // Once the request is posted, the application must wait for the
  597. // response from the ANTFSHost object. Possible responses are:
  598. // ANTFS_RESPONSE_MANUAL_TRANSFER_PASS
  599. // ANTFS_RESPONSE_MANUAL_TRANSFER_TRANSMIT_FAIL
  600. // ANTFS_RESPONSE_MANUAL_TRANSFER_RESPONSE_FAIL
  601. // ANTFS_RESPONSE_CONNECTION_LOST
  602. // ANTFS_RESPONSE_SERIAL_FAIL
  603. // Upon receiving ANTFS_RESPONSE_MANUAL_TRANSFER_PASS the downloaed data
  604. // will be available in the transfer buffer. See GetTransferData().
  605. /////////////////////////////////////////////////////////////////
  606. ANTFS_RETURN EraseData(USHORT usFileIndex_);
  607. /////////////////////////////////////////////////////////////////
  608. // Request the erasure of a file on the authenticated remote
  609. // device.
  610. // Parameters:
  611. // usFileIndex_: The file number of the file to be erased.
  612. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  613. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  614. // ANTFS_RETURN_BUSY if the library is busy with another request.
  615. // Operation:
  616. // Once the request is posted, the application must wait for the
  617. // response from the ANTFSHost object. Possible responses are:
  618. // ANTFS_RESPONSE_ERASE_PASS
  619. // ANTFS_RESPONSE_ERASE_FAIL
  620. // ANTFS_RESPONSE_CONNECTION_LOST
  621. // ANTFS_RESPONSE_SERIAL_FAIL
  622. /////////////////////////////////////////////////////////////////
  623. BOOL EnablePing(BOOL bEnable_);
  624. /////////////////////////////////////////////////////////////////
  625. // Enables ping message to be sent to the remote device periodically.
  626. // This can be used to keep the remote device from timing out during
  627. // operations that wait for user input (i.e. pairing).
  628. // Parameters:
  629. // bEnable_: Periodic ping enable.
  630. // Returns TRUE if successful. Otherwise, it returns FALSE.
  631. /////////////////////////////////////////////////////////////////
  632. #if defined(DEBUG_FILE)
  633. void SetDebug(BOOL bDebugOn_, const char *pcDirectory_ = (const char*) NULL);
  634. /////////////////////////////////////////////////////////////////
  635. // Enables debug files
  636. // Parameters:
  637. // bDebugOn_: Enable/disable debug logs.
  638. // *pcDirectory_: A string to use as the path for storing
  639. // debug logs. Set to NULL to use the working
  640. // directory as the default path.
  641. /////////////////////////////////////////////////////////////////
  642. #endif
  643. };
  644. #endif // !defined(ANTFS_HOST_H)