Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include <sys/time.h>
00038 #include <unistd.h>
00039 #include <stdio.h>
00040 #include <time.h>
00041
00042 unsigned long long timeZero=0;
00043
00044
00045 unsigned long getActualTimems() {
00046 static int initialized = 0;
00047 long timer = 0;
00048 if (!initialized) {
00049 initialized = 1;
00050 struct timeval tv;
00051 gettimeofday(&tv, 0);
00052 unsigned long long tmp = (tv.tv_sec) * 1000000LL;
00053 tmp += tv.tv_usec;
00054 timeZero = tmp;
00055 }
00056
00057 struct timeval tv;
00058 gettimeofday(&tv, 0);
00059 unsigned long long tmp = (tv.tv_sec) * 1000000LL;
00060 tmp += tv.tv_usec;
00061 tmp = tmp - timeZero;
00062 tmp = (unsigned long long) ((double) tmp / 1000.0);
00063 return (unsigned long) tmp;
00064 }
00065
00066
00067 unsigned long long getActualTimeus(){
00068 static int initialized = 0;
00069 long timer=0;
00070 if (!initialized) {
00071 initialized=1;
00072 struct timeval tv;
00073 gettimeofday(&tv,0);
00074 unsigned long long tmp=(tv.tv_sec)*1000000LL;
00075 tmp+=tv.tv_usec;
00076 timeZero=tmp;
00077 }
00078 struct timeval tv;
00079 gettimeofday(&tv,0);
00080 unsigned long long tmp=(tv.tv_sec)*1000000LL;
00081 tmp+=tv.tv_usec;
00082 tmp=tmp-timeZero;
00083 return tmp;
00084 }
00085
00086 void mssleep(int ms){
00087 int i;
00088 long us=ms*1000;
00089 int n_iterations=us /1000000;
00090 int remaining=us % 1000000;
00091 for (i=0;i<n_iterations;i++){
00092 usleep(999999);
00093 }
00094 usleep((unsigned int)(remaining*0.99));
00095 }
00096
00097 unsigned long long getActualDateus(){
00098 unsigned long long timer=0;
00099 struct timeval tv;
00100 gettimeofday(&tv,0);
00101 unsigned long long tmp=(tv.tv_sec)*1000000LL;
00102 tmp+=tv.tv_usec;
00103 return tmp;
00104 }
00105
00106 unsigned long long getRawActualTimeus() {
00107 struct timeval tv;
00108 gettimeofday(&tv, 0);
00109 unsigned long long tim1=tv.tv_sec;
00110 tim1*=1000000;
00111 tim1+=tv.tv_usec;
00112 return tim1;
00113 }
00114
00115
00116 void wmp_get_timestamp(char *timecad){
00117 struct tm *tmPtr;
00118 time_t tiempo;
00119 tiempo = time(NULL);
00120 tmPtr = localtime(&tiempo);
00121 strftime(timecad, 80, "%Y-%m-%d_%H-%M", tmPtr);
00122 }
00123
00124 void textcolor(int attr, int fg, int bg)
00125 { char command[13];
00126
00127 sprintf(command, "%c[%d;%d;%dm", 0x1B, attr, fg + 30, bg + 40);
00128 fprintf(stderr,"%s", command);
00129 }