默认暗色模式,添加值显示开关
This commit is contained in:
@@ -27,10 +27,12 @@ using nlohmann::json;
|
||||
// void dump_compact_json(...)
|
||||
// json serialize_tactile_frame(const DecodedFrame& frame) { ... }
|
||||
|
||||
std::string payload_to_csv_row(const std::vector<std::uint8_t>& payload) {
|
||||
// Combine every 2 bytes (little-endian) into one 16-bit value, output in decimal.
|
||||
std::string payload_to_csv_row(const std::string& timestamp,
|
||||
const std::vector<std::uint8_t>& payload) {
|
||||
// First column: receive local time (YYYYMMDDHHMMSS). Then payload every 2 bytes -> uint16.
|
||||
std::ostringstream oss;
|
||||
bool first = true;
|
||||
oss << timestamp;
|
||||
bool first = false; // timestamp already placed
|
||||
for (std::size_t idx = 0; idx + 1U < payload.size(); idx += 2U) {
|
||||
const auto value =
|
||||
static_cast<std::uint16_t>(payload[idx]) | static_cast<std::uint16_t>(payload[idx + 1U] << 8U);
|
||||
@@ -49,6 +51,28 @@ std::string payload_to_csv_row(const std::vector<std::uint8_t>& payload) {
|
||||
namespace {
|
||||
using nlohmann::json;
|
||||
|
||||
std::string format_receive_time(const std::chrono::steady_clock::time_point& received) {
|
||||
// Map steady_clock timestamp to system_clock using the current offset, then format as YYYYMMDDHHMMSS.
|
||||
const auto now_sys = std::chrono::system_clock::now();
|
||||
const auto now_steady = std::chrono::steady_clock::now();
|
||||
const auto steady_delta = received - now_steady;
|
||||
const auto sys_tp = now_sys + steady_delta;
|
||||
const auto sys_ms_tp = std::chrono::time_point_cast<std::chrono::milliseconds>(sys_tp);
|
||||
const auto ms_part = std::chrono::duration_cast<std::chrono::milliseconds>(sys_ms_tp.time_since_epoch()) % 1000;
|
||||
const auto sys_sec_tp = std::chrono::time_point_cast<std::chrono::seconds>(sys_ms_tp);
|
||||
const std::time_t tt = std::chrono::system_clock::to_time_t(sys_sec_tp);
|
||||
std::tm tm{};
|
||||
#if defined(_WIN32)
|
||||
localtime_s(&tm, &tt);
|
||||
#else
|
||||
localtime_r(&tt, &tm);
|
||||
#endif
|
||||
std::ostringstream oss;
|
||||
oss << std::put_time(&tm, "%Y%m%d%H%M%S")
|
||||
<< std::setw(3) << std::setfill('0') << ms_part.count();
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
bool is_simple_array(const json& value) {
|
||||
if (!value.is_array()) {
|
||||
return false;
|
||||
@@ -261,7 +285,8 @@ std::deque<std::shared_ptr<DecodedFrame>> frames) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto row = payload_to_csv_row(payload);
|
||||
const auto timestamp = format_receive_time(frame->received_at);
|
||||
const auto row = payload_to_csv_row(timestamp, payload);
|
||||
stream << row << '\n';
|
||||
wrote_any = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user