Rule
pub struct Rule
An alarm rule under construction, or a copy of one installed.
Freed when dropped. Adding it to a camera copies it, so dropping
the builder afterwards does not remove the rule; use
crate::Camera::remove_rule for that.
Rule — methods
pub fn new() -> Result<Self>
A new rule: enabled, no name, no actions, comparing above zero.
Errors
Returns Status::OutOfMemory if the builder cannot be
allocated.
pub fn set_name(&mut self, name: &str) -> Result<&mut Self>
Name the rule. The name is carried on every event it produces.
Errors
Returns Status::InvalidArgument if name contains an
interior NUL byte.
pub fn name(&self) -> Result<String>
Read the name back.
Errors
Returns Status::InvalidHandle if the builder is unusable.
pub fn set_enabled(&mut self, enabled: bool) -> Result<&mut Self>
Switch the rule off without removing it.
A disabled rule reports AlarmState::Disabled, which an
operator interface should show differently from "suppressed right
now".
Errors
As Rule::name.
pub fn enabled(&self) -> Result<bool>
Whether the rule is enabled.
Errors
As Rule::name.
pub fn set_input(&mut self, input: SignalId) -> Result<&mut Self>
What the rule watches.
Errors
Returns Status::InvalidArgument if the domain and field
belong to different ranges.
pub fn input(&self) -> Result<SignalId>
Read the input back.
Errors
As Rule::name.
pub fn set_reference(&mut self, reference: SignalId) -> Result<&mut Self>
Compare the input with a second signal: a differential alarm.
With a reference, every band of the condition is tested against
the input minus the reference, so the limits are offsets.
"Region A's maximum more than 2 K above region B's maximum" is
Condition::above(2.0, 0.0) with a reference naming B's
SignalField::Max; "a spot within 5 K of a reference region
either way" is an outside band from -5 to 5. The warning band,
hysteresis, delays, latching, inhibits and actions apply to the
difference unchanged, and the alarm event's value carries the
difference.
Either signal missing orphans the rule: it reports
AlarmState::Orphaned while the input or the reference is not
being produced (a region removed, a replay that does not carry
it), and resumes when both are back.
SignalId::region means the rule's own region and is resolved
when the rule is added to a region; to name another region, set
index to the slot from
crate::Camera::region_signal_slot. Setting a reference
replaces any earlier one; Rule::clear_reference removes it.
Errors
Returns Status::InvalidArgument if the domain and field
belong to different ranges. A reference that is the same signal
as the input is refused when the rule is added.
pub fn reference(&self) -> Result<Option<SignalId>>
The signal the input is compared with, or None when the rule
compares its input alone.
Errors
As Rule::name.
pub fn clear_reference(&mut self) -> Result<&mut Self>
Remove the reference, so the rule compares its input alone again. Clearing a rule that has none is not an error.
Errors
As Rule::name.
pub fn set_condition(&mut self, condition: Condition) -> Result<&mut Self>
When the rule fires.
Errors
Returns Status::InvalidArgument if the condition is not
evaluable.
pub fn condition(&self) -> Result<Condition>
Read the condition back.
Errors
As Rule::name.
pub fn add_inhibit(
Hold the rule clear while another signal's condition holds.
This is how an operator silences alarms during a known
disturbance without disabling them. An inhibited rule reports
AlarmState::Inhibited rather than clear, so the difference
stays visible.
If the suppressing signal stops arriving the rule alarms: suppression fails towards the alarm working, never towards silence.
Set invert to inhibit while the condition is not met.
Errors
Returns Status::InvalidArgument if the signal or condition is
not evaluable.
pub fn inhibit_count(&self) -> Result<usize>
How many inhibit sources the rule has.
Errors
As Rule::name.
pub fn clear_inhibits(&mut self) -> Result<&mut Self>
Remove every inhibit source.
Errors
As Rule::name.
pub fn add_callback_action(&mut self, on: ActionTrigger, slot: u32) -> Result<&mut Self>
Call a handler registered with
crate::Camera::register_alarm_callback when the rule fires.
Use this when one global handler is not enough; the handler set
by crate::Camera::on_alarm sees every transition regardless
and needs no action.
Errors
Returns Status::InvalidArgument if the slot is unknown.
pub fn add_pif_output_action(
Drive a process-interface output while the alarm is active.
Errors
Returns Status::InvalidArgument if the channel is not an
output.
pub fn add_snapshot_action(
Write a still image when the rule fires.
directory defaults to the camera's output directory, then the
working directory. name_pattern defaults to
"{rule}_{timestamp}"; {rule}, {region}, {serial},
{model}, {sequence}, {timestamp} and {timestamp_us}
expand. One table, shared with interval capture: {timestamp}
is a local YYYYmmdd_HHMMSS date and {sequence} is
zero-padded to six digits. {timestamp_us} is the raw
microsecond stamp {timestamp} used to produce.
min_interval_ms is the least time between two snapshots from
this action, rate-limited so an alarm chattering at the frame
rate cannot fill a disk. Zero selects the default of one second;
NO_MIN_INTERVAL_MS switches the limit off, so that every
activation writes a still.
Errors
Returns Status::InvalidArgument if a path contains an
interior NUL byte.
pub fn add_snapshot_action_with(
Write a still image when the rule fires, saying how to write it.
Everything Rule::add_snapshot_action does, plus the one
thing it could not express. None for options is the
documented defaults, which is exactly what
Rule::add_snapshot_action gives; the _with spelling and
the Option are the same pair as
crate::Camera::save_snapshot and
crate::Camera::save_snapshot_with, over the same struct.
Two stills of one frame must not differ by who asked for them, and until this existed they did: an alarm still was written with the defaults whatever the application had chosen for its own stills, so a user who picked a 16-bit TIFF because their tool cannot read float32 got alarm stills that tool could not open.
Examples
# fn main() -> optris_sdk::Result<()> {
use optris_sdk::{
ActionTrigger, Rule, SnapshotFormat, SnapshotOptions,
};
let mut rule = Rule::new()?;
let options = SnapshotOptions {
tiff_int16: true,
..SnapshotOptions::default()
};
rule.add_snapshot_action_with(
ActionTrigger::OnActivate,
SnapshotFormat::Tiff,
None,
None,
0,
Some(&options),
)?;
# Ok(())
# }
Errors
As Rule::add_snapshot_action, plus
Status::InvalidArgument for a software_override longer
than the ABI's field.
pub fn add_recording_action(
Start or stop a recording when the rule fires.
duration_s applies only to
RecordingActionMode::FixedDuration.
Errors
pub fn add_recording_action_with(
Start or stop a recording when the rule fires, saying how to write it.
Everything Rule::add_recording_action does, plus the segment
limits and the lossy settings. None for options is the
documented defaults, which is exactly what
Rule::add_recording_action gives.
The segment limits are the reason this is not cosmetic:
without them an alarm recording runs with
RecordingOptions::max_segment_bytes zero, so it never rolls
over and a recording onto a FAT32 volume fails at 4 GiB instead
of continuing in a new part. An alarm recording is the one case
where nobody is watching when that happens.
RecordingOptions::duration is ignored: mode and
duration_s are this action's stop, and running two stops on
one recorder would leave the SDK believing a rule still owned a
recording that had closed itself. It reads back as
Duration::ZERO from
Rule::action_recording_options rather than as what was
passed, so that the readback cannot describe a stop that does
not happen.
Examples
# fn main() -> optris_sdk::Result<()> {
use optris_sdk::{
ActionTrigger, RecordingActionMode, RecordingOptions, Rule,
};
let mut rule = Rule::new()?;
let options = RecordingOptions {
max_segment_bytes: 4_290_772_992,
..RecordingOptions::default()
};
rule.add_recording_action_with(
ActionTrigger::OnActivate,
RecordingActionMode::WhileActive,
0,
Some("/media/stick"),
None,
Some(&options),
)?;
# Ok(())
# }
Errors
As Rule::add_snapshot_action, plus
Status::InvalidArgument for a duration on options that
does not fit the ABI's millisecond field.
pub fn action_count(&self) -> Result<usize>
How many actions the rule has.
Errors
As Rule::name.
pub fn action(&self, index: usize) -> Result<RuleAction>
One of the rule's actions, read back.
In the order they were added, which is the order they run in
and the order crate::ActionError::action_index refers to.
Earlier the ABI reported only how many there were, so a rule
obtained from crate::Camera::rule -- and after loading a
configuration every rule is one -- could not be shown or
written back without losing its actions.
Errors
Returns Status::InvalidArgument if index is past the end.
pub fn action_snapshot_options(&self, index: usize) -> Result<SnapshotOptions>
How the snapshot action at index writes its file.
A second call rather than a field on
RuleActionKind::Snapshot, and deliberately so, for the
reason the ABI gives: SnapshotOptions is versioned on its
own struct_size and will grow, and nesting a growable struct
inside a growable struct moves every offset after it. It also
means the answer can be handed straight back to
Rule::add_snapshot_action_with with no field-by-field
copying.
Errors
Returns Status::InvalidArgument if index is past the end,
or if the action there is not a snapshot action, refused
rather than answered with the defaults, because all-defaults is
exactly what a snapshot action using the defaults reads back
as.
pub fn action_recording_options(&self, index: usize) -> Result<RecordingOptions>
How the recording action at index writes its file.
The recording half of Rule::action_snapshot_options; see
there for why it is a call of its own.
RecordingOptions::duration always reads back as
Duration::ZERO. The field is ignored on an action, see
Rule::add_recording_action_with, and reporting what was
passed would describe a stop that does not happen. The action's
stop is the mode and duration on
RuleActionKind::Recording.
Errors
As Rule::action_snapshot_options, for a recording action.
pub fn actions(&self) -> Result<Vec<RuleAction>>
Every action the rule has, in order.
Errors
As Rule::name.
pub fn clear_actions(&mut self) -> Result<&mut Self>
Remove every action.
Errors
As Rule::name.