forked from torriem/QtAgOpenGPS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformgps_udpcomm.cpp
49 lines (39 loc) · 1.26 KB
/
formgps_udpcomm.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <QNetworkDatagram>
#include "formgps.h"
#include "aogsettings.h"
#include "cnmea.h"
#define UDP_NMEA_PORT 9999
void FormGPS::udpServerReadDatagrams()
{
QNetworkDatagram datagram;
/* this runs in the main GUI thread, it won't ever run at the
* exact same time as the timer callback, so we can safely just
* append to the rawBuffer, even if it's about to be processed
* by the parser.
*/
while (udpSocket->hasPendingDatagrams()) {
datagram = udpSocket->receiveDatagram();
pn->rawBuffer += datagram.data();
//Will a ton of incoming data make this whole thing block
//forever? maybe.
}
//qDebug() << pn->rawBuffer ;
}
void FormGPS::startUDPServer()
{
AOGSettings s;
int port = s.value("port/udp_port_num",9999).toInt();
if(udpSocket) stopUDPServer();
udpSocket = new QUdpSocket(this); //should auto delete with the form
udpSocket->bind(port); //by default, bind to all interfaces.
connect(udpSocket,SIGNAL(readyRead()),this,SLOT(udpServerReadDatagrams()));
}
void FormGPS::stopUDPServer()
{
if(udpSocket) {
udpSocket->close();
delete udpSocket;
udpSocket = NULL;
}
}
//TODO: connection to MKR1000 on fixed address.. probably in another module