Replaced RetrieveTargetPinStates event with TC command

This commit is contained in:
Nav
2022-05-01 00:07:12 +01:00
parent 7c4e39dd03
commit 870c4ba3d7
10 changed files with 75 additions and 64 deletions

View File

@@ -32,7 +32,6 @@ namespace Bloom::Events
EXTRACT_TARGET_DESCRIPTOR, EXTRACT_TARGET_DESCRIPTOR,
TARGET_DESCRIPTOR_EXTRACTED, TARGET_DESCRIPTOR_EXTRACTED,
INSIGHT_THREAD_STATE_CHANGED, INSIGHT_THREAD_STATE_CHANGED,
RETRIEVE_TARGET_PIN_STATES,
TARGET_PIN_STATES_RETRIEVED, TARGET_PIN_STATES_RETRIEVED,
SET_TARGET_PIN_STATE, SET_TARGET_PIN_STATE,
RETRIEVE_STACK_POINTER_FROM_TARGET, RETRIEVE_STACK_POINTER_FROM_TARGET,

View File

@@ -19,7 +19,6 @@
#include "ExtractTargetDescriptor.hpp" #include "ExtractTargetDescriptor.hpp"
#include "TargetDescriptorExtracted.hpp" #include "TargetDescriptorExtracted.hpp"
#include "InsightThreadStateChanged.hpp" #include "InsightThreadStateChanged.hpp"
#include "RetrieveTargetPinStates.hpp"
#include "TargetPinStatesRetrieved.hpp" #include "TargetPinStatesRetrieved.hpp"
#include "SetTargetPinState.hpp" #include "SetTargetPinState.hpp"
#include "RetrieveStackPointerFromTarget.hpp" #include "RetrieveStackPointerFromTarget.hpp"

View File

@@ -1,27 +0,0 @@
#pragma once
#include <string>
#include "Event.hpp"
#include "TargetPinStatesRetrieved.hpp"
namespace Bloom::Events
{
class RetrieveTargetPinStates: public Event
{
public:
using TargetControllerResponseType = TargetPinStatesRetrieved;
static constexpr EventType type = EventType::RETRIEVE_TARGET_PIN_STATES;
static inline const std::string name = "RetrieveTargetPinStates";
int variantId = 0;
[[nodiscard]] EventType getType() const override {
return RetrieveTargetPinStates::type;
}
[[nodiscard]] std::string getName() const override {
return RetrieveTargetPinStates::name;
}
};
}

View File

@@ -20,5 +20,6 @@ namespace Bloom::TargetController::Commands
SET_BREAKPOINT, SET_BREAKPOINT,
REMOVE_BREAKPOINT, REMOVE_BREAKPOINT,
SET_PROGRAM_COUNTER, SET_PROGRAM_COUNTER,
GET_TARGET_PIN_STATES,
}; };
} }

View File

@@ -0,0 +1,31 @@
#pragma once
#include "Command.hpp"
#include "src/TargetController/Responses/TargetPinStates.hpp"
namespace Bloom::TargetController::Commands
{
class GetTargetPinStates: public Command
{
public:
using SuccessResponseType = Responses::TargetPinStates;
static constexpr CommandType type = CommandType::GET_TARGET_PIN_STATES;
static inline const std::string name = "GetTargetPinStates";
int variantId = 0;
explicit GetTargetPinStates(int variantId)
: variantId(variantId)
{};
[[nodiscard]] CommandType getType() const override {
return GetTargetPinStates::type;
}
[[nodiscard]] bool requiresStoppedTargetState() const override {
return true;
}
};
}

View File

@@ -11,5 +11,6 @@ namespace Bloom::TargetController::Responses
TARGET_REGISTERS_READ, TARGET_REGISTERS_READ,
TARGET_MEMORY_READ, TARGET_MEMORY_READ,
TARGET_STATE, TARGET_STATE,
TARGET_PIN_STATES,
}; };
} }

View File

@@ -0,0 +1,24 @@
#pragma once
#include "Response.hpp"
#include "src/Targets/TargetPinDescriptor.hpp"
namespace Bloom::TargetController::Responses
{
class TargetPinStates: public Response
{
public:
static constexpr ResponseType type = ResponseType::TARGET_PIN_STATES;
Targets::TargetPinStateMappingType pinStatesByNumber;
explicit TargetPinStates(const Targets::TargetPinStateMappingType& pinStatesByNumber)
: pinStatesByNumber(pinStatesByNumber)
{}
[[nodiscard]] ResponseType getType() const override {
return TargetPinStates::type;
}
};
}

View File

@@ -34,10 +34,12 @@ namespace Bloom::TargetController
using Commands::SetBreakpoint; using Commands::SetBreakpoint;
using Commands::RemoveBreakpoint; using Commands::RemoveBreakpoint;
using Commands::SetProgramCounter; using Commands::SetProgramCounter;
using Commands::GetTargetPinStates;
using Responses::Response; using Responses::Response;
using Responses::TargetRegistersRead; using Responses::TargetRegistersRead;
using Responses::TargetMemoryRead; using Responses::TargetMemoryRead;
using Responses::TargetPinStates;
TargetControllerComponent::TargetControllerComponent( TargetControllerComponent::TargetControllerComponent(
const ProjectConfig& projectConfig, const ProjectConfig& projectConfig,
@@ -399,11 +401,11 @@ namespace Bloom::TargetController
this->deregisterCommandHandler(SetBreakpoint::type); this->deregisterCommandHandler(SetBreakpoint::type);
this->deregisterCommandHandler(RemoveBreakpoint::type); this->deregisterCommandHandler(RemoveBreakpoint::type);
this->deregisterCommandHandler(SetProgramCounter::type); this->deregisterCommandHandler(SetProgramCounter::type);
this->deregisterCommandHandler(GetTargetPinStates::type);
this->eventListener->deregisterCallbacksForEventType<Events::DebugSessionFinished>(); this->eventListener->deregisterCallbacksForEventType<Events::DebugSessionFinished>();
this->eventListener->deregisterCallbacksForEventType<Events::ExtractTargetDescriptor>(); this->eventListener->deregisterCallbacksForEventType<Events::ExtractTargetDescriptor>();
this->eventListener->deregisterCallbacksForEventType<Events::InsightThreadStateChanged>(); this->eventListener->deregisterCallbacksForEventType<Events::InsightThreadStateChanged>();
this->eventListener->deregisterCallbacksForEventType<Events::RetrieveTargetPinStates>();
this->eventListener->deregisterCallbacksForEventType<Events::SetTargetPinState>(); this->eventListener->deregisterCallbacksForEventType<Events::SetTargetPinState>();
this->eventListener->deregisterCallbacksForEventType<Events::RetrieveStackPointerFromTarget>(); this->eventListener->deregisterCallbacksForEventType<Events::RetrieveStackPointerFromTarget>();
@@ -470,6 +472,10 @@ namespace Bloom::TargetController
std::bind(&TargetControllerComponent::handleSetProgramCounter, this, std::placeholders::_1) std::bind(&TargetControllerComponent::handleSetProgramCounter, this, std::placeholders::_1)
); );
this->registerCommandHandler<GetTargetPinStates>(
std::bind(&TargetControllerComponent::handleGetTargetPinStates, this, std::placeholders::_1)
);
this->eventListener->registerCallbackForEventType<Events::DebugSessionFinished>( this->eventListener->registerCallbackForEventType<Events::DebugSessionFinished>(
std::bind(&TargetControllerComponent::onDebugSessionFinishedEvent, this, std::placeholders::_1) std::bind(&TargetControllerComponent::onDebugSessionFinishedEvent, this, std::placeholders::_1)
); );
@@ -478,10 +484,6 @@ namespace Bloom::TargetController
std::bind(&TargetControllerComponent::onExtractTargetDescriptor, this, std::placeholders::_1) std::bind(&TargetControllerComponent::onExtractTargetDescriptor, this, std::placeholders::_1)
); );
this->eventListener->registerCallbackForEventType<Events::RetrieveTargetPinStates>(
std::bind(&TargetControllerComponent::onRetrieveTargetPinStatesEvent, this, std::placeholders::_1)
);
this->eventListener->registerCallbackForEventType<Events::SetTargetPinState>( this->eventListener->registerCallbackForEventType<Events::SetTargetPinState>(
std::bind(&TargetControllerComponent::onSetPinStateEvent, this, std::placeholders::_1) std::bind(&TargetControllerComponent::onSetPinStateEvent, this, std::placeholders::_1)
); );
@@ -877,25 +879,8 @@ namespace Bloom::TargetController
return std::make_unique<Response>(); return std::make_unique<Response>();
} }
void TargetControllerComponent::onRetrieveTargetPinStatesEvent(const Events::RetrieveTargetPinStates& event) { std::unique_ptr<TargetPinStates> TargetControllerComponent::handleGetTargetPinStates(GetTargetPinStates& command) {
try { return std::make_unique<TargetPinStates>(this->target->getPinStates(command.variantId));
if (this->target->getState() != TargetState::STOPPED) {
throw TargetOperationFailure(
"Invalid target state - target must be stopped before pin states can be retrieved"
);
}
auto pinStatesRetrieved = std::make_shared<Events::TargetPinStatesRetrieved>();
pinStatesRetrieved->correlationId = event.id;
pinStatesRetrieved->variantId = event.variantId;
pinStatesRetrieved->pinSatesByNumber = this->target->getPinStates(event.variantId);
EventManager::triggerEvent(pinStatesRetrieved);
} catch (const TargetOperationFailure& exception) {
Logger::error("Failed to retrieve target pin states - " + exception.getMessage());
this->emitErrorEvent(event.id, exception.getMessage());
}
} }
void TargetControllerComponent::onSetPinStateEvent(const Events::SetTargetPinState& event) { void TargetControllerComponent::onSetPinStateEvent(const Events::SetTargetPinState& event) {

View File

@@ -30,12 +30,14 @@
#include "Commands/SetBreakpoint.hpp" #include "Commands/SetBreakpoint.hpp"
#include "Commands/RemoveBreakpoint.hpp" #include "Commands/RemoveBreakpoint.hpp"
#include "Commands/SetProgramCounter.hpp" #include "Commands/SetProgramCounter.hpp"
#include "Commands/GetTargetPinStates.hpp"
// Responses // Responses
#include "Responses/Response.hpp" #include "Responses/Response.hpp"
#include "Responses/TargetState.hpp" #include "Responses/TargetState.hpp"
#include "Responses/TargetRegistersRead.hpp" #include "Responses/TargetRegistersRead.hpp"
#include "Responses/TargetMemoryRead.hpp" #include "Responses/TargetMemoryRead.hpp"
#include "Responses/TargetPinStates.hpp"
#include "TargetControllerState.hpp" #include "TargetControllerState.hpp"
@@ -312,13 +314,7 @@ namespace Bloom::TargetController
std::unique_ptr<Responses::Response> handleSetBreakpoint(Commands::SetBreakpoint& command); std::unique_ptr<Responses::Response> handleSetBreakpoint(Commands::SetBreakpoint& command);
std::unique_ptr<Responses::Response> handleRemoveBreakpoint(Commands::RemoveBreakpoint& command); std::unique_ptr<Responses::Response> handleRemoveBreakpoint(Commands::RemoveBreakpoint& command);
std::unique_ptr<Responses::Response> handleSetProgramCounter(Commands::SetProgramCounter& command); std::unique_ptr<Responses::Response> handleSetProgramCounter(Commands::SetProgramCounter& command);
std::unique_ptr<Responses::TargetPinStates> handleGetTargetPinStates(Commands::GetTargetPinStates& command);
/**
* Will attempt to obtain the pin states from the target. Will emit a TargetPinStatesRetrieved event on success.
*
* @param event
*/
void onRetrieveTargetPinStatesEvent(const Events::RetrieveTargetPinStates& event);
/** /**
* Will update a pin state for a particular pin. Will emit a TargetPinStatesRetrieved with the new pin * Will update a pin state for a particular pin. Will emit a TargetPinStatesRetrieved with the new pin

View File

@@ -17,6 +17,7 @@
#include "Commands/SetBreakpoint.hpp" #include "Commands/SetBreakpoint.hpp"
#include "Commands/RemoveBreakpoint.hpp" #include "Commands/RemoveBreakpoint.hpp"
#include "Commands/SetProgramCounter.hpp" #include "Commands/SetProgramCounter.hpp"
#include "Commands/GetTargetPinStates.hpp"
#include "src/Logger/Logger.hpp" #include "src/Logger/Logger.hpp"
@@ -38,6 +39,7 @@ namespace Bloom::TargetController
using Commands::SetBreakpoint; using Commands::SetBreakpoint;
using Commands::RemoveBreakpoint; using Commands::RemoveBreakpoint;
using Commands::SetProgramCounter; using Commands::SetProgramCounter;
using Commands::GetTargetPinStates;
TargetControllerConsole::TargetControllerConsole(EventListener& eventListener) TargetControllerConsole::TargetControllerConsole(EventListener& eventListener)
: eventListener(eventListener) : eventListener(eventListener)
@@ -166,10 +168,10 @@ namespace Bloom::TargetController
} }
Targets::TargetPinStateMappingType TargetControllerConsole::getPinStates(int variantId) { Targets::TargetPinStateMappingType TargetControllerConsole::getPinStates(int variantId) {
auto requestEvent = std::make_shared<RetrieveTargetPinStates>(); return this->commandManager.sendCommandAndWaitForResponse(
requestEvent->variantId = variantId; std::make_unique<GetTargetPinStates>(variantId),
this->defaultTimeout
return this->triggerTargetControllerEventAndWaitForResponse(requestEvent)->pinSatesByNumber; )->pinStatesByNumber;
} }
void TargetControllerConsole::setPinState(TargetPinDescriptor pinDescriptor, TargetPinState pinState) { void TargetControllerConsole::setPinState(TargetPinDescriptor pinDescriptor, TargetPinState pinState) {