1#!/usr/bin/perl
2#==============================================================================
3#
4#  This file is part of GPSTk, the GPS Toolkit.
5#
6#  The GPSTk is free software; you can redistribute it and/or modify
7#  it under the terms of the GNU Lesser General Public License as published
8#  by the Free Software Foundation; either version 3.0 of the License, or
9#  any later version.
10#
11#  The GPSTk is distributed in the hope that it will be useful,
12#  but WITHOUT ANY WARRANTY; without even the implied warranty of
13#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14#  GNU Lesser General Public License for more details.
15#
16#  You should have received a copy of the GNU Lesser General Public
17#  License along with GPSTk; if not, write to the Free Software Foundation,
18#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19#
20#  This software was developed by Applied Research Laboratories at the
21#  University of Texas at Austin.
22#  Copyright 2004-2020, The Board of Regents of The University of Texas System
23#
24#==============================================================================
25
26#==============================================================================
27#
28#  This software was developed by Applied Research Laboratories at the
29#  University of Texas at Austin, under contract to an agency or agencies
30#  within the U.S. Department of Defense. The U.S. Government retains all
31#  rights to use, duplicate, distribute, disclose, or release this software.
32#
33#  Pursuant to DoD Directive 523024
34#
35#  DISTRIBUTION STATEMENT A: This software has been approved for public
36#                            release, distribution is unlimited.
37#
38#==============================================================================
39
40# This script converts the output from rawNavDump to C++ code that can
41# be inserted into BDSEphemeris_T::wut()
42
43use warnings;
44use strict;
45
46my ($prn, $health, $tocStr, $toeStr, $af0, $af1, $af2, $A, $Adot, $dn, $dndot,
47    $ecc, $w, $M0, $OMEGA0, $OMEGAdot, $i0, $idot, $crs, $crc, $cis, $cic,
48    $cus, $cuc);
49my ($m, $d, $y, $hr, $min, $sec);
50
51while (<>)
52{
53    chomp;
54    my @arr = split(/ +/);
55    if (/^PRN : /)
56    {
57        $prn = $arr[2];
58    }
59    elsif (/^Health bit/)
60    {
61        $health = hex($arr[$#arr]);
62    }
63    elsif (/^Clock Epoch:/)
64    {
65        $tocStr = $arr[$#arr-1] . " " . $arr[$#arr];
66    }
67    elsif (/^Eph Epoch:/)
68    {
69        $toeStr = $arr[$#arr-1] . " " . $arr[$#arr];
70    }
71    elsif (/^Bias T0:/)
72    {
73        $af0 = $arr[2];
74    }
75    elsif (/^Drift:/)
76    {
77        $af1 = $arr[1];
78    }
79    elsif (/^Drift rate:/)
80    {
81        $af2 = $arr[2];
82    }
83    elsif (/^Semi-major axis:/)
84    {
85        $A = $arr[2];
86        $Adot = $arr[4];
87    }
88    elsif (/^Motion correction:/)
89    {
90        $dn = $arr[2];
91        $dndot = $arr[4];
92    }
93    elsif (/^Eccentricity:/)
94    {
95        $ecc = $arr[1];
96    }
97    elsif (/^Arg of perigee:/)
98    {
99        $w = $arr[3];
100    }
101    elsif (/^Mean anomaly at epoch:/)
102    {
103        $M0 = $arr[4];
104    }
105    elsif (/^Right ascension:/)
106    {
107        $OMEGA0 = $arr[2];
108        $OMEGAdot= $arr[4];
109    }
110    elsif (/^Inclination:/)
111    {
112        $i0 = $arr[1];
113        $idot = $arr[3];
114    }
115    elsif (/^Radial *Sine:/)
116    {
117        $crs = $arr[2];
118        $crc = $arr[5];
119    }
120    elsif (/^Inclination *Sine:/)
121    {
122        $cis = $arr[2];
123        $cic = $arr[5];
124    }
125    elsif (/^In-track *Sine:/)
126    {
127        $cus = $arr[2];
128        $cuc = $arr[5];
129        printf("   try\n   {\n");
130        printf("      gpstk::BDSEphemeris oe;\n");
131        printf("      oe.Cuc      = $cuc;\n");
132        printf("      oe.Cus      = $cus;\n");
133        printf("      oe.Crc      = $crc;\n");
134        printf("      oe.Crs      = $crs;\n");
135        printf("      oe.Cic      = $cic;\n");
136        printf("      oe.Cis      = $cis;\n");
137        printf("      oe.M0       = $M0;\n");
138        printf("      oe.dn       = $dn;\n");
139        printf("      oe.dndot    = $dndot;\n");
140        printf("      oe.ecc      = $ecc;\n");
141        printf("      oe.A        = $A;\n");
142        printf("      oe.Adot     = $Adot;\n");
143        printf("      oe.OMEGA0   = $OMEGA0;\n");
144        printf("      oe.i0       = $i0;\n");
145        printf("      oe.w        = $w;\n");
146        printf("      oe.OMEGAdot = $OMEGAdot;\n");
147        printf("      oe.idot     = $idot;\n");
148        ($m, $d, $y, $hr, $min, $sec) = split(/[\/ :]/, $tocStr);
149        printf("      oe.ctToc    = gpstk::CivilTime(%d,%d,%d,%d,%d,%d,gpstk::TimeSystem::BDT);\n",$y,$m,$d,$hr,$min,$sec);
150        printf("      oe.af0      = $af0;\n");
151        printf("      oe.af1      = $af1;\n");
152        printf("      oe.af2      = $af2;\n");
153        printf("      oe.dataLoadedFlag = true;\n");
154        printf("      oe.satID = gpstk::SatID($prn, gpstk::SatID::systemBeiDou);\n");
155        ($m, $d, $y, $hr, $min, $sec) = split(/[\/ :]/, $toeStr);
156        printf("      oe.ctToe    = gpstk::CivilTime(%d,%d,%d,%d,%d,%d,gpstk::TimeSystem::BDT);\n",$y,$m,$d,$hr,$min,$sec);
157        printf("      writeVel(oe);\n");
158        printf("   }\n");
159        printf("   catch(...)\n");
160        printf("   {\n");
161        printf("      cerr << \"exception\" << endl;\n");
162        printf("   }\n");
163    }
164}
165