Skip to main content

printobserver_printer_api/
ranges.rs

1//! The plausibility ranges the printer port declares for what a printer reports.
2//!
3//! A numeric field of a snapshot this port answers is typed
4//! [`Reported<f64>`](printobserver_types::Reported), carrying whether the value
5//! lies outside the range declared here for it. **These are validity ranges on
6//! what a printer can plausibly report, and they are not the operator's safety
7//! envelope.** A reading outside one of them says the source reported something
8//! implausible — a disconnected thermistor, a firmware that answers in another
9//! unit. What an actor is *allowed to ask for* is
10//! the supervision domain's `SafetyEnvelope`, which is server
11//! configuration and is narrower by orders of magnitude; nothing reads these
12//! ranges as a bound on an action, and the two are never intersected, compared
13//! or substituted for one another.
14//!
15//! [`RANGED_FIELDS`] is the one table of which field carries which range, read
16//! by the tests that drive every ranged field at its boundary.
17
18use printobserver_types::Range;
19
20/// The plausibility range of `PrinterSnapshot::feedrate_factor`.
21///
22/// A multiplier where one means one hundred percent, spanning what the
23/// firmware's own speed command accepts. A validity range on what a printer can
24/// plausibly report, not a bound on what an actor may ask for.
25pub const FEEDRATE_FACTOR_RANGE: Range = Range::new(0.1, 10.0);
26
27/// The plausibility range of `PrinterSnapshot::flowrate_factor`.
28///
29/// A multiplier where one means one hundred percent, spanning what the
30/// firmware's own flow command accepts. A validity range on what a printer can
31/// plausibly report, not a bound on what an actor may ask for.
32pub const FLOWRATE_FACTOR_RANGE: Range = Range::new(0.1, 10.0);
33
34/// The plausibility range of `PrinterSnapshot::fan_percent`, in percent.
35///
36/// A validity range on what a printer can plausibly report, not a bound on what
37/// an actor may ask for.
38pub const FAN_PERCENT_RANGE: Range = Range::new(0.0, 100.0);
39
40/// The plausibility range of `JobSnapshot::completion`, as a fraction.
41///
42/// A validity range on what a printer can plausibly report, not a bound on what
43/// an actor may ask for.
44pub const COMPLETION_RANGE: Range = Range::new(0.0, 1.0);
45
46/// The plausibility range of `HeaterSnapshot::actual_c`, in degrees Celsius.
47///
48/// A validity range on what a printer can plausibly report, not a bound on what
49/// an actor may ask for.
50pub const HEATER_ACTUAL_C_RANGE: Range = Range::new(-20.0, 500.0);
51
52/// The plausibility range of `HeaterSnapshot::target_c`, in degrees Celsius.
53///
54/// A validity range on what a printer can plausibly report, not a bound on what
55/// an actor may ask for.
56pub const HEATER_TARGET_C_RANGE: Range = Range::new(0.0, 500.0);
57
58/// The plausibility range of `HeaterSnapshot::offset_c`, in degrees Celsius.
59///
60/// A validity range on what a printer can plausibly report, not a bound on what
61/// an actor may ask for.
62pub const HEATER_OFFSET_C_RANGE: Range = Range::new(-50.0, 50.0);
63
64/// One field this port declares a plausibility range for.
65#[derive(Debug, Clone, Copy, PartialEq)]
66pub struct RangedField {
67    /// The type the field belongs to.
68    pub type_name: &'static str,
69    /// The field's own name.
70    pub field: &'static str,
71    /// The plausibility range declared for it.
72    pub range: Range,
73}
74
75/// Every field this port types as `Reported<f64>`, with its declared range.
76///
77/// These are validity ranges on what a printer can plausibly report. They are
78/// not the operator's safety envelope, and nothing intersects, compares or
79/// substitutes the two.
80pub const RANGED_FIELDS: [RangedField; 7] = [
81    RangedField {
82        type_name: "PrinterSnapshot",
83        field: "feedrate_factor",
84        range: FEEDRATE_FACTOR_RANGE,
85    },
86    RangedField {
87        type_name: "PrinterSnapshot",
88        field: "flowrate_factor",
89        range: FLOWRATE_FACTOR_RANGE,
90    },
91    RangedField {
92        type_name: "PrinterSnapshot",
93        field: "fan_percent",
94        range: FAN_PERCENT_RANGE,
95    },
96    RangedField {
97        type_name: "JobSnapshot",
98        field: "completion",
99        range: COMPLETION_RANGE,
100    },
101    RangedField {
102        type_name: "HeaterSnapshot",
103        field: "actual_c",
104        range: HEATER_ACTUAL_C_RANGE,
105    },
106    RangedField {
107        type_name: "HeaterSnapshot",
108        field: "target_c",
109        range: HEATER_TARGET_C_RANGE,
110    },
111    RangedField {
112        type_name: "HeaterSnapshot",
113        field: "offset_c",
114        range: HEATER_OFFSET_C_RANGE,
115    },
116];