00001 /*************************************************************************** 00002 LOW_deviceIDRaw.h - description 00003 ------------------- 00004 begin : Thu Jul 18 2002 00005 copyright : (C) 2002 by Harald Roelle, Helmut Reiser 00006 email : roelle@informatik.uni-muenchen.de, reiser@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 #ifndef LOW_DEVICEIDRAW_H 00019 #define LOW_DEVICEIDRAW_H 00020 00021 00022 #include "LOW_types.h" 00023 #include "LOW_exception.h" 00024 00025 00026 00027 /** Base class for 1-Wire ROM IDs. 00028 00029 In contrast to LOW_deviceID this class allows manipulation of the ID. 00030 Furthermore no CRC validation is done on creation. 00031 00032 @author Harald Roelle, Helmut Reiser 00033 */ 00034 class LOW_deviceIDRaw { 00035 00036 //======================================================================================= 00037 public: 00038 00039 //===================================================================================== 00040 // 00041 // exceptions 00042 // 00043 00044 /** Exception base class for all exceptions thrown by LOW_deviceIDRaw. */ 00045 class_DERIVE_FROM_EXCEPTION( deviceIDRaw_error , LOW_exception); 00046 00047 /** Exception class indicating a mismatch of expected/required 00048 size in dynamic sized data types. 00049 */ 00050 class_DERIVE_FROM_EXCEPTION( sizeMismatch_error , deviceIDRaw_error); 00051 00052 /** Exception class indicating an illegal or out of range parameter. */ 00053 class_DERIVE_FROM_EXCEPTION( range_error , deviceIDRaw_error); 00054 00055 00056 //===================================================================================== 00057 // 00058 // type definitions 00059 // 00060 00061 typedef std::vector<LOW_deviceIDRaw> deviceIDRawVec_t; /**< Vector type of class LOW_deviceIDRaw */ 00062 00063 typedef uint8_t devRomID_t[8]; /**< Type of the whole 64 bit ID. */ 00064 typedef uint8_t devCRC_t; /**< Type of 8 bit CRC checksum of the whole ID. */ 00065 typedef uint8_t devSerNum_t[6]; /**< Type of device individual serial number. */ 00066 typedef uint8_t devFamCode_t; /**< Type of device's family code. */ 00067 00068 00069 //===================================================================================== 00070 // 00071 // constructors 00072 // 00073 00074 /** Default constructor. */ 00075 LOW_deviceIDRaw(); 00076 00077 /** Constructor from ROM ID as our own data type. 00078 <B>Note:</B> No CRC validation is done. 00079 @param inRomID Reference to ROM ID. 00080 */ 00081 LOW_deviceIDRaw( const devRomID_t &inRomID); 00082 00083 /** Constructor from two 32 bit values. 00084 <B>Note:</B> No CRC validation is done. 00085 @param inHighInt Upper 32 bits of ROM ID. 00086 @param inLowInt Lower 32 bits of ROM ID. 00087 */ 00088 LOW_deviceIDRaw( uint32_t inHighInt, uint32_t inLowInt); 00089 00090 /** Constructor from byte vector. 00091 <B>Note:</B> No CRC validation is done. 00092 @param inRomID Reference to byte vector of exactly 8 bytes. 00093 @throw sizeMismatch_error Thrown when <I>inRomID</I> has other size than 8. 00094 */ 00095 LOW_deviceIDRaw( const byteVec_t &inRomID); 00096 00097 /** Destructor. */ 00098 ~LOW_deviceIDRaw(); 00099 00100 00101 //===================================================================================== 00102 // 00103 // operators 00104 // 00105 00106 bool operator==(const LOW_deviceIDRaw &inDID) const; /**< Comparison on the whole 64 bits of ID. */ 00107 bool operator!=(const LOW_deviceIDRaw &inDID) const; /**< Comparison on the whole 64 bits of ID. */ 00108 bool operator<(const LOW_deviceIDRaw &inDID) const; /**< Comparison on the whole 64 bits of ID. */ 00109 00110 00111 //===================================================================================== 00112 // 00113 // methods 00114 // 00115 00116 /** Get 64 bit ROM ID as our data type. 00117 @param outID Reference where ID is written to. 00118 */ 00119 void getRomID( devRomID_t &outID) const; 00120 00121 /** Get 64 bit ROM ID as byte vector. 00122 @return The ROM ID as byte vector. 00123 */ 00124 byteVec_t getRomIDVec() const; 00125 00126 /** Get 64 bit ROM ID as hex C++ string. 00127 @return The ROM ID as hex string. 00128 */ 00129 std::string getRomIDString() const; 00130 00131 /** Get 8 bit CRC. 00132 @return The ID's CRC part. 00133 */ 00134 devCRC_t getCRC() const; 00135 00136 /** Get 48 bit serial number. 00137 @param outSerNum Reference where rhe ID's serial number part is written to. 00138 */ 00139 void getSerialNum( devSerNum_t &outSerNum) const; 00140 00141 /** Get 8 bit family code. 00142 @return The ID's family code part. 00143 */ 00144 devFamCode_t getFamilyCode() const; 00145 00146 /** Set 8 bit family code. 00147 @param inFamCode Value of family code to set. 00148 */ 00149 void setFamilyCode( const devFamCode_t inFamCode); 00150 00151 /** Get 1 bit from the ID. 00152 @param inBitNum Number of the bit to get (0-63). 00153 @return Value of requested bit. 00154 @throw range_error Thrown when <I>inBitNum</I> is out of range. 00155 */ 00156 bool getBit( uint8_t inBitNum) const; 00157 00158 /** Set 1 bit in the ID. 00159 @param inBitNum Number of the bit to set (0-63). 00160 @param inValue Value to set the bit to. 00161 @throw range_error Thrown when <I>inBitNum</I> is out of range. 00162 */ 00163 void setBit( const uint8_t inBitNum, const bool inValue); 00164 00165 00166 //======================================================================================= 00167 protected: 00168 00169 //===================================================================================== 00170 // 00171 // attributes 00172 // 00173 00174 devRomID_t romID; /**< The lasered ROM ID. */ 00175 00176 }; 00177 00178 #endif