Skip to content

Commit

Permalink
Initial logging
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Jan 21, 2024
1 parent f216589 commit 10646da
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions cpp/devices/daynaport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -159,11 +161,14 @@ int DaynaPort::Read(cdb_t cdb, vector<uint8_t> &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;

Expand Down Expand Up @@ -207,21 +212,30 @@ int DaynaPort::Read(cdb_t cdb, vector<uint8_t> &buf, uint64_t)
//---------------------------------------------------------------------------
bool DaynaPort::Write(cdb_t cdb, span<const uint8_t> 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<int>(buf[0]) & 0xff) << 8);
data_length = buf[1] + ((static_cast<int>(buf[0]) & 0xff) << 8);
tap.Send(&(buf.data()[4]), data_length);
byte_write_count += data_length;
}
else {
LogWarn(fmt::format("Unknown data format: ${:02x}", data_format));
}

if (spdlog::get_level() == spdlog::level::trace) {
vector<uint8_t> 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;
Expand Down

0 comments on commit 10646da

Please sign in to comment.