1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-14 12:10:34 +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,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;
}

View File

@ -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;
}