Closed bomilkar closed 4 years ago
Have you tried the fix with strlen(s)+1 ? Does it solve the problem ?
I have seen spurious chars on the receiving end with the string being incompletely sent. Does this surprise you?? Instead of running XCSoar you can run netcat to see what happens on port 4353.
Think this is indeed an error. As the docu of strlen() states that the ending character is not included. Please provide a pull request to fix this.
After a bit more digging into the code it's now clear that it must say send(sock, s, strlen(s)+1, 0) instead of send(sock, s, strlen(s), 0) . Run it with XCSoar, turn on "Setup->Logger->NMEA_logger" and look at the log files with the terminating '\0' being sent or without it. Understood??
You are meaning send(sock, s, strlen(s)+1, 0) instead of send(sock, s, strlen(s), 0) ??
Correct. Copy/Paste error. ;-) strlen(s) returns the length of the string w/o the terminating '\0'. But the terminating '\0' should be included in the outgoing sentence since the receiving end may think of it as a string, not being lead by the number of bytes received. The best what the receiving end may do is to think it's an incomplete sentence looking for the rest of it coming from the next recv().
OK, agree. PR #6 merged.
In main() there are 3 places like this:
send(sock, s, strlen(s), 0)
with s holding the NMEA sentence to be sent. I think it would be better to send the complete string including the terminating '\0', which is part of the string (in C notation) but not counted by strlen(). I suggest to do this instead:send(sock, s, strlen(s)+1, 0)
This would include the '\0' which was previously appended bysprintf()
.The reason is not so esoteric as it sounds. There is no control over the number of sentences being sent in one package. This becomes obvious when observing the receiving end. The function
recv()
may very well receive multiple sentences in one chunk, even if each sentence was sent by an individualsend()
. It would be safer if the received data can be considered a concatenation of strings. It would also eliminate the need to mark the end of the sentence in any other way (e.g. '\n', '\r' ...).