00001 /* --------------------------------------------------------------------------- 00002 Phission : 00003 Realtime Vision Processing System 00004 00005 Copyright (C) 2003-2006 Philip D.S. Thoren (pthoren@cs.uml.edu) 00006 University of Massachusetts at Lowell, 00007 Laboratory for Artificial Intelligence and Robotics 00008 00009 This file is part of Phission. 00010 00011 Phission is free software; you can redistribute it and/or modify 00012 it under the terms of the GNU Lesser 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 Phission is distributed in the hope that it will be useful, 00017 but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 GNU Lesser General Public License for more details. 00020 00021 You should have received a copy of the GNU Lesser General Public License 00022 along with Phission; if not, write to the Free Software 00023 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00024 00025 ---------------------------------------------------------------------------*/ 00026 #ifdef HAVE_CONFIG_H 00027 #include <phissionconfig.h> 00028 #endif 00029 00030 #if defined(WIN32) 00031 #include <windows.h> 00032 #define USE_CLOCK() 0 00033 #define USE_TIMEVAL() 0 00034 #elif defined(__ADSPBLACKFIN__) 00035 #include <PhissionVDK.h> 00036 #define USE_CLOCK() 0 00037 #define USE_TIMEVAL() 0 00038 #else 00039 #define USE_CLOCK() 0 00040 #define USE_TIMEVAL() 1 00041 #if defined(HAVE_SYS_TIME_H) && USE_TIMEVAL() 00042 #include <sys/time.h> 00043 #endif 00044 00045 #if defined(HAVE_TIME_H) && USE_CLOCK() 00046 #include <time.h> 00047 #endif 00048 #endif 00049 00050 #include <phStandard.h> 00051 00052 #include <phObject.h> 00053 #include <phTimeStamp.h> 00054 00055 #include <phError.h> 00056 #include <phMemory.h> 00057 #include <phPrint.h> 00058 00059 /* ------------------------------------------------------------------------ */ 00060 phTimeStamp::phTimeStamp() 00061 { 00062 phFUNCTION("phTimeStamp::phTimeStamp") 00063 #if defined(WIN32) 00064 LARGE_INTEGER li; 00065 if (QueryPerformanceFrequency(&li)) 00066 this->m_priv = li.QuadPart; 00067 else 00068 #endif 00069 this->m_priv = 0; 00070 this->setName("phTimeStamp"); // comment this in when deriving from 00071 // phObject 00072 this->stamp(); 00073 } 00074 00075 /* ------------------------------------------------------------------------ */ 00076 phTimeStamp::phTimeStamp( const phTimeStamp &stamp ) 00077 { 00078 this->m_stamp_val = stamp.m_stamp_val; 00079 00080 } 00081 /* ------------------------------------------------------------------------ */ 00082 phTimeStamp::~phTimeStamp() 00083 { 00084 } 00085 00086 /* ------------------------------------------------------------------------ */ 00087 double phTimeStamp::getStampValue() const 00088 { 00089 return this->m_stamp_val; 00090 } 00091 00092 /* ------------------------------------------------------------------------ */ 00093 uint32_t phTimeStamp::getSeconds() const 00094 { 00095 return (uint32_t)(this->m_stamp_val / 1000000000.0); 00096 } 00097 00098 /* ------------------------------------------------------------------------ */ 00099 uint32_t phTimeStamp::getMilliseconds() const 00100 { 00101 return (uint32_t)(this->m_stamp_val / 1000000.0); 00102 } 00103 00104 /* ------------------------------------------------------------------------ */ 00105 uint32_t phTimeStamp::getMicroseconds() const 00106 { 00107 return (uint32_t)(this->m_stamp_val / 1000.0); 00108 } 00109 00110 /* ------------------------------------------------------------------------ */ 00111 uintmax_t phTimeStamp::getNanoseconds() const 00112 { 00113 return (uintmax_t)(this->m_stamp_val); 00114 } 00115 00116 /* ------------------------------------------------------------------------ */ 00117 int phTimeStamp::setFromSeconds (uint32_t sec) 00118 { 00119 this->m_stamp_val = (double)(sec * 1000000000); 00120 return phSUCCESS; 00121 } 00122 00123 /* ------------------------------------------------------------------------ */ 00124 int phTimeStamp::setFromMilliseconds (uint32_t micro) 00125 { 00126 this->m_stamp_val = (double)(micro * 1000000); 00127 return phSUCCESS; 00128 } 00129 00130 /* ------------------------------------------------------------------------ */ 00131 int phTimeStamp::setFromMicroseconds (uint32_t micro) 00132 { 00133 this->m_stamp_val = (double)(micro * 1000); 00134 return phSUCCESS; 00135 } 00136 00137 /* ------------------------------------------------------------------------ */ 00138 int phTimeStamp::setFromNanoseconds (uintmax_t nano ) 00139 { 00140 this->m_stamp_val = (double)nano; 00141 return phSUCCESS; 00142 } 00143 00144 /* ------------------------------------------------------------------------ */ 00145 void phTimeStamp::stamp() 00146 { 00147 #if defined(WIN32) 00148 LARGE_INTEGER li; 00149 if ((this->m_priv) && (QueryPerformanceCounter(&li))) 00150 this->m_stamp_val = ((double)li.QuadPart / (double)(this->m_priv)) * 00151 1000000000.0; 00152 else 00153 this->m_stamp_val = (double)(GetTickCount()) * 1000000.0; 00154 #elif defined(__ADSPBLACKFIN__) 00155 double tick_per = (double)VDK::GetTickPeriod(); 00156 this->m_stamp_val = ((double)VDK::GetUptime()) * 00157 ((double)VDK::GetTickPeriod()) * 00158 1000000.0; 00159 #else 00160 #if USE_TIMEVAL() 00161 double sec = 0; 00162 double usec = 0; 00163 struct timeval tval; 00164 gettimeofday(&tval,NULL); 00165 sec = (double)tval.tv_sec; 00166 usec= (double)tval.tv_usec; 00167 this->m_stamp_val = (sec * 1000000.0 + usec) * 1000.0; 00168 #endif 00169 #if USE_CLOCK() 00170 this->m_stamp_val = ((double)clock() / CLOCKS_PER_SEC) * 1000000000.0; 00171 #endif 00172 #endif 00173 /*phPRINT("%12.8lf\n",this->m_stamp_val);*/ 00174 } 00175 00176 /* ------------------------------------------------------------------------ */ 00177 void phTimeStamp::clear() 00178 { 00179 this->m_stamp_val = 0.0; 00180 } 00181 00182 /* ------------------------------------------------------------------------ */ 00183 bool phTimeStamp::operator ==( const phTimeStamp &right ) const 00184 { 00185 bool retrc = false; 00186 00187 if (this->m_stamp_val == right.m_stamp_val) 00188 { 00189 retrc = true; 00190 } 00191 00192 return retrc; 00193 } 00194 00195 /* ------------------------------------------------------------------------ */ 00196 bool phTimeStamp::operator <( const phTimeStamp &right ) const 00197 { 00198 bool retrc = false; 00199 00200 if (this->m_stamp_val < right.m_stamp_val) 00201 { 00202 retrc = true; 00203 } 00204 00205 return retrc; 00206 } 00207 00208 /* ------------------------------------------------------------------------ */ 00209 bool phTimeStamp::operator !=( const phTimeStamp &right ) const 00210 { 00211 return !(*this == right); 00212 } 00213 00214 /* ------------------------------------------------------------------------ */ 00215 bool phTimeStamp::operator <=( const phTimeStamp &right ) const 00216 { 00217 return !(right < *this); 00218 } 00219 00220 /* ------------------------------------------------------------------------ */ 00221 bool phTimeStamp::operator >( const phTimeStamp &right ) const 00222 { 00223 return (right < *this); 00224 } 00225 00226 /* ------------------------------------------------------------------------ */ 00227 bool phTimeStamp::operator >=( const phTimeStamp &right ) const 00228 { 00229 return !(*this < right); 00230 } 00231 00232 /* ------------------------------------------------------------------------ */ 00233 /* Assignment operator */ 00234 phTimeStamp &phTimeStamp::operator =( const phTimeStamp &right ) 00235 { 00236 if (&right != this) 00237 { 00238 this->m_stamp_val = right.m_stamp_val; 00239 } 00240 00241 return *this; 00242 } 00243 00244 /* ------------------------------------------------------------------------ */ 00245 /* Addition operators */ 00246 phTimeStamp &phTimeStamp::operator +=( const phTimeStamp &right ) 00247 { 00248 this->m_stamp_val += right.m_stamp_val; 00249 00250 return *this; 00251 } 00252 00253 /* ------------------------------------------------------------------------ */ 00254 phTimeStamp phTimeStamp::operator +( const phTimeStamp &right ) 00255 { 00256 phTimeStamp temp; 00257 temp.m_stamp_val = this->m_stamp_val + right.m_stamp_val; 00258 00259 return temp; 00260 } 00261 00262 /* ------------------------------------------------------------------------ */ 00263 /* Subtraction operators */ 00264 phTimeStamp &phTimeStamp::operator -=( const phTimeStamp &right ) 00265 { 00266 this->m_stamp_val -= right.m_stamp_val; 00267 00268 return *this; 00269 } 00270 00271 /* ------------------------------------------------------------------------ */ 00272 phTimeStamp phTimeStamp::operator -( const phTimeStamp &right ) 00273 { 00274 phFUNCTION("phTimeStamp::operator -"); 00275 phTimeStamp temp; 00276 00277 temp.m_stamp_val = this->m_stamp_val - right.m_stamp_val; 00278 00279 return temp; 00280 } 00281 00282 /* ------------------------------------------------------------------------ */ 00283 void phTimeStamp::report(char *label, 00284 FILE *file_desc ) 00285 { 00286 phFUNCTION("phTimeStamp::report") 00287 00288 double sec = 0; 00289 double usec = 0; 00290 double nsec = 0; 00291 00292 if (file_desc == NULL) file_desc = stdout; 00293 00294 sec = (unsigned long)(this->m_stamp_val / 1000000000.0); 00295 usec = (unsigned long)((this->m_stamp_val - (sec * 1000000000)) / 1000); 00296 nsec = (unsigned long)(this->m_stamp_val - 00297 ((sec * 1000000000) + (usec * 1000))); 00298 00299 if (label == NULL) 00300 { 00301 fprintf(file_desc, 00302 "Time - %12.lf [%4.lf(s) %6.lf(us) %6.lf(ns)]\n", 00303 this->m_stamp_val, sec, usec, nsec 00304 ); 00305 } 00306 else 00307 { 00308 fprintf(file_desc, 00309 "(%s)Time - %12.lf [%4.lf(s) %6.lf(us) %6.lf(ns)]\n", 00310 label, 00311 this->m_stamp_val, sec, usec, nsec 00312 ); 00313 } 00314 fflush(file_desc); 00315 } 00316
Copyright (C) 2002 - 2007 |
Philip D.S. Thoren ( pthoren@users.sourceforge.net ) University Of Massachusetts at Lowell Robotics Lab |