Ts error codes (#1706)
* correct TS errors * tidy Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
parent
67b7b4c197
commit
a73d5718a7
|
@ -206,8 +206,8 @@ void sendOkResponse(ts_channel_s *tsChannel, ts_response_format_e mode) {
|
||||||
sr5SendResponse(tsChannel, mode, NULL, 0);
|
sr5SendResponse(tsChannel, mode, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sendErrorCode(ts_channel_s *tsChannel) {
|
static void sendErrorCode(ts_channel_s *tsChannel, uint8_t code) {
|
||||||
sr5WriteCrcPacket(tsChannel, TS_RESPONSE_CRC_FAILURE, NULL, 0);
|
sr5WriteCrcPacket(tsChannel, code, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handlePageSelectCommand(ts_channel_s *tsChannel, ts_response_format_e mode) {
|
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()) {
|
if (offset + count > getTunerStudioPageSize()) {
|
||||||
scheduleMsg(&tsLogger, "TS: Project mismatch? Too much configuration requested %d/%d", offset, count);
|
scheduleMsg(&tsLogger, "TS: Project mismatch? Too much configuration requested %d/%d", offset, count);
|
||||||
tunerStudioError("ERROR: out of range");
|
tunerStudioError("ERROR: out of range");
|
||||||
sendErrorCode(tsChannel);
|
sendErrorCode(tsChannel, TS_RESPONSE_OUT_OF_RANGE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -496,20 +496,21 @@ void runBinaryProtocolLoop(ts_channel_s *tsChannel) {
|
||||||
if (incomingPacketSize == 0 || incomingPacketSize > (sizeof(tsChannel->crcReadBuffer) - CRC_WRAPPING_SIZE)) {
|
if (incomingPacketSize == 0 || incomingPacketSize > (sizeof(tsChannel->crcReadBuffer) - CRC_WRAPPING_SIZE)) {
|
||||||
scheduleMsg(&tsLogger, "TunerStudio: invalid size: %d", incomingPacketSize);
|
scheduleMsg(&tsLogger, "TunerStudio: invalid size: %d", incomingPacketSize);
|
||||||
tunerStudioError("ERROR: CRC header size");
|
tunerStudioError("ERROR: CRC header size");
|
||||||
sendErrorCode(tsChannel);
|
sendErrorCode(tsChannel, TS_RESPONSE_UNDERRUN);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
received = sr5ReadData(tsChannel, (uint8_t* )tsChannel->crcReadBuffer, 1);
|
received = sr5ReadData(tsChannel, (uint8_t* )tsChannel->crcReadBuffer, 1);
|
||||||
if (received != 1) {
|
if (received != 1) {
|
||||||
tunerStudioError("ERROR: did not receive command");
|
tunerStudioError("ERROR: did not receive command");
|
||||||
|
sendErrorCode(tsChannel, TS_RESPONSE_UNDERRUN);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
char command = tsChannel->crcReadBuffer[0];
|
char command = tsChannel->crcReadBuffer[0];
|
||||||
if (!isKnownCommand(command)) {
|
if (!isKnownCommand(command)) {
|
||||||
scheduleMsg(&tsLogger, "unexpected command %x", command);
|
scheduleMsg(&tsLogger, "unexpected command %x", command);
|
||||||
sendErrorCode(tsChannel);
|
sendErrorCode(tsChannel, TS_RESPONSE_UNRECOGNIZED_COMMAND);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -517,9 +518,6 @@ void runBinaryProtocolLoop(ts_channel_s *tsChannel) {
|
||||||
logMsg("command %c\r\n", command);
|
logMsg("command %c\r\n", command);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// scheduleMsg(logger, "TunerStudio: reading %d+4 bytes(s)", incomingPacketSize);
|
|
||||||
|
|
||||||
received = sr5ReadData(tsChannel, (uint8_t * ) (tsChannel->crcReadBuffer + 1),
|
received = sr5ReadData(tsChannel, (uint8_t * ) (tsChannel->crcReadBuffer + 1),
|
||||||
incomingPacketSize + CRC_VALUE_SIZE - 1);
|
incomingPacketSize + CRC_VALUE_SIZE - 1);
|
||||||
int expectedSize = 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,
|
scheduleMsg(&tsLogger, "Got only %d bytes while expecting %d for command %c", received,
|
||||||
expectedSize, command);
|
expectedSize, command);
|
||||||
tunerStudioError("ERROR: not enough bytes in stream");
|
tunerStudioError("ERROR: not enough bytes in stream");
|
||||||
sendResponseCode(TS_CRC, tsChannel, TS_RESPONSE_UNDERRUN);
|
sendErrorCode(tsChannel, TS_RESPONSE_UNDERRUN);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -544,12 +542,10 @@ void runBinaryProtocolLoop(ts_channel_s *tsChannel) {
|
||||||
scheduleMsg(&tsLogger, "TunerStudio: command %c actual CRC %x/expected %x", tsChannel->crcReadBuffer[0],
|
scheduleMsg(&tsLogger, "TunerStudio: command %c actual CRC %x/expected %x", tsChannel->crcReadBuffer[0],
|
||||||
actualCrc, expectedCrc);
|
actualCrc, expectedCrc);
|
||||||
tunerStudioError("ERROR: CRC issue");
|
tunerStudioError("ERROR: CRC issue");
|
||||||
|
sendErrorCode(tsChannel, TS_RESPONSE_CRC_FAILURE);
|
||||||
continue;
|
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);
|
int success = tunerStudioHandleCrcCommand(tsChannel, tsChannel->crcReadBuffer, incomingPacketSize);
|
||||||
if (!success)
|
if (!success)
|
||||||
print("got unexpected TunerStudio command %x:%c\r\n", command, command);
|
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)) {
|
if (offset + count > sizeof(TunerStudioOutputChannels)) {
|
||||||
scheduleMsg(&tsLogger, "TS: Version Mismatch? Too much outputs requested %d/%d/%d", offset, count,
|
scheduleMsg(&tsLogger, "TS: Version Mismatch? Too much outputs requested %d/%d/%d", offset, count,
|
||||||
sizeof(TunerStudioOutputChannels));
|
sizeof(TunerStudioOutputChannels));
|
||||||
sendErrorCode(tsChannel);
|
sendErrorCode(tsChannel, TS_RESPONSE_OUT_OF_RANGE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,9 @@
|
||||||
|
|
||||||
#define TS_RESPONSE_UNDERRUN 0x80
|
#define TS_RESPONSE_UNDERRUN 0x80
|
||||||
#define TS_RESPONSE_CRC_FAILURE 0x82
|
#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 {
|
typedef enum {
|
||||||
TS_PLAIN = 0,
|
TS_PLAIN = 0,
|
||||||
|
|
Loading…
Reference in New Issue