[hamradio-commits] [gnss-sdr] 53/126: fixing error handling when writing to a serial bus

Carles Fernandez carles_fernandez-guest at moszumanska.debian.org
Sat Dec 26 18:38:01 UTC 2015


This is an automated email from the git hooks/post-receive script.

carles_fernandez-guest pushed a commit to branch next
in repository gnss-sdr.

commit 337dc3b2da52c0bd6e8090ec0a06f51f03b7c53e
Author: Carles Fernandez <carles.fernandez at gmail.com>
Date:   Tue Nov 24 17:57:05 2015 +0100

    fixing error handling when writing to a serial bus
---
 src/algorithms/PVT/libs/nmea_printer.cc | 36 ++++++++++++++++++---------------
 src/algorithms/PVT/libs/rtcm_printer.cc | 24 +++++++++++-----------
 2 files changed, 32 insertions(+), 28 deletions(-)

diff --git a/src/algorithms/PVT/libs/nmea_printer.cc b/src/algorithms/PVT/libs/nmea_printer.cc
index c3213b9..c313e63 100644
--- a/src/algorithms/PVT/libs/nmea_printer.cc
+++ b/src/algorithms/PVT/libs/nmea_printer.cc
@@ -173,22 +173,26 @@ bool Nmea_Printer::Print_Nmea_Line(const std::shared_ptr<Pvt_Solution>& pvt_data
     //write to serial device
     if (nmea_dev_descriptor!=-1)
         {
-            try
-            {
-                    int n_bytes_written;
-                    //GPRMC
-                    n_bytes_written = write(nmea_dev_descriptor, GPRMC.c_str(), GPRMC.length());
-                    //GPGGA (Global Positioning System Fixed Data)
-                    n_bytes_written = write(nmea_dev_descriptor, GPGGA.c_str(), GPGGA.length());
-                    //GPGSA
-                    n_bytes_written = write(nmea_dev_descriptor, GPGSA.c_str(), GPGSA.length());
-                    //GPGSV
-                    n_bytes_written = write(nmea_dev_descriptor, GPGSV.c_str(), GPGSV.length());
-            }
-            catch(std::exception ex)
-            {
-                    DLOG(INFO) << "NMEA printer can not write on serial device" << nmea_filename.c_str();;
-            }
+            if(write(nmea_dev_descriptor, GPRMC.c_str(), GPRMC.length()) == -1)
+                {
+                    DLOG(INFO) << "NMEA printer cannot write on serial device" << nmea_devname.c_str();
+                    return false;
+                }
+            if(write(nmea_dev_descriptor, GPGGA.c_str(), GPGGA.length()) == -1)
+                {
+                    DLOG(INFO) << "NMEA printer cannot write on serial device" << nmea_devname.c_str();
+                    return false;
+                }
+            if(write(nmea_dev_descriptor, GPGSA.c_str(), GPGSA.length()) == -1)
+                {
+                    DLOG(INFO) << "NMEA printer cannot write on serial device" << nmea_devname.c_str();
+                    return false;
+                }
+            if(write(nmea_dev_descriptor, GPGSV.c_str(), GPGSV.length()) == -1)
+                {
+                    DLOG(INFO) << "NMEA printer cannot write on serial device" << nmea_devname.c_str();
+                    return false;
+                }
         }
     return true;
 }
diff --git a/src/algorithms/PVT/libs/rtcm_printer.cc b/src/algorithms/PVT/libs/rtcm_printer.cc
index b45dd60..24b184e 100644
--- a/src/algorithms/PVT/libs/rtcm_printer.cc
+++ b/src/algorithms/PVT/libs/rtcm_printer.cc
@@ -86,11 +86,12 @@ Rtcm_Printer::~Rtcm_Printer()
 
 bool Rtcm_Printer::Print_Rtcm_MT1001(const Gps_Ephemeris& gps_eph, double obs_time, const std::map<int, Gnss_Synchro> & pseudoranges)
 {
-    std::string m1001 = rtcm->print_MT1001( gps_eph, obs_time, pseudoranges);
+    std::string m1001 = rtcm->print_MT1001(gps_eph, obs_time, pseudoranges);
     Rtcm_Printer::Print_Message(m1001);
     return true;
 }
 
+
 bool Rtcm_Printer::Print_Rtcm_MT1019(const Gps_Ephemeris & gps_eph)
 {
     std::string m1019 = rtcm->print_MT1019(gps_eph);
@@ -98,6 +99,7 @@ bool Rtcm_Printer::Print_Rtcm_MT1019(const Gps_Ephemeris & gps_eph)
     return true;
 }
 
+
 bool Rtcm_Printer::Print_Rtcm_MT1045(const Galileo_Ephemeris & gal_eph)
 {
     std::string m1045 = rtcm->print_MT1045(gal_eph);
@@ -156,28 +158,26 @@ void Rtcm_Printer::close_serial()
 
 bool Rtcm_Printer::Print_Message(std::string message)
 {
+    //write to file
     try
     {
             rtcm_file_descriptor << message << std::endl;
-
     }
     catch(std::exception ex)
     {
             DLOG(INFO) << "RTCM printer can not write on output file" << rtcm_filename.c_str();
+            return false;
     }
 
     //write to serial device
-    if (rtcm_dev_descriptor!=-1)
+    if (rtcm_dev_descriptor != -1)
         {
-            try
-            {
-                    int n_bytes_written;
-                    n_bytes_written = write(rtcm_dev_descriptor, message.c_str(), message.length());
-            }
-            catch(std::exception ex)
-            {
-                    DLOG(INFO) << "RTCM printer can not write on serial device" << rtcm_filename.c_str();;
-            }
+            if(write(rtcm_dev_descriptor, message.c_str(), message.length()) == -1)
+                {
+                    DLOG(INFO) << "RTCM printer cannot write on serial device" << rtcm_devname.c_str();
+                    std::cout << "RTCM printer cannot write on serial device" << rtcm_devname.c_str() << std::endl;
+                    return false;
+                }
         }
     return true;
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-hamradio/gnss-sdr.git



More information about the pkg-hamradio-commits mailing list