Ads_bEvent.cc
Go to the documentation of this file.
1 #include "Ads_bEvent.h"
2 #include "Ads_bDataBase.h"
3 #include "Airplane.h"
4 #include "Flight.h"
5 
6 #include "det/Detector.h"
7 
8 #include "atm/Atmosphere.h"
9 #include "atm/USStdADBProfileModel.h"
10 #include "utl/AugerUnits.h"
11 
12 #include <stdlib.h>
13 
14 //uncomment for debugging
15 //#include "utl/ErrorLogger.h"
16 //#include "boost/lexical_cast.hpp"
17 
18 
19 using namespace RdAirplane;
20 using namespace std;
21 using namespace utl;
22 using namespace det;
23 using namespace atm;
24 using namespace boost;
25 
27 
28 Ads_bEvent::Ads_bEvent(const TimeStamp& pCaptureTime,const utl::UTMPoint& pCoordinates, const string& pAds_bMessageAsHex, Flight* pFlight) :
29  _captureTime_(pCaptureTime),
30  _coordinatesFromAds_b_(pCoordinates),
31  _pressureAltitude_(-1.0),
32  _manuallyCorrectedPressureAltitude_(-1.0),
33  _GDAScorrectedPressureAltitude_(-1.0),
34  _gpsAltitude_(-1.0),
35  _ads_bMessageBinary_(_binaryFromHexString(pAds_bMessageAsHex)),
36  _tc_(0),
37  _flight_(pFlight),
38  _altitudeType_(ePressureAltitude) {
40  const AirplaneOffset* offset = pFlight->getOffset();
41  double altitudeOffset=0.0;
42  if(offset!=NULL) {
43  _captureTime_ += offset->getTimeOffset();
44  altitudeOffset = offset->getAltitudeOffset();
45  }
46  if(HasGPSAltitude()) {
49  } else {
53 
54  // correct altitude
55  Detector& detector = Detector::GetInstance();
56  //updating the detector every time would need years for the evaluation of all log files
58  detector.Update(_captureTime_);
59  const Atmosphere& atmosphere = detector.GetAtmosphere();
60  USStdADBProfileModel stdAtm;
61  double pressure = stdAtm.EvaluatePressureVsHeight().Y(_pressureAltitude_);
65  }
66  tuple<double, double, double> geodeticCoordinates = _coordinatesFromAds_b_.GetGeodeticCoordinates();
67  double latitude = geodeticCoordinates.get<0>();
68  double longitude = geodeticCoordinates.get<1>();
70  _coordinatesPressureAltitude_ = new UTMPoint(latitude, longitude , _pressureAltitude_, ellipsoid);
73  _coordinatesGPSAltitude_ = new UTMPoint(latitude, longitude , _gpsAltitude_, ellipsoid);
74 }
75 
81 }
82 
85 }
86 
87 const UTMPoint& Ads_bEvent::getCoordinates(AltitudeType pAltitudeType) const {
88  switch(pAltitudeType) {
89  case eGPSAltitude:
95  case ePressureAltitude:
97  default:
98  throw runtime_error("Encountered an unknown altitude type.");
99  }
100 }
101 
102 double Ads_bEvent::getAltitude(AltitudeType pAltitudeType) const {
103  switch(pAltitudeType) {
104  case eGPSAltitude:
106  throw runtime_error("Tried to read the gps altitude from ADS-B data that does not contain gps informations.");
107  return _gpsAltitude_;
110  throw runtime_error("Tried to read the corrected pressure altitude from ADS-B data for which the altitude was either from gps or could not be corrected.");
112  case ePressureAltitude:
114  throw runtime_error("Tried to read the pressure altitude from ADS-B data only holding the gps altitude.");
115  return _pressureAltitude_;
118  throw runtime_error("Tried to read the pressure altitude from ADS-B data only holding the gps altitude.");
120  default:
121  throw runtime_error("Encountered an unknown altitude type.");
122  }
123 }
124 
125 
126 double Ads_bEvent::_getAltitudeFromPressure(const atm::ProfileResult& pProfileResult, double pPressure, double pLowerAltitude, double pUpperAltitude, double pPressureTreshold, unsigned int pRecursionDepth, unsigned int pMaxRecursionDepth) {
127  if(pRecursionDepth>=pMaxRecursionDepth)
128  return -1.0;
129  double middleAltitude = (pLowerAltitude+pUpperAltitude)/2;
130  double middlePressure = pProfileResult.Y(middleAltitude);
131  if(abs(middlePressure-pPressure)<pPressureTreshold)
132  return middleAltitude;
133  if(middlePressure >= pPressure)
134  return _getAltitudeFromPressure(pProfileResult, pPressure, middleAltitude, pUpperAltitude, pPressureTreshold, ++pRecursionDepth, pMaxRecursionDepth);
135  else
136  return _getAltitudeFromPressure(pProfileResult, pPressure, pLowerAltitude, middleAltitude, pPressureTreshold, ++pRecursionDepth, pMaxRecursionDepth);
137 }
138 
139 double Ads_bEvent::_getAltitudeFromPressure(const atm::ProfileResult& pProfileResult, double pPressure) {
140  static double lowestAltitude = 7000*m;
141  static double highestAltitude = 13000*m;
142  static double pressureThreshold = 1*milli*bar;
143  static unsigned int maxRecursionDepth = 100;
144  return _getAltitudeFromPressure(pProfileResult, pPressure, lowestAltitude, highestAltitude, pressureThreshold, 0, maxRecursionDepth);
145 }
146 
147 vector<bool> Ads_bEvent::_binaryFromHexChar(const char& pHexChar) {
148  static bool alphabet[16][4] = {
149  {0, 0, 0, 0},
150  {0, 0, 0, 1},
151  {0, 0, 1, 0},
152  {0, 0, 1, 1},
153  {0, 1, 0, 0},
154  {0, 1, 0, 1},
155  {0, 1, 1, 0},
156  {0, 1, 1, 1},
157  {1, 0, 0, 0},
158  {1, 0, 0, 1},
159  {1, 0, 1, 0},
160  {1, 0, 1, 1},
161  {1, 1, 0, 0},
162  {1, 1, 0, 1},
163  {1, 1, 1, 0},
164  {1, 1, 1, 1}
165  };
166  int index = 0;
167  switch(toupper(pHexChar)) {
168  case '0': index = 0; break;
169  case '1': index = 1; break;
170  case '2': index = 2; break;
171  case '3': index = 3; break;
172  case '4': index = 4; break;
173  case '5': index = 5; break;
174  case '6': index = 6; break;
175  case '7': index = 7; break;
176  case '8': index = 8; break;
177  case '9': index = 9; break;
178  case 'A': index = 10; break;
179  case 'B': index = 11; break;
180  case 'C': index = 12; break;
181  case 'D': index = 13; break;
182  case 'E': index = 14; break;
183  case 'F': index = 15; break;
184  default:
185  throw runtime_error("Encountered invalid hex character " + pHexChar);
186  break;
187  }
188  bool* res = alphabet[index];
189  return vector<bool>(res, res+4);
190 }
191 
192 vector<bool> Ads_bEvent::_binaryFromHexString(const string& pHexString) {
193  vector<bool> res;
194  for(size_t i = 0; i<pHexString.length();++i) {
195  const vector<bool>& charToBinary = _binaryFromHexChar(pHexString[i]);
196  for(vector<bool>::const_iterator iter = charToBinary.begin(); iter!=charToBinary.end(); ++iter)
197  res.push_back(*iter);
198  }
199  return res;
200 }
201 
203  return false;
204 }
205 
207  bool res = _decodeTC();
208  return res;
209 }
210 
211 int Ads_bEvent::_intFromBoolVector(const vector<bool>& pVector) {
212  int res = 0;
213  unsigned short i = pVector.size()-1;
214  for(vector<bool>::const_iterator it = pVector.begin(); it != pVector.end(); ++it,--i){
215  int bit = int(*it);
216  res |= bit<<i;
217  }
218  return res;
219 }
220 
222  vector<bool>::const_iterator first = _ads_bMessageBinary_.begin() + ADS_B_DATA_BIT_OFFSET;
223  vector<bool>::const_iterator last = _ads_bMessageBinary_.begin() + ADS_B_DATA_BIT_OFFSET + 5;
224  vector<bool> tc(first, last);
225  _tc_ = _intFromBoolVector(tc);
226  return true;
227 }
228 
230  return _tc_ == 15 || _tc_ == 16;
231 }
232 
void Update(const utl::TimeStamp &time, const bool invData=true, const bool invComp=true, const bool forceRadio=false)
Update detector: deletes currently constructed stations and sets new time.
Definition: Detector.cc:179
Top of the interface to Atmosphere information.
constexpr double milli
Definition: AugerUnits.h:66
constexpr double atmosphere
Definition: AugerUnits.h:215
const double & getAltitudeOffset() const
AltitudeType _altitudeType_
Definition: Ads_bEvent.h:84
static std::vector< bool > _binaryFromHexString(const std::string &pHexString)
Definition: Ads_bEvent.cc:192
std::vector< bool > _ads_bMessageBinary_
Definition: Ads_bEvent.h:80
bool ShouldBeFilteredOut() const
Definition: Ads_bEvent.cc:202
utl::TimeStamp GetTime() const
Get time pertaining to the detector description.
Definition: Detector.h:134
Class to hold and convert a point in geodetic coordinates.
Definition: UTMPoint.h:40
bool HasGPSAltitude() const
Definition: Ads_bEvent.cc:229
static const unsigned int ADS_B_DATA_BIT_OFFSET
Definition: Ads_bEvent.h:31
const atm::ProfileResult & EvaluatePressureVsHeight() const
Tabulated function giving Y=air pressure as a function of X=height.
double _manuallyCorrectedPressureAltitude_
Definition: Ads_bEvent.h:71
static int _intFromBoolVector(const std::vector< bool > &pVector)
Definition: Ads_bEvent.cc:211
Ads_bEvent(const utl::TimeStamp &pCaptureTime, const utl::UTMPoint &pCoordinates, const std::string &pAds_bMessageAsHex, Flight *pFlight)
Definition: Ads_bEvent.cc:28
utl::UTMPoint * _coordinatesGPSAltitude_
Definition: Ads_bEvent.h:78
utl::UTMPoint * _coordinatesManuallyCorrectedPressureAltitude_
Definition: Ads_bEvent.h:77
utl::UTMPoint * _coordinatesGDASCorrectedPressureAltitude_
Definition: Ads_bEvent.h:76
utl::TimeStamp _captureTime_
Definition: Ads_bEvent.h:67
double Y(const double x) const
Get the Y value (coordinate) for given X (ordinate)
A TimeStamp holds GPS second and nanosecond for some event.
Definition: TimeStamp.h:110
const atm::Atmosphere & GetAtmosphere() const
Definition: Detector.h:113
Extracts profile info from US Standard Atmosphere.
constexpr double s
Definition: AugerUnits.h:163
Reference ellipsoids for UTM transformations.
double GetHeight() const
Get the height.
Definition: UTMPoint.h:212
Class describing the Atmospheric profile.
Definition: ProfileResult.h:25
const utl::UTMPoint & getCoordinates() const
Definition: Ads_bEvent.cc:83
double abs(const SVector< n, T > &v)
double _GDAScorrectedPressureAltitude_
Definition: Ads_bEvent.h:72
Top of the hierarchy of the detector description interface.
Definition: Detector.h:81
static double _getAltitudeFromPressure(const atm::ProfileResult &pProfileResult, double pPressure, double pLowerHeight, double pUpperHeight, double pPressureTreshold, unsigned int pRecursionDepth, unsigned int pMaxRecursionDepth)
Definition: Ads_bEvent.cc:126
A TimeInterval is used to represent time elapsed between two events.
Definition: TimeInterval.h:43
const ReferenceEllipsoid & GetEllipsoid() const
Get the reference ellipsoid.
Definition: UTMPoint.h:221
double getAltitude(AltitudeType pAltitudeType) const
Definition: Ads_bEvent.cc:102
static utl::TimeInterval MAX_TIME_SPAN_BETWEEN_ADS_B_EVENT_AND_DETECTOR_TIME
Definition: Ads_bEvent.h:30
const AirplaneOffset * getOffset() const
Definition: Flight.h:50
static std::vector< bool > _binaryFromHexChar(const char &pHexChar)
Definition: Ads_bEvent.cc:147
utl::UTMPoint * _coordinatesPressureAltitude_
Definition: Ads_bEvent.h:75
const atm::ProfileResult & EvaluatePressureVsHeight() const override
Table of air pressure as a function of height.
constexpr double m
Definition: AugerUnits.h:121
boost::tuple< double, double, double > GetGeodeticCoordinates() const
Get geodetic latitude, longitude, height.
Definition: UTMPoint.cc:67
const utl::TimeInterval & getTimeOffset() const
constexpr double bar
Definition: AugerUnits.h:213
utl::UTMPoint _coordinatesFromAds_b_
Definition: Ads_bEvent.h:69

, generated on Tue Sep 26 2023.