Wiselib
|
00001 /*************************************************************************** 00002 ** This file is part of the generic algorithm library Wiselib. ** 00003 ** Copyright (C) 2008,2009 by the Wisebed (www.wisebed.eu) project. ** 00004 ** ** 00005 ** The Wiselib is free software: you can redistribute it and/or modify ** 00006 ** it under the terms of the GNU Lesser General Public License as ** 00007 ** published by the Free Software Foundation, either version 3 of the ** 00008 ** License, or (at your option) any later version. ** 00009 ** ** 00010 ** The Wiselib is distributed in the hope that it will be useful, ** 00011 ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** 00012 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** 00013 ** GNU Lesser General Public License for more details. ** 00014 ** ** 00015 ** You should have received a copy of the GNU Lesser General Public ** 00016 ** License along with the Wiselib. ** 00017 ** If not, see <http://www.gnu.org/licenses/>. ** 00018 ***************************************************************************/ 00019 #ifndef CONNECTOR_ISENSE_TXPOWER_H 00020 #define CONNECTOR_ISENSE_TXPOWER_H 00021 00022 namespace wiselib 00023 { 00024 00029 template<typename OsModel_P> 00030 class ComIsenseTxPower { 00031 public: 00032 ComIsenseTxPower(); 00033 ComIsenseTxPower(ComIsenseTxPower const &); 00034 00035 ComIsenseTxPower &operator=(ComIsenseTxPower const &); 00036 bool operator==(ComIsenseTxPower) const; 00037 bool operator!=(ComIsenseTxPower) const; 00038 bool operator<=(ComIsenseTxPower) const; 00039 bool operator>=(ComIsenseTxPower) const; 00040 bool operator<(ComIsenseTxPower) const; 00041 bool operator>(ComIsenseTxPower) const; 00042 ComIsenseTxPower operator++(); 00043 ComIsenseTxPower operator++(int); 00044 ComIsenseTxPower operator--(); 00045 ComIsenseTxPower operator--(int); 00046 00047 static ComIsenseTxPower from_ratio(int); 00048 void set_ratio(int); 00049 int to_ratio() const; 00050 static ComIsenseTxPower from_dB(int); 00051 void set_dB(int); 00052 int to_dB() const; 00053 00054 static ComIsenseTxPower const MIN; 00055 static ComIsenseTxPower const MAX; 00056 00057 private: 00058 ComIsenseTxPower(int); 00059 int value_; 00060 }; 00061 00063 template<typename OsModel_P> ComIsenseTxPower<OsModel_P> const ComIsenseTxPower<OsModel_P>:: 00064 MIN=-30; 00065 00067 template<typename OsModel_P> ComIsenseTxPower<OsModel_P> const ComIsenseTxPower<OsModel_P>:: 00068 MAX=0; 00069 00070 template<typename OsModel_P> 00071 inline ComIsenseTxPower<OsModel_P>::ComIsenseTxPower(int v): 00072 value_(v){} 00073 00074 template<typename OsModel_P> 00075 inline ComIsenseTxPower<OsModel_P>::ComIsenseTxPower(): 00076 value_(0) 00077 {} 00078 00079 template<typename OsModel_P> 00080 inline ComIsenseTxPower<OsModel_P> &ComIsenseTxPower<OsModel_P>::operator=(ComIsenseTxPower<OsModel_P> const &p) { 00081 value_=p.value_; 00082 return *this; 00083 } 00084 00085 template<typename OsModel_P> 00086 inline ComIsenseTxPower<OsModel_P>::ComIsenseTxPower(ComIsenseTxPower const &power): 00087 value_( power.value_ ){} 00088 00089 template<typename OsModel_P> 00090 inline bool ComIsenseTxPower<OsModel_P>::operator==(ComIsenseTxPower p) const { 00091 return value_==p.value_; 00092 } 00093 00094 template<typename OsModel_P> 00095 inline bool ComIsenseTxPower<OsModel_P>::operator!=(ComIsenseTxPower p) const { 00096 return value_!=p.value_; 00097 } 00098 00099 template<typename OsModel_P> 00100 inline bool ComIsenseTxPower<OsModel_P>::operator<=(ComIsenseTxPower p) const { 00101 return value_<=p.value_; 00102 } 00103 00104 template<typename OsModel_P> 00105 inline bool ComIsenseTxPower<OsModel_P>::operator>=(ComIsenseTxPower p) const { 00106 return value_>=p.value_; 00107 } 00108 00109 template<typename OsModel_P> 00110 inline bool ComIsenseTxPower<OsModel_P>::operator<(ComIsenseTxPower p) const { 00111 return value_<p.value_; 00112 } 00113 00114 template<typename OsModel_P> 00115 inline bool ComIsenseTxPower<OsModel_P>::operator>(ComIsenseTxPower p) const { 00116 return value_>p.value_; 00117 } 00118 00119 template<typename OsModel_P> 00120 ComIsenseTxPower<OsModel_P> ComIsenseTxPower<OsModel_P>::operator++(){ 00121 value_+=6; 00122 return *this; 00123 } 00124 00125 template<typename OsModel_P> 00126 ComIsenseTxPower<OsModel_P> ComIsenseTxPower<OsModel_P>::operator++(int){ 00127 ComIsenseTxPower p=*this; 00128 value_+=6; 00129 return p; 00130 } 00131 00132 template<typename OsModel_P> 00133 ComIsenseTxPower<OsModel_P> ComIsenseTxPower<OsModel_P>::operator--(){ 00134 value_-=6; 00135 return *this; 00136 } 00137 00138 template<typename OsModel_P> 00139 ComIsenseTxPower<OsModel_P> ComIsenseTxPower<OsModel_P>::operator--(int){ 00140 ComIsenseTxPower p=*this; 00141 value_-=6; 00142 return p; 00143 } 00144 00150 template<typename OsModel_P> ComIsenseTxPower<OsModel_P> ComIsenseTxPower<OsModel_P>:: 00151 from_ratio( int ratio ) 00152 { 00153 if(ratio<=1) 00154 return MIN; 00155 else if(ratio<=4) 00156 return ComIsenseTxPower(-24); 00157 else if(ratio<=16) 00158 return ComIsenseTxPower(-18); 00159 else if(ratio<=63) 00160 return ComIsenseTxPower(-12); 00161 else if(ratio<=251) 00162 return ComIsenseTxPower(-6); 00163 else 00164 return MAX; 00165 } 00166 00175 template<typename OsModel_P> void ComIsenseTxPower<OsModel_P>:: 00176 set_ratio( int ratio ) 00177 { 00178 if(ratio<=1) 00179 value_=-30; 00180 else if(ratio<=4) 00181 value_=-24; 00182 else if(ratio<=16) 00183 value_=-18; 00184 else if(ratio<=63) 00185 value_=-12; 00186 else if(ratio<=251) 00187 value_=-6; 00188 else 00189 value_=0; 00190 } 00191 00196 template<typename OsModel_P> int ComIsenseTxPower<OsModel_P>:: 00197 to_ratio() const 00198 { 00199 switch(value_){ 00200 case 0: 00201 return 1000; 00202 case -6: 00203 return 251; 00204 case -12: 00205 return 63; 00206 case -18: 00207 return 16; 00208 case -24: 00209 return 4; 00210 default: 00211 return 1; 00212 } 00213 } 00214 00220 template<typename OsModel_P> ComIsenseTxPower<OsModel_P> ComIsenseTxPower<OsModel_P>:: 00221 from_dB( int db ) 00222 { 00223 if(db<=-30) 00224 return MIN; 00225 else if(db<=-24) 00226 return ComIsenseTxPower(-24); 00227 else if(db<=-18) 00228 return ComIsenseTxPower(-18); 00229 else if(db<=-12) 00230 return ComIsenseTxPower(-12); 00231 else if(db<=-6) 00232 return ComIsenseTxPower(-6); 00233 else 00234 return MAX; 00235 } 00236 00245 template<typename OsModel_P> void ComIsenseTxPower<OsModel_P>:: 00246 set_dB( int db ) 00247 { 00248 if(db<=-30) 00249 value_=-30; 00250 else if(db<=-24) 00251 value_=-24; 00252 else if(db<=-18) 00253 value_=-18; 00254 else if(db<=-12) 00255 value_=-12; 00256 else if(db<=-6) 00257 value_=-6; 00258 else 00259 value_=0; 00260 } 00261 00266 template<typename OsModel_P> inline int ComIsenseTxPower<OsModel_P>:: 00267 to_dB() const 00268 { 00269 return value_; 00270 } 00271 } 00272 #endif