📄 ogr_inout.c
字号:
/* ************************************************************************ * * * OpenGPS Receiver * * * * -------------------------------------------------------------------- * * * * Module: ogr_inout.c * * * * Version: 0.1 * * * * Date: 30.06.02 * * * * Author: C. Kelley, G. Beyerle * * * * -------------------------------------------------------------------- * * * * Copyright (C) 2001-2003 C. Kelley, 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 'gpsfuncs.cpp', 'gpsrcvr.cpp' are modified versions of * * the files with the same name from Clifford Kelley's OpenSourceGPS * * distribution. The unmodified files can be obtained from * * http://www.home.earthlink.net/~cwkelley * * * * -------------------------------------------------------------------- * * * * Input / Output functions * * * ************************************************************************ *//* ******************************* changes ******************************** 18.07.03 - updated help screen ************************************************************************ *//* ------------------------------- includes ------------------------------- */#include <stdio.h>#include <stdlib.h>#include <math.h>#include <string.h>#include <time.h>#include <fcntl.h> #include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include "port.h"#include "ogr_defines.h"#include "ogr_structs.h"#include "ogr_prototypes.h"#include "ogr_globals.h"/* ------------------------------- defines -------------------------------- */// file names are defined here#define LOC_FILE "../input/current.loc"#define ALM_FILE "../input/current.alm"#define EPH_FILE "../input/current.eph"#define RCVR_FILE "../input/receiverpars.dat"#define IONUTC_FILE "../input/ionoclock.dat"/* ------------------------------- prototypes ----------------------------- *//* ------------------------------- globals -------------------------------- *//* ------------------------------- procedures ----------------------------- */void open_dump_file( void){ char tmpfile[256]; if ( FpDmp) return; sprintf( DmpFileName, "dmp-%03d-%06ld.dat", Ctrl.gps_week, RT_Ctrl->tow_tic_count/10); sprintf( tmpfile, "../output/%s", DmpFileName); if (( FpDmp = fopen( tmpfile, "wb")) == NULL) { printf( "ogr: error opening file %s.\n", tmpfile); user_exit( 0); } return;}/* * close nav info dump file */void close_dump_file( void){ if ( !FpDmp) return; fclose( FpDmp); FpDmp = NULL; return;}/* * open dump file (ASCII) */void open_dump_file_ascii( void){ char tmpfile[256]; if ( FpDmpASCII || Ctrl.status != mode_navigate) return; sprintf( DmpASCIIFileName, "out-%03d-%06ld.dat", Ctrl.gps_week, RT_Ctrl->tow_tic_count/10); sprintf( tmpfile, "../output/%s", DmpASCIIFileName); if (( FpDmpASCII = fopen( tmpfile, "wb")) == NULL) { printf( "ogr: error opening file %s.\n", tmpfile); user_exit( 0); } fprintf( FpDmpASCII, "# prn elev az power \n"); return;}/* * write elevation/azimuth data to file */void write_dump_file_ascii( INT16 nof_trk, INT16 tr_ch[], ECEF rpos){ int n, prn, ch; double elev, az, i, q; ECEF xpos; for ( n=0; n<nof_trk; n++) { ch = tr_ch[n]; prn = Chan[ch].prn; xpos = Xmit_Info[prn].pos; // get azimuth and elevation for this PRN calc_elevation_azimuth( &elev, &az, xpos, rpos); i = Chan[ch].i_prompt_20ms + Chan[ch].i_dith_20ms; q = Chan[ch].q_prompt_20ms + Chan[ch].q_dith_20ms; fprintf( FpDmpASCII, "%2d %7.3f %7.3f %.4e\n", prn, elev * RAD2DEG, az * RAD2DEG, i*i + q*q); } return;}/* * close nav info dump file */void close_dump_file_ascii( void){ if ( !FpDmpASCII) return; fclose( FpDmpASCII); FpDmpASCII = NULL; return;}/* * dump nav info (G*RM*N binary format) to file. * it is sufficient to write msg 0x0e, 0x11 and 0xff just once */void write_info_dump_file( double lat, double lon, time_t thetime){ struct tm *gmt; if ( !FpDmp) return; gmt = gmtime( &thetime); write_msg_0x0e( FpDmp, gmt); write_msg_0x11( FpDmp, lat, lon); write_msg_0xff( FpDmp); return;}/* * read key:value pair from parameter file */static INT16 read_key_value_pair_double( char *tok, char pattern[], double *val, char sep[]){ char *token; INT16 ret = 0; if ( strstr( tok, pattern)) { token = strtok( NULL, sep); if ( token) { sscanf( token, "%le", val); printf( "ogr: key pattern %s = %f\n", pattern, *val); ret = 1; } } return (ret);} #if 0/* * read key:value pair from parameter file */static INT16 read_key_value_pair_float( char *tok, char pattern[], float *val, char sep[]){ char *token; INT16 ret = 0; if ( strstr( tok, pattern)) { token = strtok( NULL, sep); if ( token) { sscanf( token, "%f", val);// printf( "%s = %f\n", pattern, *val); ret = 1; } } return (ret);} #endifstatic INT16 read_key_value_pair_int( char *tok, char pattern[], INT16 *val, char sep[]){ char *token; INT16 ret = 0; if ( strstr( tok, pattern)) { token = strtok( NULL, sep); if ( token) { sscanf( token, "%hd", val);// printf( "%s = %d\n", pattern, *val); ret = 1; } } return (ret);} #if 0static INT16 read_key_value_pair_uint( char *tok, char pattern[], UINT16 *val, char sep[]){ char *token; INT16 ret = 0; if ( strstr( tok, pattern)) { token = strtok( NULL, sep); if ( token) { sscanf( token, "%hd", val);// printf( "%s = %d\n", pattern, *val); ret = 1; } } return (ret);} #endif static INT16 read_key_value_pair_long( char *tok, char pattern[], long *val, char sep[]){ char *token; INT16 ret = 0; if ( strstr( tok, pattern)) { token = strtok( NULL, sep); if ( token) { sscanf( token, "%ld", val);// printf( "%s = %ld\n", pattern, *val); ret = 1; } } return (ret);} /*******************************************************************************FUNCTION read_rcvr_par()RETURNS None.PARAMETERS None.PURPOSE To read in from the rcvr_par file the receiver parameters that control acquisition, tracking etc.WRITTEN BY Clifford Kelley Modified by G. Beyerle*******************************************************************************/void read_rcvr_par( RT_CTRL* rt_par, CTRL* par){ char infile[] = RCVR_FILE; FILE *fp; if (( fp = fopen( infile, "rt")) == NULL) { printf( "ogr: error opening parameter file '%s'.\n", infile); perror( NULL); exit(-1); } else {#define SPSIZE 200 INT16 loop = 1, ret; char buf[SPSIZE]; char sep[] = ":"; /* list of token separators */ char *token; // printf( "Read parameter from file '%s' ...\n", tmpstr); while ( !feof( fp) && loop) { fgets( buf, SPSIZE, fp); if ( buf[0] == '#') continue; token = strtok( buf, sep); // format is <keyword> : <value> if ( token) { ret = read_key_value_pair_double( token, "Mask Angle(deg)", &par->mask_angle, sep); if ( ret) { par->mask_angle /= RAD2DEG; printf( "ogr: set mask_angle to %e\n", par->mask_angle); } if ( !ret) ret = read_key_value_pair_double( token, "Clock offset(ppm)", &par->clock_offset, sep); if ( !ret) ret = read_key_value_pair_long( token, "Acq threshold", &rt_par->acq_thresh, sep); if ( !ret) ret = read_key_value_pair_int( token, "search_min_f", &rt_par->search_min_f, sep); if ( !ret) ret = read_key_value_pair_int( token, "cold_prn", &Ctrl.cold_prn, sep);#if 0// if ( !ret)// ret = read_key_value_pair_long( token, // "noise rms", &par->rms, sep); if ( !ret) ret = read_key_value_pair_long( token, "pull_code_k", &rt_par->pull_code_k, sep); if ( !ret) ret = read_key_value_pair_long( token, "pull_code_d", &rt_par->pull_code_d, sep); if ( !ret) ret = read_key_value_pair_long( token, "pull_carr_k", &rt_par->pull_carr_k, sep); if ( !ret) ret = read_key_value_pair_long( token, "pull_carr_d", &rt_par->pull_carr_d, sep); if ( !ret) ret = read_key_value_pair_long( token, "trk_code_k", &rt_par->trk_code_k, sep); if ( !ret) ret = read_key_value_pair_long( token, "trk_code_d", &rt_par->trk_code_d, sep); if ( !ret) ret = read_key_value_pair_long( token, "trk_carr_k", &rt_par->trk_carr_k, sep); if ( !ret) ret = read_key_value_pair_long( token, "trk_carr_d", &rt_par->trk_carr_d, sep);#endif// code PLL parameter (pull-in) if ( !ret) ret = read_key_value_pair_double( token, "pul_cod_dampratio", &par->pul_cod_dampratio, sep); if ( !ret) ret = read_key_value_pair_double( token, "pul_cod_loopgain", &par->pul_cod_loopgain, sep); if ( !ret) ret = read_key_value_pair_double( token, "pul_cod_bandwidth", &par->pul_cod_bandwidth, sep);// carier PLL parameter (pull-in) if ( !ret) ret = read_key_value_pair_double( token, "pul_car_dampratio", &par->pul_car_dampratio, sep); if ( !ret) ret = read_key_value_pair_double( token, "pul_car_loopgain", &par->pul_car_loopgain, sep); if ( !ret) ret = read_key_value_pair_double( token, "pul_car_bandwidth", &par->pul_car_bandwidth, sep);// code PLL parameter (tracking) if ( !ret) ret = read_key_value_pair_double( token, "trk_cod_dampratio", &par->trk_cod_dampratio, sep); if ( !ret) ret = read_key_value_pair_double( token, "trk_cod_loopgain", &par->trk_cod_loopgain, sep); if ( !ret) ret = read_key_value_pair_double( token, "trk_cod_bandwidth", &par->trk_cod_bandwidth, sep);// carier PLL parameter (tracking) if ( !ret) ret = read_key_value_pair_double( token, "trk_car_dampratio", &par->trk_car_dampratio, sep); if ( !ret) ret = read_key_value_pair_double( token, "trk_car_loopgain", &par->trk_car_loopgain, sep); if ( !ret) ret = read_key_value_pair_double( token, "trk_car_bandwidth", &par->trk_car_bandwidth, sep); if ( !ret) ret = read_key_value_pair_double( token, "nav_update(s)", &par->nav_upd, sep);#if 0 if ( !ret) ret = read_key_value_pair_int( token, "pull_in_time(ms)", &rt_par->pull_in_count_max, sep); if ( !ret) ret = read_key_value_pair_int( token, "phase_test(ms)", &rt_par->phase_test, sep);#endif if ( !ret) ret = read_key_value_pair_long( token,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -