mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-09-11 00:23:43 +08:00
0e51ecbb7e
version: sunnypilot v2026.003.000 (dev)
date: 2026-09-09T15:43:49
master commit: b255314f5a
34 lines
825 B
C++
34 lines
825 B
C++
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <cstdio>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace cabana { class Signal; }
|
|
|
|
namespace utils {
|
|
|
|
std::string formatSeconds(double sec, bool include_milliseconds = false, bool absolute_time = false);
|
|
std::string signalToolTip(const cabana::Signal *sig);
|
|
|
|
inline std::string toHex(const std::vector<uint8_t> &dat, char separator = '\0') {
|
|
static const char digits[] = "0123456789ABCDEF";
|
|
std::string hex;
|
|
hex.reserve(dat.size() * (separator ? 3 : 2));
|
|
for (size_t i = 0; i < dat.size(); ++i) {
|
|
if (separator && i) hex += separator;
|
|
hex += digits[dat[i] >> 4];
|
|
hex += digits[dat[i] & 0xf];
|
|
}
|
|
return hex;
|
|
}
|
|
|
|
inline std::string toHexString(int value) {
|
|
char buf[16] = {};
|
|
snprintf(buf, sizeof(buf), "0x%02X", value);
|
|
return buf;
|
|
}
|
|
|
|
} // namespace utils
|