Chunk outputchannels (#3916)

* executeCommand knows about opcodes

* kick

* remove allowLongResponse

* unused

* chunk output channel reads

* add api in firmware instead

* test size

* bad merge

* firmware missed a spot

* bad merge

* fix logic

* haha we have to disable it

* we can remove the TODO from #3917
This commit is contained in:
Matthew Kennedy 2022-02-11 14:24:08 -08:00 committed by GitHub
parent d6cb66ff73
commit 9b71969ae2
5 changed files with 33 additions and 34 deletions

View File

@ -91,10 +91,7 @@ void TsChannelBase::writeCrcPacket(uint8_t responseCode, const uint8_t* buf, siz
bool isBigPacket = size > BLOCKING_FACTOR + 7;
if (isBigPacket && !allowLongPackets) {
// TODO: turn this in to an error once console output channel reads are chunked!
// Hardware CI may fail before that time.
//firmwareError(OBD_PCM_Processor_Fault, "tried to send disallowed long packet of size %d", size);
warning(OBD_PCM_Processor_Fault, "tried to send disallowed long packet of size %d", size);
firmwareError(OBD_PCM_Processor_Fault, "tried to send disallowed long packet of size %d", size);
}
if (isBigPacket) {

View File

@ -64,9 +64,6 @@ public class BinaryProtocol {
BinaryProtocolLogger binaryProtocolLogger;
public static boolean DISABLE_LOCAL_CACHE;
// hack needed by
public static int tsOutputSize = TS_OUTPUT_SIZE;
public static String findCommand(byte command) {
switch (command) {
case Fields.TS_PAGE_COMMAND:
@ -104,17 +101,11 @@ public class BinaryProtocol {
public CommunicationLoggingListener communicationLoggingListener;
public BinaryProtocol(LinkManager linkManager, IoStream stream) {
this.linkManager = linkManager;
this.stream = stream;
communicationLoggingListener = new CommunicationLoggingListener() {
@Override
public void onPortHolderMessage(Class clazz, String message) {
linkManager.messageListener.postMessage(clazz, message);
}
};
communicationLoggingListener = linkManager.messageListener::postMessage;
incomingData = stream.getDataBuffer();
binaryProtocolLogger = new BinaryProtocolLogger(linkManager);
@ -522,8 +513,7 @@ public class BinaryProtocol {
}
public static byte[] getTextCommandBytes(String text) {
byte[] asBytes = text.getBytes();
return asBytes;
return text.getBytes();
}
private String requestPendingMessages() {
@ -544,23 +534,39 @@ public class BinaryProtocol {
if (isClosed)
return false;
byte[] packet = GetOutputsCommand.createRequest(tsOutputSize);
// TODO: Get rid of the +1. This adds a byte at the front to tack a fake TS response code on the front
// of the reassembled packet.
byte[] reassemblyBuffer = new byte[Fields.TS_OUTPUT_SIZE + 1];
reassemblyBuffer[0] = Fields.TS_RESPONSE_OK;
byte[] response = executeCommand(Fields.TS_OUTPUT_COMMAND, packet, "output channels");
if (response == null || response.length != (tsOutputSize + 1) || response[0] != Fields.TS_RESPONSE_OK)
return false;
int reassemblyIdx = 0;
int remaining = Fields.TS_OUTPUT_SIZE;
state.setCurrentOutputs(response);
while (remaining > 0) {
// If less than one full chunk left, do a smaller read
int chunkSize = Math.min(remaining, Fields.BLOCKING_FACTOR);
if (tsOutputSize == Fields.TS_OUTPUT_SIZE) // do not care about sensor values in test mode
SensorCentral.getInstance().grabSensorValues(response);
byte[] response = executeCommand(
Fields.TS_OUTPUT_COMMAND,
GetOutputsCommand.createRequest(reassemblyIdx, chunkSize),
"output channels"
);
if (response == null || response.length != (chunkSize + 1) || response[0] != Fields.TS_RESPONSE_OK) {
return false;
}
// Copy this chunk in to the reassembly buffer
System.arraycopy(response, 1, reassemblyBuffer, reassemblyIdx + 1, chunkSize);
remaining -= chunkSize;
}
state.setCurrentOutputs(reassemblyBuffer);
SensorCentral.getInstance().grabSensorValues(reassemblyBuffer);
return true;
}
public void setRange(byte[] src, int scrPos, int offset, int count) {
state.setRange(src, scrPos, offset, count);
}
public BinaryProtocolState getBinaryProtocolState() {
return state;
}

View File

@ -2,7 +2,6 @@ package com.rusefi.binaryprotocol;
import com.devexperts.logging.Logging;
import com.rusefi.Timeouts;
import com.rusefi.config.generated.Fields;
import com.rusefi.io.IoStream;
import com.rusefi.io.serial.AbstractIoStream;
import etch.util.CircularByteBuffer;

View File

@ -11,12 +11,12 @@ import static com.rusefi.binaryprotocol.IoHelper.swap16;
public class GetOutputsCommand {
public static byte[] createRequest() {
return createRequest(Fields.TS_OUTPUT_SIZE);
return createRequest(0, Fields.TS_OUTPUT_SIZE);
}
public static byte[] createRequest(int size) {
public static byte[] createRequest(int offset, int size) {
byte[] packet = new byte[4];
putShort(packet, 0, 0); // offset
putShort(packet, 0, swap16(offset));
putShort(packet, 2, swap16(size));
return packet;
}

View File

@ -11,9 +11,6 @@ import java.util.concurrent.CountDownLatch;
public class SerialSandbox {
public static void main(String[] args) {
// todo: open issue #1
BinaryProtocol.tsOutputSize = 100;
long startTime = System.currentTimeMillis();
SerialAutoChecker.AutoDetectResult autoDetectResult = PortDetector.autoDetectSerial(callbackContext -> null);