00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <stdio.h>
00020
00021 #include "LOW_deviceIDRaw.h"
00022
00023
00024
00025
00026
00027
00028
00029
00030 LOW_deviceIDRaw::LOW_deviceIDRaw()
00031 {
00032 for( unsigned int a=0; a<sizeof( romID); a++)
00033 romID[a] = 0x00;
00034 }
00035
00036 LOW_deviceIDRaw::LOW_deviceIDRaw( const devRomID_t &inRomID)
00037 {
00038 for( unsigned int a=0; a<sizeof( romID); a++) {
00039 romID[a] = inRomID[a];
00040 }
00041 }
00042
00043 LOW_deviceIDRaw::LOW_deviceIDRaw( uint32_t inHighInt, uint32_t inLowInt)
00044 {
00045 for( unsigned int a=0; a<4; a++) {
00046 romID[a] = inLowInt & 0xff;
00047 inLowInt>>=8;
00048 }
00049 for( unsigned int a=4; a<8; a++) {
00050 romID[a] = inHighInt & 0xff;
00051 inHighInt>>=8;
00052 }
00053 }
00054
00055 LOW_deviceIDRaw::LOW_deviceIDRaw( const byteVec_t &inRomID)
00056 {
00057 if ( inRomID.size() != sizeof( romID) )
00058 throw sizeMismatch_error( "Byte vector length does not match", __FILE__, __LINE__);
00059
00060 for( unsigned int a=0; a<sizeof( romID); a++)
00061 romID[a] = inRomID[a];
00062 }
00063
00064
00065 LOW_deviceIDRaw::~LOW_deviceIDRaw()
00066 {
00067 }
00068
00069
00070
00071
00072
00073
00074
00075 bool LOW_deviceIDRaw::operator==(const LOW_deviceIDRaw &inDID) const
00076 {
00077 for( unsigned int a=0; a<8; a++)
00078 if ( inDID.romID[a] != romID[a] )
00079 return false;
00080 return true;
00081 }
00082
00083 bool LOW_deviceIDRaw::operator!=(const LOW_deviceIDRaw &inDID) const
00084 {
00085 return !(inDID.romID==romID);
00086 }
00087
00088 bool LOW_deviceIDRaw::operator<(const LOW_deviceIDRaw &inDID) const
00089 {
00090 for( int a=7; a>=0; a--) {
00091 if( romID[a] < inDID.romID[a] )
00092 return true;
00093 if( romID[a] > inDID.romID[a] )
00094 return false;
00095 }
00096 return false;
00097 }
00098
00099
00100
00101
00102
00103
00104
00105 void LOW_deviceIDRaw::getRomID( devRomID_t& outID) const
00106 {
00107 for( unsigned int a=0; a<sizeof( romID); a++)
00108 outID[a] = romID[a];
00109 }
00110
00111
00112 byteVec_t LOW_deviceIDRaw::getRomIDVec() const
00113 {
00114 byteVec_t retVal = byteVec_t( sizeof( romID));
00115
00116 for( unsigned int a=0; a<sizeof( romID); a++)
00117 retVal[a] = romID[a];
00118
00119 return retVal;
00120 }
00121
00122
00123 std::string LOW_deviceIDRaw::getRomIDString() const
00124 {
00125 const unsigned int bufLen = 2*sizeof(romID) + 1;
00126 char buffer[bufLen];
00127 char *tmpBuffer = buffer;
00128
00129 for( int a=sizeof( romID)-1; a>=0; --a) {
00130 snprintf( tmpBuffer, bufLen, "%02x", romID[a]);
00131 tmpBuffer += 2;
00132 }
00133
00134 return std::string( buffer);
00135 }
00136
00137
00138 LOW_deviceIDRaw::devCRC_t LOW_deviceIDRaw::getCRC() const
00139 {
00140 return romID[7];
00141 }
00142
00143
00144 void LOW_deviceIDRaw::getSerialNum( devSerNum_t& outSerNum) const
00145 {
00146 for( int a=0; a<6; a++)
00147 outSerNum[a] = romID[a+1];
00148 }
00149
00150
00151 LOW_deviceIDRaw::devFamCode_t LOW_deviceIDRaw::getFamilyCode() const
00152 {
00153 return romID[0];
00154 }
00155
00156
00157 void LOW_deviceIDRaw::setFamilyCode( const devFamCode_t inFamCode)
00158 {
00159 romID[0] = inFamCode;
00160 }
00161
00162
00163 bool LOW_deviceIDRaw::getBit( uint8_t inBitNum) const
00164 {
00165 if ( inBitNum > 63 )
00166 throw range_error( "Index out of range", __FILE__, __LINE__);
00167
00168 return (romID[inBitNum/8]&(0x01<<(inBitNum%8)))==0?false:true;
00169 }
00170
00171
00172 void LOW_deviceIDRaw::setBit( const uint8_t inBitNum, const bool inValue)
00173 {
00174 if ( inBitNum > 63 )
00175 throw range_error( "Index out of range", __FILE__, __LINE__);
00176
00177 if ( inValue )
00178 romID[inBitNum/8] |= 0x01<<(inBitNum%8);
00179 else
00180 romID[inBitNum/8] &= ~(0x01<<(inBitNum%8));
00181 }