Openvario / variod

Daemon for autonomous e-vario
4 stars 8 forks source link

handle multiple and incomplete NMEA sentences in a single recv() #13

Closed bomilkar closed 4 years ago

bomilkar commented 4 years ago

We have to deal with the fact that one recv() may yield more than 1 NMEA sentence. That is particularly true if they were sent in short burst sequence or if the system was loaded at the time. The previous implementation processed the first sentence only, the remaining sentences from that recv() were ignored. That might have gone unnoticed for data coming from sensord but now that we need information from XCSoar (to enable STF) we must not drop any of the sentences sent.

Introducing multi_sentence_clean() helps make receiving more robust. NMEA sentences may be terminated by '\n', '\r', '\0' or any combination and multiples of these.

Some changes were made to improve readability and/or understanding of what the code is supposed to do. E.g. instead of calling the socket address "server" I choose "sensor_server" to help the reader understand which direction the data is flowing.

For similar reasons I improved some of the error messages to give a better understanding of what is going on. E.g. instead of "accept failed" I decided to explain which accept it was that failed.

After a lot of thought and analysis I came to realize, that it is NOT uncommon that recv() returns incomplete NMEA sentences. For instance if a burst of sentences came in. So it is safer to deal with this gracefully than to hope it will not happen.

Unfortunately the above required quite a lot of change in the code and I couldn't think of splitting it in self-contained parts.

bomilkar commented 4 years ago

If you feel we don't need to deal with multiple and/or incomplete sentences, then let's discuss this here https://github.com/Openvario/variod/issues/14

bomilkar commented 4 years ago

This commit https://github.com/Openvario/variod/pull/13/commits/dbbd4c73caed789065675af393cda65d5f2b2f9e takes care of 2 things:

  1. parse_NMEA_sensor() wants no '\n' at the end of the sentence. If there is, then verify_nmea_checksum() will fail.
  2. NMEA sentences sent to XCSoar must have a '\n' at the end and the string terminator '\0' must not be included in the send()
bomilkar commented 4 years ago

Restart.