From 5dfbe7865cbd05add45e9480e5119d03cea940f7 Mon Sep 17 00:00:00 2001 From: Jon Beniston Date: Fri, 31 Jul 2026 15:56:51 +0100 Subject: [PATCH] Fix number of sentences. --- sdrbase/util/ais.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sdrbase/util/ais.cpp b/sdrbase/util/ais.cpp index b714aa7a2..0bcc78ff4 100644 --- a/sdrbase/util/ais.cpp +++ b/sdrbase/util/ais.cpp @@ -40,8 +40,11 @@ QString AISMessage::toNMEA(const QByteArray bytes) { QStringList nmeaSentences; - // Max payload is ~61 chars -> 366 bits - int sentences = bytes.size() / 45 + 1; + // Number of 6-bit characters needed for the message + int totalChars = (bytes.size() * 8 + 5) / 6; + // A single sentence "!AIVDM,1,1,,," header allows 62 payload chars in 80 chars total, + // a multi-sentence "!AIVDM,n,m,i,," header allows 61 + int sentences = (totalChars <= 62) ? 1 : (totalChars + 60) / 61; int sentence = 1; int bits = 8;