Library to allo USB PTP device to be hosted by the mbed platform
Dependents: class_project_main
Revision 10:fc1cb68fc91e, committed 2013-09-18
- Comitter:
- jakowisp
- Date:
- Wed Sep 18 01:48:07 2013 +0000
- Parent:
- 9:961c3357504d
- Child:
- 11:3b072cf16df8
- Commit message:
- Adding DST code;
Changed in this revision
--- a/PIMA15740/PIMA15740_types.h Tue Sep 10 07:40:44 2013 +0000 +++ b/PIMA15740/PIMA15740_types.h Wed Sep 18 01:48:07 2013 +0000 @@ -15,6 +15,7 @@ #include "PIMAconst.h" #include "PIMAArray.h" #include "PIMAString.h" +#include "PIMAPropDescr.h" /** @struct PIMAContainer * PIMA 15740:2000 standard Appendix D.7.1.1 @@ -34,11 +35,11 @@ uint16_t vendorExtensionVersion; PIMAString vendorExtensionDesc; uint16_t functionMode; - PIMAArray operationsSupported; - PIMAArray eventsSupported; - PIMAArray devicePropertiesSupported; - PIMAArray captureFormats; - PIMAArray imageFormats; + PIMAArray<uint16_t> operationsSupported; + PIMAArray<uint16_t> eventsSupported; + PIMAArray<uint16_t> devicePropertiesSupported; + PIMAArray<uint16_t> captureFormats; + PIMAArray<uint16_t> imageFormats; PIMAString manufacturer; PIMAString model; PIMAString deviceVersion;
--- a/PIMA15740/PIMAArray.h Tue Sep 10 07:40:44 2013 +0000 +++ b/PIMA15740/PIMAArray.h Wed Sep 18 01:48:07 2013 +0000 @@ -2,7 +2,7 @@ * @file PIMAArray.h * @brief PIMA Array class definition * @author Dwayne Dilbeck -* @date 8/23/2013 +* @date 9/16/2013 * * mbed USBHostPTP Library(PIMA15740 Array definition) * @@ -18,6 +18,7 @@ * The PIMA15740 standard defines an array as an unsigned 32bit number of elements followed by a list * of insinged 16bit codes; */ +template <class TYPE> class PIMAArray { public: /** @@ -28,7 +29,7 @@ */ PIMAArray() { numberOfElements=0; - codes=NULL; + elements=NULL; }; /** @@ -38,8 +39,8 @@ * @param None */ ~PIMAArray() { - if( codes !=NULL) - free(codes); + if( elements !=NULL) + free(elements); }; /** @@ -49,17 +50,31 @@ * * @return The number of bytes used from the buffer to create the PIMA array. */ - int FillArray(uint8_t *currentPtr) { + + int FillArray(uint8_t *currentPtr) { SetNumberOfElements(*((uint32_t *)currentPtr)); - SetCodes((uint16_t *)(currentPtr+4)); - return (2*numberOfElements) + 4; -} + SetElements((TYPE *)(currentPtr+sizeof(uint32_t))); + return (sizeof(TYPE)*numberOfElements) + sizeof(uint32_t); + } + + TYPE GetElement(uint32_t index) { + return elements[index]; + } + + bool CheckValueInArray(TYPE value) { + bool res=false; + for(int i=0; i<numberOfElements;i++) + if(value == elements[i]) + res=true; + return res; + } + ///Number of elelments stored in the array uint32_t numberOfElements; - ///Pointer to Code storage - uint16_t *codes; - + ///Pointer to elements storage + TYPE *elements; + private: /** * Function to allocate array storage space and set the number of elements @@ -69,21 +84,19 @@ */ void SetNumberOfElements(uint8_t length) { this->numberOfElements=length; - if( codes !=NULL) - free(codes); - codes = (uint16_t *) malloc(sizeof(uint16_t)*length); + if( elements !=NULL) + free(elements); + elements = (TYPE *) malloc(sizeof(TYPE)*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) + void SetElements(uint16_t *buffer){ + if(buffer!=NULL && elements !=NULL) for(int i=0;i<this->numberOfElements;i++) - codes[i]=buffer[i]; + elements[i]=buffer[i]; }; }; - -
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PIMA15740/PIMADTS.h Wed Sep 18 01:48:07 2013 +0000 @@ -0,0 +1,30 @@ +/* + typedef DTS union { + int8_t signed8bitInt; //0x0001 + uint8_t unsigned8bitint; //0x0002 + int16_t signed16bitInt; //0x0003 + uint16_t unsigned16bitint; //0x0004 + int32_t signed32bitInt; //0x0005 + uint32_t unsigned32bitint; //0x0006 + int64_t signed32bitInt; //0x0007 + uint64_t unsigned32bitint; //0x0008 + int128_t signed32bitInt; //0x0009 + uint128_t unsigned32bitint; //0x000a + aint8_t arraysigned8bitInt; //0x4001 + auint8_t arrayunsigned8bitint; //0x4002 + aint16_t arraysigned16bitInt; //0x4003 + auint16_t arrayunsigned16bitint; //0x4004 + aint32_t arraysigned32bitInt; //0x4005 + auint32_t arrayunsigned32bitint; //0x4006 + aint64_t arraysigned32bitInt; //0x4007 + auint64_t arrayunsigned32bitint; //0x4008 + aint128_t arraysigned32bitInt; //0x4009 + auint128_t arrayunsigned32bitint; //0x400a + PIMAString stringValue; //0xffff + }; */ + +template <class TYPE> +class DTS { +private: + TYPE value; +};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PIMA15740/PIMAPropDescr.h Wed Sep 18 01:48:07 2013 +0000 @@ -0,0 +1,144 @@ +/** +* @file PIMAPropDesc.h +* @brief PIMA Property Description class definition +* @author Dwayne Dilbeck +* @date 9/16/2013 +* +* mbed USBHostPTP Library(PIMA15740 String definition) +* @par Copyright: +* Copyright (c) 2013 Dwayne Dilbeck +* @par License: +* This software is distributed under the terms of the GNU Lesser General Public License +*/ +#include "PIMADTS.h" + +/** +* Class Property Description +* +* The PIMA15740 standard defines +* +*/ +class PIMAPropDesc { +public: + + + + int FillPropDesc(uint8_t *currentPtr) { + devicePropertyCode = *((uint16_t *)currentPtr); + dataType = *((uint16_t *)(currentPtr+sizeof(uint16_t))); + getSet=*((uint8_t *)(currentPtr+2*sizeof(uint16_t))); + switch(dataType) { + case PIMA_DATATYPE_CODE_INT8: + factoryDefault.ptri8 = new DTS<int8_t>; + currentValue.ptri8 = new DTS<int8_t>; + break; + case PIMA_DATATYPE_CODE_UINT8: + factoryDefault.ptru8 = new DTS<uint8_t>; + currentValue.ptru8 = new DTS<uint8_t>; + break; + case PIMA_DATATYPE_CODE_INT16: + factoryDefault.ptri16 = new DTS<int16_t>; + currentValue.ptri16 = new DTS<int16_t>; + break; + case PIMA_DATATYPE_CODE_UINT16: + factoryDefault.ptru16 = new DTS<uint16_t>; + currentValue.ptru16 = new DTS<uint16_t>; + break; + case PIMA_DATATYPE_CODE_INT32: + factoryDefault.ptri32 = new DTS<int32_t>; + currentValue.ptri32 = new DTS<int32_t>; + break; + case PIMA_DATATYPE_CODE_UINT32: + factoryDefault.ptru32 = new DTS<uint32_t>; + currentValue.ptru32 = new DTS<uint32_t>; + break; + case PIMA_DATATYPE_CODE_INT64: + factoryDefault.ptri64 = new DTS<int64_t>; + currentValue.ptri64 = new DTS<int64_t>; + break; + case PIMA_DATATYPE_CODE_UINT64: + factoryDefault.ptru64 = new DTS<uint64_t>; + currentValue.ptru64 = new DTS<uint64_t>; + break; + case PIMA_DATATYPE_CODE_INT128: + break; + case PIMA_DATATYPE_CODE_UINT128: + break; + case PIMA_DATATYPE_CODE_AINT8: + factoryDefault.ptri8 = new PIMAArray<int8_t>; + currentValue.ptri8 = new PIMAArray<int8_t>; + break; + case PIMA_DATATYPE_CODE_AUINT8: + factoryDefault.ptri8 = new PIMAArray<uint8_t> ; + currentValue.ptri8 = new PIMAArray<uint8_t>; + break; + case PIMA_DATATYPE_CODE_AINT16: + factoryDefault.ptri8 = new DTS<PIMAArray<int8_t> >; + currentValue.ptri8 = new DTS<PIMAArray<int8_t> >; + break; + case PIMA_DATATYPE_CODE_AUINT16: + factoryDefault.ptri8 = new DTS<PIMAArray<int8_t> >; + currentValue.ptri8 = new DTS<PIMAArray<int8_t> >; + break; + case PIMA_DATATYPE_CODE_AINT32: + factoryDefault.ptri8 = new DTS<PIMAArray<int8_t> >; + currentValue.ptri8 = new DTS<PIMAArray<int8_t> >; + break; + case PIMA_DATATYPE_CODE_AUINT32: + factoryDefault.ptri8 = new DTS<PIMAArray<int8_t> >; + currentValue.ptri8 = new DTS<PIMAArray<int8_t> >; + break; + case PIMA_DATATYPE_CODE_AINT64: + factoryDefault.ptri8 = new DTS<PIMAArray<int8_t> >; + currentValue.ptri8 = new DTS<PIMAArray<int8_t> >; + break; + case PIMA_DATATYPE_CODE_AUINT64: + factoryDefault.ptri8 = new DTS<PIMAArray<int8_t> >; + currentValue.ptri8 = new DTS<PIMAArray<int8_t> >; + break; + case PIMA_DATATYPE_CODE_AINT128: + break; + case PIMA_DATATYPE_CODE_AUINT128: + break; + case PIMA_DATATYPE_CODE_STR: + factoryDefault.ptri8 = new DTS<PIMAString>; + currentValue.ptri8 = new DTS<PIMAString>; + break; + default: + break; + } + factoryDefault.fill(currentPtr); + currentValue.fill(currentPtr); + //(sizeof(TYPE)*numberOfElements) + + return (sizeof(uint32_t)); //TODO: Finish Fill function. + } + +private: + ///PIMA 15740:2000 Section 13, table 23 + uint16_t devicePropertyCode; + uint16_t dataType; + uint8_t getSet; + typedef union DTSPTR { + DTS<int8_t> *ptri8; + DTS<uint8_t> *ptru8; + DTS<int16_t> *ptri16; + DTS<uint16_t> *ptru16; + DTS<int32_t> *ptri32; + DTS<uint32_t> *ptru32; + DTS<int64_t> *ptri64; + DTS<uint64_t> *ptru64; + } DTSPTR; + DTSPTR factoryDefault; + DTSPTR currentValue; + + uint8_t formFlag; + typedef union { + struct { + DTSPTR minimumValue; + DTSPTR maximumValue; + DTSPTR stepSize; + } rangeForm; + DTSPTR enumerationForm; + } FORMS; + FORMS FORM; +};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PIMA15740/uint128_t..h Wed Sep 18 01:48:07 2013 +0000 @@ -0,0 +1,600 @@ +/* +uint128_t.h +An unsigned 128 bit integer library for C++ +By Jason Lee @ calccrypto@yahoo.com +with much help from Auston Sterling + +And thanks to Stefan Deigmüller for finding +a bug in operator*. +*/ + +#ifndef UINT128_T_H +#define UINT128_T_H + +#include <cstdlib> +#include <iostream> +#include <stdint.h> + +class uint128_t{ + private: + uint64_t UPPER, LOWER; + + public: + // Constructors + uint128_t(){ + UPPER = 0; + LOWER = 0; + } + + template <typename T> + uint128_t(T rhs){ + UPPER = 0; + LOWER = (uint64_t) rhs; + } + + template <typename S, typename T> + uint128_t(const S upper_rhs, const T lower_rhs){ + UPPER = (uint64_t) upper_rhs; + LOWER = (uint64_t) lower_rhs; + } + + uint128_t(const uint128_t & rhs){ + UPPER = rhs.UPPER; + LOWER = rhs.LOWER; + } + + // RHS input args only + + // Assignment Operator + template <typename T> uint128_t operator=(T rhs){ + UPPER = 0; + LOWER = (uint64_t) rhs; + return *this; + } + + uint128_t operator=(uint128_t rhs){ + UPPER = rhs.UPPER; + LOWER = rhs.LOWER; + return *this; + } + + // Typecast Operators + operator bool(){ + return (bool) (UPPER | LOWER); + } + + operator char(){ + return (char) LOWER; + } + + operator int(){ + return (int) LOWER; + } + + operator uint8_t(){ + return (uint8_t) LOWER; + } + + operator uint16_t(){ + return (uint16_t) LOWER; + } + + operator uint32_t(){ + return (uint32_t) LOWER; + } + + operator uint64_t(){ + return LOWER; + } + + // Bitwise Operators + template <typename T> uint128_t operator&(T rhs){ + return uint128_t(0, LOWER & (uint64_t) rhs); + } + + uint128_t operator&(uint128_t rhs){ + return uint128_t(UPPER & rhs.UPPER, LOWER & rhs.LOWER); + } + + template <typename T> uint128_t operator|(T rhs){ + return uint128_t(UPPER, LOWER | (uint64_t) rhs); + } + + uint128_t operator|(uint128_t rhs){ + return uint128_t(UPPER | rhs.UPPER, LOWER | rhs.LOWER); + } + + template <typename T> uint128_t operator^(T rhs){ + return uint128_t(UPPER, LOWER ^ (uint64_t) rhs); + } + + uint128_t operator^(uint128_t rhs){ + return uint128_t(UPPER ^ rhs.UPPER, LOWER ^ rhs.LOWER); + } + + template <typename T> uint128_t operator&=(T rhs){ + UPPER = 0; + LOWER &= rhs; + return *this; + } + + uint128_t operator&=(uint128_t rhs){ + UPPER &= rhs.UPPER; + LOWER &= rhs.LOWER; + return *this; + } + + template <typename T> uint128_t operator|=(T rhs){ + LOWER |= (uint64_t) rhs; + return *this; + } + + uint128_t operator|=(uint128_t rhs){ + UPPER |= rhs.UPPER; + LOWER |= rhs.LOWER; + return *this; + } + + template <typename T> uint128_t operator^=(T rhs){ + LOWER ^= (uint64_t) rhs; + return *this; + } + + uint128_t operator^=(const uint128_t rhs){ + UPPER ^= rhs.UPPER; + LOWER ^= rhs.LOWER; + return *this; + } + + uint128_t operator~(){ + return uint128_t(~UPPER, ~LOWER); + } + + // Bit Shift Operators + template <typename T> + uint128_t operator<<(const T shift){ + if (shift >= 128) + return uint128_t(0, 0); + else if (shift == 64) + return uint128_t(LOWER, 0); + else if (shift == 0) + return *this; + else if (shift < 64) + return uint128_t((UPPER << shift) + (LOWER >> (64 - shift)), LOWER << shift); + else if ((128 > shift) && (shift > 64)) + return uint128_t(LOWER << (shift - 64), 0); + else + return uint128_t(0); + } + + template <typename T> + uint128_t operator>>(const T shift){ + if (shift >= 128) + return uint128_t(0, 0); + else if (shift == 64) + return uint128_t(0, UPPER); + else if (shift == 0) + return *this; + else if (shift < 64) + return uint128_t(UPPER >> shift, (UPPER << (64 - shift)) + (LOWER >> shift)); + else if ((128 > shift) && (shift > 64)) + return uint128_t(0, (UPPER >> (shift - 64))); + else + return uint128_t(0); + } + + uint128_t operator<<=(int shift){ + *this = *this << shift; + return *this; + } + + uint128_t operator>>=(int shift){ + *this = *this >> shift; + return *this; + } + + // Logical Operators + bool operator!(){ + return !(bool) (UPPER | LOWER); + } + + template <typename T> bool operator&&(T rhs){ + return (bool) *this && rhs; + } + + template <typename T> bool operator&&(uint128_t rhs){ + return (bool) *this && (bool) rhs; + } + + template <typename T> bool operator||(T rhs){ + return ((bool) *this) || rhs; + + } + + template <typename T> bool operator||(uint128_t rhs){ + return ((bool) *this) || (bool) rhs; + } + + // Comparison Operators + template <typename T> bool operator==(T rhs){ + return (!UPPER && (LOWER == (uint64_t) rhs)); + } + + bool operator==(uint128_t rhs){ + return ((UPPER == rhs.UPPER) && (LOWER == rhs.LOWER)); + } + + template <typename T> bool operator!=(T rhs){ + return (UPPER | (LOWER != (uint64_t) rhs)); + } + + bool operator!=(uint128_t rhs){ + return ((UPPER != rhs.UPPER) | (LOWER != rhs.LOWER)); + } + + template <typename T> bool operator>(T rhs){ + if (UPPER) + return true; + return (LOWER > (uint64_t) rhs); + } + + bool operator>(uint128_t rhs){ + if (UPPER == rhs.UPPER) + return (LOWER > rhs.LOWER); + if (UPPER > rhs.UPPER) + return true; + return false; + } + + template <typename T> bool operator<(T rhs){ + if (!UPPER) + return (LOWER < (uint64_t) rhs); + return false; + } + + bool operator<(uint128_t rhs){ + if (UPPER == rhs.UPPER) + return (LOWER < rhs.LOWER); + if (UPPER < rhs.UPPER) + return true; + return false; + } + + template <typename T> bool operator>=(T rhs){ + return ((*this > rhs) | (*this == rhs)); + } + + bool operator>=(uint128_t rhs){ + return ((*this > rhs) | (*this == rhs)); + } + + template <typename T> bool operator<=(T rhs){ + return ((*this < rhs) | (*this == rhs)); + } + + bool operator<=(uint128_t rhs){ + return ((*this < rhs) | (*this == rhs)); + } + + // Arithmetic Operators + template <typename T> uint128_t operator+(T rhs){ + return uint128_t(UPPER + ((LOWER + (uint64_t) rhs) < LOWER), LOWER + (uint64_t) rhs); + } + + uint128_t operator+(uint128_t rhs){ + return uint128_t(rhs.UPPER + UPPER + ((LOWER + rhs.LOWER) < LOWER), LOWER + rhs.LOWER); + } + + template <typename T> uint128_t operator+=(T rhs){ + UPPER = UPPER + ((LOWER + rhs) < LOWER); + LOWER = LOWER + rhs; + return *this; + } + + uint128_t operator+=(uint128_t rhs){ + UPPER = rhs.UPPER + UPPER + ((LOWER + rhs.LOWER) < LOWER); + LOWER = LOWER + rhs.LOWER; + return *this; + } + + template <typename T> uint128_t operator-(T rhs){ + return uint128_t((uint64_t) (UPPER - ((LOWER - rhs) > LOWER)), (uint64_t) (LOWER - rhs)); + } + + uint128_t operator-(uint128_t rhs){ + return uint128_t(UPPER - rhs.UPPER - ((LOWER - rhs.LOWER) > LOWER), LOWER - rhs.LOWER); + } + + template <typename T> uint128_t operator-=(T rhs){ + *this = *this - rhs; + return *this; + } + + uint128_t operator-=(uint128_t rhs){ + *this = *this - rhs; + return *this; + } + + template <typename T> uint128_t operator*(T rhs){ + return *this * uint128_t(rhs); + } + + uint128_t operator*(uint128_t rhs){ + // split values into 4 32-bit parts + uint64_t top[4] = {UPPER >> 32, UPPER % 0x100000000ULL, LOWER >> 32, LOWER % 0x100000000ULL}; + uint64_t bottom[4] = {rhs.upper() >> 32, rhs.upper() % 0x100000000ULL, rhs.lower() >> 32, rhs.lower() % 0x100000000ULL}; + uint64_t products[4][4]; + + for(int y = 3; y > -1; y--) + for(int x = 3; x > -1; x--){ + products[3 - x][y] = top[x] * bottom[y]; + } + + // initial row + uint64_t fourth32 = products[0][3] % 0x100000000ULL; + uint64_t third32 = products[0][2] % 0x100000000ULL + (products[0][3] >> 32); + uint64_t second32 = products[0][1] % 0x100000000ULL + (products[0][2] >> 32); + uint64_t first32 = products[0][0] % 0x100000000ULL + (products[0][1] >> 32); + + // second row + third32 += products[1][3] % 0x100000000ULL; + second32 += (products[1][2] % 0x100000000ULL) + (products[1][3] >> 32); + first32 += (products[1][1] % 0x100000000ULL) + (products[1][2] >> 32); + + // third row + second32 += products[2][3] % 0x100000000ULL; + first32 += (products[2][2] % 0x100000000ULL) + (products[2][3] >> 32); + + // fourth row + first32 += products[3][3] % 0x100000000ULL; + + // combines the values, taking care of carry over + return uint128_t(first32 << 32, 0) + uint128_t(third32 >> 32, third32 << 32) + uint128_t(second32, 0) + uint128_t(fourth32); + } + + template <typename T> uint128_t operator*=(T rhs){ + *this = *this * uint128_t(rhs); + return *this; + } + + uint128_t operator*=(uint128_t rhs){ + *this = *this * rhs; + return *this; + } + + template <typename T> uint128_t operator/(T rhs){ + return *this / uint128_t(rhs); + } + + uint128_t operator/(uint128_t rhs){ + // Save some calculations ///////////////////// + if (rhs == 0){ + std::cout << "Error: division or modulus by zero" << std::endl; + exit(1); + } + if (rhs == 1) + return *this; + if (*this == rhs) + return uint128_t(1); + if ((*this == 0) | (*this < rhs)) + return uint128_t(0); + // Checks for divisors that are powers of two + uint16_t s = 0; + uint128_t copyd(rhs); + while ((copyd.LOWER & 1) == 0){ + copyd >>= 1; + s++; + } + if (copyd == 1) + return *this >> s; + //////////////////////////////////////////////// + uint128_t copyn(*this), quotient = 0; + while (copyn >= rhs){ + uint128_t copyd(rhs), temp(1); + // shift the divsor to match the highest bit + while ((copyn >> 1) > copyd){ + copyd <<= 1; + temp <<= 1; + } + copyn -= copyd; + quotient += temp; + } + return quotient; + } + + template <typename T> uint128_t operator/=(T rhs){ + *this = *this / uint128_t(rhs); + return *this; + } + + uint128_t operator/=(uint128_t rhs){ + *this = *this / rhs; + return *this; + } + + template <typename T> uint128_t operator%(T rhs){ + return *this - (rhs * (*this / rhs)); + } + + uint128_t operator%(uint128_t rhs){ + return *this - (rhs * (*this / rhs)); + } + + template <typename T> uint128_t operator%=(T rhs){ + *this = *this % uint128_t(rhs); + return *this; + } + + uint128_t operator%=(uint128_t rhs){ + *this = *this % rhs; + return *this; + } + + // Increment Operator + uint128_t operator++(){ + *this += 1; + return *this; + } + + uint128_t operator++(int){ + uint128_t temp(*this); + ++*this; + return temp; + } + + // Decrement Operator + uint128_t operator--(){ + *this -= 1; + return *this; + } + + uint128_t operator--(int){ + uint128_t temp(*this); + --*this; + return temp; + } + + // get private values + uint64_t upper(){ + return UPPER; + } + + uint64_t lower(){ + return LOWER; + } +}; +// lhs type T as first arguemnt + +// Bitwise Operators +template <typename T> T operator&(T lhs, uint128_t rhs){ + T out = lhs & (T) rhs.lower(); + return out; +} + +template <typename T> T operator|(T lhs, uint128_t rhs){ + T out = lhs | (T) rhs.lower(); + return out; +} + +template <typename T> T operator^(T lhs, uint128_t rhs){ + T out = lhs ^ (T) rhs.lower(); + return out; +} + +template <typename T> T operator&=(T & lhs, uint128_t rhs){ + lhs &= (T) rhs.lower(); + return lhs; +} + +template <typename T> T operator|=(T & lhs, uint128_t rhs){ + lhs |= (T) rhs.lower(); + return lhs; +} + +template <typename T> T operator^=(T & lhs, uint128_t rhs){ + lhs ^= (T) rhs.lower(); + return lhs; +} + +// Comparison Operators +template <typename T> bool operator==(T lhs, uint128_t rhs){ + return (!rhs.upper() && ((uint64_t) lhs == rhs.lower())); +} + +template <typename T> bool operator!=(T lhs, uint128_t rhs){ + return (rhs.upper() | ((uint64_t) lhs != rhs.lower())); +} + +template <typename T> bool operator>(T lhs, uint128_t rhs){ + if (rhs.upper()) + return false; + return ((uint64_t) lhs > rhs.lower()); +} + +template <typename T> bool operator<(T lhs, uint128_t rhs){ + if (rhs.upper()) + return true; + return ((uint64_t) lhs < rhs.lower()); +} + +template <typename T> bool operator>=(T lhs, uint128_t rhs){ + if (rhs.upper()) + return false; + return ((uint64_t) lhs >= rhs.lower()); +} + +template <typename T> bool operator<=(T lhs, uint128_t rhs){ + if (rhs.upper()) + return true; + return ((uint64_t) lhs <= rhs.lower()); +} + +// Arithmetic Operators +template <typename T> T operator+(T lhs, uint128_t rhs){ + return (T) (rhs + lhs); +} + +template <typename T> T & operator+=(T & lhs, uint128_t rhs){ + lhs = (T) (rhs + lhs); + return lhs; +} + +template <typename T> T operator-(T lhs, uint128_t rhs){ + return (T) (rhs - lhs); +} + +template <typename T> T & operator-=(T & lhs, uint128_t rhs){ + lhs = (T) (rhs - lhs); + return lhs; +} + +template <typename T> T operator*(T lhs, uint128_t rhs){ + return lhs * rhs.lower(); +} + +template <typename T> T & operator*=(T & lhs, uint128_t rhs){ + lhs = (T) (rhs.lower() * lhs); + return lhs; +} + +template <typename T> T operator/(T lhs, uint128_t rhs){ + return (T) (uint128_t(lhs) / rhs); +} + +template <typename T> T & operator/=(T & lhs, uint128_t rhs){ + lhs = (T) (uint128_t(lhs) / rhs); + return lhs; +} + +template <typename T> T operator%(T lhs, uint128_t rhs){ + return (T) (uint128_t(lhs) % rhs); +} + +template <typename T> T & operator%=(T & lhs, uint128_t rhs){ + lhs = (T) (uint128_t(lhs) % rhs); + return lhs; +} + +// IO Operator +std::ostream & operator<<(std::ostream & stream, uint128_t rhs){ + std::string out = ""; + if (rhs == 0) + out = "0"; + else { + int div = 10; + if (stream.flags() & stream.oct) + div = 8; + if (stream.flags() & stream.dec) + div = 10; + if (stream.flags() & stream.hex) + div = 16; + while (rhs > 0){ + out = "0123456789abcdef"[size_t(rhs % div)] + out; + rhs /= div; + } + } + stream << out; + return stream; +} + +#endif // UINT128_T_H
--- a/USBHostPTP.cpp Tue Sep 10 07:40:44 2013 +0000 +++ b/USBHostPTP.cpp Wed Sep 18 01:48:07 2013 +0000 @@ -580,12 +580,12 @@ { OperFlags flags = { 1, 0, 0, 1, 1, 0 }; uint32_t params[1]; - + params[0] = (uint32_t)pcode; if(IsPropertySupported(pcode)==false) return PIMA_RETURN_CODE_DevicePropertyNotSupported; - + return Transaction(PIMA_OPERATION_CODE_GetDevicePropDesc, &flags, params, parser); } @@ -756,6 +756,13 @@ obj->storageInfo.volumeLabel.FillString(ptr); } +void USBHostPTP::ParseDevicePropDescrBlock(void *ptp,uint8_t *buffer,uint16_t length){ + PIMAPropDescr *temp; + + temp= new PIMAPropDescr; + temp.fill(buffer); + +} bool USBHostPTP::IsCommandSupported(uint16_t opcode){ bool res=false; @@ -763,23 +770,17 @@ if(opcode==PIMA_OPERATION_CODE_OpenSession || opcode==PIMA_OPERATION_CODE_GetDeviceInfo) res=true; else - res = CheckValueInArray(&deviceInfo.operationsSupported,opcode); + res = deviceInfo.operationsSupported.CheckValueInArray(opcode); return res; } bool USBHostPTP::IsPropertySupported(uint16_t code){ - return CheckValueInArray(&deviceInfo.devicePropertiesSupported, code); + return deviceInfo.devicePropertiesSupported.CheckValueInArray(code); } -bool USBHostPTP::CheckValueInArray(PIMAArray *array, uint16_t code) { - bool res=false; - for(int i=0; i<array->numberOfElements;i++) - if(code == array->codes[i]) - res=true; - return res; -} + void USBHostPTP::DumpBuffer(uint8_t *buffer,uint32_t length){ @@ -803,23 +804,23 @@ printf("Functional Mode: %x\r\n",deviceInfo.functionMode); printf("Supported Operations: \r\n"); for(i=0;i<deviceInfo.operationsSupported.numberOfElements;i++) { - printf("0x%04x\r\n",deviceInfo.operationsSupported.codes[i]); + printf("0x%04x\r\n",deviceInfo.operationsSupported.GetElement(i)); } printf("Supported Events: \r\n"); for(i=0;i<deviceInfo.eventsSupported.numberOfElements;i++) { - printf("0x%04x\r\n",deviceInfo.eventsSupported.codes[i]); + printf("0x%04x\r\n",deviceInfo.eventsSupported.GetElement(i)); } printf("Supported Device Properties: \r\n"); for(i=0;i<deviceInfo.devicePropertiesSupported.numberOfElements;i++) { - printf("0x%04x\r\n",deviceInfo.devicePropertiesSupported.codes[i]); + printf("0x%04x\r\n",deviceInfo.devicePropertiesSupported.GetElement(i)); } printf("Supported Capture Formats: \r\n"); for(i=0;i<deviceInfo.captureFormats.numberOfElements;i++) { - printf("0x%04x\r\n",deviceInfo.captureFormats.codes[i]); + printf("0x%04x\r\n",deviceInfo.captureFormats.GetElement(i)); } printf("Supported Image Formats: \r\n"); for(i=0;i<deviceInfo.imageFormats.numberOfElements;i++) { - printf("0x%04x\r\n",deviceInfo.imageFormats.codes[i]); + printf("0x%04x\r\n",deviceInfo.imageFormats.GetElement(i)); } printf("Manufacturer: \r\n");
--- a/USBHostPTP.h Tue Sep 10 07:40:44 2013 +0000 +++ b/USBHostPTP.h Wed Sep 18 01:48:07 2013 +0000 @@ -381,11 +381,11 @@ int checkResult(uint8_t res, USBEndpoint * ep); bool IsCommandSupported(uint16_t opcode); bool IsPropertySupported(uint16_t code); - bool CheckValueInArray(PIMAArray *array, uint16_t code); bool CheckEvent(void); static void ParseDeviceInfoDataBlock(void *ptp, uint8_t *buffer,uint16_t length); static void ParseObjectInfoDataBlock(void *ptp, uint8_t *buffer,uint16_t length); static void ParseStorageInfoDataBlock(void *ptp, uint8_t *buffer,uint16_t length); + static void ParseDevicePropDescrBlock(void *ptp,uint8_t *buffer,uint16_t length); void PrepareControlContainer(uint16_t operationCode, OperFlags *operationFlags, uint32_t *parameters);