83 lines
3.4 KiB
C++
83 lines
3.4 KiB
C++
#pragma once
|
|
|
|
#include <map>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace fgc {
|
|
|
|
// Structured decode of a firmware DUMP block (the text between "DUMP BEGIN" and
|
|
// "DUMP END"). Mirrors firmware/tools/decode_dump.py, which is authoritative for
|
|
// the on-wire field names and the TMC status-register bit tables.
|
|
|
|
struct DumpAxis {
|
|
char axis = '?'; // 'Y' (yaw) / 'P' (pitch)
|
|
std::string state_name = "?"; // BOOT/RESET/HOMING/READY/ERROR
|
|
bool enabled = false;
|
|
bool has_encoder = false;
|
|
long lim_neg = 0;
|
|
long lim_pos = 0;
|
|
long soft_margin = 0; // counts kept clear of each hard limit
|
|
long center_count = 0; // count the firmware anchored the homed midpoint to
|
|
long hold_target = 0;
|
|
long speed = 0;
|
|
// Motor current, as the firmware believes it applied it. GLOBALSCALER and
|
|
// IHOLD_IRUN are write-only on the TMC5160, so this echo is the only way the
|
|
// host can confirm a CURRENT command landed.
|
|
//
|
|
// -1 means the field was absent, i.e. the firmware predates the command -
|
|
// which is a different thing from "applied a current of zero" and has to stay
|
|
// distinguishable, because one is a version skew and the other is a fault.
|
|
long global_scaler = -1;
|
|
long run_irun = -1;
|
|
long homing_irun = -1;
|
|
// The rest of what the host declares and the firmware is told. Same -1
|
|
// convention and the same reason: absent means a firmware that predates the
|
|
// config handshake, which is a version skew, not a value of zero.
|
|
long steps_per_rev = -1;
|
|
long enc_deviation = -1;
|
|
long homing_speed = -1;
|
|
long center_speed = -1;
|
|
long sw_mode = -1;
|
|
// Bitmask over the firmware's CfgKey: which required keys have arrived.
|
|
// -1 when absent.
|
|
long cfg_received = -1;
|
|
// Encoder-tracking health accumulated by the firmware hold corrector.
|
|
long hold_corrections = 0; // # of hold resyncs since firmware boot/RESET
|
|
long hold_peak_dev = 0; // largest deviation seen while holding (counts)
|
|
long hold_cumulative_dev = 0; // sum of corrected deviations (counts)
|
|
int hsub = 0;
|
|
|
|
// Raw register hex strings as received, keyed by name (GCONF, DRV_STATUS...).
|
|
std::map<std::string, std::string> regs;
|
|
|
|
// Decoded status registers + their set-bit names.
|
|
unsigned drv_status = 0;
|
|
unsigned gstat = 0;
|
|
unsigned ramp_stat = 0;
|
|
int cs_actual = 0; // (DRV_STATUS >> 16) & 0x1F
|
|
int sg_result = 0; // DRV_STATUS & 0x3FF
|
|
std::vector<std::string> drv_flags;
|
|
std::vector<std::string> gstat_flags;
|
|
std::vector<std::string> ramp_flags;
|
|
};
|
|
|
|
struct DumpData {
|
|
bool valid = false;
|
|
std::string build;
|
|
long uptime_ms = 0;
|
|
unsigned mcusr = 0;
|
|
long free_ram = 0;
|
|
std::vector<std::string> reset_flags;
|
|
std::vector<DumpAxis> axes;
|
|
};
|
|
|
|
// Parse a raw DUMP block. Returns {valid=false} for empty/malformed input (no
|
|
// "DUMP BEGIN .. DUMP END" pair).
|
|
DumpData parseDump(const std::string& block);
|
|
|
|
// Human-readable lines for a decoded dump (console-reusable pretty print).
|
|
std::vector<std::string> formatDump(const DumpData& d);
|
|
|
|
} // namespace fgc
|