From 562ea6c28b25973275c6ade0c9089471b6b3dcc5 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Tue, 5 Apr 2011 11:22:28 +0200 Subject: [PATCH] [Positioning] Add options output.udp-{host,port} --- owlps-positioning/src/output.cc | 8 ++++---- owlps-positioning/src/outputudpsocket.cc | 12 +++++------- owlps-positioning/src/outputudpsocket.hh | 8 +++++--- owlps-positioning/src/userinterface.cc | 8 +++++++- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/owlps-positioning/src/output.cc b/owlps-positioning/src/output.cc index 2c6baea..6b14696 100644 --- a/owlps-positioning/src/output.cc +++ b/owlps-positioning/src/output.cc @@ -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"))) ; } diff --git a/owlps-positioning/src/outputudpsocket.cc b/owlps-positioning/src/outputudpsocket.cc index 0a59274..48a464e 100644 --- a/owlps-positioning/src/outputudpsocket.cc +++ b/owlps-positioning/src/outputudpsocket.cc @@ -4,8 +4,6 @@ #include #include -#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); } diff --git a/owlps-positioning/src/outputudpsocket.hh b/owlps-positioning/src/outputudpsocket.hh index 852a3ba..803f2d5 100644 --- a/owlps-positioning/src/outputudpsocket.hh +++ b/owlps-positioning/src/outputudpsocket.hh @@ -4,14 +4,15 @@ #include "outputmedium.hh" #include +#include // 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 */ diff --git a/owlps-positioning/src/userinterface.cc b/owlps-positioning/src/userinterface.cc index 3e473c5..e3d1cb8 100644 --- a/owlps-positioning/src/userinterface.cc +++ b/owlps-positioning/src/userinterface.cc @@ -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 >()->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(), "CSV file to use for output (when output.medium = CSV).") + ("output.udp-host", po::value(), + "Host to which the UDP data is sent (when output.medium = UDP).") + ("output.udp-port", po::value() + ->default_value(DEFAULT_OUTPUT_PORT), + "Port on which the UDP data is sent (when output.medium = UDP).") ; file_options->add(options) ;