feat(config,diagnostics): explicit transport in DeviceConfig, vendor-neutral diagnostics
DeviceConfig now carries an optional transport (serial/udp/tcp) instead of
the ESPE-only use_udp bool. Plugins validate it in create_driver_instance:
a fixed-transport driver configured with the wrong transport fails open()
with InvalidConfig (via InvalidConfigDriver — the plugin ABI forbids
returning nullptr) rather than silently ignoring the setting. Selectable
drivers (ESPE) switch TCP/UDP through the same field. config.json
load/save round-trips "transport" for every transport, including serial,
and migrates legacy use_udp:true entries.
Diagnostics drops the per-vendor accessors (espe_fault, rplidar_fault,
monitor_fault, sick_error, pollution_*, contamination_*, manipulation) for
one common shape: a list of DiagnosticIssue{severity, code, detail} with
cross-vendor codes, plus a raw map of vendor passthrough values and
to_json() for hosts that prefer a string. Vendor bit decoding now lives in
one place (decode_diagnostics); has_fault/has_warning/healthy keep their
meaning, so is_ready()/wait_ready() are unchanged.
Also: README regains the model/protocol and ExtraInfo tables lost in the
lidarlib->xlidar refactor (verified against current code), and the empty
xlocd/ tree left by a stray sync run is gone.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -132,23 +132,89 @@ struct ScanResult {
|
||||
ExtraInfo info;
|
||||
};
|
||||
|
||||
// Decode the diagnostic fields of one scan; sets valid = true.
|
||||
// Decode the diagnostic fields of one scan into the vendor-neutral
|
||||
// Diagnostics structure; sets valid = true. Vendor bit layouts are decoded
|
||||
// here (constants in lidar_diagnostics.hpp) so hosts only ever see common
|
||||
// issue codes; the raw values ride along in Diagnostics::raw.
|
||||
inline Diagnostics decode_diagnostics(const ExtraInfo& info) {
|
||||
Diagnostics d;
|
||||
d.valid = true;
|
||||
d.model = info.detected_model;
|
||||
d.error_status = info.error_status;
|
||||
d.rotation_raw = info.rotation_raw;
|
||||
d.scan_frequency_raw = info.scan_frequency_raw;
|
||||
d.input_status = info.input_status;
|
||||
d.output_status = info.output_status;
|
||||
d.field_status = info.field_status;
|
||||
d.status_flags = info.status_flags;
|
||||
d.sick_device_status = info.sick_device_status;
|
||||
d.nano_general_state = info.nano_general_state;
|
||||
d.espe_error_status = info.espe_error_status;
|
||||
d.rplidar_health_status = info.rplidar_health_status;
|
||||
d.rplidar_error_code = info.rplidar_error_code;
|
||||
d.valid = true;
|
||||
d.model = info.detected_model;
|
||||
|
||||
const auto add = [&d](DiagSeverity severity, const char* code, std::string detail) {
|
||||
d.issues.push_back({severity, code, std::move(detail)});
|
||||
};
|
||||
char buf[48];
|
||||
|
||||
// OLEI Family A error byte (Family B/C don't carry it — stays 0).
|
||||
if (info.error_status != 0) {
|
||||
d.raw["olei.error_status"] = info.error_status;
|
||||
if (info.error_status & kFaultMonitor)
|
||||
add(DiagSeverity::Fault, "motor", "OLEI monitor/motor abnormal");
|
||||
if (info.error_status & kFaultVoltage)
|
||||
add(DiagSeverity::Fault, "voltage", "OLEI supply voltage out of range");
|
||||
if (info.error_status & kFaultTemperature)
|
||||
add(DiagSeverity::Fault, "temperature", "OLEI internal temperature abnormal");
|
||||
if (const uint8_t rest = info.error_status
|
||||
& static_cast<uint8_t>(~(kFaultMonitor | kFaultVoltage | kFaultTemperature))) {
|
||||
std::snprintf(buf, sizeof(buf), "OLEI reserved error bits 0x%02X", rest);
|
||||
add(DiagSeverity::Fault, "device_error", buf);
|
||||
}
|
||||
}
|
||||
|
||||
// OLEI raw passthroughs (meanings unverified — no issue decoding).
|
||||
if (info.rotation_raw) d.raw["olei.rotation"] = *info.rotation_raw;
|
||||
if (info.distance_ratio_raw) d.raw["olei.distance_ratio"] = *info.distance_ratio_raw;
|
||||
if (info.scan_frequency_raw) d.raw["olei.scan_frequency"] = *info.scan_frequency_raw;
|
||||
if (info.input_status) d.raw["olei.input_status"] = *info.input_status;
|
||||
if (info.output_status) d.raw["olei.output_status"] = *info.output_status;
|
||||
if (info.field_status) d.raw["olei.field_status"] = *info.field_status;
|
||||
if (info.status_flags) d.raw["olei.status_flags"] = *info.status_flags;
|
||||
|
||||
// SICK TiM device status pair.
|
||||
if (info.sick_device_status) {
|
||||
d.raw["sick.device_status"] = *info.sick_device_status;
|
||||
if (*info.sick_device_status & kSickStatusError)
|
||||
add(DiagSeverity::Fault, "device_error", "SICK TiM device error");
|
||||
if (*info.sick_device_status & kSickStatusPollutionWarning)
|
||||
add(DiagSeverity::Warning, "optics_dirty", "SICK TiM pollution warning");
|
||||
if (*info.sick_device_status & kSickStatusPollutionError)
|
||||
add(DiagSeverity::Fault, "optics_dirty", "SICK TiM pollution error");
|
||||
}
|
||||
|
||||
// SICK nanoScan3 general system state.
|
||||
if (info.nano_general_state) {
|
||||
d.raw["nano.general_state"] = *info.nano_general_state;
|
||||
if (*info.nano_general_state & kNanoStateContaminationWarning)
|
||||
add(DiagSeverity::Warning, "optics_dirty", "nanoScan3 contamination warning");
|
||||
if (*info.nano_general_state & kNanoStateContaminationError)
|
||||
add(DiagSeverity::Fault, "optics_dirty", "nanoScan3 contamination error");
|
||||
if (*info.nano_general_state & kNanoStateManipulation)
|
||||
add(DiagSeverity::Fault, "manipulation", "nanoScan3 manipulation suspected");
|
||||
}
|
||||
|
||||
// ESPE fault word (bit meanings unverified).
|
||||
if (info.espe_error_status) {
|
||||
d.raw["espe.error_status"] = *info.espe_error_status;
|
||||
if (*info.espe_error_status != 0) {
|
||||
std::snprintf(buf, sizeof(buf), "ESPE fault word 0x%04X", *info.espe_error_status);
|
||||
add(DiagSeverity::Fault, "device_error", buf);
|
||||
}
|
||||
}
|
||||
|
||||
// RPLIDAR SDK health.
|
||||
if (info.rplidar_health_status) {
|
||||
d.raw["rplidar.health_status"] = *info.rplidar_health_status;
|
||||
if (info.rplidar_error_code) d.raw["rplidar.error_code"] = *info.rplidar_error_code;
|
||||
if (*info.rplidar_health_status == kRplidarHealthError) {
|
||||
std::snprintf(buf, sizeof(buf), "RPLIDAR health error, code 0x%04X",
|
||||
info.rplidar_error_code ? *info.rplidar_error_code : 0);
|
||||
add(DiagSeverity::Fault, "device_error", buf);
|
||||
} else if (*info.rplidar_health_status == kRplidarHealthWarning) {
|
||||
add(DiagSeverity::Warning, "device_warning", "RPLIDAR health warning");
|
||||
}
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
@@ -183,7 +249,7 @@ using ScanCallback = std::function<void(const ScanResult&)>;
|
||||
|
||||
// Transport a driver uses to reach the device. A driver declares exactly one
|
||||
// primary transport; drivers that can switch (e.g. ESPE TCP/UDP) declare the
|
||||
// default and honor DeviceConfig::use_udp.
|
||||
// default and honor DeviceConfig::transport.
|
||||
enum class Transport { Serial, Udp, Tcp };
|
||||
|
||||
inline const char* to_string(Transport t) {
|
||||
@@ -195,6 +261,14 @@ inline const char* to_string(Transport t) {
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
// Parse the strings written by to_string(Transport); nullopt for anything else.
|
||||
inline std::optional<Transport> transport_from_string(const std::string& s) {
|
||||
if (s == "serial") return Transport::Serial;
|
||||
if (s == "udp") return Transport::Udp;
|
||||
if (s == "tcp") return Transport::Tcp;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// Static identity a plugin registers about itself (get_driver_info entry
|
||||
// point and LidarDriverInterface::get_driver_info()).
|
||||
struct DriverInfo {
|
||||
@@ -207,18 +281,25 @@ struct DriverInfo {
|
||||
|
||||
// Extra metadata for hosts/UIs (not part of the required identity):
|
||||
Transport transport = Transport::Udp; // primary transport
|
||||
bool transport_selectable = false; // true → use_udp switches TCP/UDP
|
||||
bool transport_selectable = false; // true → DeviceConfig::transport
|
||||
// may pick either TCP or UDP
|
||||
std::vector<std::string> supported_models; // valid DeviceConfig::model values
|
||||
};
|
||||
|
||||
// Settings for one lidar instance. `name` is the unique key across saves.
|
||||
// Which fields matter depends on the driver's transport:
|
||||
// Which fields matter depends on the transport in effect:
|
||||
// serial → serial_port + baudrate; udp/tcp → ip + port.
|
||||
struct DeviceConfig {
|
||||
std::string name = "lidar";
|
||||
std::string driver_id; // plugin that owns this device
|
||||
std::string model = "AUTO"; // one of DriverInfo::supported_models
|
||||
|
||||
// Transport to reach the device. nullopt = the driver's declared default
|
||||
// (DriverInfo::transport). A fixed-transport driver rejects a mismatch
|
||||
// from open() with InvalidConfig; transport-selectable drivers (ESPE)
|
||||
// switch between TCP and UDP through this field.
|
||||
std::optional<Transport> transport;
|
||||
|
||||
// Network transports (udp: local bind address / tcp: device address)
|
||||
std::string ip = "0.0.0.0";
|
||||
uint16_t port = 0; // 0 = driver default
|
||||
@@ -228,7 +309,6 @@ struct DeviceConfig {
|
||||
uint32_t baudrate = 460800;
|
||||
|
||||
bool inverted = false; // unit mounted upside-down → mirror the scan
|
||||
bool use_udp = false; // only for transport-selectable drivers (ESPE)
|
||||
|
||||
// Valid field-of-view window (deg, signed system: 0 = ahead, + = left).
|
||||
// Points outside are reported as NaN (invalid), the scan geometry is
|
||||
@@ -252,9 +332,10 @@ struct DeviceConfig {
|
||||
|
||||
friend bool operator==(const DeviceConfig& a, const DeviceConfig& b) {
|
||||
return a.name == b.name && a.driver_id == b.driver_id && a.model == b.model &&
|
||||
a.transport == b.transport &&
|
||||
a.ip == b.ip && a.port == b.port &&
|
||||
a.serial_port == b.serial_port && a.baudrate == b.baudrate &&
|
||||
a.inverted == b.inverted && a.use_udp == b.use_udp &&
|
||||
a.inverted == b.inverted &&
|
||||
a.angle_min_deg == b.angle_min_deg && a.angle_max_deg == b.angle_max_deg &&
|
||||
a.range_min_m == b.range_min_m && a.range_max_m == b.range_max_m &&
|
||||
a.remap_angle_min_deg == b.remap_angle_min_deg &&
|
||||
|
||||
Reference in New Issue
Block a user