Ts error codes (#1706)

* correct TS errors

* tidy

Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
Matthew Kennedy 2020-08-21 05:24:31 -07:00 committed by GitHub
parent 67b7b4c197
commit a73d5718a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 13 deletions

View File

@ -206,8 +206,8 @@ void sendOkResponse(ts_channel_s *tsChannel, ts_response_format_e mode) {
sr5SendResponse(tsChannel, mode, NULL, 0);
}
static void sendErrorCode(ts_channel_s *tsChannel) {
sr5WriteCrcPacket(tsChannel, TS_RESPONSE_CRC_FAILURE, NULL, 0);
static void sendErrorCode(ts_channel_s *tsChannel, uint8_t code) {
sr5WriteCrcPacket(tsChannel, code, NULL, 0);
}
static void handlePageSelectCommand(ts_channel_s *tsChannel, ts_response_format_e mode) {
@ -297,7 +297,7 @@ static bool validateOffsetCount(size_t offset, size_t count, ts_channel_s *tsCha
if (offset + count > getTunerStudioPageSize()) {
scheduleMsg(&tsLogger, "TS: Project mismatch? Too much configuration requested %d/%d", offset, count);
tunerStudioError("ERROR: out of range");
sendErrorCode(tsChannel);
sendErrorCode(tsChannel, TS_RESPONSE_OUT_OF_RANGE);
return true;
}
@ -496,20 +496,21 @@ void runBinaryProtocolLoop(ts_channel_s *tsChannel) {
if (incomingPacketSize == 0 || incomingPacketSize > (sizeof(tsChannel->crcReadBuffer) - CRC_WRAPPING_SIZE)) {
scheduleMsg(&tsLogger, "TunerStudio: invalid size: %d", incomingPacketSize);
tunerStudioError("ERROR: CRC header size");
sendErrorCode(tsChannel);
sendErrorCode(tsChannel, TS_RESPONSE_UNDERRUN);
continue;
}
received = sr5ReadData(tsChannel, (uint8_t* )tsChannel->crcReadBuffer, 1);
if (received != 1) {
tunerStudioError("ERROR: did not receive command");
sendErrorCode(tsChannel, TS_RESPONSE_UNDERRUN);
continue;
}
char command = tsChannel->crcReadBuffer[0];
if (!isKnownCommand(command)) {
scheduleMsg(&tsLogger, "unexpected command %x", command);
sendErrorCode(tsChannel);
sendErrorCode(tsChannel, TS_RESPONSE_UNRECOGNIZED_COMMAND);
continue;
}
@ -517,9 +518,6 @@ void runBinaryProtocolLoop(ts_channel_s *tsChannel) {
logMsg("command %c\r\n", command);
#endif
// scheduleMsg(logger, "TunerStudio: reading %d+4 bytes(s)", incomingPacketSize);
received = sr5ReadData(tsChannel, (uint8_t * ) (tsChannel->crcReadBuffer + 1),
incomingPacketSize + CRC_VALUE_SIZE - 1);
int expectedSize = incomingPacketSize + CRC_VALUE_SIZE - 1;
@ -527,7 +525,7 @@ void runBinaryProtocolLoop(ts_channel_s *tsChannel) {
scheduleMsg(&tsLogger, "Got only %d bytes while expecting %d for command %c", received,
expectedSize, command);
tunerStudioError("ERROR: not enough bytes in stream");
sendResponseCode(TS_CRC, tsChannel, TS_RESPONSE_UNDERRUN);
sendErrorCode(tsChannel, TS_RESPONSE_UNDERRUN);
continue;
}
@ -544,12 +542,10 @@ void runBinaryProtocolLoop(ts_channel_s *tsChannel) {
scheduleMsg(&tsLogger, "TunerStudio: command %c actual CRC %x/expected %x", tsChannel->crcReadBuffer[0],
actualCrc, expectedCrc);
tunerStudioError("ERROR: CRC issue");
sendErrorCode(tsChannel, TS_RESPONSE_CRC_FAILURE);
continue;
}
// scheduleMsg(logger, "TunerStudio: P00-07 %x %x %x %x %x %x %x %x", crcIoBuffer[0], crcIoBuffer[1],
// crcIoBuffer[2], crcIoBuffer[3], crcIoBuffer[4], crcIoBuffer[5], crcIoBuffer[6], crcIoBuffer[7]);
int success = tunerStudioHandleCrcCommand(tsChannel, tsChannel->crcReadBuffer, incomingPacketSize);
if (!success)
print("got unexpected TunerStudio command %x:%c\r\n", command, command);
@ -606,7 +602,7 @@ static void handleOutputChannelsCommand(ts_channel_s *tsChannel, ts_response_for
if (offset + count > sizeof(TunerStudioOutputChannels)) {
scheduleMsg(&tsLogger, "TS: Version Mismatch? Too much outputs requested %d/%d/%d", offset, count,
sizeof(TunerStudioOutputChannels));
sendErrorCode(tsChannel);
sendErrorCode(tsChannel, TS_RESPONSE_OUT_OF_RANGE);
return;
}

View File

@ -16,6 +16,9 @@
#define TS_RESPONSE_UNDERRUN 0x80
#define TS_RESPONSE_CRC_FAILURE 0x82
#define TS_RESPONSE_UNRECOGNIZED_COMMAND 0x83
#define TS_RESPONSE_OUT_OF_RANGE 0x84
#define TS_RESPONSE_FRAMING_ERROR 0x8D
typedef enum {
TS_PLAIN = 0,