source: pacpussensors/trunk/Gps/SeptentrioSocket.cpp@ 63

Last change on this file since 63 was 59, checked in by DHERBOMEZ Gérald, 10 years ago

Integration of new modules:

  • GPS NMEA0183 decoder
  • Span CPT Decoder

Update of:

File size: 3.9 KB
Line 
1/*********************************************************************
2// created: 2008/07/18 - 15:33
3// filename: SeptentrioSocket.cpp
4//
5// author: Gerald Dherbomez
6// Copyright Heudiasyc UMR UTC/CNRS 6599
7//
8// version: $Id: $
9//
10// purpose: Management of the TCP/IP connection with the Septentrio
11// receiver.
12*********************************************************************/
13
14
15
16#include "SeptentrioSocket.h"
17#include "SeptentrioComponent.h"
18#include <QApplication>
19#include <QtDebug>
20
21
22
23//////////////////////////////////////////////////////////////////////////
24// Constructor
25//////////////////////////////////////////////////////////////////////////
26SeptentrioSocket::SeptentrioSocket() : sem(MAX_RESOURCES_COUNT)
27{
28 sem.acquire(MAX_RESOURCES_COUNT);
29 socket_ = new QTcpSocket(this);
30 connect( socket_, SIGNAL(connected()), this,SLOT(socketConnected()) );
31 connect( socket_, SIGNAL(disconnected()),this, SLOT(socketConnectionClosed()) );
32 connect( socket_, SIGNAL(readyRead()),this, SLOT(socketReadyRead()) );
33 connect( socket_, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError(QAbstractSocket::SocketError)) );
34}
35
36
37
38//////////////////////////////////////////////////////////////////////////
39// Destructor
40//////////////////////////////////////////////////////////////////////////
41SeptentrioSocket::~SeptentrioSocket()
42{
43 delete socket_;
44}
45
46
47
48
49//////////////////////////////////////////////////////////////////////////
50// public slot
51// connection to server
52//////////////////////////////////////////////////////////////////////////
53void SeptentrioSocket::connectToServer(QString host, int port)
54{
55 qDebug("trying to connect to server");
56 socket_->connectToHost(host,port);
57}
58
59
60
61
62//////////////////////////////////////////////////////////////////////////
63// protected slot
64//////////////////////////////////////////////////////////////////////////
65int SeptentrioSocket::socketConnected()
66{
67 qDebug() << "we are connected to the server " << socket_->peerName().toLatin1()
68 << " at the port " << socket_->peerPort() << " via the socket " << socket_->socketDescriptor();
69
70 // request data as soon as we are connected
71// sendToServer("sso curr all\n");
72
73 return 1;
74}
75
76
77
78
79
80//////////////////////////////////////////////////////////////////////////
81// protected slot
82//////////////////////////////////////////////////////////////////////////
83void SeptentrioSocket::socketConnectionClosed()
84{
85 qDebug("the connection was closed");
86}
87
88
89
90
91//////////////////////////////////////////////////////////////////////////
92// protected slot
93// new incoming data to read
94//////////////////////////////////////////////////////////////////////////
95void SeptentrioSocket::socketReadyRead()
96{
97 SbfFrame frame;
98 frame.time = road_time();
99 if ( socket_->bytesAvailable() <= SBFBLOCK_MAX_LENGTH)
100 {
101 frame.size = socket_->bytesAvailable();
102// printf("received = %d\n",frame.size);
103 }
104 else
105 {
106 qDebug() << "Problem with SeptentrioSocket: size of data exceeds maximal capacity of "<< SBFBLOCK_MAX_LENGTH << " bytes. \nData will be ignored !";
107 socket_->readAll();
108 }
109 frame.size = socket_->read( (char*)&(frame.data), frame.size );
110 sbfFrames.push(frame);
111 sem.release();
112}
113
114
115//////////////////////////////////////////////////////////////////////////
116// protected slot
117//////////////////////////////////////////////////////////////////////////
118void SeptentrioSocket::socketError( QAbstractSocket::SocketError e )
119{
120 qWarning("socket error number %d",e);
121}
122
123
124
125//////////////////////////////////////////////////////////////////////////
126// Send data to server via a text stream
127//////////////////////////////////////////////////////////////////////////
128void SeptentrioSocket::sendToServer(QString data)
129{
130 mutex_.lock();
131 QTextStream os(socket_);
132 os << data << endl;
133 mutex_.unlock();
134 qDebug() << "data sent to server: " << data.toLatin1();
135}
Note: See TracBrowser for help on using the repository browser.