From 41238fc595f0c6180428a73d7659e02cc3eb2263 Mon Sep 17 00:00:00 2001 From: Michael Keller Date: Sun, 1 Dec 2024 12:17:09 +1300 Subject: [PATCH] Heinrichs Weikamp: Add logging for compass events. --- src/hw_ostc_parser.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/hw_ostc_parser.c b/src/hw_ostc_parser.c index 5426c6f8..41410841 100644 --- a/src/hw_ostc_parser.c +++ b/src/hw_ostc_parser.c @@ -1131,6 +1131,40 @@ hw_ostc_parser_internal_foreach (hw_ostc_parser_t *parser, dc_sample_callback_t offset += 2; length -= 2; } + + // Compass heading update + if (events & 0x0200) { + if (length < 2) { + ERROR (abstract->context, "Buffer overflow detected!"); + return DC_STATUS_DATAFORMAT; + } + + if (callback) { + unsigned int heading = array_uint16_le(data + offset); + dc_sample_value_t sample = { + .event.type = SAMPLE_EVENT_STRING, + .event.flags = SAMPLE_FLAGS_SEVERITY_INFO, + }; + + if (heading & 0x8000) { + sample.event.name = "Cleared compass heading"; + } else { + if (heading & 0x4000) { + sample.event.type = SAMPLE_EVENT_HEADING; + sample.event.name = "Set compass heading"; + } else { + sample.event.name = "Logged compass heading"; + } + + sample.event.value = heading & 0x1FF; + } + + callback(DC_SAMPLE_EVENT, &sample, userdata); + } + + offset += 2; + length -= 2; + } } // Extended sample info.