Xendweek.cpp

Go to the documentation of this file.
00001 /* $Id: Xendweek.cpp 1895 2009-05-12 19:34:29Z afarris $
00002 *  Xendweek.c - Test scaffold for demonstrating correctness of the 
00003 *  SVPCodeGen class.  In this case, the test is to correctly generate
00004 *  the P-code for the last 6 seconds of the week for each possible
00005 *  GPS PRN.
00006 *
00007 *  August 2003
00008 *  Applied Reserach Laboratories, The University of Texas at Austin
00009 */
00010 
00011 //============================================================================
00012 //
00013 //  This file is part of GPSTk, the GPS Toolkit.
00014 //
00015 //  The GPSTk is free software; you can redistribute it and/or modify
00016 //  it under the terms of the GNU Lesser General Public License as published
00017 //  by the Free Software Foundation; either version 2.1 of the License, or
00018 //  any later version.
00019 //
00020 //  The GPSTk is distributed in the hope that it will be useful,
00021 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 //  GNU Lesser General Public License for more details.
00024 //
00025 //  You should have received a copy of the GNU Lesser General Public
00026 //  License along with GPSTk; if not, write to the Free Software Foundation,
00027 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00028 //  
00029 //  Copyright 2009, The University of Texas at Austin
00030 //
00031 //============================================================================
00032 
00033    // Language headers
00034 #include <stdlib.h>
00035 #include <stdio.h>
00036 #include <map>
00037 
00038    // Project headers
00039 #include "PCodeConst.hpp"
00040 #include "SVPCodeGen.hpp"
00041 #include "CodeBuffer.hpp"
00042 #include "X1Sequence.hpp"
00043 #include "X2Sequence.hpp"
00044 
00050 using namespace std;    // for map and pair access
00051 using namespace gpstk;
00052 
00053    //  Convenience structure for grouping all the data objects associated
00054    //  with a single SV.  These structs are commonly placed in maps for
00055    //  processing.
00056 struct SVData
00057 {
00058    SVPCodeGen *           PCodeGen;
00059    CodeBuffer *           PCodeBuf;
00060    codeType               cType;
00061    SVData( SVPCodeGen *         a1,
00062            CodeBuffer *         a2,
00063            codeType             c )
00064    { 
00065       PCodeGen = a1;
00066       PCodeBuf = a2;
00067       cType    = c; 
00068    };
00069 };
00070 
00071 const int NUM_SATS = 38;
00072 
00073 int main(int argc, char* argv[] )
00074 {
00075   printf("Ryan's Xendweek\n");
00076 
00077   if (argc < 2)
00078     {
00079       printf("Usage: >>Xendweek <outputfile>\n");
00080       exit(1);
00081     }  
00082       // Open an output file.
00083    printf(" Opening output file.\n");
00084    FILE *outFile = fopen( argv[1], "wt" );
00085    if (outFile==NULL)
00086    {
00087       printf(" Cannot open Xendweek.out for output.\n");
00088       exit(-1);
00089    }
00090    fprintf(outFile," XENDWEEK.OUT - Demonstrating P-Code End of Week Generation..\n");
00091    fprintf(outFile,"                Reproducing ICD-GPS-200, Table 3-IV\n");
00092 
00093       // Set time to end of week minus six seconds
00094    printf(" Setting time to end of week.\n");
00095    //DayTime dt( 1233, 604794.0, 2003 );
00096    DayTime dt( 1233, 604794.0 );
00097    
00098       // NOTE: The P-code generator works in 6-second "chunks".  This implies
00099       // that there are 6 seconds of X1 bitstream and 6 seconds of X2 bitstreams
00100       // held in memory.  To mimimize the memory footprint, these bitstreams
00101       // are shared between all coders and are located in dynamically allocated
00102       // buffers referenced through static pointers.  THEREFORE, before any 
00103       // SVPCodeGen objects are instantiated, these buffers must be allocated
00104       // and initialized via the following two calls.  Failure to do so will
00105       // resort in abnormal program termination (unless the exceptions are
00106       // trapped). 
00107    try
00108    {
00109       X1Sequence::allocateMemory();
00110       X2Sequence::allocateMemory();
00111    }
00112    catch (gpstk::Exception e)
00113    {
00114       printf(" Memory allocation failure.\n");
00115       printf(" Xbegweek will terminate.\n");
00116       return(1);
00117    }
00118    
00119       // Instantiate a map to hold SVPCodeGen and CodeBuffer objects
00120    printf(" Instantiating the PRN map.\n");
00121    map<int, SVData>svdMap;
00122    typedef map<int, SVData>::iterator SVDataI;
00123    
00124       // Instantiate and initialize the P-coder objects
00125    SVPCodeGen * svp[NUM_SATS];
00126    CodeBuffer * pcb[NUM_SATS]; 
00127    for (int n=0;n<NUM_SATS;++n) { svp[n]=0; pcb[n]=0; };
00128    
00129    for (int PRNndx=0; PRNndx<NUM_SATS; ++PRNndx)
00130    {
00131       svp[PRNndx] = new SVPCodeGen( PRNndx, dt );
00132       pcb[PRNndx] = new CodeBuffer( PRNndx );
00133 
00134       SVData svd( svp[PRNndx], pcb[PRNndx], P_CODE );
00135       pair<int,SVData> ps( PRNndx, svd );
00136       svdMap.insert( ps );
00137    }
00138    
00139    fprintf(outFile," PRN  Last word ");
00140 
00141       // Calculate X1count where X2 starts to transition to end of week "hold"
00142    long EndOfWeekTestCount =
00143       3 * (XA_COUNT * XA_MAX_EPOCH) + (XA_COUNT * (XA_MAX_EPOCH-1)) + 3023;
00144    long EndOfWeekTestWord = (EndOfWeekTestCount / MAX_BIT);
00145    long EndOfWeekTestEnd = EndOfWeekTestWord+(XA_EPOCH_DELAY+104)/MAX_BIT+3; 
00146    
00147    long chip = EndOfWeekTestWord * MAX_BIT -
00148                3 * (XA_COUNT * XA_MAX_EPOCH) - (XA_COUNT * (XA_MAX_EPOCH-1));
00149    for (long j=EndOfWeekTestWord;j<EndOfWeekTestEnd;j++)
00150    {
00151       fprintf(outFile,"%4d      ",chip);
00152       chip+=32;
00153    }
00154    fprintf(outFile,"\n");
00155    
00156    int PRNID;
00157    unsigned long temp;
00158    for ( SVDataI p=svdMap.begin(); p!=svdMap.end(); ++p )
00159    {
00160       PRNID = p->first;
00161       SVData& rsvd = p->second;
00162       SVPCodeGen& rsvp = *(rsvd.PCodeGen);
00163       CodeBuffer& rcb = *(rsvd.PCodeBuf);
00164       rsvp.getCurrentSixSeconds( rcb );
00165       temp = rcb[NUM_6SEC_WORDS-1];
00166       fprintf( outFile,"  %02d  x%08X",PRNID,temp);
00167       for (long n=EndOfWeekTestWord;n<EndOfWeekTestEnd;n++)
00168       {
00169          fprintf(outFile," x%08X",rcb[n]);
00170       }
00171       fprintf(outFile,"\n");
00172    }
00173 
00174       /*
00175          Close the output files and exit gracefully.
00176       */
00177    printf(" Closing files.\n");
00178    fflush( outFile );
00179    fclose( outFile );
00180    return(0);
00181 }

Generated on Wed Feb 8 03:31:04 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1