Refactored Insight GUI to accommodate the many changes made to Bloom's internals

Also lots of tidying.
This commit is contained in:
Nav
2024-12-24 18:27:59 +00:00
parent 28e0a6d9e4
commit 7fe5b88dd8
195 changed files with 3449 additions and 3171 deletions

View File

@@ -1,18 +1,52 @@
#include "WriteTargetMemory.hpp"
#include <cmath>
#include <QLocale>
#include <algorithm>
#include <numeric>
#include "src/Exceptions/Exception.hpp"
using Services::TargetControllerService;
using Targets::TargetMemorySize;
WriteTargetMemory::WriteTargetMemory(
const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor,
const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor,
std::vector<Block>&& blocks
)
: addressSpaceDescriptor(addressSpaceDescriptor)
, memorySegmentDescriptor(memorySegmentDescriptor)
, blocks(std::move(blocks))
{}
WriteTargetMemory::WriteTargetMemory(
const Targets::TargetAddressSpaceDescriptor& addressSpaceDescriptor,
const Targets::TargetMemorySegmentDescriptor& memorySegmentDescriptor,
Targets::TargetMemoryAddress startAddress,
const Targets::TargetMemoryBuffer& data
)
: WriteTargetMemory(
addressSpaceDescriptor,
memorySegmentDescriptor,
std::vector<Block>{{startAddress, data}}
)
{}
QString WriteTargetMemory::brief() const {
return "Writing " + QLocale{QLocale::English}.toString(this->totalSize()) + " byte(s) to \""
+ QString::fromStdString(this->memorySegmentDescriptor.name) + "\"";
}
TaskGroups WriteTargetMemory::taskGroups() const {
return {
TaskGroup::USES_TARGET_CONTROLLER,
};
}
void WriteTargetMemory::run(TargetControllerService& targetControllerService) {
using Targets::TargetMemorySize;
if (!this->memoryDescriptor.access.writeableDuringDebugSession) {
throw Exceptions::Exception("Invalid request - cannot write to this memory type during a debug session.");
if (!this->memorySegmentDescriptor.debugModeAccess.writeable) {
throw Exceptions::Exception{"Invalid request - cannot write to this memory segment during a debug session."};
}
/*
@@ -23,20 +57,12 @@ void WriteTargetMemory::run(TargetControllerService& targetControllerService) {
* command timeouts when we're writing lots of data.
*/
const auto maxBlockSize = std::max(
TargetMemorySize(256),
this->memoryDescriptor.pageSize.value_or(TargetMemorySize(0))
TargetMemorySize{256},
this->memorySegmentDescriptor.pageSize.value_or(TargetMemorySize{0})
);
const TargetMemorySize totalBytesToWrite = std::accumulate(
this->blocks.begin(),
this->blocks.end(),
TargetMemorySize{0},
[] (TargetMemorySize bytes, const Block& block) {
return bytes + block.data.size();
}
);
TargetMemorySize totalBytesWritten = 0;
const auto writeSize = this->totalSize();
auto totalBytesWritten = TargetMemorySize{0};
for (const auto& block : this->blocks) {
const auto totalBytes = block.data.size();
@@ -50,22 +76,34 @@ void WriteTargetMemory::run(TargetControllerService& targetControllerService) {
);
targetControllerService.writeMemory(
this->memoryDescriptor.type,
this->addressSpaceDescriptor,
this->memorySegmentDescriptor,
block.startAddress + bytesWritten,
Targets::TargetMemoryBuffer(
Targets::TargetMemoryBuffer{
block.data.begin() + bytesWritten,
block.data.begin() + bytesWritten + bytesToWrite
)
}
);
bytesWritten += bytesToWrite;
totalBytesWritten += bytesToWrite;
this->setProgressPercentage(static_cast<std::uint8_t>(
(static_cast<float>(totalBytesWritten) + 1) / (static_cast<float>(totalBytesToWrite) / 100)
(static_cast<float>(totalBytesWritten) + 1) / (static_cast<float>(writeSize) / 100)
));
}
}
emit this->targetMemoryWritten(totalBytesWritten);
}
TargetMemorySize WriteTargetMemory::totalSize() const {
return std::accumulate(
this->blocks.begin(),
this->blocks.end(),
TargetMemorySize{0},
[] (TargetMemorySize bytes, const Block& block) {
return bytes + block.data.size();
}
);
}