1 #ifndef _FG_MIDG_II_HXX
2 #define _FG_MIDG_II_HXX
9 #include <simgear/compiler.h>
15 #include <simgear/misc/stdint.hxx>
16 #include <simgear/io/iochannel.hxx>
24 // encapsulate a midg integer time (fixme, assumes all times in a track
25 // are from the same day, so we don't handle midnight roll over)
33 inline MIDGTime( const int dd, const int hh, const int mm,
36 seconds = dd*86400.0 + hh*3600.0 + mm*60.0 + ss;
37 msec = (uint32_t)(seconds * 1000);
39 inline MIDGTime( const uint32_t midgtime_msec ) {
41 seconds = (double)midgtime_msec / 1000.0;
42 // cout << midgtime << " = " << seconds << endl;
46 inline double get_seconds() const { return seconds; }
47 inline uint32_t get_msec() const { return msec; }
48 inline double diff_seconds( const MIDGTime t ) const {
49 return seconds - t.seconds;
55 // base class for MIDG data types
63 midg_time(MIDGTime(0))
66 inline double get_seconds() const { return midg_time.get_seconds(); }
67 inline uint32_t get_msec() const { return midg_time.get_msec(); }
71 // encapsulate the interesting midg data for a moment in time
72 class MIDGpos : public MIDGpoint {
98 // encapsulate the interesting midg data for a moment in time
99 class MIDGatt : public MIDGpoint {
115 // Manage a saved midg log (track file)
120 vector <MIDGpos> pos_data;
121 vector <MIDGatt> att_data;
123 // parse message and put current data into vector if message has a
124 // newer time stamp than existing data.
125 void parse_msg( const int id, char *buf, MIDGpos *pos, MIDGatt *att );
132 // read/parse the next message from the specified data stream,
133 // returns id # if a valid message found.
134 int next_message( SGIOChannel *ch, SGIOChannel *log,
135 MIDGpos *pos, MIDGatt *att );
137 // load the named file into internal buffers
138 bool load( const string &file );
140 inline int pos_size() const { return pos_data.size(); }
141 inline int att_size() const { return att_data.size(); }
143 inline MIDGpos get_pospt( const unsigned int i )
145 if ( i < pos_data.size() ) {
151 inline MIDGatt get_attpt( const unsigned int i )
153 if ( i < att_data.size() ) {
164 MIDGpos MIDGInterpPos( const MIDGpos A, const MIDGpos B, const double percent );
165 MIDGatt MIDGInterpAtt( const MIDGatt A, const MIDGatt B, const double percent );
168 #endif // _FG_MIDG_II_HXX