1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-01-07 16:00:35 +00:00

fixing error handling when writing to a serial bus

This commit is contained in:
Carles Fernandez 2015-11-24 17:57:05 +01:00
parent 18dfe81a71
commit 337dc3b2da
2 changed files with 32 additions and 28 deletions

View File

@ -173,21 +173,25 @@ bool Nmea_Printer::Print_Nmea_Line(const std::shared_ptr<Pvt_Solution>& pvt_data
//write to serial device //write to serial device
if (nmea_dev_descriptor!=-1) if (nmea_dev_descriptor!=-1)
{ {
try if(write(nmea_dev_descriptor, GPRMC.c_str(), GPRMC.length()) == -1)
{ {
int n_bytes_written; DLOG(INFO) << "NMEA printer cannot write on serial device" << nmea_devname.c_str();
//GPRMC return false;
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) if(write(nmea_dev_descriptor, GPGGA.c_str(), GPGGA.length()) == -1)
{ {
DLOG(INFO) << "NMEA printer can not write on serial device" << nmea_filename.c_str();; 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; return true;

View File

@ -91,6 +91,7 @@ bool Rtcm_Printer::Print_Rtcm_MT1001(const Gps_Ephemeris& gps_eph, double obs_ti
return true; return true;
} }
bool Rtcm_Printer::Print_Rtcm_MT1019(const Gps_Ephemeris & gps_eph) bool Rtcm_Printer::Print_Rtcm_MT1019(const Gps_Ephemeris & gps_eph)
{ {
std::string m1019 = rtcm->print_MT1019(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; return true;
} }
bool Rtcm_Printer::Print_Rtcm_MT1045(const Galileo_Ephemeris & gal_eph) bool Rtcm_Printer::Print_Rtcm_MT1045(const Galileo_Ephemeris & gal_eph)
{ {
std::string m1045 = rtcm->print_MT1045(gal_eph); std::string m1045 = rtcm->print_MT1045(gal_eph);
@ -156,27 +158,25 @@ void Rtcm_Printer::close_serial()
bool Rtcm_Printer::Print_Message(std::string message) bool Rtcm_Printer::Print_Message(std::string message)
{ {
//write to file
try try
{ {
rtcm_file_descriptor << message << std::endl; rtcm_file_descriptor << message << std::endl;
} }
catch(std::exception ex) catch(std::exception ex)
{ {
DLOG(INFO) << "RTCM printer can not write on output file" << rtcm_filename.c_str(); DLOG(INFO) << "RTCM printer can not write on output file" << rtcm_filename.c_str();
return false;
} }
//write to serial device //write to serial device
if (rtcm_dev_descriptor != -1) if (rtcm_dev_descriptor != -1)
{ {
try if(write(rtcm_dev_descriptor, message.c_str(), message.length()) == -1)
{ {
int n_bytes_written; DLOG(INFO) << "RTCM printer cannot write on serial device" << rtcm_devname.c_str();
n_bytes_written = write(rtcm_dev_descriptor, message.c_str(), message.length()); std::cout << "RTCM printer cannot write on serial device" << rtcm_devname.c_str() << std::endl;
} return false;
catch(std::exception ex)
{
DLOG(INFO) << "RTCM printer can not write on serial device" << rtcm_filename.c_str();;
} }
} }
return true; return true;