Xbegweek.cpp

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

Generated on Tue May 22 03:31:02 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1