[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).
This commit is contained in:
parent
6fbb0874e7
commit
756b850375
|
@ -71,7 +71,13 @@ void Output::initialise_output_terminal()
|
||||||
|
|
||||||
void Output::initialise_output_socket()
|
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()
|
void Output::initialise_output_csv()
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
//#include <unistd.h>
|
//#include <unistd.h>
|
||||||
//#include <limits>
|
//#include <limits>
|
||||||
|
|
||||||
#define IP_R "127.0.0.1"
|
#define PORT 9910
|
||||||
#define PORT 1600
|
|
||||||
using namespace std ;
|
using namespace std ;
|
||||||
|
|
||||||
struct hostent *hostInfo ;
|
struct hostent *hostInfo ;
|
||||||
|
@ -22,49 +22,35 @@ struct sockaddr_in serverAddress ;
|
||||||
|
|
||||||
/* *** Operations *** */
|
/* *** Operations *** */
|
||||||
|
|
||||||
|
/*OutputSocket::OutputSocket(const string m_ip)
|
||||||
|
{
|
||||||
|
init_socket();
|
||||||
|
}*/
|
||||||
|
|
||||||
|
OutputSocket::~OutputSocket()
|
||||||
|
{
|
||||||
|
kill_socket();
|
||||||
|
}
|
||||||
|
|
||||||
void OutputSocket::write(const Result &result)
|
void OutputSocket::write(const Result &result)
|
||||||
{
|
{
|
||||||
string timestampXYZ;
|
string timestampXYZ;
|
||||||
|
ostringstream os;
|
||||||
const Request *const request = result.get_request() ;
|
const Request *const request = result.get_request() ;
|
||||||
|
|
||||||
Point3D position = result.get_position() ;
|
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);
|
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()
|
void OutputSocket::init_socket()
|
||||||
{
|
{
|
||||||
hostInfo = gethostbyname(IP_R);
|
cout << "Initialisation socket..." << endl;
|
||||||
|
hostInfo = gethostbyname(m_ip.c_str());
|
||||||
serverPort = PORT;
|
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;
|
||||||
|
@ -82,6 +68,16 @@ void OutputSocket::send_data(string data)
|
||||||
{
|
{
|
||||||
cerr << "Émission du message impossible\n";
|
cerr << "Émission du message impossible\n";
|
||||||
close(socketDescriptor);
|
close(socketDescriptor);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OutputSocket::kill_socket()
|
||||||
|
{
|
||||||
|
cout << "Fermeture de la socket..." << endl;
|
||||||
|
close(socketDescriptor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OutputSocket::send_screen()
|
||||||
|
{
|
||||||
|
cout << "Hello world !!" << endl;
|
||||||
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include "outputmedium.hh"
|
#include "outputmedium.hh"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <stdint.h> // <cstdint> is not C++ 98 compliant
|
#include <stdint.h> // <cstdint> is not C++ 98 compliant
|
||||||
|
#include <iostream>
|
||||||
//#include <netinet/in.h>
|
//#include <netinet/in.h>
|
||||||
//#include <unistd.h>
|
//#include <unistd.h>
|
||||||
|
|
||||||
|
@ -12,10 +12,12 @@ class OutputSocket: public OutputMedium
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
int socketDescriptor ;
|
int socketDescriptor ;
|
||||||
|
std::string m_ip ;
|
||||||
unsigned short int serverPort ;
|
unsigned short int serverPort ;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OutputSocket() {}
|
OutputSocket(const std::string &remote_ip): m_ip(remote_ip) { init_socket(); }
|
||||||
|
~OutputSocket() ;
|
||||||
|
|
||||||
void write(const Result &result) ;
|
void write(const Result &result) ;
|
||||||
|
|
||||||
|
@ -23,7 +25,9 @@ public:
|
||||||
std::string uint2string(uint64_t f) ;
|
std::string uint2string(uint64_t f) ;
|
||||||
std::string int2string(int f) ;
|
std::string int2string(int f) ;
|
||||||
void init_socket() ;
|
void init_socket() ;
|
||||||
|
void kill_socket() ;
|
||||||
void send_data(std::string msg) ;
|
void send_data(std::string msg) ;
|
||||||
|
void send_screen() ;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue