Events¶
Class buffers, deadbands, and the overflow they report. What changed, when, and which class it belongs to.
py1815.events ¶
Event buffers: what changed, when, and which class it belongs to.
A static read answers "what is the value now". An event answers "it changed, and here is what it was at the time" -- which is the question a master asks when it wants a sequence rather than a snapshot, and it is why events are held rather than computed.
Three properties are the whole of this module, and each exists because of a way event reporting goes wrong in practice.
An event is generated by a deadband, not by a difference. Reporting every read of a measured value floods the buffer with noise no operator asked for. The deadband is the operator's statement of what counts as a change.
A quality change always generates an event, whatever the magnitude. A point that goes comm-lost while holding the same number has not changed value and has changed in the way that matters most. A deadband applied to quality would hide exactly the transitions someone is watching for.
A full buffer drops its oldest event and says so. The alternative -- dropping the newest -- keeps a master reading history while the present goes unreported, and silence about either is worse than the loss.
Copyright 2026 DER Security Corp. Licensed under the Apache License, Version 2.0.
EventClass ¶
Bases: IntEnum
The class an event is reported in.
Class 0 is not here: it is the static data, which is a read rather than a buffer. An event assigned class 0 is an event that is never reported, so assigning one is refused rather than quietly honored.
Source code in src/py1815/events.py
AnalogEvent
dataclass
¶
One analog input change.
Source code in src/py1815/events.py
BinaryEvent
dataclass
¶
One binary input change.
Source code in src/py1815/events.py
FrozenCounterEvent
dataclass
¶
One counter, as it stood at one freeze.
Source code in src/py1815/events.py
EventBuffers ¶
Per-class event storage, and the deadband rules that fill it.
Holds the last reported value per point so a deadband can be applied against what the master was actually told, rather than against the previous reading. Comparing against the previous reading lets a value drift past the deadband in steps that individually fall inside it, and the master never hears about a change that has already happened.
Source code in src/py1815/events.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 | |
holds_unsynchronized
property
¶
Whether any buffered binary event was stamped by a clock that had not been set.
overflow_generation
property
¶
How many events have been lost, counted from the first.
Monotonic, and deliberately not reset by clear_overflow. A
confirmation acknowledges the loss a particular response reported, and
the flag alone cannot say whether more has been lost since that response
was built -- it reads the same after one eviction and after a hundred.
Clearing on the flag would retire a report of data loss the master has
never been sent.
recorded
property
¶
How many events have been recorded, counted from the first.
Monotonic, like :attr:overflow_generation, and for a similar reason:
the count of events held cannot say whether anything new has happened,
since one may have been retired or evicted for each one recorded. A
session that has stopped retrying an unsolicited response reads this
to learn that there is news worth starting again for.
analog_latest_only
property
¶
Whether only the newest event per analog point is kept.
overflowed ¶
classes_with_events ¶
Which classes have something to report, for the indication bits.
excluding names events a response is already carrying. A class
whose every event is in the response being built has nothing more
to report, and saying it has would send the master back for events
it is holding.
Source code in src/py1815/events.py
peek ¶
The oldest events of a class, without removing them.
Reads do not consume. An event leaves the buffer when the master confirms the response carrying it, because a response that never arrives must not have taken the only copy with it.
limit is taken from the front, and taken while the deque is walked
rather than after. The difference is the whole point of the parameter:
materializing the class and slicing it afterwards costs the buffer on
every call, and capacity has no upper bound, so a caller asking for
the few events that fit a response would still pay for all of them.
Source code in src/py1815/events.py
drop ¶
Remove events a master has confirmed.
Matched on identity, not equality, and the difference matters. Events
are frozen dataclasses, so two genuinely distinct events carrying the
same index, value and timestamp compare equal -- a master confirming
one of them would silently drop both. id() is what tells them
apart, and tidying this into == would reintroduce that.
It is load-bearing that the events passed in are still held by a
buffer, since that is what keeps them alive and their ids stable for
the length of this call. True of the peek then drop lifecycle
above; not true of ids kept across a confirm cycle.
Source code in src/py1815/events.py
clear_overflow ¶
record_analog ¶
record_analog(
index: int,
point: AnalogPoint,
*,
event_class: EventClass,
deadband: float = 0.0,
timestamp_ms: int | None = None,
) -> AnalogEvent | None
Record an analog reading, returning the event it generated, if any.
Source code in src/py1815/events.py
prime_analog ¶
Note where an analog point stands, without reporting it.
For the first reading after start. A change is measured against the last value a master was told, and at start it has been told nothing -- it learns every point from its integrity poll, so an event per point here would report a few hundred changes that did not happen.
Source code in src/py1815/events.py
prime_binary ¶
record_frozen_counter ¶
record_frozen_counter(
index: int,
point: CounterPoint,
*,
event_class: EventClass,
timestamp_ms: int | None = None,
) -> FrozenCounterEvent
Record one counter's value at a freeze. Always an event.
No comparison against the previous freeze, unlike the other two. A frozen counter event is an entry in a log -- the value at this moment -- and two freezes of a counter that did not move are two entries the master is owed, since their absence would read as freezes that never happened.
Source code in src/py1815/events.py
peek_kind ¶
The oldest events of one type, across every class, without removing them.
For a master that reads an event group by name rather than a class. Oldest first whichever class each is in: a master that asks for the next three binary changes is asking for the three that happened first, and taking them a class at a time would hand it a later change ahead of an earlier one.
Each class is already in order, so the oldest limit overall are
among the oldest limit of each, and no class is walked further.
Source code in src/py1815/events.py
record_binary ¶
record_binary(
index: int,
point: BinaryPoint,
*,
event_class: EventClass,
timestamp_ms: int | None = None,
synchronized: bool | None = None,
) -> BinaryEvent | None
Record a binary reading, returning the event it generated, if any.
No deadband: a binary point has two values, so any change is the whole of its range.
synchronized says whether the clock behind the timestamp had
been set, and defaults to what these buffers were last told.
Source code in src/py1815/events.py
now_ms ¶
Wall-clock milliseconds, which is what a DNP3 timestamp carries.
Wall clock rather than monotonic, deliberately: the timestamp is for the master's sequence of record, and a monotonic reading means nothing to it. A clock that steps backwards produces events out of order, which is a real hazard and the operator's to resolve -- not one to be hidden here by inventing times that look plausible.