Merge branch 'dev-outputsocket' into dev
Adds OutputUDPSocket. OutputUDPSocket::write(ResultList) is a mock function, since important changes have to be done before that. Conflicts: owlps-positioning/src/userinterface.cc
This commit is contained in:
commit
40fb159a91
|
@ -77,6 +77,7 @@ OBJ_LIST = \
|
||||||
output.o \
|
output.o \
|
||||||
outputterminal.o \
|
outputterminal.o \
|
||||||
outputcsv.o \
|
outputcsv.o \
|
||||||
|
outputudpsocket.o \
|
||||||
positioning.o \
|
positioning.o \
|
||||||
input.o \
|
input.o \
|
||||||
inputcsv.o \
|
inputcsv.o \
|
||||||
|
@ -220,8 +221,16 @@ $(OBJ_DIR)/outputcsv.o: \
|
||||||
$(OBJ_DIR)/textfilewriter.o \
|
$(OBJ_DIR)/textfilewriter.o \
|
||||||
$(OBJ_DIR)/resultlist.o \
|
$(OBJ_DIR)/resultlist.o \
|
||||||
$(OBJ_DIR)/result.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)/output.o: \
|
||||||
$(OBJ_DIR)/outputterminal.o \
|
$(OBJ_DIR)/outputterminal.o \
|
||||||
|
$(OBJ_DIR)/outputcsv.o \
|
||||||
|
$(OBJ_DIR)/outputudpsocket.o \
|
||||||
$(OBJ_DIR)/configuration.o \
|
$(OBJ_DIR)/configuration.o \
|
||||||
$(OBJ_DIR)/posexcept.o
|
$(OBJ_DIR)/posexcept.o
|
||||||
$(OBJ_DIR)/multilaterationalgorithm.o: \
|
$(OBJ_DIR)/multilaterationalgorithm.o: \
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "outputterminal.hh"
|
#include "outputterminal.hh"
|
||||||
#include "outputcsv.hh"
|
#include "outputcsv.hh"
|
||||||
|
#include "outputudpsocket.hh"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
@ -53,6 +54,9 @@ void Output::initialise_output_media()
|
||||||
else if (*i == "CSV")
|
else if (*i == "CSV")
|
||||||
initialise_output_csv() ;
|
initialise_output_csv() ;
|
||||||
|
|
||||||
|
else if (*i == "UDP")
|
||||||
|
initialise_output_udp_socket() ;
|
||||||
|
|
||||||
else
|
else
|
||||||
throw bad_configuration(
|
throw bad_configuration(
|
||||||
"The specified output medium « "+ *i +" » is unknown!") ;
|
"The specified output medium « "+ *i +" » is unknown!") ;
|
||||||
|
@ -66,6 +70,18 @@ void Output::initialise_output_terminal()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Output::initialise_output_udp_socket()
|
||||||
|
{
|
||||||
|
if (! Configuration::is_configured("output.udp-host"))
|
||||||
|
throw missing_configuration(
|
||||||
|
"No remote UDP host specified in the configuration!") ;
|
||||||
|
|
||||||
|
output_media.push_back(
|
||||||
|
new OutputUDPSocket(Configuration::string_value("output.udp-host"),
|
||||||
|
Configuration::int_value("output.udp-port"))) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Output::initialise_output_csv()
|
void Output::initialise_output_csv()
|
||||||
{
|
{
|
||||||
if (! Configuration::is_configured("output.csv-file"))
|
if (! Configuration::is_configured("output.csv-file"))
|
||||||
|
|
|
@ -18,6 +18,7 @@ protected:
|
||||||
void initialise_output_media(void) ;
|
void initialise_output_media(void) ;
|
||||||
void initialise_output_terminal(void) ;
|
void initialise_output_terminal(void) ;
|
||||||
void initialise_output_csv(void) ;
|
void initialise_output_csv(void) ;
|
||||||
|
void initialise_output_udp_socket(void) ;
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -0,0 +1,91 @@
|
||||||
|
#include "outputudpsocket.hh"
|
||||||
|
#include "request.hh"
|
||||||
|
#include "resultlist.hh"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
using namespace std ;
|
||||||
|
|
||||||
|
struct hostent *hostInfo ;
|
||||||
|
struct sockaddr_in serverAddress ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* *** Constructors *** */
|
||||||
|
|
||||||
|
|
||||||
|
OutputUDPSocket::OutputUDPSocket(const string &_remote_host,
|
||||||
|
const uint_fast16_t _remote_port):
|
||||||
|
remote_host(_remote_host), remote_port(_remote_port)
|
||||||
|
{
|
||||||
|
init_socket() ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
OutputUDPSocket::~OutputUDPSocket()
|
||||||
|
{
|
||||||
|
kill_socket() ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* *** Operations *** */
|
||||||
|
|
||||||
|
|
||||||
|
void OutputUDPSocket::write(const ResultList &results)
|
||||||
|
{
|
||||||
|
// Not implemented
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void OutputUDPSocket::write(const Result &result)
|
||||||
|
{
|
||||||
|
string timestampXYZ;
|
||||||
|
ostringstream os;
|
||||||
|
|
||||||
|
Point3D position = result.get_position() ;
|
||||||
|
|
||||||
|
os
|
||||||
|
<< position.get_x() << ';'
|
||||||
|
<< position.get_y() << ';'
|
||||||
|
<< position.get_z() ;
|
||||||
|
timestampXYZ = os.str() ;
|
||||||
|
|
||||||
|
cout << timestampXYZ << '\n' ;
|
||||||
|
send_data(timestampXYZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void OutputUDPSocket::init_socket()
|
||||||
|
{
|
||||||
|
cout << "Initialisation socket..." << endl;
|
||||||
|
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(remote_port);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void OutputUDPSocket::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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void OutputUDPSocket::kill_socket()
|
||||||
|
{
|
||||||
|
cout << "Fermeture de la socket..." << endl;
|
||||||
|
close(socketDescriptor);
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
#ifndef _OWLPS_POSITIONING_OUTPUTUDPSOCKET_HH_
|
||||||
|
#define _OWLPS_POSITIONING_OUTPUTUDPSOCKET_HH_
|
||||||
|
|
||||||
|
#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_host ;
|
||||||
|
uint_fast16_t remote_port ;
|
||||||
|
|
||||||
|
/** @name Operations */
|
||||||
|
//@{
|
||||||
|
/// Initialises the socket
|
||||||
|
void init_socket(void) ;
|
||||||
|
void kill_socket(void) ;
|
||||||
|
void send_data(std::string msg) ;
|
||||||
|
//@}
|
||||||
|
|
||||||
|
public:
|
||||||
|
OutputUDPSocket(const std::string &_remote_ip,
|
||||||
|
const uint_fast16_t _port) ;
|
||||||
|
~OutputUDPSocket(void) ;
|
||||||
|
|
||||||
|
/** @name Operations */
|
||||||
|
//@{
|
||||||
|
/// Initialises the socket
|
||||||
|
void write(const Result &result) ;
|
||||||
|
void write(const ResultList &results) ;
|
||||||
|
//@}
|
||||||
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // _OWLPS_POSITIONING_OUTPUTUDPSOCKET_HH_
|
|
@ -183,10 +183,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(MOBILE_DEFAULT_PORT),
|
||||||
|
"Port on which the UDP data is sent (when output.medium = UDP).")
|
||||||
;
|
;
|
||||||
|
|
||||||
file_options->add(options) ;
|
file_options->add(options) ;
|
||||||
|
|
Loading…
Reference in New Issue