From a4a1e39c25d960d6760e576dc5a03874a6b18ce5 Mon Sep 17 00:00:00 2001 From: Reinder Feenstra Date: Tue, 5 Dec 2023 22:48:06 +0100 Subject: [PATCH] traintasticdiy: added loggin of dropped bytes (untested) --- .../traintasticdiy/iohandler/hardwareiohandler.cpp | 5 +++-- server/src/utils/tohex.cpp | 10 +++++++--- server/src/utils/tohex.hpp | 4 ++-- shared/src/traintastic/enum/logmessage.hpp | 1 + shared/translations/en-us.json | 4 ++++ 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/server/src/hardware/protocol/traintasticdiy/iohandler/hardwareiohandler.cpp b/server/src/hardware/protocol/traintasticdiy/iohandler/hardwareiohandler.cpp index fcde6560..55f2b6a4 100644 --- a/server/src/hardware/protocol/traintasticdiy/iohandler/hardwareiohandler.cpp +++ b/server/src/hardware/protocol/traintasticdiy/iohandler/hardwareiohandler.cpp @@ -25,6 +25,7 @@ #include "../messages.hpp" #include "../../../../core/eventloop.hpp" #include "../../../../log/log.hpp" +#include "../../../../utils/tohex.hpp" namespace TraintasticDIY { @@ -75,9 +76,9 @@ void HardwareIOHandler::processRead(size_t bytesTransferred) if(drop != 0) { EventLoop::call( - [this, drop]() + [this, drop, bytes=toHex(pos - drop, drop, true)]() { - Log::log(m_kernel.logId, LogMessage::W2001_RECEIVED_MALFORMED_DATA_DROPPED_X_BYTES, drop); + Log::log(m_kernel.logId, LogMessage::W2003_RECEIVED_MALFORMED_DATA_DROPPED_X_BYTES_X, drop, bytes); }); } diff --git a/server/src/utils/tohex.cpp b/server/src/utils/tohex.cpp index f0d2d127..5ae845ed 100644 --- a/server/src/utils/tohex.cpp +++ b/server/src/utils/tohex.cpp @@ -3,7 +3,7 @@ * * This file is part of the traintastic source code. * - * Copyright (C) 2022 Reinder Feenstra + * Copyright (C) 2022-2023 Reinder Feenstra * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -23,13 +23,17 @@ #include "tohex.hpp" #include -std::string toHex(const void* buffer, const size_t size) +std::string toHex(const void* buffer, const size_t size, const bool addSpaceSeperator) { std::string s; - s.reserve(size * 2); + s.reserve(size * (addSpaceSeperator ? 3 : 2)); const uint8_t* p = reinterpret_cast(buffer); for(size_t i = 0; i < size; i++, p++) { + if(addSpaceSeperator && i != 0) + { + s.push_back(' '); + } s.push_back(toHexDigits[*p >> 4]); s.push_back(toHexDigits[*p & 0x0F]); } diff --git a/server/src/utils/tohex.hpp b/server/src/utils/tohex.hpp index a7136bbd..4c84ec1d 100644 --- a/server/src/utils/tohex.hpp +++ b/server/src/utils/tohex.hpp @@ -3,7 +3,7 @@ * * This file is part of the traintastic source code. * - * Copyright (C) 2019-2020,2022 Reinder Feenstra + * Copyright (C) 2019-2020,2022-2023 Reinder Feenstra * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -38,7 +38,7 @@ std::string toHex(T value, size_t length = sizeof(T) * 2) return s; } -std::string toHex(const void* buffer, size_t size); +std::string toHex(const void* buffer, size_t size, const bool addSpaceSeperator = false); inline std::string toHex(std::string_view value) { diff --git a/shared/src/traintastic/enum/logmessage.hpp b/shared/src/traintastic/enum/logmessage.hpp index 6e3c61c2..5396df78 100644 --- a/shared/src/traintastic/enum/logmessage.hpp +++ b/shared/src/traintastic/enum/logmessage.hpp @@ -139,6 +139,7 @@ enum class LogMessage : uint32_t W1003_READING_WORLD_X_FAILED_LIBARCHIVE_ERROR_X_X = LogMessageOffset::warning + 1003, W2001_RECEIVED_MALFORMED_DATA_DROPPED_X_BYTES = LogMessageOffset::warning + 2001, W2002_COMMAND_STATION_DOESNT_SUPPORT_FUNCTIONS_ABOVE_FX = LogMessageOffset::warning + 2002, + W2003_RECEIVED_MALFORMED_DATA_DROPPED_X_BYTES_X = LogMessageOffset::warning + 2003, W2004_INPUT_ADDRESS_X_IS_INVALID = LogMessageOffset::warning + 2004, W2005_OUTPUT_ADDRESS_X_IS_INVALID = LogMessageOffset::warning + 2005, W2006_COMMAND_STATION_DOES_NOT_SUPPORT_LOCO_SLOT_X = LogMessageOffset::warning + 2006, diff --git a/shared/translations/en-us.json b/shared/translations/en-us.json index 15e0e523..2ca26aff 100644 --- a/shared/translations/en-us.json +++ b/shared/translations/en-us.json @@ -2599,6 +2599,10 @@ "reference": "", "comment": "" }, + { + "term": "message:W2003", + "definition": "Received malformed data dropped %1 bytes [%2]" + }, { "term": "message:W2004", "definition": "Input address %1 is invalid",