mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2025-10-16 08:07:42 +00:00
Added a new tracking algorithm that uses TCP sockets to move the work of a processing block to a remote machine executing MATLAB Simulink.
git-svn-id: https://svn.code.sf.net/p/gnss-sdr/code/trunk@185 64b25241-fba3-4117-9849-534c7e92360d
This commit is contained in:
@@ -7,3 +7,4 @@ obj tracking_2nd_PLL_filter : tracking_2nd_PLL_filter.cc ;
|
||||
obj tracking_2nd_DLL_filter : tracking_2nd_DLL_filter.cc ;
|
||||
obj correlator : correlator.cc ;
|
||||
obj cordic : cordic.cc ;
|
||||
obj tcp_communication : tcp_communication.cc ;
|
||||
|
115
src/algorithms/tracking/libs/tcp_communication.cc
Normal file
115
src/algorithms/tracking/libs/tcp_communication.cc
Normal file
@@ -0,0 +1,115 @@
|
||||
/*!
|
||||
* \file tcp_communication.h
|
||||
* \brief Library with the definition of the TCP communication class
|
||||
* \author David Pubill, 2011. dpubill(at)cttc.es
|
||||
*
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors)
|
||||
*
|
||||
* GNSS-SDR is a software defined Global Navigation
|
||||
* Satellite Systems receiver
|
||||
*
|
||||
* This file is part of GNSS-SDR.
|
||||
*
|
||||
* GNSS-SDR is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* at your option) any later version.
|
||||
*
|
||||
* GNSS-SDR is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GNSS-SDR. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "tcp_packet_data.h"
|
||||
#include "tcp_communication.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
|
||||
#define NUM_TX_VARIABLES 7
|
||||
#define NUM_RX_VARIABLES 3
|
||||
|
||||
tcp_communication::tcp_communication() : tcp_socket_(io_service_){
|
||||
}
|
||||
|
||||
tcp_communication::~tcp_communication(){
|
||||
}
|
||||
|
||||
int tcp_communication::listen_tcp_connection(size_t d_port_)
|
||||
{
|
||||
try
|
||||
{
|
||||
//! Specify IP type and port
|
||||
boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), d_port_);
|
||||
boost::asio::ip::tcp::acceptor acceptor(io_service_, endpoint);
|
||||
|
||||
//! Reuse the IP address for each connection
|
||||
acceptor.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
|
||||
|
||||
std::cout << "Server ready on port " << d_port_ << std::endl;
|
||||
|
||||
//! Listen for a connection and accept it
|
||||
acceptor.listen(12);
|
||||
acceptor.accept(tcp_socket_);
|
||||
|
||||
std::cout << "Socket accepted on port " << d_port_ << std::endl;
|
||||
}
|
||||
|
||||
catch(std::exception& e)
|
||||
{
|
||||
std::cerr << "Exception: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void tcp_communication::send_receive_tcp_packet(boost::array<float, NUM_TX_VARIABLES> buf, tcp_packet_data *tcp_data_)
|
||||
{
|
||||
int controlc = 0;
|
||||
boost::array<float, NUM_RX_VARIABLES> readbuf;
|
||||
float d_control_id_ = buf.data()[6];
|
||||
|
||||
try
|
||||
{
|
||||
//! Send a TCP packet
|
||||
tcp_socket_.write_some(boost::asio::buffer(buf));
|
||||
|
||||
//! Read the received TCP packet
|
||||
tcp_socket_.read_some(boost::asio::buffer(readbuf));
|
||||
|
||||
//! Recover the variables received
|
||||
tcp_data_->proc_pack_code_error = readbuf.data()[0];
|
||||
tcp_data_->proc_pack_carr_error = readbuf.data()[1];
|
||||
|
||||
//! Control. The GNSS-SDR program ends if an error in a TCP packet is detected.
|
||||
if (d_control_id_ != readbuf.data()[2])
|
||||
{
|
||||
throw "Packet error!";
|
||||
}
|
||||
}
|
||||
|
||||
catch(std::exception& e)
|
||||
{
|
||||
std::cerr << "Exception: " << e.what() << ". Please press Ctrl+C to end the program." << std::endl;
|
||||
std::cin >> controlc;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void tcp_communication::close_tcp_connection(size_t d_port_)
|
||||
{
|
||||
//! Close the TCP connection
|
||||
tcp_socket_.close();
|
||||
std::cout << "Socket closed on port " << d_port_ << std::endl;
|
||||
|
||||
return;
|
||||
}
|
54
src/algorithms/tracking/libs/tcp_communication.h
Normal file
54
src/algorithms/tracking/libs/tcp_communication.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/*!
|
||||
* \file tcp_communication.h
|
||||
* \brief Library with the definition of the TCP communication class
|
||||
* \author David Pubill, 2011. dpubill(at)cttc.es
|
||||
*
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors)
|
||||
*
|
||||
* GNSS-SDR is a software defined Global Navigation
|
||||
* Satellite Systems receiver
|
||||
*
|
||||
* This file is part of GNSS-SDR.
|
||||
*
|
||||
* GNSS-SDR is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* at your option) any later version.
|
||||
*
|
||||
* GNSS-SDR is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GNSS-SDR. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef TCP_COMMUNICATION_H_
|
||||
#define TCP_COMMUNICATION_H_
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include "tcp_packet_data.h"
|
||||
|
||||
class tcp_communication
|
||||
{
|
||||
public:
|
||||
|
||||
tcp_communication();
|
||||
~tcp_communication();
|
||||
|
||||
int listen_tcp_connection(size_t d_port_);
|
||||
void send_receive_tcp_packet(boost::array<float, 7> buf, tcp_packet_data *tcp_data_);
|
||||
void close_tcp_connection(size_t d_port_);
|
||||
|
||||
private:
|
||||
boost::asio::io_service io_service_;
|
||||
boost::asio::ip::tcp::socket tcp_socket_;
|
||||
};
|
||||
|
||||
#endif
|
46
src/algorithms/tracking/libs/tcp_packet_data.h
Normal file
46
src/algorithms/tracking/libs/tcp_packet_data.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/*!
|
||||
* \file tcp_packet_data.h
|
||||
* \brief Library with the definition of the TCP packet data class
|
||||
* \author David Pubill, 2011. dpubill(at)cttc.es
|
||||
*
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors)
|
||||
*
|
||||
* GNSS-SDR is a software defined Global Navigation
|
||||
* Satellite Systems receiver
|
||||
*
|
||||
* This file is part of GNSS-SDR.
|
||||
*
|
||||
* GNSS-SDR is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* at your option) any later version.
|
||||
*
|
||||
* GNSS-SDR is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GNSS-SDR. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifndef TCP_PACKET_DATA_H_
|
||||
#define TCP_PACKET_DATA_H_
|
||||
|
||||
class tcp_packet_data
|
||||
{
|
||||
public:
|
||||
tcp_packet_data();
|
||||
|
||||
float proc_pack_code_error;
|
||||
float proc_pack_carr_error;
|
||||
|
||||
~tcp_packet_data();
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user