From 8f2f8bc132d6748fcd4693941a671c24ed0afd34 Mon Sep 17 00:00:00 2001 From: rusefi Date: Thu, 6 Aug 2020 01:15:41 -0400 Subject: [PATCH] TS SD integration #1653 --- firmware/console/binary/tunerstudio.cpp | 23 ++----- firmware/console/binary/tunerstudio_io.h | 9 +-- firmware/console/binary/tunerstudio_outputs.h | 4 +- firmware/console/status_loop.cpp | 4 ++ firmware/hw_layer/mmc_card.h | 6 +- firmware/hw_layer/mmc_card_access.cpp | 67 ++++++++++++++++--- .../com/rusefi/ts_plugin/ConnectPanel.java | 12 +++- simulator/simulator/rusEfiFunctionalTest.cpp | 2 +- 8 files changed, 84 insertions(+), 43 deletions(-) diff --git a/firmware/console/binary/tunerstudio.cpp b/firmware/console/binary/tunerstudio.cpp index 93961c6972..51960ca963 100644 --- a/firmware/console/binary/tunerstudio.cpp +++ b/firmware/console/binary/tunerstudio.cpp @@ -202,7 +202,7 @@ static constexpr size_t getTunerStudioPageSize() { return TOTAL_CONFIG_SIZE; } -static void sendOkResponse(ts_channel_s *tsChannel, ts_response_format_e mode) { +void sendOkResponse(ts_channel_s *tsChannel, ts_response_format_e mode) { sr5SendResponse(tsChannel, mode, NULL, 0); } @@ -310,17 +310,6 @@ static bool validateOffsetCount(size_t offset, size_t count, ts_channel_s *tsCha return false; } -/** - * read log file content for rusEfi console - */ -static void handleReadFileContent(ts_channel_s *tsChannel, short fileId, uint16_t offset, uint16_t length) { -//#if EFI_FILE_LOGGING -// readLogFileContent(tsChannel->crcReadBuffer, fileId, offset, length); -//#else - UNUSED(tsChannel); UNUSED(fileId); UNUSED(offset); UNUSED(length); -//#endif /* EFI_FILE_LOGGING */ -} - /** * This command is needed to make the whole transfer a bit faster * @note See also handleWriteValueCommand @@ -458,7 +447,6 @@ static bool isKnownCommand(char command) { || command == TS_CHUNK_WRITE_COMMAND || command == TS_EXECUTE || command == TS_IO_TEST_COMMAND || command == TS_GET_STRUCT - || command == TS_GET_FILE_RANGE || command == TS_SET_LOGGER_SWITCH || command == TS_GET_LOGGER_GET_BUFFER || command == TS_GET_COMPOSITE_BUFFER_DONE_DIFFERENTLY @@ -762,12 +750,12 @@ int tunerStudioHandleCrcCommand(ts_channel_s *tsChannel, char *data, int incomin case TS_GET_FIRMWARE_VERSION: handleGetVersion(tsChannel, TS_CRC); break; -#if EFI_FILE_LOGGING +#if EFI_FILE_LOGGING || EFI_SIMULATOR case TS_SD_R_COMMAND: - handleTsR(data); + handleTsR(tsChannel, data); break; case TS_SD_W_COMMAND: - handleTsW(data); + handleTsW(tsChannel, data); break; #endif //EFI_FILE_LOGGING case TS_GET_TEXT: @@ -782,9 +770,6 @@ int tunerStudioHandleCrcCommand(ts_channel_s *tsChannel, char *data, int incomin case TS_GET_STRUCT: handleGetStructContent(tsChannel, data16[0], data16[1]); break; - case TS_GET_FILE_RANGE: - handleReadFileContent(tsChannel, data16[0], data16[1], data16[2]); - break; case TS_CHUNK_WRITE_COMMAND: handleWriteChunkCommand(tsChannel, TS_CRC, data16[1], data16[2], data + sizeof(TunerStudioWriteChunkRequest)); break; diff --git a/firmware/console/binary/tunerstudio_io.h b/firmware/console/binary/tunerstudio_io.h index 613c2ae33d..27776c5616 100644 --- a/firmware/console/binary/tunerstudio_io.h +++ b/firmware/console/binary/tunerstudio_io.h @@ -35,14 +35,6 @@ struct ts_channel_s { #endif // TS_UART_DMA_MODE }; -// These commands are used exclusively by the rusEfi console -#define TS_GET_FILE_RANGE '2' // 0x32 - - -// many commands are now defined in rusefi_config.txt see TS_* constants -// this way we reuse between firmware and java code - - #define CRC_VALUE_SIZE 4 // todo: double-check this #define CRC_WRAPPING_SIZE (CRC_VALUE_SIZE + 3) @@ -63,6 +55,7 @@ bool stopTsPort(ts_channel_s *tsChannel); void sr5WriteData(ts_channel_s *tsChannel, const uint8_t * buffer, int size); void sr5WriteCrcPacket(ts_channel_s *tsChannel, const uint8_t responseCode, const void *buf, const uint16_t size); void sr5SendResponse(ts_channel_s *tsChannel, ts_response_format_e mode, const uint8_t * buffer, int size); +void sendOkResponse(ts_channel_s *tsChannel, ts_response_format_e mode); int sr5ReadData(ts_channel_s *tsChannel, uint8_t * buffer, int size); int sr5ReadDataTimeout(ts_channel_s *tsChannel, uint8_t * buffer, int size, int timeout); bool sr5IsReady(ts_channel_s *tsChannel); diff --git a/firmware/console/binary/tunerstudio_outputs.h b/firmware/console/binary/tunerstudio_outputs.h index 7865f6df6c..1ddb2fc71c 100644 --- a/firmware/console/binary/tunerstudio_outputs.h +++ b/firmware/console/binary/tunerstudio_outputs.h @@ -225,7 +225,9 @@ typedef struct { scaled_voltage rawOilPressure; // 242 int16_t tuneCrc16; // 244 - uint8_t unusedAtTheEnd[42]; // we have some unused bytes to allow compatible TS changes + uint8_t sd_status; // 246 + + uint8_t unusedAtTheEnd[41]; // we have some unused bytes to allow compatible TS changes // Temporary - will remove soon TsDebugChannels* getDebugChannels() { diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index 4b31b16f22..a085b1cb32 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -474,6 +474,10 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_ executorStatistics(); #endif /* EFI_PROD_CODE */ +#if EFI_SIMULATOR + tsOutputChannels->sd_status = 1 + 4; +#endif + // header tsOutputChannels->tsConfigVersion = TS_FILE_VERSION; diff --git a/firmware/hw_layer/mmc_card.h b/firmware/hw_layer/mmc_card.h index c2aa434db3..ba9487abf7 100644 --- a/firmware/hw_layer/mmc_card.h +++ b/firmware/hw_layer/mmc_card.h @@ -9,11 +9,13 @@ #pragma once +#include "tunerstudio_io.h" + void initMmcCard(void); bool isSdCardAlive(void); void appendToLog(const char *line, size_t length); void readLogFileContent(char *buffer, short fileId, short offset, short length); -void handleTsR(char *input); -void handleTsW(char *input); +void handleTsR(ts_channel_s *tsChannel, char *input); +void handleTsW(ts_channel_s *tsChannel, char *input); diff --git a/firmware/hw_layer/mmc_card_access.cpp b/firmware/hw_layer/mmc_card_access.cpp index 571671be48..9eb29e29de 100644 --- a/firmware/hw_layer/mmc_card_access.cpp +++ b/firmware/hw_layer/mmc_card_access.cpp @@ -5,50 +5,95 @@ #include "global.h" -#if EFI_FILE_LOGGING +#if EFI_FILE_LOGGING || EFI_SIMULATOR #include "mmc_card.h" extern LoggingWithStorage sharedLogger; -static char *buffer[2048]; +#define TRANSFER_SIZE 2048 +static uint8_t buffer[TRANSFER_SIZE + 2]; -void handleTsR(char *input) { +static void setFileEntry(uint8_t *buffer, int index, const char *fileName, int fileSize) { + int offset = 32 * index; + memcpy(buffer + offset, fileName, 11); + buffer[offset + 11] = 1; + + *(uint32_t *) (&buffer[offset + 28]) = fileSize; +} + +void handleTsR(ts_channel_s *tsChannel, char *input) { const uint16_t* data16 = reinterpret_cast(input); - if (input[0] == 0 && input[1] == 1) { + if (input[0] == 0 && input[1] == TS_SD_PROTOCOL_RTC) { scheduleMsg(&sharedLogger, "TS_SD: RTC read command"); memset(buffer, 0, 9); + sr5SendResponse(tsChannel, TS_CRC, buffer, 9); - } else if (input[0] == 0 && input[1] == 0x11) { + } else if (input[0] == 0 && input[1] == TS_SD_PROTOCOL_FETCH_INFO) { int length = data16[2]; scheduleMsg(&sharedLogger, "TS_SD: fetch buffer command, length=%d", length); if (length == 16) { + buffer[0] = 1 + 4; // Card present + Ready + buffer[1] = 0; // Y - error code - } else { + buffer[2] = 2; // higher byte of '512' sector size + buffer[3] = 0; // lower byte + + buffer[4] = 0; + buffer[5] = 0x20; // 0x20 00 00 of 512 is 1G virtual card + buffer[6] = 0; + buffer[7] = 0; + + buffer[8] = 0; + buffer[9] = 1; // number of files + + sr5SendResponse(tsChannel, TS_CRC, buffer, 16); + } else if (length == 0x202) { // SD read directory command + memset(buffer, 0, 512); + +#if EFI_SIMULATOR + + setFileEntry(buffer, 0, "hello123.msq", 123123); + setFileEntry(buffer, 1, "hello222.msq", 123123); + +#endif // EFI_SIMULATOR + sr5SendResponse(tsChannel, TS_CRC, buffer, 0x202); } + } else if (input[0] == 0 && input[1] == TS_SD_PROTOCOL_FETCH_DATA) { + int blockNumber = data16[1]; + scheduleMsg(&sharedLogger, "TS_SD: fetch data command blockNumber=%d", blockNumber); - - } else if (input[0] == 0 && input[1] == 0x14) { - scheduleMsg(&sharedLogger, "TS_SD: fetch data command blockNumber="); + int offset = blockNumber * TRANSFER_SIZE; } else { scheduleMsg(&sharedLogger, "TS_SD: unexpected r"); } } -void handleTsW(char *input) { +void handleTsW(ts_channel_s *tsChannel, char *input) { const uint16_t* data16 = reinterpret_cast(input); - if (input[0] == 0 && input[1] == 0x11) { + if (input[0] == 0 && input[1] == TS_SD_PROTOCOL_FETCH_INFO) { int code = data16[2]; scheduleMsg(&sharedLogger, "TS_SD: w, code=%d", code); + if (input[5] == TS_SD_PROTOCOL_DO) { + sendOkResponse(tsChannel, TS_CRC); + } else if (input[5] == TS_SD_PROTOCOL_READ_DIR) { + sendOkResponse(tsChannel, TS_CRC); + } else if (input[5] == TS_SD_PROTOCOL_REMOVE_FILE) { + // todo + + } else if (input[5] == TS_SD_PROTOCOL_FETCH_COMPRESSED) { + } + + } else { scheduleMsg(&sharedLogger, "TS_SD: unexpected w"); } diff --git a/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/ConnectPanel.java b/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/ConnectPanel.java index 5107a3c756..67b1378c9f 100644 --- a/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/ConnectPanel.java +++ b/java_tools/ts_plugin/src/main/java/com/rusefi/ts_plugin/ConnectPanel.java @@ -1,5 +1,6 @@ package com.rusefi.ts_plugin; +import com.rusefi.autoupdate.AutoupdateUtil; import com.rusefi.config.generated.Fields; import com.rusefi.io.ConnectionStateListener; import com.rusefi.io.IoStream; @@ -35,7 +36,8 @@ public class ConnectPanel { .setCompositeLogicEnabled(false) .setNeedPullData(false); - controllerConnector.startAndConnect(":2390", ConnectionStateListener.VOID); + //controllerConnector.startAndConnect(":2390", ConnectionStateListener.VOID); + controllerConnector.startAndConnect(":29001", ConnectionStateListener.VOID); } }); @@ -86,6 +88,8 @@ public class ConnectPanel { for (int fileIndex = 0; fileIndex < 512 / 32; fileIndex++) { int offset = 32 * fileIndex; String fileNamePart = new String(response, 1 + offset, 8).trim(); + if (fileNamePart.trim().isEmpty()) + break; String fileExt = new String(response, 1 + offset + 8, 3).trim(); String fileName = fileNamePart + "." + fileExt; @@ -118,7 +122,12 @@ public class ConnectPanel { }); filePanel.add(delete); + fileList.add(filePanel); + System.out.println("Filename " + fileName + " size " + size); + + + AutoupdateUtil.trueLayout(fileList.getParent()); } } catch (IOException ioException) { @@ -127,6 +136,7 @@ public class ConnectPanel { } }); + flow.add(connect); flow.add(poke); diff --git a/simulator/simulator/rusEfiFunctionalTest.cpp b/simulator/simulator/rusEfiFunctionalTest.cpp index 71681347a8..a661af8421 100644 --- a/simulator/simulator/rusEfiFunctionalTest.cpp +++ b/simulator/simulator/rusEfiFunctionalTest.cpp @@ -37,7 +37,7 @@ EXTERN_ENGINE; extern WaveChart waveChart; -static LoggingWithStorage sharedLogger("simulator"); +LoggingWithStorage sharedLogger("simulator"); int getRemainingStack(thread_t *otp) { return 99999;