[Positioning] Add options output.udp-{host,port}

This commit is contained in:
Matteo Cypriani 2011-04-05 11:22:28 +02:00
parent 22cad4c214
commit 562ea6c28b
4 changed files with 21 additions and 15 deletions

View File

@ -72,13 +72,13 @@ void Output::initialise_output_terminal()
void Output::initialise_output_udp_socket() void Output::initialise_output_udp_socket()
{ {
if (! Configuration::is_configured("output.remote-ip")) if (! Configuration::is_configured("output.udp-host"))
throw missing_configuration( throw missing_configuration(
"No remote ip specified in the configuration!") ; "No remote UDP host specified in the configuration!") ;
output_media.push_back( output_media.push_back(
new OutputUDPSocket( new OutputUDPSocket(Configuration::string_value("output.udp-host"),
Configuration::string_value("output.remote-ip"))) ; Configuration::int_value("output.udp-port"))) ;
} }

View File

@ -4,8 +4,6 @@
#include <sstream> #include <sstream>
#include <iostream> #include <iostream>
#define PORT 9910
using namespace std ; using namespace std ;
struct hostent *hostInfo ; struct hostent *hostInfo ;
@ -16,8 +14,9 @@ struct sockaddr_in serverAddress ;
/* *** Constructors *** */ /* *** Constructors *** */
OutputUDPSocket::OutputUDPSocket(const string &_remote_ip): OutputUDPSocket::OutputUDPSocket(const string &_remote_host,
remote_ip(_remote_ip) const uint_fast16_t _remote_port):
remote_host(_remote_host), remote_port(_remote_port)
{ {
init_socket() ; init_socket() ;
} }
@ -56,13 +55,12 @@ void OutputUDPSocket::write(const Result &result)
void OutputUDPSocket::init_socket() void OutputUDPSocket::init_socket()
{ {
cout << "Initialisation socket..." << endl; cout << "Initialisation socket..." << endl;
hostInfo = gethostbyname(remote_ip.c_str()); hostInfo = gethostbyname(remote_host.c_str());
serverPort = PORT;
socketDescriptor = socket(AF_INET, SOCK_DGRAM, 0); socketDescriptor = socket(AF_INET, SOCK_DGRAM, 0);
serverAddress.sin_family = hostInfo->h_addrtype; serverAddress.sin_family = hostInfo->h_addrtype;
memcpy((char *) &serverAddress.sin_addr.s_addr, memcpy((char *) &serverAddress.sin_addr.s_addr,
hostInfo->h_addr_list[0], hostInfo->h_length); hostInfo->h_addr_list[0], hostInfo->h_length);
serverAddress.sin_port = htons(serverPort); serverAddress.sin_port = htons(remote_port);
} }

View File

@ -4,14 +4,15 @@
#include "outputmedium.hh" #include "outputmedium.hh"
#include <string> #include <string>
#include <stdint.h> // <cstdint> is not C++ 98 compliant
/// Sends results to an UDP socket /// Sends results to an UDP socket
class OutputUDPSocket: public OutputMedium class OutputUDPSocket: public OutputMedium
{ {
private: private:
int socketDescriptor ; int socketDescriptor ;
std::string remote_ip ; std::string remote_host ;
unsigned short int serverPort ; uint_fast16_t remote_port ;
/** @name Operations */ /** @name Operations */
//@{ //@{
@ -22,7 +23,8 @@ private:
//@} //@}
public: public:
OutputUDPSocket(const std::string &_remote_ip) ; OutputUDPSocket(const std::string &_remote_ip,
const uint_fast16_t _port) ;
~OutputUDPSocket(void) ; ~OutputUDPSocket(void) ;
/** @name Operations */ /** @name Operations */

View File

@ -14,6 +14,7 @@ namespace po = boost::program_options ;
#define DEFAULT_CONFIG_FILE_NAME "cfg/owlps-positioning.cfg" #define DEFAULT_CONFIG_FILE_NAME "cfg/owlps-positioning.cfg"
#define DEFAULT_LISTENING_PORT 9902 #define DEFAULT_LISTENING_PORT 9902
#define DEFAULT_OUTPUT_PORT 9910
@ -195,10 +196,15 @@ void UserInterface::fill_output_options()
options.add_options() options.add_options()
("output.medium,O", po::value< vector<string> >()->composing(), ("output.medium,O", po::value< vector<string> >()->composing(),
"Medium to which the results will be wrote. You can specify \ "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.") If this option is absent, results will be printed on the terminal.")
("output.csv-file", po::value<string>(), ("output.csv-file", po::value<string>(),
"CSV file to use for output (when output.medium = CSV).") "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) ; file_options->add(options) ;