Refactored CMSIS-DAP Response command classes and introduced the ExpectedResponseType alias in CMSIS-DAP commands.

This commit is contained in:
Nav
2022-02-28 16:27:24 +00:00
parent 081fba5cbd
commit 5aa233eec7
16 changed files with 137 additions and 116 deletions

View File

@@ -3,8 +3,6 @@
#include <thread>
#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/Command.hpp"
#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/Response.hpp"
#include "src/TargetController/Exceptions/DeviceCommunicationFailure.hpp"
namespace Bloom::DebugToolDrivers::Protocols::CmsisDap
{
@@ -25,28 +23,4 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap
this->getUsbHidInterface().write(static_cast<std::vector<unsigned char>>(cmsisDapCommand));
}
std::unique_ptr<Response> CmsisDapInterface::getResponse() {
auto rawResponse = this->getUsbHidInterface().read(10000);
if (rawResponse.empty()) {
throw DeviceCommunicationFailure("Empty CMSIS-DAP response received");
}
auto response = std::make_unique<Response>(Response());
response->init(rawResponse);
return response;
}
std::unique_ptr<Response> CmsisDapInterface::sendCommandAndWaitForResponse(const Command& cmsisDapCommand) {
this->sendCommand(cmsisDapCommand);
auto response = this->getResponse();
if (response->getResponseId() != cmsisDapCommand.getCommandId()) {
// This response is not what we were expecting
throw DeviceCommunicationFailure("Unexpected response to CMSIS-DAP command.");
}
return response;
}
}