From 526e02af53a15111322ae0270d4e3fb17911667e Mon Sep 17 00:00:00 2001 From: rusefi Date: Thu, 6 Aug 2020 22:05:26 -0400 Subject: [PATCH] TS SD integration #1653 --- firmware/console/binary/tunerstudio_io.h | 2 ++ firmware/hw_layer/mmc_card.cpp | 2 -- firmware/hw_layer/mmc_card.h | 3 +++ firmware/hw_layer/mmc_card_access.cpp | 22 +++++++++++++++++++ firmware/util/efilib.cpp | 2 +- .../rusefi/io/tcp/BinaryProtocolServer.java | 6 +++++ unit_tests/tests/test_util.cpp | 9 +++++++- 7 files changed, 42 insertions(+), 4 deletions(-) diff --git a/firmware/console/binary/tunerstudio_io.h b/firmware/console/binary/tunerstudio_io.h index 27776c5616..c120ee31b5 100644 --- a/firmware/console/binary/tunerstudio_io.h +++ b/firmware/console/binary/tunerstudio_io.h @@ -23,7 +23,9 @@ typedef enum { } ts_response_format_e; struct ts_channel_s { +#if ! EFI_UNIT_TEST BaseChannel * channel = nullptr; +#endif uint8_t writeBuffer[7]; // size(2 bytes) + response(1 byte) + crc32 (4 bytes) /** * See 'blockingFactor' in rusefi.ini diff --git a/firmware/hw_layer/mmc_card.cpp b/firmware/hw_layer/mmc_card.cpp index 6989bc3e6a..b8898be5cf 100644 --- a/firmware/hw_layer/mmc_card.cpp +++ b/firmware/hw_layer/mmc_card.cpp @@ -52,8 +52,6 @@ static int totalSyncCounter = 0; #define LOG_INDEX_FILENAME "index.txt" -#define DOT_MLG ".mlg" - #define RUSEFI_LOG_PREFIX "re_" #define PREFIX_LEN 3 #define SHORT_TIME_LEN 13 diff --git a/firmware/hw_layer/mmc_card.h b/firmware/hw_layer/mmc_card.h index ba9487abf7..3281438577 100644 --- a/firmware/hw_layer/mmc_card.h +++ b/firmware/hw_layer/mmc_card.h @@ -11,6 +11,9 @@ #include "tunerstudio_io.h" +#define DOT_MLG ".mlg" + +bool isLogFile(const char *fileName); void initMmcCard(void); bool isSdCardAlive(void); void appendToLog(const char *line, size_t length); diff --git a/firmware/hw_layer/mmc_card_access.cpp b/firmware/hw_layer/mmc_card_access.cpp index 9eb29e29de..fb7215f997 100644 --- a/firmware/hw_layer/mmc_card_access.cpp +++ b/firmware/hw_layer/mmc_card_access.cpp @@ -5,6 +5,28 @@ #include "global.h" +#if EFI_FILE_LOGGING || EFI_SIMULATOR || EFI_UNIT_TEST + +#include "mmc_card.h" +#include "efilib.h" + +/** + * for funny reasons file name has to be at least 4 symbols before the dot + */ +bool isLogFile(const char *fileName) { + int dotIndex = indexOf(fileName, '.'); + if (dotIndex == -1) { + return false; + } + if (dotIndex < 4) { + return false; + } + return 0 == strncmp(fileName + dotIndex, DOT_MLG, 4); +} + +#endif + + #if EFI_FILE_LOGGING || EFI_SIMULATOR #include "mmc_card.h" diff --git a/firmware/util/efilib.cpp b/firmware/util/efilib.cpp index f50ae7cb5a..8e0a0f313d 100644 --- a/firmware/util/efilib.cpp +++ b/firmware/util/efilib.cpp @@ -96,7 +96,7 @@ bool startsWith(const char *line, const char *prefix) { } int indexOf(const char *string, char ch) { - // todo: there should be a standard function for this + // a standard function for this is strnchr? // todo: on the other hand MISRA wants us not to use standard headers int len = efiStrlen(string); for (int i = 0; i < len; i++) { diff --git a/java_console/io/src/main/java/com/rusefi/io/tcp/BinaryProtocolServer.java b/java_console/io/src/main/java/com/rusefi/io/tcp/BinaryProtocolServer.java index 3b361458ba..059765a198 100644 --- a/java_console/io/src/main/java/com/rusefi/io/tcp/BinaryProtocolServer.java +++ b/java_console/io/src/main/java/com/rusefi/io/tcp/BinaryProtocolServer.java @@ -327,6 +327,12 @@ public class BinaryProtocolServer implements BinaryProtocolCommands { response[offset + 11] = 1; // file // 12-15 = undefined + response[offset + 14] = 0x11; + response[offset + 15] = 0x13; // time + + response[offset + 16] = 0x24; + response[offset + 17] = 0x25; // 0x2425 = FAT16 date format September 4, 1998 + for (int i = 18; i < 22; i++) response[offset + i] = (byte) (i + 10 * index); // sector number diff --git a/unit_tests/tests/test_util.cpp b/unit_tests/tests/test_util.cpp index 379d1c5690..e13f8f7b9b 100644 --- a/unit_tests/tests/test_util.cpp +++ b/unit_tests/tests/test_util.cpp @@ -17,7 +17,7 @@ #include "engine_controller.h" #include "nmea.h" - +#include "mmc_card.h" #include "lcd_menu_tree.h" #include "crc.h" #include "fl_stack.h" @@ -28,6 +28,13 @@ #include "gtest/gtest.h" +TEST(util, isLogFileName) { + ASSERT_FALSE(isLogFile("aaaa")); + ASSERT_FALSE(isLogFile("aaa.mlq")); + ASSERT_TRUE (isLogFile("aaaa.mlg")); + ASSERT_FALSE(isLogFile("aaaa.aaa")); +} + TEST(util, negativeZero) { ASSERT_TRUE(IS_NEGATIVE_ZERO(-0.0));