Flight.cc
Go to the documentation of this file.
1 /*
2  * Flight.cpp
3  *
4  * Created on: Apr 24, 2015
5  * Author: leven
6  */
7 
8 #include "Flight.h"
9 #include "Interpolator3D.h"
10 #include "Ads_bEvent.h"
11 #include "Airplane.h"
12 #include "AirplaneUtil.h"
13 #include "Ads_bDataBase.h"
14 
15 #include "utl/UTCDateTime.h"
16 //uncomment for debugging
17 //#include "utl/ErrorLogger.h"
18 
19 #include "boost/lexical_cast.hpp"
20 
21 using namespace RdAirplane;
22 using namespace std;
23 using namespace utl;
24 using namespace RdAirplane::Util;
25 
27  static TimeInterval interval(15*s);
28  return interval;
29 }
30 
31 Flight::Flight(Airplane* pAirplane) :
32  _id_(""),
33  _airplane_(pAirplane),
34  _earliestEvent_(NULL),
35  _latestEvent_(NULL),
36  _offset_(NULL) {}
37 
38 void Flight::Init() {
41  _setId();
46 }
47 
49  if(_ads_bEventsAll_.empty())
50  return NULL;
51  return *_ads_bEventsAll_.begin();
52 }
53 
55  if(_ads_bEventsAll_.empty())
56  return NULL;
57  return *_ads_bEventsAll_.rbegin();
58 }
59 
62  Ads_bEventSet& ads_bEvents = _getAdsbEvents(pAltitudeType);
63  vector<const TimeStamp*> timesForInterpolation;
64  vector<const UTMPoint*> coordForInterpolation;
65  for(Ads_bEventSet::iterator iter = ads_bEvents.begin(); iter != ads_bEvents.end(); ++iter) {
66  Ads_bEvent* event = *iter;
67  const UTMPoint& eventCoordinates = event->getCoordinates(pAltitudeType);
68  const TimeStamp& time = event->getCaptureTime();
69  if(!timesForInterpolation.empty() &&
70  (time-*timesForInterpolation.back()>MaxAllowedTimeBetweenADS_BEventsForInterpolation() ||
71  iter == --ads_bEvents.end())) {
72  if(timesForInterpolation.size()>3) {
73  // at least three points to make a second order polynomial fit and account for the curvature of the earth in a later version
74  _getInterpolators(pAltitudeType).push_back(new Interpolator3D(timesForInterpolation, coordForInterpolation, this));
75  }
76  timesForInterpolation.clear();
77  coordForInterpolation.clear();
78  }
79  timesForInterpolation.push_back(&time);
80  coordForInterpolation.push_back(&eventCoordinates);
81  }
82 }
83 
84 
85 
87  // object does not change, so this is okay
88  Flight* this_noConst = const_cast<Flight*>(this);
89  switch(pAltitudeType) {
92  return this_noConst->_ads_bEventsPressureAltitude_;
94  return this_noConst->_ads_bEventsCorrectedPressureAltitude_;
96  return this_noConst->_ads_bEventsGPSAltitude_;
97  default:
98  throw runtime_error("Encountered an unknown altitude type.");
99  };
100  return this_noConst->_ads_bEventsPressureAltitude_;
101 }
102 
104  // object does not change, so this is okay
105  Flight* this_noConst = const_cast<Flight*>(this);
106  switch(pAltitudeType) {
108  return this_noConst->_interpolatorsPressureAltitude_;
114  return this_noConst->_interpolatorsGPSAltitude_;
115  default:
116  throw runtime_error("Encountered an unknown altitude type.");
117  };
118  return this_noConst->_interpolatorsPressureAltitude_;
119 }
120 
122  return _getAdsbEvents(pAltitudeType);
123 }
124 
126  return _ads_bEventsAll_;
127 }
128 
131  string year = boost::lexical_cast<string>(time.GetYear());
132  char month_c[3];
133  sprintf(month_c, "%02d", time.GetMonth());
134  char day_c[3];
135  sprintf(day_c, "%02d", time.GetDay());
136  char hour_c[3];
137  sprintf(hour_c, "%02d", time.GetHour());
138  char minute_c[3];
139  sprintf(minute_c, "%02d", time.GetMinute());
140  string timeIdendifier = year+month_c+day_c+hour_c+minute_c;
141  _id_=_airplane_->getId()+"_"+timeIdendifier;
142 }
143 
144 Ads_bEvent* Flight::addAds_bEvent(const TimeStamp& pCaptureTime, const UTMPoint& pCoordinates, const string& pAds_bMessageAsHex) {
145  cout.flush();
146  if(_ads_bEventsAll_.empty()) {
148  }
149  cout.flush();
150  Ads_bEvent* event = new Ads_bEvent(pCaptureTime, pCoordinates, pAds_bMessageAsHex, this);
151  if(event->ShouldBeFilteredOut()) {
152  delete event;
153  return NULL;
154  }
155  _ads_bEventsAll_.insert(event);
156  switch(event->getAltitudeType()) {
159  break;
163  break;
166  break;
167  default:
168  throw runtime_error("Encountered an unknown altitude type.");
169  break;
170  }
171  return event;
172 }
173 
180 }
181 
182 bool Flight::isTimeDuringFlight(const utl::TimeStamp& pTime) const {
183  return pTime > _earliestEvent_->getCaptureTime() && pTime <_latestEvent_->getCaptureTime();
184 }
185 
186 Point* Flight::getPosition(const TimeStamp& pTime, Ads_bEvent::AltitudeType pAltitudeType) const {
187  static Point* point;
188  if(!isTimeDuringFlight(pTime))
189  return NULL;
190  const InterpolatorList& interpolators = _getInterpolators(pAltitudeType);
191  for(InterpolatorList::const_iterator iter = interpolators.begin(); iter!=interpolators.end(); ++iter) {
192  if((*iter)->isTimeInInterpolatedRange(pTime)) {
193  delete point;
194  point = new Point((*iter)->getCoordinates(pTime));
195  return point;
196  }
197  }
198  return NULL;
199 }
200 
201 Point* Flight::getPosition(const TimeStamp& pTime) const {
203  if(res==NULL)
205  if(res==NULL)
207  if(res==NULL)
209  return res;
210 }
211 
212 Vector* Flight::getSpeed(const TimeStamp& pTime, Ads_bEvent::AltitudeType pAltitudeType) const {
213  static Vector* speed;
214  if(!isTimeDuringFlight(pTime))
215  return NULL;
216  const InterpolatorList& interpolators = _getInterpolators(pAltitudeType);
217  for(InterpolatorList::const_iterator iter = interpolators.begin(); iter!=interpolators.end(); ++iter) {
218  if((*iter)->isTimeInInterpolatedRange(pTime)) {
219  delete speed;
220  speed = new Vector((*iter)->getDerivative(pTime));
221  return speed;
222  }
223  }
224  return NULL;
225 }
226 
227 Vector* Flight::getSpeed(const TimeStamp& pTime) const {
229  if(res==NULL)
231  if(res==NULL)
233  if(res==NULL)
235  return res;
236 }
237 
238 string Flight::getInfo() const {
239  ostringstream info;
240  info << "\t Flight Id: " << getId() << endl
241  << "\t\t first seen: " << UTCDateTime(_earliestEvent_->getCaptureTime()).GetInAugerFormat() << endl
242  << "\t\t last seen: " << UTCDateTime(_latestEvent_->getCaptureTime()).GetInAugerFormat() << endl;
243  info << "\t\t pressure altitude interpolated:" << endl;
245  for(InterpolatorList::const_iterator iter = interpolators.begin(); iter != interpolators.end(); ++iter) {
246  info << "\t\t\t" << (*iter)->getInformation() << endl;
247  }
248  info << "\t\t corrected pressure altitude interpolated:" << endl;
250  for(InterpolatorList::const_iterator iter = interpolators.begin(); iter != interpolators.end(); ++iter) {
251  info << "\t\t\t" << (*iter)->getInformation() << endl;
252  }
253  info << "\t\t GPS altitude interpolated:" << endl;
255  for(InterpolatorList::const_iterator iter = interpolators.begin(); iter != interpolators.end(); ++iter) {
256  info << "\t\t\t" << (*iter)->getInformation() << endl;
257  }
258  return info.str();
259 }
260 
261 
const Ads_bDataBase & getAdsBDataBase() const
Definition: Airplane.h:36
InterpolatorList _interpolatorsGPSAltitude_
Definition: Flight.h:99
Point object.
Definition: Point.h:32
const Ads_bEvent * getEarliestAds_bEvent() const
Definition: Flight.cc:48
utl::CoordinateSystemPtr getCoordinateSystem() const
Definition: Ads_bDataBase.h:54
Class to hold and convert a point in geodetic coordinates.
Definition: UTMPoint.h:40
utl::Point * getPosition(const utl::TimeStamp &pTime, Ads_bEvent::AltitudeType pAltitudeType) const
Definition: Flight.cc:186
Flight(Airplane *pAirplane)
Definition: Flight.cc:31
InterpolatorList _interpolatorsGDASCorrectedPressureAltitude_
Definition: Flight.h:98
std::list< Interpolator3D * > InterpolatorList
Definition: Flight.h:33
void _interpolateAds_bEvents(Ads_bEvent::AltitudeType pAltitudeType)
Definition: Flight.cc:60
const Ads_bEventSet & getAdsbEvents() const
Definition: Flight.cc:125
const Airplane & getAirplane() const
Definition: Flight.h:57
Ads_bEventSet _ads_bEventsAll_
Definition: Flight.h:94
const Ads_bEvent * _latestEvent_
Definition: Flight.h:102
A TimeStamp holds GPS second and nanosecond for some event.
Definition: TimeStamp.h:110
static const utl::TimeInterval & MaxAllowedTimeBetweenADS_BEventsForInterpolation()
Definition: Flight.cc:26
utl::Vector * getSpeed(const utl::TimeStamp &pTime, Ads_bEvent::AltitudeType pAltitudeType) const
Definition: Flight.cc:212
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
constexpr double s
Definition: AugerUnits.h:163
Ads_bEventSet _ads_bEventsPressureAltitude_
Definition: Flight.h:91
const std::string & getId() const
Definition: Airplane.h:32
const AirplaneOffset * _offset_
Definition: Flight.h:104
const Ads_bEvent * _earliestEvent_
Definition: Flight.h:101
Ads_bEventSet & _getAdsbEvents(Ads_bEvent::AltitudeType pAltitudeType) const
Definition: Flight.cc:86
Ads_bEventSet _ads_bEventsCorrectedPressureAltitude_
Definition: Flight.h:92
InterpolatorList _interpolatorsPressureAltitude_
Definition: Flight.h:96
const Ads_bEvent * getLatestAds_bEvent() const
Definition: Flight.cc:54
A TimeInterval is used to represent time elapsed between two events.
Definition: TimeInterval.h:43
const utl::TimeStamp & getCaptureTime() const
Definition: Ads_bEvent.h:39
void deleteAllPointersInContainer(ContainerType &pContainer)
Definition: AirplaneUtil.h:41
std::string _id_
Definition: Flight.h:88
Vector object.
Definition: Vector.h:30
bool isTimeDuringFlight(const utl::TimeStamp &pTime) const
Definition: Flight.cc:182
std::set< Ads_bEvent *, Ads_bEventComparator > Ads_bEventSet
Definition: Flight.h:31
const AirplaneOffset * getAirplaneOffset(const Airplane &pAirplane, const utl::TimeStamp &pTime) const
std::string getInfo() const
Definition: Flight.cc:238
const std::string & getId() const
Definition: Flight.h:46
InterpolatorList _interpolatorsManuallyCorrectedPressureAltitude_
Definition: Flight.h:97
virtual ~Flight()
Definition: Flight.cc:174
Ads_bEventSet _ads_bEventsGPSAltitude_
Definition: Flight.h:93
InterpolatorList & _getInterpolators(Ads_bEvent::AltitudeType pAltitudeType) const
Definition: Flight.cc:103
Airplane * _airplane_
Definition: Flight.h:89
Ads_bEvent * addAds_bEvent(const utl::TimeStamp &pCaptureTime, const utl::UTMPoint &pCoordinates, const std::string &pAds_bMessageAsHex)
Definition: Flight.cc:144
const double year
Definition: GalacticUnits.h:22

, generated on Tue Sep 26 2023.