TcpCommunicationIntegrationTest
This commit is contained in:
parent
6008159238
commit
8a91ca0e29
|
@ -67,10 +67,10 @@ public class BinaryProtocol implements BinaryProtocolCommands {
|
||||||
private final IncomingDataBuffer incomingData;
|
private final IncomingDataBuffer incomingData;
|
||||||
private boolean isBurnPending;
|
private boolean isBurnPending;
|
||||||
|
|
||||||
|
private BinaryProtocolState state = new BinaryProtocolState();
|
||||||
|
|
||||||
// todo: this ioLock needs better documentation!
|
// todo: this ioLock needs better documentation!
|
||||||
private final Object ioLock = new Object();
|
private final Object ioLock = new Object();
|
||||||
private final Object imageLock = new Object();
|
|
||||||
private ConfigurationImage controller;
|
|
||||||
|
|
||||||
private static final int COMPOSITE_OFF_RPM = 300;
|
private static final int COMPOSITE_OFF_RPM = 300;
|
||||||
|
|
||||||
|
@ -94,11 +94,15 @@ public class BinaryProtocol implements BinaryProtocolCommands {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isClosed;
|
public boolean isClosed;
|
||||||
/**
|
|
||||||
* Snapshot of current gauges status
|
public byte[] getCurrentOutputs() {
|
||||||
* @see Fields#TS_OUTPUT_COMMAND
|
return state.getCurrentOutputs();
|
||||||
*/
|
}
|
||||||
public byte[] currentOutputs;
|
|
||||||
|
public void setCurrentOutputs(byte[] currentOutputs) {
|
||||||
|
state.setCurrentOutputs(currentOutputs);
|
||||||
|
}
|
||||||
|
|
||||||
private SensorCentral.SensorListener rpmListener = value -> {
|
private SensorCentral.SensorListener rpmListener = value -> {
|
||||||
if (value <= COMPOSITE_OFF_RPM) {
|
if (value <= COMPOSITE_OFF_RPM) {
|
||||||
needCompositeLogger = true;
|
needCompositeLogger = true;
|
||||||
|
@ -467,20 +471,14 @@ public class BinaryProtocol implements BinaryProtocolCommands {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setController(ConfigurationImage controller) {
|
public void setController(ConfigurationImage controller) {
|
||||||
synchronized (imageLock) {
|
state.setController(controller);
|
||||||
this.controller = controller.clone();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration as it is in the controller to the best of our knowledge
|
* Configuration as it is in the controller to the best of our knowledge
|
||||||
*/
|
*/
|
||||||
public ConfigurationImage getControllerConfiguration() {
|
public ConfigurationImage getControllerConfiguration() {
|
||||||
synchronized (imageLock) {
|
return state.getControllerConfiguration();
|
||||||
if (controller == null)
|
|
||||||
return null;
|
|
||||||
return controller.clone();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendPacket(byte[] command) throws IOException {
|
private void sendPacket(byte[] command) throws IOException {
|
||||||
|
@ -561,7 +559,7 @@ public class BinaryProtocol implements BinaryProtocolCommands {
|
||||||
if (response == null || response.length != (Fields.TS_OUTPUT_SIZE + 1) || response[0] != RESPONSE_OK)
|
if (response == null || response.length != (Fields.TS_OUTPUT_SIZE + 1) || response[0] != RESPONSE_OK)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
currentOutputs = response;
|
state.setCurrentOutputs(response);
|
||||||
|
|
||||||
for (Sensor sensor : Sensor.values()) {
|
for (Sensor sensor : Sensor.values()) {
|
||||||
if (sensor.getType() == null) {
|
if (sensor.getType() == null) {
|
||||||
|
@ -603,8 +601,6 @@ public class BinaryProtocol implements BinaryProtocolCommands {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRange(byte[] src, int scrPos, int offset, int count) {
|
public void setRange(byte[] src, int scrPos, int offset, int count) {
|
||||||
synchronized (imageLock) {
|
state.setRange(src, scrPos, offset, count);
|
||||||
System.arraycopy(src, scrPos, controller.getContent(), offset, count);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
package com.rusefi.binaryprotocol;
|
||||||
|
|
||||||
|
import com.opensr5.ConfigurationImage;
|
||||||
|
import com.rusefi.config.generated.Fields;
|
||||||
|
|
||||||
|
public class BinaryProtocolState {
|
||||||
|
private final Object imageLock = new Object();
|
||||||
|
private ConfigurationImage controller;
|
||||||
|
/**
|
||||||
|
* Snapshot of current gauges status
|
||||||
|
* @see Fields#TS_OUTPUT_COMMAND
|
||||||
|
*/
|
||||||
|
private byte[] currentOutputs;
|
||||||
|
|
||||||
|
public void setController(ConfigurationImage controller) {
|
||||||
|
synchronized (imageLock) {
|
||||||
|
this.controller = controller.clone();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getCurrentOutputs() {
|
||||||
|
return currentOutputs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCurrentOutputs(byte[] currentOutputs) {
|
||||||
|
this.currentOutputs = currentOutputs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigurationImage getControllerConfiguration() {
|
||||||
|
synchronized (imageLock) {
|
||||||
|
if (controller == null)
|
||||||
|
return null;
|
||||||
|
return controller.clone();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRange(byte[] src, int scrPos, int offset, int count) {
|
||||||
|
synchronized (imageLock) {
|
||||||
|
System.arraycopy(src, scrPos, controller.getContent(), offset, count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -126,7 +126,7 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
|
||||||
byte[] response = new byte[1 + count];
|
byte[] response = new byte[1 + count];
|
||||||
response[0] = (byte) TS_OK.charAt(0);
|
response[0] = (byte) TS_OK.charAt(0);
|
||||||
BinaryProtocol bp = linkManager.getCurrentStreamState();
|
BinaryProtocol bp = linkManager.getCurrentStreamState();
|
||||||
byte[] currentOutputs = bp.currentOutputs;
|
byte[] currentOutputs = bp.getCurrentOutputs();
|
||||||
if (currentOutputs != null)
|
if (currentOutputs != null)
|
||||||
System.arraycopy(currentOutputs, 1 + offset , response, 1, count);
|
System.arraycopy(currentOutputs, 1 + offset , response, 1, count);
|
||||||
stream.sendPacket(response, FileLog.LOGGER);
|
stream.sendPacket(response, FileLog.LOGGER);
|
||||||
|
|
|
@ -5,7 +5,6 @@ import com.rusefi.FileLog;
|
||||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||||
import com.rusefi.config.generated.Fields;
|
import com.rusefi.config.generated.Fields;
|
||||||
import com.rusefi.io.ConnectionStateListener;
|
import com.rusefi.io.ConnectionStateListener;
|
||||||
import com.rusefi.io.IoStream;
|
|
||||||
import com.rusefi.io.LinkConnector;
|
import com.rusefi.io.LinkConnector;
|
||||||
import com.rusefi.io.LinkManager;
|
import com.rusefi.io.LinkManager;
|
||||||
import com.rusefi.io.tcp.BinaryProtocolServer;
|
import com.rusefi.io.tcp.BinaryProtocolServer;
|
||||||
|
@ -41,7 +40,7 @@ class BinaryProtocolServerSandbox {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
bp.setController(new ConfigurationImage(new byte[Fields.TOTAL_CONFIG_SIZE]));
|
bp.setController(new ConfigurationImage(new byte[Fields.TOTAL_CONFIG_SIZE]));
|
||||||
bp.currentOutputs = new byte[1 + Fields.TS_OUTPUT_SIZE];
|
bp.setCurrentOutputs(new byte[1 + Fields.TS_OUTPUT_SIZE]);
|
||||||
BinaryProtocolServer.start(linkManager);
|
BinaryProtocolServer.start(linkManager);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue