antfs_host.hpp 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  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_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_polling.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. DSIANTDevicePolling* 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 GetCurrentConfig( ANTFS_CONFIG_PARAMETERS* pCfg_ );
  151. /////////////////////////////////////////////////////////////////
  152. // Passes back the current value of configurable parameters.
  153. // If SetCurrentConfig has not been called, passes back the defaults.
  154. /////////////////////////////////////////////////////////////////
  155. BOOL SetCurrentConfig( const ANTFS_CONFIG_PARAMETERS* pCfg_ );
  156. /////////////////////////////////////////////////////////////////
  157. // Sets up the configurable parameters.
  158. // Returns TRUE if successful. Otherwise, it returns FALSE.
  159. // If FALSE is returned, all the parameters remain unchanged.
  160. // If this method has not been called, the default values are used.
  161. // It is possible to call this method multiple times in the program.
  162. /////////////////////////////////////////////////////////////////
  163. void SetChannelID(UCHAR ucDeviceType_, UCHAR ucTransmissionType_);
  164. void SetMessagePeriod(USHORT usMessagePeriod_);
  165. void SetNetworkkey(UCHAR ucNetworkkey[]);
  166. void SetProximitySearch(UCHAR ucSearchThreshold_);
  167. /////////////////////////////////////////////////////////////////
  168. // Sets the value for the proximity bin setting for searching.
  169. // Note: If applying this value fails when attempting to start search,
  170. // it is ignored to maintain compatibility with devices that
  171. // do not support this feature. This means that a real failure can occur
  172. // on a device that actually does support it, and it will be missed. The
  173. // debug log will show if this command fails.
  174. // Parameters:
  175. // ucSearchThreshold_ Desired proximity bin from 0-10 (If value is
  176. // set higher then 10, it is automatically capped at 10)
  177. /////////////////////////////////////////////////////////////////
  178. void Close(void);
  179. /////////////////////////////////////////////////////////////////
  180. // Stops any pending actions, closes all devices down and cleans
  181. // up any dynamic memory being used by the library.
  182. /////////////////////////////////////////////////////////////////
  183. ANTFS_STATE GetStatus(void);
  184. /////////////////////////////////////////////////////////////////
  185. // Returns the current library status.
  186. /////////////////////////////////////////////////////////////////
  187. /////////////////////////////////////////////////////////////////
  188. // Returns the current ANTFS state from the last seen ANTFS beacon of the
  189. // connected device.
  190. // Returns the beacon ANTFS state:
  191. // REMOTE_DEVICE_STATE_LINK
  192. // REMOTE_DEVICE_STATE_AUTH
  193. //...REMOTE_DEVICE_STATE_TRANS
  194. //...REMOTE_DEVICE_STATE_BUSY
  195. // or REMOTE_DEVICE_BEACON_NOT_FOUND if no device is connected
  196. /////////////////////////////////////////////////////////////////
  197. UCHAR GetConnectedDeviceBeaconAntfsState(void);
  198. ANTFS_RESPONSE WaitForResponse(ULONG ulMilliseconds_);
  199. /////////////////////////////////////////////////////////////////
  200. // Wait for a response from the ANTFSHost object.
  201. // Parameters:
  202. // ulMilliseconds_: Set this value to the minimum time to
  203. // wait before returning. If the value is
  204. // 0, the function will return immediately.
  205. // If the value is DSI_THREAD_INFINITE, the
  206. // function will not time out.
  207. // If one or more responses are pending before the timeout
  208. // expires the function will return the first response that
  209. // occured. If no response is pending at the time the timeout
  210. // expires, ANTFS_RESPONSE_NONE is returned.
  211. /////////////////////////////////////////////////////////////////
  212. void Cancel(void);
  213. /////////////////////////////////////////////////////////////////
  214. // Cancels any pending actions and returns the library to the
  215. // appropriate ANTFS layer if possible. ie if the library was
  216. // executing a download command in the transport layer, the
  217. // library would be returned to ANTFS_STATE_TRANSPORT after
  218. // execution of this function.
  219. /////////////////////////////////////////////////////////////////
  220. USHORT AddSearchDevice(ANTFS_DEVICE_PARAMETERS *pstDeviceSearchMask_, ANTFS_DEVICE_PARAMETERS *pstDeviceParameters_);
  221. /////////////////////////////////////////////////////////////////
  222. // Adds a set of parameters for which to search to the internal
  223. // search device list.
  224. // Parameters:
  225. // *pstDeviceSearchMask_: A pointer to an
  226. // ANTFS_DEVICE_PARAMETERS structure. Set a
  227. // member to zero (0) to wildcard search for
  228. // it. Otherwise, set the bits that you want
  229. // to be matched to 1 in each member. Members
  230. // that are integer values will be treated the
  231. // same as bit fields for the purposes for the mask.
  232. // *pstDeviceParameters_: A pointer to an
  233. // ANTFS_DEVICE_PARAMETERS structure. Set
  234. // the member to the desired search value.
  235. // A member in this structure is ignored if
  236. // the associated member in the
  237. // *pstDeviceSearchMask_ parameter is set
  238. // to zero (0) for wildcard.
  239. // Returns a handle the the search device entry. If the return
  240. // value is 0, the function failed adding the device entry.
  241. // This means that the device list is already full.
  242. // Operation:
  243. // Note that the default search masks should normally be applied
  244. // to the ucStatusByte1 and ucStatusByte2 members of the
  245. // *pstDeviceSearchMask_ parameter. Eg;
  246. // pstMyDeviceSearchMask->ucStatusByte1 =
  247. // ANTFS_STATUS1_DEFAULT_SEARCH_MASK & ucMyStatus1Criteria;
  248. // Setting bits outside the masks, especially reserved bits, may
  249. // lead to undesired behaviour.
  250. /////////////////////////////////////////////////////////////////
  251. void RemoveSearchDevice(USHORT usHandle_);
  252. /////////////////////////////////////////////////////////////////
  253. // Removes a device entry from the internal search list.
  254. // Parameters:
  255. // usHandle_: Handle to the device entry to be removed
  256. // from the list.
  257. /////////////////////////////////////////////////////////////////
  258. void ClearSearchDeviceList(void);
  259. /////////////////////////////////////////////////////////////////
  260. // Clears the internal search device list.
  261. /////////////////////////////////////////////////////////////////
  262. ANTFS_RETURN SearchForDevice(UCHAR ucSearchRadioFrequency_ = ANTFS_RF_FREQ, UCHAR ucConnectRadioFrequency_ = ANTFS_DEFAULT_TRANSPORT_FREQ, USHORT usRadioChannelID_ = 0, BOOL bUseRequestPage_ = FALSE);
  263. /////////////////////////////////////////////////////////////////
  264. // Begins a search for ANTFS remote devices.
  265. // Parameters:
  266. // ucSearchRadioFrequency_: This specifies the frequency on
  267. // which to search for devices. This
  268. // frequency is calculated as
  269. // (ucSearchRadioFrequency_ * 1 MHz +
  270. // 2400 MHz). MAX_UCHAR (0xFF) is reserved.
  271. // ucConnectRadioFrequency_: This specifies the frequency
  272. // on which the connection communication
  273. // will occur. This frequency is calculated
  274. // as (ucConnectRadioFrequency_ * 1 MHz +
  275. // 2400 MHz). If ucConnectRadioFrequency_
  276. // is set to ANTFS_AUTO_FREQUENCY_SELECTION
  277. // (0xFF), then the library will use an
  278. // adaptive frequency-hopping scheme.
  279. // usRadioChannelID_: This specifies the channel ID for the
  280. // the ANT channel search. Set to zero to
  281. // wildcard.
  282. // bUseRequestPage_: Specifies whether the search will include
  283. // ANT-FS broadcast devices, using a request
  284. // page to begin an ANT-FS session
  285. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  286. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  287. // ANTFS_RETURN_BUSY if the library is busy with another request.
  288. // Operation:
  289. // Once this function is called successfully, the application
  290. // must wait for the response from the ANTFSHost object.
  291. // Possible responses are:
  292. // ANTFS_RESPONSE_CONNECT_PASS
  293. // ANTFS_RESPONSE_SERIAL_FAIL
  294. // The library will continue to search for devices until a device
  295. // is found, the Cancel() function is called, an error occurs, or
  296. // the library is closed.
  297. /////////////////////////////////////////////////////////////////
  298. BOOL GetFoundDeviceParameters(ANTFS_DEVICE_PARAMETERS *pstDeviceParameters_, UCHAR *aucFriendlyName_, UCHAR *pucBufferSize_);
  299. /////////////////////////////////////////////////////////////////
  300. // Copies the parameters of the most recently found device to the
  301. // supplied parameter.
  302. // Parameters:
  303. // *ptsDeviceParameters_: A pointer to a structure that will
  304. // receive a copy of the device parameters.
  305. // *aucFriendlyName_: A pointer to a buffer where the remote
  306. // device friendly name will be copied.
  307. // *pucBufferSize_: Pointer to a UCHAR variable that should contain the
  308. // maximum size of the buffer pointed to by aucFriendlyName_.
  309. // aucFriendlyName will receive a copy of min(pucBufferSize, actualSize) length.
  310. // After the function returns, this variable
  311. // will be set to reflect the actual size of friendly name string.
  312. // Returns TRUE if successful. Otherwise, it returns FALSE.
  313. /////////////////////////////////////////////////////////////////
  314. BOOL GetFoundDeviceChannelID(USHORT *pusDeviceNumber_ = (USHORT *)NULL, UCHAR *pucDeviceType_ = (UCHAR *)NULL, UCHAR *pucTransmitType_ = (UCHAR *)NULL);
  315. /////////////////////////////////////////////////////////////////
  316. // Copies the ANT channel ID of the most recently found device to
  317. // the supplied parameters.
  318. // Parameters:
  319. // *pusDeviceNumber_: A pointer to a USHORT variable that will
  320. // receive the ANT device number of the device.
  321. // *pucDeviceType_: A pointer to a UCHAR variable that will
  322. // hold the =device type of the found device.
  323. // *pucTransmitType_: Pointer to a UCHAR variable that will
  324. // receive the transmission type of the found
  325. // device
  326. // Returns TRUE if successful. Otherwise, it returns FALSE.
  327. /////////////////////////////////////////////////////////////////
  328. BOOL GetUploadStatus(ULONG *pulByteProgress_, ULONG *pulTotalLength_);
  329. /////////////////////////////////////////////////////////////////
  330. // Gets the transfer progress of a pending or a complete
  331. // upload.
  332. // Parameters:
  333. // *pulByteProgress_: Pointer to a ULONG that will receive
  334. // the current byte progress of a pending or
  335. // complete upload.
  336. // *pulTotalLength_: Pointer to a ULONG that will receive the
  337. // total length of the file being uploaded.
  338. // Returns TRUE if successful. Otherwise, it returns FALSE.
  339. // Operation:
  340. // A data upload occurs when information is requested to be sent to
  341. // a remote device. This function may be called at any point
  342. // during an upload as a progress indicator. After the upload
  343. // is complete, this information is valid until another request
  344. // for a data transfer is made.
  345. /////////////////////////////////////////////////////////////////
  346. BOOL GetDownloadStatus(ULONG *pulByteProgress_, ULONG *pulTotalLength_);
  347. /////////////////////////////////////////////////////////////////
  348. // Gets the transfer progress of a pending or a complete
  349. // download.
  350. // Parameters:
  351. // *pulByteProgress_: Pointer to a ULONG that will receive
  352. // the current byte progress of a pending or
  353. // complete download.
  354. // *pulTotalLength_: Pointer to a ULONG that will receive the
  355. // total expected length of the download.
  356. // Returns TRUE if successful. Otherwise, it returns FALSE.
  357. // Operation:
  358. // A data download occurs when information is requested from a
  359. // remote device. This function may be called at any point
  360. // during a download as a progress indicator. After the transfer
  361. // is complete, this information is valid until another request
  362. // for a data transfer is made.
  363. /////////////////////////////////////////////////////////////////
  364. BOOL GetTransferData(ULONG *pulDataSize_ , void *pvData_ = NULL);
  365. /////////////////////////////////////////////////////////////////
  366. // Gets the received data from a transfer (download/manual transfer).
  367. //
  368. // Parameters:
  369. // *ulDataSize_ : Pointer to a ULONG that will receive
  370. // the size of the data available in bytes.
  371. // *pvData_ : Pointer to a buffer where the received data
  372. // will be copied. NULL can be passed to this
  373. // parameter so that the size can be retried
  374. // without copying any data. The application
  375. // can then call this function again to after it
  376. // has allocated a buffer of sufficient size to
  377. // handle the data.
  378. // Returns TRUE if successful. Otherwise, it returns FALSE.
  379. /////////////////////////////////////////////////////////////////
  380. BOOL RecoverTransferData(ULONG *pulDataSize_ , void *pvData_ = NULL);
  381. /////////////////////////////////////////////////////////////////
  382. // Gets the partially received data from a failed transfer (download/manual transfer).
  383. //
  384. // Parameters:
  385. // *ulDataSize_ : Pointer to a ULONG that will receive
  386. // the size of the data available in bytes.
  387. // *pvData_ : Pointer to a buffer where the received data
  388. // will be copied. NULL can be passed to this
  389. // parameter so that the size can be retried
  390. // without copying any data. The application
  391. // can then call this function again to after it
  392. // has allocated a buffer of sufficient size to
  393. // handle the data.
  394. // Returns TRUE if successful. Otherwise, it returns FALSE.
  395. /////////////////////////////////////////////////////////////////
  396. ANTFS_RETURN Authenticate(UCHAR ucAuthenticationType_, UCHAR *pucAuthenticationString_, UCHAR ucLength_, UCHAR *aucResponseBuffer_, UCHAR *pucResponseBufferSize_, ULONG ulResponseTimeout_);
  397. /////////////////////////////////////////////////////////////////
  398. // Request to pair with the connected remote device.
  399. // Parameters:
  400. // ucAuthenticationType_: The type of authentication to
  401. // execute on the remote device.
  402. // *pucAuthenticationString_: A string that may be used in
  403. // conjunction with the particular
  404. // authentication type in use (e.g. a
  405. // password or a friendly name.
  406. // ucLength_: The length of the authentication string,
  407. // including any '\n' terminator. This
  408. // parameter may be set to zero if an
  409. // authentication string is not required.
  410. // *pucResponseBuffer_: Pointer to the buffer where additional
  411. // data from the response will be saved. This will
  412. // include data such as passwords and friendly names.
  413. // This memory must be allocated by the application.
  414. // *pucResponseBufferSize_: Pointer to UCHAR varible that contains the
  415. // size of the buffer pointed to by pucResponseBuffer_.
  416. // After the response has be recived, the UCHAR variable
  417. // will be set to reflect the size of the new data received
  418. // in pucResponseBuffer_.
  419. // ulResponseTimeout_: Number of miliseconds to wait for a response after
  420. // the authenticate command is sent.
  421. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  422. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  423. // ANTFS_RETURN_BUSY if the library is busy with another request.
  424. // Operation:
  425. // Once the request is posted, the application must wait for the
  426. // response from the ANTFSHost object. Possible responses are:
  427. // ANTFS_RESPONSE_AUTHENTICATE_NA
  428. // ANTFS_RESPONSE_AUTHENTICATE_PASS
  429. // ANTFS_RESPONSE_AUTHENTICATE_REJECT
  430. // ANTFS_RESPONSE_AUTHENTICATE_FAIL
  431. // ANTFS_RESPONSE_CONNECTION_LOST
  432. // ANTFS_RESPONSE_SERIAL_FAIL
  433. // Upon receiving the ANTFS_RESPONSE_AUTHENTICATE_PASS, an
  434. // authentication string provided by the remoted device may be
  435. // available in the response buffer. This depends on the
  436. // authentication type used. The transport
  437. // layer connection is also only established after receiving
  438. // ANTFS_RESPONSE_AUTHENTICATE_PASS .
  439. /////////////////////////////////////////////////////////////////
  440. ANTFS_RETURN Disconnect(USHORT usBlackoutTime_, UCHAR ucDisconnectType_ = 0, UCHAR ucTimeDuration_ = 0, UCHAR ucAppSpecificDuration_ = 0);
  441. /////////////////////////////////////////////////////////////////
  442. // Disconnect from a remote device. Optionally put that device
  443. // on a blackout list for a period of time. The application can
  444. // also request the remote device to become undiscoverable for a
  445. // specified time/application specific duration.
  446. // Parameters:
  447. // usBlackoutTime_: The number of seconds the device ID
  448. // should remain on the blackout list. If
  449. // set to zero (0), then the device will
  450. // not be put on the blackout list. If set
  451. // to MAX_USHORT (0xFFFF), the device will
  452. // remain on the blackout list until
  453. // explicitly removed, or until the blackout
  454. // list is reset.
  455. // ucDisconnectType_: Specifies whether the client should
  456. // return to LINK state or broadcast mode
  457. // (ANT-FS broadcast)
  458. // ucTimeDuration_: Time, in 30 seconds increments, the client
  459. // device will remain undiscoverable after
  460. // disconnect has been requested. Set to 0 to
  461. // disable.
  462. // ucAppSpecificDuration_: Application specific duration the client
  463. // shall remain undiscoverable after disconnection.
  464. // This field is left to the developer, or defined
  465. // in an ANT+ Device Profile. Set to 0 to disable.
  466. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  467. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  468. // ANTFS_RETURN_BUSY if the library is busy with another request.
  469. // Operation:
  470. // Once the request is posted, the application must wait for the
  471. // response from the ANTFSHost object. Possible responses are:
  472. // ANTFS_RESPONSE_DISCONNECT_PASS
  473. // ANTFS_RESPONSE_CONNECTION_LOST
  474. // ANTFS_RESPONSE_SERIAL_FAIL
  475. // The remote device will not show up in any search results for
  476. // the duration specified in usBlackoutTime_. This allows the
  477. // host to more easily find other devices in crowded
  478. // environments. The host can also request the remote device to
  479. // become undiscoverable, to more easily find other devices, however
  480. // not all client devices might implement this feature. Not all
  481. // client devices support a broadcast mode.
  482. /////////////////////////////////////////////////////////////////
  483. BOOL Blackout(ULONG ulDeviceID_, USHORT usManufacturerID_, USHORT usDeviceType_, USHORT usBlackoutTime_);
  484. /////////////////////////////////////////////////////////////////
  485. // Put the device on a blackout list for a period of time.
  486. // Parameters:
  487. // ulDeviceID_: The device ID of a specific device.
  488. // usManufacturerID_: The specific manufacturer ID.
  489. // usDeviceType_: The specific device type.
  490. // usBlackoutTime_: The number of seconds the device ID
  491. // should remain on the blackout list. If
  492. // set to zero (0), then the device will
  493. // not be put on the blackout list. If set
  494. // to MAX_USHORT (0xFFFF), the device will
  495. // remain on the blackout list until
  496. // explicitly removed, or until the blackout
  497. // list is reset.
  498. // Returns TRUE if successful. Otherwise, it returns FALSE.
  499. // A wildcard parameter (0) is not allowed in any of the device
  500. // ID parameters and will result in returning FALSE.
  501. // Operation:
  502. // The remote device will not show up in any search results for
  503. // the duration specified in usBlackoutTime_. This allows the
  504. // host to more easily find other devices in crowded
  505. // environments.
  506. /////////////////////////////////////////////////////////////////
  507. BOOL RemoveBlackout(ULONG ulDeviceID_, USHORT usManufacturerID_, USHORT usDeviceType_);
  508. /////////////////////////////////////////////////////////////////
  509. // Remove the device from the blackout list.
  510. // Parameters:
  511. // ulDeviceID_: The device ID of a specific device.
  512. // usManufacturerID_: The specific manufacturer ID.
  513. // usDeviceType_: The specific device type.
  514. // Returns TRUE if successful. Returns FALSE if the device is
  515. // not found in the blackout list. A wildcard parameter (0) is
  516. // not allowed in any of the device ID parameters and will result
  517. // in returning FALSE.
  518. /////////////////////////////////////////////////////////////////
  519. void ClearBlackoutList(void);
  520. /////////////////////////////////////////////////////////////////
  521. // Clears the blackout list.
  522. /////////////////////////////////////////////////////////////////
  523. ANTFS_RETURN Download(USHORT usFileIndex_, ULONG ulDataOffset_, ULONG ulMaxDataLength_, ULONG ulMaxBlockSize_ = 0);
  524. /////////////////////////////////////////////////////////////////
  525. // Request a download of a file from the authenticated device.
  526. // Parameters:
  527. // usFileIndex_: The file number to be downloaded. Some
  528. // file numbers are reserved for special
  529. // purposes, such as the device directory
  530. // (0). Consult the ANT_FS specification
  531. // and any docs for specific device types.
  532. // ulDataOffset_: The byte offset from where to begin
  533. // transferring the data.
  534. // ulMaxDataLength_: ULONG varible that contains the maximum
  535. // number of bytes to download.
  536. // ulMaxBlockSize_: Maximum number of bytes that the host
  537. // wishes to download in a single block.
  538. // Set to zero to disable.
  539. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  540. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  541. // ANTFS_RETURN_BUSY if the library is busy with another request.
  542. // Operation:
  543. // Once the request is posted, the application must wait for the
  544. // response from the ANTFSHost object. Possible responses are:
  545. // ANTFS_RESPONSE_DOWNLOAD_PASS
  546. // ANTFS_RESPONSE_DOWNLOAD_REJECT
  547. // ANTFS_RESPONSE_DOWNLOAD_FAIL
  548. // ANTFS_RESPONSE_CONNECTION_LOST
  549. // ANTFS_RESPONSE_SERIAL_FAIL
  550. // Upon receiving ANTFS_RESPONSE_DOWNLOAD_PASS the downloaed data
  551. // will be available in the transfer buffer. See GetTransferData().
  552. /////////////////////////////////////////////////////////////////
  553. ANTFS_RETURN Upload(USHORT usFileIndex_, ULONG ulDataOffset_, ULONG ulDataLength_, void *pvData_, BOOL bForceOffset_ = TRUE, ULONG ulMaxBlockSize_ = 0);
  554. /////////////////////////////////////////////////////////////////
  555. // Request an upload of a file to the authenticated device.
  556. // Parameters:
  557. // usFileIndex_: The file number to be uploaded. Some
  558. // file numbers are reserved for special
  559. // purposes, such as the device directory
  560. // (0). Consult the ANT_FS specification
  561. // and any docs for specific device types.
  562. // ulDataOffset_: The byte offset from where to begin
  563. // transferring the data.
  564. // ulDataLength_: The byte length of data to be uploaded
  565. // to the remote device.
  566. // Return value:
  567. // *pvData_: Pointer to the location where the data
  568. // to be uploaded is stored. This pointer must be valid
  569. // throughout the entire transfer.
  570. // bForceOffset_: Set to TRUE (default) to enforce the
  571. // provided byte data offset. Set to FALSE
  572. // to continue a transfer, indicating that
  573. // the host will continue the upload at the
  574. // last data offset specified by the client
  575. // in the Upload Response.
  576. // ulMaxBlockSize_: Maximum block size that the host can send
  577. // in a single block of data. Set to zero
  578. // to disable
  579. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  580. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  581. // ANTFS_RETURN_BUSY if the library is busy with another request.
  582. // Operation:
  583. // Once the request is posted, the application must wait for the
  584. // response from the ANTFSHost object. Possible responses are:
  585. // ANTFS_RESPONSE_UPLOAD_PASS
  586. // ANTFS_RESPONSE_UPLOAD_REJECT
  587. // ANTFS_RESPONSE_UPLOAD_FAIL
  588. // ANTFS_RESPONSE_CONNECTION_LOST
  589. // ANTFS_RESPONSE_SERIAL_FAIL
  590. /////////////////////////////////////////////////////////////////
  591. ANTFS_RETURN ManualTransfer(USHORT usFileIndex_, ULONG ulDataOffset_, ULONG ulDataLength_, void *pvData_);
  592. /////////////////////////////////////////////////////////////////
  593. // Send data directly to the device without requesting first.
  594. // This is especially useful for communicating small pieces of
  595. // data to the device. Another use is the implementation of a
  596. // higher-level communication protocol. Care must be taken to
  597. // ensure the device can handle the amount of data being sent
  598. // using this method.
  599. // usFileIndex_: The file number to be uploaded. Some
  600. // file numbers are reserved for special
  601. // purposes, such as the device directory
  602. // (0). Consult the ANT_FS specification
  603. // and any docs for specific device types.
  604. // ulDataOffset_: The byte offset from where to begin
  605. // transferring the data. Note that this
  606. // value will always get rounded up to the
  607. // next higher multiple of 8. Under normal
  608. // use, this parameter should always be set
  609. // to zero, and the only time it would be
  610. // non-zero is for retrying ManualTransfer()
  611. // from a known offset.
  612. // ulDataLength_: The byte length of data to be sent to
  613. // the remote device.
  614. // *pvData_: The Pointer to a buffer where the
  615. // data to be sent is stored.
  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. // Once the request is posted, the application must wait for the
  621. // response from the ANTFSHost object. Possible responses are:
  622. // ANTFS_RESPONSE_MANUAL_TRANSFER_PASS
  623. // ANTFS_RESPONSE_MANUAL_TRANSFER_TRANSMIT_FAIL
  624. // ANTFS_RESPONSE_MANUAL_TRANSFER_RESPONSE_FAIL
  625. // ANTFS_RESPONSE_CONNECTION_LOST
  626. // ANTFS_RESPONSE_SERIAL_FAIL
  627. // Upon receiving ANTFS_RESPONSE_MANUAL_TRANSFER_PASS the downloaed data
  628. // will be available in the transfer buffer. See GetTransferData().
  629. /////////////////////////////////////////////////////////////////
  630. ANTFS_RETURN EraseData(USHORT usFileIndex_);
  631. /////////////////////////////////////////////////////////////////
  632. // Request the erasure of a file on the authenticated remote
  633. // device.
  634. // Parameters:
  635. // usFileIndex_: The file number of the file to be erased.
  636. // Returns ANTFS_RETURN_PASS if successful. Otherwise, it returns
  637. // ANTFS_RETURN_FAIL if the library is in the wrong state, or
  638. // ANTFS_RETURN_BUSY if the library is busy with another request.
  639. // Operation:
  640. // Once the request is posted, the application must wait for the
  641. // response from the ANTFSHost object. Possible responses are:
  642. // ANTFS_RESPONSE_ERASE_PASS
  643. // ANTFS_RESPONSE_ERASE_FAIL
  644. // ANTFS_RESPONSE_CONNECTION_LOST
  645. // ANTFS_RESPONSE_SERIAL_FAIL
  646. /////////////////////////////////////////////////////////////////
  647. BOOL EnablePing(BOOL bEnable_);
  648. /////////////////////////////////////////////////////////////////
  649. // Enables ping message to be sent to the remote device periodically.
  650. // This can be used to keep the remote device from timing out during
  651. // operations that wait for user input (i.e. pairing).
  652. // Parameters:
  653. // bEnable_: Periodic ping enable.
  654. // Returns TRUE if successful. Otherwise, it returns FALSE.
  655. /////////////////////////////////////////////////////////////////
  656. #if defined(DEBUG_FILE)
  657. void SetDebug(BOOL bDebugOn_, const char *pcDirectory_ = (const char*) NULL);
  658. /////////////////////////////////////////////////////////////////
  659. // Enables debug files
  660. // Parameters:
  661. // bDebugOn_: Enable/disable debug logs.
  662. // *pcDirectory_: A string to use as the path for storing
  663. // debug logs. Set to NULL to use the working
  664. // directory as the default path.
  665. /////////////////////////////////////////////////////////////////
  666. #endif
  667. };
  668. #endif // !defined(ANTFS_HOST_H)