Building a program to read NTRIP from a server and pass it on via a serial port to a GPS
the GPS would sporadically recognize the RTCM data being given to it, but couldn't use it/lost the connection. I used the SNIP RTCM decoder to see what messages where getting though and found that only type 1006 message (base station location) but when SNIP connected to the same mountpoint it could find type 1006, 1033, 1074, 1084, 1094, 1124.
I removed the Ntrip-version: Ntrip/2.0 header from my GET request and it started to send all of the message types I expected (1006, 1033, 1074, 1084, 1094, 1124). when I feed this into the GPS it recognizes the RTCM data but it still doesn't want to use the data.
public static NetworkStream? ConnectToMountPoint(NTripClientSettings settings, NTripMountPoint mountpoint)
{
try
{
TcpClient tcp = new ();
// login details.
string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{settings.Username}:{settings.Password}"));
// build up the raw HTTP request.
StringBuilder rawhttpreq = new ();
rawhttpreq.AppendLine($"GET /{mountpoint.MountPointAddress} HTTP/1.1");
rawhttpreq.AppendLine($"Host: {settings.Address}:{settings.Port}");
rawhttpreq.AppendLine("Ntrip-Version: Ntrip/2.0");
rawhttpreq.AppendLine("User-Agent: NtripClient/2.0");
rawhttpreq.AppendLine("Accept: */*");
rawhttpreq.AppendLine($"Authorization: Basic {credentials}");
rawhttpreq.AppendLine();
// request vars
byte[] requestBuffer = Encoding.ASCII.GetBytes(rawhttpreq.ToString());
//
// Try and Connect to the NTrip Mount point
//
tcp.Connect(settings.Address, settings.Port);
// if we have connected
if (tcp.Connected)
{
SystemLog.Log("Connected to mount point");
// Get the stream
NetworkStream stream = tcp.GetStream();
if(stream != null)
{
// write out request
stream.Write(requestBuffer, 0, requestBuffer.Length);
return stream;
}
}
return null;
}
catch (Exception ex)
{
if (ex is SocketException)
{
SystemLog.Log("Error connecting to ntrip server", ex, SystemLogType.Error);
}
else if (ExceptionHelper.IsKnownException(ex))
{
SystemLog.Log("Error reading from ntrip server", ex, SystemLogType.Error);
}
else
{
SystemLog.Log($"Error: {ex.Message}");
// unknown error.
throw;
}
return null;
}
}
this is the code making a GET Request to the Mountpoint
public static void StreamNtripDataFromMountPoint(NetworkStream? networkstream, SerialPort? ggaport, SerialPort? ntripport)
{
// response/receive vars.
byte[] responseBuffer = new byte[BUFFER_SIZE];
Task outgoingMessage;
// If NtripStream has been attached
if (networkstream != null)
{
// Read from the response stream
while (networkstream.CanRead && networkstream.CanWrite)
{
Array.Clear(responseBuffer);
Task<int> networkMessage;
int bytesread = 0;
networkMessage = networkstream.ReadAsync(responseBuffer, 0, responseBuffer.Length);
networkMessage.Wait();
bytesread = networkMessage.Result;
/// if the ntrip port is ready pass ntrip data out of it
if (ntripport != null && ntripport.IsOpen)
{
outgoingMessage = ntripport.BaseStream.WriteAsync(responseBuffer, 0, bytesread);
outgoingMessage.Wait();
}
/// if the ntrip port is closed or unattached print data to console to show that it is receiving and not sending over port
else
{
string responseString = Encoding.ASCII.GetString(responseBuffer);
SystemLog.Log($"{responseString}");
}
}
SystemLog.Log("NtripStream reset");
}
else
{
SystemLog.Log("NtripStream not found");
}
}
this is the code reading data from the network stream
the messages when Ntrip-Version is in header the messages when Ntrip-Version is not a header
why is this happening? is there some other step I should be taking to handle the incoming data if I tell it to expect Ntrip-Version? and what does the server default to if no Ntrip-version is provided? because i've tried Ntrip/1.0 and Ntrip/2.0 both of them result in me only getting one kind of message.
any direction for why this happens would be apricated.
thank you for your time.