TS SD integration #1653
This commit is contained in:
parent
9774c74f42
commit
8bd4b94807
|
@ -28,6 +28,8 @@ public interface IoStream extends WriteStream, Closeable, StreamStatistics {
|
|||
Logging log = getLogging(IoStream.class);
|
||||
|
||||
static String printHexBinary(byte[] data) {
|
||||
if (data == null)
|
||||
return "(null)";
|
||||
char[] hexCode = "0123456789ABCDEF".toCharArray();
|
||||
|
||||
StringBuilder r = new StringBuilder(data.length * 2);
|
||||
|
|
|
@ -219,13 +219,13 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
|
|||
if (payload[6] == 1) {
|
||||
log.info("TS_SD: do command, command=" + payload[payload.length - 1]);
|
||||
sendOkResponse(stream);
|
||||
} else if (payload[6] == 2) {
|
||||
} else if (payload[6] == TS_SD_PROTOCOL_READ_DIR) {
|
||||
log.info("TS_SD: read directory command " + payload[payload.length - 1]);
|
||||
sendOkResponse(stream);
|
||||
} else if (payload[6] == 6) {
|
||||
} else if (payload[6] == TS_SD_PROTOCOL_REMOVE_FILE) {
|
||||
log.info("TS_SD: remove file command " + Arrays.toString(packet.packet));
|
||||
sendOkResponse(stream);
|
||||
} else if (payload[6] == 8) {
|
||||
} else if (payload[6] == TS_SD_PROTOCOL_FETCH_COMPRESSED) {
|
||||
log.info("TS_SD: read compressed file command " + Arrays.toString(packet.packet));
|
||||
ByteBuffer bb = ByteBuffer.wrap(payload, 7, 8);
|
||||
bb.order(ByteOrder.BIG_ENDIAN);
|
||||
|
@ -241,7 +241,7 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
|
|||
|
||||
private void handleSD_R_command(TcpIoStream stream, Packet packet, byte[] payload) throws IOException {
|
||||
log.info("TS_SD: 'r' " + IoStream.printHexBinary(packet.packet));
|
||||
if (payload[1] == 0 && payload[2] == 7) {
|
||||
if (payload[1] == 0 && payload[2] == TS_SD_PROTOCOL_RTC) {
|
||||
log.info("TS_SD: RTC read command");
|
||||
byte[] response = new byte[9];
|
||||
stream.sendPacket(response);
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
package com.rusefi.ts_plugin;
|
||||
|
||||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.io.ConnectionStateListener;
|
||||
import com.rusefi.io.IoStream;
|
||||
import com.rusefi.io.LinkManager;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ConnectPanel {
|
||||
private final JPanel content = new JPanel(new BorderLayout());
|
||||
|
||||
private LinkManager controllerConnector;
|
||||
|
||||
public ConnectPanel() {
|
||||
JPanel flow = new JPanel(new FlowLayout());
|
||||
|
||||
|
||||
JButton connect = new JButton("Connect");
|
||||
connect.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
controllerConnector = new LinkManager()
|
||||
.setCompositeLogicEnabled(false)
|
||||
.setNeedPullData(false);
|
||||
|
||||
controllerConnector.startAndConnect(":2390", ConnectionStateListener.VOID);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
JButton poke = new JButton("poke");
|
||||
poke.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
byte[] packet;
|
||||
byte[] response;
|
||||
|
||||
packet = new byte[3];
|
||||
packet[0] = Fields.TS_SD_R_COMMAND;
|
||||
packet[2] = Fields.TS_SD_PROTOCOL_RTC;
|
||||
IoStream stream = controllerConnector.getConnector().getBinaryProtocol().getStream();
|
||||
|
||||
stream.sendPacket(packet);
|
||||
|
||||
response = stream.getDataBuffer().getPacket("RTC status");
|
||||
System.out.println("RTC response " + IoStream.printHexBinary(response));
|
||||
|
||||
|
||||
packet = new byte[17];
|
||||
packet[0] = Fields.TS_SD_W_COMMAND;
|
||||
packet[7] = Fields.TS_SD_PROTOCOL_READ_DIR;
|
||||
response = stream.getDataBuffer().getPacket("read dir command");
|
||||
System.out.println("read dir command " + IoStream.printHexBinary(response));
|
||||
|
||||
|
||||
packet = new byte[17];
|
||||
packet[0] = Fields.TS_SD_R_COMMAND;
|
||||
packet[1] = 0;
|
||||
packet[2] = 0x11;
|
||||
response = stream.getDataBuffer().getPacket("read command");
|
||||
System.out.println("read command " + IoStream.printHexBinary(response));
|
||||
|
||||
|
||||
} catch (IOException ioException) {
|
||||
ioException.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
flow.add(connect);
|
||||
flow.add(poke);
|
||||
|
||||
content.add(flow);
|
||||
}
|
||||
|
||||
public JComponent getContent() {
|
||||
return content;
|
||||
}
|
||||
}
|
|
@ -47,6 +47,7 @@ public class PluginEntry implements TsPluginBody {
|
|||
tabbedPane.addTab("Upload", uploadTab.getContent());
|
||||
tabbedPane.addTab("Broadcast", broadcastTab.getContent());
|
||||
tabbedPane.addTab("Remote ECU", remoteTab.getContent());
|
||||
tabbedPane.addTab("Read SD Card", new SdCardReader().getContent());
|
||||
content.add(tabbedPane);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package com.rusefi.ts_plugin;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class SdCardReader {
|
||||
private final JPanel content = new JPanel();
|
||||
|
||||
public SdCardReader() {
|
||||
content.add(new ConnectPanel().getContent());
|
||||
}
|
||||
|
||||
public Component getContent() {
|
||||
return content;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue