📄 track_log.c
字号:
#ident "@(#) track_log.c v1.0.0"/* * Copyright (C) 2002 Ricardo Arroyo <ricardo.arroyo@eresmas.net> * * This code may be used under the terms of Version 2 of the GPL, * read the file COPYING for details. * * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ******************************************************************************//* Log Track from GPS receive module data * Creates track file in Oziexplorer (www.oziexplorer.com) format. * With permision of Oziexplorer Author */#include <stdio.h>#include <sys/param.h>#include <sys/stat.h>#include <stdlib.h>#include <errno.h>#include <string.h>#include <signal.h>#include "lc_debug.h"#include "lc_msg_q.h"#include "lc_syslog.h"#include "lc_math.h"#include "recGPS.h"#include "gps.h"#include "rGPS_Debug.h"int iDebug;static key_t ktGPSR_q = GPS_REC_Q; /* default GPS reception module queue key */static key_t ktQueue; /* local queue */static int iLocalQid;static int iRemoteQid;/*----------------------------------------------------------------------------*//* FUNCTION : vExitHandler(int iSigId) *//* *//* .- Handles the SIGTERM SIGNAL. *//* deletes rec_GPS input queue *//* *//* INPUT PARAMETERS iSigId: Signal identifier (SIGTERM) *//* *//* OUTPUT PARAMETERS none *//* *//*----------------------------------------------------------------------------*/static void vExitHandler(int iSigId){RGPS_ctlMsg *pMsg = NULL; if (iDebug & DEP_GPSREC) { fprintf(stderr,"vExitHandler: signal=%d\n",iSigId); } // send disconnect message pMsg = malloc(sizeof(RGPS_ctlMsg)); if (iDebug & DEP_GPSREC) { fprintf(stderr,"track_log, pMsg=%lx\n",(long)pMsg); } pMsg->mtype = MSG_CONTROL; pMsg->iRGPSid = GPSREC_DISC; pMsg->RGPSctl.stcRGPS_disc.ktQueue = ktQueue; if (iDebug & DEP_GPSREC) { fprintf(stderr,"track_log/vExitHandler, disconnect message: Queue=%d\n",pMsg->RGPSctl.stcRGPS_disc.ktQueue); } if (iSend2Queue(iRemoteQid, pMsg, sizeof(RGPS_ctlMsg)) < 0) { vLC_syslog(LCLOG_ERR_MSGQSEND, "track_log/vExitHandler", iRemoteQid); } // delete recGPS input Queue// iDelQmsg(iQid); exit(0);}/*----------------------------------------------------------------------------*//* main program *//* Usage: track_log <local_queue_key> *//*----------------------------------------------------------------------------*/int main(int argc, char **argv){ char sGPSdir[MAXPATHLEN]; struct stat buf; FILE *inf; char line[MAXPATHLEN]; RGPS_ctlMsg *pMsg = NULL; RGPS_dataMsg *pDMsg = NULL; time_t tPrevTime = 0; char *p; // *************** Check for Debug environment variable **************** iDebug = ( getenv("GPSNAV_DEBUG") == (char *)0 ? 0 : atoi(getenv("GPSNAV_DEBUG"))); if(argc != 2) { fprintf(stdout,"Usage: track_log <local_queue_key> \n"); exit(-1); } // register SIGTERM handler signal(SIGTERM,vExitHandler); signal(SIGQUIT,vExitHandler); signal(SIGINT,vExitHandler); p = getenv("GPSDIR"); if(p) { (void) strcpy(sGPSdir,p); (void) strcat(sGPSdir,"/"); } else { (void) strcpy(sGPSdir,""); } (void) strcat(sGPSdir,".GPSconf"); if (iDebug & DEP_GPSREC) { fprintf(stderr,"track_log: ConfFile = \"%s\"\n",sGPSdir); } if(!stat(sGPSdir,&buf)) { if(buf.st_mode | S_IRUSR) { if((inf=fopen(sGPSdir,"r"))) { while(fgets(line,MAXPATHLEN,inf)) { if (iDebug & DEP_GPSREC) { fprintf(stderr,"track_log: line = %s\n",line); } if(*line=='#' || *line=='\n') continue; line[strlen(line)-1]='\0'; if(!strncmp(line,"REC_QUEUE",9)) { sscanf(&line[9],"%d",&ktGPSR_q); if (iDebug & DEP_GPSREC) { fprintf(stderr,"track_log: Queue = %d\n",ktGPSR_q); } } } } } } ktQueue = atoi(argv[1]); /* first argument is local queue key */ iLocalQid = iCreateQmsg(ktQueue); if (iLocalQid < 0) { vLC_syslog(LCLOG_ERR_MSGQCREATE, "track_log", ktQueue); exit(-1); } iRemoteQid = iOpenQmsg(ktGPSR_q); if (iRemoteQid < 0) { vLC_syslog(LCLOG_ERR_MSGQOPEN, "track_log", ktGPSR_q); exit(-1); } if (iDebug & DEP_GPSREC) { fprintf(stderr,"track_log, iLocalQid=%d, iRemoteQid=%d\n",iLocalQid, iRemoteQid); } pMsg = malloc(sizeof(RGPS_ctlMsg)); if (iDebug & DEP_GPSREC) { fprintf(stderr,"track_log, pMsg=%lx\n",(long)pMsg); } pMsg->mtype = MSG_CONTROL; pMsg->iRGPSid = GPSREC_CON; pMsg->RGPSctl.stcRGPS_con.ktQueue = ktQueue; pMsg->RGPSctl.stcRGPS_con.iDatum = DT_WGS84; pMsg->RGPSctl.stcRGPS_con.btUnits = UD_ESTATUATE; pMsg->RGPSctl.stcRGPS_con.btPosFormat = PF_HD; if (iDebug & DEP_GPSREC) { fprintf(stderr,"track_log, connect message: Queue=%d, Datum=%d, Units=%d, PosFormat=%d\n", pMsg->RGPSctl.stcRGPS_con.ktQueue, pMsg->RGPSctl.stcRGPS_con.iDatum, pMsg->RGPSctl.stcRGPS_con.btUnits, pMsg->RGPSctl.stcRGPS_con.btPosFormat); } if (iSend2Queue(iRemoteQid, pMsg, sizeof(RGPS_ctlMsg)) < 0) { vLC_syslog(LCLOG_ERR_MSGQSEND, "track_log", iRemoteQid); } /* Print file header */ fprintf(stdout,"OziExplorer Track Point File Version 2.0\n"); fprintf(stdout,"WGS 84\n"); fprintf(stdout,"Altitude is in Feet\n"); fprintf(stdout,"Reserved 3\n"); fprintf(stdout,"0,2,255,LinuxCar generated track,1\n"); fprintf(stdout,"0\n"); fprintf(stdout,"0,0,3,ACTIVE LOG\n"); for(;;) { pDMsg = NULL; pDMsg = (RGPS_dataMsg *)pRecQueue(iLocalQid); if (pDMsg == NULL) { vLC_syslog(LCLOG_ERR_MSGQRECEIVE, "track_log", iLocalQid); exit (-1); } /* message received */ if (iDebug & DEP_GPSREC) { fprintf(stderr,"track_log, message received: Type=%ld, Id=%d\n",pDMsg->mtype, pDMsg->iRGPSid); } if (pDMsg->mtype == MSG_CONTROL) { free(pDMsg); pDMsg = NULL; } else { switch (pDMsg->iRGPSid) { case GPSSEND_POS: if (iDebug & DEP_GPSREC) { vPrint_Debug_DataPos(pDMsg, "track_log"); } fprintf(stdout," %2.8f, %2.8f, %d, %4.0f,%5.7f\r\n", pDMsg->RGPSpos.stcD.dNorth, pDMsg->RGPSpos.stcD.dEast, ( tPrevTime + 1 == pDMsg->tTime ? 0 : 1), pDMsg->dAltitude, dUnixtime2Windatetime(pDMsg->tTime)); tPrevTime = pDMsg->tTime; free(pDMsg); pDMsg = NULL; break; default: free(pDMsg); pDMsg = NULL; break; } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -