AlmanacDataGenerator.hpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // This file is part of GNSSTk, the ARL:UT GNSS Toolkit.
4 //
5 // The GNSSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GNSSTk is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GNSSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2022, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
38 
39 #include <iostream>
40 #include <fstream>
41 #include <algorithm>
42 #include <string>
43 #include <stdlib.h>
44 #include <math.h>
45 #include <stdint.h>
46 
47 #ifdef _MSC_VER
48 static inline double round(double val)
49 {
50  return floor(val + 0.5);
51 }
52 #endif
53 
54 //Reads in the almanac file and stores it in data types
56 {
57 public:
58  int id[31];
59  int health[31];
60  float ecc[31];
61  float toa[31];
62  float oi[31];
63  float rora[31];
64  float sqrta[31];
65  float raaw[31];
66  float aop[31];
67  float ma[31];
68  float af0[31];
69  float af1[31];
70  float week[31];
71  std::string line;
72 
74  {
75 
76  }
77 
78  AlmanacData(std::ifstream &file)
79  {
80  for (int i=0; i<31; i++)
81  {
82  getline(file, line); //skip
83  id[i] = readData(file); // sat id
84  health[i] = readData(file);
85  ecc[i] = readData(file); // eccentricity (e)
86  toa[i] = readData(file); // Time of Applicability (toa)
87  oi[i] = readData(file); // Orbital Inclination (detai)
88  rora[i] = readData(file); // Rate of Right Ascension (OMEGADOT)
89  sqrta[i] = readData(file);
90  raaw[i] = readData(file); // Rate of Ascension at Week (OMEGA0)
91  aop[i] = readData(file); // Argument of Perigee (omega)
92  ma[i] = readData(file); // Mean Anomaly (M0)
93  af0[i] = readData(file);
94  af1[i] = readData(file);
95  week[i] = readData(file);
96  getline(file, line); //skip
97  }
98 
99  }
100 
101  float readData(std::ifstream &file)
102  {
103  getline(file, line);
105  return atof(line.c_str());
106  }
107 
108  std::string cleanLine(std::string line)
109  {
110  line = line.substr(25, std::string::npos);
111  line.erase( std::remove(line.begin(), line.end(), ' '), line.end());
112  return line;
113  }
114 };
115 
116 //Converts almanac data to subframes
117 //No parity! EngAlmanac doesn't test for parity
119 {
120 public:
121  struct SVsubframes
122  {
123  uint32_t word1;
124  uint32_t word2;
125  uint32_t word3;
126  uint32_t word4;
127  uint32_t word5;
128  uint32_t word6;
129  uint32_t word7;
130  uint32_t word8;
131  uint32_t word9;
132  uint32_t word10;
133  } allSVs[31];
134 
135  long totalSf[31][10];
136 
138  {
139 
140  }
141 
142  AlmanacSubframes(AlmanacData aData) //Shouldn't be a reference, need the original data for comparison
143  {
144  scaleData(aData);
145 
146  for (int i=0; i<31; i++)
147  {
148  allSVs[i].word1 = 0x22c000e4;
149  allSVs[i].word2 = 0x00000598;
150  if(aData.id[i] > 25) allSVs[i].word2 = 0x0000042c;
151  allSVs[i].word3 = ( (( (1 << 6) + ((uint32_t) aData.id[i])) << 16) + ((uint32_t) aData.ecc[i]) ) << 6;
152  allSVs[i].word4 = ( (((uint32_t) aData.toa[i]) << 16) + ((uint32_t) aData.oi[i]) ) << 6;
153  allSVs[i].word5 = ( (((uint32_t) aData.rora[i]) << 8) + ((uint32_t) aData.health[i]) ) << 6;
154  allSVs[i].word6 = ((uint32_t) aData.sqrta[i]) << 6;
155  allSVs[i].word7 = ((uint32_t) aData.raaw[i]) << 6;
156  allSVs[i].word8 = ((uint32_t) aData.aop[i]) << 6;
157  allSVs[i].word9 = ((uint32_t) aData.ma[i]) << 6;
158  startaf0 = ( (uint32_t) aData.af0[i] ) >> 3;
159  endaf0 = (((uint32_t) aData.af0[i]) << (32-3)) >> (32-3);
160  allSVs[i].word10 = ( (((startaf0 << 11) + (uint32_t) aData.af1[i]) << 3) + endaf0 ) << 8;
161 
162  totalSf[i][0] = allSVs[i].word1;
163  totalSf[i][1] = allSVs[i].word2;
164  totalSf[i][2] = allSVs[i].word3;
165  totalSf[i][3] = allSVs[i].word4;
166  totalSf[i][4] = allSVs[i].word5;
167  totalSf[i][5] = allSVs[i].word6;
168  totalSf[i][6] = allSVs[i].word7;
169  totalSf[i][7] = allSVs[i].word8;
170  totalSf[i][8] = allSVs[i].word9;
171  totalSf[i][9] = allSVs[i].word10;
172  }
173 
174  }
175 
177  {
178  for(int i=0; i<31; i++)
179  {
180  //pow is used to scale, round returns an signed int, uint32_t recasts to unsigned
181  //resigned in 32, so
182  aData.ecc[i] = twosCompliment((uint32_t) round(aData.ecc[i] * pow(2.,21)), 16);
183  aData.toa[i] = twosCompliment((uint32_t) round(aData.toa[i] * pow(2.,-12)), 8);
184  aData.oi[i] = twosCompliment((uint32_t) round((aData.oi[i] - .3*M_PI) * pow(2., 19) / M_PI), 16);
185  aData.rora[i] = twosCompliment((uint32_t) round(aData.rora[i] * pow(2.,38) / M_PI), 16);
186  aData.sqrta[i] = twosCompliment((uint32_t) round(aData.sqrta[i] * pow(2.,11)), 24);
187  aData.raaw[i] = twosCompliment((uint32_t) round(aData.raaw[i] * pow(2.,23) / M_PI), 24);
188  aData.aop[i] = twosCompliment((uint32_t) round(aData.aop[i] * pow(2.,23) / M_PI), 24);
189  aData.ma[i] = twosCompliment((uint32_t) round(aData.ma[i] * pow(2.,23) / M_PI), 24);
190  aData.af0[i] = twosCompliment(((uint32_t) round(aData.af0[i] * pow(2.,20))), 11);
191  aData.af1[i] = twosCompliment(((uint32_t) round(aData.af1[i] * pow(2.,38))), 11);
192  }
193 
194  return aData;
195  }
196 
197  uint32_t twosCompliment(uint32_t data, int size)
198  {
199  if (data > 0x1000)
200  data = (data << (32 - size)) >> (32-size);
201  else data = (uint32_t) round(data);
202 
203  return data;
204  }
205 
206  uint32_t startaf0;
207  uint32_t endaf0;
208 };
209 
210 uint32_t threesCompliment(uint32_t data, int size)
211 {
212  if (data > 0x1000)
213  data = (data << (32 - size)) >> (32-size);
214  else data = (uint32_t) round(data);
215 
216  return data;
217 }
218 /*
219 int main(void)
220 {
221 std::ifstream file("./current.txt");
222 
223 AlmanacData aData(file);
224 AlmanacSubframes dataIHope(aData);
225 
226 for (int i = 0; i<31; i++)
227 {
228 std::cout<<std::hex<<dataIHope.allSVs[i].word1<<", ";
229 std::cout<<dataIHope.allSVs[i].word2<<", ";
230 std::cout<<dataIHope.allSVs[i].word3<<", ";
231 std::cout<<dataIHope.allSVs[i].word4<<", ";
232 std::cout<<dataIHope.allSVs[i].word5<<", ";
233 std::cout<<dataIHope.allSVs[i].word6<<", ";
234 std::cout<<dataIHope.allSVs[i].word7<<", ";
235 std::cout<<dataIHope.allSVs[i].word8<<", ";
236 std::cout<<dataIHope.allSVs[i].word9<<", ";
237 std::cout<<dataIHope.allSVs[i].word10<<std::endl;
238 };
239  //std::cout<<cleanLine(clean)<<std::endl;
240  return 0;
241  }*/
AlmanacData::aop
float aop[31]
Definition: AlmanacDataGenerator.hpp:66
AlmanacData::ecc
float ecc[31]
Definition: AlmanacDataGenerator.hpp:60
AlmanacSubframes::AlmanacSubframes
AlmanacSubframes(void)
Definition: AlmanacDataGenerator.hpp:137
file
page HOWTO subpage DoxygenGuide Documenting Your Code page DoxygenGuide Documenting Your Code todo Flesh out this document section doctips Tips for Documenting When defining make sure that the prototype is identical between the cpp and hpp file
Definition: DOCUMENTING.dox:9
AlmanacData::AlmanacData
AlmanacData(void)
Definition: AlmanacDataGenerator.hpp:73
AlmanacData
Definition: AlmanacDataGenerator.hpp:55
AlmanacData::readData
float readData(std::ifstream &file)
Definition: AlmanacDataGenerator.hpp:101
AlmanacSubframes::SVsubframes::word9
uint32_t word9
Definition: AlmanacDataGenerator.hpp:131
AlmanacData::rora
float rora[31]
Definition: AlmanacDataGenerator.hpp:63
AlmanacSubframes::SVsubframes::word3
uint32_t word3
Definition: AlmanacDataGenerator.hpp:125
AlmanacData::id
int id[31]
Definition: AlmanacDataGenerator.hpp:58
AlmanacSubframes::SVsubframes
Definition: AlmanacDataGenerator.hpp:121
AlmanacSubframes::scaleData
AlmanacData scaleData(AlmanacData &aData)
Definition: AlmanacDataGenerator.hpp:176
AlmanacData::AlmanacData
AlmanacData(std::ifstream &file)
Definition: AlmanacDataGenerator.hpp:78
AlmanacData::health
int health[31]
Definition: AlmanacDataGenerator.hpp:59
AlmanacSubframes::SVsubframes::word10
uint32_t word10
Definition: AlmanacDataGenerator.hpp:132
AlmanacSubframes::SVsubframes::word2
uint32_t word2
Definition: AlmanacDataGenerator.hpp:124
AlmanacSubframes
Definition: AlmanacDataGenerator.hpp:118
AlmanacSubframes::twosCompliment
uint32_t twosCompliment(uint32_t data, int size)
Definition: AlmanacDataGenerator.hpp:197
AlmanacSubframes::SVsubframes::word8
uint32_t word8
Definition: AlmanacDataGenerator.hpp:130
AlmanacData::sqrta
float sqrta[31]
Definition: AlmanacDataGenerator.hpp:64
AlmanacSubframes::SVsubframes::word7
uint32_t word7
Definition: AlmanacDataGenerator.hpp:129
AlmanacData::ma
float ma[31]
Definition: AlmanacDataGenerator.hpp:67
AlmanacData::line
std::string line
Definition: AlmanacDataGenerator.hpp:71
AlmanacSubframes::SVsubframes::word4
uint32_t word4
Definition: AlmanacDataGenerator.hpp:126
threesCompliment
uint32_t threesCompliment(uint32_t data, int size)
Definition: AlmanacDataGenerator.hpp:210
AlmanacSubframes::allSVs
struct AlmanacSubframes::SVsubframes allSVs[31]
example3.data
data
Definition: example3.py:22
AlmanacSubframes::startaf0
uint32_t startaf0
Definition: AlmanacDataGenerator.hpp:206
AlmanacSubframes::totalSf
long totalSf[31][10]
Definition: AlmanacDataGenerator.hpp:135
AlmanacSubframes::SVsubframes::word6
uint32_t word6
Definition: AlmanacDataGenerator.hpp:128
AlmanacData::cleanLine
std::string cleanLine(std::string line)
Definition: AlmanacDataGenerator.hpp:108
AlmanacData::toa
float toa[31]
Definition: AlmanacDataGenerator.hpp:61
AlmanacSubframes::SVsubframes::word1
uint32_t word1
Definition: AlmanacDataGenerator.hpp:123
AlmanacSubframes::endaf0
uint32_t endaf0
Definition: AlmanacDataGenerator.hpp:207
AlmanacSubframes::AlmanacSubframes
AlmanacSubframes(AlmanacData aData)
Definition: AlmanacDataGenerator.hpp:142
AlmanacSubframes::SVsubframes::word5
uint32_t word5
Definition: AlmanacDataGenerator.hpp:127
AlmanacData::af1
float af1[31]
Definition: AlmanacDataGenerator.hpp:69
AlmanacData::af0
float af0[31]
Definition: AlmanacDataGenerator.hpp:68
AlmanacData::week
float week[31]
Definition: AlmanacDataGenerator.hpp:70
AlmanacData::oi
float oi[31]
Definition: AlmanacDataGenerator.hpp:62
AlmanacData::raaw
float raaw[31]
Definition: AlmanacDataGenerator.hpp:65


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:38