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
DoubleBitEvent
dataclass
¶
One double-bit 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
CounterEvent
dataclass
¶
One change in a counter's flags, with the count it held at the change.
Source code in src/py1815/events.py
BinaryOutputEvent
dataclass
¶
One binary output change: its state or its flags.
Source code in src/py1815/events.py
AnalogOutputEvent
dataclass
¶
One analog output change: its value or its flags.
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
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 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 | |
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,
unscaled: float | None = None,
) -> AnalogEvent | None
Record an analog reading, returning the event it generated, if any.
unscaled is the value a floating-point variation reports for the
event. It plays no part in deciding whether the change is an event.
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 ¶
prime_double_bit ¶
Note where a double-bit point stands, without reporting it.
prime_counter ¶
Note a counter's flags and count, without reporting them.
record_counter ¶
record_counter(
index: int,
point: CounterPoint,
*,
event_class: EventClass,
value_deadband: float | None = None,
timestamp_ms: int | None = None,
) -> CounterEvent | None
Record a counter reading, returning the event it generated, if any.
A change in the flags is always an event: IEEE 1815-2012 11.9.5.2 has a device that supports counter events generate one whenever a flag changes. A change in value is optional there, and is an event only when value_deadband is given and the count has moved further than it from the count in the counter's last event (or its first reading). Each event is kept, as binary changes are, because the sequence is the information.
Source code in src/py1815/events.py
prime_binary_output ¶
prime_analog_output ¶
Note where an analog output stands, without reporting it.
record_binary_output ¶
record_binary_output(
index: int,
point: BinaryPoint,
*,
event_class: EventClass,
timestamp_ms: int | None = None,
) -> BinaryOutputEvent | None
Record a binary output's status, returning the event it generated, if any.
Any change of state or of a quality flag is an event, and a repeat of what the master was last told is not (IEEE 1815-2012, A.7.1.1).
Source code in src/py1815/events.py
record_analog_output ¶
record_analog_output(
index: int,
point: AnalogPoint,
value: float,
*,
event_class: EventClass,
timestamp_ms: int | None = None,
) -> AnalogOutputEvent | None
Record an analog output's status, returning the event it generated, if any.
Any change of the transmitted value or of a quality flag is an event. Every one is kept: each is a setpoint taking effect, and a master reading the sequence is owed all of them.
Source code in src/py1815/events.py
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
record_double_bit ¶
record_double_bit(
index: int,
point: DoubleBitPoint,
*,
event_class: EventClass,
timestamp_ms: int | None = None,
synchronized: bool | None = None,
) -> DoubleBitEvent | None
Record a double-bit reading, returning the event it generated, if any.
A change of state or of any quality flag is an event, and one event covers both bits of the state changing together (IEEE 1815-2012 11.9.6).
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.