#include "model.hpp" #include namespace clockmodel { std::vector Bus::export_snapshot(const Device& device) { std::vector values; values.reserve(5 + device.fifo.size()); for (Word word : device.regs) { values.push_back(word); } values.push_back(static_cast(device.fifo.size())); for (Word word : device.fifo) { values.push_back(word); } return values; } std::vector Bus::export_history(const Device& device, std::size_t count) { const std::size_t total = device.events.size(); const std::size_t length = std::min(count, total); const std::size_t skip = total - length; std::vector values; values.reserve(length * 2); for (std::size_t offset = skip; offset < total; ++offset) { const Event& event = device.events[offset]; values.push_back(event.reg); values.push_back(event.value); } return values; } Reply Bus::snapshot(Arg id) const { if (!valid_id(id)) { return error("ID"); } const auto index = static_cast(id); const Device& device = devices_[index]; Reply reply = success(); reply.values = export_snapshot(device); return reply; } Reply Bus::history(Arg id, Arg count) const { if (!valid_id(id)) { return error("ID"); } if (!valid_count(count, 32)) { return error("COUNT"); } const auto index = static_cast(id); const auto length = static_cast(count); const Device& device = devices_[index]; Reply reply = success(); reply.values = export_history(device, length); return reply; } }