📄 ogsxmit.c
字号:
/* ************************************************************************ * * * GPS Simulation * * * * -------------------------------------------------------------------- * * * * Module: ogsxmit.cpp * * * * Version: 0.1 * * * * Date: 17.02.02 * * * * Author: G. Beyerle * * * * -------------------------------------------------------------------- * * * * Copyright (C) 2002-2006 Georg 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' and 'gp2021.cpp' are modi- * * fied 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 * * * * -------------------------------------------------------------------- * * * * GPS signal transmitter * * * ************************************************************************ *//* ******************************* changes ******************************** dd.mm.yy - ************************************************************************ */// to do:// - fill struct iono_data und struct UTC_data / 17.2.02// - parity bits// - check calc of parity in parity_check()/* ------------------------------- includes ------------------------------- */#include <stdio.h>#include <stdlib.h>#include <math.h>#include <string.h>#include <time.h>#include <assert.h>#include "ogsdefine.h"#include "ogsstructs.h"#include "ogsprototypes.h"#include "ogslibrary.h"#include "boxmuller.h"#define MAIN#include "ogsextern.h"#undef MAIN/* ------------------------------- defines -------------------------------- *///#define XMTRBUFLEN 500000#define XMTRBUFLEN 150000//#define XMTRBUFLEN 1000/* ------------------------------- structs -------------------------------- */typedef struct{ int active, inhibited; int prn; // satellite id long carrier_cycle_counter; // # of positive going zero crossings of i_lo long code_phase_counter; long carrier_dco_incr, // 26 bit, frq res. is 42.57475 mHz carrier_dco_phase, // carrier cycle fraction / phase in 2pi/1024 increments code_dco_phase, code_dco_incr; int epoch_counter, epoch_1ms, // 0,...,19; 1 msec (1 C/A) code epoch epoch_20ms; // 0,...,49; 20 msec (20 C/A, 1 data bit) epoch} XMTRINFO;XMTRINFO XmtrInfo[NOFSAT+1];/* ------------------------------- globals -------------------------------- *///static double const SampleFrq = 5.714e6;//static double const CarrierFrq = 1.405396825e6;//static double const CodeFrq = 1.023e6;static double SampleTime = 0;char *NavFrame[NOFSAT+1];static int HalfChip_Counter[NOFSAT+1];// phase countersstatic unsigned long Carrier_Cycle[NOFSAT+1], Code_Cycle[NOFSAT+1], CACode_Counter[NOFSAT+1]; // 0,...,20*1500-1static double Carrier_DCO_Cycle[NOFSAT+1];//static int Carrier_DCO_I[] = {-1,1,2, 2, 1,-1,-2,-2};static int Carrier_DCO_I[] = {2, 2, 1, -1, -2, -2, -1, 1};static unsigned char XmtrBuf[XMTRBUFLEN];static char *NavBit[NOFSAT+1];static float QuantThresh, // quantization theshold Noise_dB, // noise added to signal Noise_Ampl, // noise added to signal MaxTime;static float Latitude, Longitude; // receiver locationchar ProgramName[] = "ogsxmit";static char Version[] = "0.1.1";extern char *OutputFileName;extern char *NavFilePattern;extern int OverWrite;extern long CounterStartValue;/* -------------------------- prototypen (global) ------------------------- */void getargs( int argc, char *argv[]);/* ------------------------------ procedures ------------------------------ */void usage( void){ printf( "usage: %s [options]\n", ProgramName); printf( "version %s (compiled %s %s) \n", Version, __DATE__, __TIME__); printf( " options:\n"); printf( " -h : print this message \n"); printf( " -v : verbose \n"); printf( " -f : overwrite existing files \n"); printf( " -n <pat> : navigation file pattern <pat> \n"); printf( " -o <file> : write data to 'data/'<file> ['ogsraw.dat'] \n"); exit(0);}void check_options( void){ if ( !NavFilePattern) { printf( "No navigation file selected (option -n)."); exit(-1); } return;}//// read parameters from file// adapted from read_rcvr_par() (c) Clifford Kelley//static void read_xmit_par( void){ char infile[] = "xmit_par.dat", *tmpstr; FILE *in; tmpstr = conmalloc( strlen( OGSBinDir) + strlen( infile) + 1); strcpy( tmpstr, OGSBinDir); strcat( tmpstr, infile); if (( in = fopen( tmpstr, "rt")) == NULL) { printf( "Error opening parameter file '%s'.\n", tmpstr); perror( NULL); exit( 0); } else {#define SPSIZE 200 int loop = 1, ret; char buf[SPSIZE]; char sep[] = ":"; /* list of token separators */ char *token; printf( "Read parameter from file '%s' ...\n", tmpstr); while ( !feof( in) && loop) { fgets( buf, SPSIZE, in); if ( buf[0] == '#') continue; token = strtok( buf, sep); // format is <keyword> : <value> if ( token) { ret = read_key_value_pair_float( token, "Quantiz. Threshold", &QuantThresh, sep); if ( !ret) ret = read_key_value_pair_float( token, "Noise [dB]", &Noise_dB, sep); if ( !ret) ret = read_key_value_pair_float( token, "Max. Time [sec]", &MaxTime, sep); if ( !ret) ret = read_key_value_pair_float( token, "latitude [deg]", &Latitude, sep); if ( !ret) ret = read_key_value_pair_float( token, "longitude [deg]", &Longitude, sep); if ( !ret) { token = strtok( NULL, sep); if ( token) { printf( "unkown keyword >%s< in file %s\n", buf, tmpstr); exit( -1); } } } else// --- token is NULL --- loop = 0; } // --- while ( !feof( in) && loop) --- } fclose( in); if ( Verbose) { printf( "Finished reading parameter file %s.\n", tmpstr); printf( "Press ENTER\n"); getchar(); } if ( tmpstr) free( tmpstr); return;}//// initialize carrier and code counter increments//static void init_struct_xmitter( void){ int i; for ( i=1; i<=NOFSAT; i++) { XmtrInfo[i].carrier_dco_incr = 0x1f7b1b9L; // 33010105 * 42.57475 mHz = 1405396.968 Hz XmtrInfo[i].code_dco_incr = 0x16ea4a8L; // 24028328 * 42.57475 mHz = 1023000.058 Hz// start nav message at bit position CounterStartValue (out of 1500) CACode_Counter[i] = 20 * CounterStartValue; } return;}//// calculate GPS C/A signal//static int calc_raw_sgn( void){ int i, j, cidx, didx, nidx, prn; int sgn = 0; int savsgn; short int ca_prompt; char navbit; float sgnflt; char d;// float tmp, savtmp;// nofprn = 0; for ( prn=1; prn<=NOFSAT; prn++) { if ( NavBit[prn]) {//// increment carrier and code cycle counter// Carrier_Cycle[prn] += XmtrInfo[prn].carrier_dco_incr; Code_Cycle[prn] += XmtrInfo[prn].code_dco_incr;// printf(" Carrier_Cycle[%d] = %d\n", prn, Carrier_Cycle[prn]);// printf(" Code_Cycle[%d] = %d\n", prn, Code_Cycle[prn]); //// carrier DCO: 2^27 = 0x8000000 corresponds to 1 carrier cycle (1.4 MHz)// if ( Carrier_Cycle[prn] & (0x1 << 27)) { Carrier_Cycle[prn] &= ~(0x1f << 27); // clear top 5 bits XmtrInfo[prn].carrier_cycle_counter += 1; }//// code DCO: 2^26 = 0x4000000 corresponds to 1/2 chip (2*1.023 MHz)// 2^27 = 0x8000000 corresponds to 1 chip (1.023 MHz)// if ( Code_Cycle[prn] & (0x1 << 26)) { Code_Cycle[prn] &= ~(0x3f << 26); // clear top 6 bits HalfChip_Counter[prn] += 1; } if ( HalfChip_Counter[prn] == 2046) { HalfChip_Counter[prn] = 0; CACode_Counter[prn] += 1;// printf("CACode_Counter[%d] = %d\n", prn, CACode_Counter[prn]);// getchar(); }// wrap around after 1 frame (5 subframes, 5x300 bits) CACode_Counter[prn] = CACode_Counter[prn] % (20*NAVMSGLEN); //// index in sin/cos look-up table (8-phase)// cidx = (Carrier_Cycle[prn] >> 24) & 0x7;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -