Library to allo USB PTP device to be hosted by the mbed platform
Dependents: class_project_main
Revision 7:c3a16a61643f, committed 2013-08-29
- Comitter:
- jakowisp
- Date:
- Thu Aug 29 23:59:17 2013 +0000
- Parent:
- 6:124a01eaf569
- Child:
- 8:5f6024e68aa7
- Commit message:
- Fixed issue where previous fix got lost in reponse container handling when included in data transfer.
;
Changed in this revision
USBHostPTP.cpp | Show annotated file Show diff for this revision Revisions of this file |
USBHostPTP.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/USBHostPTP.cpp Thu Aug 29 19:19:37 2013 +0000 +++ b/USBHostPTP.cpp Thu Aug 29 23:59:17 2013 +0000 @@ -1,7 +1,17 @@ -/* mbed USBHostPTP Library - * Copyright (c) 2013 Dwayne Dilbeck - * This software is distributed under the terms of the GNU Lesser General Public License - */ +/** +* @file USBHostPTP.cpp +* @brief USBHostPTP class function definitions +* @author Dwayne Dilbeck +* @date 8/23/2013 +* +* mbed USBHostPTP Library +* +* @par Copyright: +* Copyright (c) 2013 Dwayne Dilbeck +* @par License: +* This software is distributed under the terms of the GNU Lesser General Public License +*/ + #include "USBHostPTP.h" @@ -34,6 +44,7 @@ commandContainer.type = PIMA_CONTAINER_COMMAND; sessionID = 1; dataLeftToTransfer = 0; + memset(buffer,0,1024); } @@ -237,8 +248,10 @@ DataHandler dataHandler1 = (DataHandler) dataHandlerFunctionCastToVoid; - if( responseCode!=NULL) - *responseCode= PIMA_RETURN_CODE_Undefined; + if( responseCode==NULL) + return false; + + *responseCode=PIMA_RETURN_CODE_Undefined; do { ///TODO: Magic number needs to be replaced with DEFINE @@ -300,6 +313,8 @@ pointerToUint8tData[i]=buffer[bytesRemaining+i]; } *responseCode = responseContainer.code; + bytesRemaining=0; + } else { return false; } @@ -348,21 +363,12 @@ } } transferResult = host->bulkRead(pointerToDevice, bulk_in,(uint8_t *)&responseContainer, sizeof(responseContainer)); + #ifdef USDBPTPDEBUG + printf("Response bulkRead result: %d\r\n",transferResult); + DumpResponseContainer(); + #endif if (checkResult(transferResult, bulk_in)) return PIMA_RETURN_CODE_GeneralError; - #ifdef USDBPTPDEBUG - printf("Response bulkRead result: %d\r\n",transferResult); - printf("PTPResponseContainer:\r\n"); - DumpBuffer((uint8_t *)&responseContainer,responseContainer.len); - if (responseContainer.opcode==PIMA_RETURN_CODE_OK) { - printf("PIMA_RETURN_CODE_OK\r\n"); - } else { - printf("Response Length: %x\r\n",responseContainer.len); - printf("Response type: %x\r\n",responseContainer.type); - printf("Response code: %x\r\n",responseContainer.opcode); - printf("Response ID: %d\r\n",responseContainer.TransactionID); - } - #endif return responseContainer.code; } @@ -446,6 +452,8 @@ params[0] = handle; //Clear any previous data, incase a Reponse packet is returned instead of a data packet + ///TODO:Magic number issue + //No buffer overun issue: See ParseObjectInfoDataBlock memset((uint8_t *)&objectInfo,0,0x34); return Transaction(PIMA_OPERATION_CODE_GetObjectInfo, &flags, params, (void*)&USBHostPTP::ParseObjectInfoDataBlock); @@ -683,11 +691,15 @@ } void USBHostPTP::ParseObjectInfoDataBlock(void *ptp,uint8_t *buffer,uint16_t length){ + //TEST: PASS + // iterated thru getObjectInfo for all 789 objects on phone in a loop 200 times + // memory dumps show no buffer over runs on objectInfo uint8_t *ptr,*structptr; USBHostPTP *obj=(USBHostPTP *)ptp; structptr=(uint8_t *) &(obj->objectInfo); ptr=buffer; + ////TODO: MAGIC number issue for(int i=0;i<0x34;i++) structptr[i]=ptr[i]; ptr+=0x34; @@ -820,8 +832,21 @@ printf("%s\r\n",objectInfo.keywords.getString()); } +void USBHostPTP::DumpResponseContainer(){ + printf("PTPResponseContainer:\r\n"); + this->DumpBuffer((uint8_t *)&responseContainer,responseContainer.length); + if (responseContainer.code==PIMA_RETURN_CODE_OK) { + printf("PIMA_RETURN_CODE_OK\r\n"); + } else { + printf("Response Length: %x\r\n",responseContainer.length); + printf("Response type: %x\r\n",responseContainer.type); + printf("Response code: %x\r\n",responseContainer.code); + printf("Response ID: %d\r\n",responseContainer.transactionID); + } +} #endif +
--- a/USBHostPTP.h Thu Aug 29 19:19:37 2013 +0000 +++ b/USBHostPTP.h Thu Aug 29 23:59:17 2013 +0000 @@ -346,17 +346,19 @@ */ void DumpObjectInfo(void); PIMAContainer dataContainer; + + //This is a generic function should belong to some other class or namespance. + void DumpBuffer(uint8_t *buffer,uint32_t length); -protected: +//protected: //From IUSBEnumerator virtual void setVidPid(uint16_t vid, uint16_t pid); virtual bool parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol); //Must return true if the interface should be parsed virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used - //This is a generic function should belong to some other class or namespance. - void DumpBuffer(uint8_t *buffer,uint32_t length); + void DumpResponseContainer(void); -private: +//private: USBHost * host; USBDeviceConnected * pointerToDevice; bool deviceFound;