Moved toHex functions to String helper class
This commit is contained in:
@@ -3,7 +3,9 @@
|
|||||||
#include "src/DebugServer/Gdb/ResponsePackets/ErrorResponsePacket.hpp"
|
#include "src/DebugServer/Gdb/ResponsePackets/ErrorResponsePacket.hpp"
|
||||||
#include "src/DebugServer/Gdb/ResponsePackets/ResponsePacket.hpp"
|
#include "src/DebugServer/Gdb/ResponsePackets/ResponsePacket.hpp"
|
||||||
|
|
||||||
|
#include "src/Helpers/String.hpp"
|
||||||
#include "src/Logger/Logger.hpp"
|
#include "src/Logger/Logger.hpp"
|
||||||
|
|
||||||
#include "src/Exceptions/Exception.hpp"
|
#include "src/Exceptions/Exception.hpp"
|
||||||
|
|
||||||
namespace Bloom::DebugServer::Gdb::AvrGdb::CommandPackets
|
namespace Bloom::DebugServer::Gdb::AvrGdb::CommandPackets
|
||||||
@@ -146,7 +148,7 @@ namespace Bloom::DebugServer::Gdb::AvrGdb::CommandPackets
|
|||||||
memoryBuffer.insert(memoryBuffer.end(), (this->bytes - bytesToRead), 0x00);
|
memoryBuffer.insert(memoryBuffer.end(), (this->bytes - bytesToRead), 0x00);
|
||||||
}
|
}
|
||||||
|
|
||||||
debugSession.connection.writePacket(ResponsePacket(Packet::toHex(memoryBuffer)));
|
debugSession.connection.writePacket(ResponsePacket(String::toHex(memoryBuffer)));
|
||||||
|
|
||||||
} catch (const Exception& exception) {
|
} catch (const Exception& exception) {
|
||||||
Logger::error("Failed to read memory from target - " + exception.getMessage());
|
Logger::error("Failed to read memory from target - " + exception.getMessage());
|
||||||
|
|||||||
@@ -6,8 +6,11 @@
|
|||||||
#include "src/DebugServer/Gdb/ResponsePackets/ResponsePacket.hpp"
|
#include "src/DebugServer/Gdb/ResponsePackets/ResponsePacket.hpp"
|
||||||
|
|
||||||
#include "src/Application.hpp"
|
#include "src/Application.hpp"
|
||||||
|
|
||||||
#include "src/Helpers/Paths.hpp"
|
#include "src/Helpers/Paths.hpp"
|
||||||
|
#include "src/Helpers/String.hpp"
|
||||||
#include "src/Logger/Logger.hpp"
|
#include "src/Logger/Logger.hpp"
|
||||||
|
|
||||||
#include "src/Exceptions/Exception.hpp"
|
#include "src/Exceptions/Exception.hpp"
|
||||||
|
|
||||||
namespace Bloom::DebugServer::Gdb::CommandPackets
|
namespace Bloom::DebugServer::Gdb::CommandPackets
|
||||||
@@ -26,7 +29,7 @@ namespace Bloom::DebugServer::Gdb::CommandPackets
|
|||||||
void BloomVersion::handle(DebugSession& debugSession, TargetControllerConsole&) {
|
void BloomVersion::handle(DebugSession& debugSession, TargetControllerConsole&) {
|
||||||
Logger::debug("Handling BloomVersion packet");
|
Logger::debug("Handling BloomVersion packet");
|
||||||
|
|
||||||
debugSession.connection.writePacket(ResponsePacket(Packet::toHex(
|
debugSession.connection.writePacket(ResponsePacket(String::toHex(
|
||||||
std::string(
|
std::string(
|
||||||
"Bloom v" + Application::VERSION.toString() + "\n"
|
"Bloom v" + Application::VERSION.toString() + "\n"
|
||||||
+ Paths::homeDomainName() + "\n"
|
+ Paths::homeDomainName() + "\n"
|
||||||
|
|||||||
@@ -7,7 +7,10 @@
|
|||||||
#include "src/DebugServer/Gdb/ResponsePackets/ResponsePacket.hpp"
|
#include "src/DebugServer/Gdb/ResponsePackets/ResponsePacket.hpp"
|
||||||
|
|
||||||
#include "src/Application.hpp"
|
#include "src/Application.hpp"
|
||||||
|
|
||||||
|
#include "src/Helpers/String.hpp"
|
||||||
#include "src/Logger/Logger.hpp"
|
#include "src/Logger/Logger.hpp"
|
||||||
|
|
||||||
#include "src/Exceptions/Exception.hpp"
|
#include "src/Exceptions/Exception.hpp"
|
||||||
|
|
||||||
namespace Bloom::DebugServer::Gdb::CommandPackets
|
namespace Bloom::DebugServer::Gdb::CommandPackets
|
||||||
@@ -25,7 +28,7 @@ namespace Bloom::DebugServer::Gdb::CommandPackets
|
|||||||
void BloomVersionMachine::handle(DebugSession& debugSession, TargetControllerConsole&) {
|
void BloomVersionMachine::handle(DebugSession& debugSession, TargetControllerConsole&) {
|
||||||
Logger::debug("Handling BloomVersionMachine packet");
|
Logger::debug("Handling BloomVersionMachine packet");
|
||||||
|
|
||||||
debugSession.connection.writePacket(ResponsePacket(Packet::toHex(
|
debugSession.connection.writePacket(ResponsePacket(String::toHex(
|
||||||
QJsonDocument(QJsonObject({
|
QJsonDocument(QJsonObject({
|
||||||
{"version", QString::fromStdString(Application::VERSION.toString())},
|
{"version", QString::fromStdString(Application::VERSION.toString())},
|
||||||
{"components", QJsonObject({
|
{"components", QJsonObject({
|
||||||
|
|||||||
@@ -6,9 +6,11 @@
|
|||||||
#include "src/DebugServer/Gdb/ResponsePackets/ResponsePacket.hpp"
|
#include "src/DebugServer/Gdb/ResponsePackets/ResponsePacket.hpp"
|
||||||
#include "src/DebugServer/Gdb/ResponsePackets/ErrorResponsePacket.hpp"
|
#include "src/DebugServer/Gdb/ResponsePackets/ErrorResponsePacket.hpp"
|
||||||
|
|
||||||
|
#include "src/Helpers/String.hpp"
|
||||||
|
#include "src/Logger/Logger.hpp"
|
||||||
|
|
||||||
#include "src/DebugServer/Gdb/Exceptions/InvalidCommandOption.hpp"
|
#include "src/DebugServer/Gdb/Exceptions/InvalidCommandOption.hpp"
|
||||||
#include "src/Exceptions/Exception.hpp"
|
#include "src/Exceptions/Exception.hpp"
|
||||||
#include "src/Logger/Logger.hpp"
|
|
||||||
|
|
||||||
namespace Bloom::DebugServer::Gdb::CommandPackets
|
namespace Bloom::DebugServer::Gdb::CommandPackets
|
||||||
{
|
{
|
||||||
@@ -85,7 +87,7 @@ namespace Bloom::DebugServer::Gdb::CommandPackets
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto hexValues = Packet::toHex(data);
|
const auto hexValues = String::toHex(data);
|
||||||
Logger::debug("Filling EEPROM with values: " + hexValues);
|
Logger::debug("Filling EEPROM with values: " + hexValues);
|
||||||
|
|
||||||
targetControllerConsole.writeMemory(
|
targetControllerConsole.writeMemory(
|
||||||
@@ -94,13 +96,13 @@ namespace Bloom::DebugServer::Gdb::CommandPackets
|
|||||||
std::move(data)
|
std::move(data)
|
||||||
);
|
);
|
||||||
|
|
||||||
debugSession.connection.writePacket(ResponsePacket(Packet::toHex(
|
debugSession.connection.writePacket(ResponsePacket(String::toHex(
|
||||||
"Filled " + std::to_string(eepromSize) + " bytes of EEPROM, with values: " + hexValues + "\n"
|
"Filled " + std::to_string(eepromSize) + " bytes of EEPROM, with values: " + hexValues + "\n"
|
||||||
)));
|
)));
|
||||||
|
|
||||||
} catch (const InvalidCommandOption& exception) {
|
} catch (const InvalidCommandOption& exception) {
|
||||||
Logger::error(exception.getMessage());
|
Logger::error(exception.getMessage());
|
||||||
debugSession.connection.writePacket(ResponsePacket(Packet::toHex(exception.getMessage() + "\n")));
|
debugSession.connection.writePacket(ResponsePacket(String::toHex(exception.getMessage() + "\n")));
|
||||||
|
|
||||||
} catch (const Exception& exception) {
|
} catch (const Exception& exception) {
|
||||||
Logger::error("Failed to fill EEPROM - " + exception.getMessage());
|
Logger::error("Failed to fill EEPROM - " + exception.getMessage());
|
||||||
|
|||||||
@@ -7,12 +7,14 @@
|
|||||||
#include "src/DebugServer/Gdb/ResponsePackets/ErrorResponsePacket.hpp"
|
#include "src/DebugServer/Gdb/ResponsePackets/ErrorResponsePacket.hpp"
|
||||||
|
|
||||||
#include "src/Targets/TargetMemory.hpp"
|
#include "src/Targets/TargetMemory.hpp"
|
||||||
|
|
||||||
#include "src/Application.hpp"
|
#include "src/Application.hpp"
|
||||||
|
|
||||||
#include "src/Helpers/Paths.hpp"
|
#include "src/Helpers/Paths.hpp"
|
||||||
#include "src/Exceptions/Exception.hpp"
|
#include "src/Helpers/String.hpp"
|
||||||
#include "src/Logger/Logger.hpp"
|
#include "src/Logger/Logger.hpp"
|
||||||
|
|
||||||
|
#include "src/Exceptions/Exception.hpp"
|
||||||
|
|
||||||
namespace Bloom::DebugServer::Gdb::CommandPackets
|
namespace Bloom::DebugServer::Gdb::CommandPackets
|
||||||
{
|
{
|
||||||
using TargetController::TargetControllerConsole;
|
using TargetController::TargetControllerConsole;
|
||||||
@@ -40,7 +42,7 @@ namespace Bloom::DebugServer::Gdb::CommandPackets
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (this->sendOutput) {
|
if (this->sendOutput) {
|
||||||
debugSession.connection.writePacket(ResponsePacket(Packet::toHex(svdXml.toString().toStdString())));
|
debugSession.connection.writePacket(ResponsePacket(String::toHex(svdXml.toString().toStdString())));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +58,7 @@ namespace Bloom::DebugServer::Gdb::CommandPackets
|
|||||||
outputFile.write(svdXml.toByteArray());
|
outputFile.write(svdXml.toByteArray());
|
||||||
outputFile.close();
|
outputFile.close();
|
||||||
|
|
||||||
debugSession.connection.writePacket(ResponsePacket(Packet::toHex(
|
debugSession.connection.writePacket(ResponsePacket(String::toHex(
|
||||||
"SVD output saved to " + svdOutputFilePath + "\n"
|
"SVD output saved to " + svdOutputFilePath + "\n"
|
||||||
)));
|
)));
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,9 @@
|
|||||||
#include "src/DebugServer/Gdb/ResponsePackets/ResponsePacket.hpp"
|
#include "src/DebugServer/Gdb/ResponsePackets/ResponsePacket.hpp"
|
||||||
|
|
||||||
#include "src/Helpers/Paths.hpp"
|
#include "src/Helpers/Paths.hpp"
|
||||||
|
#include "src/Helpers/String.hpp"
|
||||||
#include "src/Logger/Logger.hpp"
|
#include "src/Logger/Logger.hpp"
|
||||||
|
|
||||||
#include "src/Exceptions/Exception.hpp"
|
#include "src/Exceptions/Exception.hpp"
|
||||||
|
|
||||||
namespace Bloom::DebugServer::Gdb::CommandPackets
|
namespace Bloom::DebugServer::Gdb::CommandPackets
|
||||||
@@ -45,7 +47,7 @@ namespace Bloom::DebugServer::Gdb::CommandPackets
|
|||||||
}
|
}
|
||||||
|
|
||||||
debugSession.connection.writePacket(
|
debugSession.connection.writePacket(
|
||||||
ResponsePacket(Packet::toHex("\n" + QTextStream(&helpFile).readAll().toUtf8().toStdString() + "\n"))
|
ResponsePacket(String::toHex("\n" + QTextStream(&helpFile).readAll().toUtf8().toStdString() + "\n"))
|
||||||
);
|
);
|
||||||
|
|
||||||
} catch (const Exception& exception) {
|
} catch (const Exception& exception) {
|
||||||
|
|||||||
@@ -4,7 +4,9 @@
|
|||||||
|
|
||||||
#include "src/Targets/TargetRegister.hpp"
|
#include "src/Targets/TargetRegister.hpp"
|
||||||
|
|
||||||
|
#include "src/Helpers/String.hpp"
|
||||||
#include "src/Logger/Logger.hpp"
|
#include "src/Logger/Logger.hpp"
|
||||||
|
|
||||||
#include "src/Exceptions/Exception.hpp"
|
#include "src/Exceptions/Exception.hpp"
|
||||||
|
|
||||||
namespace Bloom::DebugServer::Gdb::CommandPackets
|
namespace Bloom::DebugServer::Gdb::CommandPackets
|
||||||
@@ -87,7 +89,7 @@ namespace Bloom::DebugServer::Gdb::CommandPackets
|
|||||||
}
|
}
|
||||||
|
|
||||||
debugSession.connection.writePacket(
|
debugSession.connection.writePacket(
|
||||||
ResponsePacket(Packet::toHex(registers))
|
ResponsePacket(String::toHex(registers))
|
||||||
);
|
);
|
||||||
|
|
||||||
} catch (const Exception& exception) {
|
} catch (const Exception& exception) {
|
||||||
|
|||||||
@@ -3,7 +3,9 @@
|
|||||||
#include "src/DebugServer/Gdb/ResponsePackets/ErrorResponsePacket.hpp"
|
#include "src/DebugServer/Gdb/ResponsePackets/ErrorResponsePacket.hpp"
|
||||||
#include "src/DebugServer/Gdb/ResponsePackets/ResponsePacket.hpp"
|
#include "src/DebugServer/Gdb/ResponsePackets/ResponsePacket.hpp"
|
||||||
|
|
||||||
|
#include "src/Helpers/String.hpp"
|
||||||
#include "src/Logger/Logger.hpp"
|
#include "src/Logger/Logger.hpp"
|
||||||
|
|
||||||
#include "src/Exceptions/Exception.hpp"
|
#include "src/Exceptions/Exception.hpp"
|
||||||
|
|
||||||
namespace Bloom::DebugServer::Gdb::CommandPackets
|
namespace Bloom::DebugServer::Gdb::CommandPackets
|
||||||
@@ -27,7 +29,7 @@ namespace Bloom::DebugServer::Gdb::CommandPackets
|
|||||||
targetControllerConsole.resetTarget();
|
targetControllerConsole.resetTarget();
|
||||||
Logger::info("Target reset complete");
|
Logger::info("Target reset complete");
|
||||||
|
|
||||||
debugSession.connection.writePacket(ResponsePacket(Packet::toHex(
|
debugSession.connection.writePacket(ResponsePacket(String::toHex(
|
||||||
"Target reset complete - use the 'continue' command to begin execution.\n"
|
"Target reset complete - use the 'continue' command to begin execution.\n"
|
||||||
)));
|
)));
|
||||||
|
|
||||||
|
|||||||
@@ -83,42 +83,6 @@ namespace Bloom::DebugServer::Gdb
|
|||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts raw data to hexadecimal form, the form in which responses are expected to be delivered from the
|
|
||||||
* server.
|
|
||||||
*
|
|
||||||
* @param data
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
static std::string toHex(const std::vector<unsigned char>& data) {
|
|
||||||
std::stringstream stream;
|
|
||||||
stream << std::hex << std::setfill('0');
|
|
||||||
|
|
||||||
for (const auto& byte : data) {
|
|
||||||
stream << std::setw(2) << static_cast<unsigned int>(byte);
|
|
||||||
}
|
|
||||||
|
|
||||||
return stream.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a string to hexadecimal form, the form in which responses are expected to be delivered from the
|
|
||||||
* server.
|
|
||||||
*
|
|
||||||
* @param data
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
static std::string toHex(const std::string& data) {
|
|
||||||
std::stringstream stream;
|
|
||||||
stream << std::hex << std::setfill('0');
|
|
||||||
|
|
||||||
for (const auto& byte : data) {
|
|
||||||
stream << std::setw(2) << static_cast<unsigned int>(byte);
|
|
||||||
}
|
|
||||||
|
|
||||||
return stream.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts data in hexadecimal form to raw data.
|
* Converts data in hexadecimal form to raw data.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
#include "src/DebugServer/Gdb/Signal.hpp"
|
#include "src/DebugServer/Gdb/Signal.hpp"
|
||||||
#include "src/DebugServer/Gdb/StopReason.hpp"
|
#include "src/DebugServer/Gdb/StopReason.hpp"
|
||||||
|
|
||||||
|
#include "src/Helpers/String.hpp"
|
||||||
|
|
||||||
namespace Bloom::DebugServer::Gdb::ResponsePackets
|
namespace Bloom::DebugServer::Gdb::ResponsePackets
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -23,7 +25,7 @@ namespace Bloom::DebugServer::Gdb::ResponsePackets
|
|||||||
: signal(signal)
|
: signal(signal)
|
||||||
, stopReason(stopReason)
|
, stopReason(stopReason)
|
||||||
{
|
{
|
||||||
std::string packetData = "T" + Packet::toHex(std::vector({static_cast<unsigned char>(this->signal)}));
|
std::string packetData = "T" + String::toHex(std::vector({static_cast<unsigned char>(this->signal)}));
|
||||||
|
|
||||||
if (this->stopReason.has_value()) {
|
if (this->stopReason.has_value()) {
|
||||||
static const auto stopReasonMapping = getStopReasonToNameMapping();
|
static const auto stopReasonMapping = getStopReasonToNameMapping();
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
#include <sstream>
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
namespace Bloom
|
namespace Bloom
|
||||||
{
|
{
|
||||||
@@ -26,4 +28,32 @@ namespace Bloom
|
|||||||
return character > 127;
|
return character > 127;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string String::toHex(unsigned char value) {
|
||||||
|
auto stream = std::stringstream();
|
||||||
|
stream << std::hex << std::setfill('0') << std::setw(2) << static_cast<unsigned int>(value);
|
||||||
|
return stream.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string String::toHex(const std::vector<unsigned char>& data) {
|
||||||
|
auto stream = std::stringstream();
|
||||||
|
stream << std::hex << std::setfill('0');
|
||||||
|
|
||||||
|
for (const auto& byte : data) {
|
||||||
|
stream << std::setw(2) << static_cast<unsigned int>(byte);
|
||||||
|
}
|
||||||
|
|
||||||
|
return stream.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string String::toHex(const std::string& data) {
|
||||||
|
std::stringstream stream;
|
||||||
|
stream << std::hex << std::setfill('0');
|
||||||
|
|
||||||
|
for (const auto& byte : data) {
|
||||||
|
stream << std::setw(2) << static_cast<unsigned int>(byte);
|
||||||
|
}
|
||||||
|
|
||||||
|
return stream.str();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace Bloom
|
namespace Bloom
|
||||||
{
|
{
|
||||||
@@ -12,5 +13,9 @@ namespace Bloom
|
|||||||
static std::string asciiToUpper(std::string str);
|
static std::string asciiToUpper(std::string str);
|
||||||
|
|
||||||
static bool isAscii(const std::string& str);
|
static bool isAscii(const std::string& str);
|
||||||
|
|
||||||
|
static std::string toHex(unsigned char value);
|
||||||
|
static std::string toHex(const std::vector<unsigned char>& data);
|
||||||
|
static std::string toHex(const std::string& data);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user