summaryrefslogtreecommitdiff
path: root/qmap/qmap_ipc.h
diff options
context:
space:
mode:
authorhibby <d@vehibberd.com>2026-10-06 21:24:40 +0100
committerhibby <d@vehibberd.com>2026-10-06 21:24:40 +0100
commitc25cbdf6fb6d946175f4335fab77bfea601b56db (patch)
tree6f7a94b7b81f999e434f61b73d47e337dfd26bf2 /qmap/qmap_ipc.h
parent71f5689252c9f13e70e1c24856904475b2307809 (diff)
parent0685fcada9f95fe90f70b387cd7d757da8209624 (diff)
Merge tag 'debian/3.2.0_rc1+dfsg-2' into debian/trixie-backportsdebian/trixie-backports
tagging wsjtx 3.2.0~rc1+dfsg-2
Diffstat (limited to 'qmap/qmap_ipc.h')
-rw-r--r--qmap/qmap_ipc.h107
1 files changed, 107 insertions, 0 deletions
diff --git a/qmap/qmap_ipc.h b/qmap/qmap_ipc.h
new file mode 100644
index 00000000..2ded811d
--- /dev/null
+++ b/qmap/qmap_ipc.h
@@ -0,0 +1,107 @@
+#ifndef QMAP_IPC_H
+#define QMAP_IPC_H
+
+#include "decode_ipc.h"
+
+#include <algorithm>
+#include <cstddef>
+#include <cstdint>
+#include <cstring>
+#include <type_traits>
+
+constexpr std::size_t QMapDecodeCapacity = qmap_decode_ipc::max_rows;
+constexpr std::size_t QMapDecodeRowSize = qmap_decode_ipc::row_size;
+
+static_assert (QMapDecodeRowSize == 80,
+ "QMAP IPC must use the fixed 80-byte decoder row");
+
+enum class QMapClickAction : std::int32_t
+{
+ None = 0,
+ Disarm = 1,
+ Select = 2,
+ SelectAndEnableTx = 3,
+};
+
+using QMapDecodeBlock = qmap_decode_ipc::DecodeRows;
+
+struct QMapClickMailbox
+{
+ char selectedDecode[QMapDecodeRowSize];
+ QMapClickAction action;
+};
+
+struct QMapSharedMemory
+{
+ QMapDecodeBlock decodes;
+ QMapClickMailbox click;
+};
+
+static_assert (sizeof (std::int32_t) == 4, "QMAP IPC requires 32-bit integers");
+static_assert (std::is_standard_layout<QMapClickMailbox>::value,
+ "QMAP click mailbox must have a stable field layout");
+static_assert (std::is_trivially_copyable<QMapClickMailbox>::value,
+ "QMAP click mailbox must support byte-for-byte copying");
+static_assert (offsetof (QMapClickMailbox, action) == QMapDecodeRowSize,
+ "QMAP click request offset changed");
+static_assert (sizeof (QMapClickMailbox) == QMapDecodeRowSize + sizeof (std::int32_t),
+ "QMAP click mailbox size changed");
+static_assert (std::is_standard_layout<QMapSharedMemory>::value,
+ "QMAP shared memory must have a stable field layout");
+static_assert (std::is_trivially_copyable<QMapSharedMemory>::value,
+ "QMAP shared memory must support byte-for-byte copying");
+static_assert (offsetof (QMapSharedMemory, decodes) == 0,
+ "QMAP decode block must start the shared segment");
+static_assert (offsetof (QMapSharedMemory, click) == sizeof (QMapDecodeBlock),
+ "QMAP click mailbox offset changed");
+static_assert (sizeof (QMapSharedMemory) == sizeof (QMapDecodeBlock) + sizeof (QMapClickMailbox),
+ "QMAP IPC wire layout changed");
+
+constexpr std::size_t QMapSharedMemorySize {
+ ((sizeof (QMapSharedMemory) + 15) / 16) * 16
+};
+
+static_assert (QMapSharedMemorySize >= qmap_decode_ipc::shared_memory_size,
+ "QMAP shared memory must preserve the decoder segment size");
+static_assert (sizeof (QMapSharedMemory) <= QMapSharedMemorySize,
+ "QMAP IPC exceeds the shared-memory segment");
+
+constexpr bool qmapDecoderRegionAvailable (std::size_t mappedSize) noexcept
+{
+ return mappedSize >= qmap_decode_ipc::shared_memory_size;
+}
+
+constexpr bool qmapClickMailboxAvailable (std::size_t mappedSize) noexcept
+{
+ return mappedSize >= sizeof (QMapSharedMemory);
+}
+
+constexpr std::size_t qmapClearLength (std::size_t mappedSize) noexcept
+{
+ return std::min (mappedSize, QMapSharedMemorySize);
+}
+
+inline void clearQMapSharedMemory (void * mappedData,
+ std::size_t mappedSize) noexcept
+{
+ if (mappedData) std::memset (mappedData, 0, qmapClearLength (mappedSize));
+}
+
+inline void publishQMapDecodeBlock (QMapSharedMemory& shared,
+ QMapDecodeBlock& publication) noexcept
+{
+ publication.nWDecoderBusy = shared.decodes.nWDecoderBusy;
+ publication.nWTransmitting = shared.decodes.nWTransmitting;
+ publication.kHzRequested = shared.decodes.kHzRequested;
+ shared.decodes = publication;
+}
+
+inline bool acknowledgeQMapDecodeBatch (QMapDecodeBlock& shared) noexcept
+{
+ if (shared.nQDecoderDone == 0) return false;
+ shared.ndecodes = 0;
+ shared.nQDecoderDone = 0;
+ return true;
+}
+
+#endif // QMAP_IPC_H