diff --git a/src/algorithms/PVT/libs/nmea_printer.cc b/src/algorithms/PVT/libs/nmea_printer.cc index c3213b90e..c313e6321 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_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 b45dd6028..24b184e81 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 & 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; }