optris::sdk::AlarmEvent
A state transition, carrying its own cause. This is the "which region fired, and why" answer in one copyable struct; a subscriber never has to go and look anything up.
Public attributes
rule_id
uint64_t rule_id = 0
which rule changed state
rule_name
std::string rule_name
its name, so a log line needs no lookup
previous
AlarmState previous = AlarmState::kUnknown
state before the change
current
AlarmState current = AlarmState::kUnknown
state after it
input
SignalId input
the signal the rule watches
value
double value = 0.0
The reading that caused the change. For a rule with a reference (RuleEngine::SetReference()) it is the input minus the reference, which is the number limit was compared with, not the input's own reading.
value and limit are in the unit of the input's quantity, as Limits describes: a temperature in the SDK's temperature unit (Celsius unless SetTemperatureUnit() chose Fahrenheit), and for a rule with a reference a difference in degrees of that unit.
limit
float limit = 0.0F
the limit it crossed
limit_kind
LimitKind limit_kind = LimitKind::kNone
which limit that was
region_id
uint64_t region_id = 0
The region owning the rule, or 0 for a non-region rule.
region_name
std::string region_name
The region's name as it was when the rule was attached.
A snapshot, not a live lookup. Renaming the region afterwards does not change what its rules report -- neither in events already delivered nor in later ones. Empty for a non-region rule, and {region} in a file-name pattern falls back to the decimal region_id when it is.
timestamp_us
uint64_t timestamp_us = 0
When the input was observed, in microseconds.
Which clock that is depends on the rule, because this is the driving observation's own timestamp carried over unchanged, not a stamp taken at the transition:
- a rule on a region or on device telemetry is evaluated on a frame and carries that frame's timestamp -- the monotonic frame clock of
frame_stamp.h, counting from the camera's start; - a rule on a PIF channel carries whatever the PIF poll stamped;
- a rule on a value passed to Imager::PublishSignal() carries wall-clock microseconds since the Unix epoch;
- a transition into
AlarmState::kOrphanedbefore any input has arrived carries 0.
So two of these are comparable only when both rules watch the same kind of signal, and none of them can be formatted as a time of day. Order with sequence, measure an interval between two events of one rule with this, and read host_time_us to say when something happened.
sequence
uint64_t sequence = 0
Increments per event, so a consumer can detect a gap.
host_time_us
uint64_t host_time_us = 0
Wall-clock time of the evaluation that raised this event, in microseconds since the Unix epoch (std::chrono::system_clock).
This is the field to put in a log row or an alarm history: it is a date, and it is the same date for every event of one evaluation cycle. Sampled when the cycle produces its first event, not when a subscriber is handed the event, so the queue latency between the transition and the callback is not in it.
One frame is not always one cycle. A frame evaluates the region and device rules in one pass and the motion rules in a second one, after every zone has published; PIF and user rules are evaluated on their own occasions again. Each pass reads the clock once, so two events from the same frame can differ here by microseconds. Use sequence to tell which observation an event belongs to; this field is for display.
It is not monotonic, and timestamp_us is. NTP can step the system clock in either direction and an operator can set it, so two consecutive events can carry host times that go backwards or jump by hours. timestamp_us never does that. Use timestamp_us -- or better, sequence -- to order or to measure an interval; use this one to say when something happened. Never derive one from the other: they are read from two different clocks, on purpose.
The two are also not read at the same instant. timestamp_us is carried over from the input observation, which was stamped when the frame arrived or the value was published; this one is read when the rule engine evaluates that observation. The gap is the evaluation latency -- well under a frame period -- but it is not zero, so the difference between the two is not a clock offset.
Zero only if the SDK could not read the system clock.