1 #ifndef _FG_MIDG_II_HXX
2 #define _FG_MIDG_II_HXX
9 #include <simgear/compiler.h>
17 #elif defined( _MSC_VER ) || defined(__MINGW32__) || defined(sun)
18 typedef signed short int16_t;
19 typedef signed int int32_t;
20 typedef unsigned short uint16_t;
21 typedef unsigned int uint32_t;
23 # error "Port me! Platforms that don't have <stdint.h> need to define int8_t, et. al."
26 #include <simgear/io/iochannel.hxx>
34 // encapsulate a midg integer time (fixme, assumes all times in a track
35 // are from the same day, so we don't handle midnight roll over)
43 inline MIDGTime( const int dd, const int hh, const int mm,
46 seconds = dd*86400.0 + hh*3600.0 + mm*60.0 + ss;
47 msec = (uint32_t)(seconds * 1000);
49 inline MIDGTime( const uint32_t midgtime_msec ) {
51 seconds = (double)midgtime_msec / 1000.0;
52 // cout << midgtime << " = " << seconds << endl;
56 inline double get_seconds() const { return seconds; }
57 inline uint32_t get_msec() const { return msec; }
58 inline double diff_seconds( const MIDGTime t ) const {
59 return seconds - t.seconds;
65 // base class for MIDG data types
73 midg_time(MIDGTime(0))
76 inline double get_seconds() const { return midg_time.get_seconds(); }
77 inline uint32_t get_msec() const { return midg_time.get_msec(); }
81 // encapsulate the interesting midg data for a moment in time
82 class MIDGpos : public MIDGpoint {
108 // encapsulate the interesting midg data for a moment in time
109 class MIDGatt : public MIDGpoint {
125 // Manage a saved midg log (track file)
130 vector <MIDGpos> pos_data;
131 vector <MIDGatt> att_data;
133 // parse message and put current data into vector if message has a
134 // newer time stamp than existing data.
135 void parse_msg( const int id, char *buf, MIDGpos *pos, MIDGatt *att );
142 // read/parse the next message from the specified data stream,
143 // returns id # if a valid message found.
144 int next_message( SGIOChannel *ch, MIDGpos *pos, MIDGatt *att );
146 // load the named file into internal buffers
147 bool load( const string &file );
149 inline int pos_size() const { return pos_data.size(); }
150 inline int att_size() const { return att_data.size(); }
152 inline MIDGpos get_pospt( const unsigned int i )
154 if ( i < pos_data.size() ) {
160 inline MIDGatt get_attpt( const unsigned int i )
162 if ( i < att_data.size() ) {
173 MIDGpos MIDGInterpPos( const MIDGpos A, const MIDGpos B, const double percent );
174 MIDGatt MIDGInterpAtt( const MIDGatt A, const MIDGatt B, const double percent );
177 #endif // _FG_MIDG_II_HXX