| 1 | #pragma once |
| 2 | |
| 3 | #include <simgear/compiler.h> |
| 4 | |
| 5 | #include <iostream> |
| 6 | #include <string> |
| 7 | #include <vector> |
| 8 | |
| 9 | |
| 10 | // encapsulate a gps integer time (fixme, assumes all times in a track |
| 11 | // are from the same day, so we don't handle midnight roll over) |
| 12 | class GPSTime { |
| 13 | |
| 14 | public: |
| 15 | |
| 16 | double seconds; |
| 17 | |
| 18 | inline GPSTime( const int hh, const int mm, const double ss ) { |
| 19 | seconds = hh*3600 + mm*60 + ss; |
| 20 | } |
| 21 | inline GPSTime( const double gpstime ) { |
| 22 | double tmp = gpstime; |
| 23 | int hh = (int)(tmp / 10000); |
| 24 | tmp -= hh * 10000; |
| 25 | int mm = (int)(tmp / 100); |
| 26 | tmp -= mm * 100; |
| 27 | double ss = tmp; |
| 28 | seconds = hh*3600 + mm*60 + ss; |
| 29 | // std::cout << gpstime << " = " << seconds << std::endl; |
| 30 | } |
| 31 | inline ~GPSTime() {} |
| 32 | |
| 33 | inline double get_time() const { return seconds; } |
| 34 | inline double diff_sec( const GPSTime t ) const { |
| 35 | return seconds - t.seconds; |
| 36 | } |
| 37 | }; |
| 38 | |
| 39 | |
| 40 | |
| 41 | // encapsulate the interesting gps data for a moment in time |
| 42 | class GPSPoint { |
| 43 | |
| 44 | public: |
| 45 | |
| 46 | GPSTime gps_time; |
| 47 | double lat_deg; |
| 48 | double lon_deg; |
| 49 | int fix_quality; |
| 50 | int num_satellites; |
| 51 | double hdop; |
| 52 | double altitude_msl; |
| 53 | double speed_kts; |
| 54 | double course_true; |
| 55 | |
| 56 | GPSPoint() : |
| 57 | gps_time(GPSTime(0,0,0)), |
| 58 | lat_deg(0.0), |
| 59 | lon_deg(0.0), |
| 60 | fix_quality(0), |
| 61 | num_satellites(0), |
| 62 | hdop(0.0), |
| 63 | altitude_msl(0.0), |
| 64 | speed_kts(0.0), |
| 65 | course_true(0.0) |
| 66 | { } |
| 67 | |
| 68 | inline double get_time() const { return gps_time.get_time(); } |
| 69 | }; |
| 70 | |
| 71 | |
| 72 | // Manage a saved gps log (track file) |
| 73 | class GPSTrack { |
| 74 | |
| 75 | private: |
| 76 | |
| 77 | std::vector <GPSPoint> data; |
| 78 | |
| 79 | public: |
| 80 | |
| 81 | GPSTrack(); |
| 82 | ~GPSTrack(); |
| 83 | |
| 84 | int load( const std::string &file ); |
| 85 | |
| 86 | inline int size() const { return data.size(); } |
| 87 | |
| 88 | inline GPSPoint get_point( const unsigned int i ) |
| 89 | { |
| 90 | if ( i < data.size() ) { |
| 91 | return data[i]; |
| 92 | } else { |
| 93 | return GPSPoint(); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | |
| 98 | }; |
| 99 | |
| 100 | |
| 101 | GPSPoint GPSInterpolate( const GPSPoint A, const GPSPoint B, |
| 102 | const double percent ); |