auto-sync

This commit is contained in:
rusEfi 2016-02-13 21:02:14 -05:00
parent 6210c7b9bb
commit 294f949bd3
8 changed files with 25 additions and 5 deletions

View File

@ -440,6 +440,7 @@ void runBinaryProtocolLoop(ts_channel_s *tsChannel, bool isConsoleRedirect) {
// tunerStudioError("ERROR: no command");
continue;
}
onDataArrived();
// scheduleMsg(logger, "Got first=%x=[%c]", firstByte, firstByte);
if (handlePlainCommand(tsChannel, firstByte))
continue;

View File

@ -40,6 +40,13 @@ static bool isSerialConsoleStarted = false;
static event_listener_t consoleEventListener;
bool consoleByteArrived = false;
void onDataArrived(void) {
consoleByteArrived = true;
}
/**
* @brief Reads a whole line from the input channel.
*
@ -61,6 +68,7 @@ static bool getConsoleLine(BaseSequentialStream *chp, char *line, unsigned size)
}
short c = (short) chSequentialStreamGet(chp);
onDataArrived();
if (isSerialOverUart()) {
uint32_t flags;

View File

@ -26,6 +26,7 @@ void consolePutChar(int x);
void consoleOutputBuffer(const uint8_t *buf, int size);
void startConsole(Logging *sharedLogger, CommandHandler console_line_callback_p);
bool isSerialOverUart(void);
void onDataArrived(void);
#if EFI_PROD_CODE || EFI_SIMULATOR || EFI_EGT
bool isConsoleReady(void);

View File

@ -500,6 +500,8 @@ static bool isTriggerErrorNow() {
return justHadError || isTriggerDecoderError();
}
extern bool consoleByteArrived;
/**
* this thread has a lower-then-usual stack size so we cannot afford *print* methods here
*/
@ -524,8 +526,10 @@ static void blinkingThread(void *arg) {
communicationPin.setValue(1);
#if EFI_ENGINE_CONTROL || defined(__DOXYGEN__)
if (isTriggerErrorNow() || isIgnitionTimingError())
if (isTriggerErrorNow() || isIgnitionTimingError() || consoleByteArrived) {
consoleByteArrived = false;
warningPin.setValue(1);
}
#endif
chThdSleepMilliseconds(delayMs);

View File

@ -14,7 +14,7 @@ import java.util.Arrays;
*/
@ThreadSafe
public class IncomingDataBuffer {
private static final int BUFFER_SIZE = 10000;
private static final int BUFFER_SIZE = 32768;
/**
* buffer for response bytes from controller
*/

View File

@ -54,9 +54,8 @@ public class PortHolder {
FileLog.MAIN.logLine("Opening " + port + " @ " + BAUD_RATE);
boolean opened = serialPort.openPort();//Open serial port
if (!opened)
FileLog.MAIN.logLine("not opened!");
FileLog.MAIN.logLine(port + ": not opened!");
setupPort(serialPort, BAUD_RATE);
// serialPort.setDataListener(new SerialPortReader(serialPort, communicationLoggingListener));
} catch (SerialPortException e) {
FileLog.MAIN.logLine("ERROR " + e.getMessage());
return false;

View File

@ -57,7 +57,9 @@ public class SerialIoStream implements IoStream {
@Override
public void setDataListener(DataListener listener) {
try {
serialPort.addEventListener(new SerialPortReader(serialPort, listener));
SerialPortReader reader = new SerialPortReader(serialPort, listener);
serialPort.addEventListener(reader);
reader.readInitial();
} catch (SerialPortException e) {
throw new IllegalStateException(e);
}

View File

@ -43,5 +43,10 @@ public class SerialPortReader implements SerialPortEventListener {
public void readInitial() throws SerialPortException {
int input = serialPort.getInputBufferBytesCount();
FileLog.MAIN.logLine(input + " bytes in input buffer");
while (serialPort.getInputBufferBytesCount() > 0) {
byte[] data = serialPort.readBytes();
if (data != null)
listener.onDataArrived(data);
}
}
}