Tidying
This commit is contained in:
@@ -1,24 +1,15 @@
|
||||
#include <cstdint>
|
||||
|
||||
#include "src/Exceptions/Exception.hpp"
|
||||
#include "Response.hpp"
|
||||
|
||||
using namespace Bloom::DebugToolDrivers::Protocols::CmsisDap;
|
||||
|
||||
void Response::init(unsigned char* response, std::size_t length)
|
||||
void Response::init(const std::vector<unsigned char>& rawResponse)
|
||||
{
|
||||
if (length == 0) {
|
||||
if (rawResponse.size() < 1) {
|
||||
throw Exceptions::Exception("Failed to process CMSIS-DAP response - invalid response");
|
||||
}
|
||||
|
||||
this->setResponseId(response[0]);
|
||||
std::vector<unsigned char> data = this->getData();
|
||||
|
||||
// TODO: use insert with iterators here
|
||||
for (std::size_t i = 1; i < length; i++) {
|
||||
data.push_back(response[i]);
|
||||
}
|
||||
|
||||
this->setData(data);
|
||||
this->setResponseId(rawResponse[0]);
|
||||
this->setData(std::vector<unsigned char>(rawResponse.begin() + 1, rawResponse.end()));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
namespace Bloom::DebugToolDrivers::Protocols::CmsisDap
|
||||
@@ -23,10 +22,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap
|
||||
|
||||
public:
|
||||
Response() = default;
|
||||
virtual void init(unsigned char* response, std::size_t length);
|
||||
virtual void init(std::vector<unsigned char> response) {
|
||||
this->init(response.data(), response.size());
|
||||
}
|
||||
virtual void init(const std::vector<unsigned char>& rawResponse);
|
||||
|
||||
unsigned char getResponseId() const {
|
||||
return this->responseId;
|
||||
|
||||
@@ -16,9 +16,7 @@ std::vector<unsigned char> AvrCommand::getData() const
|
||||
data[2] = (unsigned char) (commandPacketSize & 0xFF);
|
||||
|
||||
if (commandPacketSize > 0) {
|
||||
for (std::size_t index = 0; index <= commandPacketSize - 1; index++) {
|
||||
data[3 + index] = commandPacket[index];
|
||||
}
|
||||
data.insert(data.begin() + 3, commandPacket.begin(), commandPacket.end());
|
||||
}
|
||||
|
||||
return data;
|
||||
|
||||
@@ -1,21 +1,17 @@
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
|
||||
#include "AvrEvent.hpp"
|
||||
#include "src/Exceptions/Exception.hpp"
|
||||
|
||||
using namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr;
|
||||
using namespace Bloom::Exceptions;
|
||||
|
||||
void AvrEvent::init(unsigned char* response, size_t length)
|
||||
{
|
||||
Response::init(response, length);
|
||||
void AvrEvent::init(const std::vector<unsigned char>& rawResponse) {
|
||||
Response::init(rawResponse);
|
||||
|
||||
if (this->getResponseId() != 0x82) {
|
||||
throw Exception("Failed to construct AvrEvent object - invalid response ID.");
|
||||
}
|
||||
|
||||
std::vector<unsigned char> responseData = this->getData();
|
||||
auto& responseData = this->getData();
|
||||
|
||||
if (responseData.size() < 2) {
|
||||
// All AVR_EVT responses should consist of at least two bytes (excluding the AVR_EVT ID)
|
||||
@@ -32,7 +28,7 @@ void AvrEvent::init(unsigned char* response, size_t length)
|
||||
"contained invalid event data size.");
|
||||
}
|
||||
|
||||
std::vector<unsigned char> eventData;
|
||||
auto eventData = std::vector<unsigned char>();
|
||||
|
||||
/*
|
||||
* Ignore the SOF, protocol version &handler id and sequence ID (with all make up 5 bytes in total, 7 when
|
||||
|
||||
@@ -45,10 +45,10 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
|
||||
void init(const Response& response) {
|
||||
auto rawData = response.getData();
|
||||
rawData.insert(rawData.begin(), response.getResponseId());
|
||||
this->init(rawData.data(), rawData.size());
|
||||
this->init(rawData);
|
||||
}
|
||||
|
||||
void init(unsigned char* response, size_t length) override;
|
||||
void init(const std::vector<unsigned char>& rawResponse) override;
|
||||
|
||||
const std::vector<unsigned char>& getEventData() const {
|
||||
return this->eventData;
|
||||
|
||||
@@ -6,20 +6,19 @@
|
||||
using namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr;
|
||||
using namespace Bloom::Exceptions;
|
||||
|
||||
void AvrResponse::init(unsigned char* response, std::size_t length)
|
||||
{
|
||||
Response::init(response, length);
|
||||
void AvrResponse::init(const std::vector<unsigned char>& rawResponse) {
|
||||
Response::init(rawResponse);
|
||||
|
||||
if (this->getResponseId() != 0x81) {
|
||||
throw Exception("Failed to construct AvrResponse object - invalid response ID.");
|
||||
}
|
||||
|
||||
std::vector<unsigned char> responseData = this->getData();
|
||||
auto& responseData = this->getData();
|
||||
|
||||
if (responseData.empty()) {
|
||||
// All AVR responses should contain at least one byte (the fragment info byte)
|
||||
throw Exception("Failed to construct AvrResponse object - AVR_RSP response "
|
||||
"returned no additional data");
|
||||
"returned no additional data");
|
||||
}
|
||||
|
||||
if (responseData[0] == 0x00) {
|
||||
|
||||
@@ -39,10 +39,10 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
|
||||
void init(const Response& response) {
|
||||
auto rawData = response.getData();
|
||||
rawData.insert(rawData.begin(), response.getResponseId());
|
||||
this->init(rawData.data(), rawData.size());
|
||||
this->init(rawData);
|
||||
}
|
||||
|
||||
void init(unsigned char* response, std::size_t length) override;
|
||||
void init(const std::vector<unsigned char>& rawResponse) override;
|
||||
|
||||
std::uint8_t getFragmentNumber() const {
|
||||
return this->fragmentNumber;
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
|
||||
|
||||
public:
|
||||
ActivatePhysical() = default;
|
||||
ActivatePhysical(bool reset) : reset(reset) {};
|
||||
ActivatePhysical(bool reset): reset(reset) {};
|
||||
|
||||
void setReset(bool reset) {
|
||||
this->reset = reset;
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
|
||||
|
||||
public:
|
||||
Attach() = default;
|
||||
Attach(bool breakAfterAttach) : breakAfterAttach(breakAfterAttach) {};
|
||||
Attach(bool breakAfterAttach): breakAfterAttach(breakAfterAttach) {};
|
||||
|
||||
void setBreadAfterAttach(bool breakAfterAttach) {
|
||||
this->breakAfterAttach = breakAfterAttach;
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
|
||||
public:
|
||||
ClearSoftwareBreakpoints() = default;
|
||||
|
||||
ClearSoftwareBreakpoints(const std::vector<std::uint32_t>& addresses) : addresses(addresses) {}
|
||||
ClearSoftwareBreakpoints(const std::vector<std::uint32_t>& addresses): addresses(addresses) {}
|
||||
|
||||
void setAddresses(const std::vector<std::uint32_t>& addresses) {
|
||||
this->addresses = addresses;
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
|
||||
this->setParameter(parameter);
|
||||
}
|
||||
|
||||
GetParameter(const Avr8EdbgParameter& parameter, std::uint8_t size) : GetParameter(parameter) {
|
||||
GetParameter(const Avr8EdbgParameter& parameter, std::uint8_t size): GetParameter(parameter) {
|
||||
this->setSize(size);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
|
||||
|
||||
public:
|
||||
Reset() = default;
|
||||
Reset(bool stopAtMainAddress) : stopAtMainAddress(stopAtMainAddress) {};
|
||||
Reset(bool stopAtMainAddress): stopAtMainAddress(stopAtMainAddress) {};
|
||||
|
||||
void setStopAtMainAddress(bool stopAtMainAddress) {
|
||||
this->stopAtMainAddress = stopAtMainAddress;
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
|
||||
public:
|
||||
RunTo() = default;
|
||||
|
||||
RunTo(const std::uint32_t& address) : address(address) {}
|
||||
RunTo(const std::uint32_t& address): address(address) {}
|
||||
|
||||
void setAddress(const std::uint32_t& address) {
|
||||
this->address = address;
|
||||
|
||||
@@ -19,11 +19,11 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
|
||||
this->setParameter(parameter);
|
||||
}
|
||||
|
||||
SetParameter(const Avr8EdbgParameter& parameter, const std::vector<unsigned char>& value) : SetParameter(parameter) {
|
||||
SetParameter(const Avr8EdbgParameter& parameter, const std::vector<unsigned char>& value): SetParameter(parameter) {
|
||||
this->setValue(value);
|
||||
}
|
||||
|
||||
SetParameter(const Avr8EdbgParameter& parameter, unsigned char value) : SetParameter(parameter) {
|
||||
SetParameter(const Avr8EdbgParameter& parameter, unsigned char value): SetParameter(parameter) {
|
||||
this->setValue(value);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
|
||||
std::uint32_t programCounter = 0;
|
||||
|
||||
public:
|
||||
SetProgramCounter(std::uint32_t programCounter) : programCounter(programCounter) {}
|
||||
SetProgramCounter(std::uint32_t programCounter): programCounter(programCounter) {}
|
||||
|
||||
virtual std::vector<unsigned char> getPayload() const override {
|
||||
/*
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
|
||||
public:
|
||||
SetSoftwareBreakpoints() = default;
|
||||
|
||||
SetSoftwareBreakpoints(const std::vector<std::uint32_t>& addresses) : addresses(addresses) {}
|
||||
SetSoftwareBreakpoints(const std::vector<std::uint32_t>& addresses): addresses(addresses) {}
|
||||
|
||||
void setAddresses(const std::vector<std::uint32_t>& addresses) {
|
||||
this->addresses = addresses;
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
|
||||
public:
|
||||
SetXmegaSoftwareBreakpoint() = default;
|
||||
|
||||
SetXmegaSoftwareBreakpoint(std::uint32_t address) : address(address) {}
|
||||
SetXmegaSoftwareBreakpoint(std::uint32_t address): address(address) {}
|
||||
|
||||
void setAddress(std::uint32_t address) {
|
||||
this->address = address;
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
|
||||
|
||||
public:
|
||||
Stop() = default;
|
||||
Stop(bool stopImmediately) : stopImmediately(stopImmediately) {};
|
||||
Stop(bool stopImmediately): stopImmediately(stopImmediately) {};
|
||||
|
||||
void setStopImmediately(bool stopImmediately) {
|
||||
this->stopImmediately = stopImmediately;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/ResponseFrames/DiscoveryResponseFrame.hpp>
|
||||
#include "../AvrCommandFrame.hpp"
|
||||
#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/ResponseFrames/DiscoveryResponseFrame.hpp"
|
||||
|
||||
namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames::Discovery
|
||||
{
|
||||
|
||||
@@ -25,9 +25,9 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
|
||||
QueryContext context;
|
||||
|
||||
public:
|
||||
Query() : DiscoveryCommandFrame() {}
|
||||
Query(): DiscoveryCommandFrame() {}
|
||||
|
||||
Query(QueryContext context) : DiscoveryCommandFrame() {
|
||||
Query(QueryContext context): DiscoveryCommandFrame() {
|
||||
this->setContext(context);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
|
||||
}
|
||||
|
||||
public:
|
||||
EndSession() : HouseKeepingCommandFrame() {
|
||||
EndSession(): HouseKeepingCommandFrame() {
|
||||
this->init();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
|
||||
}
|
||||
|
||||
public:
|
||||
StartSession() : HouseKeepingCommandFrame() {
|
||||
StartSession(): HouseKeepingCommandFrame() {
|
||||
this->init();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "EdbgAvr8Interface.hpp"
|
||||
#include "src/Exceptions/InvalidConfig.hpp"
|
||||
#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/Exceptions/Avr8CommandFailure.hpp"
|
||||
#include "src/Logger/Logger.hpp"
|
||||
|
||||
// Command frames
|
||||
#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/VendorSpecific/EDBG/AVR/CommandFrames/AVR8Generic/SetParameter.hpp"
|
||||
|
||||
@@ -16,7 +16,6 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
|
||||
using namespace DebugToolDrivers;
|
||||
using namespace Targets;
|
||||
using namespace Targets::Microchip::Avr;
|
||||
using namespace Events;
|
||||
|
||||
using Protocols::CmsisDap::Edbg::EdbgInterface;
|
||||
using Targets::Microchip::Avr::Avr8Bit::Family;
|
||||
|
||||
@@ -60,11 +60,11 @@ namespace Bloom::Exceptions
|
||||
});
|
||||
|
||||
public:
|
||||
explicit Avr8CommandFailure(const std::string& message) : Exception(message) {
|
||||
explicit Avr8CommandFailure(const std::string& message): Exception(message) {
|
||||
this->message = message;
|
||||
}
|
||||
|
||||
explicit Avr8CommandFailure(const char* message) : Exception(message) {
|
||||
explicit Avr8CommandFailure(const char* message): Exception(message) {
|
||||
this->message = std::string(message);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::ResponseFrame
|
||||
class Avr8GenericResponseFrame: public AvrResponseFrame
|
||||
{
|
||||
public:
|
||||
Avr8GenericResponseFrame(const std::vector<AvrResponse>& AVRResponses) : AvrResponseFrame(AVRResponses) {}
|
||||
Avr8GenericResponseFrame(const std::vector<AvrResponse>& AVRResponses): AvrResponseFrame(AVRResponses) {}
|
||||
Avr8GenericResponseFrame() {}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::ResponseFrame
|
||||
class GetDeviceId: public Avr8GenericResponseFrame
|
||||
{
|
||||
public:
|
||||
GetDeviceId(const std::vector<AvrResponse>& AvrResponses) : Avr8GenericResponseFrame(AvrResponses) {}
|
||||
GetDeviceId(const std::vector<AvrResponse>& AvrResponses): Avr8GenericResponseFrame(AvrResponses) {}
|
||||
GetDeviceId() {}
|
||||
|
||||
TargetSignature extractSignature(Avr8PhysicalInterface physicalInterface) {
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::ResponseFrame
|
||||
class GetProgramCounter: public Avr8GenericResponseFrame
|
||||
{
|
||||
public:
|
||||
GetProgramCounter(const std::vector<AvrResponse>& AVRResponses) : Avr8GenericResponseFrame(AVRResponses) {}
|
||||
GetProgramCounter(const std::vector<AvrResponse>& AVRResponses): Avr8GenericResponseFrame(AVRResponses) {}
|
||||
GetProgramCounter() {}
|
||||
|
||||
std::uint32_t extractProgramCounter() {
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::ResponseFrame
|
||||
class ReadMemory: public Avr8GenericResponseFrame
|
||||
{
|
||||
public:
|
||||
ReadMemory(const std::vector<AvrResponse>& AVRResponses) : Avr8GenericResponseFrame(AVRResponses) {}
|
||||
ReadMemory(const std::vector<AvrResponse>& AVRResponses): Avr8GenericResponseFrame(AVRResponses) {}
|
||||
ReadMemory() {}
|
||||
|
||||
TargetMemoryBuffer getMemoryBuffer() {
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::ResponseFrame
|
||||
class DiscoveryResponseFrame: public AvrResponseFrame
|
||||
{
|
||||
public:
|
||||
DiscoveryResponseFrame(const std::vector<AvrResponse>& AVRResponses) : AvrResponseFrame(AVRResponses) {}
|
||||
DiscoveryResponseFrame(const std::vector<AvrResponse>& AVRResponses): AvrResponseFrame(AVRResponses) {}
|
||||
DiscoveryResponseFrame() {}
|
||||
|
||||
/**
|
||||
|
||||
@@ -53,7 +53,7 @@ std::optional<Protocols::CmsisDap::Edbg::Avr::AvrEvent> EdbgInterface::requestAv
|
||||
// This is an AVR_EVT response
|
||||
auto avrEvent = Protocols::CmsisDap::Edbg::Avr::AvrEvent();
|
||||
avrEvent.init(*cmsisResponse);
|
||||
return avrEvent.getEventDataSize() > 0 ? std::optional(avrEvent) : std::nullopt;
|
||||
return avrEvent.getEventDataSize() > 0 ? std::optional(avrEvent): std::nullopt;
|
||||
} else {
|
||||
throw Exception("Unexpected response to AvrEventCommand from device");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user