From: James Turner Date: Sun, 16 Mar 2014 22:35:00 +0000 (+0000) Subject: Rename GPSsmooth files. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2d5d43a57d8c0aeb655ae9255cd767f35f6f8517;p=flightgear.git Rename GPSsmooth files. - avoid confusion with GPS instrument files. --- diff --git a/utils/GPSsmooth/CMakeLists.txt b/utils/GPSsmooth/CMakeLists.txt index 2349cc727..a76c9521d 100644 --- a/utils/GPSsmooth/CMakeLists.txt +++ b/utils/GPSsmooth/CMakeLists.txt @@ -1,6 +1,6 @@ add_executable(GPSsmooth - gps.cxx gps.hxx + GPSsmooth.cxx GPSsmooth.hxx gps_main.cxx ) diff --git a/utils/GPSsmooth/GPSsmooth.cxx b/utils/GPSsmooth/GPSsmooth.cxx new file mode 100644 index 000000000..c3ddde99e --- /dev/null +++ b/utils/GPSsmooth/GPSsmooth.cxx @@ -0,0 +1,165 @@ +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include + +#include +#include +#include + +#include "GPSsmooth.hxx" + +using std::cout; +using std::endl; + + +GPSTrack::GPSTrack() {}; +GPSTrack::~GPSTrack() {}; + + +// load the specified file, return the number of records loaded +int GPSTrack::load( const string &file ) { + int count = 0; + + data.clear(); + + // openg the file + sg_gzifstream in( file ); + if ( !in.is_open() ) { + cout << "Cannot open file: " << file << endl; + return 0; + } + + vector tokens; + GPSPoint p; + + while ( ! in.eof() ) { + char tmp[2049]; + + in.getline(tmp, 2048); + + tokens.clear(); + tokens = simgear::strutils::split(tmp, ","); + + int dd; + double raw, min; + + if ( tokens[0] == "$GPRMC" && tokens.size() == 13 ) { + double raw_time = atof(tokens[1].c_str()); + GPSTime gps_time = GPSTime( raw_time ); + if ( (gps_time.get_time() > p.gps_time.get_time()) && + (p.gps_time.get_time() > 1.0) ) + { + // new data cycle store last data before continuing + data.push_back( p ); + count++; + } + + p.gps_time = gps_time; + + raw = atof( tokens[3].c_str() ); + dd = (int)(raw / 100.00); + min = raw - dd * 100.0; + p.lat_deg = dd + min / 60.0; + if ( tokens[4] == "S" ) { + p.lat_deg = -p.lat_deg; + } + raw = atof( tokens[5].c_str() ); + dd = (int)(raw / 100.00); + min = raw - dd * 100.0; + p.lon_deg = dd + min / 60.0; + if ( tokens[6] == "W" ) { + p.lon_deg = -p.lon_deg; + } + + static double max_speed = 0.0; + p.speed_kts = atof( tokens[7].c_str() ); + if ( p.speed_kts > max_speed ) { + max_speed = p.speed_kts; + cout << "max speed = " << max_speed << endl; + } + p.course_true = atof( tokens[8].c_str() ) * SGD_DEGREES_TO_RADIANS; + + } else if ( tokens[0] == "$GPGGA" && tokens.size() == 15 ) { + double raw_time = atof(tokens[1].c_str()); + GPSTime gps_time = GPSTime( raw_time ); + if ( fabs(gps_time.get_time() - p.gps_time.get_time()) > 0.0001 && + (p.gps_time.get_time() > 1.0) ) { + // new data cycle store last data before continuing + data.push_back( p ); + count++; + } + + p.gps_time = gps_time; + + raw = atof( tokens[2].c_str() ); + dd = (int)(raw / 100.00); + min = raw - dd * 100.0; + p.lat_deg = dd + min / 60.0; + if ( tokens[3] == "S" ) { + p.lat_deg = -p.lat_deg; + } + raw = atof( tokens[4].c_str() ); + dd = (int)(raw / 100.00); + min = raw - dd * 100.0; + p.lon_deg = dd + min / 60.0; + if ( tokens[5] == "W" ) { + p.lon_deg = -p.lon_deg; + } + + p.fix_quality = atoi( tokens[6].c_str() ); + p.num_satellites = atoi( tokens[7].c_str() ); + p.hdop = atof( tokens[8].c_str() ); + + static double max_alt = 0.0; + double alt = atof( tokens[9].c_str() ); + if ( alt > max_alt ) { + max_alt = alt; + cout << "max alt = " << max_alt << endl; + } + + if ( tokens[10] == "F" || tokens[10] == "f" ) { + alt *= SG_FEET_TO_METER; + } + p.altitude_msl = alt; + } + } + + return count; +} + + +static double interp( double a, double b, double p, bool rotational = false ) { + double diff = b - a; + if ( rotational ) { + // special handling of rotational data + if ( diff > SGD_PI ) { + diff -= SGD_2PI; + } else if ( diff < -SGD_PI ) { + diff += SGD_2PI; + } + } + return a + diff * p; +} + + +GPSPoint GPSInterpolate( const GPSPoint A, const GPSPoint B, + const double percent ) { + GPSPoint p; + p.gps_time = GPSTime((int)interp(A.gps_time.get_time(), + B.gps_time.get_time(), + percent)); + p.lat_deg = interp(A.lat_deg, B.lat_deg, percent); + p.lon_deg = interp(A.lon_deg, B.lon_deg, percent); + p.fix_quality = (int)interp(A.fix_quality, B.fix_quality, percent); + p.num_satellites = (int)interp(A.num_satellites, B.num_satellites, percent); + p.hdop = interp(A.hdop, B.hdop, percent); + p.altitude_msl = interp(A.altitude_msl, B.altitude_msl, percent); + p.speed_kts = interp(A.speed_kts, B.speed_kts, percent); + p.course_true = interp(A.course_true, B.course_true, percent, true); + + return p; +} diff --git a/utils/GPSsmooth/GPSsmooth.hxx b/utils/GPSsmooth/GPSsmooth.hxx new file mode 100644 index 000000000..2795c92cb --- /dev/null +++ b/utils/GPSsmooth/GPSsmooth.hxx @@ -0,0 +1,109 @@ +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include +#include +#include + +using std::cout; +using std::endl; +using std::string; +using std::vector; + + +// encapsulate a gps integer time (fixme, assumes all times in a track +// are from the same day, so we don't handle midnight roll over) +class GPSTime { + +public: + + double seconds; + + inline GPSTime( const int hh, const int mm, const double ss ) { + seconds = hh*3600 + mm*60 + ss; + } + inline GPSTime( const double gpstime ) { + double tmp = gpstime; + int hh = (int)(tmp / 10000); + tmp -= hh * 10000; + int mm = (int)(tmp / 100); + tmp -= mm * 100; + double ss = tmp; + seconds = hh*3600 + mm*60 + ss; + // cout << gpstime << " = " << seconds << endl; + } + inline ~GPSTime() {} + + inline double get_time() const { return seconds; } + inline double diff_sec( const GPSTime t ) const { + return seconds - t.seconds; + } +}; + + + +// encapsulate the interesting gps data for a moment in time +class GPSPoint { + +public: + + GPSTime gps_time; + double lat_deg; + double lon_deg; + int fix_quality; + int num_satellites; + double hdop; + double altitude_msl; + double speed_kts; + double course_true; + + GPSPoint() : + gps_time(GPSTime(0,0,0)), + lat_deg(0.0), + lon_deg(0.0), + fix_quality(0), + num_satellites(0), + hdop(0.0), + altitude_msl(0.0), + speed_kts(0.0), + course_true(0.0) + { } + + inline double get_time() const { return gps_time.get_time(); } +}; + + +// Manage a saved gps log (track file) +class GPSTrack { + +private: + + vector data; + +public: + + GPSTrack(); + ~GPSTrack(); + + int load( const string &file ); + + inline int size() const { return data.size(); } + + inline GPSPoint get_point( const unsigned int i ) + { + if ( i < data.size() ) { + return data[i]; + } else { + return GPSPoint(); + } + } + + +}; + + +GPSPoint GPSInterpolate( const GPSPoint A, const GPSPoint B, + const double percent ); diff --git a/utils/GPSsmooth/gps.cxx b/utils/GPSsmooth/gps.cxx deleted file mode 100644 index 1d6a79c22..000000000 --- a/utils/GPSsmooth/gps.cxx +++ /dev/null @@ -1,165 +0,0 @@ -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#include - -#include -#include -#include - -#include "gps.hxx" - -using std::cout; -using std::endl; - - -GPSTrack::GPSTrack() {}; -GPSTrack::~GPSTrack() {}; - - -// load the specified file, return the number of records loaded -int GPSTrack::load( const string &file ) { - int count = 0; - - data.clear(); - - // openg the file - sg_gzifstream in( file ); - if ( !in.is_open() ) { - cout << "Cannot open file: " << file << endl; - return 0; - } - - vector tokens; - GPSPoint p; - - while ( ! in.eof() ) { - char tmp[2049]; - - in.getline(tmp, 2048); - - tokens.clear(); - tokens = simgear::strutils::split(tmp, ","); - - int dd; - double raw, min; - - if ( tokens[0] == "$GPRMC" && tokens.size() == 13 ) { - double raw_time = atof(tokens[1].c_str()); - GPSTime gps_time = GPSTime( raw_time ); - if ( (gps_time.get_time() > p.gps_time.get_time()) && - (p.gps_time.get_time() > 1.0) ) - { - // new data cycle store last data before continuing - data.push_back( p ); - count++; - } - - p.gps_time = gps_time; - - raw = atof( tokens[3].c_str() ); - dd = (int)(raw / 100.00); - min = raw - dd * 100.0; - p.lat_deg = dd + min / 60.0; - if ( tokens[4] == "S" ) { - p.lat_deg = -p.lat_deg; - } - raw = atof( tokens[5].c_str() ); - dd = (int)(raw / 100.00); - min = raw - dd * 100.0; - p.lon_deg = dd + min / 60.0; - if ( tokens[6] == "W" ) { - p.lon_deg = -p.lon_deg; - } - - static double max_speed = 0.0; - p.speed_kts = atof( tokens[7].c_str() ); - if ( p.speed_kts > max_speed ) { - max_speed = p.speed_kts; - cout << "max speed = " << max_speed << endl; - } - p.course_true = atof( tokens[8].c_str() ) * SGD_DEGREES_TO_RADIANS; - - } else if ( tokens[0] == "$GPGGA" && tokens.size() == 15 ) { - double raw_time = atof(tokens[1].c_str()); - GPSTime gps_time = GPSTime( raw_time ); - if ( fabs(gps_time.get_time() - p.gps_time.get_time()) > 0.0001 && - (p.gps_time.get_time() > 1.0) ) { - // new data cycle store last data before continuing - data.push_back( p ); - count++; - } - - p.gps_time = gps_time; - - raw = atof( tokens[2].c_str() ); - dd = (int)(raw / 100.00); - min = raw - dd * 100.0; - p.lat_deg = dd + min / 60.0; - if ( tokens[3] == "S" ) { - p.lat_deg = -p.lat_deg; - } - raw = atof( tokens[4].c_str() ); - dd = (int)(raw / 100.00); - min = raw - dd * 100.0; - p.lon_deg = dd + min / 60.0; - if ( tokens[5] == "W" ) { - p.lon_deg = -p.lon_deg; - } - - p.fix_quality = atoi( tokens[6].c_str() ); - p.num_satellites = atoi( tokens[7].c_str() ); - p.hdop = atof( tokens[8].c_str() ); - - static double max_alt = 0.0; - double alt = atof( tokens[9].c_str() ); - if ( alt > max_alt ) { - max_alt = alt; - cout << "max alt = " << max_alt << endl; - } - - if ( tokens[10] == "F" || tokens[10] == "f" ) { - alt *= SG_FEET_TO_METER; - } - p.altitude_msl = alt; - } - } - - return count; -} - - -static double interp( double a, double b, double p, bool rotational = false ) { - double diff = b - a; - if ( rotational ) { - // special handling of rotational data - if ( diff > SGD_PI ) { - diff -= SGD_2PI; - } else if ( diff < -SGD_PI ) { - diff += SGD_2PI; - } - } - return a + diff * p; -} - - -GPSPoint GPSInterpolate( const GPSPoint A, const GPSPoint B, - const double percent ) { - GPSPoint p; - p.gps_time = GPSTime((int)interp(A.gps_time.get_time(), - B.gps_time.get_time(), - percent)); - p.lat_deg = interp(A.lat_deg, B.lat_deg, percent); - p.lon_deg = interp(A.lon_deg, B.lon_deg, percent); - p.fix_quality = (int)interp(A.fix_quality, B.fix_quality, percent); - p.num_satellites = (int)interp(A.num_satellites, B.num_satellites, percent); - p.hdop = interp(A.hdop, B.hdop, percent); - p.altitude_msl = interp(A.altitude_msl, B.altitude_msl, percent); - p.speed_kts = interp(A.speed_kts, B.speed_kts, percent); - p.course_true = interp(A.course_true, B.course_true, percent, true); - - return p; -} diff --git a/utils/GPSsmooth/gps.hxx b/utils/GPSsmooth/gps.hxx deleted file mode 100644 index 2795c92cb..000000000 --- a/utils/GPSsmooth/gps.hxx +++ /dev/null @@ -1,109 +0,0 @@ -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#include -#include -#include - -using std::cout; -using std::endl; -using std::string; -using std::vector; - - -// encapsulate a gps integer time (fixme, assumes all times in a track -// are from the same day, so we don't handle midnight roll over) -class GPSTime { - -public: - - double seconds; - - inline GPSTime( const int hh, const int mm, const double ss ) { - seconds = hh*3600 + mm*60 + ss; - } - inline GPSTime( const double gpstime ) { - double tmp = gpstime; - int hh = (int)(tmp / 10000); - tmp -= hh * 10000; - int mm = (int)(tmp / 100); - tmp -= mm * 100; - double ss = tmp; - seconds = hh*3600 + mm*60 + ss; - // cout << gpstime << " = " << seconds << endl; - } - inline ~GPSTime() {} - - inline double get_time() const { return seconds; } - inline double diff_sec( const GPSTime t ) const { - return seconds - t.seconds; - } -}; - - - -// encapsulate the interesting gps data for a moment in time -class GPSPoint { - -public: - - GPSTime gps_time; - double lat_deg; - double lon_deg; - int fix_quality; - int num_satellites; - double hdop; - double altitude_msl; - double speed_kts; - double course_true; - - GPSPoint() : - gps_time(GPSTime(0,0,0)), - lat_deg(0.0), - lon_deg(0.0), - fix_quality(0), - num_satellites(0), - hdop(0.0), - altitude_msl(0.0), - speed_kts(0.0), - course_true(0.0) - { } - - inline double get_time() const { return gps_time.get_time(); } -}; - - -// Manage a saved gps log (track file) -class GPSTrack { - -private: - - vector data; - -public: - - GPSTrack(); - ~GPSTrack(); - - int load( const string &file ); - - inline int size() const { return data.size(); } - - inline GPSPoint get_point( const unsigned int i ) - { - if ( i < data.size() ) { - return data[i]; - } else { - return GPSPoint(); - } - } - - -}; - - -GPSPoint GPSInterpolate( const GPSPoint A, const GPSPoint B, - const double percent ); diff --git a/utils/GPSsmooth/gps_main.cxx b/utils/GPSsmooth/gps_main.cxx index 998a23510..2118b9f24 100644 --- a/utils/GPSsmooth/gps_main.cxx +++ b/utils/GPSsmooth/gps_main.cxx @@ -20,7 +20,7 @@ #include #include -#include "gps.hxx" +#include "GPSsmooth.hxx" using std::cout;