From 347413e44b4649a495ef31cadb2343efd82f8318 Mon Sep 17 00:00:00 2001 From: rusefi Date: Tue, 26 May 2020 22:30:53 -0400 Subject: [PATCH] console composite logger --- firmware/console/binary/tooth_logger.cpp | 10 ++++++++++ firmware/console/binary/tooth_logger.h | 4 ++++ firmware/console/binary/tunerstudio.cpp | 22 ++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/firmware/console/binary/tooth_logger.cpp b/firmware/console/binary/tooth_logger.cpp index 20970d7a41..df531c9978 100644 --- a/firmware/console/binary/tooth_logger.cpp +++ b/firmware/console/binary/tooth_logger.cpp @@ -51,6 +51,10 @@ static bool coil = false; // same about injectors static bool injector = false; +int getCompositeRecordCount() { + return NextIdx; +} + static void SetNextCompositeEntry(efitick_t timestamp, bool trigger1, bool trigger2, bool isTDC DECLARE_ENGINE_PARAMETER_SUFFIX) { uint32_t nowUs = NT2US(timestamp); @@ -159,6 +163,12 @@ void EnableToothLogger() { tsOutputChannels.toothLogReady = true; } +void EnableToothLoggerIfNotEnabled() { + if (!ToothLoggerEnabled) { + EnableToothLogger(); + } +} + void DisableToothLogger() { ToothLoggerEnabled = false; tsOutputChannels.toothLogReady = false; diff --git a/firmware/console/binary/tooth_logger.h b/firmware/console/binary/tooth_logger.h index 96688415e6..be0c07f1a6 100644 --- a/firmware/console/binary/tooth_logger.h +++ b/firmware/console/binary/tooth_logger.h @@ -13,6 +13,10 @@ #include "rusefi_enums.h" #include "engine.h" +int getCompositeRecordCount(); + +void EnableToothLoggerIfNotEnabled(); + // Enable the tooth logger - this clears the buffer starts logging void EnableToothLogger(); diff --git a/firmware/console/binary/tunerstudio.cpp b/firmware/console/binary/tunerstudio.cpp index bb3e016e07..d8b964694b 100644 --- a/firmware/console/binary/tunerstudio.cpp +++ b/firmware/console/binary/tunerstudio.cpp @@ -749,6 +749,8 @@ bool handlePlainCommand(ts_channel_s *tsChannel, uint8_t command) { } } +static int transmitted = 0; + int tunerStudioHandleCrcCommand(ts_channel_s *tsChannel, char *data, int incomingPacketSize) { ScopePerf perf(PE::TunerStudioHandleCrcCommand); @@ -842,6 +844,26 @@ int tunerStudioHandleCrcCommand(ts_channel_s *tsChannel, char *data, int incomin sendOkResponse(tsChannel, TS_CRC); break; + case TS_GET_COMPOSITE_BUFFER_DONE_DIFFERENTLY: + { + const uint8_t* const buffer = GetToothLoggerBuffer().Buffer; + + const uint8_t* const start = buffer + COMPOSITE_PACKET_SIZE * transmitted; + + int currentEnd = getCompositeRecordCount(); + + if (currentEnd > transmitted) { + // more normal case - tail after head + sr5SendResponse(tsChannel, TS_CRC, start, COMPOSITE_PACKET_SIZE * (currentEnd - transmitted)); + transmitted = currentEnd; + } else { + // we are here if tail of buffer has reached the end of buffer and re-started from the start of buffer + // sending end of the buffer, next transmission would take care of the rest + sr5SendResponse(tsChannel, TS_CRC, start, COMPOSITE_PACKET_SIZE * (COMPOSITE_PACKET_COUNT - transmitted)); + transmitted = 0; + } + } + break; case TS_GET_LOGGER_GET_BUFFER: { auto toothBuffer = GetToothLoggerBuffer();