From 6fbb0874e76749947c9898b71f8d63da9ab779f8 Mon Sep 17 00:00:00 2001 From: Florian Taillard Date: Tue, 15 Mar 2011 15:27:42 +0100 Subject: [PATCH 1/5] [Positioning] Add OutputSocket --- owlps-positioning/Makefile | 4 ++ owlps-positioning/src/output.cc | 8 +++ owlps-positioning/src/output.hh | 1 + owlps-positioning/src/outputsocket.cc | 87 +++++++++++++++++++++++++++ owlps-positioning/src/outputsocket.hh | 32 ++++++++++ 5 files changed, 132 insertions(+) create mode 100644 owlps-positioning/src/outputsocket.cc create mode 100644 owlps-positioning/src/outputsocket.hh diff --git a/owlps-positioning/Makefile b/owlps-positioning/Makefile index a515ffe..34b3247 100644 --- a/owlps-positioning/Makefile +++ b/owlps-positioning/Makefile @@ -76,6 +76,7 @@ OBJ_LIST = \ output.o \ outputterminal.o \ outputcsv.o \ + outputsocket.o \ positioning.o \ input.o \ inputcsv.o \ @@ -213,6 +214,9 @@ $(OBJ_DIR)/outputcsv.o: \ $(SRC_DIR)/outputmedium.hh \ $(OBJ_DIR)/textfilewriter.o \ $(OBJ_DIR)/result.o +$(OBJ_DIR)/outputcsv.o: \ + $(SRC_DIR)/outputmedium.hh \ + $(OBJ_DIR)/result.o $(OBJ_DIR)/output.o: \ $(OBJ_DIR)/outputterminal.o \ $(OBJ_DIR)/configuration.o \ diff --git a/owlps-positioning/src/output.cc b/owlps-positioning/src/output.cc index ab1743c..d34b62f 100644 --- a/owlps-positioning/src/output.cc +++ b/owlps-positioning/src/output.cc @@ -4,6 +4,7 @@ #include "outputterminal.hh" #include "outputcsv.hh" +#include "outputsocket.hh" #include @@ -53,6 +54,9 @@ void Output::initialise_output_media() else if (*i == "CSV") initialise_output_csv() ; + else if (*i == "Socket") + initialise_output_socket() ; + else throw bad_configuration( "The specified output medium « "+ *i +" » is unknown!") ; @@ -65,6 +69,10 @@ void Output::initialise_output_terminal() output_media.push_back(new OutputTerminal) ; } +void Output::initialise_output_socket() +{ + output_media.push_back(new OutputSocket) ; +} void Output::initialise_output_csv() { diff --git a/owlps-positioning/src/output.hh b/owlps-positioning/src/output.hh index fbfa7fe..5987d6b 100644 --- a/owlps-positioning/src/output.hh +++ b/owlps-positioning/src/output.hh @@ -18,6 +18,7 @@ protected: void initialise_output_media(void) ; void initialise_output_terminal(void) ; void initialise_output_csv(void) ; + void initialise_output_socket(void) ; //@} public: diff --git a/owlps-positioning/src/outputsocket.cc b/owlps-positioning/src/outputsocket.cc new file mode 100644 index 0000000..1133810 --- /dev/null +++ b/owlps-positioning/src/outputsocket.cc @@ -0,0 +1,87 @@ +#include "outputsocket.hh" +#include "request.hh" +#include +#include +#include +#include +#include + +//#include "mobile.hh" +//#include +//#include +//#include +//#include + +#define IP_R "127.0.0.1" +#define PORT 1600 +using namespace std ; + +struct hostent *hostInfo ; +struct sockaddr_in serverAddress ; + + +/* *** Operations *** */ + + +void OutputSocket::write(const Result &result) +{ + string timestampXYZ; + const Request *const request = result.get_request() ; + + Point3D position = result.get_position() ; + + timestampXYZ= uint2string(request->get_time_sent()) + ";" + float2string(position.get_x()) + ";" + float2string(position.get_y()) + ";" + float2string(position.get_z()); + + init_socket(); +//cout << timestampXYZ << endl; + send_data(timestampXYZ); +} + + +string OutputSocket::float2string(float f) +{ + ostringstream os; + os << f; + return os.str(); + +} + +string OutputSocket::uint2string(uint64_t f) +{ + ostringstream os; + os << f; + return os.str(); + +} + +string OutputSocket::int2string(int f) +{ + ostringstream os; + os << f; + return os.str(); + +} + +void OutputSocket::init_socket() +{ + hostInfo = gethostbyname(IP_R); + serverPort = PORT; + 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); + +} + +void OutputSocket::send_data(string data) +{ + if (sendto(socketDescriptor, data.c_str(), data.size(), 0, + (struct sockaddr *) &serverAddress, + sizeof(serverAddress)) < 0) + { + cerr << "Émission du message impossible\n"; + close(socketDescriptor); + exit(1); + } +} diff --git a/owlps-positioning/src/outputsocket.hh b/owlps-positioning/src/outputsocket.hh new file mode 100644 index 0000000..e5b62c0 --- /dev/null +++ b/owlps-positioning/src/outputsocket.hh @@ -0,0 +1,32 @@ +#ifndef _OWLPS_POSITIONING_OUTPUTSOCKET_HH_ +#define _OWLPS_POSITIONING_OUTPUTSOCKET_HH_ +#include "outputmedium.hh" +#include +#include // is not C++ 98 compliant + +//#include +//#include + +/// Send a result to socket +class OutputSocket: public OutputMedium +{ +private: + int socketDescriptor ; + unsigned short int serverPort ; + +public: + OutputSocket() {} + + void write(const Result &result) ; + + std::string float2string(float f) ; + std::string uint2string(uint64_t f) ; + std::string int2string(int f) ; + void init_socket() ; + void send_data(std::string msg) ; +} ; + + + +#endif // _OWLPS_POSITIONING_OUTPUTSOCKET_HH_ + From 756b850375c523c24ebb11b6dcca041069a2ca09 Mon Sep 17 00:00:00 2001 From: Florian Taillard Date: Fri, 1 Apr 2011 16:24:25 +0200 Subject: [PATCH 2/5] [Positioning] Modified output socket UDP The ip of destination is now configured in cfg/owlps-positioning.cfg and activate by argument -O Socket. Update owlps-positioning.cfg (Add remote-ip). --- owlps-positioning/src/output.cc | 8 +++- owlps-positioning/src/outputsocket.cc | 60 +++++++++++++-------------- owlps-positioning/src/outputsocket.hh | 8 +++- 3 files changed, 41 insertions(+), 35 deletions(-) diff --git a/owlps-positioning/src/output.cc b/owlps-positioning/src/output.cc index d34b62f..3289d7e 100644 --- a/owlps-positioning/src/output.cc +++ b/owlps-positioning/src/output.cc @@ -71,7 +71,13 @@ void Output::initialise_output_terminal() void Output::initialise_output_socket() { - output_media.push_back(new OutputSocket) ; + if (! Configuration::is_configured("output.remote-ip")) + throw missing_configuration( + "No remote ip specified in the configuration!") ; + + output_media.push_back( + new OutputSocket( + Configuration::string_value("output.remote-ip"))) ; } void Output::initialise_output_csv() diff --git a/owlps-positioning/src/outputsocket.cc b/owlps-positioning/src/outputsocket.cc index 1133810..e2d5725 100644 --- a/owlps-positioning/src/outputsocket.cc +++ b/owlps-positioning/src/outputsocket.cc @@ -12,8 +12,8 @@ //#include //#include -#define IP_R "127.0.0.1" -#define PORT 1600 +#define PORT 9910 + using namespace std ; struct hostent *hostInfo ; @@ -22,49 +22,35 @@ struct sockaddr_in serverAddress ; /* *** Operations *** */ +/*OutputSocket::OutputSocket(const string m_ip) +{ +init_socket(); +}*/ + +OutputSocket::~OutputSocket() +{ +kill_socket(); +} void OutputSocket::write(const Result &result) { string timestampXYZ; + ostringstream os; const Request *const request = result.get_request() ; Point3D position = result.get_position() ; - timestampXYZ= uint2string(request->get_time_sent()) + ";" + float2string(position.get_x()) + ";" + float2string(position.get_y()) + ";" + float2string(position.get_z()); + os << request->get_time_sent() << ";" << position.get_x() << ";" << position.get_y() << ";" << position.get_z(); + timestampXYZ= os.str(); - init_socket(); -//cout << timestampXYZ << endl; + cout << timestampXYZ << endl; send_data(timestampXYZ); } - -string OutputSocket::float2string(float f) -{ - ostringstream os; - os << f; - return os.str(); - -} - -string OutputSocket::uint2string(uint64_t f) -{ - ostringstream os; - os << f; - return os.str(); - -} - -string OutputSocket::int2string(int f) -{ - ostringstream os; - os << f; - return os.str(); - -} - void OutputSocket::init_socket() { - hostInfo = gethostbyname(IP_R); + cout << "Initialisation socket..." << endl; + hostInfo = gethostbyname(m_ip.c_str()); serverPort = PORT; socketDescriptor = socket(AF_INET, SOCK_DGRAM, 0); serverAddress.sin_family = hostInfo->h_addrtype; @@ -82,6 +68,16 @@ void OutputSocket::send_data(string data) { cerr << "Émission du message impossible\n"; close(socketDescriptor); - exit(1); } } + +void OutputSocket::kill_socket() +{ + cout << "Fermeture de la socket..." << endl; + close(socketDescriptor); +} + +void OutputSocket::send_screen() +{ + cout << "Hello world !!" << endl; +} diff --git a/owlps-positioning/src/outputsocket.hh b/owlps-positioning/src/outputsocket.hh index e5b62c0..c1d52e9 100644 --- a/owlps-positioning/src/outputsocket.hh +++ b/owlps-positioning/src/outputsocket.hh @@ -3,7 +3,7 @@ #include "outputmedium.hh" #include #include // is not C++ 98 compliant - +#include //#include //#include @@ -12,10 +12,12 @@ class OutputSocket: public OutputMedium { private: int socketDescriptor ; + std::string m_ip ; unsigned short int serverPort ; public: - OutputSocket() {} + OutputSocket(const std::string &remote_ip): m_ip(remote_ip) { init_socket(); } + ~OutputSocket() ; void write(const Result &result) ; @@ -23,7 +25,9 @@ public: std::string uint2string(uint64_t f) ; std::string int2string(int f) ; void init_socket() ; + void kill_socket() ; void send_data(std::string msg) ; + void send_screen() ; } ; From a2c0556ee8c11aa9ac611fb0282b89787641a21f Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Mon, 4 Apr 2011 16:45:00 +0200 Subject: [PATCH 3/5] [Positioning] OutputSocket: review & clean --- owlps-positioning/src/outputsocket.cc | 52 ++++++++++++++------------- owlps-positioning/src/outputsocket.hh | 43 +++++++++++----------- 2 files changed, 49 insertions(+), 46 deletions(-) diff --git a/owlps-positioning/src/outputsocket.cc b/owlps-positioning/src/outputsocket.cc index e2d5725..eca6762 100644 --- a/owlps-positioning/src/outputsocket.cc +++ b/owlps-positioning/src/outputsocket.cc @@ -1,16 +1,8 @@ #include "outputsocket.hh" #include "request.hh" -#include -#include -#include -#include -#include -//#include "mobile.hh" -//#include -//#include -//#include -//#include +#include +#include #define PORT 9910 @@ -20,18 +12,27 @@ struct hostent *hostInfo ; struct sockaddr_in serverAddress ; -/* *** Operations *** */ -/*OutputSocket::OutputSocket(const string m_ip) +/* *** Constructors *** */ + + +OutputSocket::OutputSocket(const string &_remote_ip): + remote_ip(_remote_ip) { -init_socket(); -}*/ + init_socket() ; +} + OutputSocket::~OutputSocket() { -kill_socket(); + kill_socket() ; } + + +/* *** Operations *** */ + + void OutputSocket::write(const Result &result) { string timestampXYZ; @@ -40,26 +41,31 @@ void OutputSocket::write(const Result &result) Point3D position = result.get_position() ; - os << request->get_time_sent() << ";" << position.get_x() << ";" << position.get_y() << ";" << position.get_z(); - timestampXYZ= os.str(); + os + << request->get_time_sent() << ';' + << position.get_x() << ';' + << position.get_y() << ';' + << position.get_z() ; + timestampXYZ = os.str() ; - cout << timestampXYZ << endl; + cout << timestampXYZ << '\n' ; send_data(timestampXYZ); } + void OutputSocket::init_socket() { cout << "Initialisation socket..." << endl; - hostInfo = gethostbyname(m_ip.c_str()); + hostInfo = gethostbyname(remote_ip.c_str()); serverPort = PORT; 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); - } + void OutputSocket::send_data(string data) { if (sendto(socketDescriptor, data.c_str(), data.size(), 0, @@ -71,13 +77,9 @@ void OutputSocket::send_data(string data) } } + void OutputSocket::kill_socket() { cout << "Fermeture de la socket..." << endl; close(socketDescriptor); } - -void OutputSocket::send_screen() -{ - cout << "Hello world !!" << endl; -} diff --git a/owlps-positioning/src/outputsocket.hh b/owlps-positioning/src/outputsocket.hh index c1d52e9..6a24cec 100644 --- a/owlps-positioning/src/outputsocket.hh +++ b/owlps-positioning/src/outputsocket.hh @@ -1,36 +1,37 @@ #ifndef _OWLPS_POSITIONING_OUTPUTSOCKET_HH_ #define _OWLPS_POSITIONING_OUTPUTSOCKET_HH_ -#include "outputmedium.hh" -#include -#include // is not C++ 98 compliant -#include -//#include -//#include -/// Send a result to socket +#include "outputmedium.hh" + +#include + +/// Sends results to an UDP socket class OutputSocket: public OutputMedium { private: int socketDescriptor ; - std::string m_ip ; + std::string remote_ip ; unsigned short int serverPort ; -public: - OutputSocket(const std::string &remote_ip): m_ip(remote_ip) { init_socket(); } - ~OutputSocket() ; - - void write(const Result &result) ; - - std::string float2string(float f) ; - std::string uint2string(uint64_t f) ; - std::string int2string(int f) ; - void init_socket() ; - void kill_socket() ; + /** @name Operations */ + //@{ + /// Initialises the socket + void init_socket(void) ; + void kill_socket(void) ; void send_data(std::string msg) ; - void send_screen() ; + //@} + +public: + OutputSocket(const std::string &_remote_ip) ; + ~OutputSocket(void) ; + + /** @name Operations */ + //@{ + /// Initialises the socket + void write(const Result &result) ; + //@} } ; #endif // _OWLPS_POSITIONING_OUTPUTSOCKET_HH_ - From 22cad4c2148e6636aff18a3fb413a715e1b05a8f Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Mon, 4 Apr 2011 17:37:19 +0200 Subject: [PATCH 4/5] [Positioning] OutputSocket -> OutputUDPSocket --- owlps-positioning/Makefile | 7 ++++++- owlps-positioning/src/output.cc | 12 +++++++----- owlps-positioning/src/output.hh | 2 +- .../src/{outputsocket.cc => outputudpsocket.cc} | 14 +++++++------- .../src/{outputsocket.hh => outputudpsocket.hh} | 12 ++++++------ 5 files changed, 27 insertions(+), 20 deletions(-) rename owlps-positioning/src/{outputsocket.cc => outputudpsocket.cc} (82%) rename owlps-positioning/src/{outputsocket.hh => outputudpsocket.hh} (63%) diff --git a/owlps-positioning/Makefile b/owlps-positioning/Makefile index 34b3247..684b669 100644 --- a/owlps-positioning/Makefile +++ b/owlps-positioning/Makefile @@ -76,7 +76,7 @@ OBJ_LIST = \ output.o \ outputterminal.o \ outputcsv.o \ - outputsocket.o \ + outputudpsocket.o \ positioning.o \ input.o \ inputcsv.o \ @@ -214,11 +214,16 @@ $(OBJ_DIR)/outputcsv.o: \ $(SRC_DIR)/outputmedium.hh \ $(OBJ_DIR)/textfilewriter.o \ $(OBJ_DIR)/result.o +$(OBJ_DIR)/outputudpsocket.o: \ + $(SRC_DIR)/outputmedium.hh \ + $(OBJ_DIR)/result.o $(OBJ_DIR)/outputcsv.o: \ $(SRC_DIR)/outputmedium.hh \ $(OBJ_DIR)/result.o $(OBJ_DIR)/output.o: \ $(OBJ_DIR)/outputterminal.o \ + $(OBJ_DIR)/outputcsv.o \ + $(OBJ_DIR)/outputudpsocket.o \ $(OBJ_DIR)/configuration.o \ $(OBJ_DIR)/posexcept.o $(OBJ_DIR)/multilaterationalgorithm.o: \ diff --git a/owlps-positioning/src/output.cc b/owlps-positioning/src/output.cc index 3289d7e..2c6baea 100644 --- a/owlps-positioning/src/output.cc +++ b/owlps-positioning/src/output.cc @@ -4,7 +4,7 @@ #include "outputterminal.hh" #include "outputcsv.hh" -#include "outputsocket.hh" +#include "outputudpsocket.hh" #include @@ -54,8 +54,8 @@ void Output::initialise_output_media() else if (*i == "CSV") initialise_output_csv() ; - else if (*i == "Socket") - initialise_output_socket() ; + else if (*i == "UDP") + initialise_output_udp_socket() ; else throw bad_configuration( @@ -69,17 +69,19 @@ void Output::initialise_output_terminal() output_media.push_back(new OutputTerminal) ; } -void Output::initialise_output_socket() + +void Output::initialise_output_udp_socket() { if (! Configuration::is_configured("output.remote-ip")) throw missing_configuration( "No remote ip specified in the configuration!") ; output_media.push_back( - new OutputSocket( + new OutputUDPSocket( Configuration::string_value("output.remote-ip"))) ; } + void Output::initialise_output_csv() { if (! Configuration::is_configured("output.csv-file")) diff --git a/owlps-positioning/src/output.hh b/owlps-positioning/src/output.hh index 5987d6b..32e7c31 100644 --- a/owlps-positioning/src/output.hh +++ b/owlps-positioning/src/output.hh @@ -18,7 +18,7 @@ protected: void initialise_output_media(void) ; void initialise_output_terminal(void) ; void initialise_output_csv(void) ; - void initialise_output_socket(void) ; + void initialise_output_udp_socket(void) ; //@} public: diff --git a/owlps-positioning/src/outputsocket.cc b/owlps-positioning/src/outputudpsocket.cc similarity index 82% rename from owlps-positioning/src/outputsocket.cc rename to owlps-positioning/src/outputudpsocket.cc index eca6762..0a59274 100644 --- a/owlps-positioning/src/outputsocket.cc +++ b/owlps-positioning/src/outputudpsocket.cc @@ -1,4 +1,4 @@ -#include "outputsocket.hh" +#include "outputudpsocket.hh" #include "request.hh" #include @@ -16,14 +16,14 @@ struct sockaddr_in serverAddress ; /* *** Constructors *** */ -OutputSocket::OutputSocket(const string &_remote_ip): +OutputUDPSocket::OutputUDPSocket(const string &_remote_ip): remote_ip(_remote_ip) { init_socket() ; } -OutputSocket::~OutputSocket() +OutputUDPSocket::~OutputUDPSocket() { kill_socket() ; } @@ -33,7 +33,7 @@ OutputSocket::~OutputSocket() /* *** Operations *** */ -void OutputSocket::write(const Result &result) +void OutputUDPSocket::write(const Result &result) { string timestampXYZ; ostringstream os; @@ -53,7 +53,7 @@ void OutputSocket::write(const Result &result) } -void OutputSocket::init_socket() +void OutputUDPSocket::init_socket() { cout << "Initialisation socket..." << endl; hostInfo = gethostbyname(remote_ip.c_str()); @@ -66,7 +66,7 @@ void OutputSocket::init_socket() } -void OutputSocket::send_data(string data) +void OutputUDPSocket::send_data(string data) { if (sendto(socketDescriptor, data.c_str(), data.size(), 0, (struct sockaddr *) &serverAddress, @@ -78,7 +78,7 @@ void OutputSocket::send_data(string data) } -void OutputSocket::kill_socket() +void OutputUDPSocket::kill_socket() { cout << "Fermeture de la socket..." << endl; close(socketDescriptor); diff --git a/owlps-positioning/src/outputsocket.hh b/owlps-positioning/src/outputudpsocket.hh similarity index 63% rename from owlps-positioning/src/outputsocket.hh rename to owlps-positioning/src/outputudpsocket.hh index 6a24cec..852a3ba 100644 --- a/owlps-positioning/src/outputsocket.hh +++ b/owlps-positioning/src/outputudpsocket.hh @@ -1,12 +1,12 @@ -#ifndef _OWLPS_POSITIONING_OUTPUTSOCKET_HH_ -#define _OWLPS_POSITIONING_OUTPUTSOCKET_HH_ +#ifndef _OWLPS_POSITIONING_OUTPUTUDPSOCKET_HH_ +#define _OWLPS_POSITIONING_OUTPUTUDPSOCKET_HH_ #include "outputmedium.hh" #include /// Sends results to an UDP socket -class OutputSocket: public OutputMedium +class OutputUDPSocket: public OutputMedium { private: int socketDescriptor ; @@ -22,8 +22,8 @@ private: //@} public: - OutputSocket(const std::string &_remote_ip) ; - ~OutputSocket(void) ; + OutputUDPSocket(const std::string &_remote_ip) ; + ~OutputUDPSocket(void) ; /** @name Operations */ //@{ @@ -34,4 +34,4 @@ public: -#endif // _OWLPS_POSITIONING_OUTPUTSOCKET_HH_ +#endif // _OWLPS_POSITIONING_OUTPUTUDPSOCKET_HH_ From 562ea6c28b25973275c6ade0c9089471b6b3dcc5 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Tue, 5 Apr 2011 11:22:28 +0200 Subject: [PATCH 5/5] [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) ;