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