From 847fb75a23246abddcfb22f4bfc3588ff04e4fe7 Mon Sep 17 00:00:00 2001 From: rusefillc Date: Sat, 18 Sep 2021 15:33:14 -0400 Subject: [PATCH] TS channel names for nicer console messages --- firmware/console/binary/tunerstudio.cpp | 2 +- firmware/console/binary/tunerstudio_io.cpp | 4 ++++ firmware/console/binary/tunerstudio_io.h | 7 +++++-- firmware/console/usb_console.cpp | 2 +- unit_tests/tests/test_tunerstudio.cpp | 2 ++ 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/firmware/console/binary/tunerstudio.cpp b/firmware/console/binary/tunerstudio.cpp index bc39314893..d15263344b 100644 --- a/firmware/console/binary/tunerstudio.cpp +++ b/firmware/console/binary/tunerstudio.cpp @@ -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; diff --git a/firmware/console/binary/tunerstudio_io.cpp b/firmware/console/binary/tunerstudio_io.cpp index 57814d480c..a1bce6c007 100644 --- a/firmware/console/binary/tunerstudio_io.cpp +++ b/firmware/console/binary/tunerstudio_io.cpp @@ -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. */ diff --git a/firmware/console/binary/tunerstudio_io.h b/firmware/console/binary/tunerstudio_io.h index 66a14b09c9..2b37cd401d 100644 --- a/firmware/console/binary/tunerstudio_io.h +++ b/firmware/console/binary/tunerstudio_io.h @@ -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; diff --git a/firmware/console/usb_console.cpp b/firmware/console/usb_console.cpp index 395c4a214e..1d8022c145 100644 --- a/firmware/console/usb_console.cpp +++ b/firmware/console/usb_console.cpp @@ -15,7 +15,7 @@ extern SerialUSBDriver EFI_CONSOLE_USB_DEVICE; class UsbChannel : public TsChannelBase { public: UsbChannel(SerialUSBDriver& driver) - : m_channel(reinterpret_cast(&driver)) + : TsChannelBase("USB"), m_channel(reinterpret_cast(&driver)) { } diff --git a/unit_tests/tests/test_tunerstudio.cpp b/unit_tests/tests/test_tunerstudio.cpp index efe4ff5f36..9620ebb200 100644 --- a/unit_tests/tests/test_tunerstudio.cpp +++ b/unit_tests/tests/test_tunerstudio.cpp @@ -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;