[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:
Florian Taillard 2011-04-01 16:24:25 +02:00 committed by Matteo Cypriani
parent 6fbb0874e7
commit 756b850375
3 changed files with 41 additions and 35 deletions

View File

@ -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()

View File

@ -12,8 +12,8 @@
//#include <unistd.h>
//#include <limits>
#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;
}

View File

@ -3,7 +3,7 @@
#include "outputmedium.hh"
#include <string>
#include <stdint.h> // <cstdint> is not C++ 98 compliant
#include <iostream>
//#include <netinet/in.h>
//#include <unistd.h>
@ -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() ;
} ;