98 lines
2.8 KiB
Dart
98 lines
2.8 KiB
Dart
import 'dart:async';
|
|
import 'dart:convert';
|
|
import 'dart:developer';
|
|
import 'dart:io';
|
|
import 'dart:typed_data';
|
|
|
|
class RtkBase {
|
|
// String host = "192.168.1.6";
|
|
// String host = "120.253.239.161"; //ip地址
|
|
// int port = 8001; //端口号
|
|
// String account = "csar6309"; //用户名
|
|
// String password = "9kd6kmd3"; //密码
|
|
// String mountPoint = "RTCM33_GRCE"; //挂载点
|
|
String host = "vrs.sixents.com";
|
|
int port = 8005; //端口号
|
|
String account = "uhjns21929"; //用户名
|
|
String password = "UpqbKp4Q"; //密码
|
|
String mountPoint = "RTCM32_GRECJ2"; //挂载点
|
|
String lastGGA = ""; //最后一次发送的GGA
|
|
Socket? _client;
|
|
bool isConnected = false;
|
|
int lastSendGGATime = 0;
|
|
var rtcmStreamController = StreamController<Uint8List>.broadcast();
|
|
Stream<Uint8List> get rtcmStream => rtcmStreamController.stream;
|
|
var updateCount = 0; //
|
|
dispose() {
|
|
close();
|
|
}
|
|
|
|
connect() {
|
|
var headers = [
|
|
"GET /$mountPoint HTTP/1.0",
|
|
"Host: $host",
|
|
"Ntrip-Version: Ntrip/2.0",
|
|
"User-Agent: NTRIP u-blox",
|
|
"Accept: */*",
|
|
"Authorization: Basic ${base64Encode(('$account:$password').codeUnits)}",
|
|
"Connection: close",
|
|
"\r\n"
|
|
];
|
|
Socket.connect(host, port).then((Socket client) {
|
|
_client = client;
|
|
log('Connected to: ${client.remoteAddress.address}:${client.remotePort}');
|
|
var reqStr = headers.join("\r\n");
|
|
client.write(reqStr);
|
|
log(reqStr);
|
|
|
|
client.listen(
|
|
(Uint8List data) {
|
|
if (data[0] == 211) {
|
|
rtcmStreamController.add(data);
|
|
} else {
|
|
String response = String.fromCharCodes(data);
|
|
log("Connected to NTRIP caster: $response");
|
|
if (response.contains("ICY 200 OK")) {
|
|
if (lastGGA.isNotEmpty) {
|
|
_client!.write(lastGGA);
|
|
lastSendGGATime = DateTime.now().millisecondsSinceEpoch;
|
|
}
|
|
} else {
|
|
log("Failed to connect to NTRIP caster", error: response);
|
|
client.close();
|
|
_client = null;
|
|
}
|
|
}
|
|
},
|
|
onError: (error) {
|
|
log("Error reading from response body: $error");
|
|
// client.close();
|
|
},
|
|
);
|
|
client.done.then((_) {
|
|
log('Connection to NTRIP caster closed');
|
|
_client = null;
|
|
});
|
|
}).catchError((error) {
|
|
log("Error connecting to server: $error");
|
|
_client = null;
|
|
});
|
|
}
|
|
|
|
close() {
|
|
if (_client != null) {
|
|
_client!.close();
|
|
_client = null;
|
|
}
|
|
}
|
|
|
|
sendGGA(String gga) {
|
|
var now = DateTime.now().millisecondsSinceEpoch;
|
|
if (now - lastSendGGATime > 10000 && _client != null) {
|
|
lastGGA = "$gga\r\n";
|
|
_client!.write(lastGGA);
|
|
lastSendGGATime = now;
|
|
}
|
|
}
|
|
}
|