Replaced SetTargetPinState event with TC command

This commit is contained in:
Nav
2022-05-01 17:33:09 +01:00
parent 870c4ba3d7
commit 1072534809
9 changed files with 52 additions and 102 deletions

View File

@@ -32,8 +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,
TARGET_PIN_STATES_RETRIEVED,
SET_TARGET_PIN_STATE,
RETRIEVE_STACK_POINTER_FROM_TARGET, RETRIEVE_STACK_POINTER_FROM_TARGET,
STACK_POINTER_RETRIEVED_FROM_TARGET, STACK_POINTER_RETRIEVED_FROM_TARGET,
TARGET_RESET, TARGET_RESET,

View File

@@ -19,8 +19,6 @@
#include "ExtractTargetDescriptor.hpp" #include "ExtractTargetDescriptor.hpp"
#include "TargetDescriptorExtracted.hpp" #include "TargetDescriptorExtracted.hpp"
#include "InsightThreadStateChanged.hpp" #include "InsightThreadStateChanged.hpp"
#include "TargetPinStatesRetrieved.hpp"
#include "SetTargetPinState.hpp"
#include "RetrieveStackPointerFromTarget.hpp" #include "RetrieveStackPointerFromTarget.hpp"
#include "StackPointerRetrievedFromTarget.hpp" #include "StackPointerRetrievedFromTarget.hpp"
#include "TargetReset.hpp" #include "TargetReset.hpp"

View File

@@ -1,29 +0,0 @@
#pragma once
#include <string>
#include "Event.hpp"
#include "TargetPinStatesRetrieved.hpp"
#include "src/Targets/TargetPinDescriptor.hpp"
namespace Bloom::Events
{
class SetTargetPinState: public Event
{
public:
using TargetControllerResponseType = TargetPinStatesRetrieved;
static constexpr EventType type = EventType::SET_TARGET_PIN_STATE;
static inline const std::string name = "SetTargetPinState";
Targets::TargetPinDescriptor pinDescriptor;
Targets::TargetPinState pinState;
[[nodiscard]] EventType getType() const override {
return SetTargetPinState::type;
}
[[nodiscard]] std::string getName() const override {
return SetTargetPinState::name;
}
};
}

View File

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

View File

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

View File

@@ -0,0 +1,34 @@
#pragma once
#include "Command.hpp"
#include "src/Targets/TargetPinDescriptor.hpp"
namespace Bloom::TargetController::Commands
{
class SetTargetPinState: public Command
{
public:
static constexpr CommandType type = CommandType::SET_TARGET_PIN_STATE;
static inline const std::string name = "SetTargetPinState";
Targets::TargetPinDescriptor pinDescriptor;
Targets::TargetPinState pinState;
SetTargetPinState(
const Targets::TargetPinDescriptor& pinDescriptor,
const Targets::TargetPinState& pinState
)
: pinDescriptor(pinDescriptor)
, pinState(pinState)
{};
[[nodiscard]] CommandType getType() const override {
return SetTargetPinState::type;
}
[[nodiscard]] bool requiresStoppedTargetState() const override {
return true;
}
};
}

View File

@@ -35,6 +35,7 @@ namespace Bloom::TargetController
using Commands::RemoveBreakpoint; using Commands::RemoveBreakpoint;
using Commands::SetProgramCounter; using Commands::SetProgramCounter;
using Commands::GetTargetPinStates; using Commands::GetTargetPinStates;
using Commands::SetTargetPinState;
using Responses::Response; using Responses::Response;
using Responses::TargetRegistersRead; using Responses::TargetRegistersRead;
@@ -402,11 +403,11 @@ namespace Bloom::TargetController
this->deregisterCommandHandler(RemoveBreakpoint::type); this->deregisterCommandHandler(RemoveBreakpoint::type);
this->deregisterCommandHandler(SetProgramCounter::type); this->deregisterCommandHandler(SetProgramCounter::type);
this->deregisterCommandHandler(GetTargetPinStates::type); this->deregisterCommandHandler(GetTargetPinStates::type);
this->deregisterCommandHandler(SetTargetPinState::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::SetTargetPinState>();
this->eventListener->deregisterCallbacksForEventType<Events::RetrieveStackPointerFromTarget>(); this->eventListener->deregisterCallbacksForEventType<Events::RetrieveStackPointerFromTarget>();
this->lastTargetState = TargetState::UNKNOWN; this->lastTargetState = TargetState::UNKNOWN;
@@ -476,6 +477,10 @@ namespace Bloom::TargetController
std::bind(&TargetControllerComponent::handleGetTargetPinStates, this, std::placeholders::_1) std::bind(&TargetControllerComponent::handleGetTargetPinStates, this, std::placeholders::_1)
); );
this->registerCommandHandler<SetTargetPinState>(
std::bind(&TargetControllerComponent::handleSetTargetPinState, 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)
); );
@@ -484,10 +489,6 @@ namespace Bloom::TargetController
std::bind(&TargetControllerComponent::onExtractTargetDescriptor, this, std::placeholders::_1) std::bind(&TargetControllerComponent::onExtractTargetDescriptor, this, std::placeholders::_1)
); );
this->eventListener->registerCallbackForEventType<Events::SetTargetPinState>(
std::bind(&TargetControllerComponent::onSetPinStateEvent, this, std::placeholders::_1)
);
this->eventListener->registerCallbackForEventType<Events::RetrieveStackPointerFromTarget>( this->eventListener->registerCallbackForEventType<Events::RetrieveStackPointerFromTarget>(
std::bind(&TargetControllerComponent::onRetrieveStackPointerEvent, this, std::placeholders::_1) std::bind(&TargetControllerComponent::onRetrieveStackPointerEvent, this, std::placeholders::_1)
); );
@@ -883,30 +884,9 @@ namespace Bloom::TargetController
return std::make_unique<TargetPinStates>(this->target->getPinStates(command.variantId)); return std::make_unique<TargetPinStates>(this->target->getPinStates(command.variantId));
} }
void TargetControllerComponent::onSetPinStateEvent(const Events::SetTargetPinState& event) { std::unique_ptr<Response> TargetControllerComponent::handleSetTargetPinState(SetTargetPinState& command) {
try { this->target->setPinState(command.pinDescriptor, command.pinState);
if (this->target->getState() != TargetState::STOPPED) { return std::make_unique<Response>();
throw TargetOperationFailure(
"Invalid target state - target must be stopped before pin state can be set"
);
}
this->target->setPinState(event.pinDescriptor, event.pinState);
auto pinStatesUpdateEvent = std::make_shared<Events::TargetPinStatesRetrieved>();
pinStatesUpdateEvent->correlationId = event.id;
pinStatesUpdateEvent->variantId = event.pinDescriptor.variantId;
pinStatesUpdateEvent->pinSatesByNumber = {
{event.pinDescriptor.number, event.pinState}
};
EventManager::triggerEvent(pinStatesUpdateEvent);
} catch (const TargetOperationFailure& exception) {
Logger::error("Failed to set target pin state for pin " + event.pinDescriptor.name + " - "
+ exception.getMessage());
this->emitErrorEvent(event.id, exception.getMessage());
}
} }
void TargetControllerComponent::onRetrieveStackPointerEvent(const Events::RetrieveStackPointerFromTarget& event) { void TargetControllerComponent::onRetrieveStackPointerEvent(const Events::RetrieveStackPointerFromTarget& event) {

View File

@@ -31,6 +31,7 @@
#include "Commands/RemoveBreakpoint.hpp" #include "Commands/RemoveBreakpoint.hpp"
#include "Commands/SetProgramCounter.hpp" #include "Commands/SetProgramCounter.hpp"
#include "Commands/GetTargetPinStates.hpp" #include "Commands/GetTargetPinStates.hpp"
#include "Commands/SetTargetPinState.hpp"
// Responses // Responses
#include "Responses/Response.hpp" #include "Responses/Response.hpp"
@@ -315,14 +316,7 @@ namespace Bloom::TargetController
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); std::unique_ptr<Responses::TargetPinStates> handleGetTargetPinStates(Commands::GetTargetPinStates& command);
std::unique_ptr<Responses::Response> handleSetTargetPinState(Commands::SetTargetPinState& command);
/**
* Will update a pin state for a particular pin. Will emit a TargetPinStatesRetrieved with the new pin
* state, on success.
*
* @param event
*/
void onSetPinStateEvent(const Events::SetTargetPinState& event);
/** /**
* Will retrieve the current stack pointer from the target. Will emit a StackPointerRetrievedFromTarget event * Will retrieve the current stack pointer from the target. Will emit a StackPointerRetrievedFromTarget event

View File

@@ -18,6 +18,7 @@
#include "Commands/RemoveBreakpoint.hpp" #include "Commands/RemoveBreakpoint.hpp"
#include "Commands/SetProgramCounter.hpp" #include "Commands/SetProgramCounter.hpp"
#include "Commands/GetTargetPinStates.hpp" #include "Commands/GetTargetPinStates.hpp"
#include "Commands/SetTargetPinState.hpp"
#include "src/Logger/Logger.hpp" #include "src/Logger/Logger.hpp"
@@ -40,6 +41,7 @@ namespace Bloom::TargetController
using Commands::RemoveBreakpoint; using Commands::RemoveBreakpoint;
using Commands::SetProgramCounter; using Commands::SetProgramCounter;
using Commands::GetTargetPinStates; using Commands::GetTargetPinStates;
using Commands::SetTargetPinState;
TargetControllerConsole::TargetControllerConsole(EventListener& eventListener) TargetControllerConsole::TargetControllerConsole(EventListener& eventListener)
: eventListener(eventListener) : eventListener(eventListener)
@@ -175,11 +177,10 @@ namespace Bloom::TargetController
} }
void TargetControllerConsole::setPinState(TargetPinDescriptor pinDescriptor, TargetPinState pinState) { void TargetControllerConsole::setPinState(TargetPinDescriptor pinDescriptor, TargetPinState pinState) {
auto updateEvent = std::make_shared<SetTargetPinState>(); this->commandManager.sendCommandAndWaitForResponse(
updateEvent->pinDescriptor = std::move(pinDescriptor); std::make_unique<SetTargetPinState>(pinDescriptor, pinState),
updateEvent->pinState = pinState; this->defaultTimeout
);
this->triggerTargetControllerEventAndWaitForResponse(updateEvent);
} }
std::uint32_t TargetControllerConsole::getStackPointer() { std::uint32_t TargetControllerConsole::getStackPointer() {