wmp_misc.c
Go to the documentation of this file.
00001 /*------------------------------------------------------------------------
00002  *---------------------           RT-WMP              --------------------
00003  *------------------------------------------------------------------------
00004  *                                                         V7.0B  11/05/10
00005  *
00006  *
00007  *  File: ./src/platforms/linux_us/wmp_misc.c                             
00008  *  Authors: Danilo Tardioli                                              
00009  *  ----------------------------------------------------------------------
00010  *  Copyright (C) 2000-2010, Universidad de Zaragoza, SPAIN
00011  *
00012  *  Contact Addresses: Danilo Tardioli                   dantard@unizar.es
00013  *
00014  *  RT-WMP is free software; you can  redistribute it and/or  modify it
00015  *  under the terms of the GNU General Public License  as published by the
00016  *  Free Software Foundation;  either  version 2, or (at  your option) any
00017  *  later version.
00018  *
00019  *  RT-WMP  is distributed  in the  hope  that  it will be   useful, but
00020  *  WITHOUT  ANY  WARRANTY;     without  even the   implied   warranty  of
00021  *  MERCHANTABILITY  or  FITNESS FOR A  PARTICULAR PURPOSE.    See the GNU
00022  *  General Public License for more details.
00023  *
00024  *  You should have received  a  copy of  the  GNU General Public  License
00025  *  distributed with RT-WMP;  see file COPYING.   If not,  write to the
00026  *  Free Software  Foundation,  59 Temple Place  -  Suite 330,  Boston, MA
00027  *  02111-1307, USA.
00028  *
00029  *  As a  special exception, if you  link this  unit  with other  files to
00030  *  produce an   executable,   this unit  does  not  by  itself cause  the
00031  *  resulting executable to be covered by the  GNU General Public License.
00032  *  This exception does  not however invalidate  any other reasons why the
00033  *  executable file might be covered by the GNU Public License.
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         /* Command is the control command to the terminal */
00127         sprintf(command, "%c[%d;%d;%dm", 0x1B, attr, fg + 30, bg + 40);
00128         fprintf(stderr,"%s", command);
00129 }


ros_rt_wmp
Author(s): Danilo Tardioli, dantard@unizar.es
autogenerated on Fri Jan 3 2014 12:07:56