diff --git a/firmware/console/binary/FragmentEntry.cpp b/firmware/console/binary/FragmentEntry.cpp deleted file mode 100644 index ab1e8136fa..0000000000 --- a/firmware/console/binary/FragmentEntry.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * FragmentEntry.cpp - * - * Created on: Jan 5, 2022 - * @author Andrey Belomutskiy, (c) 2012-2022 - */ - -#include "pch.h" -#include "FragmentEntry.h" - -void copyRange(uint8_t* destination, FragmentList src, size_t skip, size_t size) { - int fragmentIndex = 0; - - // Find which fragment to start - skip any full fragments smaller than `skip` parameter - while (skip > src.fragments[fragmentIndex].size && fragmentIndex <= src.count) { - skip -= src.fragments[fragmentIndex].size; - fragmentIndex++; - } - - int destinationIndex = 0; - - while (size > 0) { - if (fragmentIndex >= src.count) { - // somehow we are past the end of fragments - fill with zeros - memset(destination + destinationIndex, 0, size); - return; - } - - int copyNowSize = minI(size, src.fragments[fragmentIndex].size - skip); - const uint8_t* fromBase = src.fragments[fragmentIndex].data; - if (!fromBase) { - // we have no buffer for this fragment - fill with zeroes - memset(destination + destinationIndex, 0, copyNowSize); - } else { - memcpy(destination + destinationIndex, fromBase + skip, copyNowSize); - } - destinationIndex += copyNowSize; - skip = 0; - size -= copyNowSize; - fragmentIndex++; - } -} diff --git a/firmware/console/binary/FragmentEntry.h b/firmware/console/binary/FragmentEntry.h deleted file mode 100644 index 05227488e9..0000000000 --- a/firmware/console/binary/FragmentEntry.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * FragmentEntry.h - * - * Created on: Jan 5, 2022 - * @author Andrey Belomutskiy, (c) 2012-2022 - */ - -#pragma once - -struct FragmentEntry { - template - FragmentEntry(const TData* data) - : data(reinterpret_cast(data)) - , size(sizeof(TData)) - { - } - - const uint8_t* const data; - const size_t size; -}; - -struct FragmentList { - const FragmentEntry* fragments; - const size_t count; -}; - -// copy `size` of fragmented outputs in to destination, skipping the first `skip` bytes -void copyRange(uint8_t* destination, FragmentList src, size_t skip, size_t size); diff --git a/firmware/console/binary/live_data.h b/firmware/console/binary/live_data.h index 41d237e1fc..985a3b36a4 100644 --- a/firmware/console/binary/live_data.h +++ b/firmware/console/binary/live_data.h @@ -1,6 +1,6 @@ #pragma once -#include "FragmentEntry.h" +#include template const TStruct* getLiveDataAddr(); diff --git a/firmware/console/binary/tunerstudio.h b/firmware/console/binary/tunerstudio.h index a7b1d65fe2..d9b5e8b72b 100644 --- a/firmware/console/binary/tunerstudio.h +++ b/firmware/console/binary/tunerstudio.h @@ -8,7 +8,6 @@ #pragma once #include "global.h" #include "tunerstudio_io.h" -#include "FragmentEntry.h" typedef struct { int queryCommandCounter; diff --git a/firmware/console/binary/tunerstudio.mk b/firmware/console/binary/tunerstudio.mk index bcc035661e..45e7866d29 100644 --- a/firmware/console/binary/tunerstudio.mk +++ b/firmware/console/binary/tunerstudio.mk @@ -6,7 +6,6 @@ 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/libfirmware b/firmware/libfirmware index 7fea28f1c1..ba9e280fc4 160000 --- a/firmware/libfirmware +++ b/firmware/libfirmware @@ -1 +1 @@ -Subproject commit 7fea28f1c1b1fde209258e97824b8b16ef0ace19 +Subproject commit ba9e280fc477c577dda124981b52f6108ff43015 diff --git a/firmware/pch/pch.h b/firmware/pch/pch.h index 531404de21..c39c1cc3b2 100644 --- a/firmware/pch/pch.h +++ b/firmware/pch/pch.h @@ -19,6 +19,7 @@ #include #include +#include #include #include #include diff --git a/unit_tests/tests/test_scattered_outputs.cpp b/unit_tests/tests/test_scattered_outputs.cpp deleted file mode 100644 index d913c40b89..0000000000 --- a/unit_tests/tests/test_scattered_outputs.cpp +++ /dev/null @@ -1,89 +0,0 @@ -#include "pch.h" -#include "FragmentEntry.h" - -struct obj1 { - const uint8_t x[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; -}; - -static_assert(sizeof(obj1) == 10); - -struct obj2 { - const uint8_t x[5] = { 11, 12, 13, 14, 15 }; -}; - -static_assert(sizeof(obj2) == 5); - -obj1 buffer10; -obj2 buffer5; - -static FragmentEntry fragmentBuffer[] = { - &buffer10, - &buffer5, - reinterpret_cast(0), // null fragment for fun - &buffer10 -}; - -static uint8_t buffer[120]; -static void resetBuffer() { - memset(buffer, 0xFF, sizeof(buffer)); -} - -TEST(outputs, fragments) { - static_assert(4 == efi::size(fragmentBuffer)); - - FragmentList fragments{ fragmentBuffer, efi::size(fragmentBuffer) }; - - resetBuffer(); - - { - // Check overlap between first and second fragments - uint8_t expected[] = {9, 10, 11, 12, 13}; - copyRange(buffer, fragments, 8, 5); - EXPECT_TRUE( 0 == std::memcmp(buffer, expected, sizeof(expected))); - } - - resetBuffer(); - - { - // Check partial of only second fragment - uint8_t expected[] = {13, 14, 15}; - copyRange(buffer, fragments, 12, 3); - EXPECT_TRUE( 0 == std::memcmp(buffer, expected, sizeof(expected))); - } - - resetBuffer(); - - { - // Check overlap between second fragment and null fragment - uint8_t expected[] = {15, 0, 0}; - copyRange(buffer, fragments, 14, 3); - EXPECT_TRUE( 0 == std::memcmp(buffer, expected, sizeof(expected))); - } - - resetBuffer(); - - { - // Check overlap between null fragment and 4th fragment - uint8_t expected[] = {0, 1, 2}; - copyRange(buffer, fragments, 19, 3); - EXPECT_TRUE( 0 == std::memcmp(buffer, expected, sizeof(expected))); - } - - resetBuffer(); - - { - // Check overlap between last fragment and off-end of buffer (off-buffer should give 0s) - uint8_t expected[] = {9, 10, 0, 0}; - copyRange(buffer, fragments, 28, 4); - EXPECT_TRUE( 0 == std::memcmp(buffer, expected, sizeof(expected))); - } - - resetBuffer(); - - { - // Check way off the end of the buffer - uint8_t expected[] = {0, 0, 0}; - copyRange(buffer, fragments, 1000, 3); - EXPECT_TRUE( 0 == std::memcmp(buffer, expected, sizeof(expected))); - } -} diff --git a/unit_tests/tests/tests.mk b/unit_tests/tests/tests.mk index 72a6b2d106..a57b720264 100644 --- a/unit_tests/tests/tests.mk +++ b/unit_tests/tests/tests.mk @@ -50,7 +50,6 @@ TESTS_SRC_CPP = \ tests/test_dwell_corner_case_issue_796.cpp \ tests/test_idle_controller.cpp \ tests/test_issue_898.cpp \ - tests/test_scattered_outputs.cpp \ tests/test_launch.cpp \ tests/test_fuel_map.cpp \ tests/test_gear_detector.cpp \