TS SD integration #1653
This commit is contained in:
parent
4e35178bd3
commit
bc2bb94dee
|
@ -30,6 +30,9 @@ public abstract class IniField {
|
||||||
|
|
||||||
public abstract int getSize();
|
public abstract int getSize();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see com.rusefi.config.Field#getValue
|
||||||
|
*/
|
||||||
public String getValue(ConfigurationImage image) {
|
public String getValue(ConfigurationImage image) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,11 +39,11 @@ public class IoHelper {
|
||||||
return (((x & 0xff) << 8) | ((x >> 8) & 0xff));
|
return (((x & 0xff) << 8) | ((x >> 8) & 0xff));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int swap32(int x) {
|
public static int swap32(int x) {
|
||||||
return (((x) >> 24) & 0xff) | (((x) << 8) & 0xff0000) | (((x) >> 8) & 0xff00) | (((x) << 24) & 0xff000000);
|
return (((x) >> 24) & 0xff) | (((x) << 8) & 0xff0000) | (((x) >> 8) & 0xff00) | (((x) << 24) & 0xff000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void putInt(byte[] packet, int offset, int value) {
|
public static void putInt(byte[] packet, int offset, int value) {
|
||||||
int index = offset + 3;
|
int index = offset + 3;
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
packet[index--] = (byte) value;
|
packet[index--] = (byte) value;
|
||||||
|
|
|
@ -39,6 +39,7 @@ import static com.rusefi.config.generated.Fields.*;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class BinaryProtocolServer implements BinaryProtocolCommands {
|
public class BinaryProtocolServer implements BinaryProtocolCommands {
|
||||||
|
public static final String TEST_FILE = "test_log.mlg.Z";
|
||||||
private static final Logging log = getLogging(BinaryProtocolServer.class);
|
private static final Logging log = getLogging(BinaryProtocolServer.class);
|
||||||
private static final int DEFAULT_PROXY_PORT = 2390;
|
private static final int DEFAULT_PROXY_PORT = 2390;
|
||||||
public static final String TS_OK = "\0";
|
public static final String TS_OK = "\0";
|
||||||
|
@ -267,6 +268,9 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
|
||||||
response[9] = 0;
|
response[9] = 0;
|
||||||
response[10] = 1; // number of files
|
response[10] = 1; // number of files
|
||||||
} else {
|
} else {
|
||||||
|
// SD read directory command
|
||||||
|
//
|
||||||
|
|
||||||
System.arraycopy("hello123mlq".getBytes(), 0, response, 1, 11);
|
System.arraycopy("hello123mlq".getBytes(), 0, response, 1, 11);
|
||||||
response[1 + 11] = 1; // file
|
response[1 + 11] = 1; // file
|
||||||
|
|
||||||
|
@ -275,9 +279,14 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
|
||||||
response[1 + 24] = (byte) 0; // size
|
response[1 + 24] = (byte) 0; // size
|
||||||
response[1 + 25] = (byte) 0; // size
|
response[1 + 25] = (byte) 0; // size
|
||||||
|
|
||||||
response[1 + 29] = (byte) 128;
|
File f = new File(TEST_FILE);
|
||||||
response[1 + 30] = (byte) 1;
|
int size = (int) f.length();
|
||||||
response[1 + 31] = (byte) 0; // size
|
|
||||||
|
IoHelper.putInt(response, 29, IoHelper.swap32(size));
|
||||||
|
|
||||||
|
// response[1 + 29] = (byte) 128;
|
||||||
|
// response[1 + 30] = (byte) 1;
|
||||||
|
// response[1 + 31] = (byte) 0; // size
|
||||||
|
|
||||||
}
|
}
|
||||||
stream.sendPacket(response);
|
stream.sendPacket(response);
|
||||||
|
@ -296,6 +305,21 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
|
||||||
// fake data
|
// fake data
|
||||||
response[3] = payload[3];
|
response[3] = payload[3];
|
||||||
response[4] = payload[4];
|
response[4] = payload[4];
|
||||||
|
|
||||||
|
File f = new File(BinaryProtocolServer.TEST_FILE);
|
||||||
|
FileInputStream fis = new FileInputStream(f);
|
||||||
|
int size = (int) f.length();
|
||||||
|
|
||||||
|
|
||||||
|
int offset = blockNumber * 2048;
|
||||||
|
int len = Math.min(size - offset, 2048);
|
||||||
|
|
||||||
|
if (len > 0) {
|
||||||
|
fis.skip(offset);
|
||||||
|
log.info("TS_SD reading " + offset + " " + len + " of " + size);
|
||||||
|
fis.read(response, 3, len);
|
||||||
|
}
|
||||||
|
|
||||||
stream.sendPacket(response);
|
stream.sendPacket(response);
|
||||||
} else {
|
} else {
|
||||||
log.info("TS_SD: Got unexpected r " + IoStream.printHexBinary(packet.packet));
|
log.info("TS_SD: Got unexpected r " + IoStream.printHexBinary(packet.packet));
|
||||||
|
|
Binary file not shown.
|
@ -1,17 +1,30 @@
|
||||||
package com.rusefi.io;
|
package com.rusefi.io;
|
||||||
|
|
||||||
import com.opensr5.ConfigurationImage;
|
import com.opensr5.ConfigurationImage;
|
||||||
|
import com.opensr5.ini.field.ScalarIniField;
|
||||||
|
import com.rusefi.TestHelper;
|
||||||
import com.rusefi.binaryprotocol.BinaryProtocolState;
|
import com.rusefi.binaryprotocol.BinaryProtocolState;
|
||||||
import com.rusefi.config.generated.Fields;
|
import com.rusefi.config.generated.Fields;
|
||||||
import com.rusefi.io.tcp.BinaryProtocolServer;
|
import com.rusefi.io.tcp.BinaryProtocolServer;
|
||||||
|
import com.rusefi.tune.xml.Constant;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts a fake device with TCP connector at {@link BinaryProtocolServer#DEFAULT_PROXY_PORT} port
|
* Starts a fake device with TCP connector at {@link BinaryProtocolServer#DEFAULT_PROXY_PORT} port
|
||||||
*/
|
*/
|
||||||
class BinaryProtocolServerSandbox {
|
class BinaryProtocolServerSandbox {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
File f = new File(BinaryProtocolServer.TEST_FILE);
|
||||||
|
if (!f.exists())
|
||||||
|
throw new IllegalStateException("File not found: " + BinaryProtocolServer.TEST_FILE);
|
||||||
|
|
||||||
BinaryProtocolState state = new BinaryProtocolState();
|
BinaryProtocolState state = new BinaryProtocolState();
|
||||||
state.setController(new ConfigurationImage(new byte[Fields.TOTAL_CONFIG_SIZE]));
|
ConfigurationImage controller = new ConfigurationImage(new byte[Fields.TOTAL_CONFIG_SIZE]);
|
||||||
|
ScalarIniField iniField = TestHelper.createIniField(Fields.AMBIGUOUSOPERATIONMODE);
|
||||||
|
iniField.setValue(controller, new Constant(iniField.getName(), "", "1", iniField.getDigits()));
|
||||||
|
state.setController(controller);
|
||||||
state.setCurrentOutputs(new byte[1 + Fields.TS_OUTPUT_SIZE]);
|
state.setCurrentOutputs(new byte[1 + Fields.TS_OUTPUT_SIZE]);
|
||||||
|
|
||||||
LinkManager linkManager = new LinkManager();
|
LinkManager linkManager = new LinkManager();
|
||||||
|
|
Loading…
Reference in New Issue