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>
17 #include <simgear/serial/serial.hxx>
25 // encapsulate a midg integer time (fixme, assumes all times in a track
26 // are from the same day, so we don't handle midnight roll over)
34 inline MIDGTime( const int dd, const int hh, const int mm,
37 seconds = dd*86400.0 + hh*3600.0 + mm*60.0 + ss;
38 msec = (uint32_t)(seconds * 1000);
40 inline MIDGTime( const uint32_t midgtime_msec ) {
42 seconds = (double)midgtime_msec / 1000.0;
43 // cout << midgtime << " = " << seconds << endl;
47 inline double get_seconds() const { return seconds; }
48 inline uint32_t get_msec() const { return msec; }
49 inline double diff_seconds( const MIDGTime t ) const {
50 return seconds - t.seconds;
56 // base class for MIDG data types
64 midg_time(MIDGTime(0))
67 inline double get_seconds() const { return midg_time.get_seconds(); }
68 inline uint32_t get_msec() const { return midg_time.get_msec(); }
72 // encapsulate the interesting midg data for a moment in time
73 class MIDGpos : public MIDGpoint {
99 // encapsulate the interesting midg data for a moment in time
100 class MIDGatt : public MIDGpoint {
116 // Manage a saved midg log (track file)
121 vector <MIDGpos> pos_data;
122 vector <MIDGatt> att_data;
124 // parse message and put current data into vector if message has a
125 // newer time stamp than existing data.
126 void parse_msg( const int id, char *buf, MIDGpos *pos, MIDGatt *att );
133 // read/parse the next message from the specified data stream,
134 // returns id # if a valid message found.
135 int next_message( SGIOChannel *ch, SGIOChannel *log,
136 MIDGpos *pos, MIDGatt *att );
137 int next_message( SGSerialPort *serial, SGIOChannel *log,
138 MIDGpos *pos, MIDGatt *att );
140 // load the named file into internal buffers
141 bool load( const string &file );
143 inline int pos_size() const { return pos_data.size(); }
144 inline int att_size() const { return att_data.size(); }
146 inline MIDGpos get_pospt( const unsigned int i )
148 if ( i < pos_data.size() ) {
154 inline MIDGatt get_attpt( const unsigned int i )
156 if ( i < att_data.size() ) {
167 MIDGpos MIDGInterpPos( const MIDGpos A, const MIDGpos B, const double percent );
168 MIDGatt MIDGInterpAtt( const MIDGatt A, const MIDGatt B, const double percent );
171 #endif // _FG_MIDG_II_HXX