Skip to content

Commit

Permalink
Compilation error
Browse files Browse the repository at this point in the history
  • Loading branch information
Keidan committed Apr 14, 2024
1 parent 4d93e6c commit 769a21f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
16 changes: 16 additions & 0 deletions src/Helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,22 @@ namespace h2b
return static_cast<T>(t);
}

/**
* @brief Converts an integer to a hexadecimal string.
*
* @param[in] t integer.
* @retval std::string
*/
template <typename T>
static auto int2hex(T t, char fill = '0', int width = 1) -> std::string
{
std::stringstream ss;
ss << std::hex << hex;
ss << std::setfill(fill);
ss << std::setw(width);
ss << t;
return ss.str();
}
private:
Helper() = default;
};
Expand Down
16 changes: 8 additions & 8 deletions src/IntelHex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,12 @@ auto IntelHex::convertLine(const Line& line) -> std::string
address = 0U;
std::stringstream ss;
ss << ":";
ss << std::format("{0:02X}", line.data.size());
ss << std::format("{0:04X}", address);
ss << std::format("{0:02X}", +static_cast<std::uint8_t>(line.type));
ss << Helper::int2hex(line.data.size(), '0', 2);
ss << Helper::int2hex(address, '0', 4);
ss << Helper::int2hex(+static_cast<std::uint8_t>(line.type), '0', 2);
for(const auto& dd : line.data)
ss << std::format("{0:02X}", +dd);
ss << std::format("{0:02X}", +line.checksum);
ss << Helper::int2hex(+dd, '0', 2);
ss << Helper::int2hex(+line.checksum, '0', 2);
ss << "\n";
return ss.str();
}
Expand Down Expand Up @@ -492,9 +492,9 @@ auto IntelHex::processData(const Line& line, std::uint32_t number, std::uint32_t
else
{
#if 1
std::cerr << std::format("Off-range address on line {}", number);
std::cerr << std::format(", address: 0x{0:X}", m_currentAddress);
std::cerr << std::format(", offset: 0x{0:X}", m_addrOffset) << std::endl;
std::cerr << "Off-range address on line " << number;
std::cerr << ", address: 0x" << Helper::int2hex(m_currentAddress);
std::cerr << ", offset: 0x" << Helper::int2hex(m_addrOffset) << std::endl;
#endif
m_currentAddress += line.length;
/* next packet*/
Expand Down

0 comments on commit 769a21f

Please sign in to comment.