mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2025-11-02 00:03:04 +00:00
Added TTY serial device NMEA output (Linux only)
git-svn-id: https://svn.code.sf.net/p/gnss-sdr/code/trunk@236 64b25241-fba3-4117-9849-534c7e92360d
This commit is contained in:
@@ -54,6 +54,8 @@ GpsL1CaPvt::GpsL1CaPvt(ConfigurationInterface* configuration,
|
||||
{
|
||||
|
||||
std::string default_dump_filename = "./pvt.dat";
|
||||
std::string default_nmea_dump_filename = "./nmea_pvt.nmea";
|
||||
std::string default_nmea_dump_devname = "/dev/tty1";
|
||||
|
||||
DLOG(INFO) << "role " << role;
|
||||
|
||||
@@ -71,7 +73,16 @@ GpsL1CaPvt::GpsL1CaPvt(ConfigurationInterface* configuration,
|
||||
dump_ = configuration->property(role + ".dump", false);
|
||||
dump_filename_ = configuration->property(role + ".dump_filename", default_dump_filename);
|
||||
|
||||
pvt_ = gps_l1_ca_make_pvt_cc(in_streams_, queue_, dump_, dump_filename_, averaging_depth, flag_averaging, output_rate_ms, display_rate_ms);
|
||||
// NMEA Printer settings
|
||||
|
||||
bool flag_nmea_tty_port;
|
||||
flag_nmea_tty_port = configuration->property(role + ".flag_nmea_tty_port", false);
|
||||
std::string nmea_dump_filename;
|
||||
nmea_dump_filename = configuration->property(role + ".nmea_dump_filename", default_nmea_dump_filename);
|
||||
std::string nmea_dump_devname;
|
||||
nmea_dump_devname = configuration->property(role + ".nmea_dump_devname", default_nmea_dump_devname);
|
||||
|
||||
pvt_ = gps_l1_ca_make_pvt_cc(in_streams_, queue_, dump_, dump_filename_, averaging_depth, flag_averaging, output_rate_ms, display_rate_ms,flag_nmea_tty_port,nmea_dump_filename,nmea_dump_devname);
|
||||
|
||||
DLOG(INFO) << "pvt(" << pvt_->unique_id() << ")";
|
||||
// set the navigation msg queue;
|
||||
|
||||
@@ -47,13 +47,13 @@ using google::LogMessage;
|
||||
|
||||
|
||||
gps_l1_ca_pvt_cc_sptr
|
||||
gps_l1_ca_make_pvt_cc(unsigned int nchannels, gr_msg_queue_sptr queue, bool dump, std::string dump_filename, int averaging_depth, bool flag_averaging, int output_rate_ms, int display_rate_ms)
|
||||
gps_l1_ca_make_pvt_cc(unsigned int nchannels, gr_msg_queue_sptr queue, bool dump, std::string dump_filename, int averaging_depth, bool flag_averaging, int output_rate_ms, int display_rate_ms, bool flag_nmea_tty_port, std::string nmea_dump_filename, std::string nmea_dump_devname)
|
||||
{
|
||||
return gps_l1_ca_pvt_cc_sptr(new gps_l1_ca_pvt_cc(nchannels, queue, dump, dump_filename, averaging_depth, flag_averaging, output_rate_ms, display_rate_ms));
|
||||
return gps_l1_ca_pvt_cc_sptr(new gps_l1_ca_pvt_cc(nchannels, queue, dump, dump_filename, averaging_depth, flag_averaging, output_rate_ms, display_rate_ms, flag_nmea_tty_port, nmea_dump_filename, nmea_dump_devname));
|
||||
}
|
||||
|
||||
|
||||
gps_l1_ca_pvt_cc::gps_l1_ca_pvt_cc(unsigned int nchannels, gr_msg_queue_sptr queue, bool dump, std::string dump_filename, int averaging_depth, bool flag_averaging, int output_rate_ms, int display_rate_ms) :
|
||||
gps_l1_ca_pvt_cc::gps_l1_ca_pvt_cc(unsigned int nchannels, gr_msg_queue_sptr queue, bool dump, std::string dump_filename, int averaging_depth, bool flag_averaging, int output_rate_ms, int display_rate_ms, bool flag_nmea_tty_port, std::string nmea_dump_filename, std::string nmea_dump_devname) :
|
||||
gr_block ("gps_l1_ca_pvt_cc", gr_make_io_signature (nchannels, nchannels, sizeof(Gnss_Synchro)),
|
||||
gr_make_io_signature(1, 1, sizeof(gr_complex)))
|
||||
{
|
||||
@@ -74,10 +74,7 @@ gps_l1_ca_pvt_cc::gps_l1_ca_pvt_cc(unsigned int nchannels, gr_msg_queue_sptr que
|
||||
d_kml_dump.set_headers(kml_dump_filename);
|
||||
|
||||
//initialize nmea_printer
|
||||
std::string nmea_dump_filename;
|
||||
nmea_dump_filename = d_dump_filename;
|
||||
nmea_dump_filename.append(".nmea");
|
||||
d_nmea_printer=new Nmea_Printer(nmea_dump_filename);
|
||||
d_nmea_printer=new Nmea_Printer(nmea_dump_filename,flag_nmea_tty_port,nmea_dump_devname);
|
||||
|
||||
d_dump_filename.append("_raw.dat");
|
||||
dump_ls_pvt_filename.append("_ls_pvt.dat");
|
||||
|
||||
@@ -49,7 +49,7 @@ class gps_l1_ca_pvt_cc;
|
||||
typedef boost::shared_ptr<gps_l1_ca_pvt_cc> gps_l1_ca_pvt_cc_sptr;
|
||||
|
||||
gps_l1_ca_pvt_cc_sptr
|
||||
gps_l1_ca_make_pvt_cc(unsigned int n_channels, gr_msg_queue_sptr queue, bool dump, std::string dump_filename, int averaging_depth, bool flag_averaging, int output_rate_ms, int display_rate_ms);
|
||||
gps_l1_ca_make_pvt_cc(unsigned int n_channels, gr_msg_queue_sptr queue, bool dump, std::string dump_filename, int averaging_depth, bool flag_averaging, int output_rate_ms, int display_rate_ms, bool flag_nmea_tty_port, std::string nmea_dump_filename, std::string nmea_dump_devname);
|
||||
|
||||
/*!
|
||||
* \brief This class implements a block that computes the PVT solution
|
||||
@@ -60,9 +60,9 @@ class gps_l1_ca_pvt_cc : public gr_block
|
||||
private:
|
||||
|
||||
friend gps_l1_ca_pvt_cc_sptr
|
||||
gps_l1_ca_make_pvt_cc(unsigned int nchannels, gr_msg_queue_sptr queue, bool dump, std::string dump_filename, int averaging_depth, bool flag_averaging, int output_rate_ms, int display_rate_ms);
|
||||
gps_l1_ca_make_pvt_cc(unsigned int nchannels, gr_msg_queue_sptr queue, bool dump, std::string dump_filename, int averaging_depth, bool flag_averaging, int output_rate_ms, int display_rate_ms, bool flag_nmea_tty_port, std::string nmea_dump_filename, std::string nmea_dump_devname);
|
||||
|
||||
gps_l1_ca_pvt_cc(unsigned int nchannels, gr_msg_queue_sptr queue, bool dump, std::string dump_filename, int averaging_depth, bool flag_averaging, int output_rate_ms, int display_rate_ms);
|
||||
gps_l1_ca_pvt_cc(unsigned int nchannels, gr_msg_queue_sptr queue, bool dump, std::string dump_filename, int averaging_depth, bool flag_averaging, int output_rate_ms, int display_rate_ms, bool flag_nmea_tty_port, std::string nmea_dump_filename, std::string nmea_dump_devname);
|
||||
|
||||
gr_msg_queue_sptr d_queue;
|
||||
bool d_dump;
|
||||
|
||||
@@ -37,6 +37,8 @@
|
||||
#include <glog/logging.h>
|
||||
#include <gflags/gflags.h>
|
||||
#include "boost/date_time/posix_time/posix_time.hpp"
|
||||
#include <fcntl.h>
|
||||
#include <termios.h>
|
||||
#include "GPS_L1_CA.h"
|
||||
#include "nmea_printer.h"
|
||||
|
||||
@@ -44,7 +46,7 @@ using google::LogMessage;
|
||||
|
||||
//DEFINE_string(NMEA_version, "2.1", "Specifies the NMEA version (2.1)");
|
||||
|
||||
Nmea_Printer::Nmea_Printer(std::string filename)
|
||||
Nmea_Printer::Nmea_Printer(std::string filename, bool flag_nmea_tty_port, std::string nmea_dump_devname)
|
||||
{
|
||||
nmea_filename=filename;
|
||||
nmea_file_descriptor.open(nmea_filename.c_str(), std::ios::out);
|
||||
@@ -52,6 +54,19 @@ Nmea_Printer::Nmea_Printer(std::string filename)
|
||||
{
|
||||
DLOG(INFO) << "NMEA printer writing on " << nmea_filename.c_str();
|
||||
}
|
||||
|
||||
nmea_devname=nmea_dump_devname;
|
||||
if (flag_nmea_tty_port==true)
|
||||
{
|
||||
|
||||
nmea_dev_descriptor=init_serial(nmea_devname.c_str());
|
||||
if (nmea_dev_descriptor!=-1)
|
||||
{
|
||||
DLOG(INFO) << "NMEA printer writing on " << nmea_devname.c_str();
|
||||
}
|
||||
}else{
|
||||
nmea_dev_descriptor=-1;
|
||||
}
|
||||
}
|
||||
|
||||
Nmea_Printer::~Nmea_Printer()
|
||||
@@ -60,30 +75,112 @@ Nmea_Printer::~Nmea_Printer()
|
||||
{
|
||||
nmea_file_descriptor.close();
|
||||
}
|
||||
close_serial();
|
||||
}
|
||||
|
||||
|
||||
int Nmea_Printer::init_serial (std::string serial_device) {
|
||||
/*!
|
||||
* Opens the serial device and sets the deffault baud rate for a NMEA transmission (9600,8,N,1)
|
||||
*/
|
||||
int fd = 0;
|
||||
struct termios options;
|
||||
|
||||
long BAUD;
|
||||
long DATABITS;
|
||||
long STOPBITS;
|
||||
long PARITYON;
|
||||
long PARITY;
|
||||
|
||||
fd = open(serial_device.c_str(), O_RDWR | O_NOCTTY | O_NDELAY);
|
||||
if (fd == -1) return fd; //failed to open TTY port
|
||||
|
||||
fcntl(fd, F_SETFL, 0); // clear all flags on descriptor, enable direct I/O
|
||||
tcgetattr(fd, &options); // read serial port options
|
||||
|
||||
BAUD = B9600;
|
||||
//BAUD = B38400;
|
||||
DATABITS = CS8;
|
||||
STOPBITS = 0;
|
||||
PARITYON = 0;
|
||||
PARITY = 0;
|
||||
|
||||
options.c_cflag = BAUD | DATABITS | STOPBITS | PARITYON | PARITY | CLOCAL | CREAD;
|
||||
// enable receiver, set 8 bit data, ignore control lines
|
||||
//options.c_cflag |= (CLOCAL | CREAD | CS8);
|
||||
options.c_iflag = IGNPAR;
|
||||
|
||||
// set the new port options
|
||||
tcsetattr(fd, TCSANOW, &options);
|
||||
return fd;
|
||||
}
|
||||
|
||||
void Nmea_Printer::close_serial ()
|
||||
{
|
||||
if (nmea_dev_descriptor != -1)
|
||||
{
|
||||
close(nmea_dev_descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
bool Nmea_Printer::Print_Nmea_Line(gps_l1_ca_ls_pvt* pvt_data, bool print_average_values)
|
||||
{
|
||||
|
||||
std::string GPRMC;
|
||||
std::string GPGGA;
|
||||
std::string GPGSA;
|
||||
std::string GPGSV;
|
||||
|
||||
// set the new PVT data
|
||||
d_PVT_data=pvt_data;
|
||||
|
||||
// generate the NMEA sentences
|
||||
|
||||
//GPRMC
|
||||
GPRMC=get_GPRMC();
|
||||
//GPGGA (Global Positioning System Fixed Data)
|
||||
GPGGA=get_GPGGA();
|
||||
//GPGSA
|
||||
GPGSA=get_GPGSA();
|
||||
//GPGSV
|
||||
GPGSV=get_GPGSV();
|
||||
|
||||
// write to log file
|
||||
try{
|
||||
//GPRMC
|
||||
nmea_file_descriptor<<get_GPRMC();
|
||||
nmea_file_descriptor<<GPRMC;
|
||||
//GPGGA (Global Positioning System Fixed Data)
|
||||
nmea_file_descriptor<<get_GPGGA();
|
||||
nmea_file_descriptor<<GPGGA;
|
||||
//GPGSA
|
||||
nmea_file_descriptor<<get_GPGSA();
|
||||
nmea_file_descriptor<<GPGSA;
|
||||
//GPGSV
|
||||
nmea_file_descriptor<<get_GPGSV();
|
||||
nmea_file_descriptor<<GPGSV;
|
||||
|
||||
}catch(std::exception ex)
|
||||
{
|
||||
DLOG(INFO) << "NMEA printer can not write on output file" << nmea_filename.c_str();;
|
||||
}
|
||||
|
||||
//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();;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
/*!
|
||||
* \brief Default constructor.
|
||||
*/
|
||||
Nmea_Printer(std::string filename);
|
||||
Nmea_Printer(std::string filename, bool flag_nmea_tty_port, std::string nmea_dump_filename);
|
||||
|
||||
/*!
|
||||
* \brief Print NMEA PVT and satellite info to the initialized device
|
||||
@@ -63,9 +63,14 @@ public:
|
||||
private:
|
||||
std::string nmea_filename ; //<! String with the NMEA log filename
|
||||
std::ofstream nmea_file_descriptor ; //<! Output file stream for NMEA log file
|
||||
std::string nmea_devname;
|
||||
int nmea_dev_descriptor ; //<! NMEA serial device descriptor (i.e. COM port)
|
||||
|
||||
gps_l1_ca_ls_pvt* d_PVT_data;
|
||||
|
||||
int init_serial (std::string serial_device); //serial port control
|
||||
void close_serial ();
|
||||
|
||||
std::string get_GPGGA();
|
||||
std::string get_GPGSV();
|
||||
std::string get_GPGSA();
|
||||
|
||||
Reference in New Issue
Block a user