Files
BloomPatched/src/DebugToolDrivers/Protocols/CMSIS-DAP/CmsisDapInterface.cpp

31 lines
1.0 KiB
C++
Raw Normal View History

#include "CmsisDapInterface.hpp"
2021-04-04 21:04:12 +01:00
#include <thread>
#include "src/DebugToolDrivers/Protocols/CMSIS-DAP/Command.hpp"
namespace DebugToolDrivers::Protocols::CmsisDap
{
using namespace Exceptions;
2021-04-04 21:04:12 +01:00
CmsisDapInterface::CmsisDapInterface(Usb::HidInterface&& usbHidInterface)
: usbHidInterface(std::move(usbHidInterface))
{}
void CmsisDapInterface::sendCommand(const Command& cmsisDapCommand) {
if (this->msSendCommandDelay.count() > 0) {
using namespace std::chrono;
std::int64_t now = duration_cast<milliseconds>(high_resolution_clock::now().time_since_epoch()).count();
std::int64_t difference = (now - this->lastCommandSentTimeStamp);
2021-04-04 21:04:12 +01:00
if (difference < this->msSendCommandDelay.count()) {
std::this_thread::sleep_for(milliseconds(this->msSendCommandDelay.count() - difference));
}
this->lastCommandSentTimeStamp = now;
2021-04-04 21:04:12 +01:00
}
this->getUsbHidInterface().write(cmsisDapCommand.rawCommand());
2021-04-04 21:04:12 +01:00
}
}