Library to allo USB PTP device to be hosted by the mbed platform
Dependents: class_project_main
PIMA15740/PIMAArray.h@0:98cf19bcd828, 2013-08-23 (annotated)
- Committer:
- jakowisp
- Date:
- Fri Aug 23 00:52:52 2013 +0000
- Revision:
- 0:98cf19bcd828
- Child:
- 1:71c0e9dc153d
Fix for a buffer overrun and refactored the Tranactoion code.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jakowisp | 0:98cf19bcd828 | 1 | |
jakowisp | 0:98cf19bcd828 | 2 | #include "mallocdebug.h" |
jakowisp | 0:98cf19bcd828 | 3 | |
jakowisp | 0:98cf19bcd828 | 4 | /** |
jakowisp | 0:98cf19bcd828 | 5 | * Class PIMA array |
jakowisp | 0:98cf19bcd828 | 6 | * |
jakowisp | 0:98cf19bcd828 | 7 | * |
jakowisp | 0:98cf19bcd828 | 8 | * |
jakowisp | 0:98cf19bcd828 | 9 | */ |
jakowisp | 0:98cf19bcd828 | 10 | class PIMAArray { |
jakowisp | 0:98cf19bcd828 | 11 | public: |
jakowisp | 0:98cf19bcd828 | 12 | /** |
jakowisp | 0:98cf19bcd828 | 13 | * Constructor |
jakowisp | 0:98cf19bcd828 | 14 | * @params: None |
jakowisp | 0:98cf19bcd828 | 15 | * |
jakowisp | 0:98cf19bcd828 | 16 | */ |
jakowisp | 0:98cf19bcd828 | 17 | PIMAArray() { |
jakowisp | 0:98cf19bcd828 | 18 | numberOfElements=0; |
jakowisp | 0:98cf19bcd828 | 19 | codes=NULL; |
jakowisp | 0:98cf19bcd828 | 20 | }; |
jakowisp | 0:98cf19bcd828 | 21 | |
jakowisp | 0:98cf19bcd828 | 22 | ~PIMAArray() { |
jakowisp | 0:98cf19bcd828 | 23 | if( codes !=NULL) |
jakowisp | 0:98cf19bcd828 | 24 | free(codes); |
jakowisp | 0:98cf19bcd828 | 25 | }; |
jakowisp | 0:98cf19bcd828 | 26 | |
jakowisp | 0:98cf19bcd828 | 27 | int FillArray(uint8_t *currentPtr) { |
jakowisp | 0:98cf19bcd828 | 28 | SetNumberOfElements(*((uint32_t *)currentPtr)); |
jakowisp | 0:98cf19bcd828 | 29 | SetCodes((uint16_t *)(currentPtr+4)); |
jakowisp | 0:98cf19bcd828 | 30 | return (2*numberOfElements) + 4; |
jakowisp | 0:98cf19bcd828 | 31 | } |
jakowisp | 0:98cf19bcd828 | 32 | |
jakowisp | 0:98cf19bcd828 | 33 | void SetNumberOfElements(uint8_t length) { |
jakowisp | 0:98cf19bcd828 | 34 | this->numberOfElements=length; |
jakowisp | 0:98cf19bcd828 | 35 | if( codes !=NULL) |
jakowisp | 0:98cf19bcd828 | 36 | free(codes); |
jakowisp | 0:98cf19bcd828 | 37 | codes = (uint16_t *) malloc(sizeof(uint16_t)*length); |
jakowisp | 0:98cf19bcd828 | 38 | }; |
jakowisp | 0:98cf19bcd828 | 39 | |
jakowisp | 0:98cf19bcd828 | 40 | void SetCodes(uint16_t *buffer){ |
jakowisp | 0:98cf19bcd828 | 41 | if(buffer!=NULL && codes !=NULL) |
jakowisp | 0:98cf19bcd828 | 42 | for(int i=0;i<this->numberOfElements;i++) |
jakowisp | 0:98cf19bcd828 | 43 | codes[i]=buffer[i]; |
jakowisp | 0:98cf19bcd828 | 44 | }; |
jakowisp | 0:98cf19bcd828 | 45 | |
jakowisp | 0:98cf19bcd828 | 46 | uint32_t numberOfElements; |
jakowisp | 0:98cf19bcd828 | 47 | uint16_t *codes; |
jakowisp | 0:98cf19bcd828 | 48 | }; |