Library to allo USB PTP device to be hosted by the mbed platform
Dependents: class_project_main
PIMA15740/PIMAArray.h
- Committer:
- jakowisp
- Date:
- 2013-08-28
- Revision:
- 4:9c6f5867f050
- Parent:
- 3:1fcb46ab18df
- Child:
- 10:fc1cb68fc91e
File content as of revision 4:9c6f5867f050:
/** * @file PIMAArray.h * @brief PIMA Array class definition * @author Dwayne Dilbeck * @date 8/23/2013 * * mbed USBHostPTP Library(PIMA15740 Array definition) * * @par Copyright: * Copyright (c) 2013 Dwayne Dilbeck * @par License: * This software is distributed under the terms of the GNU Lesser General Public License */ /** * Class PIMA array * * The PIMA15740 standard defines an array as an unsigned 32bit number of elements followed by a list * of insinged 16bit codes; */ class PIMAArray { public: /** * Constructor * @param None * * Zeros the number of elements and sets codes pointer to NUll */ PIMAArray() { numberOfElements=0; codes=NULL; }; /** * Destructor * * Frees assigned storage for codes. * @param None */ ~PIMAArray() { if( codes !=NULL) free(codes); }; /** * Create and fill array storage from a supplied buffer pointer * * @param currentPtr a unit8_t pointer to a buffer location where a PIMAArray should be read * * @return The number of bytes used from the buffer to create the PIMA array. */ int FillArray(uint8_t *currentPtr) { SetNumberOfElements(*((uint32_t *)currentPtr)); SetCodes((uint16_t *)(currentPtr+4)); return (2*numberOfElements) + 4; } ///Number of elelments stored in the array uint32_t numberOfElements; ///Pointer to Code storage uint16_t *codes; private: /** * Function to allocate array storage space and set the number of elements * * @param uint8_t The number of elements to create storage space for. * @return none */ void SetNumberOfElements(uint8_t length) { this->numberOfElements=length; if( codes !=NULL) free(codes); codes = (uint16_t *) malloc(sizeof(uint16_t)*length); }; /** * Function to read codes form a uint8t buffer and store them. * @param buffer pointer to a uint8_t buffer */ void SetCodes(uint16_t *buffer){ if(buffer!=NULL && codes !=NULL) for(int i=0;i<this->numberOfElements;i++) codes[i]=buffer[i]; }; };