Implemented ResetTaret handler in TargetController
This commit is contained in:
@@ -53,6 +53,7 @@ namespace Bloom::Events
|
|||||||
SET_TARGET_PIN_STATE,
|
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,
|
||||||
};
|
};
|
||||||
|
|
||||||
class Event
|
class Event
|
||||||
|
|||||||
@@ -41,6 +41,7 @@
|
|||||||
#include "SetTargetPinState.hpp"
|
#include "SetTargetPinState.hpp"
|
||||||
#include "RetrieveStackPointerFromTarget.hpp"
|
#include "RetrieveStackPointerFromTarget.hpp"
|
||||||
#include "StackPointerRetrievedFromTarget.hpp"
|
#include "StackPointerRetrievedFromTarget.hpp"
|
||||||
|
#include "TargetReset.hpp"
|
||||||
|
|
||||||
namespace Bloom::Events
|
namespace Bloom::Events
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,12 +3,15 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "Event.hpp"
|
#include "Event.hpp"
|
||||||
|
#include "TargetReset.hpp"
|
||||||
|
|
||||||
namespace Bloom::Events
|
namespace Bloom::Events
|
||||||
{
|
{
|
||||||
class ResetTarget: public Event
|
class ResetTarget: public Event
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
using TargetControllerResponseType = TargetReset;
|
||||||
|
|
||||||
static constexpr EventType type = EventType::RESET_TARGET;
|
static constexpr EventType type = EventType::RESET_TARGET;
|
||||||
static inline const std::string name = "ResetTargetEvent";
|
static inline const std::string name = "ResetTargetEvent";
|
||||||
|
|
||||||
|
|||||||
23
src/EventManager/Events/TargetReset.hpp
Normal file
23
src/EventManager/Events/TargetReset.hpp
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "Event.hpp"
|
||||||
|
|
||||||
|
namespace Bloom::Events
|
||||||
|
{
|
||||||
|
class TargetReset: public Event
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static constexpr EventType type = EventType::TARGET_RESET;
|
||||||
|
static inline const std::string name = "TargetReset";
|
||||||
|
|
||||||
|
[[nodiscard]] EventType getType() const override {
|
||||||
|
return TargetReset::type;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] std::string getName() const override {
|
||||||
|
return TargetReset::name;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -257,6 +257,10 @@ namespace Bloom
|
|||||||
std::bind(&TargetController::onRetrieveStackPointerEvent, this, std::placeholders::_1)
|
std::bind(&TargetController::onRetrieveStackPointerEvent, this, std::placeholders::_1)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this->eventListener->registerCallbackForEventType<Events::ResetTarget>(
|
||||||
|
std::bind(&TargetController::onResetTarget, this, std::placeholders::_1)
|
||||||
|
);
|
||||||
|
|
||||||
this->state = TargetControllerState::ACTIVE;
|
this->state = TargetControllerState::ACTIVE;
|
||||||
EventManager::triggerEvent(
|
EventManager::triggerEvent(
|
||||||
std::make_shared<TargetControllerStateReported>(this->state)
|
std::make_shared<TargetControllerStateReported>(this->state)
|
||||||
@@ -446,6 +450,15 @@ namespace Bloom
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TargetController::resetTarget(const std::optional<int>& resetEventCorrelationId) {
|
||||||
|
this->target->reset();
|
||||||
|
|
||||||
|
auto targetResetEvent = std::make_shared<Events::TargetReset>();
|
||||||
|
targetResetEvent->correlationId = resetEventCorrelationId;
|
||||||
|
|
||||||
|
EventManager::triggerEvent(targetResetEvent);
|
||||||
|
}
|
||||||
|
|
||||||
void TargetController::emitErrorEvent(int correlationId, const std::string& errorMessage) {
|
void TargetController::emitErrorEvent(int correlationId, const std::string& errorMessage) {
|
||||||
auto errorEvent = std::make_shared<Events::TargetControllerErrorOccurred>();
|
auto errorEvent = std::make_shared<Events::TargetControllerErrorOccurred>();
|
||||||
errorEvent->correlationId = correlationId;
|
errorEvent->correlationId = correlationId;
|
||||||
@@ -487,7 +500,7 @@ namespace Bloom
|
|||||||
this->fireTargetEvents();
|
this->fireTargetEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
this->target->reset();
|
this->resetTarget();
|
||||||
|
|
||||||
if (this->target->getState() != TargetState::STOPPED) {
|
if (this->target->getState() != TargetState::STOPPED) {
|
||||||
this->target->stop();
|
this->target->stop();
|
||||||
@@ -800,4 +813,14 @@ namespace Bloom
|
|||||||
this->emitErrorEvent(event.id, exception.getMessage());
|
this->emitErrorEvent(event.id, exception.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TargetController::onResetTarget(const Events::ResetTarget& event) {
|
||||||
|
try {
|
||||||
|
this->resetTarget(event.id);
|
||||||
|
|
||||||
|
} catch (const TargetOperationFailure& exception) {
|
||||||
|
Logger::error("Failed to reset target - " + exception.getMessage());
|
||||||
|
this->emitErrorEvent(event.id, exception.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -276,6 +276,13 @@ namespace Bloom
|
|||||||
*/
|
*/
|
||||||
void fireTargetEvents();
|
void fireTargetEvents();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Triggers a target reset and emits a TargetReset event.
|
||||||
|
*
|
||||||
|
* @param resetEventCorrelationId
|
||||||
|
*/
|
||||||
|
void resetTarget(const std::optional<int>& resetEventCorrelationId = std::nullopt);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When the TargetController fails to handle an event, a TargetControllerErrorOccurred event is emitted, with
|
* When the TargetController fails to handle an event, a TargetControllerErrorOccurred event is emitted, with
|
||||||
* a correlation ID matching the ID of the event that triggered the handler.
|
* a correlation ID matching the ID of the event that triggered the handler.
|
||||||
@@ -425,5 +432,7 @@ namespace Bloom
|
|||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
void onRetrieveStackPointerEvent(const Events::RetrieveStackPointerFromTarget& event);
|
void onRetrieveStackPointerEvent(const Events::RetrieveStackPointerFromTarget& event);
|
||||||
|
|
||||||
|
void onResetTarget(const Events::ResetTarget& event);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,4 +140,8 @@ namespace Bloom
|
|||||||
std::make_shared<RetrieveStackPointerFromTarget>()
|
std::make_shared<RetrieveStackPointerFromTarget>()
|
||||||
)->stackPointer;
|
)->stackPointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TargetControllerConsole::resetTarget() {
|
||||||
|
this->triggerTargetControllerEventAndWaitForResponse(std::make_shared<ResetTarget>());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -165,6 +165,11 @@ namespace Bloom
|
|||||||
*/
|
*/
|
||||||
std::uint32_t getStackPointer();
|
std::uint32_t getStackPointer();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Triggers a reset on the target. The target will be held in a stopped state.
|
||||||
|
*/
|
||||||
|
void resetTarget();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EventListener& eventListener;
|
EventListener& eventListener;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user