Library to allo USB PTP device to be hosted by the mbed platform
Dependents: class_project_main
PIMA15740/PIMAArray.h@11:3b072cf16df8, 2013-10-07 (annotated)
- Committer:
- jakowisp
- Date:
- Mon Oct 07 04:45:55 2013 +0000
- Revision:
- 11:3b072cf16df8
- Parent:
- 10:fc1cb68fc91e
Add code for Property description download.; Add code decoder logic.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jakowisp | 3:1fcb46ab18df | 1 | /** |
jakowisp | 3:1fcb46ab18df | 2 | * @file PIMAArray.h |
jakowisp | 3:1fcb46ab18df | 3 | * @brief PIMA Array class definition |
jakowisp | 3:1fcb46ab18df | 4 | * @author Dwayne Dilbeck |
jakowisp | 10:fc1cb68fc91e | 5 | * @date 9/16/2013 |
jakowisp | 3:1fcb46ab18df | 6 | * |
jakowisp | 3:1fcb46ab18df | 7 | * mbed USBHostPTP Library(PIMA15740 Array definition) |
jakowisp | 4:9c6f5867f050 | 8 | * |
jakowisp | 3:1fcb46ab18df | 9 | * @par Copyright: |
jakowisp | 3:1fcb46ab18df | 10 | * Copyright (c) 2013 Dwayne Dilbeck |
jakowisp | 3:1fcb46ab18df | 11 | * @par License: |
jakowisp | 3:1fcb46ab18df | 12 | * This software is distributed under the terms of the GNU Lesser General Public License |
jakowisp | 3:1fcb46ab18df | 13 | */ |
jakowisp | 0:98cf19bcd828 | 14 | |
jakowisp | 0:98cf19bcd828 | 15 | /** |
jakowisp | 0:98cf19bcd828 | 16 | * Class PIMA array |
jakowisp | 0:98cf19bcd828 | 17 | * |
jakowisp | 3:1fcb46ab18df | 18 | * The PIMA15740 standard defines an array as an unsigned 32bit number of elements followed by a list |
jakowisp | 3:1fcb46ab18df | 19 | * of insinged 16bit codes; |
jakowisp | 0:98cf19bcd828 | 20 | */ |
jakowisp | 10:fc1cb68fc91e | 21 | template <class TYPE> |
jakowisp | 0:98cf19bcd828 | 22 | class PIMAArray { |
jakowisp | 0:98cf19bcd828 | 23 | public: |
jakowisp | 0:98cf19bcd828 | 24 | /** |
jakowisp | 0:98cf19bcd828 | 25 | * Constructor |
jakowisp | 3:1fcb46ab18df | 26 | * @param None |
jakowisp | 0:98cf19bcd828 | 27 | * |
jakowisp | 3:1fcb46ab18df | 28 | * Zeros the number of elements and sets codes pointer to NUll |
jakowisp | 0:98cf19bcd828 | 29 | */ |
jakowisp | 0:98cf19bcd828 | 30 | PIMAArray() { |
jakowisp | 0:98cf19bcd828 | 31 | numberOfElements=0; |
jakowisp | 10:fc1cb68fc91e | 32 | elements=NULL; |
jakowisp | 0:98cf19bcd828 | 33 | }; |
jakowisp | 0:98cf19bcd828 | 34 | |
jakowisp | 3:1fcb46ab18df | 35 | /** |
jakowisp | 3:1fcb46ab18df | 36 | * Destructor |
jakowisp | 3:1fcb46ab18df | 37 | * |
jakowisp | 3:1fcb46ab18df | 38 | * Frees assigned storage for codes. |
jakowisp | 3:1fcb46ab18df | 39 | * @param None |
jakowisp | 3:1fcb46ab18df | 40 | */ |
jakowisp | 0:98cf19bcd828 | 41 | ~PIMAArray() { |
jakowisp | 10:fc1cb68fc91e | 42 | if( elements !=NULL) |
jakowisp | 10:fc1cb68fc91e | 43 | free(elements); |
jakowisp | 0:98cf19bcd828 | 44 | }; |
jakowisp | 0:98cf19bcd828 | 45 | |
jakowisp | 3:1fcb46ab18df | 46 | /** |
jakowisp | 3:1fcb46ab18df | 47 | * Create and fill array storage from a supplied buffer pointer |
jakowisp | 3:1fcb46ab18df | 48 | * |
jakowisp | 3:1fcb46ab18df | 49 | * @param currentPtr a unit8_t pointer to a buffer location where a PIMAArray should be read |
jakowisp | 3:1fcb46ab18df | 50 | * |
jakowisp | 3:1fcb46ab18df | 51 | * @return The number of bytes used from the buffer to create the PIMA array. |
jakowisp | 3:1fcb46ab18df | 52 | */ |
jakowisp | 10:fc1cb68fc91e | 53 | |
jakowisp | 11:3b072cf16df8 | 54 | unsigned int FillArray(uint8_t *initialPtr) { |
jakowisp | 11:3b072cf16df8 | 55 | uint8_t *currentPtr=initialPtr; |
jakowisp | 11:3b072cf16df8 | 56 | |
jakowisp | 11:3b072cf16df8 | 57 | currentPtr+=SetNumberOfElements(*((uint32_t *)currentPtr)); |
jakowisp | 11:3b072cf16df8 | 58 | currentPtr+=SetElements((uint8_t *)(currentPtr)); |
jakowisp | 11:3b072cf16df8 | 59 | return (currentPtr-initialPtr); |
jakowisp | 10:fc1cb68fc91e | 60 | } |
jakowisp | 10:fc1cb68fc91e | 61 | |
jakowisp | 10:fc1cb68fc91e | 62 | TYPE GetElement(uint32_t index) { |
jakowisp | 10:fc1cb68fc91e | 63 | return elements[index]; |
jakowisp | 10:fc1cb68fc91e | 64 | } |
jakowisp | 10:fc1cb68fc91e | 65 | |
jakowisp | 10:fc1cb68fc91e | 66 | bool CheckValueInArray(TYPE value) { |
jakowisp | 10:fc1cb68fc91e | 67 | bool res=false; |
jakowisp | 10:fc1cb68fc91e | 68 | for(int i=0; i<numberOfElements;i++) |
jakowisp | 10:fc1cb68fc91e | 69 | if(value == elements[i]) |
jakowisp | 10:fc1cb68fc91e | 70 | res=true; |
jakowisp | 10:fc1cb68fc91e | 71 | return res; |
jakowisp | 10:fc1cb68fc91e | 72 | } |
jakowisp | 10:fc1cb68fc91e | 73 | |
jakowisp | 0:98cf19bcd828 | 74 | |
jakowisp | 3:1fcb46ab18df | 75 | ///Number of elelments stored in the array |
jakowisp | 3:1fcb46ab18df | 76 | uint32_t numberOfElements; |
jakowisp | 10:fc1cb68fc91e | 77 | ///Pointer to elements storage |
jakowisp | 10:fc1cb68fc91e | 78 | TYPE *elements; |
jakowisp | 10:fc1cb68fc91e | 79 | |
jakowisp | 3:1fcb46ab18df | 80 | private: |
jakowisp | 3:1fcb46ab18df | 81 | /** |
jakowisp | 3:1fcb46ab18df | 82 | * Function to allocate array storage space and set the number of elements |
jakowisp | 3:1fcb46ab18df | 83 | * |
jakowisp | 3:1fcb46ab18df | 84 | * @param uint8_t The number of elements to create storage space for. |
jakowisp | 3:1fcb46ab18df | 85 | * @return none |
jakowisp | 3:1fcb46ab18df | 86 | */ |
jakowisp | 11:3b072cf16df8 | 87 | unsigned int SetNumberOfElements(uint8_t length) { |
jakowisp | 0:98cf19bcd828 | 88 | this->numberOfElements=length; |
jakowisp | 10:fc1cb68fc91e | 89 | if( elements !=NULL) |
jakowisp | 10:fc1cb68fc91e | 90 | free(elements); |
jakowisp | 10:fc1cb68fc91e | 91 | elements = (TYPE *) malloc(sizeof(TYPE)*length); |
jakowisp | 11:3b072cf16df8 | 92 | return sizeof(uint32_t); |
jakowisp | 0:98cf19bcd828 | 93 | }; |
jakowisp | 0:98cf19bcd828 | 94 | |
jakowisp | 3:1fcb46ab18df | 95 | /** |
jakowisp | 3:1fcb46ab18df | 96 | * Function to read codes form a uint8t buffer and store them. |
jakowisp | 3:1fcb46ab18df | 97 | * @param buffer pointer to a uint8_t buffer |
jakowisp | 3:1fcb46ab18df | 98 | */ |
jakowisp | 11:3b072cf16df8 | 99 | unsigned int SetElements(uint8_t *buffer){ |
jakowisp | 11:3b072cf16df8 | 100 | TYPE *castPtr = (TYPE *)buffer; |
jakowisp | 11:3b072cf16df8 | 101 | if(castPtr!=NULL && elements !=NULL) |
jakowisp | 0:98cf19bcd828 | 102 | for(int i=0;i<this->numberOfElements;i++) |
jakowisp | 11:3b072cf16df8 | 103 | elements[i]=castPtr[i]; |
jakowisp | 11:3b072cf16df8 | 104 | return (sizeof(elements[0])*numberOfElements); |
jakowisp | 0:98cf19bcd828 | 105 | }; |
jakowisp | 0:98cf19bcd828 | 106 | |
jakowisp | 0:98cf19bcd828 | 107 | }; |