12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223 |
- /*
- This software is subject to the license described in the License.txt file
- included with this software distribution. You may not use this file except in compliance
- with this license.
- Copyright (c) Dynastream Innovations Inc. 2014
- All rights reserved.
- */
- #include "types.h"
- #include "defines.h"
- #include "antmessage.h"
- #include "antdefines.h"
- #include "checksum.h"
- #include "dsi_thread.h"
- #include "dsi_framer_ant.hpp"
- #include <string.h>
- #define WAIT_TO_FEED_TRANSFER
- #include "dsi_debug.hpp"
- #if defined(DEBUG_FILE)
- #define SERIAL_DEBUG
- #endif
- //////////////////////////////////////////////////
- //ANTFS Tx-Message Buffer Offsets
- //////////////////////////////////////////////////
- #define OFFSET_COMMAND_ID ((UCHAR)0x00)
- #define OFFSET_REQUEST_ID ((UCHAR)0x00)
- #define OFFSET_MESSAGE_ID ((UCHAR)0x01)
- #define OFFSET_DATA0 ((UCHAR)0x02)
- //////////////////////////////////////////////////
- //ANTFS Command-Response Buffer Offsets
- //////////////////////////////////////////////////
- #define OFFSET_RESPONSE_RESPONSE_ID_HIGH ((UCHAR)0x00)
- #define OFFSET_RESPONSE_COMMAND_ID_LOW ((UCHAR)0x01)
- #define OFFSET_RESPONSE_COMMAND_ID_HIGH ((UCHAR)0x02)
- #define OFFSET_RESPONSE_FSRESPONSE ((UCHAR)0x03)
- //////////////////////////////////////////////////
- //ANTFS Request-Response Buffer Offsets
- //////////////////////////////////////////////////
- #define OFFSET_REQUEST_RESPONSE_RESPONSE_ID ((UCHAR)0x00)
- #define OFFSET_REQUEST_RESPONSE_FSRESPONSE ((UCHAR)0x01)
- #define OFFSET_REQUEST_RESPONSE_PAYLOAD ((UCHAR)0x02)
- ////////////////////////////////////////////////////////
- //Public Functions
- // This file contains the implementation of the extended ANT messaging
- // for integrated ANT-FS client. Function declarations are
- // in dsi_framer_ant.hpp
- ////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////
- BOOL DSIFramerANT::SendFSCommand(FS_MESSAGE *pstFSMessage_, USHORT usMessageSize_, UCHAR* pucFSResponse, ULONG ulResponseTime_)
- {
- ANTMessageResponse *pclCommandResponse = (ANTMessageResponse*)NULL;
- // If we are going to be waiting for a response setup the Response object
- if (ulResponseTime_ != 0)
- {
- UCHAR aucDesiredData[MESG_FS_REQUEST_RESPONSE_SIZE];
- UCHAR bytesToMatch = MESG_FS_REQUEST_RESPONSE_SIZE;
- aucDesiredData[OFFSET_RESPONSE_RESPONSE_ID_HIGH] = (UCHAR)(MESG_EXT_RESPONSE_ID & 0xFF);
- aucDesiredData[OFFSET_RESPONSE_COMMAND_ID_LOW] = pstFSMessage_->ucCommandID;
- aucDesiredData[OFFSET_RESPONSE_COMMAND_ID_HIGH] = pstFSMessage_->ucMessageID;
- pclCommandResponse = new ANTMessageResponse();
- pclCommandResponse->Attach((UCHAR)((MESG_EXT_RESPONSE_ID >> 8) & 0xFF), aucDesiredData, bytesToMatch, this);
- }
- // Write the command message.
- if (!WriteMessage(pstFSMessage_, usMessageSize_))
- {
- #if defined(DEBUG_FILE)
- DSIDebug::ThreadWrite("Framer->SendFSCommand(): WriteMessage Failed.");
- #endif
- if(pclCommandResponse != NULL)
- {
- delete pclCommandResponse;
- pclCommandResponse = (ANTMessageResponse*)NULL;
- }
- return FALSE;
- }
- // Return immediately if we aren't waiting for the response.
- if (ulResponseTime_ == 0)
- return TRUE;
- // Wait for the response.
- pclCommandResponse->WaitForResponse(ulResponseTime_);
- pclCommandResponse->Remove(); //detach from list
- // We haven't received a response in the allotted time.
- //if (pclCommandResponse->stMessageItem.ucSize == 0)
- if (pclCommandResponse->bResponseReady == FALSE)
- {
- delete pclCommandResponse;
- #if defined(SERIAL_DEBUG)
- DSIDebug::ThreadWrite("Framer->SendCommand(): Timeout.");
- #endif
- return FALSE;
- }
- // Check the response.
- if (pclCommandResponse->stMessageItem.stANTMessage.aucData[OFFSET_RESPONSE_FSRESPONSE] != FS_NO_ERROR_RESPONSE)
- {
- delete pclCommandResponse;
- #if defined(DEBUG_FILE)
- DSIDebug::ThreadWrite("Framer->SendFSCommand(): Response != RESPONSE_NO_ERROR.");
- #endif
- return FALSE;
- }
- *pucFSResponse = pclCommandResponse->stMessageItem.stANTMessage.aucData[OFFSET_RESPONSE_FSRESPONSE]; //Save the FSResponse
- delete pclCommandResponse;
- return TRUE;
- }
- ///////////////////////////////////////////////////////////////////////
- BOOL DSIFramerANT::SendFSRequest(UCHAR MesgSize, ANT_MESSAGE_ITEM *pstANTResponse_, FS_MESSAGE stMessage, ULONG ulResponseTime_)
- {
- ANTMessageResponse *pclRequestResponse = (ANTMessageResponse*)NULL;
- // If we are going to be waiting for a response setup the Response object
- if ((ulResponseTime_ != 0) && (pstANTResponse_ != NULL))
- {
- pclRequestResponse = new ANTMessageResponse();
- pclRequestResponse->Attach(MESG_EXT_ID_2, (UCHAR*)NULL, 0, this);
- }
- // Write the command message.
- if (!WriteMessage(&stMessage, MesgSize))
- {
- if(pclRequestResponse != NULL)
- {
- delete pclRequestResponse;
- pclRequestResponse = (ANTMessageResponse*)NULL;
- }
- return FALSE;
- }
- // Return immediately if we aren't waiting for the response.
- if ((ulResponseTime_ == 0) || (pstANTResponse_ == NULL))
- return TRUE;
- // Wait for the response.
- pclRequestResponse->WaitForResponse(ulResponseTime_);
- pclRequestResponse->Remove();
- // We haven't received a response in the allotted time.
- if (pclRequestResponse->bResponseReady == FALSE)
- {
- delete pclRequestResponse;
- return FALSE;
- }
- // Copy out the response
- pstANTResponse_->ucSize = pclRequestResponse->stMessageItem.ucSize;
- pstANTResponse_->stANTMessage.ucMessageID = pclRequestResponse->stMessageItem.stANTMessage.ucMessageID;
- memcpy (pstANTResponse_->stANTMessage.aucData, pclRequestResponse->stMessageItem.stANTMessage.aucData, pclRequestResponse->stMessageItem.ucSize);
- delete pclRequestResponse;
- return TRUE;
- }
- UCHAR getByte_ulLE(int byteNum, ULONG value)
- {
- if (byteNum == 1) //Return low byte
- return (UCHAR)(value & 0x000000FF);
- else if (byteNum == 2) //Return mid-low byte
- return (UCHAR)((value & 0x0000FF00) >> 8);
- else if (byteNum == 3) //Return mid-high byte
- return (UCHAR)((value & 0x00FF0000) >> 16);
- else if (byteNum == 4) //Return high byte
- return (UCHAR)((value & 0xFF000000) >> 24);
- #if defined(DEBUG_FILE)
- DSIDebug::ThreadWrite("getByte_ulLE(): Invalid byteNum, returning 0.");
- #endif
- return 0; //If bytenum is invalid always return 0
- }
- /////////////////////////////////////////////////////
- //ANTFS_Integrated Serial Functions
- ////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////
- /* MEMDev COMMANDS */
- //////////////////////////////////////////////////////////////
- BOOL DSIFramerANT::InitEEPROMDevice(USHORT usPageSize_, UCHAR ucAddressConfig_, ULONG ulResponseTime_)
- {
- FS_MESSAGE stMessage;
- UCHAR ucResponse;
- stMessage.ucCommandID = (UCHAR)((MESG_MEMDEV_EEPROM_INIT_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_MEMDEV_EEPROM_INIT_ID & 0xFF);
- stMessage.aucData[0] = getByte_ulLE(1,usPageSize_);
- stMessage.aucData[1] = getByte_ulLE(2,usPageSize_);
- stMessage.aucData[2] = getByte_ulLE(1,ucAddressConfig_);
- if(SendFSCommand(&stMessage, MESG_MEMDEV_EEPROM_INIT_SIZE, &ucResponse, ulResponseTime_))
- {
- ucFSResponse = ucResponse;
- return TRUE;
- }
- else
- return FALSE;
- }
- ////////////////////////////////////////////////////////////////////////
- /* File System Commands*/
- ////////////////////////////////////////////////////////////////////////
- BOOL DSIFramerANT::InitFSMemory(ULONG ulResponseTime_)
- {
- FS_MESSAGE stMessage;
- UCHAR ucResponse;
- stMessage.ucCommandID = (UCHAR)((MESG_FS_INIT_MEMORY_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_FS_INIT_MEMORY_ID & 0xFF);
- if(SendFSCommand(&stMessage, MESG_FS_INIT_MEMORY_SIZE, &ucResponse, ulResponseTime_))
- {
- ucFSResponse = ucResponse; //save FSResponse
- return TRUE;
- }
- else
- {
- ucFSResponse = ucResponse;
- return FALSE;
- }
- }
- ///////////////////////////////////////////////////////////////////////
- BOOL DSIFramerANT::FormatFSMemory(USHORT usNumberOfSectors_, USHORT usPagesPerSector_, ULONG ulResponseTime_)
- {
- FS_MESSAGE stMessage;
- UCHAR ucResponse;
- stMessage.ucCommandID = (UCHAR)((MESG_FS_FORMAT_MEMORY_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_FS_FORMAT_MEMORY_ID & 0xFF);
- stMessage.aucData[0] = getByte_ulLE(1,usNumberOfSectors_);
- stMessage.aucData[1] = getByte_ulLE(2,usNumberOfSectors_);
- stMessage.aucData[2] = getByte_ulLE(1,usPagesPerSector_);
- stMessage.aucData[3] = getByte_ulLE(2,usPagesPerSector_);
- if(SendFSCommand(&stMessage, MESG_FS_FORMAT_MEMORY_SIZE, &ucResponse, ulResponseTime_))
- {
- ucFSResponse = ucResponse; //save FSResponse
- return TRUE;
- }
- else
- {
- ucFSResponse = ucResponse;
- return FALSE;
- }
- }
- ///////////////////////////////////////////////////////////////////////
- BOOL DSIFramerANT::SaveDirectory(ULONG ulResponseTime_)
- {
- FS_MESSAGE stMessage;
- UCHAR ucResponse;
- stMessage.ucCommandID = (UCHAR)((MESG_FS_DIRECTORY_SAVE_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_FS_DIRECTORY_SAVE_ID & 0xFF);
- if(SendFSCommand(&stMessage, MESG_FS_DIRECTORY_SAVE_SIZE, &ucResponse, ulResponseTime_))
- {
- ucFSResponse = ucResponse; //save FSResponse
- return TRUE;
- }
- else
- {
- ucFSResponse = ucResponse;
- return FALSE;
- }
- }
- ///////////////////////////////////////////////////////////////////////
- BOOL DSIFramerANT::DirectoryRebuild(ULONG ulResponseTime_)
- {
- FS_MESSAGE stMessage;
- UCHAR ucResponse;
- stMessage.ucCommandID = (UCHAR)((MESG_FS_DIRECTORY_REBUILD_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_FS_DIRECTORY_REBUILD_ID & 0xFF);
- if(SendFSCommand(&stMessage, MESG_FS_DIRECTORY_REBUILD_SIZE, &ucResponse, ulResponseTime_))
- {
- ucFSResponse = ucResponse; //save FSResponse
- return TRUE;
- }
- else
- {
- ucFSResponse = ucResponse;
- return FALSE;
- }
- }
- ///////////////////////////////////////////////////////////////////////
- BOOL DSIFramerANT::FileDelete(UCHAR ucFileHandle_, ULONG ulResponseTime_)
- {
- FS_MESSAGE stMessage;
- UCHAR ucResponse;
- stMessage.ucCommandID = (UCHAR)((MESG_FS_FILE_DELETE_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_FS_FILE_DELETE_ID & 0xFF);
- stMessage.aucData[0] = ucFileHandle_;
- if(SendFSCommand(&stMessage, MESG_FS_FILE_DELETE_SIZE, &ucResponse, ulResponseTime_))
- {
- ucFSResponse = ucResponse; //save FSResponse
- return TRUE;
- }
- else
- {
- ucFSResponse = ucResponse;
- return FALSE;
- }
- }
- ///////////////////////////////////////////////////////////////////////
- BOOL DSIFramerANT::FileClose(UCHAR ucFileHandle_, ULONG ulResponseTime_)
- {
- FS_MESSAGE stMessage;
- UCHAR ucResponse;
- stMessage.ucCommandID = (UCHAR)((MESG_FS_FILE_CLOSE_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_FS_FILE_CLOSE_ID & 0xFF);
- stMessage.aucData[0] = ucFileHandle_;
- if(SendFSCommand(&stMessage, MESG_FS_FILE_CLOSE_SIZE, &ucResponse, ulResponseTime_))
- {
- ucFSResponse = ucResponse; //save FSResponse
- return TRUE;
- }
- else
- {
- ucFSResponse = ucResponse;
- return FALSE;
- }
- }
- ///////////////////////////////////////////////////////////////////////
- BOOL DSIFramerANT::SetFileSpecificFlags(UCHAR ucFileHandle_, UCHAR ucFlags_, ULONG ulResponseTime_)
- {
- FS_MESSAGE stMessage;
- UCHAR ucResponse;
- stMessage.ucCommandID = (UCHAR)((MESG_FS_FILE_SET_SPECIFIC_FLAGS_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_FS_FILE_SET_SPECIFIC_FLAGS_ID & 0xFF);
- stMessage.aucData[0] = ucFileHandle_;
- stMessage.aucData[1] = ucFlags_;
- if(SendFSCommand(&stMessage, MESG_FS_FILE_SET_SPECIFIC_FLAGS_SIZE, &ucResponse, ulResponseTime_))
- {
- ucFSResponse = ucResponse; //save FSResponse
- return TRUE;
- }
- else
- {
- ucFSResponse = ucResponse;
- return FALSE;
- }
- }
- ///////////////////////////////////////////////////////////////////////
- UCHAR DSIFramerANT::DirectoryReadLock(BOOL bLock_, ULONG ulResponseTime_)
- {
- FS_MESSAGE stMessage;
- UCHAR ucResponse;
- stMessage.ucCommandID = (UCHAR)((MESG_FS_DIRECTORY_READ_LOCK_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_FS_DIRECTORY_READ_LOCK_ID & 0xFF);
- stMessage.aucData[0] = (UCHAR) bLock_;
- if(SendFSCommand(&stMessage, MESG_FS_DIRECTORY_READ_LOCK_SIZE, &ucResponse, ulResponseTime_))
- {
- ucFSResponse = ucResponse; //save FSResponse
- return ucFSResponse;
- }
- else
- {
- ucFSResponse = ucResponse;
- return ucFSResponse;
- }
- }
- ///////////////////////////////////////////////////////////////////////
- BOOL DSIFramerANT::SetSystemTime(ULONG ulTime_, ULONG ulResponseTime_)
- {
- FS_MESSAGE stMessage;
- UCHAR ucResponse;
- stMessage.ucCommandID = (UCHAR)((MESG_FS_SYSTEM_TIME_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_FS_SYSTEM_TIME_ID & 0xFF);
- stMessage.aucData[0] = getByte_ulLE(1,ulTime_);
- stMessage.aucData[1] = getByte_ulLE(2,ulTime_);
- stMessage.aucData[2] = getByte_ulLE(3,ulTime_);
- stMessage.aucData[3] = getByte_ulLE(4,ulTime_);
- if(SendFSCommand(&stMessage, MESG_FS_SYSTEM_TIME_SIZE, &ucResponse, ulResponseTime_))
- {
- ucFSResponse = ucResponse; //save FSResponse
- return TRUE;
- }
- else
- {
- ucFSResponse = ucResponse;
- return FALSE;
- }
- }
- ///////////////////////////////////////////////////////////////////////
- /* File System Requests */
- ///////////////////////////////////////////////////////////////////////
- ULONG DSIFramerANT::GetUsedSpace(ULONG ulResponseTime_)
- {
- ANT_MESSAGE_ITEM stResponse;
- FS_MESSAGE stMessage;
- // Build the request message
- stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
- stMessage.aucData[0] = (UCHAR)((MESG_FS_GET_USED_SPACE_ID >> 8) & 0xFF);
- stMessage.aucData[1] = (UCHAR)(MESG_FS_GET_USED_SPACE_ID & 0xFF);
- SendFSRequest(MESG_FS_GET_USED_SPACE_SIZE, &stResponse, stMessage, ulResponseTime_);
- ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
- 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));
- }
- ///////////////////////////////////////////////////////////////////////
- ULONG DSIFramerANT::GetFreeFSSpace(ULONG ulResponseTime_)
- {
- ANT_MESSAGE_ITEM stResponse;
- FS_MESSAGE stMessage;
- // Build the request message
- stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
- stMessage.aucData[0] = (UCHAR)((MESG_FS_GET_FREE_SPACE_ID >> 8) & 0xFF);
- stMessage.aucData[1] = (UCHAR)(MESG_FS_GET_FREE_SPACE_ID & 0xFF);
- SendFSRequest(MESG_FS_GET_FREE_SPACE_SIZE, &stResponse, stMessage, ulResponseTime_);
- ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
- 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);
- }
- ///////////////////////////////////////////////////////////////////////
- USHORT DSIFramerANT::FindFileIndex(UCHAR ucFileDataType_, UCHAR ucFileSubType_, USHORT usFileNumber_, ULONG ulResponseTime_)
- {
- ANT_MESSAGE_ITEM stResponse;
- FS_MESSAGE stMessage;
- // Build the request message
- stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
- stMessage.aucData[0] = (UCHAR)((MESG_FS_FIND_FILE_INDEX_ID >> 8) & 0xFF);
- stMessage.aucData[1] = (UCHAR)(MESG_FS_FIND_FILE_INDEX_ID & 0xFF);
- stMessage.aucData[2] = ucFileDataType_;
- stMessage.aucData[3] = ucFileSubType_;
- stMessage.aucData[4] = getByte_ulLE(1,usFileNumber_);
- stMessage.aucData[5] = getByte_ulLE(2,usFileNumber_);
- SendFSRequest(MESG_FS_FIND_FILE_INDEX_SIZE, &stResponse, stMessage, ulResponseTime_);
- ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
- return (USHORT)(stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD]) | (USHORT)(stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD + 1] << 8);
- }
- ///////////////////////////////////////////////////////////////////////
- UCHAR DSIFramerANT::ReadDirectoryAbsolute(ULONG ulOffset_, UCHAR ucSize_, UCHAR *pucBuffer_, ULONG ulResponseTime_)
- {
- ANT_MESSAGE_ITEM stResponse;
- FS_MESSAGE stMessage;
- // Build the request message
- stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
- stMessage.aucData[0] = (UCHAR)((MESG_FS_DIRECTORY_READ_ABSOLUTE_ID >> 8) & 0xFF);
- stMessage.aucData[1] = (UCHAR)(MESG_FS_DIRECTORY_READ_ABSOLUTE_ID & 0xFF);
- stMessage.aucData[2] = getByte_ulLE(1,ulOffset_);
- stMessage.aucData[3] = getByte_ulLE(2,ulOffset_);
- stMessage.aucData[4] = getByte_ulLE(3,ulOffset_);
- stMessage.aucData[5] = getByte_ulLE(4,ulOffset_);
- stMessage.aucData[6] = ucSize_;
- SendFSRequest(MESG_FS_DIRECTORY_READ_ABSOLUTE_SIZE, &stResponse, stMessage, ulResponseTime_);
- ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
- //Now load pucBuffer_ with the Paylaod Array
- //Caller has to do validation of the response before reading the buffer
- for(int i = 0; i < ucSize_; i++)
- pucBuffer_[i] = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD + 1 + i]; //add 1 to skip sizeRead byte
- return ucFSResponse;
- }
- ///////////////////////////////////////////////////////////////////////
- UCHAR DSIFramerANT::DirectoryReadEntry(USHORT usFileIndex_, UCHAR *ucFileDirectoryBuffer_, ULONG ulResponseTime_)
- {
- ANT_MESSAGE_ITEM stResponse;
- FS_MESSAGE stMessage;
- // Build the request message
- stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
- stMessage.aucData[0] = (UCHAR)((MESG_FS_DIRECTORY_READ_ENTRY_ID >> 8) & 0xFF);
- stMessage.aucData[1] = (UCHAR)(MESG_FS_DIRECTORY_READ_ENTRY_ID & 0xFF);
- stMessage.aucData[2] = getByte_ulLE(1, usFileIndex_);
- stMessage.aucData[3] = getByte_ulLE(2, usFileIndex_);
- SendFSRequest(MESG_FS_DIRECTORY_READ_ENTRY_SIZE, &stResponse, stMessage, ulResponseTime_);
- ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
- //Now load pucBuffer_ with the Paylaod Array
- for(int i = 0; i < 16; i++)
- ucFileDirectoryBuffer_[i] = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD + 1 + i]; //add 1 to skip sizeRead byte
- return ucFSResponse;
- }
- ///////////////////////////////////////////////////////////////////////
- ULONG DSIFramerANT::DirectoryGetSize(ULONG ulResponseTime_)
- {
- ANT_MESSAGE_ITEM stResponse;
- FS_MESSAGE stMessage;
- // Build the request message
- stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
- stMessage.aucData[0] = (UCHAR)((MESG_FS_DIRECTORY_GET_SIZE_ID >> 8) & 0xFF);
- stMessage.aucData[1] = (UCHAR)(MESG_FS_DIRECTORY_GET_SIZE_ID & 0xFF);
- SendFSRequest(MESG_FS_DIRECTORY_GET_SIZE_SIZE, &stResponse, stMessage, ulResponseTime_);
- ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
- 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);
- }
- ///////////////////////////////////////////////////////////////////////
- USHORT DSIFramerANT::FileCreate(USHORT usFileIndex_, UCHAR ucFileDataType_, ULONG ulFileIdentifier_, UCHAR ucFileDataTypeSpecificFlags_, UCHAR ucGeneralFlags_, ULONG ulResponseTime_)
- {
- ANT_MESSAGE_ITEM stResponse;
- FS_MESSAGE stMessage;
- // Build the request message
- stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
- stMessage.aucData[0] = (UCHAR)((MESG_FS_FILE_CREATE_ID >> 8) & 0xFF);
- stMessage.aucData[1] = (UCHAR)(MESG_FS_FILE_CREATE_ID & 0xFF);
- stMessage.aucData[2] = getByte_ulLE(1, usFileIndex_);
- stMessage.aucData[3] = getByte_ulLE(2, usFileIndex_);
- stMessage.aucData[4] = ucFileDataType_;
- stMessage.aucData[5] = getByte_ulLE(1, ulFileIdentifier_);
- stMessage.aucData[6] = getByte_ulLE(2, ulFileIdentifier_);
- stMessage.aucData[7] = getByte_ulLE(3, ulFileIdentifier_);
- stMessage.aucData[8] = ucFileDataTypeSpecificFlags_;
- stMessage.aucData[9] = ucGeneralFlags_;
- SendFSRequest(MESG_FS_FILE_CREATE_SIZE, &stResponse, stMessage, ulResponseTime_);
- ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
- return (USHORT)(stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD]) | (USHORT)(stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD + 1] << 8);
- }
- ///////////////////////////////////////////////////////////////////////
- UCHAR DSIFramerANT::FileOpen(USHORT usFileIndex_, UCHAR ucOpenFlags_, ULONG ulResponseTime_)
- {
- ANT_MESSAGE_ITEM stResponse;
- FS_MESSAGE stMessage;
- // Build the request message
- stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
- stMessage.aucData[0] = (UCHAR)((MESG_FS_FILE_OPEN_ID >> 8) & 0xFF);
- stMessage.aucData[1] = (UCHAR)(MESG_FS_FILE_OPEN_ID & 0xFF);
- stMessage.aucData[2] = getByte_ulLE(1, usFileIndex_);
- stMessage.aucData[3] = getByte_ulLE(2, usFileIndex_);
- stMessage.aucData[4] = ucOpenFlags_;
- SendFSRequest(MESG_FS_FILE_OPEN_SIZE, &stResponse, stMessage, ulResponseTime_);
- ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
- return (UCHAR)(stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD]);
- }
- ///////////////////////////////////////////////////////////////////////
- UCHAR DSIFramerANT::FileReadAbsolute(UCHAR ucFileHandle_, ULONG ulOffset_, UCHAR ucReadSize_, UCHAR *pucReadBuffer_, ULONG ulResponseTime_)
- {
- ANT_MESSAGE_ITEM stResponse;
- FS_MESSAGE stMessage;
- // Build the request message
- stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
- stMessage.aucData[0] = (UCHAR)((MESG_FS_FILE_READ_ABSOLUTE_ID >> 8) & 0xFF);
- stMessage.aucData[1] = (UCHAR)(MESG_FS_FILE_READ_ABSOLUTE_ID & 0xFF);
- stMessage.aucData[2] = ucFileHandle_;
- stMessage.aucData[3] = getByte_ulLE(1,ulOffset_);
- stMessage.aucData[4] = getByte_ulLE(2,ulOffset_);
- stMessage.aucData[5] = getByte_ulLE(3,ulOffset_);
- stMessage.aucData[6] = getByte_ulLE(4,ulOffset_);
- stMessage.aucData[7] = ucReadSize_;
- SendFSRequest(MESG_FS_FILE_READ_ABSOLUTE_SIZE, &stResponse, stMessage, ulResponseTime_);
- ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
- //Now load pucBuffer_ with the Paylaod Array
- for(int i = 0; i < ucReadSize_; i++)
- pucReadBuffer_[i] = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD + 1 + i]; //add 1 to skip SizeRead byte
- return ucFSResponse;
- }
- ///////////////////////////////////////////////////////////////////////
- UCHAR DSIFramerANT::FileReadRelative(UCHAR ucFileHandle_, UCHAR ucReadSize_, UCHAR *pucReadBuffer_, ULONG ulResponseTime_)
- {
- ANT_MESSAGE_ITEM stResponse;
- FS_MESSAGE stMessage;
- // Build the request message
- stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
- stMessage.aucData[0] = (UCHAR)((MESG_FS_FILE_READ_RELATIVE_ID >> 8) & 0xFF);
- stMessage.aucData[1] = (UCHAR)(MESG_FS_FILE_READ_RELATIVE_ID & 0xFF);
- stMessage.aucData[2] = ucFileHandle_;
- stMessage.aucData[3] = ucReadSize_;
- SendFSRequest(MESG_FS_FILE_READ_RELATIVE_SIZE, &stResponse, stMessage, ulResponseTime_);
- ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
- //Now load pucBuffer_ with the Paylaod Array
- for(int i = 0; i < ucReadSize_; i++)
- pucReadBuffer_[i] = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD + 1 + i]; //add 1 to skip SizeRead byte
- return ucFSResponse;
- }
- ///////////////////////////////////////////////////////////////////////
- UCHAR DSIFramerANT::FileWriteAbsolute(UCHAR ucFileHandle_, ULONG ulFileOffset_, UCHAR ucWriteSize_, const UCHAR *pucWriteBuffer_, UCHAR *ucBytesWritten_, ULONG ulResponseTime_)
- {
- ANT_MESSAGE_ITEM stResponse;
- FS_MESSAGE stMessage;
- // Build the request message
- stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
- stMessage.aucData[0] = (UCHAR)((MESG_FS_FILE_WRITE_ABSOLUTE_ID >> 8) & 0xFF);
- stMessage.aucData[1] = (UCHAR)(MESG_FS_FILE_WRITE_ABSOLUTE_ID & 0xFF);
- stMessage.aucData[2] = ucFileHandle_;
- stMessage.aucData[3] = getByte_ulLE(1,ulFileOffset_);
- stMessage.aucData[4] = getByte_ulLE(2,ulFileOffset_);
- stMessage.aucData[5] = getByte_ulLE(3,ulFileOffset_);
- stMessage.aucData[6] = getByte_ulLE(4,ulFileOffset_);
- stMessage.aucData[7] = ucWriteSize_;
- for(int i = 0; i < ucWriteSize_; i++)
- stMessage.aucData[MESG_FS_FILE_WRITE_ABSOLUTE_SIZE - 1 + i] = pucWriteBuffer_[i];
- SendFSRequest(MESG_FS_FILE_WRITE_ABSOLUTE_SIZE + ucWriteSize_, &stResponse, stMessage, ulResponseTime_);
- ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
- *ucBytesWritten_ = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD];
- return stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD]; //return the Number of bytes successfully written
- }
- ///////////////////////////////////////////////////////////////////////
- UCHAR DSIFramerANT::FileWriteRelative(UCHAR ucFileHandle_, UCHAR ucWriteSize_, const UCHAR *pucWriteBuffer_, UCHAR *ucBytesWritten_, ULONG ulResponseTime_)
- {
- ANT_MESSAGE_ITEM stResponse;
- FS_MESSAGE stMessage;
- // Build the request message
- stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
- stMessage.aucData[0] = (UCHAR)((MESG_FS_FILE_WRITE_RELATIVE_ID >> 8) & 0xFF);
- stMessage.aucData[1] = (UCHAR)(MESG_FS_FILE_WRITE_RELATIVE_ID & 0xFF);
- stMessage.aucData[2] = ucFileHandle_;
- stMessage.aucData[3] = ucWriteSize_;
- for(int i = 0; i < ucWriteSize_; i++)
- stMessage.aucData[MESG_FS_FILE_WRITE_RELATIVE_SIZE - 1 + i] = pucWriteBuffer_[i];
- SendFSRequest(MESG_FS_FILE_WRITE_RELATIVE_SIZE + ucWriteSize_, &stResponse, stMessage, ulResponseTime_);
- ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
- *ucBytesWritten_ = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD];
- return stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD]; //return the Number of bytes successfully written
- }
- ///////////////////////////////////////////////////////////////////////
- ULONG DSIFramerANT::FileGetSize(UCHAR ucFileHandle_, ULONG ulResponseTime_)
- {
- ANT_MESSAGE_ITEM stResponse;
- FS_MESSAGE stMessage;
- // Build the request message
- stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
- stMessage.aucData[0] = (UCHAR)((MESG_FS_FILE_GET_SIZE_ID >> 8) & 0xFF);
- stMessage.aucData[1] = (UCHAR)(MESG_FS_FILE_GET_SIZE_ID & 0xFF);
- stMessage.aucData[2] = ucFileHandle_;
- SendFSRequest(MESG_FS_FILE_GET_SIZE_SIZE, &stResponse, stMessage, ulResponseTime_);
- ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
- 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);
- }
- ///////////////////////////////////////////////////////////////////////
- ULONG DSIFramerANT::FileGetSizeInMem(UCHAR ucFileHandle_, ULONG ulResponseTime_)
- {
- ANT_MESSAGE_ITEM stResponse;
- FS_MESSAGE stMessage;
- // Build the request message
- stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
- stMessage.aucData[0] = (UCHAR)((MESG_FS_FILE_GET_SIZE_IN_MEM_ID >> 8) & 0xFF);
- stMessage.aucData[1] = (UCHAR)(MESG_FS_FILE_GET_SIZE_IN_MEM_ID & 0xFF);
- stMessage.aucData[2] = ucFileHandle_;
- SendFSRequest(MESG_FS_FILE_GET_SIZE_IN_MEM_SIZE, &stResponse, stMessage, ulResponseTime_);
- ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
- 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);
- }
- ///////////////////////////////////////////////////////////////////////
- UCHAR DSIFramerANT::FileGetSpecificFlags(UCHAR ucFileHandle_, ULONG ulResponseTime_)
- {
- ANT_MESSAGE_ITEM stResponse;
- FS_MESSAGE stMessage;
- // Build the request message
- stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
- stMessage.aucData[0] = (UCHAR)((MESG_FS_FILE_GET_SPECIFIC_FILE_FLAGS_ID >> 8) & 0xFF);
- stMessage.aucData[1] = (UCHAR)(MESG_FS_FILE_GET_SPECIFIC_FILE_FLAGS_ID & 0xFF);
- stMessage.aucData[2] = ucFileHandle_;
- SendFSRequest(MESG_FS_FILE_GET_SPECIFIC_FILE_FLAGS_SIZE, &stResponse, stMessage, ulResponseTime_);
- ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
- return stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD];
- }
- ///////////////////////////////////////////////////////////////////////
- ULONG DSIFramerANT::FileGetSystemTime(ULONG ulResponseTime_)
- {
- ANT_MESSAGE_ITEM stResponse;
- FS_MESSAGE stMessage;
- // Build the request message
- stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
- stMessage.aucData[0] = (UCHAR)((MESG_FS_SYSTEM_TIME_ID >> 8) & 0xFF);
- stMessage.aucData[1] = (UCHAR)(MESG_FS_SYSTEM_TIME_ID & 0xFF);
- SendFSRequest(MESG_FS_SYSTEM_TIME_REQUEST_SIZE, &stResponse, stMessage, ulResponseTime_);
- ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
- 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);
- }
- ///////////////////////////////////////////////////////////////////////
- /* FS-Crypto Commands */
- ///////////////////////////////////////////////////////////////////////
- UCHAR DSIFramerANT::CryptoAddUserKeyIndex(UCHAR ucIndex_, UCHAR *pucKey_, ULONG ulResponseTime_)
- {
- FS_MESSAGE stMessage;
- UCHAR ucResponse;
- stMessage.ucCommandID = (UCHAR)((MESG_FS_CRYPTO_ADD_USER_KEY_INDEX_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_FS_CRYPTO_ADD_USER_KEY_INDEX_ID & 0xFF);
- stMessage.aucData[0] = ucIndex_;
- //copy Crypto Key into the aucData array starting at index 1 as index 0 is already used
- for(int i = 1; i < 33; i++)
- stMessage.aucData[i] = pucKey_[i - 1];
- if(SendFSCommand(&stMessage, MESG_FS_CRYPTO_ADD_USER_KEY_INDEX_SIZE, &ucResponse, ulResponseTime_))
- {
- ucFSResponse = ucResponse; //save FSResponse
- return ucFSResponse;
- }
- else
- {
- ucFSResponse = ucResponse;
- return ucFSResponse;
- }
- }
- ///////////////////////////////////////////////////////////////////////
- UCHAR DSIFramerANT::CryptoSetUserKeyIndex(UCHAR ucIndex_, ULONG ulResponseTime_)
- {
- FS_MESSAGE stMessage;
- UCHAR ucResponse;
- stMessage.ucCommandID = (UCHAR)((MESG_FS_CRYPTO_SET_USER_KEY_INDEX_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_FS_CRYPTO_SET_USER_KEY_INDEX_ID & 0xFF);
- stMessage.aucData[0] = ucIndex_;
- if(SendFSCommand(&stMessage, MESG_FS_CRYPTO_SET_USER_KEY_INDEX_SIZE, &ucResponse, ulResponseTime_))
- {
- ucFSResponse = ucResponse; //save FSResponse
- return ucFSResponse;
- }
- else
- {
- ucFSResponse = ucResponse;
- return ucFSResponse;
- }
- }
- ///////////////////////////////////////////////////////////////////////
- UCHAR DSIFramerANT::CryptoSetUserKeyVal(UCHAR *pucKey_, ULONG ulResponseTime_)
- {
- FS_MESSAGE stMessage;
- UCHAR ucResponse;
- stMessage.ucCommandID = (UCHAR)((MESG_FS_CRYPTO_SET_USER_KEY_VAL_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_FS_CRYPTO_SET_USER_KEY_VAL_ID & 0xFF);
- //copy Crypto Key into the aucData array starting at index 1 as index 0 is already used
- for(int i = 0; i < 33; i++)
- stMessage.aucData[i] = pucKey_[i];
- if(SendFSCommand(&stMessage, MESG_FS_CRYPTO_SET_USER_KEY_VAL_SIZE, &ucResponse, ulResponseTime_))
- {
- ucFSResponse = ucResponse; //save FSResponse
- return ucFSResponse;
- }
- else
- {
- ucFSResponse = ucResponse;
- return ucFSResponse;
- }
- }
- ///////////////////////////////////////////////////////////////////////
- /* FIT Commands */
- ///////////////////////////////////////////////////////////////////////
- UCHAR DSIFramerANT::FitFileIntegrityCheck(UCHAR ucFileHandle_, ULONG ulResponseTime_)
- {
- FS_MESSAGE stMessage;
- UCHAR ucResponse;
- stMessage.ucCommandID = (UCHAR)((MESG_FS_FIT_FILE_INTEGRITY_CHECK_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_FS_FIT_FILE_INTEGRITY_CHECK_ID & 0xFF);
- stMessage.aucData[0] = ucFileHandle_;
- if(SendFSCommand(&stMessage, MESG_FS_FIT_FILE_INTEGRITY_CHECK_SIZE, &ucResponse, ulResponseTime_))
- {
- ucFSResponse = ucResponse; //save FSResponse
- return ucFSResponse;
- }
- else
- {
- ucFSResponse = ucResponse;
- return ucFSResponse;
- }
- }
- ///////////////////////////////////////////////////////////////////////
- /* ANTFS Commands */
- ///////////////////////////////////////////////////////////////////////
- UCHAR DSIFramerANT::OpenBeacon(ULONG ulResponseTime_)
- {
- FS_MESSAGE stMessage;
- UCHAR ucResponse;
- stMessage.ucCommandID = (UCHAR)((MESG_FS_ANTFS_OPEN_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_FS_ANTFS_OPEN_ID & 0xFF);
- if(SendFSCommand(&stMessage, MESG_FS_ANTFS_OPEN_SIZE, &ucResponse, ulResponseTime_))
- {
- ucFSResponse = ucResponse; //save FSResponse
- return ucFSResponse;
- }
- else
- {
- ucFSResponse = ucResponse;
- return ucFSResponse;
- }
- }
- ///////////////////////////////////////////////////////////////////////
- UCHAR DSIFramerANT::CloseBeacon(ULONG ulResponseTime_)
- {
- FS_MESSAGE stMessage;
- UCHAR ucResponse;
- stMessage.ucCommandID = (UCHAR)((MESG_FS_ANTFS_CLOSE_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_FS_ANTFS_CLOSE_ID & 0xFF);
- if(SendFSCommand(&stMessage, MESG_FS_ANTFS_CLOSE_SIZE, &ucResponse, ulResponseTime_))
- {
- ucFSResponse = ucResponse; //save FSResponse
- return ucFSResponse;
- }
- else
- {
- ucFSResponse = ucResponse;
- return ucFSResponse;
- }
- }
- ///////////////////////////////////////////////////////////////////////
- UCHAR DSIFramerANT::ConfigBeacon(USHORT usDeviceType_, USHORT usManufacturer_, UCHAR ucAuthType_, UCHAR ucBeaconStatus_, ULONG ulResponseTime_)
- {
- FS_MESSAGE stMessage;
- UCHAR ucResponse;
- stMessage.ucCommandID = (UCHAR)((MESG_FS_ANTFS_CONFIG_BEACON_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_FS_ANTFS_CONFIG_BEACON_ID & 0xFF);
- stMessage.aucData[0] = getByte_ulLE(1,usDeviceType_);
- stMessage.aucData[1] = getByte_ulLE(2,usDeviceType_);
- stMessage.aucData[2] = getByte_ulLE(1,usManufacturer_);
- stMessage.aucData[3] = getByte_ulLE(2,usManufacturer_);
- stMessage.aucData[4] = ucAuthType_;
- stMessage.aucData[5] = ucBeaconStatus_;
- if(SendFSCommand(&stMessage, MESG_FS_ANTFS_CONFIG_BEACON_SIZE, &ucResponse, ulResponseTime_))
- {
- ucFSResponse = ucResponse; //save FSResponse
- return ucFSResponse;
- }
- else
- {
- ucFSResponse = ucResponse;
- return ucFSResponse;
- }
- }
- ///////////////////////////////////////////////////////////////////////
- UCHAR DSIFramerANT::SetFriendlyName(UCHAR ucLength_, const UCHAR *pucString_, ULONG ulResponseTime_)
- {
- FS_MESSAGE stMessage;
- UCHAR ucResponse;
- stMessage.ucCommandID = (UCHAR)((MESG_FS_ANTFS_SET_AUTH_STRING_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_FS_ANTFS_SET_AUTH_STRING_ID & 0xFF);
- stMessage.aucData[0] = 0; //send 0 for Friendlyname Command
- //Load up the String into the aucData starting at index 1
- for(int i = 1; i < ucLength_ + 1; i++)
- stMessage.aucData[i] = pucString_[i - 1];
- if(SendFSCommand(&stMessage, MESG_FS_ANTFS_SET_AUTH_STRING_SIZE + ucLength_, &ucResponse, ulResponseTime_))
- {
- ucFSResponse = ucResponse; //save FSResponse
- return ucFSResponse;
- }
- else
- {
- ucFSResponse = ucResponse;
- return ucFSResponse;
- }
- }
- ///////////////////////////////////////////////////////////////////////
- UCHAR DSIFramerANT::SetPasskey(UCHAR ucLength_, const UCHAR *pucString_, ULONG ulResponseTime_)
- {
- FS_MESSAGE stMessage;
- UCHAR ucResponse;
- stMessage.ucCommandID = (UCHAR)((MESG_FS_ANTFS_SET_AUTH_STRING_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_FS_ANTFS_SET_AUTH_STRING_ID & 0xFF);
- stMessage.aucData[0] = 1; //send 1 for Passkey Command
- //Load up the String into the aucData starting at index 1
- for(int i = 1; i < ucLength_ + 1; i++)
- stMessage.aucData[i] = pucString_[i - 1];
- if(SendFSCommand(&stMessage, MESG_FS_ANTFS_SET_AUTH_STRING_SIZE + ucLength_, &ucResponse, ulResponseTime_))
- {
- ucFSResponse = ucResponse; //save FSResponse
- return ucFSResponse;
- }
- else
- {
- ucFSResponse = ucResponse;
- return ucFSResponse;
- }
- }
- ///////////////////////////////////////////////////////////////////////
- UCHAR DSIFramerANT::SetBeaconState(UCHAR ucBeaconStatus_, ULONG ulResponseTime_)
- {
- FS_MESSAGE stMessage;
- UCHAR ucResponse;
- stMessage.ucCommandID = (UCHAR)((MESG_FS_ANTFS_SET_BEACON_STATE_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_FS_ANTFS_SET_BEACON_STATE_ID & 0xFF);
- stMessage.aucData[0] = ucBeaconStatus_;
- if(SendFSCommand(&stMessage, MESG_FS_ANTFS_SET_BEACON_STATE_SIZE, &ucResponse, ulResponseTime_))
- {
- ucFSResponse = ucResponse; //save FSResponse
- return ucFSResponse;
- }
- else
- {
- ucFSResponse = ucResponse;
- return ucFSResponse;
- }
- }
- ///////////////////////////////////////////////////////////////////////
- UCHAR DSIFramerANT::PairResponse(BOOL bAccept_, ULONG ulResponseTime_)
- {
- FS_MESSAGE stMessage;
- UCHAR ucResponse;
- stMessage.ucCommandID = (UCHAR)((MESG_FS_ANTFS_PAIR_RESPONSE_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_FS_ANTFS_PAIR_RESPONSE_ID & 0xFF);
- stMessage.aucData[0] = (UCHAR) bAccept_;
- if(SendFSCommand(&stMessage, MESG_FS_ANTFS_PAIR_RESPONSE_SIZE, &ucResponse, ulResponseTime_))
- {
- ucFSResponse = ucResponse; //save FSResponse
- return ucFSResponse;
- }
- else
- {
- ucFSResponse = ucResponse;
- return ucFSResponse;
- }
- }
- ///////////////////////////////////////////////////////////////////////
- UCHAR DSIFramerANT::SetLinkFrequency(UCHAR ucChannelNumber_, UCHAR ucFrequency_, ULONG ulResponseTime_)
- {
- FS_MESSAGE stMessage;
- UCHAR ucResponse;
- stMessage.ucCommandID = (UCHAR)((MESG_FS_ANTFS_SET_LINK_FREQ_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_FS_ANTFS_SET_LINK_FREQ_ID & 0xFF);
- stMessage.aucData[0] = ucChannelNumber_;
- stMessage.aucData[1] = ucFrequency_;
- if(SendFSCommand(&stMessage, MESG_FS_ANTFS_SET_LINK_FREQ_SIZE, &ucResponse, ulResponseTime_))
- {
- ucFSResponse = ucResponse; //save FSResponse
- return ucFSResponse;
- }
- else
- {
- ucFSResponse = ucResponse;
- return ucFSResponse;
- }
- }
- ///////////////////////////////////////////////////////////////////////
- UCHAR DSIFramerANT::SetBeaconTimeout(UCHAR ucTimeout_, ULONG ulResponseTime_)
- {
- FS_MESSAGE stMessage;
- UCHAR ucResponse;
- stMessage.ucCommandID = (UCHAR)((MESG_FS_ANTFS_SET_BEACON_TIMEOUT_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_FS_ANTFS_SET_BEACON_TIMEOUT_ID & 0xFF);
- stMessage.aucData[0] = ucTimeout_;
- if(SendFSCommand(&stMessage, MESG_FS_ANTFS_SET_BEACON_TIMEOUT_SIZE, &ucResponse, ulResponseTime_))
- {
- ucFSResponse = ucResponse; //save FSResponse
- return ucFSResponse;
- }
- else
- {
- ucFSResponse = ucResponse;
- return ucFSResponse;
- }
- }
- ///////////////////////////////////////////////////////////////////////
- UCHAR DSIFramerANT::SetPairingTimeout(UCHAR ucTimeout_, ULONG ulResponseTime_)
- {
- FS_MESSAGE stMessage;
- UCHAR ucResponse;
- stMessage.ucCommandID = (UCHAR)((MESG_FS_ANTFS_SET_PAIRING_TIMEOUT_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_FS_ANTFS_SET_PAIRING_TIMEOUT_ID & 0xFF);
- stMessage.aucData[0] = ucTimeout_;
- if(SendFSCommand(&stMessage, MESG_FS_ANTFS_SET_PAIRING_TIMEOUT_SIZE, &ucResponse, ulResponseTime_))
- {
- ucFSResponse = ucResponse; //save FSResponse
- return ucFSResponse;
- }
- else
- {
- ucFSResponse = ucResponse;
- return ucFSResponse;
- }
- }
- ///////////////////////////////////////////////////////////////////////
- UCHAR DSIFramerANT::EnableRemoteFileCreate(BOOL bEnable_, ULONG ulResponseTime_)
- {
- FS_MESSAGE stMessage;
- UCHAR ucResponse;
- stMessage.ucCommandID = (UCHAR)((MESG_FS_ANTFS_REMOTE_FILE_CREATE_EN_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_FS_ANTFS_REMOTE_FILE_CREATE_EN_ID & 0xFF);
- stMessage.aucData[0] = (UCHAR) bEnable_;
- if(SendFSCommand(&stMessage, MESG_FS_ANTFS_REMOTE_FILE_CREATE_EN_SIZE, &ucResponse, ulResponseTime_))
- {
- ucFSResponse = ucResponse; //save FSResponse
- return ucFSResponse;
- }
- else
- {
- ucFSResponse = ucResponse;
- return ucFSResponse;
- }
- }
- ///////////////////////////////////////////////////////////////////////
- /* ANTFS REQUESTS */
- ///////////////////////////////////////////////////////////////////////
- UCHAR DSIFramerANT::GetCmdPipe(UCHAR ucOffset_, UCHAR ucReadSize_, UCHAR *pucReadBuffer_, ULONG ulResponseTime_)
- {
- ANT_MESSAGE_ITEM stResponse;
- FS_MESSAGE stMessage;
- // Build the request message
- stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
- stMessage.aucData[0] = (UCHAR)((MESG_FS_ANTFS_GET_CMD_PIPE_ID >> 8) & 0xFF);
- stMessage.aucData[1] = (UCHAR)(MESG_FS_ANTFS_GET_CMD_PIPE_ID & 0xFF);
- stMessage.aucData[2] = ucOffset_;
- stMessage.aucData[3] = ucReadSize_;
- SendFSRequest(MESG_FS_ANTFS_GET_CMD_PIPE_SIZE, &stResponse, stMessage, ulResponseTime_);
- ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
- //Now load pucBuffer_ with the Payload Array
- for(int i = 0; i < ucReadSize_; i++)
- pucReadBuffer_[i] = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD + 1 + i]; //add 1 to skip SizeRead byte
- return stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD ]; //return t
- }
- ///////////////////////////////////////////////////////////////////////
- UCHAR DSIFramerANT::SetCmdPipe(UCHAR ucOffset_, UCHAR ucWriteSize_, const UCHAR *pucWriteBuffer_, ULONG ulResponseTime_)
- {
- ANT_MESSAGE_ITEM stResponse;
- FS_MESSAGE stMessage;
- // Build the request message
- stMessage.ucCommandID = (UCHAR)((MESG_EXT_REQUEST_ID >> 8) & 0xFF);
- stMessage.ucMessageID = (UCHAR)(MESG_EXT_REQUEST_ID & 0xFF);
- stMessage.aucData[0] = (UCHAR)((MESG_FS_ANTFS_SET_CMD_PIPE_ID >> 8) & 0xFF);
- stMessage.aucData[1] = (UCHAR)(MESG_FS_ANTFS_SET_CMD_PIPE_ID & 0xFF);
- stMessage.aucData[2] = ucOffset_;
- stMessage.aucData[3] = ucWriteSize_;
- for(int i = 0; i < ucWriteSize_; i++)
- stMessage.aucData[MESG_FS_ANTFS_SET_CMD_PIPE_SIZE - 1 + i] = pucWriteBuffer_[i];
- SendFSRequest(MESG_FS_ANTFS_SET_CMD_PIPE_SIZE + ucWriteSize_, &stResponse, stMessage, ulResponseTime_);
- ucFSResponse = stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_FSRESPONSE];
- return stResponse.stANTMessage.aucData[OFFSET_REQUEST_RESPONSE_PAYLOAD]; //return the Number of bytes successfully written
- }
- ///////////////////////////////////////////////////////////////////////
- UCHAR DSIFramerANT::GetLastError()
- {
- return ucFSResponse;
- }
|