Files
BloomPatched/src/DebugToolDrivers/Microchip/Protocols/EDBG/AVR/AvrResponse.cpp

42 lines
1.4 KiB
C++
Raw Normal View History

2021-10-02 17:39:27 +01:00
#include "AvrResponse.hpp"
2021-04-04 21:04:12 +01:00
#include "src/Exceptions/Exception.hpp"
namespace DebugToolDrivers::Microchip::Protocols::Edbg::Avr
{
using namespace Exceptions;
2021-04-04 21:04:12 +01:00
AvrResponse::AvrResponse(const std::vector<unsigned char>& rawResponse)
: Response(rawResponse)
{
if (this->id != 0x81) {
throw Exception{"Failed to construct AvrResponse object - invalid response ID."};
}
2021-04-04 21:04:12 +01:00
if (this->data.empty()) {
// All AVR responses should contain at least one byte (the fragment info byte)
throw Exception{"Failed to construct AvrResponse object - malformed AVR_RSP data"};
}
2021-04-04 21:04:12 +01:00
if (this->data[0] == 0x00) {
// This AVR Response contains no data (the device had no data to send), so we can stop here.
return;
}
2021-04-04 21:04:12 +01:00
this->fragmentCount = static_cast<std::uint8_t>(this->data[0] & 0x0FU);
this->fragmentNumber = static_cast<std::uint8_t>(this->data[0] >> 4);
2021-04-04 21:04:12 +01:00
// Response size is two bytes, MSB
const auto responsePacketSize = static_cast<std::uint16_t>((this->data[1] << 8U) + this->data[2]);
if (responsePacketSize > 0) {
// Packet data
this->responsePacket.insert(
this->responsePacket.begin(),
this->data.begin() + 3,
this->data.begin() + 3 + responsePacketSize
);
}
}
2021-04-04 21:04:12 +01:00
}