Nmea0183 output buffer and sentence dropping

This forum is for discussing hardware (electronics) and software design aspects of multiplexers in general.
Post Reply
Luis Sa
Site Admin
Posts: 848
Joined: Thu May 04, 2017 4:12 am

Nmea0183 output buffer and sentence dropping

Post by Luis Sa » Thu Mar 28, 2024 7:42 pm

Hello,

Starting with versions:
  • 8.2 of NMEA2WIFI
  • 2.3 of NMEA3WIFI
  • 6.2 of NMEA4WIFI
  • 2.0 of the N2K0183
we changed the operation of the Nmea0183 serial output buffer (referred to as P2 in the N2K0183, P3 in the NNMEA2WWIFI and NMEA3WIFI and P5 in NMEA4WIFI). We use the example of the NMEA4WIFI multiplexer to explain the change. Similar considerations apply to the other multiplexers. In the case of the NMEA4WIFI multiplexer we have 4 serial Nmea0183 inputs, P1, P2, P3 and P4. We also have UDP, TCP and EXT inputs. If we check the boxes:
  • P1>P5 (P1 routed to P5)
  • P2>P5 (P2 routed to P5)
  • ...
  • EXT>P5 (EXT routed to P5)
we will likely create a potential congestion issue with the P5 buffer, which could lead to buffer overflow problems. The likelihood of congestion depends on the data rates of incoming data from multiple inputs (P1 to P4) compared to the output data rate of P5. For instance, if the combined input data rate exceeds the output data rate of P5, issues may arise. That will depend on the rate that data comes from the several inputs and the rate that data leaves P5. If the combined input data rate is greater than the output data rate of P5 we get problems. If the P5 baud rate is set to 115200 (each character takes about 86 us to be transmitted) and P1 ...P4 are set at 4800 there will be no problem (assuming UDP, TCP and EXT are not routed to P5). However, only computers listeners can receive data from P5 at that fast data rate. In addition there's a risk of buffer overflow if bursts of data arrive simultaneously from the inputs.

The P5 output serial buffer had a size of 128 bytes (128 characters). Nmea0183 sentences can have a maximum of 81 characters but, for the sake of explanation, we consider that the sentences have a length of 40 characters. If a burst of 4 sentences arrive almost at the same time to be sent out by P5, the 1st 3 will be written to buffer, occupying 120 chars and leaving only 8 chars for the next 4th sentence. When this sentence arrives, the multiplexer was halted in a wait state until 32 characters were sent out, so that a space of 40 chars becomes available for the sentence. We see that when the serial output buffer lacks space to output the sentence, the multiplexer is halted until space becomes available. Consequently, if more data continues to arrive at the multiplexer inputs during this wait state, the incoming data won't be read immediately. Instead, it accumulates in the input buffers, eventually leading to overflow. As the input buffers operate as ring buffers, overflow results in data corruption.

In order to alleviate this problem we no longer wait for space to be available. When the sentence arrives and there is no space available in the output serial buffer we drop the sentence. This is better than data corruption and possibly multiplexer crashes. These are the new buffer sizes:
  • For the NMEA2WIFI multiplexer: 256 bytes for the P1 and P2 serial input buffers and 128 bytes for the P3 serial output buffer
  • For the NMEA3WIFI multiplexer: 256 bytes for the P1 and P2 serial input buffers and 256 bytes for the P3 serial output buffer
  • For the NMEA4WIFI multiplexer: 256 bytes for the P1, P2, P3 and P4 serial input buffers and 256 bytes for the P5 serial output buffer
  • For the N2K0183 multiplexer: 256 bytes for the P1 and PX serial input buffers and 1024 bytes for the P2 serial output buffer

Regards, Luis

Post Reply