Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members | Related Pages

LOW_deviceIDRaw.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           LOW_deviceIDRaw.cpp  -  description
00003                              -------------------
00004     begin                : Thu Jul 18 2002
00005     copyright            : (C) 2002 by Harald Roelle
00006     email                : roelle@informatik.uni-muenchen.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018  
00019 #include <stdio.h> // needed for snprintf()
00020 
00021 #include "LOW_deviceIDRaw.h"
00022 
00023 
00024 
00025 //=====================================================================================
00026 //
00027 // public constructors
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 LOW_deviceIDRaw &inDeviceIDRaw) :
00037   LOW_objectSynchronizer( inDeviceIDRaw)
00038 {
00039   for( unsigned int a=0; a<sizeof( romID); a++)
00040     romID[a] = inDeviceIDRaw.romID[a];
00041 }
00042 
00043 LOW_deviceIDRaw::LOW_deviceIDRaw( const devRomID_t &inRomID)
00044 {
00045   for( unsigned int a=0; a<sizeof( romID); a++) {
00046     romID[a] = inRomID[a];
00047   }
00048 }
00049 
00050 LOW_deviceIDRaw::LOW_deviceIDRaw( uint32_t inHighInt, uint32_t inLowInt)
00051 {
00052   for( unsigned int a=0; a<4; a++) {
00053     romID[a] = inLowInt & 0xff;
00054     inLowInt>>=8;
00055   }
00056   for( unsigned int a=4; a<8; a++) {
00057     romID[a] = inHighInt & 0xff;
00058     inHighInt>>=8;
00059   }
00060 }
00061   
00062 LOW_deviceIDRaw::LOW_deviceIDRaw( const byteVec_t &inRomID)
00063 {
00064   if ( inRomID.size() != sizeof( romID) )
00065     throw sizeMismatch_error( "Byte vector length does not match", __FILE__, __LINE__);
00066     
00067   for( unsigned int a=0; a<sizeof( romID); a++)
00068     romID[a] = inRomID[a];
00069 }
00070 
00071 
00072 LOW_deviceIDRaw::~LOW_deviceIDRaw()
00073 {
00074 }
00075 
00076 
00077 //=====================================================================================
00078 //
00079 // operator overloading
00080 //
00081 
00082 bool LOW_deviceIDRaw::operator==(const LOW_deviceIDRaw &inDID) const
00083 {
00084   __LOW_SYNCHRONIZE_METHOD_READ__
00085 
00086   for( unsigned int a=0; a<8; a++)
00087     if ( inDID.romID[a] != romID[a] )
00088       return false;
00089   return true;
00090 }
00091 
00092 bool LOW_deviceIDRaw::operator!=(const LOW_deviceIDRaw &inDID) const
00093 {
00094   __LOW_SYNCHRONIZE_METHOD_READ__
00095 
00096   return !(inDID.romID==romID);
00097 }
00098 
00099 bool LOW_deviceIDRaw::operator<(const LOW_deviceIDRaw &inDID) const
00100 {
00101   __LOW_SYNCHRONIZE_METHOD_READ__
00102 
00103   for( int a=7; a>=0; a--) {
00104     if( romID[a] < inDID.romID[a] )
00105       return true;
00106     if( romID[a] > inDID.romID[a] )
00107       return false;
00108   }
00109   return false;  // they are identical
00110 }
00111 
00112 
00113 //=====================================================================================
00114 //
00115 // public methods
00116 //
00117 
00118 void LOW_deviceIDRaw::getRomID( devRomID_t& outID) const
00119 {
00120   __LOW_SYNCHRONIZE_METHOD_READ__
00121 
00122   for( unsigned int a=0; a<sizeof( romID); a++)
00123     outID[a] = romID[a];
00124 }
00125 
00126 
00127 byteVec_t LOW_deviceIDRaw::getRomIDVec() const
00128 {
00129   __LOW_SYNCHRONIZE_METHOD_READ__
00130 
00131   byteVec_t retVal = byteVec_t( sizeof( romID));
00132   
00133   for( unsigned int a=0; a<sizeof( romID); a++)
00134     retVal[a] = romID[a];
00135   
00136   return retVal;
00137 }
00138   
00139 
00140 std::string LOW_deviceIDRaw::getRomIDString() const
00141 {
00142   __LOW_SYNCHRONIZE_METHOD_READ__
00143 
00144   const unsigned int bufLen = 2*sizeof(romID) + 1;  // the +1 is the terminating null byte
00145   char               buffer[bufLen];
00146   char               *tmpBuffer = buffer;
00147       
00148   for( int a=sizeof( romID)-1; a>=0; --a) {
00149     snprintf( tmpBuffer, bufLen, "%02x", romID[a]);
00150     tmpBuffer += 2;
00151   }
00152       
00153   return std::string( buffer);
00154 }
00155 
00156 
00157 LOW_deviceIDRaw::devCRC_t LOW_deviceIDRaw::getCRC() const
00158 {
00159   __LOW_SYNCHRONIZE_METHOD_READ__
00160   
00161   return romID[7];
00162 }
00163 
00164 
00165 void LOW_deviceIDRaw::getSerialNum( devSerNum_t& outSerNum) const
00166 {
00167   __LOW_SYNCHRONIZE_METHOD_READ__
00168 
00169   for( int a=0; a<6; a++)
00170     outSerNum[a] = romID[a+1];
00171 }
00172 
00173 
00174 LOW_deviceIDRaw::devFamCode_t LOW_deviceIDRaw::getFamilyCode() const
00175 {
00176   __LOW_SYNCHRONIZE_METHOD_READ__
00177   
00178   return romID[0];
00179 }
00180   
00181 
00182 void LOW_deviceIDRaw::setFamilyCode( const devFamCode_t inFamCode)
00183 {
00184   __LOW_SYNCHRONIZE_METHOD_WRITE__
00185 
00186   romID[0] = inFamCode;
00187 }
00188   
00189 
00190 bool LOW_deviceIDRaw::getBit( uint8_t inBitNum) const
00191 {
00192   __LOW_SYNCHRONIZE_METHOD_READ__
00193 
00194   if ( inBitNum > 63 )
00195     throw range_error( "Index out of range", __FILE__, __LINE__);
00196   
00197   return (romID[inBitNum/8]&(0x01<<(inBitNum%8)))==0?false:true;
00198 }
00199 
00200 
00201 void LOW_deviceIDRaw::setBit( const uint8_t inBitNum, const bool inValue)
00202 {
00203   __LOW_SYNCHRONIZE_METHOD_WRITE__
00204 
00205   if ( inBitNum > 63 )
00206     throw range_error( "Index out of range", __FILE__, __LINE__);
00207   
00208   if ( inValue )
00209     romID[inBitNum/8] |= 0x01<<(inBitNum%8);
00210   else
00211     romID[inBitNum/8] &= ~(0x01<<(inBitNum%8));
00212 }
00213 

Generated on Tue Feb 3 11:30:25 2004 for OneWireLibrary++ by doxygen 1.3.2