From 10646dad40cb0a51c1f7ed58e601934b134b3664 Mon Sep 17 00:00:00 2001 From: Uwe Seimet Date: Sun, 21 Jan 2024 13:09:37 +0100 Subject: [PATCH] Initial logging --- cpp/devices/daynaport.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/cpp/devices/daynaport.cpp b/cpp/devices/daynaport.cpp index d5dce49e..ff9dd2a3 100644 --- a/cpp/devices/daynaport.cpp +++ b/cpp/devices/daynaport.cpp @@ -22,12 +22,14 @@ #include "shared/shared_exceptions.h" #include "shared/network_util.h" +#include "shared/s2p_util.h" #include "base/memory_util.h" #include "daynaport.h" using namespace scsi_defs; using namespace memory_util; using namespace network_util; +using namespace s2p_util; // The MacOS DaynaPort driver needs to have a delay after the size/flags field of the read response. // It appears as if the real DaynaPort hardware indeed has this delay. @@ -159,11 +161,14 @@ int DaynaPort::Read(cdb_t cdb, vector &buf, uint64_t) // If we didn't receive anything, return size of 0 if (rx_packet_size <= 0) { - LogTrace("No packet received"); + LogTrace("No network packet received"); response->length = 0; response->flags = read_data_flags_t::e_no_more_data; return DAYNAPORT_READ_HEADER_SZ; } + else if (spdlog::get_level() == spdlog::level::trace) { + LogTrace(fmt::format("Read {} byte(s) of network data:\n{}", rx_packet_size, FormatBytes(buf, rx_packet_size))); + } byte_read_count += rx_packet_size; @@ -207,14 +212,15 @@ int DaynaPort::Read(cdb_t cdb, vector &buf, uint64_t) //--------------------------------------------------------------------------- bool DaynaPort::Write(cdb_t cdb, span buf) { + int data_length; if (const int data_format = cdb[5]; data_format == 0x00) { - const int data_length = GetInt16(cdb, 3); + data_length = GetInt16(cdb, 3); tap.Send(buf.data(), data_length); byte_write_count += data_length; } else if (data_format == 0x80) { // The data length is specified in the first 2 bytes of the payload - const int data_length = buf[1] + ((static_cast(buf[0]) & 0xff) << 8); + data_length = buf[1] + ((static_cast(buf[0]) & 0xff) << 8); tap.Send(&(buf.data()[4]), data_length); byte_write_count += data_length; } @@ -222,6 +228,14 @@ bool DaynaPort::Write(cdb_t cdb, span buf) LogWarn(fmt::format("Unknown data format: ${:02x}", data_format)); } + if (spdlog::get_level() == spdlog::level::trace) { + vector data; + for (uint8_t b : buf) { + data.emplace_back(b); + } + LogTrace(fmt::format("Sent {} byte(s) of network data:\n{}", data_length, FormatBytes(data, data_length))); + } + GetController()->SetBlocks(0); return true;