[Positioning] OutputSocket: review & clean
This commit is contained in:
parent
756b850375
commit
a2c0556ee8
|
@ -1,16 +1,8 @@
|
||||||
#include "outputsocket.hh"
|
#include "outputsocket.hh"
|
||||||
#include "request.hh"
|
#include "request.hh"
|
||||||
#include <sstream>
|
|
||||||
#include <string>
|
|
||||||
#include <netdb.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
//#include "mobile.hh"
|
#include <sstream>
|
||||||
//#include <netinet/in.h>
|
#include <iostream>
|
||||||
//#include <cstdlib>
|
|
||||||
//#include <unistd.h>
|
|
||||||
//#include <limits>
|
|
||||||
|
|
||||||
#define PORT 9910
|
#define PORT 9910
|
||||||
|
|
||||||
|
@ -20,18 +12,27 @@ struct hostent *hostInfo ;
|
||||||
struct sockaddr_in serverAddress ;
|
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()
|
OutputSocket::~OutputSocket()
|
||||||
{
|
{
|
||||||
kill_socket();
|
kill_socket() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* *** Operations *** */
|
||||||
|
|
||||||
|
|
||||||
void OutputSocket::write(const Result &result)
|
void OutputSocket::write(const Result &result)
|
||||||
{
|
{
|
||||||
string timestampXYZ;
|
string timestampXYZ;
|
||||||
|
@ -40,26 +41,31 @@ void OutputSocket::write(const Result &result)
|
||||||
|
|
||||||
Point3D position = result.get_position() ;
|
Point3D position = result.get_position() ;
|
||||||
|
|
||||||
os << request->get_time_sent() << ";" << position.get_x() << ";" << position.get_y() << ";" << position.get_z();
|
os
|
||||||
timestampXYZ= os.str();
|
<< 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);
|
send_data(timestampXYZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OutputSocket::init_socket()
|
void OutputSocket::init_socket()
|
||||||
{
|
{
|
||||||
cout << "Initialisation socket..." << endl;
|
cout << "Initialisation socket..." << endl;
|
||||||
hostInfo = gethostbyname(m_ip.c_str());
|
hostInfo = gethostbyname(remote_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;
|
||||||
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(serverPort);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OutputSocket::send_data(string data)
|
void OutputSocket::send_data(string data)
|
||||||
{
|
{
|
||||||
if (sendto(socketDescriptor, data.c_str(), data.size(), 0,
|
if (sendto(socketDescriptor, data.c_str(), data.size(), 0,
|
||||||
|
@ -71,13 +77,9 @@ void OutputSocket::send_data(string data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OutputSocket::kill_socket()
|
void OutputSocket::kill_socket()
|
||||||
{
|
{
|
||||||
cout << "Fermeture de la socket..." << endl;
|
cout << "Fermeture de la socket..." << endl;
|
||||||
close(socketDescriptor);
|
close(socketDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OutputSocket::send_screen()
|
|
||||||
{
|
|
||||||
cout << "Hello world !!" << endl;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,36 +1,37 @@
|
||||||
#ifndef _OWLPS_POSITIONING_OUTPUTSOCKET_HH_
|
#ifndef _OWLPS_POSITIONING_OUTPUTSOCKET_HH_
|
||||||
#define _OWLPS_POSITIONING_OUTPUTSOCKET_HH_
|
#define _OWLPS_POSITIONING_OUTPUTSOCKET_HH_
|
||||||
#include "outputmedium.hh"
|
|
||||||
#include <string>
|
|
||||||
#include <stdint.h> // <cstdint> is not C++ 98 compliant
|
|
||||||
#include <iostream>
|
|
||||||
//#include <netinet/in.h>
|
|
||||||
//#include <unistd.h>
|
|
||||||
|
|
||||||
/// Send a result to socket
|
#include "outputmedium.hh"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
/// Sends results to an UDP socket
|
||||||
class OutputSocket: public OutputMedium
|
class OutputSocket: public OutputMedium
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
int socketDescriptor ;
|
int socketDescriptor ;
|
||||||
std::string m_ip ;
|
std::string remote_ip ;
|
||||||
unsigned short int serverPort ;
|
unsigned short int serverPort ;
|
||||||
|
|
||||||
public:
|
/** @name Operations */
|
||||||
OutputSocket(const std::string &remote_ip): m_ip(remote_ip) { init_socket(); }
|
//@{
|
||||||
~OutputSocket() ;
|
/// Initialises the socket
|
||||||
|
void init_socket(void) ;
|
||||||
void write(const Result &result) ;
|
void kill_socket(void) ;
|
||||||
|
|
||||||
std::string float2string(float f) ;
|
|
||||||
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_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_
|
#endif // _OWLPS_POSITIONING_OUTPUTSOCKET_HH_
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue