⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ogr_timefun.c

📁 The OpenGPSRec receiver software runs on the real time operating system RTAI-Linux. It compiles with
💻 C
字号:
/* ************************************************************************    *                                                                      *   *                            OpenGPS Receiver                          *   *                                                                      *   * -------------------------------------------------------------------- *   *                                                                      *   *    Module:   ogr_timefun.c                                           *   *                                                                      *   *   Version:   0.1                                                     *   *                                                                      *   *      Date:   09.12.02                                                *   *                                                                      *   *    Author:   C. Kelley, G. Beyerle                                   *   *                                                                      *   * -------------------------------------------------------------------- *   *                                                                      *   * Copyright (C) 2001-2002 C. Kelley, 2003 G. Beyerle                   *   *                                                                      *   * This program is free software; you can redistribute it and/or modify *   * it under the terms of the GNU General Public License as published by *   * the Free Software Foundation; either version 2 of the License, or    *   * (at your option) any later version.                                  *   *                                                                      *   * This program is distributed in the hope that it will be useful,      *   * but WITHOUT ANY WARRANTY; without even the implied warranty of       *   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *   * GNU General Public License for more details.                         *   *                                                                      *   * You should have received a copy of the GNU General Public License    *   * along with this program; if not, write to the Free Software          *   * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.            *   *                                                                      *   * -------------------------------------------------------------------- *   *                                                                      *   * The files 'ogr_user.c', 'ogr_navdecode.c', 'ogr_navsolve.c',         *   * 'ogr_rtproc.c' are modified versions of the files 'gpsfuncs.cpp',    *   * 'gpsrcvr.cpp' from Clifford Kelley's OpenSourceGPS distribution.     *   * The unmodified files can be obtained from                            *   *             http://www.home.earthlink.net/~cwkelley                  *   *                                                                      *   * -------------------------------------------------------------------- *   *                                                                      *   *                      Time and date function                          *   *                                                                      *   ************************************************************************ *//* ******************************* changes ********************************   dd.mm.yy -   ************************************************************************ *//***********************************************************************  GPS RECEIVER (GPSRCVR) Ver. 1.02  12 Channel All-in-View GPS Receiver Program based on Mitel GP2021  chipset  Clifford Kelley cwkelley@earthlink.net  Copyright (c) 1996-2001 Clifford Kelley.  All Rights Reserved.  This LICENSE must be included with the GPSRCVR code.***********************************************************************//*Redistribution and use in source and binary forms, with or withoutmodification, are permitted provided that the following conditions aremet:      CONDITIONS1. Redistributions of GPSRCVR source code must retain the above copyrightnotice, this list of conditions, and the following disclaimer.2. Redistributions in binary form must contain the above copyrightnotice, this list of conditions and the following disclaimer in thedocumentation and/or other materials provided with the distribution.3. All modifications to the source code must be clearly marked assuch.  Binary redistributions based on modified source code must beclearly marked as modified versions in the documentation and/or othermaterials provided with the distribution.4. Notice must be given of the location of the availability of theunmodified current source code, e.g.,  http://www.Kelley.com/or  ftp://ftp.Kelley.comin the documentation and/or other materials provided with thedistribution.5. All advertising and published materials mentioning features or useof this software must display the following acknowledgment:  "Thisproduct includes software developed by Clifford Kelley and othercontributors."6. The name of Clifford Kelley may not be used to endorse or promoteproducts derived from this software without specific prior writtenpermission.      DISCLAIMERThis software is provided by Clifford Kelley and contributors "as is" andany expressed or implied warranties, including, but not limited to, theimplied warranties of merchantability and fitness for a particularpurpose are disclaimed.  In no event shall Clifford Kelley orcontributors be liable for any direct, indirect, incidental, special,exemplary, or consequential damages (including, but not limited to,procurement of substitute goods or services; loss of use, data, orprofits; or business interruption) however caused and on any theory ofliability, whether in contract, strict liability, or tort (includingnegligence or otherwise) arising in any way out of the use of thissoftware, even if advised of the possibility of such damage.*//* ------------------------------- includes ------------------------------- */#include  <stdio.h>#include  <stdlib.h>#include  <math.h>#include  <string.h>#include  <time.h>#include  <assert.h>#include  "port.h"#include  "ogr_defines.h"#include  "ogr_structs.h"#include  "ogr_prototypes.h"#include  "ogr_globals.h"/* ----------------------------- defines --------------------------------- *//* ---------------------------- prototypen -------------------------------- *//* ---------------------------- globals ----------------------------------- *//* ---------------------------- procedures -------------------------------- *//* *  convert yy.mm.dd hh:mm:ss to Julian date (GPS time!) */void gmt2julian( double *time_s, INT16 *gps_week, struct tm *gmt){  INT16     jd_m;  long      jd_yr;// set up the correct time  if ( gmt->tm_mon <= 1)  {// *** tm_year : years since 1900! ***    jd_yr = (INT32)( 365.25*(gmt->tm_year-1.0+1900.0));    jd_m  = (INT16)( 30.6001*(gmt->tm_mon+14.0));  }  else  {    jd_yr = (INT32)( 365.25*(gmt->tm_year+1900.0));    jd_m  = (INT16)( 30.6001*(gmt->tm_mon+2.0));  }// Julian(?) date  *time_s = gmt->tm_min / 1440.0 +            gmt->tm_sec / 86400.0 +            1720981.5 +            gmt->tm_hour / 24.0 + jd_yr + jd_m +            gmt->tm_mday;  *gps_week = (INT16)( (*time_s - 2444244.5) / 7.0);  return;}#include <sys/time.h>#include <unistd.h>#include <signal.h>/* *  wait for t seconds */void delay( double t){  struct itimerval scantime;  scantime.it_value.tv_sec  = 0;     scantime.it_value.tv_usec = (long) (t*1e6);  setitimer( ITIMER_REAL, &scantime, NULL);  pause();      /* wait for alarm */}#if 0/* * source: * From: Mark Lord (mlord@bnr.ca) * Subject: Re: port DOS games to Linux..?  * Newsgroups:comp.os.linux.misc * Date: 1994-01-28 13:21:10 PST  */#include <signal.h>#include <stdlib.h>#include <time.h>static volatile int usleep_in_progress = 0;static void handle_SIGALRM( void){  usleep_in_progress = 0;}void usleep( unsigned int useconds){  struct itimerval new, old;  if ( !useconds)   {    sleep( 0);    return;  }  if (useconds < 1000000)   { /* avoid division on shorter delays */    new.it_value.tv_sec  = 0;    new.it_value.tv_usec = useconds;  }   else   {    new.it_value.tv_sec  = useconds / 1000000;    new.it_value.tv_usec = useconds % 1000000;  }  new.it_interval.tv_sec = 0;  /* 0 = one-shot timer */  new.it_interval.tv_usec = 0;  signal (SIGALRM, &handle_SIGALRM); /* install timeout handler */  usleep_in_progress = 1;   /* this is reset by handler */ /* Start the timer.  It will signal with SIGALRM when it expires */  if (setitimer(ITIMER_REAL, &new, &old))   {    fprintf(stderr, "usleep: could not set ITIMER_REAL\n");    abort();  }  while ( usleep_in_progress) /* wait for timer expiry */    pause();  /* wait for signals */}main(int argc, char *argv[]){ /* expects one parameter:  a count of micro-seconds to sleep for: */ int delay; delay = atoi(*++argv); fprintf(stderr,"Sleeping for %d useconds..\n", delay); usleep(delay);}#endif#if 0/* Short program to illustrate timing problems under Linux */#include <sys/time.h>#include <unistd.h>#include <signal.h>static struct timeval stoptime;static struct timezone stopzone;void scan_alarm_()           /* alarm handler */{gettimeofday(&stoptime,&stopzone);return;}main(){struct sigaction alrmhand;struct itimerval scantime;struct timeval testtime;struct timezone testzone;const long int mytimeint = 2;long int timeerr;int i;/* set up signal handler */alrmhand.sa_handler = scan_alarm_;alrmhand.sa_mask = 0;alrmhand.sa_flags = SA_RESTART;alrmhand.sa_restorer = NULL;sigaction(SIGALRM, &alrmhand, NULL);/* set up timer value */scantime.it_value.tv_sec = mytimeint;   scantime.it_value.tv_usec = 0;/* now time the timer! */for(i=0;i<=10;i++)  {  gettimeofday(&testtime, &testzone); /* before setting timer */  setitimer(ITIMER_REAL, &scantime, NULL); /* start timer */  pause();      /* wait for alarm */  timeerr = (stoptime.tv_sec - testtime.tv_sec)*1000000 +     (stoptime.tv_usec - testtime.tv_usec) - (mytimeint*1000000);  printf("Error in time measurement: %d usecs\n", timeerr);  } }#endif/* ------------------------------- end of file ---------------------------- */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -