dsi_framer_integrated_antfs_client.cpp 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223
  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. #include "types.h"
  9. #include "defines.h"
  10. #include "antmessage.h"
  11. #include "antdefines.h"
  12. #include "checksum.h"
  13. #include "dsi_thread.h"
  14. #include "dsi_framer_ant.hpp"
  15. #include <string.h>
  16. #define WAIT_TO_FEED_TRANSFER
  17. #include "dsi_debug.hpp"
  18. #if defined(DEBUG_FILE)
  19. #define SERIAL_DEBUG
  20. #endif
  21. //////////////////////////////////////////////////
  22. //ANTFS Tx-Message Buffer Offsets
  23. //////////////////////////////////////////////////
  24. #define OFFSET_COMMAND_ID ((UCHAR)0x00)
  25. #define OFFSET_REQUEST_ID ((UCHAR)0x00)
  26. #define OFFSET_MESSAGE_ID ((UCHAR)0x01)
  27. #define OFFSET_DATA0 ((UCHAR)0x02)
  28. //////////////////////////////////////////////////
  29. //ANTFS Command-Response Buffer Offsets
  30. //////////////////////////////////////////////////
  31. #define OFFSET_RESPONSE_RESPONSE_ID_HIGH ((UCHAR)0x00)
  32. #define OFFSET_RESPONSE_COMMAND_ID_LOW ((UCHAR)0x01)
  33. #define OFFSET_RESPONSE_COMMAND_ID_HIGH ((UCHAR)0x02)
  34. #define OFFSET_RESPONSE_FSRESPONSE ((UCHAR)0x03)
  35. //////////////////////////////////////////////////
  36. //ANTFS Request-Response Buffer Offsets
  37. //////////////////////////////////////////////////
  38. #define OFFSET_REQUEST_RESPONSE_RESPONSE_ID ((UCHAR)0x00)
  39. #define OFFSET_REQUEST_RESPONSE_FSRESPONSE ((UCHAR)0x01)
  40. #define OFFSET_REQUEST_RESPONSE_PAYLOAD ((UCHAR)0x02)
  41. ////////////////////////////////////////////////////////
  42. //Public Functions
  43. // This file contains the implementation of the extended ANT messaging
  44. // for integrated ANT-FS client. Function declarations are
  45. // in dsi_framer_ant.hpp
  46. ////////////////////////////////////////////////////////
  47. ///////////////////////////////////////////////////////////////////////
  48. BOOL DSIFramerANT::SendFSCommand(FS_MESSAGE *pstFSMessage_, USHORT usMessageSize_, UCHAR* pucFSResponse, ULONG ulResponseTime_)
  49. {
  50. ANTMessageResponse *pclCommandResponse = (ANTMessageResponse*)NULL;
  51. // If we are going to be waiting for a response setup the Response object
  52. if (ulResponseTime_ != 0)
  53. {
  54. UCHAR aucDesiredData[MESG_FS_REQUEST_RESPONSE_SIZE];
  55. UCHAR bytesToMatch = MESG_FS_REQUEST_RESPONSE_SIZE;
  56. aucDesiredData[OFFSET_RESPONSE_RESPONSE_ID_HIGH] = (UCHAR)(MESG_EXT_RESPONSE_ID & 0xFF);
  57. aucDesiredData[OFFSET_RESPONSE_COMMAND_ID_LOW] = pstFSMessage_->ucCommandID;
  58. aucDesiredData[OFFSET_RESPONSE_COMMAND_ID_HIGH] = pstFSMessage_->ucMessageID;
  59. pclCommandResponse = new ANTMessageResponse();
  60. pclCommandResponse->Attach((UCHAR)((MESG_EXT_RESPONSE_ID >> 8) & 0xFF), aucDesiredData, bytesToMatch, this);
  61. }
  62. // Write the command message.
  63. if (!WriteMessage(pstFSMessage_, usMessageSize_))
  64. {
  65. #if defined(DEBUG_FILE)
  66. DSIDebug::ThreadWrite("Framer->SendFSCommand(): WriteMessage Failed.");
  67. #endif
  68. if(pclCommandResponse != NULL)
  69. {
  70. delete pclCommandResponse;
  71. pclCommandResponse = (ANTMessageResponse*)NULL;
  72. }
  73. return FALSE;
  74. }
  75. // Return immediately if we aren't waiting for the response.
  76. if (ulResponseTime_ == 0)
  77. return TRUE;
  78. // Wait for the response.
  79. pclCommandResponse->WaitForResponse(ulResponseTime_);
  80. pclCommandResponse->Remove(); //detach from list
  81. // We haven't received a response in the allotted time.
  82. //if (pclCommandResponse->stMessageItem.ucSize == 0)
  83. if (pclCommandResponse->bResponseReady == FALSE)
  84. {
  85. delete pclCommandResponse;
  86. #if defined(SERIAL_DEBUG)
  87. DSIDebug::ThreadWrite("Framer->SendCommand(): Timeout.");
  88. #endif
  89. return FALSE;
  90. }
  91. // Check the response.
  92. if (pclCommandResponse->stMessageItem.stANTMessage.aucData[OFFSET_RESPONSE_FSRESPONSE] != FS_NO_ERROR_RESPONSE)
  93. {
  94. delete pclCommandResponse;
  95. #if defined(DEBUG_FILE)
  96. DSIDebug::ThreadWrite("Framer->SendFSCommand(): Response != RESPONSE_NO_ERROR.");
  97. #endif
  98. return FALSE;
  99. }
  100. *pucFSResponse = pclCommandResponse->stMessageItem.stANTMessage.aucData[OFFSET_RESPONSE_FSRESPONSE]; //Save the FSResponse
  101. delete pclCommandResponse;
  102. return TRUE;
  103. }
  104. ///////////////////////////////////////////////////////////////////////
  105. BOOL DSIFramerANT::SendFSRequest(UCHAR MesgSize, ANT_MESSAGE_ITEM *pstANTResponse_, FS_MESSAGE stMessage, ULONG ulResponseTime_)
  106. {
  107. ANTMessageResponse *pclRequestResponse = (ANTMessageResponse*)NULL;
  108. // If we are going to be waiting for a response setup the Response object
  109. if ((ulResponseTime_ != 0) && (pstANTResponse_ != NULL))
  110. {
  111. pclRequestResponse = new ANTMessageResponse();
  112. pclRequestResponse->Attach(MESG_EXT_ID_2, (UCHAR*)NULL, 0, this);
  113. }
  114. // Write the command message.
  115. if (!WriteMessage(&stMessage, MesgSize))
  116. {
  117. if(pclRequestResponse != NULL)
  118. {
  119. delete pclRequestResponse;
  120. pclRequestResponse = (ANTMessageResponse*)NULL;
  121. }
  122. return FALSE;
  123. }
  124. // Return immediately if we aren't waiting for the response.
  125. if ((ulResponseTime_ == 0) || (pstANTResponse_ == NULL))
  126. return TRUE;
  127. // Wait for the response.
  128. pclRequestResponse->WaitForResponse(ulResponseTime_);
  129. pclRequestResponse->Remove();
  130. // We haven't received a response in the allotted time.
  131. if (pclRequestResponse->bResponseReady == FALSE)
  132. {
  133. delete pclRequestResponse;
  134. return FALSE;
  135. }
  136. // Copy out the response
  137. pstANTResponse_->ucSize = pclRequestResponse->stMessageItem.ucSize;
  138. pstANTResponse_->stANTMessage.ucMessageID = pclRequestResponse->stMessageItem.stANTMessage.ucMessageID;
  139. memcpy (pstANTResponse_->stANTMessage.aucData, pclRequestResponse->stMessageItem.stANTMessage.aucData, pclRequestResponse->stMessageItem.ucSize);
  140. delete pclRequestResponse;
  141. return TRUE;
  142. }
  143. UCHAR getByte_ulLE(int byteNum, ULONG value)
  144. {
  145. if (byteNum == 1) //Return low byte
  146. return (UCHAR)(value & 0x000000FF);
  147. else if (byteNum == 2) //Return mid-low byte
  148. return (UCHAR)((value & 0x0000FF00) >> 8);
  149. else if (byteNum == 3) //Return mid-high byte
  150. return (UCHAR)((value & 0x00FF0000) >> 16);
  151. else if (byteNum == 4) //Return high byte
  152. return (UCHAR)((value & 0xFF000000) >> 24);
  153. #if defined(DEBUG_FILE)
  154. DSIDebug::ThreadWrite("getByte_ulLE(): Invalid byteNum, returning 0.");
  155. #endif
  156. return 0; //If bytenum is invalid always return 0
  157. }
  158. /////////////////////////////////////////////////////
  159. //ANTFS_Integrated Serial Functions
  160. ////////////////////////////////////////////////////
  161. //////////////////////////////////////////////////////////////
  162. /* MEMDev COMMANDS */
  163. //////////////////////////////////////////////////////////////
  164. BOOL DSIFramerANT::InitEEPROMDevice(USHORT usPageSize_, UCHAR ucAddressConfig_, ULONG ulResponseTime_)
  165. {
  166. FS_MESSAGE stMessage;
  167. UCHAR ucResponse;
  168. stMessage.ucCommandID = (UCHAR)((MESG_MEMDEV_EEPROM_INIT_ID >> 8) & 0xFF);
  169. stMessage.ucMessageID = (UCHAR)(MESG_MEMDEV_EEPROM_INIT_ID & 0xFF);
  170. stMessage.aucData[0] = getByte_ulLE(1,usPageSize_);
  171. stMessage.aucData[1] = getByte_ulLE(2,usPageSize_);
  172. stMessage.aucData[2] = getByte_ulLE(1,ucAddressConfig_);
  173. if(SendFSCommand(&stMessage, MESG_MEMDEV_EEPROM_INIT_SIZE, &ucResponse, ulResponseTime_))
  174. {
  175. ucFSResponse = ucResponse;
  176. return TRUE;
  177. }
  178. else
  179. return FALSE;
  180. }
  181. ////////////////////////////////////////////////////////////////////////
  182. /* File System Commands*/
  183. ////////////////////////////////////////////////////////////////////////
  184. BOOL DSIFramerANT::InitFSMemory(ULONG ulResponseTime_)
  185. {
  186. FS_MESSAGE stMessage;
  187. UCHAR ucResponse;
  188. stMessage.ucCommandID = (UCHAR)((MESG_FS_INIT_MEMORY_ID >> 8) & 0xFF);
  189. stMessage.ucMessageID = (UCHAR)(MESG_FS_INIT_MEMORY_ID & 0xFF);
  190. if(SendFSCommand(&stMessage, MESG_FS_INIT_MEMORY_SIZE, &ucResponse, ulResponseTime_))
  191. {
  192. ucFSResponse = ucResponse; //save FSResponse
  193. return TRUE;
  194. }
  195. else
  196. {
  197. ucFSResponse = ucResponse;
  198. return FALSE;
  199. }
  200. }
  201. ///////////////////////////////////////////////////////////////////////
  202. BOOL DSIFramerANT::FormatFSMemory(USHORT usNumberOfSectors_, USHORT usPagesPerSector_, ULONG ulResponseTime_)
  203. {
  204. FS_MESSAGE stMessage;
  205. UCHAR ucResponse;
  206. stMessage.ucCommandID = (UCHAR)((MESG_FS_FORMAT_MEMORY_ID >> 8) & 0xFF);
  207. stMessage.ucMessageID = (UCHAR)(MESG_FS_FORMAT_MEMORY_ID & 0xFF);
  208. stMessage.aucData[0] = getByte_ulLE(1,usNumberOfSectors_);
  209. stMessage.aucData[1] = getByte_ulLE(2,usNumberOfSectors_);
  210. stMessage.aucData[2] = getByte_ulLE(1,usPagesPerSector_);
  211. stMessage.aucData[3] = getByte_ulLE(2,usPagesPerSector_);
  212. if(SendFSCommand(&stMessage, MESG_FS_FORMAT_MEMORY_SIZE, &ucResponse, ulResponseTime_))
  213. {
  214. ucFSResponse = ucResponse; //save FSResponse
  215. return TRUE;
  216. }
  217. else
  218. {
  219. ucFSResponse = ucResponse;
  220. return FALSE;
  221. }
  222. }
  223. ///////////////////////////////////////////////////////////////////////
  224. BOOL DSIFramerANT::SaveDirectory(ULONG ulResponseTime_)
  225. {
  226. FS_MESSAGE stMessage;
  227. UCHAR ucResponse;
  228. stMessage.ucCommandID = (UCHAR)((MESG_FS_DIRECTORY_SAVE_ID >> 8) & 0xFF);
  229. stMessage.ucMessageID = (UCHAR)(MESG_FS_DIRECTORY_SAVE_ID & 0xFF);
  230. if(SendFSCommand(&stMessage, MESG_FS_DIRECTORY_SAVE_SIZE, &ucResponse, ulResponseTime_))
  231. {
  232. ucFSResponse = ucResponse; //save FSResponse
  233. return TRUE;
  234. }
  235. else
  236. {
  237. ucFSResponse = ucResponse;
  238. return FALSE;
  239. }
  240. }
  241. ///////////////////////////////////////////////////////////////////////
  242. BOOL DSIFramerANT::DirectoryRebuild(ULONG ulResponseTime_)
  243. {
  244. FS_MESSAGE stMessage;
  245. UCHAR ucResponse;
  246. stMessage.ucCommandID = (UCHAR)((MESG_FS_DIRECTORY_REBUILD_ID >> 8) & 0xFF);
  247. stMessage.ucMessageID = (UCHAR)(MESG_FS_DIRECTORY_REBUILD_ID & 0xFF);
  248. if(SendFSCommand(&stMessage, MESG_FS_DIRECTORY_REBUILD_SIZE, &ucResponse, ulResponseTime_))
  249. {
  250. ucFSResponse = ucResponse; //save FSResponse
  251. return TRUE;
  252. }
  253. else
  254. {
  255. ucFSResponse = ucResponse;
  256. return FALSE;
  257. }
  258. }
  259. ///////////////////////////////////////////////////////////////////////
  260. BOOL DSIFramerANT::FileDelete(UCHAR ucFileHandle_, ULONG ulResponseTime_)
  261. {
  262. FS_MESSAGE stMessage;
  263. UCHAR ucResponse;
  264. stMessage.ucCommandID = (UCHAR)((MESG_FS_FILE_DELETE_ID >> 8) & 0xFF);
  265. stMessage.ucMessageID = (UCHAR)(MESG_FS_FILE_DELETE_ID & 0xFF);
  266. stMessage.aucData[0] = ucFileHandle_;
  267. if(SendFSCommand(&stMessage, MESG_FS_FILE_DELETE_SIZE, &ucResponse, ulResponseTime_))
  268. {
  269. ucFSResponse = ucResponse; //save FSResponse
  270. return TRUE;
  271. }
  272. else
  273. {
  274. ucFSResponse = ucResponse;
  275. return FALSE;
  276. }
  277. }
  278. ///////////////////////////////////////////////////////////////////////
  279. BOOL DSIFramerANT::FileClose(UCHAR ucFileHandle_, ULONG ulResponseTime_)
  280. {
  281. FS_MESSAGE stMessage;
  282. UCHAR ucResponse;
  283. stMessage.ucCommandID = (UCHAR)((MESG_FS_FILE_CLOSE_ID >> 8) & 0xFF);
  284. stMessage.ucMessageID = (UCHAR)(MESG_FS_FILE_CLOSE_ID & 0xFF);
  285. stMessage.aucData[0] = ucFileHandle_;
  286. if(SendFSCommand(&stMessage, MESG_FS_FILE_CLOSE_SIZE, &ucResponse, ulResponseTime_))
  287. {
  288. ucFSResponse = ucResponse; //save FSResponse
  289. return TRUE;
  290. }
  291. else
  292. {
  293. ucFSResponse = ucResponse;
  294. return FALSE;
  295. }
  296. }
  297. ///////////////////////////////////////////////////////////////////////
  298. BOOL DSIFramerANT::SetFileSpecificFlags(UCHAR ucFileHandle_, UCHAR ucFlags_, ULONG ulResponseTime_)
  299. {
  300. FS_MESSAGE stMessage;
  301. UCHAR ucResponse;
  302. stMessage.ucCommandID = (UCHAR)((MESG_FS_FILE_SET_SPECIFIC_FLAGS_ID >> 8) & 0xFF);
  303. stMessage.ucMessageID = (UCHAR)(MESG_FS_FILE_SET_SPECIFIC_FLAGS_ID & 0xFF);
  304. stMessage.aucData[0] = ucFileHandle_;
  305. stMessage.aucData[1] = ucFlags_;
  306. if(SendFSCommand(&stMessage, MESG_FS_FILE_SET_SPECIFIC_FLAGS_SIZE, &ucResponse, ulResponseTime_))
  307. {
  308. ucFSResponse = ucResponse; //save FSResponse
  309. return TRUE;
  310. }
  311. else
  312. {
  313. ucFSResponse = ucResponse;
  314. return FALSE;
  315. }
  316. }
  317. ///////////////////////////////////////////////////////////////////////
  318. UCHAR DSIFramerANT::DirectoryReadLock(BOOL bLock_, ULONG ulResponseTime_)
  319. {
  320. FS_MESSAGE stMessage;
  321. UCHAR ucResponse;
  322. stMessage.ucCommandID = (UCHAR)((MESG_FS_DIRECTORY_READ_LOCK_ID >> 8) & 0xFF);
  323. stMessage.ucMessageID = (UCHAR)(MESG_FS_DIRECTORY_READ_LOCK_ID & 0xFF);
  324. stMessage.aucData[0] = (UCHAR) bLock_;
  325. if(SendFSCommand(&stMessage, MESG_FS_DIRECTORY_READ_LOCK_SIZE, &ucResponse, ulResponseTime_))
  326. {
  327. ucFSResponse = ucResponse; //save FSResponse
  328. return ucFSResponse;
  329. }
  330. else
  331. {
  332. ucFSResponse = ucResponse;
  333. return ucFSResponse;
  334. }
  335. }
  336. ///////////////////////////////////////////////////////////////////////
  337. BOOL DSIFramerANT::SetSystemTime(ULONG ulTime_, ULONG ulResponseTime_)
  338. {
  339. FS_MESSAGE stMessage;
  340. UCHAR ucResponse;
  341. stMessage.ucCommandID = (UCHAR)((MESG_FS_SYSTEM_TIME_ID >> 8) & 0xFF);
  342. stMessage.ucMessageID = (UCHAR)(MESG_FS_SYSTEM_TIME_ID & 0xFF);
  343. stMessage.aucData[0] = getByte_ulLE(1,ulTime_);
  344. stMessage.aucData[1] = getByte_ulLE(2,ulTime_);
  345. stMessage.aucData[2] = getByte_ulLE(3,ulTime_);
  346. stMessage.aucData[3] = getByte_ulLE(4,ulTime_);
  347. if(SendFSCommand(&stMessage, MESG_FS_SYSTEM_TIME_SIZE, &ucResponse, ulResponseTime_))
  348. {
  349. ucFSResponse = ucResponse; //save FSResponse
  350. return TRUE;
  351. }
  352. else
  353. {
  354. ucFSResponse = ucResponse;
  355. return FALSE;
  356. }
  357. }
  358. ///////////////////////////////////////////////////////////////////////
  359. /* File System Requests */
  360. ///////////////////////////////////////////////////////////////////////
  361. ULONG DSIFramerANT::GetUsedSpace(ULONG ulResponseTime_)
  362. {
  363. ANT_MESSAGE_ITEM stResponse;
  364. FS_MESSAGE stMessage;
  365. // Build the request message
  366. stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
  367. stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
  368. stMessage.aucData[0] = (UCHAR)((MESG_FS_GET_USED_SPACE_ID >> 8) & 0xFF);
  369. stMessage.aucData[1] = (UCHAR)(MESG_FS_GET_USED_SPACE_ID & 0xFF);
  370. SendFSRequest(MESG_FS_GET_USED_SPACE_SIZE, &stResponse, stMessage, ulResponseTime_);
  371. ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
  372. return ((ULONG)(stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD]) | ((ULONG)stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD + 1] << 8) | (ULONG)(stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD + 2] << 16) | (ULONG)(stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD + 3] << 24));
  373. }
  374. ///////////////////////////////////////////////////////////////////////
  375. ULONG DSIFramerANT::GetFreeFSSpace(ULONG ulResponseTime_)
  376. {
  377. ANT_MESSAGE_ITEM stResponse;
  378. FS_MESSAGE stMessage;
  379. // Build the request message
  380. stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
  381. stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
  382. stMessage.aucData[0] = (UCHAR)((MESG_FS_GET_FREE_SPACE_ID >> 8) & 0xFF);
  383. stMessage.aucData[1] = (UCHAR)(MESG_FS_GET_FREE_SPACE_ID & 0xFF);
  384. SendFSRequest(MESG_FS_GET_FREE_SPACE_SIZE, &stResponse, stMessage, ulResponseTime_);
  385. ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
  386. return (ULONG)(stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD]) | (ULONG)(stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD + 1] << 8) | (ULONG)(stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD + 2] << 16) | (ULONG)(stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD + 3] << 24);
  387. }
  388. ///////////////////////////////////////////////////////////////////////
  389. USHORT DSIFramerANT::FindFileIndex(UCHAR ucFileDataType_, UCHAR ucFileSubType_, USHORT usFileNumber_, ULONG ulResponseTime_)
  390. {
  391. ANT_MESSAGE_ITEM stResponse;
  392. FS_MESSAGE stMessage;
  393. // Build the request message
  394. stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
  395. stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
  396. stMessage.aucData[0] = (UCHAR)((MESG_FS_FIND_FILE_INDEX_ID >> 8) & 0xFF);
  397. stMessage.aucData[1] = (UCHAR)(MESG_FS_FIND_FILE_INDEX_ID & 0xFF);
  398. stMessage.aucData[2] = ucFileDataType_;
  399. stMessage.aucData[3] = ucFileSubType_;
  400. stMessage.aucData[4] = getByte_ulLE(1,usFileNumber_);
  401. stMessage.aucData[5] = getByte_ulLE(2,usFileNumber_);
  402. SendFSRequest(MESG_FS_FIND_FILE_INDEX_SIZE, &stResponse, stMessage, ulResponseTime_);
  403. ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
  404. return (USHORT)(stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD]) | (USHORT)(stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD + 1] << 8);
  405. }
  406. ///////////////////////////////////////////////////////////////////////
  407. UCHAR DSIFramerANT::ReadDirectoryAbsolute(ULONG ulOffset_, UCHAR ucSize_, UCHAR *pucBuffer_, ULONG ulResponseTime_)
  408. {
  409. ANT_MESSAGE_ITEM stResponse;
  410. FS_MESSAGE stMessage;
  411. // Build the request message
  412. stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
  413. stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
  414. stMessage.aucData[0] = (UCHAR)((MESG_FS_DIRECTORY_READ_ABSOLUTE_ID >> 8) & 0xFF);
  415. stMessage.aucData[1] = (UCHAR)(MESG_FS_DIRECTORY_READ_ABSOLUTE_ID & 0xFF);
  416. stMessage.aucData[2] = getByte_ulLE(1,ulOffset_);
  417. stMessage.aucData[3] = getByte_ulLE(2,ulOffset_);
  418. stMessage.aucData[4] = getByte_ulLE(3,ulOffset_);
  419. stMessage.aucData[5] = getByte_ulLE(4,ulOffset_);
  420. stMessage.aucData[6] = ucSize_;
  421. SendFSRequest(MESG_FS_DIRECTORY_READ_ABSOLUTE_SIZE, &stResponse, stMessage, ulResponseTime_);
  422. ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
  423. //Now load pucBuffer_ with the Paylaod Array
  424. //Caller has to do validation of the response before reading the buffer
  425. for(int i = 0; i < ucSize_; i++)
  426. pucBuffer_[i] = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD + 1 + i]; //add 1 to skip sizeRead byte
  427. return ucFSResponse;
  428. }
  429. ///////////////////////////////////////////////////////////////////////
  430. UCHAR DSIFramerANT::DirectoryReadEntry(USHORT usFileIndex_, UCHAR *ucFileDirectoryBuffer_, ULONG ulResponseTime_)
  431. {
  432. ANT_MESSAGE_ITEM stResponse;
  433. FS_MESSAGE stMessage;
  434. // Build the request message
  435. stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
  436. stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
  437. stMessage.aucData[0] = (UCHAR)((MESG_FS_DIRECTORY_READ_ENTRY_ID >> 8) & 0xFF);
  438. stMessage.aucData[1] = (UCHAR)(MESG_FS_DIRECTORY_READ_ENTRY_ID & 0xFF);
  439. stMessage.aucData[2] = getByte_ulLE(1, usFileIndex_);
  440. stMessage.aucData[3] = getByte_ulLE(2, usFileIndex_);
  441. SendFSRequest(MESG_FS_DIRECTORY_READ_ENTRY_SIZE, &stResponse, stMessage, ulResponseTime_);
  442. ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
  443. //Now load pucBuffer_ with the Paylaod Array
  444. for(int i = 0; i < 16; i++)
  445. ucFileDirectoryBuffer_[i] = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD + 1 + i]; //add 1 to skip sizeRead byte
  446. return ucFSResponse;
  447. }
  448. ///////////////////////////////////////////////////////////////////////
  449. ULONG DSIFramerANT::DirectoryGetSize(ULONG ulResponseTime_)
  450. {
  451. ANT_MESSAGE_ITEM stResponse;
  452. FS_MESSAGE stMessage;
  453. // Build the request message
  454. stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
  455. stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
  456. stMessage.aucData[0] = (UCHAR)((MESG_FS_DIRECTORY_GET_SIZE_ID >> 8) & 0xFF);
  457. stMessage.aucData[1] = (UCHAR)(MESG_FS_DIRECTORY_GET_SIZE_ID & 0xFF);
  458. SendFSRequest(MESG_FS_DIRECTORY_GET_SIZE_SIZE, &stResponse, stMessage, ulResponseTime_);
  459. ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
  460. return (ULONG)(stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD]) | (ULONG)(stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD + 1] << 8) | (ULONG)(stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD + 2] << 16) | (ULONG)(stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD + 3] << 24);
  461. }
  462. ///////////////////////////////////////////////////////////////////////
  463. USHORT DSIFramerANT::FileCreate(USHORT usFileIndex_, UCHAR ucFileDataType_, ULONG ulFileIdentifier_, UCHAR ucFileDataTypeSpecificFlags_, UCHAR ucGeneralFlags_, ULONG ulResponseTime_)
  464. {
  465. ANT_MESSAGE_ITEM stResponse;
  466. FS_MESSAGE stMessage;
  467. // Build the request message
  468. stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
  469. stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
  470. stMessage.aucData[0] = (UCHAR)((MESG_FS_FILE_CREATE_ID >> 8) & 0xFF);
  471. stMessage.aucData[1] = (UCHAR)(MESG_FS_FILE_CREATE_ID & 0xFF);
  472. stMessage.aucData[2] = getByte_ulLE(1, usFileIndex_);
  473. stMessage.aucData[3] = getByte_ulLE(2, usFileIndex_);
  474. stMessage.aucData[4] = ucFileDataType_;
  475. stMessage.aucData[5] = getByte_ulLE(1, ulFileIdentifier_);
  476. stMessage.aucData[6] = getByte_ulLE(2, ulFileIdentifier_);
  477. stMessage.aucData[7] = getByte_ulLE(3, ulFileIdentifier_);
  478. stMessage.aucData[8] = ucFileDataTypeSpecificFlags_;
  479. stMessage.aucData[9] = ucGeneralFlags_;
  480. SendFSRequest(MESG_FS_FILE_CREATE_SIZE, &stResponse, stMessage, ulResponseTime_);
  481. ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
  482. return (USHORT)(stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD]) | (USHORT)(stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD + 1] << 8);
  483. }
  484. ///////////////////////////////////////////////////////////////////////
  485. UCHAR DSIFramerANT::FileOpen(USHORT usFileIndex_, UCHAR ucOpenFlags_, ULONG ulResponseTime_)
  486. {
  487. ANT_MESSAGE_ITEM stResponse;
  488. FS_MESSAGE stMessage;
  489. // Build the request message
  490. stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
  491. stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
  492. stMessage.aucData[0] = (UCHAR)((MESG_FS_FILE_OPEN_ID >> 8) & 0xFF);
  493. stMessage.aucData[1] = (UCHAR)(MESG_FS_FILE_OPEN_ID & 0xFF);
  494. stMessage.aucData[2] = getByte_ulLE(1, usFileIndex_);
  495. stMessage.aucData[3] = getByte_ulLE(2, usFileIndex_);
  496. stMessage.aucData[4] = ucOpenFlags_;
  497. SendFSRequest(MESG_FS_FILE_OPEN_SIZE, &stResponse, stMessage, ulResponseTime_);
  498. ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
  499. return (UCHAR)(stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD]);
  500. }
  501. ///////////////////////////////////////////////////////////////////////
  502. UCHAR DSIFramerANT::FileReadAbsolute(UCHAR ucFileHandle_, ULONG ulOffset_, UCHAR ucReadSize_, UCHAR *pucReadBuffer_, ULONG ulResponseTime_)
  503. {
  504. ANT_MESSAGE_ITEM stResponse;
  505. FS_MESSAGE stMessage;
  506. // Build the request message
  507. stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
  508. stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
  509. stMessage.aucData[0] = (UCHAR)((MESG_FS_FILE_READ_ABSOLUTE_ID >> 8) & 0xFF);
  510. stMessage.aucData[1] = (UCHAR)(MESG_FS_FILE_READ_ABSOLUTE_ID & 0xFF);
  511. stMessage.aucData[2] = ucFileHandle_;
  512. stMessage.aucData[3] = getByte_ulLE(1,ulOffset_);
  513. stMessage.aucData[4] = getByte_ulLE(2,ulOffset_);
  514. stMessage.aucData[5] = getByte_ulLE(3,ulOffset_);
  515. stMessage.aucData[6] = getByte_ulLE(4,ulOffset_);
  516. stMessage.aucData[7] = ucReadSize_;
  517. SendFSRequest(MESG_FS_FILE_READ_ABSOLUTE_SIZE, &stResponse, stMessage, ulResponseTime_);
  518. ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
  519. //Now load pucBuffer_ with the Paylaod Array
  520. for(int i = 0; i < ucReadSize_; i++)
  521. pucReadBuffer_[i] = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD + 1 + i]; //add 1 to skip SizeRead byte
  522. return ucFSResponse;
  523. }
  524. ///////////////////////////////////////////////////////////////////////
  525. UCHAR DSIFramerANT::FileReadRelative(UCHAR ucFileHandle_, UCHAR ucReadSize_, UCHAR *pucReadBuffer_, ULONG ulResponseTime_)
  526. {
  527. ANT_MESSAGE_ITEM stResponse;
  528. FS_MESSAGE stMessage;
  529. // Build the request message
  530. stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
  531. stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
  532. stMessage.aucData[0] = (UCHAR)((MESG_FS_FILE_READ_RELATIVE_ID >> 8) & 0xFF);
  533. stMessage.aucData[1] = (UCHAR)(MESG_FS_FILE_READ_RELATIVE_ID & 0xFF);
  534. stMessage.aucData[2] = ucFileHandle_;
  535. stMessage.aucData[3] = ucReadSize_;
  536. SendFSRequest(MESG_FS_FILE_READ_RELATIVE_SIZE, &stResponse, stMessage, ulResponseTime_);
  537. ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
  538. //Now load pucBuffer_ with the Paylaod Array
  539. for(int i = 0; i < ucReadSize_; i++)
  540. pucReadBuffer_[i] = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD + 1 + i]; //add 1 to skip SizeRead byte
  541. return ucFSResponse;
  542. }
  543. ///////////////////////////////////////////////////////////////////////
  544. UCHAR DSIFramerANT::FileWriteAbsolute(UCHAR ucFileHandle_, ULONG ulFileOffset_, UCHAR ucWriteSize_, const UCHAR *pucWriteBuffer_, UCHAR *ucBytesWritten_, ULONG ulResponseTime_)
  545. {
  546. ANT_MESSAGE_ITEM stResponse;
  547. FS_MESSAGE stMessage;
  548. // Build the request message
  549. stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
  550. stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
  551. stMessage.aucData[0] = (UCHAR)((MESG_FS_FILE_WRITE_ABSOLUTE_ID >> 8) & 0xFF);
  552. stMessage.aucData[1] = (UCHAR)(MESG_FS_FILE_WRITE_ABSOLUTE_ID & 0xFF);
  553. stMessage.aucData[2] = ucFileHandle_;
  554. stMessage.aucData[3] = getByte_ulLE(1,ulFileOffset_);
  555. stMessage.aucData[4] = getByte_ulLE(2,ulFileOffset_);
  556. stMessage.aucData[5] = getByte_ulLE(3,ulFileOffset_);
  557. stMessage.aucData[6] = getByte_ulLE(4,ulFileOffset_);
  558. stMessage.aucData[7] = ucWriteSize_;
  559. for(int i = 0; i < ucWriteSize_; i++)
  560. stMessage.aucData[MESG_FS_FILE_WRITE_ABSOLUTE_SIZE - 1 + i] = pucWriteBuffer_[i];
  561. SendFSRequest(MESG_FS_FILE_WRITE_ABSOLUTE_SIZE + ucWriteSize_, &stResponse, stMessage, ulResponseTime_);
  562. ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
  563. *ucBytesWritten_ = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD];
  564. return stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD]; //return the Number of bytes successfully written
  565. }
  566. ///////////////////////////////////////////////////////////////////////
  567. UCHAR DSIFramerANT::FileWriteRelative(UCHAR ucFileHandle_, UCHAR ucWriteSize_, const UCHAR *pucWriteBuffer_, UCHAR *ucBytesWritten_, ULONG ulResponseTime_)
  568. {
  569. ANT_MESSAGE_ITEM stResponse;
  570. FS_MESSAGE stMessage;
  571. // Build the request message
  572. stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
  573. stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
  574. stMessage.aucData[0] = (UCHAR)((MESG_FS_FILE_WRITE_RELATIVE_ID >> 8) & 0xFF);
  575. stMessage.aucData[1] = (UCHAR)(MESG_FS_FILE_WRITE_RELATIVE_ID & 0xFF);
  576. stMessage.aucData[2] = ucFileHandle_;
  577. stMessage.aucData[3] = ucWriteSize_;
  578. for(int i = 0; i < ucWriteSize_; i++)
  579. stMessage.aucData[MESG_FS_FILE_WRITE_RELATIVE_SIZE - 1 + i] = pucWriteBuffer_[i];
  580. SendFSRequest(MESG_FS_FILE_WRITE_RELATIVE_SIZE + ucWriteSize_, &stResponse, stMessage, ulResponseTime_);
  581. ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
  582. *ucBytesWritten_ = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD];
  583. return stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD]; //return the Number of bytes successfully written
  584. }
  585. ///////////////////////////////////////////////////////////////////////
  586. ULONG DSIFramerANT::FileGetSize(UCHAR ucFileHandle_, ULONG ulResponseTime_)
  587. {
  588. ANT_MESSAGE_ITEM stResponse;
  589. FS_MESSAGE stMessage;
  590. // Build the request message
  591. stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
  592. stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
  593. stMessage.aucData[0] = (UCHAR)((MESG_FS_FILE_GET_SIZE_ID >> 8) & 0xFF);
  594. stMessage.aucData[1] = (UCHAR)(MESG_FS_FILE_GET_SIZE_ID & 0xFF);
  595. stMessage.aucData[2] = ucFileHandle_;
  596. SendFSRequest(MESG_FS_FILE_GET_SIZE_SIZE, &stResponse, stMessage, ulResponseTime_);
  597. ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
  598. return (ULONG)(stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD]) | (ULONG)(stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD + 1] << 8) | (ULONG)(stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD + 2] << 16) | (ULONG)(stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD + 3] << 24);
  599. }
  600. ///////////////////////////////////////////////////////////////////////
  601. ULONG DSIFramerANT::FileGetSizeInMem(UCHAR ucFileHandle_, ULONG ulResponseTime_)
  602. {
  603. ANT_MESSAGE_ITEM stResponse;
  604. FS_MESSAGE stMessage;
  605. // Build the request message
  606. stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
  607. stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
  608. stMessage.aucData[0] = (UCHAR)((MESG_FS_FILE_GET_SIZE_IN_MEM_ID >> 8) & 0xFF);
  609. stMessage.aucData[1] = (UCHAR)(MESG_FS_FILE_GET_SIZE_IN_MEM_ID & 0xFF);
  610. stMessage.aucData[2] = ucFileHandle_;
  611. SendFSRequest(MESG_FS_FILE_GET_SIZE_IN_MEM_SIZE, &stResponse, stMessage, ulResponseTime_);
  612. ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
  613. return (ULONG)(stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD]) | (ULONG)(stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD + 1] << 8) | (ULONG)(stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD + 2] << 16) | (ULONG)(stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD + 3] << 24);
  614. }
  615. ///////////////////////////////////////////////////////////////////////
  616. UCHAR DSIFramerANT::FileGetSpecificFlags(UCHAR ucFileHandle_, ULONG ulResponseTime_)
  617. {
  618. ANT_MESSAGE_ITEM stResponse;
  619. FS_MESSAGE stMessage;
  620. // Build the request message
  621. stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
  622. stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
  623. stMessage.aucData[0] = (UCHAR)((MESG_FS_FILE_GET_SPECIFIC_FILE_FLAGS_ID >> 8) & 0xFF);
  624. stMessage.aucData[1] = (UCHAR)(MESG_FS_FILE_GET_SPECIFIC_FILE_FLAGS_ID & 0xFF);
  625. stMessage.aucData[2] = ucFileHandle_;
  626. SendFSRequest(MESG_FS_FILE_GET_SPECIFIC_FILE_FLAGS_SIZE, &stResponse, stMessage, ulResponseTime_);
  627. ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
  628. return stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD];
  629. }
  630. ///////////////////////////////////////////////////////////////////////
  631. ULONG DSIFramerANT::FileGetSystemTime(ULONG ulResponseTime_)
  632. {
  633. ANT_MESSAGE_ITEM stResponse;
  634. FS_MESSAGE stMessage;
  635. // Build the request message
  636. stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
  637. stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
  638. stMessage.aucData[0] = (UCHAR)((MESG_FS_SYSTEM_TIME_ID >> 8) & 0xFF);
  639. stMessage.aucData[1] = (UCHAR)(MESG_FS_SYSTEM_TIME_ID & 0xFF);
  640. SendFSRequest(MESG_FS_SYSTEM_TIME_REQUEST_SIZE, &stResponse, stMessage, ulResponseTime_);
  641. ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
  642. return (ULONG)(stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD]) | (ULONG)(stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD + 1] << 8) | (ULONG)(stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD + 2] << 16) | (ULONG)(stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD + 3] << 24);
  643. }
  644. ///////////////////////////////////////////////////////////////////////
  645. /* FS-Crypto Commands */
  646. ///////////////////////////////////////////////////////////////////////
  647. UCHAR DSIFramerANT::CryptoAddUserKeyIndex(UCHAR ucIndex_, UCHAR *pucKey_, ULONG ulResponseTime_)
  648. {
  649. FS_MESSAGE stMessage;
  650. UCHAR ucResponse;
  651. stMessage.ucCommandID = (UCHAR)((MESG_FS_CRYPTO_ADD_USER_KEY_INDEX_ID >> 8) & 0xFF);
  652. stMessage.ucMessageID = (UCHAR)(MESG_FS_CRYPTO_ADD_USER_KEY_INDEX_ID & 0xFF);
  653. stMessage.aucData[0] = ucIndex_;
  654. //copy Crypto Key into the aucData array starting at index 1 as index 0 is already used
  655. for(int i = 1; i < 33; i++)
  656. stMessage.aucData[i] = pucKey_[i - 1];
  657. if(SendFSCommand(&stMessage, MESG_FS_CRYPTO_ADD_USER_KEY_INDEX_SIZE, &ucResponse, ulResponseTime_))
  658. {
  659. ucFSResponse = ucResponse; //save FSResponse
  660. return ucFSResponse;
  661. }
  662. else
  663. {
  664. ucFSResponse = ucResponse;
  665. return ucFSResponse;
  666. }
  667. }
  668. ///////////////////////////////////////////////////////////////////////
  669. UCHAR DSIFramerANT::CryptoSetUserKeyIndex(UCHAR ucIndex_, ULONG ulResponseTime_)
  670. {
  671. FS_MESSAGE stMessage;
  672. UCHAR ucResponse;
  673. stMessage.ucCommandID = (UCHAR)((MESG_FS_CRYPTO_SET_USER_KEY_INDEX_ID >> 8) & 0xFF);
  674. stMessage.ucMessageID = (UCHAR)(MESG_FS_CRYPTO_SET_USER_KEY_INDEX_ID & 0xFF);
  675. stMessage.aucData[0] = ucIndex_;
  676. if(SendFSCommand(&stMessage, MESG_FS_CRYPTO_SET_USER_KEY_INDEX_SIZE, &ucResponse, ulResponseTime_))
  677. {
  678. ucFSResponse = ucResponse; //save FSResponse
  679. return ucFSResponse;
  680. }
  681. else
  682. {
  683. ucFSResponse = ucResponse;
  684. return ucFSResponse;
  685. }
  686. }
  687. ///////////////////////////////////////////////////////////////////////
  688. UCHAR DSIFramerANT::CryptoSetUserKeyVal(UCHAR *pucKey_, ULONG ulResponseTime_)
  689. {
  690. FS_MESSAGE stMessage;
  691. UCHAR ucResponse;
  692. stMessage.ucCommandID = (UCHAR)((MESG_FS_CRYPTO_SET_USER_KEY_VAL_ID >> 8) & 0xFF);
  693. stMessage.ucMessageID = (UCHAR)(MESG_FS_CRYPTO_SET_USER_KEY_VAL_ID & 0xFF);
  694. //copy Crypto Key into the aucData array starting at index 1 as index 0 is already used
  695. for(int i = 0; i < 33; i++)
  696. stMessage.aucData[i] = pucKey_[i];
  697. if(SendFSCommand(&stMessage, MESG_FS_CRYPTO_SET_USER_KEY_VAL_SIZE, &ucResponse, ulResponseTime_))
  698. {
  699. ucFSResponse = ucResponse; //save FSResponse
  700. return ucFSResponse;
  701. }
  702. else
  703. {
  704. ucFSResponse = ucResponse;
  705. return ucFSResponse;
  706. }
  707. }
  708. ///////////////////////////////////////////////////////////////////////
  709. /* FIT Commands */
  710. ///////////////////////////////////////////////////////////////////////
  711. UCHAR DSIFramerANT::FitFileIntegrityCheck(UCHAR ucFileHandle_, ULONG ulResponseTime_)
  712. {
  713. FS_MESSAGE stMessage;
  714. UCHAR ucResponse;
  715. stMessage.ucCommandID = (UCHAR)((MESG_FS_FIT_FILE_INTEGRITY_CHECK_ID >> 8) & 0xFF);
  716. stMessage.ucMessageID = (UCHAR)(MESG_FS_FIT_FILE_INTEGRITY_CHECK_ID & 0xFF);
  717. stMessage.aucData[0] = ucFileHandle_;
  718. if(SendFSCommand(&stMessage, MESG_FS_FIT_FILE_INTEGRITY_CHECK_SIZE, &ucResponse, ulResponseTime_))
  719. {
  720. ucFSResponse = ucResponse; //save FSResponse
  721. return ucFSResponse;
  722. }
  723. else
  724. {
  725. ucFSResponse = ucResponse;
  726. return ucFSResponse;
  727. }
  728. }
  729. ///////////////////////////////////////////////////////////////////////
  730. /* ANTFS Commands */
  731. ///////////////////////////////////////////////////////////////////////
  732. UCHAR DSIFramerANT::OpenBeacon(ULONG ulResponseTime_)
  733. {
  734. FS_MESSAGE stMessage;
  735. UCHAR ucResponse;
  736. stMessage.ucCommandID = (UCHAR)((MESG_FS_ANTFS_OPEN_ID >> 8) & 0xFF);
  737. stMessage.ucMessageID = (UCHAR)(MESG_FS_ANTFS_OPEN_ID & 0xFF);
  738. if(SendFSCommand(&stMessage, MESG_FS_ANTFS_OPEN_SIZE, &ucResponse, ulResponseTime_))
  739. {
  740. ucFSResponse = ucResponse; //save FSResponse
  741. return ucFSResponse;
  742. }
  743. else
  744. {
  745. ucFSResponse = ucResponse;
  746. return ucFSResponse;
  747. }
  748. }
  749. ///////////////////////////////////////////////////////////////////////
  750. UCHAR DSIFramerANT::CloseBeacon(ULONG ulResponseTime_)
  751. {
  752. FS_MESSAGE stMessage;
  753. UCHAR ucResponse;
  754. stMessage.ucCommandID = (UCHAR)((MESG_FS_ANTFS_CLOSE_ID >> 8) & 0xFF);
  755. stMessage.ucMessageID = (UCHAR)(MESG_FS_ANTFS_CLOSE_ID & 0xFF);
  756. if(SendFSCommand(&stMessage, MESG_FS_ANTFS_CLOSE_SIZE, &ucResponse, ulResponseTime_))
  757. {
  758. ucFSResponse = ucResponse; //save FSResponse
  759. return ucFSResponse;
  760. }
  761. else
  762. {
  763. ucFSResponse = ucResponse;
  764. return ucFSResponse;
  765. }
  766. }
  767. ///////////////////////////////////////////////////////////////////////
  768. UCHAR DSIFramerANT::ConfigBeacon(USHORT usDeviceType_, USHORT usManufacturer_, UCHAR ucAuthType_, UCHAR ucBeaconStatus_, ULONG ulResponseTime_)
  769. {
  770. FS_MESSAGE stMessage;
  771. UCHAR ucResponse;
  772. stMessage.ucCommandID = (UCHAR)((MESG_FS_ANTFS_CONFIG_BEACON_ID >> 8) & 0xFF);
  773. stMessage.ucMessageID = (UCHAR)(MESG_FS_ANTFS_CONFIG_BEACON_ID & 0xFF);
  774. stMessage.aucData[0] = getByte_ulLE(1,usDeviceType_);
  775. stMessage.aucData[1] = getByte_ulLE(2,usDeviceType_);
  776. stMessage.aucData[2] = getByte_ulLE(1,usManufacturer_);
  777. stMessage.aucData[3] = getByte_ulLE(2,usManufacturer_);
  778. stMessage.aucData[4] = ucAuthType_;
  779. stMessage.aucData[5] = ucBeaconStatus_;
  780. if(SendFSCommand(&stMessage, MESG_FS_ANTFS_CONFIG_BEACON_SIZE, &ucResponse, ulResponseTime_))
  781. {
  782. ucFSResponse = ucResponse; //save FSResponse
  783. return ucFSResponse;
  784. }
  785. else
  786. {
  787. ucFSResponse = ucResponse;
  788. return ucFSResponse;
  789. }
  790. }
  791. ///////////////////////////////////////////////////////////////////////
  792. UCHAR DSIFramerANT::SetFriendlyName(UCHAR ucLength_, const UCHAR *pucString_, ULONG ulResponseTime_)
  793. {
  794. FS_MESSAGE stMessage;
  795. UCHAR ucResponse;
  796. stMessage.ucCommandID = (UCHAR)((MESG_FS_ANTFS_SET_AUTH_STRING_ID >> 8) & 0xFF);
  797. stMessage.ucMessageID = (UCHAR)(MESG_FS_ANTFS_SET_AUTH_STRING_ID & 0xFF);
  798. stMessage.aucData[0] = 0; //send 0 for Friendlyname Command
  799. //Load up the String into the aucData starting at index 1
  800. for(int i = 1; i < ucLength_ + 1; i++)
  801. stMessage.aucData[i] = pucString_[i - 1];
  802. if(SendFSCommand(&stMessage, MESG_FS_ANTFS_SET_AUTH_STRING_SIZE + ucLength_, &ucResponse, ulResponseTime_))
  803. {
  804. ucFSResponse = ucResponse; //save FSResponse
  805. return ucFSResponse;
  806. }
  807. else
  808. {
  809. ucFSResponse = ucResponse;
  810. return ucFSResponse;
  811. }
  812. }
  813. ///////////////////////////////////////////////////////////////////////
  814. UCHAR DSIFramerANT::SetPasskey(UCHAR ucLength_, const UCHAR *pucString_, ULONG ulResponseTime_)
  815. {
  816. FS_MESSAGE stMessage;
  817. UCHAR ucResponse;
  818. stMessage.ucCommandID = (UCHAR)((MESG_FS_ANTFS_SET_AUTH_STRING_ID >> 8) & 0xFF);
  819. stMessage.ucMessageID = (UCHAR)(MESG_FS_ANTFS_SET_AUTH_STRING_ID & 0xFF);
  820. stMessage.aucData[0] = 1; //send 1 for Passkey Command
  821. //Load up the String into the aucData starting at index 1
  822. for(int i = 1; i < ucLength_ + 1; i++)
  823. stMessage.aucData[i] = pucString_[i - 1];
  824. if(SendFSCommand(&stMessage, MESG_FS_ANTFS_SET_AUTH_STRING_SIZE + ucLength_, &ucResponse, ulResponseTime_))
  825. {
  826. ucFSResponse = ucResponse; //save FSResponse
  827. return ucFSResponse;
  828. }
  829. else
  830. {
  831. ucFSResponse = ucResponse;
  832. return ucFSResponse;
  833. }
  834. }
  835. ///////////////////////////////////////////////////////////////////////
  836. UCHAR DSIFramerANT::SetBeaconState(UCHAR ucBeaconStatus_, ULONG ulResponseTime_)
  837. {
  838. FS_MESSAGE stMessage;
  839. UCHAR ucResponse;
  840. stMessage.ucCommandID = (UCHAR)((MESG_FS_ANTFS_SET_BEACON_STATE_ID >> 8) & 0xFF);
  841. stMessage.ucMessageID = (UCHAR)(MESG_FS_ANTFS_SET_BEACON_STATE_ID & 0xFF);
  842. stMessage.aucData[0] = ucBeaconStatus_;
  843. if(SendFSCommand(&stMessage, MESG_FS_ANTFS_SET_BEACON_STATE_SIZE, &ucResponse, ulResponseTime_))
  844. {
  845. ucFSResponse = ucResponse; //save FSResponse
  846. return ucFSResponse;
  847. }
  848. else
  849. {
  850. ucFSResponse = ucResponse;
  851. return ucFSResponse;
  852. }
  853. }
  854. ///////////////////////////////////////////////////////////////////////
  855. UCHAR DSIFramerANT::PairResponse(BOOL bAccept_, ULONG ulResponseTime_)
  856. {
  857. FS_MESSAGE stMessage;
  858. UCHAR ucResponse;
  859. stMessage.ucCommandID = (UCHAR)((MESG_FS_ANTFS_PAIR_RESPONSE_ID >> 8) & 0xFF);
  860. stMessage.ucMessageID = (UCHAR)(MESG_FS_ANTFS_PAIR_RESPONSE_ID & 0xFF);
  861. stMessage.aucData[0] = (UCHAR) bAccept_;
  862. if(SendFSCommand(&stMessage, MESG_FS_ANTFS_PAIR_RESPONSE_SIZE, &ucResponse, ulResponseTime_))
  863. {
  864. ucFSResponse = ucResponse; //save FSResponse
  865. return ucFSResponse;
  866. }
  867. else
  868. {
  869. ucFSResponse = ucResponse;
  870. return ucFSResponse;
  871. }
  872. }
  873. ///////////////////////////////////////////////////////////////////////
  874. UCHAR DSIFramerANT::SetLinkFrequency(UCHAR ucChannelNumber_, UCHAR ucFrequency_, ULONG ulResponseTime_)
  875. {
  876. FS_MESSAGE stMessage;
  877. UCHAR ucResponse;
  878. stMessage.ucCommandID = (UCHAR)((MESG_FS_ANTFS_SET_LINK_FREQ_ID >> 8) & 0xFF);
  879. stMessage.ucMessageID = (UCHAR)(MESG_FS_ANTFS_SET_LINK_FREQ_ID & 0xFF);
  880. stMessage.aucData[0] = ucChannelNumber_;
  881. stMessage.aucData[1] = ucFrequency_;
  882. if(SendFSCommand(&stMessage, MESG_FS_ANTFS_SET_LINK_FREQ_SIZE, &ucResponse, ulResponseTime_))
  883. {
  884. ucFSResponse = ucResponse; //save FSResponse
  885. return ucFSResponse;
  886. }
  887. else
  888. {
  889. ucFSResponse = ucResponse;
  890. return ucFSResponse;
  891. }
  892. }
  893. ///////////////////////////////////////////////////////////////////////
  894. UCHAR DSIFramerANT::SetBeaconTimeout(UCHAR ucTimeout_, ULONG ulResponseTime_)
  895. {
  896. FS_MESSAGE stMessage;
  897. UCHAR ucResponse;
  898. stMessage.ucCommandID = (UCHAR)((MESG_FS_ANTFS_SET_BEACON_TIMEOUT_ID >> 8) & 0xFF);
  899. stMessage.ucMessageID = (UCHAR)(MESG_FS_ANTFS_SET_BEACON_TIMEOUT_ID & 0xFF);
  900. stMessage.aucData[0] = ucTimeout_;
  901. if(SendFSCommand(&stMessage, MESG_FS_ANTFS_SET_BEACON_TIMEOUT_SIZE, &ucResponse, ulResponseTime_))
  902. {
  903. ucFSResponse = ucResponse; //save FSResponse
  904. return ucFSResponse;
  905. }
  906. else
  907. {
  908. ucFSResponse = ucResponse;
  909. return ucFSResponse;
  910. }
  911. }
  912. ///////////////////////////////////////////////////////////////////////
  913. UCHAR DSIFramerANT::SetPairingTimeout(UCHAR ucTimeout_, ULONG ulResponseTime_)
  914. {
  915. FS_MESSAGE stMessage;
  916. UCHAR ucResponse;
  917. stMessage.ucCommandID = (UCHAR)((MESG_FS_ANTFS_SET_PAIRING_TIMEOUT_ID >> 8) & 0xFF);
  918. stMessage.ucMessageID = (UCHAR)(MESG_FS_ANTFS_SET_PAIRING_TIMEOUT_ID & 0xFF);
  919. stMessage.aucData[0] = ucTimeout_;
  920. if(SendFSCommand(&stMessage, MESG_FS_ANTFS_SET_PAIRING_TIMEOUT_SIZE, &ucResponse, ulResponseTime_))
  921. {
  922. ucFSResponse = ucResponse; //save FSResponse
  923. return ucFSResponse;
  924. }
  925. else
  926. {
  927. ucFSResponse = ucResponse;
  928. return ucFSResponse;
  929. }
  930. }
  931. ///////////////////////////////////////////////////////////////////////
  932. UCHAR DSIFramerANT::EnableRemoteFileCreate(BOOL bEnable_, ULONG ulResponseTime_)
  933. {
  934. FS_MESSAGE stMessage;
  935. UCHAR ucResponse;
  936. stMessage.ucCommandID = (UCHAR)((MESG_FS_ANTFS_REMOTE_FILE_CREATE_EN_ID >> 8) & 0xFF);
  937. stMessage.ucMessageID = (UCHAR)(MESG_FS_ANTFS_REMOTE_FILE_CREATE_EN_ID & 0xFF);
  938. stMessage.aucData[0] = (UCHAR) bEnable_;
  939. if(SendFSCommand(&stMessage, MESG_FS_ANTFS_REMOTE_FILE_CREATE_EN_SIZE, &ucResponse, ulResponseTime_))
  940. {
  941. ucFSResponse = ucResponse; //save FSResponse
  942. return ucFSResponse;
  943. }
  944. else
  945. {
  946. ucFSResponse = ucResponse;
  947. return ucFSResponse;
  948. }
  949. }
  950. ///////////////////////////////////////////////////////////////////////
  951. /* ANTFS REQUESTS */
  952. ///////////////////////////////////////////////////////////////////////
  953. UCHAR DSIFramerANT::GetCmdPipe(UCHAR ucOffset_, UCHAR ucReadSize_, UCHAR *pucReadBuffer_, ULONG ulResponseTime_)
  954. {
  955. ANT_MESSAGE_ITEM stResponse;
  956. FS_MESSAGE stMessage;
  957. // Build the request message
  958. stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
  959. stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
  960. stMessage.aucData[0] = (UCHAR)((MESG_FS_ANTFS_GET_CMD_PIPE_ID >> 8) & 0xFF);
  961. stMessage.aucData[1] = (UCHAR)(MESG_FS_ANTFS_GET_CMD_PIPE_ID & 0xFF);
  962. stMessage.aucData[2] = ucOffset_;
  963. stMessage.aucData[3] = ucReadSize_;
  964. SendFSRequest(MESG_FS_ANTFS_GET_CMD_PIPE_SIZE, &stResponse, stMessage, ulResponseTime_);
  965. ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
  966. //Now load pucBuffer_ with the Payload Array
  967. for(int i = 0; i < ucReadSize_; i++)
  968. pucReadBuffer_[i] = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD + 1 + i]; //add 1 to skip SizeRead byte
  969. return stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD ]; //return t
  970. }
  971. ///////////////////////////////////////////////////////////////////////
  972. UCHAR DSIFramerANT::SetCmdPipe(UCHAR ucOffset_, UCHAR ucWriteSize_, const UCHAR *pucWriteBuffer_, ULONG ulResponseTime_)
  973. {
  974. ANT_MESSAGE_ITEM stResponse;
  975. FS_MESSAGE stMessage;
  976. // Build the request message
  977. stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
  978. stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
  979. stMessage.aucData[0] = (UCHAR)((MESG_FS_ANTFS_SET_CMD_PIPE_ID >> 8) & 0xFF);
  980. stMessage.aucData[1] = (UCHAR)(MESG_FS_ANTFS_SET_CMD_PIPE_ID & 0xFF);
  981. stMessage.aucData[2] = ucOffset_;
  982. stMessage.aucData[3] = ucWriteSize_;
  983. for(int i = 0; i < ucWriteSize_; i++)
  984. stMessage.aucData[MESG_FS_ANTFS_SET_CMD_PIPE_SIZE - 1 + i] = pucWriteBuffer_[i];
  985. SendFSRequest(MESG_FS_ANTFS_SET_CMD_PIPE_SIZE + ucWriteSize_, &stResponse, stMessage, ulResponseTime_);
  986. ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
  987. return stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD]; //return the Number of bytes successfully written
  988. }
  989. ///////////////////////////////////////////////////////////////////////
  990. UCHAR DSIFramerANT::GetLastError()
  991. {
  992. return ucFSResponse;
  993. }