Added requiresStoppedTargetState() member function to TargetController command classes.

The TargetController will use this to determine whether to stop the target before handling a given command.
This commit is contained in:
Nav
2022-04-29 22:06:05 +01:00
parent 80405057f6
commit 3fc558f3e8
7 changed files with 28 additions and 0 deletions

View File

@@ -36,6 +36,10 @@ namespace Bloom::TargetController::Commands
return Command::type;
}
[[nodiscard]] virtual bool requiresStoppedTargetState() const {
return false;
}
private:
static inline std::atomic<CommandIdType> lastCommandId = 0;
};

View File

@@ -35,5 +35,9 @@ namespace Bloom::TargetController::Commands
[[nodiscard]] CommandType getType() const override {
return ReadTargetMemory::type;
}
[[nodiscard]] bool requiresStoppedTargetState() const override {
return true;
}
};
}

View File

@@ -24,5 +24,9 @@ namespace Bloom::TargetController::Commands
[[nodiscard]] CommandType getType() const override {
return ReadTargetRegisters::type;
}
[[nodiscard]] bool requiresStoppedTargetState() const override {
return true;
}
};
}

View File

@@ -13,5 +13,9 @@ namespace Bloom::TargetController::Commands
[[nodiscard]] CommandType getType() const override {
return ResetTarget::type;
}
[[nodiscard]] bool requiresStoppedTargetState() const override {
return true;
}
};
}

View File

@@ -22,5 +22,9 @@ namespace Bloom::TargetController::Commands
[[nodiscard]] CommandType getType() const override {
return ResumeTargetExecution::type;
}
[[nodiscard]] bool requiresStoppedTargetState() const override {
return true;
}
};
}

View File

@@ -21,5 +21,9 @@ namespace Bloom::TargetController::Commands
[[nodiscard]] CommandType getType() const override {
return WriteTargetRegisters::type;
}
[[nodiscard]] bool requiresStoppedTargetState() const override {
return true;
}
};
}

View File

@@ -285,6 +285,10 @@ namespace Bloom::TargetController
throw Exception("No handler registered for this command.");
}
if (command->requiresStoppedTargetState() && this->lastTargetState != TargetState::STOPPED) {
this->target->stop();
}
this->registerCommandResponse(
commandId,
this->commandHandlersByCommandType.at(commandType)(*(command.get()))