Library to allo USB PTP device to be hosted by the mbed platform

Dependents:   class_project_main

Revision:
7:c3a16a61643f
Parent:
6:124a01eaf569
Child:
8:5f6024e68aa7
--- 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
 
 
+