TS communication minor fixes (#2847)

* console: noone use this

* console: do not stop blinking if TS command executes too long

Set and clear flag from the same place

Co-authored-by: rusefillc <48498823+rusefillc@users.noreply.github.com>
This commit is contained in:
Andrey G 2021-06-23 11:36:55 +03:00 committed by GitHub
parent 270905fa8b
commit 5c552e196a
4 changed files with 27 additions and 21 deletions

View File

@ -99,6 +99,9 @@
EXTERN_ENGINE;
/* 1S */
#define TS_COMMUNICATION_TIMEOUT TIME_MS2I(1000)
extern persistent_config_container_s persistentState;
#if !defined(EFI_NO_CONFIG_WORKING_COPY)
@ -439,18 +442,18 @@ static bool isKnownCommand(char command) {
TunerStudio tsInstance;
static void tsProcessOne(TsChannelBase* tsChannel) {
static int tsProcessOne(TsChannelBase* tsChannel) {
validateStack("communication", STACK_USAGE_COMMUNICATION, 128);
if (!tsChannel->isReady()) {
chThdSleepMilliseconds(10);
return;
return -1;
}
tsState.totalCounter++;
uint8_t firstByte;
int received = tsChannel->read(&firstByte, 1);
int received = tsChannel->readTimeout(&firstByte, 1, TS_COMMUNICATION_TIMEOUT);
#if EFI_SIMULATOR
logMsg("received %d\r\n", received);
#endif
@ -461,19 +464,18 @@ static void tsProcessOne(TsChannelBase* tsChannel) {
// assume there's connection loss and notify the bluetooth init code
bluetoothSoftwareDisconnectNotify();
#endif /* EFI_BLUETOOTH_SETUP */
return;
return -1;
}
onDataArrived();
if (handlePlainCommand(tsChannel, firstByte)) {
return;
return -1;
}
uint8_t secondByte;
received = tsChannel->read(&secondByte, 1);
received = tsChannel->readTimeout(&secondByte, 1, TS_COMMUNICATION_TIMEOUT);
if (received != 1) {
tunerStudioError("TS: ERROR: no second byte");
return;
return -1;
}
uint16_t incomingPacketSize = firstByte << 8 | secondByte;
@ -482,36 +484,35 @@ static void tsProcessOne(TsChannelBase* tsChannel) {
efiPrintf("TunerStudio: invalid size: %d", incomingPacketSize);
tunerStudioError("ERROR: CRC header size");
sendErrorCode(tsChannel, TS_RESPONSE_UNDERRUN);
return;
return -1;
}
received = tsChannel->read((uint8_t* )tsChannel->scratchBuffer, 1);
received = tsChannel->readTimeout((uint8_t* )tsChannel->scratchBuffer, 1, TS_COMMUNICATION_TIMEOUT);
if (received != 1) {
tunerStudioError("ERROR: did not receive command");
sendErrorCode(tsChannel, TS_RESPONSE_UNDERRUN);
return;
return -1;
}
char command = tsChannel->scratchBuffer[0];
if (!isKnownCommand(command)) {
efiPrintf("unexpected command %x", command);
sendErrorCode(tsChannel, TS_RESPONSE_UNRECOGNIZED_COMMAND);
return;
return -1;
}
#if EFI_SIMULATOR
logMsg("command %c\r\n", command);
#endif
received = tsChannel->read((uint8_t*)(tsChannel->scratchBuffer + 1),
incomingPacketSize + CRC_VALUE_SIZE - 1);
int expectedSize = incomingPacketSize + CRC_VALUE_SIZE - 1;
received = tsChannel->readTimeout((uint8_t*)(tsChannel->scratchBuffer + 1), expectedSize, TS_COMMUNICATION_TIMEOUT);
if (received != expectedSize) {
efiPrintf("Got only %d bytes while expecting %d for command %c", received,
expectedSize, command);
tunerStudioError("ERROR: not enough bytes in stream");
sendErrorCode(tsChannel, TS_RESPONSE_UNDERRUN);
return;
return -1;
}
uint32_t expectedCrc = *(uint32_t*) (tsChannel->scratchBuffer + incomingPacketSize);
@ -528,14 +529,17 @@ static void tsProcessOne(TsChannelBase* tsChannel) {
actualCrc, expectedCrc);
tunerStudioError("ERROR: CRC issue");
sendErrorCode(tsChannel, TS_RESPONSE_CRC_FAILURE);
return;
return -1;
}
int success = tsInstance.handleCrcCommand(tsChannel, tsChannel->scratchBuffer, incomingPacketSize);
if (!success) {
efiPrintf("got unexpected TunerStudio command %x:%c", command, command);
return -1;
}
return 0;
}
void TunerstudioThread::ThreadTask() {
@ -548,7 +552,10 @@ void TunerstudioThread::ThreadTask() {
// Until the end of time, process incoming messages.
while(true) {
tsProcessOne(channel);
if (tsProcessOne(channel) == 0)
onDataArrived(true);
else
onDataArrived(false);
}
}

View File

@ -49,8 +49,8 @@ EXTERN_ENGINE;
bool consoleByteArrived = false;
void onDataArrived(void) {
consoleByteArrived = true;
void onDataArrived(bool valid) {
consoleByteArrived = valid;
}
CommandHandler console_line_callback;

View File

@ -21,4 +21,4 @@ typedef void (*CommandHandler)(char *);
void consoleOutputBuffer(const uint8_t *buf, int size);
void startConsole(CommandHandler console_line_callback_p);
void onDataArrived(void);
void onDataArrived(bool valid);

View File

@ -404,7 +404,6 @@ extern int totalLoggedBytes;
offTimeMs = 50;
onTimeMs = 450;
} else if (consoleByteArrived) {
consoleByteArrived = false;
offTimeMs = 100;
onTimeMs = 33;
#if EFI_INTERNAL_FLASH