TS SD integration #1653
This commit is contained in:
parent
2531ba7ca6
commit
ea7fed6a16
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<uint16_t*>(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<uint16_t*>(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");
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ EXTERN_ENGINE;
|
|||
|
||||
extern WaveChart waveChart;
|
||||
|
||||
static LoggingWithStorage sharedLogger("simulator");
|
||||
LoggingWithStorage sharedLogger("simulator");
|
||||
|
||||
int getRemainingStack(thread_t *otp) {
|
||||
return 99999;
|
||||
|
|
Loading…
Reference in New Issue