TS channel names for nicer console messages

This commit is contained in:
rusefillc 2021-09-18 15:33:14 -04:00
parent 5ffa84233f
commit 847fb75a23
5 changed files with 13 additions and 4 deletions

View File

@ -469,7 +469,7 @@ static int tsProcessOne(TsChannelBase* tsChannel) {
uint16_t incomingPacketSize = firstByte << 8 | secondByte;
if (incomingPacketSize == 0 || incomingPacketSize > (sizeof(tsChannel->scratchBuffer) - CRC_WRAPPING_SIZE)) {
efiPrintf("TunerStudio: invalid size: %d", incomingPacketSize);
efiPrintf("TunerStudio: %s invalid size: %d", tsChannel->name, incomingPacketSize);
tunerStudioError("ERROR: CRC header size");
sendErrorCode(tsChannel, TS_RESPONSE_UNDERRUN);
return -1;

View File

@ -73,6 +73,10 @@ void TsChannelBase::writeCrcPacketLarge(uint8_t responseCode, const uint8_t* buf
write(crcBuffer, sizeof(crcBuffer));
}
TsChannelBase::TsChannelBase(const char *name) {
this->name = name;
}
/**
* Adds size to the beginning of a packet and a crc32 at the end. Then send the packet.
*/

View File

@ -36,6 +36,7 @@ typedef enum {
class TsChannelBase {
public:
TsChannelBase(const char *name);
// Virtual functions - implement these for your underlying transport
virtual void write(const uint8_t* buffer, size_t size) = 0;
virtual size_t readTimeout(uint8_t* buffer, size_t size, int timeout) = 0;
@ -59,6 +60,7 @@ public:
* See 'blockingFactor' in rusefi.ini
*/
char scratchBuffer[BLOCKING_FACTOR + 30];
const char *name;
private:
void writeCrcPacketSmall(uint8_t responseCode, const uint8_t* buf, size_t size);
@ -68,6 +70,7 @@ private:
// This class represents a channel for a physical async serial poart
class SerialTsChannelBase : public TsChannelBase {
public:
SerialTsChannelBase(const char *name) : TsChannelBase(name) {};
// Open the serial port with the specified baud rate
virtual void start(uint32_t baud) = 0;
};
@ -76,7 +79,7 @@ public:
// This class implements a ChibiOS Serial Driver
class SerialTsChannel : public SerialTsChannelBase {
public:
SerialTsChannel(SerialDriver& driver) : m_driver(&driver) { }
SerialTsChannel(SerialDriver& driver) : SerialTsChannelBase("Serial"), m_driver(&driver) { }
void start(uint32_t baud) override;
void stop() override;
@ -93,7 +96,7 @@ private:
// This class implements a ChibiOS UART Driver
class UartTsChannel : public SerialTsChannelBase {
public:
UartTsChannel(UARTDriver& driver) : m_driver(&driver) { }
UartTsChannel(UARTDriver& driver) : SerialTsChannelBase("UART"), m_driver(&driver) { }
void start(uint32_t baud) override;
void stop() override;

View File

@ -15,7 +15,7 @@ extern SerialUSBDriver EFI_CONSOLE_USB_DEVICE;
class UsbChannel : public TsChannelBase {
public:
UsbChannel(SerialUSBDriver& driver)
: m_channel(reinterpret_cast<BaseChannel*>(&driver))
: TsChannelBase("USB"), m_channel(reinterpret_cast<BaseChannel*>(&driver))
{
}

View File

@ -5,6 +5,8 @@ static uint8_t st5TestBuffer[16000];
class MockTsChannel : public TsChannelBase {
public:
MockTsChannel() : TsChannelBase("Test") { }
void write(const uint8_t* buffer, size_t size) override {
memcpy(&st5TestBuffer[writeIdx], buffer, size);
writeIdx += size;