From 6c1b363d37ccb091f570c9d20a7becbe323ed523 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 5 Jan 2022 20:12:38 -0500 Subject: [PATCH] Live Data progress --- firmware/console/binary/FragmentEntry.cpp | 33 +++++++++++++++++++ firmware/console/binary/FragmentEntry.h | 21 ++++++++++++ firmware/console/binary/tunerstudio.mk | 1 + .../console/binary/tunerstudio_commands.cpp | 2 +- unit_tests/tests/test_pwm_generator.cpp | 2 +- 5 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 firmware/console/binary/FragmentEntry.cpp create mode 100644 firmware/console/binary/FragmentEntry.h diff --git a/firmware/console/binary/FragmentEntry.cpp b/firmware/console/binary/FragmentEntry.cpp new file mode 100644 index 0000000000..3953a34bfa --- /dev/null +++ b/firmware/console/binary/FragmentEntry.cpp @@ -0,0 +1,33 @@ +/* + * FragmentEntry.cpp + * + * Created on: Jan 5, 2022 + * @author Andrey Belomutskiy, (c) 2012-2022 + */ + +#include "pch.h" +#include "FragmentEntry.h" + +/** + * copy dataLength of fragmented outputs starting at dataOffset into destination starting at zero + */ +void copyRange(uint8_t *destination, FragmentEntry *fragments, size_t dataOffset, size_t dataLength) { + int fragmentIndex = 0; + + // scroll to starting fragment + while (dataOffset > fragments[fragmentIndex].size) { + dataOffset -= fragments[fragmentIndex].size; + fragmentIndex ++; + } + + int destinationIndex = 0; + + while (dataLength > 0) { + int copyNowSize = minI(dataLength, fragments[fragmentIndex].size - dataOffset); + memcpy(destination + destinationIndex, fragments[fragmentIndex].data + dataOffset, copyNowSize); + destinationIndex += copyNowSize; + dataOffset = 0; + dataLength -= copyNowSize; + fragmentIndex++; + } +} diff --git a/firmware/console/binary/FragmentEntry.h b/firmware/console/binary/FragmentEntry.h new file mode 100644 index 0000000000..bc247699ba --- /dev/null +++ b/firmware/console/binary/FragmentEntry.h @@ -0,0 +1,21 @@ +/* + * FragmentEntry.h + * + * Created on: Jan 5, 2022 + * @author Andrey Belomutskiy, (c) 2012-2022 + */ + +#pragma once + +struct FragmentEntry { + FragmentEntry(uint8_t *data, size_t size) { + this->data = data; + this->size = size; + + } + + uint8_t *data; + size_t size; +}; + +void copyRange(uint8_t *destination, FragmentEntry *fragments, size_t dataOffset, size_t dataLength); diff --git a/firmware/console/binary/tunerstudio.mk b/firmware/console/binary/tunerstudio.mk index f62c5b6df3..77f2403d23 100644 --- a/firmware/console/binary/tunerstudio.mk +++ b/firmware/console/binary/tunerstudio.mk @@ -5,6 +5,7 @@ TUNERSTUDIO_SRC_CPP = $(PROJECT_DIR)/console/binary/tunerstudio_io.cpp \ $(PROJECT_DIR)/console/binary/ts_can_channel.cpp \ $(PROJECT_DIR)/console/binary/serial_can.cpp \ $(PROJECT_DIR)/console/binary/tunerstudio.cpp \ + $(PROJECT_DIR)/console/binary/FragmentEntry.cpp \ $(PROJECT_DIR)/console/binary/tunerstudio_commands.cpp \ $(PROJECT_DIR)/console/binary/bluetooth.cpp \ $(PROJECT_DIR)/console/binary/signature.cpp diff --git a/firmware/console/binary/tunerstudio_commands.cpp b/firmware/console/binary/tunerstudio_commands.cpp index 8ce82b7135..37d329c145 100644 --- a/firmware/console/binary/tunerstudio_commands.cpp +++ b/firmware/console/binary/tunerstudio_commands.cpp @@ -23,7 +23,7 @@ void TunerStudio::cmdOutputChannels(TsChannelBase* tsChannel, uint16_t offset, u tsState.outputChannelsCommandCounter++; prepareTunerStudioOutputs(); // this method is invoked too often to print any debug information - tsChannel->sendResponse(TS_CRC, reinterpret_cast(&engine->outputChannels) + offset, count); + tsChannel->writeCrcPacket(TS_RESPONSE_OK, reinterpret_cast(&engine->outputChannels) + offset, count); } #endif // EFI_TUNER_STUDIO diff --git a/unit_tests/tests/test_pwm_generator.cpp b/unit_tests/tests/test_pwm_generator.cpp index b521d06dc2..028ce6b706 100644 --- a/unit_tests/tests/test_pwm_generator.cpp +++ b/unit_tests/tests/test_pwm_generator.cpp @@ -2,7 +2,7 @@ * test_pwm_generator.cpp * * @date Dec 8, 2018 - * Author: user + * @author Andrey Belomutskiy, (c) 2012-2020 */ #include "pch.h"