[Positioning] Add options output.udp-{host,port}
This commit is contained in:
parent
22cad4c214
commit
562ea6c28b
|
@ -72,13 +72,13 @@ void Output::initialise_output_terminal()
|
|||
|
||||
void Output::initialise_output_udp_socket()
|
||||
{
|
||||
if (! Configuration::is_configured("output.remote-ip"))
|
||||
if (! Configuration::is_configured("output.udp-host"))
|
||||
throw missing_configuration(
|
||||
"No remote ip specified in the configuration!") ;
|
||||
"No remote UDP host specified in the configuration!") ;
|
||||
|
||||
output_media.push_back(
|
||||
new OutputUDPSocket(
|
||||
Configuration::string_value("output.remote-ip"))) ;
|
||||
new OutputUDPSocket(Configuration::string_value("output.udp-host"),
|
||||
Configuration::int_value("output.udp-port"))) ;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#define PORT 9910
|
||||
|
||||
using namespace std ;
|
||||
|
||||
struct hostent *hostInfo ;
|
||||
|
@ -16,8 +14,9 @@ struct sockaddr_in serverAddress ;
|
|||
/* *** Constructors *** */
|
||||
|
||||
|
||||
OutputUDPSocket::OutputUDPSocket(const string &_remote_ip):
|
||||
remote_ip(_remote_ip)
|
||||
OutputUDPSocket::OutputUDPSocket(const string &_remote_host,
|
||||
const uint_fast16_t _remote_port):
|
||||
remote_host(_remote_host), remote_port(_remote_port)
|
||||
{
|
||||
init_socket() ;
|
||||
}
|
||||
|
@ -56,13 +55,12 @@ void OutputUDPSocket::write(const Result &result)
|
|||
void OutputUDPSocket::init_socket()
|
||||
{
|
||||
cout << "Initialisation socket..." << endl;
|
||||
hostInfo = gethostbyname(remote_ip.c_str());
|
||||
serverPort = PORT;
|
||||
hostInfo = gethostbyname(remote_host.c_str());
|
||||
socketDescriptor = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
serverAddress.sin_family = hostInfo->h_addrtype;
|
||||
memcpy((char *) &serverAddress.sin_addr.s_addr,
|
||||
hostInfo->h_addr_list[0], hostInfo->h_length);
|
||||
serverAddress.sin_port = htons(serverPort);
|
||||
serverAddress.sin_port = htons(remote_port);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -4,14 +4,15 @@
|
|||
#include "outputmedium.hh"
|
||||
|
||||
#include <string>
|
||||
#include <stdint.h> // <cstdint> is not C++ 98 compliant
|
||||
|
||||
/// Sends results to an UDP socket
|
||||
class OutputUDPSocket: public OutputMedium
|
||||
{
|
||||
private:
|
||||
int socketDescriptor ;
|
||||
std::string remote_ip ;
|
||||
unsigned short int serverPort ;
|
||||
std::string remote_host ;
|
||||
uint_fast16_t remote_port ;
|
||||
|
||||
/** @name Operations */
|
||||
//@{
|
||||
|
@ -22,7 +23,8 @@ private:
|
|||
//@}
|
||||
|
||||
public:
|
||||
OutputUDPSocket(const std::string &_remote_ip) ;
|
||||
OutputUDPSocket(const std::string &_remote_ip,
|
||||
const uint_fast16_t _port) ;
|
||||
~OutputUDPSocket(void) ;
|
||||
|
||||
/** @name Operations */
|
||||
|
|
|
@ -14,6 +14,7 @@ namespace po = boost::program_options ;
|
|||
|
||||
#define DEFAULT_CONFIG_FILE_NAME "cfg/owlps-positioning.cfg"
|
||||
#define DEFAULT_LISTENING_PORT 9902
|
||||
#define DEFAULT_OUTPUT_PORT 9910
|
||||
|
||||
|
||||
|
||||
|
@ -195,10 +196,15 @@ void UserInterface::fill_output_options()
|
|||
options.add_options()
|
||||
("output.medium,O", po::value< vector<string> >()->composing(),
|
||||
"Medium to which the results will be wrote. You can specify \
|
||||
this option more than once. Allowed: Terminal, CSV. \
|
||||
this option more than once. Allowed: Terminal, CSV, UDP. \
|
||||
If this option is absent, results will be printed on the terminal.")
|
||||
("output.csv-file", po::value<string>(),
|
||||
"CSV file to use for output (when output.medium = CSV).")
|
||||
("output.udp-host", po::value<int>(),
|
||||
"Host to which the UDP data is sent (when output.medium = UDP).")
|
||||
("output.udp-port", po::value<int>()
|
||||
->default_value(DEFAULT_OUTPUT_PORT),
|
||||
"Port on which the UDP data is sent (when output.medium = UDP).")
|
||||
;
|
||||
|
||||
file_options->add(options) ;
|
||||
|
|
Loading…
Reference in New Issue