]> git.mxchange.org Git - flightgear.git/blobdiff - utils/GPSsmooth/UGear.cxx
Replace the NOAA METAR URL with the new, updated one
[flightgear.git] / utils / GPSsmooth / UGear.cxx
index b8eeb8a9aef3191add4e893b61691c75767cff69..604926c19dbd9b917a4a2214d7ab714dac53d205 100644 (file)
@@ -1,8 +1,9 @@
 #ifdef HAVE_CONFIG_H
 #  include <config.h>
-#endif 
+#endif
 
 #include <iostream>
+#include <cstdio>
 
 #include <simgear/constants.h>
 #include <simgear/io/sg_file.hxx>
 
 #include "UGear.hxx"
 
-SG_USING_STD(cout);
-SG_USING_STD(endl);
+using std::cout;
+using std::endl;
 
 
 #define START_OF_MSG0 147
 #define START_OF_MSG1 224
 
 
-UGEARTrack::UGEARTrack():
+UGTrack::UGTrack():
     sg_swap(false)
 {
 };
 
-UGEARTrack::~UGEARTrack() {};
+UGTrack::~UGTrack() {};
 
 
 // swap the 1st 4 bytes with the last 4 bytes of a stargate double so
@@ -91,7 +92,7 @@ static bool validate_cksum( uint8_t id, uint8_t size, char *buf,
 }
 
 
-void UGEARTrack::parse_msg( const int id, char *buf,
+void UGTrack::parse_msg( const int id, char *buf,
                            struct gps *gpspacket, imu *imupacket,
                            nav *navpacket, servo *servopacket,
                            health *healthpacket )
@@ -144,7 +145,7 @@ void UGEARTrack::parse_msg( const int id, char *buf,
       if ( sg_swap ) {
           servopacket->time = sg_swap_double( (uint8_t *)buf, 0 );
       }
-      // printf("servo time = %.3f\n", servopacket->time);
+      // printf("servo time = %.3f %d %d\n", servopacket->time, servopacket->chn[0], servopacket->chn[1]);
     } else if ( id == HEALTH_PACKET ) {
       *healthpacket = *(struct health *)buf;
       if ( sg_swap ) {
@@ -157,7 +158,7 @@ void UGEARTrack::parse_msg( const int id, char *buf,
 
 
 // load the named stream log file into internal buffers
-bool UGEARTrack::load_stream( const string &file, bool ignore_checksum ) {
+bool UGTrack::load_stream( const string &file, bool ignore_checksum ) {
     int count = 0;
 
     gps gpspacket;
@@ -236,7 +237,7 @@ bool UGEARTrack::load_stream( const string &file, bool ignore_checksum ) {
 
 
 // load the named stream log file into internal buffers
-bool UGEARTrack::load_flight( const string &path ) {
+bool UGTrack::load_flight( const string &path ) {
     gps gpspacket;
     imu imupacket;
     nav navpacket;
@@ -260,8 +261,10 @@ bool UGEARTrack::load_flight( const string &path ) {
 
     // open the gps file
     file = path; file.append( "gps.dat.gz" );
-    if ( (fgps = gzopen( file.c_str(), "r" )) == NULL ) {
-        printf("Cannont open %s\n", file.c_str());
+    std::string fdata = file.local8BitStr();
+
+    if ( (fgps = gzopen( fdata.c_str(), "r" )) == NULL ) {
+        printf("Cannot open %s\n", fdata.c_str());
         return false;
     }
 
@@ -273,8 +276,9 @@ bool UGEARTrack::load_flight( const string &path ) {
 
     // open the imu file
     file = path; file.append( "imu.dat.gz" );
-    if ( (fimu = gzopen( file.c_str(), "r" )) == NULL ) {
-        printf("Cannot open %s\n", file.c_str());
+    fdata = file.local8BitStr();
+    if ( (fimu = gzopen( fdata.c_str(), "r" )) == NULL ) {
+        printf("Cannot open %s\n", fdata.c_str());
         return false;
     }
 
@@ -286,8 +290,10 @@ bool UGEARTrack::load_flight( const string &path ) {
 
     // open the nav file
     file = path; file.append( "nav.dat.gz" );
-    if ( (fnav = gzopen( file.c_str(), "r" )) == NULL ) {
-        printf("Cannot open %s\n", file.c_str());
+    fdata = file.local8BitStr();
+
+    if ( (fnav = gzopen( fdata.c_str(), "r" )) == NULL ) {
+        printf("Cannot open %s\n", fdata.c_str());
         return false;
     }
 
@@ -300,8 +306,10 @@ bool UGEARTrack::load_flight( const string &path ) {
 
     // open the servo file
     file = path; file.append( "servo.dat.gz" );
-    if ( (fservo = gzopen( file.c_str(), "r" )) == NULL ) {
-        printf("Cannot open %s\n", file.c_str());
+    fdata = file.local8BitStr();
+
+    if ( (fservo = gzopen( fdata.c_str(), "r" )) == NULL ) {
+        printf("Cannot open %s\n", fdata.c_str());
         return false;
     }
 
@@ -313,8 +321,10 @@ bool UGEARTrack::load_flight( const string &path ) {
 
     // open the health file
     file = path; file.append( "health.dat.gz" );
-    if ( (fhealth = gzopen( file.c_str(), "r" )) == NULL ) {
-        printf("Cannot open %s\n", file.c_str());
+    fdata = file.local8BitStr();
+
+    if ( (fhealth = gzopen( fdata.c_str(), "r" )) == NULL ) {
+        printf("Cannot open %s\n", fdata.c_str());
         return false;
     }
 
@@ -373,7 +383,7 @@ int serial_read( SGSerialPort *serial, SGIOChannel *log,
 
 
 // load the next message of a real time data stream
-int UGEARTrack::next_message( SGIOChannel *ch, SGIOChannel *log,
+int UGTrack::next_message( SGIOChannel *ch, SGIOChannel *log,
                              gps *gpspacket, imu *imupacket, nav *navpacket,
                              servo *servopacket, health *healthpacket,
                              bool ignore_checksum )
@@ -429,7 +439,7 @@ int UGEARTrack::next_message( SGIOChannel *ch, SGIOChannel *log,
     myread( ch, log, tmpbuf, 2 );
     uint8_t cksum0 = (unsigned char)tmpbuf[0];
     uint8_t cksum1 = (unsigned char)tmpbuf[1];
-    
+
     if ( validate_cksum( id, size, savebuf, cksum0, cksum1, ignore_checksum ) )
     {
         parse_msg( id, savebuf, gpspacket, imupacket, navpacket, servopacket,
@@ -443,14 +453,13 @@ int UGEARTrack::next_message( SGIOChannel *ch, SGIOChannel *log,
 
 
 // load the next message of a real time data stream
-int UGEARTrack::next_message( SGSerialPort *serial, SGIOChannel *log,
-                             gps *gpspacket, imu *imupacket, nav *navpacket,
-                             servo *servopacket, health *healthpacket,
-                             bool ignore_checksum )
+int UGTrack::next_message( SGSerialPort *serial, SGIOChannel *log,
+                           gps *gpspacket, imu *imupacket, nav *navpacket,
+                           servo *servopacket, health *healthpacket,
+                           bool ignore_checksum )
 {
     char tmpbuf[256];
     char savebuf[256];
-    int result = 0;
 
     // cout << "in next_message()" << endl;
 
@@ -459,7 +468,7 @@ int UGEARTrack::next_message( SGSerialPort *serial, SGIOChannel *log,
     // scan for sync characters
     int scan_count = 0;
     uint8_t sync0, sync1;
-    result = serial_read( serial, log, tmpbuf, 2 );
+    serial_read( serial, log, tmpbuf, 2 );
     sync0 = (unsigned char)tmpbuf[0];
     sync1 = (unsigned char)tmpbuf[1];
     while ( (sync0 != START_OF_MSG0 || sync1 != START_OF_MSG1) && !myeof ) {
@@ -492,7 +501,7 @@ int UGEARTrack::next_message( SGSerialPort *serial, SGIOChannel *log,
     uint8_t cksum1 = (unsigned char)tmpbuf[1];
     // cout << "cksum0 = " << (int)cksum0 << " cksum1 = " << (int)cksum1
     //      << endl;
-    
+
     if ( validate_cksum( id, size, savebuf, cksum0, cksum1, ignore_checksum ) )
     {
         parse_msg( id, savebuf, gpspacket, imupacket, navpacket, servopacket,
@@ -504,7 +513,7 @@ int UGEARTrack::next_message( SGSerialPort *serial, SGIOChannel *log,
     cout << "Check sum failure!" << endl;
     return -1;
 
-    
+
 }
 
 
@@ -592,9 +601,7 @@ servo UGEARInterpSERVO( const servo A, const servo B, const double percent )
 health UGEARInterpHEALTH( const health A, const health B, const double percent )
 {
     health p;
-    p.volts_raw = interp(A.volts_raw, B.volts_raw, percent);
-    p.volts = interp(A.volts, B.volts, percent);
-    p.est_seconds = (uint16_t)interp(A.est_seconds, B.est_seconds, percent);
+    p.command_sequence = B.command_sequence;
     p.time = interp(A.time, B.time, percent);
 
     return p;