namespace ZB.MOM.WW.OtOpcUa.Driver.FOCAS.Wire;
///
/// Return envelope over a parsed wire response. carries the FOCAS
/// EW_* code from the response block — 0 / means the
/// call succeeded and is populated; non-zero means the CNC rejected
/// the call and is default. Callers use the RC to distinguish
/// "feature missing on this series" (EW_FUNC / EW_NOOPT) from genuine
/// failures.
///
public readonly record struct FocasResult(short Rc, T? Value)
{
/// True when is zero (EW_OK).
public bool IsOk => Rc == 0;
}
/// CNC identity payload returned by cnc_sysinfo.
public sealed record WireSysInfo(
short AddInfo,
short MaxAxis,
string CncType,
string MachineType,
string Series,
string Version,
string Axes);
/// Coarse CNC state bits returned by cnc_statinfo — the seven-word status block plus TM mode.
public sealed record WireStatus(
short Auto,
short Run,
short Motion,
short Mstb,
short Emergency,
short Alarm,
short Edit,
short TmMode);
///
/// Four-slot position quadruple for one axis: absolute / machine / relative / distance-to-go,
/// each carrying the scale its own 0x0026 block reported.
///
public sealed record WireAxisPosition(
FocasPosition Absolute,
FocasPosition Machine,
FocasPosition Relative,
FocasPosition Distance);
///
/// Fast-poll bundle for one axis from cnc_rddynamic2 — alarm flags, active program
/// numbers, sequence number, actual feed rate, actual spindle speed, and the position
/// quadruple.
///
public sealed record WireDynamic(
int Alarm,
int ProgramNumber,
int MainProgramNumber,
int SequenceNumber,
int FeedRate,
int SpindleSpeed,
WireAxisPosition Axis);
/// One servo-meter entry from cnc_rdsvmeter — per-axis load percentage (scale by 10^).
public sealed record WireServoMeter(
short Index,
string Name,
int Value,
short Decimal,
short Unit);
/// One spindle metric slot from cnc_rdspload / cnc_rdspmaxrpm.
public sealed record WireSpindleMetric(
short Index,
int Value);
///
/// One axis-name slot from cnc_rdaxisname. is the 1-based
/// axis index (preserved even when the name is empty so callers can pass it to
/// cnc_rddynamic2).
///
public readonly record struct WireAxisRecord(short Index, string Name);
/// One spindle-name slot from cnc_rdspdlname.
public readonly record struct WireSpindleRecord(short Index, string Name);
/// Parameter value returned by cnc_rdparam, interpreted as a scalar Int32.
public sealed record WireParameter(
short DataNumber,
short Type,
int Value);
///
/// Macro variable from cnc_rdmacro. Scaled decimal: the real value is
/// Value / 10^Decimal (). FANUC normalises every macro to a
/// 9-significant-digit mantissa, so alone is never a value to publish
/// (live: #502 = 270 arrives as 270000000 / 10^6).
///
/// Macro variable number (the request argument; not carried in the payload).
/// The 9-significant-digit mantissa.
/// Implied decimal places; negative (0xFFFF on the wire) = vacant.
public sealed record WireMacro(
short Number,
int Value,
short Decimal)
{
///
/// True when the CNC reported the variable as vacant (undefined / never set):
/// dec_val == 0xFFFF. A vacant macro's mantissa is 0, indistinguishable from a
/// genuine 0, so this must be tested before means anything. Any
/// negative decimal is treated as vacant — no other negative has ever been observed and
/// failing closed is the safe reading.
///
public bool IsVacant => Decimal < 0;
/// The real value, Value / 10^Decimal; null when .
public double? Scaled => IsVacant ? null : Decimal == 0 ? Value : Value / Math.Pow(10.0, Decimal);
}
/// PMC range read-back from pmc_rdpmcrng: one or more values of the requested width.
public sealed record WirePmcRange(
short Area,
short DataType,
ushort Start,
ushort End,
IReadOnlyList Values);
///
/// One active alarm from cnc_rdalmmsg2. Mirrors the vendor ODBALMMSG2
/// layout; is populated when the wire responder carries it
/// (currently null for both the 76-byte vendor shape and the 80-byte legacy
/// shape).
///
public sealed record WireAlarm(
int AlarmNumber,
short Type,
short Axis,
short MessageLength,
string Message,
int? AlarmGroup = null);
///
/// Executing-program identity from cnc_exeprgname2: the NUL-terminated name and
/// the trailing 32-bit O-number (null when the wire responder omits the trailing int).
///
public sealed record WireProgramName(
string Name,
int? ONumber);
/// One cumulative timer reading from cnc_rdtimer (minutes + fractional milliseconds).
public sealed record WireTimer(
short Type,
int Minutes,
int Milliseconds);