[Positioning] OutputSocket: review & clean
This commit is contained in:
parent
756b850375
commit
a2c0556ee8
|
@ -1,16 +1,8 @@
|
|||
#include "outputsocket.hh"
|
||||
#include "request.hh"
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <netdb.h>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
|
||||
//#include "mobile.hh"
|
||||
//#include <netinet/in.h>
|
||||
//#include <cstdlib>
|
||||
//#include <unistd.h>
|
||||
//#include <limits>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
|
|
@ -1,36 +1,37 @@
|
|||
#ifndef _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
|
||||
{
|
||||
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_
|
||||
|
||||
|
|
Loading…
Reference in New Issue