diff --git a/src/DebugServer/Gdb/README.md b/src/DebugServer/Gdb/README.md index 60a6bb23..f977cadc 100644 --- a/src/DebugServer/Gdb/README.md +++ b/src/DebugServer/Gdb/README.md @@ -84,7 +84,7 @@ void SetBreakpoint::handle(DebugSession& debugSession, TargetControllerService& Logger::debug("Handling SetBreakpoint packet"); try { - targetControllerServicesetBreakpoint(TargetBreakpoint(this->address)); + targetControllerService.setBreakpoint(TargetBreakpoint(this->address)); debugSession.connection.writePacket(OkResponsePacket()); } catch (const Exception& exception) { diff --git a/src/Services/TargetControllerService.cpp b/src/Services/TargetControllerService.cpp index a40a244d..3f6e8123 100644 --- a/src/Services/TargetControllerService.cpp +++ b/src/Services/TargetControllerService.cpp @@ -73,14 +73,14 @@ namespace Bloom::Services using Targets::TargetPinState; using Targets::TargetPinStateMapping; - TargetControllerState TargetControllerService::getTargetControllerState() { + TargetControllerState TargetControllerService::getTargetControllerState() const { return this->commandManager.sendCommandAndWaitForResponse( std::make_unique(), this->defaultTimeout )->state; } - bool TargetControllerService::isTargetControllerInService() noexcept { + bool TargetControllerService::isTargetControllerInService() const noexcept { try { return this->getTargetControllerState() == TargetControllerState::ACTIVE; @@ -89,7 +89,7 @@ namespace Bloom::Services } } - void TargetControllerService::resumeTargetController() { + void TargetControllerService::resumeTargetController() const { this->commandManager.sendCommandAndWaitForResponse( std::make_unique(), this->defaultTimeout @@ -97,7 +97,7 @@ namespace Bloom::Services return; } - void TargetControllerService::suspendTargetController() { + void TargetControllerService::suspendTargetController() const { this->commandManager.sendCommandAndWaitForResponse( std::make_unique(), this->defaultTimeout @@ -105,28 +105,28 @@ namespace Bloom::Services return; } - const TargetDescriptor& TargetControllerService::getTargetDescriptor() { + const TargetDescriptor& TargetControllerService::getTargetDescriptor() const { return this->commandManager.sendCommandAndWaitForResponse( std::make_unique(), this->defaultTimeout )->targetDescriptor; } - TargetState TargetControllerService::getTargetState() { + TargetState TargetControllerService::getTargetState() const { return this->commandManager.sendCommandAndWaitForResponse( std::make_unique(), this->defaultTimeout )->targetState; } - void TargetControllerService::stopTargetExecution() { + void TargetControllerService::stopTargetExecution() const { this->commandManager.sendCommandAndWaitForResponse( std::make_unique(), this->defaultTimeout ); } - void TargetControllerService::continueTargetExecution(std::optional fromAddress) { + void TargetControllerService::continueTargetExecution(std::optional fromAddress) const { auto resumeExecutionCommand = std::make_unique(); if (fromAddress.has_value()) { @@ -139,7 +139,7 @@ namespace Bloom::Services ); } - void TargetControllerService::stepTargetExecution(std::optional fromAddress) { + void TargetControllerService::stepTargetExecution(std::optional fromAddress) const { auto stepExecutionCommand = std::make_unique(); if (fromAddress.has_value()) { @@ -152,14 +152,14 @@ namespace Bloom::Services ); } - TargetRegisters TargetControllerService::readRegisters(const TargetRegisterDescriptors& descriptors) { + TargetRegisters TargetControllerService::readRegisters(const TargetRegisterDescriptors& descriptors) const { return this->commandManager.sendCommandAndWaitForResponse( std::make_unique(descriptors), this->defaultTimeout )->registers; } - void TargetControllerService::writeRegisters(const TargetRegisters& registers) { + void TargetControllerService::writeRegisters(const TargetRegisters& registers) const { this->commandManager.sendCommandAndWaitForResponse( std::make_unique(registers), this->defaultTimeout @@ -171,7 +171,7 @@ namespace Bloom::Services TargetMemoryAddress startAddress, TargetMemorySize bytes, const std::set& excludedAddressRanges - ) { + ) const { return this->commandManager.sendCommandAndWaitForResponse( std::make_unique( memoryType, @@ -187,84 +187,84 @@ namespace Bloom::Services TargetMemoryType memoryType, TargetMemoryAddress startAddress, const TargetMemoryBuffer& buffer - ) { + ) const { this->commandManager.sendCommandAndWaitForResponse( std::make_unique(memoryType, startAddress, buffer), this->defaultTimeout ); } - void TargetControllerService::eraseMemory(Targets::TargetMemoryType memoryType) { + void TargetControllerService::eraseMemory(Targets::TargetMemoryType memoryType) const { this->commandManager.sendCommandAndWaitForResponse( std::make_unique(memoryType), this->defaultTimeout ); } - void TargetControllerService::setBreakpoint(TargetBreakpoint breakpoint) { + void TargetControllerService::setBreakpoint(TargetBreakpoint breakpoint) const { this->commandManager.sendCommandAndWaitForResponse( std::make_unique(breakpoint), this->defaultTimeout ); } - void TargetControllerService::removeBreakpoint(TargetBreakpoint breakpoint) { + void TargetControllerService::removeBreakpoint(TargetBreakpoint breakpoint) const { this->commandManager.sendCommandAndWaitForResponse( std::make_unique(breakpoint), this->defaultTimeout ); } - TargetProgramCounter TargetControllerService::getProgramCounter() { + TargetProgramCounter TargetControllerService::getProgramCounter() const { return this->commandManager.sendCommandAndWaitForResponse( std::make_unique(), this->defaultTimeout )->programCounter; } - void TargetControllerService::setProgramCounter(TargetProgramCounter address) { + void TargetControllerService::setProgramCounter(TargetProgramCounter address) const { this->commandManager.sendCommandAndWaitForResponse( std::make_unique(address), this->defaultTimeout ); } - TargetPinStateMapping TargetControllerService::getPinStates(int variantId) { + TargetPinStateMapping TargetControllerService::getPinStates(int variantId) const { return this->commandManager.sendCommandAndWaitForResponse( std::make_unique(variantId), this->defaultTimeout )->pinStatesByNumber; } - void TargetControllerService::setPinState(TargetPinDescriptor pinDescriptor, TargetPinState pinState) { + void TargetControllerService::setPinState(TargetPinDescriptor pinDescriptor, TargetPinState pinState) const { this->commandManager.sendCommandAndWaitForResponse( std::make_unique(pinDescriptor, pinState), this->defaultTimeout ); } - TargetStackPointer TargetControllerService::getStackPointer() { + TargetStackPointer TargetControllerService::getStackPointer() const { return this->commandManager.sendCommandAndWaitForResponse( std::make_unique(), this->defaultTimeout )->stackPointer; } - void TargetControllerService::resetTarget() { + void TargetControllerService::resetTarget() const { this->commandManager.sendCommandAndWaitForResponse( std::make_unique(), this->defaultTimeout ); } - void TargetControllerService::enableProgrammingMode() { + void TargetControllerService::enableProgrammingMode() const { this->commandManager.sendCommandAndWaitForResponse( std::make_unique(), this->defaultTimeout ); } - void TargetControllerService::disableProgrammingMode() { + void TargetControllerService::disableProgrammingMode() const { this->commandManager.sendCommandAndWaitForResponse( std::make_unique(), this->defaultTimeout diff --git a/src/Services/TargetControllerService.hpp b/src/Services/TargetControllerService.hpp index dd86a5ad..efda40c9 100644 --- a/src/Services/TargetControllerService.hpp +++ b/src/Services/TargetControllerService.hpp @@ -39,7 +39,7 @@ namespace Bloom::Services * * @return */ - TargetController::TargetControllerState getTargetControllerState(); + TargetController::TargetControllerState getTargetControllerState() const; /** * Retrieves the TargetController state and checks if it's currently active. @@ -47,50 +47,50 @@ namespace Bloom::Services * @return * True if the TargetController is currently in an active state, otherwise false. */ - bool isTargetControllerInService() noexcept; + bool isTargetControllerInService() const noexcept; /** * Resumes the TargetController if it's suspended. Otherwise, this function does nothing. */ - void resumeTargetController(); + void resumeTargetController() const; /** * Suspends the TargetController if it's active. Otherwise, this function does nothing. */ - void suspendTargetController(); + void suspendTargetController() const; /** * Requests the TargetDescriptor from the TargetController * * @return */ - const Targets::TargetDescriptor& getTargetDescriptor(); + const Targets::TargetDescriptor& getTargetDescriptor() const; /** * Fetches the current target state. * * @return */ - Targets::TargetState getTargetState(); + Targets::TargetState getTargetState() const; /** * Requests the TargetController to halt execution on the target. */ - void stopTargetExecution(); + void stopTargetExecution() const; /** * Requests the TargetController to continue execution on the target. * * @param fromAddress */ - void continueTargetExecution(std::optional fromAddress); + void continueTargetExecution(std::optional fromAddress) const; /** * Requests the TargetController to step execution on the target. * * @param fromAddress */ - void stepTargetExecution(std::optional fromAddress); + void stepTargetExecution(std::optional fromAddress) const; /** * Requests the TargetController to read register values from the target. @@ -100,14 +100,14 @@ namespace Bloom::Services * * @return */ - Targets::TargetRegisters readRegisters(const Targets::TargetRegisterDescriptors& descriptors); + Targets::TargetRegisters readRegisters(const Targets::TargetRegisterDescriptors& descriptors) const; /** * Requests the TargetController to write register values to the target. * * @param registers */ - void writeRegisters(const Targets::TargetRegisters& registers); + void writeRegisters(const Targets::TargetRegisters& registers) const; /** * Requests the TargetController to read memory from the target. @@ -123,7 +123,7 @@ namespace Bloom::Services Targets::TargetMemoryAddress startAddress, Targets::TargetMemorySize bytes, const std::set& excludedAddressRanges = {} - ); + ) const; /** * Requests the TargetController to write memory to the target. @@ -136,49 +136,49 @@ namespace Bloom::Services Targets::TargetMemoryType memoryType, Targets::TargetMemoryAddress startAddress, const Targets::TargetMemoryBuffer& buffer - ); + ) const; /** * Requests the TargetController to erase the given target memory type. * * @param memoryType */ - void eraseMemory(Targets::TargetMemoryType memoryType); + void eraseMemory(Targets::TargetMemoryType memoryType) const; /** * Requests the TargetController to set a breakpoint on the target. * * @param breakpoint */ - void setBreakpoint(Targets::TargetBreakpoint breakpoint); + void setBreakpoint(Targets::TargetBreakpoint breakpoint) const; /** * Requests the TargetController to remove a breakpoint from the target. * * @param breakpoint */ - void removeBreakpoint(Targets::TargetBreakpoint breakpoint); + void removeBreakpoint(Targets::TargetBreakpoint breakpoint) const; /** * Retrieves the current program counter value from the target. * * @return */ - Targets::TargetProgramCounter getProgramCounter(); + Targets::TargetProgramCounter getProgramCounter() const; /** * Sets the target's program counter to the given address. * * @param address */ - void setProgramCounter(Targets::TargetProgramCounter address); + void setProgramCounter(Targets::TargetProgramCounter address) const; /** * Retrieves the pin states for a particular target variant. * * @param variantId */ - Targets::TargetPinStateMapping getPinStates(int variantId); + Targets::TargetPinStateMapping getPinStates(int variantId) const; /** * Updates the pin state on the target, for a specific pin. @@ -186,19 +186,19 @@ namespace Bloom::Services * @param pinDescriptor * @param pinState */ - void setPinState(Targets::TargetPinDescriptor pinDescriptor, Targets::TargetPinState pinState); + void setPinState(Targets::TargetPinDescriptor pinDescriptor, Targets::TargetPinState pinState) const; /** * Retrieves the current stack pointer value from the target. * * @return */ - Targets::TargetStackPointer getStackPointer(); + Targets::TargetStackPointer getStackPointer() const; /** * Triggers a reset on the target. The target will be held in a stopped state. */ - void resetTarget(); + void resetTarget() const; /** * Enables programming mode on the target. @@ -207,12 +207,12 @@ namespace Bloom::Services * debug operations (such as ResumeTargetExecution, ReadTargetRegisters, etc), until programming mode has * been disabled. */ - void enableProgrammingMode(); + void enableProgrammingMode() const; /** * Disables programming mode on the target. */ - void disableProgrammingMode(); + void disableProgrammingMode() const; private: TargetController::CommandManager commandManager = TargetController::CommandManager(); diff --git a/src/TargetController/CommandManager.hpp b/src/TargetController/CommandManager.hpp index 26832e7c..caef1c66 100644 --- a/src/TargetController/CommandManager.hpp +++ b/src/TargetController/CommandManager.hpp @@ -25,7 +25,7 @@ namespace Bloom::TargetController auto sendCommandAndWaitForResponse( std::unique_ptr command, std::chrono::milliseconds timeout - ) { + ) const { using SuccessResponseType = typename CommandType::SuccessResponseType; const auto commandId = command->id; diff --git a/src/TargetController/README.md b/src/TargetController/README.md index db92c1e2..fdf6e581 100644 --- a/src/TargetController/README.md +++ b/src/TargetController/README.md @@ -60,7 +60,7 @@ simplified means for other components to interact with the connected hardware. I memory from the target: ```c++ -auto tcService = Services::TargetControllerService(); +const auto tcService = Services::TargetControllerService(); const auto data = tcService.readMemory( someMemoryType, // Flash, RAM, EEPROM, etc