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

📄 test_recgps.c

📁 open source for car navigation in linux
💻 C
字号:
#ident "@(#) test_recGPS.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. ******************************************************************************//*Test of GPS Reception module*/#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 "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,"test_recGPS, 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,"test_recGPS/vExitHandler, disconnect message: Queue=%d\n",pMsg->RGPSctl.stcRGPS_disc.ktQueue);    }    if (iSend2Queue(iRemoteQid, pMsg, sizeof(RGPS_ctlMsg)) < 0)    {        vLC_syslog(LCLOG_ERR_MSGQSEND, "test_recGPS/vExitHandler", iRemoteQid);    }    // delete recGPS input Queue//    iDelQmsg(iQid);    exit(0);}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;    char *p;    // *************** Check for Debug environment variable ****************    iDebug = ( getenv("GPSNAV_DEBUG") == (char *)0 ? 0 : atoi(getenv("GPSNAV_DEBUG")));    if(argc != 5)    {        fprintf(stdout,"Usage: test_recGPS <local_queue_key> <Datum> <Units> <PosFormat>\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,"test_recGPS: 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,"test_recGPS: 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,"Init_Jeeps: 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, "test_recGPS", ktQueue);	exit(-1);    }    iRemoteQid = iOpenQmsg(ktGPSR_q);    if (iRemoteQid < 0)    {        vLC_syslog(LCLOG_ERR_MSGQOPEN, "test_recGPS", ktGPSR_q);	exit(-1);    }    if (iDebug & DEP_GPSREC)    {        fprintf(stderr,"test_recGPS, iLocalQid=%d, iRemoteQid=%d\n",iLocalQid, iRemoteQid);    }    pMsg = malloc(sizeof(RGPS_ctlMsg));    if (iDebug & DEP_GPSREC)    {        fprintf(stderr,"test_recGPS, pMsg=%lx\n",(long)pMsg);    }    pMsg->mtype = MSG_CONTROL;    pMsg->iRGPSid = GPSREC_CON;    pMsg->RGPSctl.stcRGPS_con.ktQueue = ktQueue;    pMsg->RGPSctl.stcRGPS_con.iDatum = atoi(argv[2]);    pMsg->RGPSctl.stcRGPS_con.btUnits = atoi(argv[3]);    pMsg->RGPSctl.stcRGPS_con.btPosFormat = atoi(argv[4]);    if (iDebug & DEP_GPSREC)    {        fprintf(stderr,"test_recGPS, 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, "test_recGPS", iRemoteQid);    }    for(;;)    {        pDMsg = NULL;	pDMsg = (RGPS_dataMsg *)pRecQueue(iLocalQid);	if (pDMsg == NULL)	{	    vLC_syslog(LCLOG_ERR_MSGQRECEIVE, "test_recGPS", iLocalQid);	    exit (-1);	}	/* message received */        if (iDebug & DEP_GPSREC)        {            fprintf(stderr,"test_recGPS, 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, "test_recGPS");			}                    free(pDMsg);		    pDMsg = NULL;		    break;	        default:		    free(pDMsg);		    pDMsg = NULL;		    break;	    }	}    }}

⌨️ 快捷键说明

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