Library to allo USB PTP device to be hosted by the mbed platform
Dependents: class_project_main
PIMA15740/PIMAArray.h@3:1fcb46ab18df, 2013-08-23 (annotated)
- Committer:
- jakowisp
- Date:
- Fri Aug 23 23:34:05 2013 +0000
- Revision:
- 3:1fcb46ab18df
- Parent:
- 1:71c0e9dc153d
- Child:
- 4:9c6f5867f050
PIMA15740 Sub Folders documented.
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 | 3:1fcb46ab18df | 5 | * @date 8/23/2013 |
jakowisp | 3:1fcb46ab18df | 6 | * |
jakowisp | 3:1fcb46ab18df | 7 | * mbed USBHostPTP Library(PIMA15740 Array definition) |
jakowisp | 3:1fcb46ab18df | 8 | * @par Copyright: |
jakowisp | 3:1fcb46ab18df | 9 | * Copyright (c) 2013 Dwayne Dilbeck |
jakowisp | 3:1fcb46ab18df | 10 | * @par License: |
jakowisp | 3:1fcb46ab18df | 11 | * This software is distributed under the terms of the GNU Lesser General Public License |
jakowisp | 3:1fcb46ab18df | 12 | */ |
jakowisp | 0:98cf19bcd828 | 13 | |
jakowisp | 0:98cf19bcd828 | 14 | /** |
jakowisp | 0:98cf19bcd828 | 15 | * Class PIMA array |
jakowisp | 0:98cf19bcd828 | 16 | * |
jakowisp | 3:1fcb46ab18df | 17 | * The PIMA15740 standard defines an array as an unsigned 32bit number of elements followed by a list |
jakowisp | 3:1fcb46ab18df | 18 | * of insinged 16bit codes; |
jakowisp | 0:98cf19bcd828 | 19 | */ |
jakowisp | 0:98cf19bcd828 | 20 | class PIMAArray { |
jakowisp | 0:98cf19bcd828 | 21 | public: |
jakowisp | 0:98cf19bcd828 | 22 | /** |
jakowisp | 0:98cf19bcd828 | 23 | * Constructor |
jakowisp | 3:1fcb46ab18df | 24 | * @param None |
jakowisp | 0:98cf19bcd828 | 25 | * |
jakowisp | 3:1fcb46ab18df | 26 | * Zeros the number of elements and sets codes pointer to NUll |
jakowisp | 0:98cf19bcd828 | 27 | */ |
jakowisp | 0:98cf19bcd828 | 28 | PIMAArray() { |
jakowisp | 0:98cf19bcd828 | 29 | numberOfElements=0; |
jakowisp | 0:98cf19bcd828 | 30 | codes=NULL; |
jakowisp | 0:98cf19bcd828 | 31 | }; |
jakowisp | 0:98cf19bcd828 | 32 | |
jakowisp | 3:1fcb46ab18df | 33 | /** |
jakowisp | 3:1fcb46ab18df | 34 | * Destructor |
jakowisp | 3:1fcb46ab18df | 35 | * |
jakowisp | 3:1fcb46ab18df | 36 | * Frees assigned storage for codes. |
jakowisp | 3:1fcb46ab18df | 37 | * @param None |
jakowisp | 3:1fcb46ab18df | 38 | */ |
jakowisp | 0:98cf19bcd828 | 39 | ~PIMAArray() { |
jakowisp | 0:98cf19bcd828 | 40 | if( codes !=NULL) |
jakowisp | 0:98cf19bcd828 | 41 | free(codes); |
jakowisp | 0:98cf19bcd828 | 42 | }; |
jakowisp | 0:98cf19bcd828 | 43 | |
jakowisp | 3:1fcb46ab18df | 44 | /** |
jakowisp | 3:1fcb46ab18df | 45 | * Create and fill array storage from a supplied buffer pointer |
jakowisp | 3:1fcb46ab18df | 46 | * |
jakowisp | 3:1fcb46ab18df | 47 | * @param currentPtr a unit8_t pointer to a buffer location where a PIMAArray should be read |
jakowisp | 3:1fcb46ab18df | 48 | * |
jakowisp | 3:1fcb46ab18df | 49 | * @return The number of bytes used from the buffer to create the PIMA array. |
jakowisp | 3:1fcb46ab18df | 50 | */ |
jakowisp | 0:98cf19bcd828 | 51 | int FillArray(uint8_t *currentPtr) { |
jakowisp | 0:98cf19bcd828 | 52 | SetNumberOfElements(*((uint32_t *)currentPtr)); |
jakowisp | 0:98cf19bcd828 | 53 | SetCodes((uint16_t *)(currentPtr+4)); |
jakowisp | 0:98cf19bcd828 | 54 | return (2*numberOfElements) + 4; |
jakowisp | 0:98cf19bcd828 | 55 | } |
jakowisp | 0:98cf19bcd828 | 56 | |
jakowisp | 3:1fcb46ab18df | 57 | ///Number of elelments stored in the array |
jakowisp | 3:1fcb46ab18df | 58 | uint32_t numberOfElements; |
jakowisp | 3:1fcb46ab18df | 59 | ///Pointer to Code storage |
jakowisp | 3:1fcb46ab18df | 60 | uint16_t *codes; |
jakowisp | 3:1fcb46ab18df | 61 | |
jakowisp | 3:1fcb46ab18df | 62 | private: |
jakowisp | 3:1fcb46ab18df | 63 | /** |
jakowisp | 3:1fcb46ab18df | 64 | * Function to allocate array storage space and set the number of elements |
jakowisp | 3:1fcb46ab18df | 65 | * |
jakowisp | 3:1fcb46ab18df | 66 | * @param uint8_t The number of elements to create storage space for. |
jakowisp | 3:1fcb46ab18df | 67 | * @return none |
jakowisp | 3:1fcb46ab18df | 68 | */ |
jakowisp | 0:98cf19bcd828 | 69 | void SetNumberOfElements(uint8_t length) { |
jakowisp | 0:98cf19bcd828 | 70 | this->numberOfElements=length; |
jakowisp | 0:98cf19bcd828 | 71 | if( codes !=NULL) |
jakowisp | 0:98cf19bcd828 | 72 | free(codes); |
jakowisp | 0:98cf19bcd828 | 73 | codes = (uint16_t *) malloc(sizeof(uint16_t)*length); |
jakowisp | 0:98cf19bcd828 | 74 | }; |
jakowisp | 0:98cf19bcd828 | 75 | |
jakowisp | 3:1fcb46ab18df | 76 | /** |
jakowisp | 3:1fcb46ab18df | 77 | * Function to read codes form a uint8t buffer and store them. |
jakowisp | 3:1fcb46ab18df | 78 | * @param buffer pointer to a uint8_t buffer |
jakowisp | 3:1fcb46ab18df | 79 | */ |
jakowisp | 0:98cf19bcd828 | 80 | void SetCodes(uint16_t *buffer){ |
jakowisp | 0:98cf19bcd828 | 81 | if(buffer!=NULL && codes !=NULL) |
jakowisp | 0:98cf19bcd828 | 82 | for(int i=0;i<this->numberOfElements;i++) |
jakowisp | 0:98cf19bcd828 | 83 | codes[i]=buffer[i]; |
jakowisp | 0:98cf19bcd828 | 84 | }; |
jakowisp | 0:98cf19bcd828 | 85 | |
jakowisp | 0:98cf19bcd828 | 86 | }; |
jakowisp | 1:71c0e9dc153d | 87 | |
jakowisp | 3:1fcb46ab18df | 88 |