Replaced SetTargetPinState event with TC command
This commit is contained in:
@@ -32,8 +32,6 @@ namespace Bloom::Events
|
||||
EXTRACT_TARGET_DESCRIPTOR,
|
||||
TARGET_DESCRIPTOR_EXTRACTED,
|
||||
INSIGHT_THREAD_STATE_CHANGED,
|
||||
TARGET_PIN_STATES_RETRIEVED,
|
||||
SET_TARGET_PIN_STATE,
|
||||
RETRIEVE_STACK_POINTER_FROM_TARGET,
|
||||
STACK_POINTER_RETRIEVED_FROM_TARGET,
|
||||
TARGET_RESET,
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
#include "ExtractTargetDescriptor.hpp"
|
||||
#include "TargetDescriptorExtracted.hpp"
|
||||
#include "InsightThreadStateChanged.hpp"
|
||||
#include "TargetPinStatesRetrieved.hpp"
|
||||
#include "SetTargetPinState.hpp"
|
||||
#include "RetrieveStackPointerFromTarget.hpp"
|
||||
#include "StackPointerRetrievedFromTarget.hpp"
|
||||
#include "TargetReset.hpp"
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -21,5 +21,6 @@ namespace Bloom::TargetController::Commands
|
||||
REMOVE_BREAKPOINT,
|
||||
SET_PROGRAM_COUNTER,
|
||||
GET_TARGET_PIN_STATES,
|
||||
SET_TARGET_PIN_STATE,
|
||||
};
|
||||
}
|
||||
|
||||
34
src/TargetController/Commands/SetTargetPinState.hpp
Normal file
34
src/TargetController/Commands/SetTargetPinState.hpp
Normal 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;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -35,6 +35,7 @@ namespace Bloom::TargetController
|
||||
using Commands::RemoveBreakpoint;
|
||||
using Commands::SetProgramCounter;
|
||||
using Commands::GetTargetPinStates;
|
||||
using Commands::SetTargetPinState;
|
||||
|
||||
using Responses::Response;
|
||||
using Responses::TargetRegistersRead;
|
||||
@@ -402,11 +403,11 @@ namespace Bloom::TargetController
|
||||
this->deregisterCommandHandler(RemoveBreakpoint::type);
|
||||
this->deregisterCommandHandler(SetProgramCounter::type);
|
||||
this->deregisterCommandHandler(GetTargetPinStates::type);
|
||||
this->deregisterCommandHandler(SetTargetPinState::type);
|
||||
|
||||
this->eventListener->deregisterCallbacksForEventType<Events::DebugSessionFinished>();
|
||||
this->eventListener->deregisterCallbacksForEventType<Events::ExtractTargetDescriptor>();
|
||||
this->eventListener->deregisterCallbacksForEventType<Events::InsightThreadStateChanged>();
|
||||
this->eventListener->deregisterCallbacksForEventType<Events::SetTargetPinState>();
|
||||
this->eventListener->deregisterCallbacksForEventType<Events::RetrieveStackPointerFromTarget>();
|
||||
|
||||
this->lastTargetState = TargetState::UNKNOWN;
|
||||
@@ -476,6 +477,10 @@ namespace Bloom::TargetController
|
||||
std::bind(&TargetControllerComponent::handleGetTargetPinStates, this, std::placeholders::_1)
|
||||
);
|
||||
|
||||
this->registerCommandHandler<SetTargetPinState>(
|
||||
std::bind(&TargetControllerComponent::handleSetTargetPinState, this, std::placeholders::_1)
|
||||
);
|
||||
|
||||
this->eventListener->registerCallbackForEventType<Events::DebugSessionFinished>(
|
||||
std::bind(&TargetControllerComponent::onDebugSessionFinishedEvent, this, std::placeholders::_1)
|
||||
);
|
||||
@@ -484,10 +489,6 @@ namespace Bloom::TargetController
|
||||
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>(
|
||||
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));
|
||||
}
|
||||
|
||||
void TargetControllerComponent::onSetPinStateEvent(const Events::SetTargetPinState& event) {
|
||||
try {
|
||||
if (this->target->getState() != TargetState::STOPPED) {
|
||||
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());
|
||||
}
|
||||
std::unique_ptr<Response> TargetControllerComponent::handleSetTargetPinState(SetTargetPinState& command) {
|
||||
this->target->setPinState(command.pinDescriptor, command.pinState);
|
||||
return std::make_unique<Response>();
|
||||
}
|
||||
|
||||
void TargetControllerComponent::onRetrieveStackPointerEvent(const Events::RetrieveStackPointerFromTarget& event) {
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "Commands/RemoveBreakpoint.hpp"
|
||||
#include "Commands/SetProgramCounter.hpp"
|
||||
#include "Commands/GetTargetPinStates.hpp"
|
||||
#include "Commands/SetTargetPinState.hpp"
|
||||
|
||||
// Responses
|
||||
#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> handleSetProgramCounter(Commands::SetProgramCounter& command);
|
||||
std::unique_ptr<Responses::TargetPinStates> handleGetTargetPinStates(Commands::GetTargetPinStates& 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);
|
||||
std::unique_ptr<Responses::Response> handleSetTargetPinState(Commands::SetTargetPinState& command);
|
||||
|
||||
/**
|
||||
* Will retrieve the current stack pointer from the target. Will emit a StackPointerRetrievedFromTarget event
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "Commands/RemoveBreakpoint.hpp"
|
||||
#include "Commands/SetProgramCounter.hpp"
|
||||
#include "Commands/GetTargetPinStates.hpp"
|
||||
#include "Commands/SetTargetPinState.hpp"
|
||||
|
||||
#include "src/Logger/Logger.hpp"
|
||||
|
||||
@@ -40,6 +41,7 @@ namespace Bloom::TargetController
|
||||
using Commands::RemoveBreakpoint;
|
||||
using Commands::SetProgramCounter;
|
||||
using Commands::GetTargetPinStates;
|
||||
using Commands::SetTargetPinState;
|
||||
|
||||
TargetControllerConsole::TargetControllerConsole(EventListener& eventListener)
|
||||
: eventListener(eventListener)
|
||||
@@ -175,11 +177,10 @@ namespace Bloom::TargetController
|
||||
}
|
||||
|
||||
void TargetControllerConsole::setPinState(TargetPinDescriptor pinDescriptor, TargetPinState pinState) {
|
||||
auto updateEvent = std::make_shared<SetTargetPinState>();
|
||||
updateEvent->pinDescriptor = std::move(pinDescriptor);
|
||||
updateEvent->pinState = pinState;
|
||||
|
||||
this->triggerTargetControllerEventAndWaitForResponse(updateEvent);
|
||||
this->commandManager.sendCommandAndWaitForResponse(
|
||||
std::make_unique<SetTargetPinState>(pinDescriptor, pinState),
|
||||
this->defaultTimeout
|
||||
);
|
||||
}
|
||||
|
||||
std::uint32_t TargetControllerConsole::getStackPointer() {
|
||||
|
||||
Reference in New Issue
Block a user