TS SD integration #1653
This commit is contained in:
parent
580af0c1e6
commit
8764693179
|
@ -8,6 +8,9 @@
|
|||
#if EFI_SIMULATOR
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
#define DIR_RESPONSE_SIZE 512
|
||||
|
@ -37,7 +40,6 @@ bool isLogFile(const char *fileName) {
|
|||
|
||||
#endif
|
||||
|
||||
|
||||
#if EFI_FILE_LOGGING || EFI_SIMULATOR
|
||||
#include "mmc_card.h"
|
||||
|
||||
|
@ -60,10 +62,18 @@ static void setFileEntry(uint8_t *buffer, int index, const char *fileName, int f
|
|||
|
||||
buffer[offset + 11] = 1;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
buffer[offset + 18 + i] = fileName[dotIndex + i - 4];
|
||||
}
|
||||
|
||||
*(uint32_t *) (&buffer[offset + 28]) = fileSize;
|
||||
}
|
||||
|
||||
void handleTsR(ts_channel_s *tsChannel, char *input) {
|
||||
#if EFI_SIMULATOR
|
||||
printf("TS_SD r %d\n", input[1]);
|
||||
#endif // EFI_SIMULATOR
|
||||
|
||||
const uint16_t* data16 = reinterpret_cast<uint16_t*>(input);
|
||||
|
||||
if (input[0] == 0 && input[1] == TS_SD_PROTOCOL_RTC) {
|
||||
|
@ -72,7 +82,7 @@ void handleTsR(ts_channel_s *tsChannel, char *input) {
|
|||
sr5SendResponse(tsChannel, TS_CRC, buffer, 9);
|
||||
|
||||
} else if (input[0] == 0 && input[1] == TS_SD_PROTOCOL_FETCH_INFO) {
|
||||
int length = data16[2];
|
||||
uint16_t length = SWAP_UINT16(data16[2]);
|
||||
scheduleMsg(&sharedLogger, "TS_SD: fetch buffer command, length=%d", length);
|
||||
|
||||
|
||||
|
@ -109,21 +119,28 @@ void handleTsR(ts_channel_s *tsChannel, char *input) {
|
|||
int index = 0;
|
||||
struct dirent *de; // Pointer for directory entry
|
||||
while ((de = readdir(dr)) != NULL) {
|
||||
printf("%s\n", de->d_name);
|
||||
const char * fileName = de->d_name;
|
||||
printf("%s\n", fileName);
|
||||
if (index >= DIR_RESPONSE_SIZE / 32) {
|
||||
break;
|
||||
}
|
||||
if (isLogFile(de->d_name)) {
|
||||
setFileEntry(buffer, index, de->d_name, 239);
|
||||
if (isLogFile(fileName)) {
|
||||
struct stat statBuffer;
|
||||
int status;
|
||||
|
||||
int fileSize = 0;
|
||||
status = stat(fileName, &statBuffer);
|
||||
if (status == 0) {
|
||||
fileSize = statBuffer.st_size;
|
||||
}
|
||||
|
||||
setFileEntry(buffer, index, fileName, fileSize);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
closedir(dr);
|
||||
|
||||
// setFileEntry(buffer, 0, "hello123.msq", 123123);
|
||||
// setFileEntry(buffer, 1, "hello222.msq", 123123);
|
||||
|
||||
#endif // EFI_SIMULATOR
|
||||
sr5SendResponse(tsChannel, TS_CRC, buffer, 0x202);
|
||||
}
|
||||
|
@ -141,20 +158,74 @@ void handleTsR(ts_channel_s *tsChannel, char *input) {
|
|||
void handleTsW(ts_channel_s *tsChannel, char *input) {
|
||||
const uint16_t* data16 = reinterpret_cast<uint16_t*>(input);
|
||||
|
||||
#if EFI_SIMULATOR
|
||||
printf("TS_SD w %d\n", input[1]);
|
||||
#endif // EFI_SIMULATOR
|
||||
|
||||
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) {
|
||||
scheduleMsg(&sharedLogger, "TS_SD_PROTOCOL_DO");
|
||||
sendOkResponse(tsChannel, TS_CRC);
|
||||
} else if (input[5] == TS_SD_PROTOCOL_READ_DIR) {
|
||||
scheduleMsg(&sharedLogger, "TS_SD_PROTOCOL_READ_DIR");
|
||||
sendOkResponse(tsChannel, TS_CRC);
|
||||
} else if (input[5] == TS_SD_PROTOCOL_REMOVE_FILE) {
|
||||
// todo
|
||||
#if EFI_SIMULATOR
|
||||
DIR *dr = opendir(".");
|
||||
|
||||
if (dr == NULL) {
|
||||
// opendir returns NULL if couldn't open directory
|
||||
printf("Could not open current directory" );
|
||||
return;
|
||||
}
|
||||
|
||||
struct dirent *de; // Pointer for directory entry
|
||||
while ((de = readdir(dr)) != NULL) {
|
||||
const char * fileName = de->d_name;
|
||||
printf("%s\n", fileName);
|
||||
if (isLogFile(fileName)) {
|
||||
int dotIndex = indexOf(fileName, DOT);
|
||||
if (0 == strncmp(input + 6, &fileName[dotIndex - 4], 4)) {
|
||||
printf("Removing %s\n", fileName);
|
||||
remove(fileName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dr);
|
||||
|
||||
#endif // EFI_SIMULATOR
|
||||
sendOkResponse(tsChannel, TS_CRC);
|
||||
|
||||
} else if (input[5] == TS_SD_PROTOCOL_FETCH_COMPRESSED) {
|
||||
}
|
||||
#if EFI_SIMULATOR
|
||||
DIR *dr = opendir(".");
|
||||
|
||||
if (dr == NULL) {
|
||||
// opendir returns NULL if couldn't open directory
|
||||
printf("Could not open current directory" );
|
||||
return;
|
||||
}
|
||||
|
||||
struct dirent *de; // Pointer for directory entry
|
||||
while ((de = readdir(dr)) != NULL) {
|
||||
const char * fileName = de->d_name;
|
||||
printf("%s\n", fileName);
|
||||
if (isLogFile(fileName)) {
|
||||
int dotIndex = indexOf(fileName, DOT);
|
||||
if (0 == strncmp(input + 6, &fileName[dotIndex - 4], 4)) {
|
||||
printf("Will be uploading %s\n", fileName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir(dr);
|
||||
#endif // EFI_SIMULATOR
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include "global.h"
|
||||
#include "efilib.h"
|
||||
|
||||
#if EFI_UNIT_TEST
|
||||
#if EFI_UNIT_TEST || EFI_SIMULATOR
|
||||
extern bool verboseMode;
|
||||
#endif /* EFI_UNIT_TEST */
|
||||
|
||||
|
@ -148,7 +148,7 @@ char * swapOutputBuffers(int *actualOutputBufferSize) {
|
|||
* this is really 'global lock + printf + scheduleLogging + unlock' a bit more clear
|
||||
*/
|
||||
void scheduleMsg(Logging *logging, const char *format, ...) {
|
||||
#if EFI_UNIT_TEST
|
||||
#if EFI_UNIT_TEST || EFI_SIMULATOR
|
||||
if (verboseMode) {
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
|
|
|
@ -20,6 +20,7 @@ import static com.rusefi.config.generated.Fields.TS_SD_PROTOCOL_FETCH_INFO;
|
|||
public class ConnectPanel {
|
||||
private final JPanel content = new JPanel(new BorderLayout());
|
||||
private final JPanel fileList = new JPanel(new VerticalFlowLayout());
|
||||
private final JLabel status = new JLabel();
|
||||
|
||||
private LinkManager controllerConnector;
|
||||
|
||||
|
@ -31,117 +32,129 @@ public class ConnectPanel {
|
|||
connect.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
connect.setEnabled(false);
|
||||
|
||||
controllerConnector = new LinkManager()
|
||||
.setCompositeLogicEnabled(false)
|
||||
.setNeedPullData(false);
|
||||
|
||||
//controllerConnector.startAndConnect(":2390", ConnectionStateListener.VOID);
|
||||
controllerConnector.startAndConnect(":29001", ConnectionStateListener.VOID);
|
||||
controllerConnector.startAndConnect(":29001", new ConnectionStateListener() {
|
||||
public void onConnectionEstablished() {
|
||||
status.setText("Connected to rusEFI");
|
||||
requestFileList();
|
||||
}
|
||||
|
||||
public void onConnectionFailed() {
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
JButton poke = new JButton("poke");
|
||||
poke.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
byte[] packet;
|
||||
byte[] response;
|
||||
IoStream stream = controllerConnector.getConnector().getBinaryProtocol().getStream();
|
||||
|
||||
packet = new byte[3];
|
||||
packet[0] = Fields.TS_SD_R_COMMAND;
|
||||
packet[2] = Fields.TS_SD_PROTOCOL_RTC;
|
||||
stream.sendPacket(packet);
|
||||
response = stream.getDataBuffer().getPacket("RTC status");
|
||||
System.out.println("RTC response " + IoStream.printHexBinary(response));
|
||||
if (response == null)
|
||||
throw new IOException("RTC No packet");
|
||||
|
||||
packet = new byte[17];
|
||||
packet[0] = Fields.TS_SD_W_COMMAND;
|
||||
packet[2] = TS_SD_PROTOCOL_FETCH_INFO;
|
||||
packet[6] = Fields.TS_SD_PROTOCOL_READ_DIR;
|
||||
stream.sendPacket(packet);
|
||||
response = stream.getDataBuffer().getPacket("read dir command");
|
||||
if (response == null)
|
||||
throw new IOException("Read Dir No packet");
|
||||
System.out.println("read dir command " + IoStream.printHexBinary(response));
|
||||
|
||||
packet = new byte[8];
|
||||
packet[0] = Fields.TS_SD_R_COMMAND;
|
||||
packet[1] = 0;
|
||||
packet[2] = TS_SD_PROTOCOL_FETCH_INFO;
|
||||
packet[5] = 0x02;
|
||||
packet[6] = 0x02;
|
||||
stream.sendPacket(packet);
|
||||
response = stream.getDataBuffer().getPacket("read command", true);
|
||||
if (response == null)
|
||||
throw new IOException("No packet");
|
||||
System.out.println("read command " + IoStream.printHexBinary(response));
|
||||
|
||||
fileList.removeAll();
|
||||
|
||||
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;
|
||||
|
||||
ByteBuffer bb = ByteBuffer.wrap(response, 1 + offset + 28, 4);
|
||||
bb.order(ByteOrder.LITTLE_ENDIAN);
|
||||
int size = bb.getInt();
|
||||
|
||||
JPanel filePanel = new JPanel(new FlowLayout());
|
||||
|
||||
|
||||
filePanel.add(new JLabel(fileName + " " + size + " byte(s)"));
|
||||
|
||||
JButton download = new JButton("Download");
|
||||
download.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
filePanel.add(download);
|
||||
JButton delete = new JButton("Delete");
|
||||
delete.addActionListener(e1 -> {
|
||||
int result = JOptionPane.showConfirmDialog(null, "Are you sure you want to remove " + fileName,
|
||||
"rusEfi", JOptionPane.YES_NO_OPTION);
|
||||
if (result == JOptionPane.YES_OPTION) {
|
||||
deleteFile(fileName);
|
||||
|
||||
}
|
||||
});
|
||||
filePanel.add(delete);
|
||||
|
||||
fileList.add(filePanel);
|
||||
|
||||
System.out.println("Filename " + fileName + " size " + size);
|
||||
|
||||
|
||||
AutoupdateUtil.trueLayout(content.getParent());
|
||||
}
|
||||
|
||||
} catch (IOException ioException) {
|
||||
ioException.printStackTrace();
|
||||
}
|
||||
requestFileList();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
flow.add(connect);
|
||||
flow.add(poke);
|
||||
|
||||
content.add(flow, BorderLayout.NORTH);
|
||||
content.add(fileList, BorderLayout.CENTER);
|
||||
content.add(status, BorderLayout.SOUTH);
|
||||
}
|
||||
|
||||
private void requestFileList() {
|
||||
try {
|
||||
byte[] packet;
|
||||
byte[] response;
|
||||
IoStream stream = controllerConnector.getConnector().getBinaryProtocol().getStream();
|
||||
|
||||
packet = new byte[3];
|
||||
packet[0] = Fields.TS_SD_R_COMMAND;
|
||||
packet[2] = Fields.TS_SD_PROTOCOL_RTC;
|
||||
stream.sendPacket(packet);
|
||||
response = stream.getDataBuffer().getPacket("RTC status");
|
||||
System.out.println("RTC response " + IoStream.printHexBinary(response));
|
||||
if (response == null)
|
||||
throw new IOException("RTC No packet");
|
||||
|
||||
packet = new byte[17];
|
||||
packet[0] = Fields.TS_SD_W_COMMAND;
|
||||
packet[2] = TS_SD_PROTOCOL_FETCH_INFO;
|
||||
packet[6] = Fields.TS_SD_PROTOCOL_READ_DIR;
|
||||
stream.sendPacket(packet);
|
||||
response = stream.getDataBuffer().getPacket("read dir command");
|
||||
if (response == null)
|
||||
throw new IOException("Read Dir No packet");
|
||||
System.out.println("read dir command " + IoStream.printHexBinary(response));
|
||||
|
||||
packet = new byte[8];
|
||||
packet[0] = Fields.TS_SD_R_COMMAND;
|
||||
packet[1] = 0;
|
||||
packet[2] = TS_SD_PROTOCOL_FETCH_INFO;
|
||||
packet[5] = 0x02;
|
||||
packet[6] = 0x02;
|
||||
stream.sendPacket(packet);
|
||||
response = stream.getDataBuffer().getPacket("read command", true);
|
||||
if (response == null)
|
||||
throw new IOException("No packet");
|
||||
System.out.println("read command " + IoStream.printHexBinary(response));
|
||||
|
||||
fileList.removeAll();
|
||||
|
||||
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;
|
||||
|
||||
ByteBuffer bb = ByteBuffer.wrap(response, 1 + offset + 28, 4);
|
||||
bb.order(ByteOrder.LITTLE_ENDIAN);
|
||||
int size = bb.getInt();
|
||||
|
||||
JPanel filePanel = new JPanel(new FlowLayout());
|
||||
|
||||
filePanel.add(new JLabel(fileName + " " + size + " byte(s)"));
|
||||
|
||||
JButton download = new JButton("Download");
|
||||
download.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
downloadFile(fileName);
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
filePanel.add(download);
|
||||
JButton delete = new JButton("Delete");
|
||||
delete.addActionListener(e1 -> {
|
||||
int result = JOptionPane.showConfirmDialog(null, "Are you sure you want to remove " + fileName,
|
||||
"rusEfi", JOptionPane.YES_NO_OPTION);
|
||||
if (result == JOptionPane.YES_OPTION) {
|
||||
deleteFile(fileName);
|
||||
requestFileList();
|
||||
}
|
||||
});
|
||||
filePanel.add(delete);
|
||||
|
||||
fileList.add(filePanel);
|
||||
|
||||
System.out.println("Filename " + fileName + " size " + size);
|
||||
|
||||
AutoupdateUtil.trueLayout(content.getParent());
|
||||
}
|
||||
|
||||
} catch (IOException ioException) {
|
||||
ioException.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getLastFour(String fileName) {
|
||||
|
@ -152,13 +165,21 @@ public class ConnectPanel {
|
|||
return fileName.substring(fileName.length() - 4);
|
||||
}
|
||||
|
||||
private void downloadFile(String fileName) {
|
||||
fileName = ConnectPanel.getLastFour(fileName);
|
||||
|
||||
}
|
||||
|
||||
private void deleteFile(String fileName) {
|
||||
fileName = ConnectPanel.getLastFour(fileName);
|
||||
|
||||
byte[] packet = new byte[17];
|
||||
packet[0] = Fields.TS_SD_W_COMMAND;
|
||||
packet[2] = TS_SD_PROTOCOL_FETCH_INFO;
|
||||
packet[6] = Fields.TS_SD_PROTOCOL_READ_DIR;
|
||||
packet[6] = Fields.TS_SD_PROTOCOL_REMOVE_FILE;
|
||||
for (int i = 0; i < 4; i++)
|
||||
packet[7 + i] = (byte) fileName.charAt(i);
|
||||
|
||||
IoStream stream = controllerConnector.getConnector().getBinaryProtocol().getStream();
|
||||
|
||||
try {
|
||||
|
|
Binary file not shown.
|
@ -130,6 +130,8 @@ static void sd2_handler(eventid_t id) {
|
|||
|
||||
static evhandler_t fhandlers[] = { termination_handler, sd1_handler, sd2_handler };
|
||||
|
||||
bool verboseMode = true;
|
||||
|
||||
/*------------------------------------------------------------------------*
|
||||
* Simulator main. *
|
||||
*------------------------------------------------------------------------*/
|
||||
|
|
Loading…
Reference in New Issue