Tidying
This commit is contained in:
@@ -15,8 +15,15 @@ namespace Bloom
|
||||
class DebugTool
|
||||
{
|
||||
public:
|
||||
DebugTool() = default;
|
||||
virtual ~DebugTool() = default;
|
||||
|
||||
DebugTool(const DebugTool& other) = default;
|
||||
DebugTool(DebugTool&& other) = default;
|
||||
|
||||
DebugTool& operator = (const DebugTool& other) = default;
|
||||
DebugTool& operator = (DebugTool&& other) = default;
|
||||
|
||||
/**
|
||||
* Should establish a connection to the device and prepare it for a debug session.
|
||||
*/
|
||||
|
||||
@@ -12,8 +12,8 @@ using namespace Bloom::Exceptions;
|
||||
void CmsisDapInterface::sendCommand(const Command& cmsisDapCommand) {
|
||||
if (this->msSendCommandDelay.count() > 0) {
|
||||
using namespace std::chrono;
|
||||
long now = duration_cast<milliseconds>(high_resolution_clock::now().time_since_epoch()).count();
|
||||
long difference = (now - this->lastCommandSentTimeStamp);
|
||||
std::int64_t now = duration_cast<milliseconds>(high_resolution_clock::now().time_since_epoch()).count();
|
||||
std::int64_t difference = (now - this->lastCommandSentTimeStamp);
|
||||
|
||||
if (difference < this->msSendCommandDelay.count()) {
|
||||
std::this_thread::sleep_for(milliseconds(this->msSendCommandDelay.count() - difference));
|
||||
@@ -28,7 +28,7 @@ void CmsisDapInterface::sendCommand(const Command& cmsisDapCommand) {
|
||||
std::unique_ptr<Response> CmsisDapInterface::getResponse() {
|
||||
auto rawResponse = this->getUsbHidInterface().read(10000);
|
||||
|
||||
if (rawResponse.size() == 0) {
|
||||
if (rawResponse.empty()) {
|
||||
throw DeviceCommunicationFailure("Empty CMSIS-DAP response received");
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,13 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap
|
||||
{
|
||||
public:
|
||||
explicit CmsisDapInterface() = default;
|
||||
virtual ~CmsisDapInterface() = default;
|
||||
|
||||
CmsisDapInterface(const CmsisDapInterface& other) = default;
|
||||
CmsisDapInterface(CmsisDapInterface&& other) = default;
|
||||
|
||||
CmsisDapInterface& operator = (const CmsisDapInterface& other) = default;
|
||||
CmsisDapInterface& operator = (CmsisDapInterface&& other) = default;
|
||||
|
||||
Usb::HidInterface& getUsbHidInterface() {
|
||||
return this->usbHidInterface;
|
||||
@@ -80,6 +87,6 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap
|
||||
* being sent, where x is the value of msSendCommandDelay.
|
||||
*/
|
||||
std::chrono::milliseconds msSendCommandDelay = std::chrono::milliseconds(0);
|
||||
long lastCommandSentTimeStamp = 0;
|
||||
std::int64_t lastCommandSentTimeStamp = 0;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -8,8 +8,15 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap
|
||||
class Command
|
||||
{
|
||||
public:
|
||||
Command() = default;
|
||||
virtual ~Command() = default;
|
||||
|
||||
Command(const Command& other) = default;
|
||||
Command(Command&& other) = default;
|
||||
|
||||
Command& operator = (const Command& other) = default;
|
||||
Command& operator = (Command&& other) = default;
|
||||
|
||||
[[nodiscard]] unsigned char getCommandId() const {
|
||||
return this->commandId;
|
||||
}
|
||||
@@ -28,11 +35,11 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap
|
||||
|
||||
[[nodiscard]] int getCommandSize() const {
|
||||
// +1 for the command ID
|
||||
return (int) (1 + this->getData().size());
|
||||
return static_cast<int>(1 + this->getData().size());
|
||||
}
|
||||
|
||||
[[nodiscard]] std::uint16_t getDataSize() const {
|
||||
return (std::uint16_t) this->getData().size();
|
||||
return static_cast<std::uint16_t>(this->getData().size());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,6 +10,12 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap
|
||||
Response() = default;
|
||||
virtual ~Response() = default;
|
||||
|
||||
Response(const Response& other) = default;
|
||||
Response(Response&& other) = default;
|
||||
|
||||
Response& operator = (const Response& other) = default;
|
||||
Response& operator = (Response&& other) = default;
|
||||
|
||||
virtual void init(const std::vector<unsigned char>& rawResponse);
|
||||
|
||||
[[nodiscard]] unsigned char getResponseId() const {
|
||||
|
||||
@@ -12,11 +12,11 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
|
||||
AVR8_BREAK_EVENT = 0x40,
|
||||
};
|
||||
|
||||
inline bool operator==(unsigned char rawId, AvrEventId id) {
|
||||
inline bool operator == (unsigned char rawId, AvrEventId id) {
|
||||
return static_cast<unsigned char>(id) == rawId;
|
||||
}
|
||||
|
||||
inline bool operator==(AvrEventId id, unsigned char rawId) {
|
||||
inline bool operator == (AvrEventId id, unsigned char rawId) {
|
||||
return rawId == id;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,13 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
|
||||
AvrCommandFrame::lastSequenceId = 0;
|
||||
}
|
||||
};
|
||||
virtual ~AvrCommandFrame() = default;
|
||||
|
||||
AvrCommandFrame(const AvrCommandFrame& other) = default;
|
||||
AvrCommandFrame(AvrCommandFrame&& other) = default;
|
||||
|
||||
AvrCommandFrame& operator = (const AvrCommandFrame& other) = default;
|
||||
AvrCommandFrame& operator = (AvrCommandFrame&& other) = default;
|
||||
|
||||
[[nodiscard]] unsigned char getProtocolVersion() const {
|
||||
return this->protocolVersion;
|
||||
|
||||
@@ -18,19 +18,19 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
|
||||
FAILED = 0xA0,
|
||||
};
|
||||
|
||||
inline bool operator==(unsigned char rawId, ResponseId id) {
|
||||
inline bool operator == (unsigned char rawId, ResponseId id) {
|
||||
return static_cast<unsigned char>(id) == rawId;
|
||||
}
|
||||
|
||||
inline bool operator==(ResponseId id, unsigned char rawId) {
|
||||
inline bool operator == (ResponseId id, unsigned char rawId) {
|
||||
return static_cast<unsigned char>(id) == rawId;
|
||||
}
|
||||
|
||||
inline bool operator!=(unsigned char rawId, ResponseId id) {
|
||||
inline bool operator != (unsigned char rawId, ResponseId id) {
|
||||
return static_cast<unsigned char>(id) != rawId;
|
||||
}
|
||||
|
||||
inline bool operator!=(ResponseId id, unsigned char rawId) {
|
||||
inline bool operator != (ResponseId id, unsigned char rawId) {
|
||||
return static_cast<unsigned char>(id) != rawId;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,11 +13,11 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr::CommandFrames
|
||||
FAILED_WITH_DATA = 0xA1
|
||||
};
|
||||
|
||||
inline bool operator==(unsigned char rawId, ResponseId id) {
|
||||
inline bool operator == (unsigned char rawId, ResponseId id) {
|
||||
return static_cast<unsigned char>(id) == rawId;
|
||||
}
|
||||
|
||||
inline bool operator==(ResponseId id, unsigned char rawId) {
|
||||
inline bool operator == (ResponseId id, unsigned char rawId) {
|
||||
return rawId == id;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,14 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
|
||||
this->initFromAvrResponses(AVRResponses);
|
||||
}
|
||||
|
||||
virtual ~AvrResponseFrame() = default;
|
||||
|
||||
AvrResponseFrame(const AvrResponseFrame& other) = default;
|
||||
AvrResponseFrame(AvrResponseFrame&& other) = default;
|
||||
|
||||
AvrResponseFrame& operator = (const AvrResponseFrame& other) = default;
|
||||
AvrResponseFrame& operator = (AvrResponseFrame&& other) = default;
|
||||
|
||||
/**
|
||||
* An AVRResponse contains a single fragment of an AvrResponseFrame.
|
||||
*
|
||||
|
||||
@@ -26,6 +26,15 @@ namespace Bloom::DebugToolDrivers::TargetInterfaces::Microchip::Avr::Avr8
|
||||
class Avr8Interface
|
||||
{
|
||||
public:
|
||||
Avr8Interface() = default;
|
||||
virtual ~Avr8Interface() = default;
|
||||
|
||||
Avr8Interface(const Avr8Interface& other) = default;
|
||||
Avr8Interface(Avr8Interface&& other) = default;
|
||||
|
||||
Avr8Interface& operator = (const Avr8Interface& other) = default;
|
||||
Avr8Interface& operator = (Avr8Interface&& other) = default;
|
||||
|
||||
/**
|
||||
* Configures the interface. Any debug tool -> target interface specific configuration should take
|
||||
* place here.
|
||||
|
||||
@@ -14,7 +14,7 @@ void HidInterface::init() {
|
||||
}
|
||||
|
||||
hid_init();
|
||||
hid_device* hidDevice;
|
||||
hid_device* hidDevice = nullptr;
|
||||
|
||||
std::string hidInterfacePath = this->getDevicePathByInterfaceNumber(this->getNumber());
|
||||
Logger::debug("HID device path: " + hidInterfacePath);
|
||||
@@ -36,7 +36,7 @@ void HidInterface::init() {
|
||||
}
|
||||
|
||||
void HidInterface::close() {
|
||||
auto hidDevice = this->getHidDevice();
|
||||
auto* hidDevice = this->getHidDevice();
|
||||
|
||||
if (hidDevice != nullptr) {
|
||||
this->libUsbDeviceHandle = nullptr;
|
||||
@@ -74,8 +74,9 @@ void HidInterface::write(std::vector<unsigned char> buffer) {
|
||||
throw DeviceCommunicationFailure(
|
||||
"Cannot send data via HID interface - data exceeds maximum packet size."
|
||||
);
|
||||
}
|
||||
|
||||
} else if (buffer.size() < this->getInputReportSize()) {
|
||||
if (buffer.size() < this->getInputReportSize()) {
|
||||
/*
|
||||
* Every report we send via the USB HID interface should be of a fixed size.
|
||||
* In the event of a report being too small, we just fill the buffer vector with 0.
|
||||
@@ -83,7 +84,7 @@ void HidInterface::write(std::vector<unsigned char> buffer) {
|
||||
buffer.resize(this->getInputReportSize(), 0);
|
||||
}
|
||||
|
||||
int transferred;
|
||||
int transferred = 0;
|
||||
auto length = buffer.size();
|
||||
|
||||
if ((transferred = hid_write(this->getHidDevice(), buffer.data(), length)) != length) {
|
||||
|
||||
@@ -15,6 +15,14 @@ namespace Bloom::Usb
|
||||
this->setNumber(interfaceNumber);
|
||||
}
|
||||
|
||||
virtual ~Interface() = default;
|
||||
|
||||
Interface(const Interface& other) = default;
|
||||
Interface(Interface&& other) = default;
|
||||
|
||||
Interface& operator = (const Interface& other) = default;
|
||||
Interface& operator = (Interface&& other) = default;
|
||||
|
||||
void setLibUsbDevice(libusb_device* libUsbDevice) {
|
||||
this->libUsbDevice = libUsbDevice;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,14 @@ namespace Bloom::Usb
|
||||
{
|
||||
public:
|
||||
UsbDevice(std::uint16_t vendorId, std::uint16_t productId): vendorId(vendorId), productId(productId) {};
|
||||
~UsbDevice() = default;
|
||||
|
||||
virtual ~UsbDevice() = default;
|
||||
|
||||
UsbDevice(const UsbDevice& other) = default;
|
||||
UsbDevice(UsbDevice&& other) = default;
|
||||
|
||||
UsbDevice& operator = (const UsbDevice& other) = default;
|
||||
UsbDevice& operator = (UsbDevice&& other) = default;
|
||||
|
||||
void init();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user