mirror of
https://github.com/akuker/RASCSI.git
synced 2026-10-26 04:02:17 +00:00
Move GPIO mappings into a single module and select a board profile at process startup instead of at compile time: Build every GPIO-facing utility for every supported profile. At the same time, we remove support for the historical AIBOM board type since it's the only one using positive logic, the other three variants share the same electrical behavior. Run piscsi, scsimon, scsiloop, scsidump, or sasidump with -C=STANDARD, FULLSPEC, or GAMERNIUM. FULLSPEC remains the default. To select a profile for the systemd service, set PISCSI_CONNECTION_TYPE and restart the service.
113 lines
3.8 KiB
C++
113 lines
3.8 KiB
C++
//---------------------------------------------------------------------------
|
|
//
|
|
// SCSI Target Emulator PiSCSI
|
|
// for Raspberry Pi
|
|
//
|
|
// Powered by XM6 TypeG Technology.
|
|
// Copyright (C) 2016-2020 GIMONS
|
|
// Copyright (C) 2021-2022 akuker
|
|
//
|
|
//---------------------------------------------------------------------------
|
|
|
|
#include "hal/data_sample_raspberry.h"
|
|
#include "hal/connection_profile.h"
|
|
#include "hal/log.h"
|
|
#include "sm_reports.h"
|
|
#include "string.h"
|
|
#include <fstream>
|
|
#include <iostream>
|
|
|
|
using namespace std;
|
|
|
|
const string timestamp_label = "\"timestamp\":\"0x";
|
|
const string data_label = "\"data\":\"0x";
|
|
const string connection_type_label = "\"connection_type\":\"";
|
|
|
|
uint32_t scsimon_read_json(const string& json_filename, vector<shared_ptr<DataSample>>& data_capture_array)
|
|
{
|
|
std::ifstream json_file(json_filename);
|
|
uint32_t sample_count = 0;
|
|
|
|
while (json_file) {
|
|
string str_buf;
|
|
std::getline(json_file, str_buf);
|
|
|
|
if (const size_t connection_type_pos = str_buf.find(connection_type_label);
|
|
connection_type_pos != string::npos) {
|
|
const size_t value_start = connection_type_pos + connection_type_label.length();
|
|
const size_t value_end = str_buf.find('"', value_start);
|
|
if (value_end != string::npos) {
|
|
string error;
|
|
if (!SetConnectionType(str_buf.substr(value_start, value_end - value_start), error)) {
|
|
spdlog::warn("Ignoring invalid connection type in capture file: " + error);
|
|
}
|
|
}
|
|
continue;
|
|
}
|
|
string timestamp;
|
|
string data;
|
|
uint64_t timestamp_uint;
|
|
uint32_t data_uint;
|
|
char* ptr;
|
|
|
|
size_t timestamp_pos = str_buf.find(timestamp_label);
|
|
if (timestamp_pos == string::npos)
|
|
continue;
|
|
timestamp = str_buf.substr(timestamp_pos + timestamp_label.length(), 16);
|
|
timestamp_uint = strtoull(timestamp.c_str(), &ptr, 16);
|
|
|
|
size_t data_pos = str_buf.find(data_label);
|
|
if (data_pos == string::npos)
|
|
continue;
|
|
data = str_buf.substr(data_pos + data_label.length(), 8);
|
|
data_uint = static_cast<uint32_t>(strtoul(data.c_str(), &ptr, 16));
|
|
|
|
// For reading in JSON files, we'll just assume raspberry pi data types
|
|
data_capture_array.push_back(make_unique<DataSample_Raspberry>(data_uint, timestamp_uint));
|
|
|
|
sample_count++;
|
|
if (sample_count == UINT32_MAX) {
|
|
spdlog::warn("Maximum number of samples read. Some data may not be included.");
|
|
break;
|
|
}
|
|
}
|
|
|
|
json_file.close();
|
|
|
|
return sample_count;
|
|
}
|
|
|
|
//---------------------------------------------------------------------------
|
|
//
|
|
// Generate JSON Output File
|
|
//
|
|
//---------------------------------------------------------------------------
|
|
void scsimon_generate_json(const string& filename, const vector<shared_ptr<DataSample>>& data_capture_array)
|
|
{
|
|
spdlog::trace("Creating JSON file (" + filename + ")");
|
|
ofstream json_ofstream;
|
|
json_ofstream.open(filename.c_str(), ios::out);
|
|
|
|
json_ofstream << "[" << endl;
|
|
json_ofstream << "{\"connection_type\":\"" << GetConnectionProfile().name << "\"}";
|
|
if (!data_capture_array.empty()) {
|
|
json_ofstream << ",";
|
|
}
|
|
json_ofstream << endl;
|
|
|
|
size_t i = 0;
|
|
size_t capture_count = data_capture_array.size();
|
|
for (auto data : data_capture_array) {
|
|
json_ofstream << fmt::format("{{\"id\": \"{0:d}\", \"timestamp\":\"{1:#016x}\", \"data\":\"{2:#08x}\"}}", i,
|
|
data->GetTimestamp(), data->GetRawCapture());
|
|
|
|
if (i != (capture_count - 1)) {
|
|
json_ofstream << ",";
|
|
}
|
|
json_ofstream << endl;
|
|
i++;
|
|
}
|
|
json_ofstream << "]" << endl;
|
|
json_ofstream.close();
|
|
}
|