Skip to content

Parse each AOG UDP datagram on its own so short packets do not drop the next one - #107

Open
gunicsba wants to merge 2 commits into
developfrom
fix/udp-parser-index
Open

gunicsba wants to merge 2 commits into
developfrom
fix/udp-parser-index

Conversation

@gunicsba

Copy link
Copy Markdown
Contributor

Summary

The AOG UDP receive loop kept unparsed bytes in a static buffer between datagrams, and didn't reset its read index after moving leftover bytes to the front. A packet shorter than 8 bytes waited in the buffer for the next datagram; AOG's section control request (PGN 241) is 7 bytes. The packet after it was then read from the wrong offset, logged as Unknown start of message and dropped.

Other problems in the same loop:

  • the 2 start bytes were read with two unsequenced index++ in one expression;
  • it never checked that a whole packet was in the buffer before passing it on;
  • index was a std::uint8_t.

Changes

  • New header-only aog_packet::parse_datagram() (include/aog_packet_parser.hpp). It passes every complete packet in one datagram to a callback, and reports whether it stopped on an unknown start or a truncated packet, and where.
  • AgIO never splits a packet across datagrams, so each datagram is now parsed on its own and nothing carries over to the next one.
  • handle_incoming_packets() and handle_address_detection() both use it. The log line now says how many bytes of the datagram were dropped.
  • tools/test_aog_packet_parser.cpp covers the field case (a 7-byte PGN 241 followed by a PGN 229), several packets in one datagram, an unknown start after a valid packet, truncated packets and empty packets. It is registered like test_async_log.

Notes

Testing

  • test_aog_packet_parser passes (MSVC and clang).
  • Release build passes on Windows (MSVC).

🤖 Generated with Claude Code

gunicsba and others added 2 commits October 14, 2026 08:32
…he next one

The receive loop kept unparsed bytes in a static buffer between datagrams and
never reset its read index after moving leftover bytes to the front. A packet
shorter than 8 bytes (AOG's 7-byte section control request, PGN 241) waited in
the buffer for the next datagram, and the packet after it was then read from
the wrong offset, logged as "Unknown start of message" and dropped. It also
read the 2 start bytes with two unsequenced index++ in one expression, and did
not check that a whole packet was present before handing it on.

AgIO never splits a packet across datagrams, so each datagram is now parsed
on its own by aog_packet::parse_datagram (header-only, unit tested), shared by
the AOG and address detection sockets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The field log showed datagrams with 2 or 4 bytes after a complete packet, and
others that are not AOG packets at all (one starts with "$P"). The log only
said how many bytes were dropped, so the sender could not be identified.

Log the sender's address and port, and up to 64 bytes as hex with a "|" where
parsing stopped, followed by the printable characters.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant