-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathNTRIPClient.cpp
83 lines (65 loc) · 1.59 KB
/
NTRIPClient.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* NTRIP Client
*
* Copyright 2023 by KLS <https://github.com/klstronics/ESPNTRIPClient>
*
* Licensed under GNU General Public License 3.0 or later.
* Some rights reserved. See COPYING, AUTHORS.
*
* @license GPL-3.0 <http://www.gnu.org/licenses/>
*/
#include "NTRIPClient.h"
#include "base64.h"
NTRIPClient::NTRIPClient(String server, int port) {
server.trim();
this->server = server;
this->port = port;
}
String NTRIPClient::getMountPoints() {
if (connected()) {
return "already connected";
}
if (!connect(server.c_str(), port)) {
return "connection failed";
}
print("GET / HTTP/1.0\r\nUser-Agent: " + useragent + "\r\nAccept: */* \r\nConnection: close\r\n\r\n");
String response;
while (connected()) {
while (available()) {
response += (char)read();
}
}
stop();
return response;
}
bool NTRIPClient::startStream(String mountpoint, String gga, String username, String password) {
mountpoint.trim();
username.trim();
password.trim();
if (connected()) {
stop();
}
if (!connect(server.c_str(), port)) {
return false;
}
print("GET /" + mountpoint + " HTTP/1.0\r\nUser-Agent: " + useragent + "\r\nAuthorization: Basic " + base64::encode(username + ":" + password) + "\r\n\r\n");
sendGGA(gga);
uint32_t timeout = millis() + 15000;
while (!available()) {
if (timeout < millis()) {
stop();
return false;
}
delay(10);
}
while (available()) {
read();
}
return true;
}
void NTRIPClient::sendGGA(String gga) {
gga.trim();
if (gga.length() > 40) {
print(gga + "\r\n");
}
}