1use crate::records::{
23 AcknowledgementDisposition, ActionId, Actor, ChargeKey, ChargeMethod, ChargedFilament,
24 ClearedMark, FilePosition, InterventionId, InterventionOutcome, LoadedSpool, PendingCharge,
25 PendingTaken, PolicyDecision, Preflight, PrintAction, PrintOutcome, SpoolCommand, SpoolId,
26 SpoolRecord, UnverifiedReason,
27};
28use printobserver_printer_api::{Adjustable, JobSnapshot, PrinterSnapshot, PrinterState};
29use printobserver_supervisor_api::AgentAssessment;
30use printobserver_types::contract::Sample;
31use printobserver_types::schemars::JsonSchema;
32use printobserver_types::serde::{Deserialize, Serialize};
33use printobserver_types::{EventId, EventKind, EventPayload, EventSource, PrintId, Timestamp};
34
35pub const SYSTEM_SOURCE: &str = "system";
37
38pub const OPERATOR_SOURCE: &str = "operator";
40
41pub const AGENT_SOURCE: &str = "agent";
43
44#[must_use]
46pub fn system_source() -> EventSource {
47 EventSource::new(SYSTEM_SOURCE)
48}
49
50#[must_use]
52pub fn operator_source() -> EventSource {
53 EventSource::new(OPERATOR_SOURCE)
54}
55
56#[must_use]
58pub fn agent_source() -> EventSource {
59 EventSource::new(AGENT_SOURCE)
60}
61
62#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
64#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
65#[schemars(crate = "printobserver_types::schemars")]
66pub struct ActionRequestedPayload {
67 pub action_id: ActionId,
69 pub action: PrintAction,
71 pub actor: Actor,
73}
74
75impl EventPayload for ActionRequestedPayload {
76 const KIND: &'static str = "action_requested";
77}
78
79impl Sample for ActionRequestedPayload {
80 fn sample_full() -> Self {
81 Self {
82 action_id: ActionId::sample_full(),
83 action: PrintAction::sample_full(),
84 actor: Actor::sample_full(),
85 }
86 }
87
88 fn sample_minimal() -> Self {
89 Self {
90 action: PrintAction::sample_minimal(),
91 ..Self::sample_full()
92 }
93 }
94}
95
96#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
98#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
99#[schemars(crate = "printobserver_types::schemars")]
100pub struct ActionExecutedPayload {
101 pub action_id: ActionId,
103 #[serde(default, skip_serializing_if = "Option::is_none")]
105 pub intervention_id: Option<InterventionId>,
106}
107
108impl EventPayload for ActionExecutedPayload {
109 const KIND: &'static str = "action_executed";
110}
111
112impl Sample for ActionExecutedPayload {
113 fn sample_full() -> Self {
114 Self {
115 action_id: ActionId::sample_full(),
116 intervention_id: Some(InterventionId::sample_full()),
117 }
118 }
119
120 fn sample_minimal() -> Self {
121 Self {
122 action_id: ActionId::sample_full(),
123 intervention_id: None,
124 }
125 }
126}
127
128#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
130#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
131#[schemars(crate = "printobserver_types::schemars")]
132pub struct ActionRejectedPayload {
133 pub action_id: ActionId,
135 pub decision: PolicyDecision,
137}
138
139impl EventPayload for ActionRejectedPayload {
140 const KIND: &'static str = "action_rejected";
141}
142
143impl Sample for ActionRejectedPayload {
144 fn sample_full() -> Self {
145 Self {
146 action_id: ActionId::sample_full(),
147 decision: PolicyDecision::sample_full(),
148 }
149 }
150}
151
152#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
154#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
155#[schemars(crate = "printobserver_types::schemars")]
156pub struct InterventionExpiredPayload {
157 pub intervention_id: InterventionId,
159 pub adjustable: Adjustable,
161 pub outcome: InterventionOutcome,
163}
164
165impl EventPayload for InterventionExpiredPayload {
166 const KIND: &'static str = "intervention_expired";
167}
168
169impl Sample for InterventionExpiredPayload {
170 fn sample_full() -> Self {
171 Self {
172 intervention_id: InterventionId::sample_full(),
173 adjustable: Adjustable::Feedrate,
174 outcome: InterventionOutcome::Restored,
175 }
176 }
177}
178
179#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
181#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
182#[schemars(crate = "printobserver_types::schemars")]
183pub struct AgentAssessmentPayload {
184 pub session_name: String,
186 pub assessment: AgentAssessment,
188}
189
190impl EventPayload for AgentAssessmentPayload {
191 const KIND: &'static str = "agent_assessment";
192}
193
194impl Sample for AgentAssessmentPayload {
195 fn sample_full() -> Self {
196 Self {
197 session_name: "print-0191f0a0".to_owned(),
198 assessment: AgentAssessment::sample_full(),
199 }
200 }
201}
202
203#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
205#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
206#[schemars(crate = "printobserver_types::schemars")]
207pub struct OperatorAcknowledgementPayload {
208 pub acknowledged_event_id: EventId,
210 pub disposition: AcknowledgementDisposition,
212}
213
214impl EventPayload for OperatorAcknowledgementPayload {
215 const KIND: &'static str = "operator_acknowledgement";
216}
217
218impl Sample for OperatorAcknowledgementPayload {
219 fn sample_full() -> Self {
220 Self {
221 acknowledged_event_id: EventId::sample_full(),
222 disposition: AcknowledgementDisposition::Watch,
223 }
224 }
225}
226
227#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
233#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
234#[schemars(crate = "printobserver_types::schemars")]
235pub struct CameraLookPayload {
236 pub waited_s: u32,
239 #[serde(default)]
242 pub delivered: Vec<EventId>,
243}
244
245impl EventPayload for CameraLookPayload {
246 const KIND: &'static str = "camera_look";
247}
248
249impl Sample for CameraLookPayload {
250 fn sample_full() -> Self {
251 Self {
252 waited_s: 60,
253 delivered: vec![EventId::sample_full()],
254 }
255 }
256
257 fn sample_minimal() -> Self {
258 Self {
259 waited_s: 0,
260 delivered: Vec::new(),
261 }
262 }
263}
264
265#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
275#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
276#[schemars(crate = "printobserver_types::schemars")]
277pub struct PeriodicObservationPayload {
278 pub interval_s: u64,
280 #[serde(default, skip_serializing_if = "Option::is_none")]
283 pub printer: Option<PrinterSnapshot>,
284 #[serde(default, skip_serializing_if = "Option::is_none")]
287 pub job: Option<JobSnapshot>,
288}
289
290impl EventPayload for PeriodicObservationPayload {
291 const KIND: &'static str = "periodic_observation";
292}
293
294impl Sample for PeriodicObservationPayload {
295 fn sample_full() -> Self {
296 Self {
297 interval_s: 120,
298 printer: Some(PrinterSnapshot::sample_full()),
299 job: Some(JobSnapshot::sample_full()),
300 }
301 }
302
303 fn sample_minimal() -> Self {
304 Self {
305 interval_s: 120,
306 printer: None,
307 job: None,
308 }
309 }
310}
311
312#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
314#[serde(
315 crate = "printobserver_types::serde",
316 rename_all = "snake_case",
317 deny_unknown_fields
318)]
319#[schemars(crate = "printobserver_types::schemars")]
320pub enum FrameCause {
321 Blank,
324 Undecodable,
326}
327
328impl Sample for FrameCause {
329 fn sample_full() -> Self {
330 Self::Blank
331 }
332
333 fn sample_alternates() -> Vec<Self> {
334 vec![Self::Undecodable]
335 }
336}
337
338#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
344#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
345#[schemars(crate = "printobserver_types::schemars")]
346pub struct CameraDegradedPayload {
347 pub attempts: u32,
349 pub cause: FrameCause,
351 pub detail: String,
353}
354
355impl EventPayload for CameraDegradedPayload {
356 const KIND: &'static str = "camera_degraded";
357}
358
359impl Sample for CameraDegradedPayload {
360 fn sample_full() -> Self {
361 Self {
362 attempts: 3,
363 cause: FrameCause::Blank,
364 detail: "every frame was near-uniform grey (grey-level spread 2.1 below 36.5)"
365 .to_owned(),
366 }
367 }
368
369 fn sample_alternates() -> Vec<Self> {
370 vec![Self {
371 cause: FrameCause::Undecodable,
372 detail: "every frame failed a strict decode: the image ends early".to_owned(),
373 ..Self::sample_full()
374 }]
375 }
376}
377
378#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
387#[serde(
388 crate = "printobserver_types::serde",
389 rename_all = "snake_case",
390 deny_unknown_fields
391)]
392#[schemars(crate = "printobserver_types::schemars")]
393pub enum PortFailureSite {
394 PrinterSnapshot,
396 PrinterJob,
398 ImageWrite,
400 SupervisionTurn,
402 CameraLook,
405 DetectorAcknowledgement,
407}
408
409impl Sample for PortFailureSite {
410 fn sample_full() -> Self {
411 Self::PrinterSnapshot
412 }
413}
414
415#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
423#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
424#[schemars(crate = "printobserver_types::schemars")]
425pub struct PortFailurePayload {
426 pub event_id: EventId,
428 pub site: PortFailureSite,
430 pub detail: String,
432}
433
434impl EventPayload for PortFailurePayload {
435 const KIND: &'static str = "port_failure";
436}
437
438impl Sample for PortFailurePayload {
439 fn sample_full() -> Self {
440 Self {
441 event_id: EventId::sample_full(),
442 site: PortFailureSite::sample_full(),
443 detail: "the printer is unreachable: connection refused".to_owned(),
444 }
445 }
446}
447
448pub const TIMELINE_KINDS: [&str; 20] = [
452 PrintStartedPayload::KIND,
453 PrintEndedPayload::KIND,
454 FilamentConsumedPayload::KIND,
455 SpoolRegisteredPayload::KIND,
456 SpoolLoadedPayload::KIND,
457 SpoolUnloadedPayload::KIND,
458 SpoolAdjustedPayload::KIND,
459 SpoolRetiredPayload::KIND,
460 SpoolCommandRejectedPayload::KIND,
461 SpoolUnverifiedPayload::KIND,
462 FilamentChangeSignalledPayload::KIND,
463 UnaccountedPrintPayload::KIND,
464 PreflightCheckedPayload::KIND,
465 ChargePendedPayload::KIND,
466 PrintUntrackedPayload::KIND,
467 FileTallyRebaselinedPayload::KIND,
468 PrinterConnectionChangedPayload::KIND,
469 PrinterResetPayload::KIND,
470 UnattendedPrinterActivityPayload::KIND,
471 DetectorHealthChangedPayload::KIND,
472];
473
474fn sample_spool_id() -> SpoolId {
476 SpoolId::sample_full()
477}
478
479fn sample_reason() -> String {
481 "the spool on the shelf changed".to_owned()
482}
483
484#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
486#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
487#[schemars(crate = "printobserver_types::schemars")]
488pub struct PrintStartedPayload {
489 #[serde(default, skip_serializing_if = "Option::is_none")]
491 pub file_name: Option<String>,
492 #[serde(default, skip_serializing_if = "Option::is_none")]
495 pub started_by: Option<ActionId>,
496 pub loaded: Vec<LoadedSpool>,
498 #[serde(default, skip_serializing_if = "Option::is_none")]
500 pub preflight: Option<Preflight>,
501}
502
503impl EventPayload for PrintStartedPayload {
504 const KIND: &'static str = "print_started";
505}
506
507impl Sample for PrintStartedPayload {
508 fn sample_full() -> Self {
509 Self {
510 file_name: Some("benchy.gcode".to_owned()),
511 started_by: Some(ActionId::sample_full()),
512 loaded: vec![LoadedSpool::sample_full()],
513 preflight: Some(Preflight::sample_full()),
514 }
515 }
516
517 fn sample_minimal() -> Self {
518 Self {
519 file_name: None,
520 started_by: None,
521 loaded: Vec::new(),
522 preflight: None,
523 }
524 }
525}
526
527#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
529#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
530#[schemars(crate = "printobserver_types::schemars")]
531pub struct PrintEndedPayload {
532 pub outcome: PrintOutcome,
534 pub state: PrinterState,
536 pub reason: String,
538 #[serde(default, skip_serializing_if = "Option::is_none")]
540 pub last_position: Option<FilePosition>,
541}
542
543impl EventPayload for PrintEndedPayload {
544 const KIND: &'static str = "print_ended";
545}
546
547impl Sample for PrintEndedPayload {
548 fn sample_full() -> Self {
549 Self {
550 outcome: PrintOutcome::Cancelled,
551 state: PrinterState::Cancelling,
552 reason: "the operator cancelled it".to_owned(),
553 last_position: Some(FilePosition::sample_full()),
554 }
555 }
556
557 fn sample_minimal() -> Self {
558 Self {
559 outcome: PrintOutcome::Completed,
560 state: PrinterState::Operational,
561 reason: "finished".to_owned(),
562 last_position: None,
563 }
564 }
565}
566
567#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
569#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
570#[schemars(crate = "printobserver_types::schemars")]
571pub struct FilamentConsumedPayload {
572 pub charge_key: ChargeKey,
574 pub tool: i64,
576 pub method: ChargeMethod,
578 pub length_mm: f64,
580 #[serde(default, skip_serializing_if = "Option::is_none")]
584 pub charged: Option<ChargedFilament>,
585 #[serde(default, skip_serializing_if = "Option::is_none")]
587 pub analysed_length_mm: Option<f64>,
588 #[serde(default, skip_serializing_if = "Option::is_none")]
590 pub position: Option<FilePosition>,
591 #[serde(default, skip_serializing_if = "Option::is_none")]
593 pub note: Option<String>,
594}
595
596impl EventPayload for FilamentConsumedPayload {
597 const KIND: &'static str = "filament_consumed";
598}
599
600impl Sample for FilamentConsumedPayload {
601 fn sample_full() -> Self {
602 Self {
603 charge_key: ChargeKey::sample_full(),
604 tool: 0,
605 method: ChargeMethod::GcodeExtrusion,
606 length_mm: 1_000.0,
607 charged: Some(ChargedFilament::sample_full()),
608 analysed_length_mm: Some(5_120.0),
609 position: Some(FilePosition::sample_full()),
610 note: Some("charged up to the filament change".to_owned()),
611 }
612 }
613
614 fn sample_minimal() -> Self {
615 Self {
616 charge_key: ChargeKey::sample_full(),
617 tool: 0,
618 method: ChargeMethod::SlicerEstimate,
619 length_mm: 5_120.0,
620 charged: None,
621 analysed_length_mm: None,
622 position: None,
623 note: None,
624 }
625 }
626}
627
628#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
630#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
631#[schemars(crate = "printobserver_types::schemars")]
632pub struct SpoolRegisteredPayload {
633 pub spool: SpoolRecord,
635 pub actor: Actor,
637 pub reason: String,
639}
640
641impl EventPayload for SpoolRegisteredPayload {
642 const KIND: &'static str = "spool_registered";
643}
644
645impl Sample for SpoolRegisteredPayload {
646 fn sample_full() -> Self {
647 Self {
648 spool: SpoolRecord::sample_full(),
649 actor: Actor::Operator,
650 reason: sample_reason(),
651 }
652 }
653
654 fn sample_minimal() -> Self {
655 Self {
656 spool: SpoolRecord::sample_minimal(),
657 ..Self::sample_full()
658 }
659 }
660}
661
662#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
664#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
665#[schemars(crate = "printobserver_types::schemars")]
666pub struct SpoolLoadedPayload {
667 pub spool_id: SpoolId,
669 pub tool: i64,
671 #[serde(default, skip_serializing_if = "Option::is_none")]
673 pub replaced: Option<SpoolId>,
674 #[serde(default, skip_serializing_if = "Vec::is_empty")]
677 pub took_pending: Vec<PendingTaken>,
678 #[serde(default, skip_serializing_if = "Vec::is_empty")]
680 pub cleared_marks: Vec<ClearedMark>,
681 pub actor: Actor,
683 pub reason: String,
685}
686
687impl EventPayload for SpoolLoadedPayload {
688 const KIND: &'static str = "spool_loaded";
689}
690
691impl Sample for SpoolLoadedPayload {
692 fn sample_full() -> Self {
693 Self {
694 spool_id: sample_spool_id(),
695 tool: 0,
696 replaced: Some(ClearedMark::sample_full().spool_id),
697 took_pending: vec![PendingTaken::sample_full()],
698 cleared_marks: vec![ClearedMark::sample_full()],
699 actor: Actor::Operator,
700 reason: sample_reason(),
701 }
702 }
703
704 fn sample_minimal() -> Self {
705 Self {
706 replaced: None,
707 took_pending: Vec::new(),
708 cleared_marks: Vec::new(),
709 ..Self::sample_full()
710 }
711 }
712}
713
714#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
716#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
717#[schemars(crate = "printobserver_types::schemars")]
718pub struct SpoolUnloadedPayload {
719 pub spool_id: SpoolId,
721 pub tool: i64,
723 pub actor: Actor,
725 pub reason: String,
727}
728
729impl EventPayload for SpoolUnloadedPayload {
730 const KIND: &'static str = "spool_unloaded";
731}
732
733impl Sample for SpoolUnloadedPayload {
734 fn sample_full() -> Self {
735 Self {
736 spool_id: sample_spool_id(),
737 tool: 0,
738 actor: Actor::Operator,
739 reason: sample_reason(),
740 }
741 }
742}
743
744#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
746#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
747#[schemars(crate = "printobserver_types::schemars")]
748pub struct SpoolAdjustedPayload {
749 pub spool_id: SpoolId,
751 pub remaining_before_g: f64,
753 pub remaining_after_g: f64,
755 #[serde(default, skip_serializing_if = "Option::is_none")]
758 pub gross_g: Option<f64>,
759 #[serde(default, skip_serializing_if = "Vec::is_empty")]
762 pub took_pending: Vec<PendingTaken>,
763 #[serde(default, skip_serializing_if = "Vec::is_empty")]
765 pub cleared_marks: Vec<ClearedMark>,
766 pub actor: Actor,
768 pub reason: String,
770}
771
772impl EventPayload for SpoolAdjustedPayload {
773 const KIND: &'static str = "spool_adjusted";
774}
775
776impl Sample for SpoolAdjustedPayload {
777 fn sample_full() -> Self {
778 Self {
779 spool_id: sample_spool_id(),
780 remaining_before_g: 742.5,
781 remaining_after_g: 700.0,
782 gross_g: Some(950.0),
783 took_pending: vec![PendingTaken::sample_full()],
784 cleared_marks: vec![ClearedMark {
785 spool_id: sample_spool_id(),
786 reason: UnverifiedReason::sample_full(),
787 }],
788 actor: Actor::Operator,
789 reason: sample_reason(),
790 }
791 }
792
793 fn sample_minimal() -> Self {
794 Self {
795 gross_g: None,
796 took_pending: Vec::new(),
797 cleared_marks: Vec::new(),
798 ..Self::sample_full()
799 }
800 }
801}
802
803#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
805#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
806#[schemars(crate = "printobserver_types::schemars")]
807pub struct SpoolRetiredPayload {
808 pub spool_id: SpoolId,
810 pub remaining_g: f64,
812 pub actor: Actor,
814 pub reason: String,
816}
817
818impl EventPayload for SpoolRetiredPayload {
819 const KIND: &'static str = "spool_retired";
820}
821
822impl Sample for SpoolRetiredPayload {
823 fn sample_full() -> Self {
824 Self {
825 spool_id: sample_spool_id(),
826 remaining_g: 12.5,
827 actor: Actor::Operator,
828 reason: "the spool is empty".to_owned(),
829 }
830 }
831}
832
833#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
835#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
836#[schemars(crate = "printobserver_types::schemars")]
837pub struct SpoolCommandRejectedPayload {
838 pub command: SpoolCommand,
840 pub decision: PolicyDecision,
842}
843
844impl EventPayload for SpoolCommandRejectedPayload {
845 const KIND: &'static str = "spool_command_rejected";
846}
847
848impl Sample for SpoolCommandRejectedPayload {
849 fn sample_full() -> Self {
850 Self {
851 command: SpoolCommand::sample_full(),
852 decision: PolicyDecision::Rejected(crate::records::RejectionReason::SpoolRefused {
853 cause: crate::records::SpoolRefusalCause::DensityRequired {
854 spool_id: None,
855 material: "PEEK".to_owned(),
856 },
857 message: "PEEK has no known density, so the spool needs one".to_owned(),
858 }),
859 }
860 }
861
862 fn sample_minimal() -> Self {
863 Self {
864 command: SpoolCommand::sample_minimal(),
865 ..Self::sample_full()
866 }
867 }
868}
869
870#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
872#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
873#[schemars(crate = "printobserver_types::schemars")]
874pub struct SpoolUnverifiedPayload {
875 pub spool_id: SpoolId,
877 pub reason: UnverifiedReason,
879}
880
881impl EventPayload for SpoolUnverifiedPayload {
882 const KIND: &'static str = "spool_unverified";
883}
884
885impl Sample for SpoolUnverifiedPayload {
886 fn sample_full() -> Self {
887 Self {
888 spool_id: sample_spool_id(),
889 reason: UnverifiedReason::sample_full(),
890 }
891 }
892}
893
894#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
896#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
897#[schemars(crate = "printobserver_types::schemars")]
898pub struct FilamentChangeSignalledPayload {
899 #[serde(default, skip_serializing_if = "Option::is_none")]
901 pub tool: Option<i64>,
902 #[serde(default, skip_serializing_if = "Option::is_none")]
904 pub spool_id: Option<SpoolId>,
905 pub source_kind: EventKind,
907 #[serde(default, skip_serializing_if = "Option::is_none")]
910 pub position: Option<SignalPosition>,
911}
912
913#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
915#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
916#[schemars(crate = "printobserver_types::schemars")]
917pub struct SignalPosition {
918 pub position: FilePosition,
920 pub freshness: PositionFreshness,
923}
924
925#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
927#[serde(crate = "printobserver_types::serde", rename_all = "snake_case")]
928#[schemars(crate = "printobserver_types::schemars")]
929pub enum PositionFreshness {
930 ReadAtSignal,
932 LastRecorded,
935}
936
937impl EventPayload for FilamentChangeSignalledPayload {
938 const KIND: &'static str = "filament_change_signalled";
939}
940
941impl Sample for FilamentChangeSignalledPayload {
942 fn sample_full() -> Self {
943 Self {
944 tool: Some(0),
945 spool_id: Some(sample_spool_id()),
946 source_kind: EventKind::new("obico_printer_notification").expect("a kind name"),
947 position: Some(SignalPosition {
948 position: FilePosition::sample_full(),
949 freshness: PositionFreshness::ReadAtSignal,
950 }),
951 }
952 }
953
954 fn sample_minimal() -> Self {
955 Self {
956 tool: None,
957 spool_id: None,
958 position: None,
959 ..Self::sample_full()
960 }
961 }
962}
963
964#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
966#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
967#[schemars(crate = "printobserver_types::schemars")]
968pub struct UnaccountedPrintPayload {
969 pub file_name: String,
971 #[serde(default, skip_serializing_if = "Option::is_none")]
973 pub printed_at: Option<Timestamp>,
974 pub success: bool,
977 pub charged: bool,
980}
981
982impl EventPayload for UnaccountedPrintPayload {
983 const KIND: &'static str = "unaccounted_print";
984}
985
986impl Sample for UnaccountedPrintPayload {
987 fn sample_full() -> Self {
988 Self {
989 file_name: "benchy.gcode".to_owned(),
990 printed_at: Some(Timestamp::sample_full()),
991 success: true,
992 charged: true,
993 }
994 }
995
996 fn sample_minimal() -> Self {
997 Self {
998 printed_at: None,
999 success: false,
1000 charged: false,
1001 ..Self::sample_full()
1002 }
1003 }
1004}
1005
1006#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1008#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1009#[schemars(crate = "printobserver_types::schemars")]
1010pub struct PreflightCheckedPayload {
1011 pub preflight: Preflight,
1013 #[serde(default, skip_serializing_if = "Option::is_none")]
1015 pub action_id: Option<ActionId>,
1016}
1017
1018impl EventPayload for PreflightCheckedPayload {
1019 const KIND: &'static str = "preflight_checked";
1020}
1021
1022impl Sample for PreflightCheckedPayload {
1023 fn sample_full() -> Self {
1024 Self {
1025 preflight: Preflight::sample_full(),
1026 action_id: Some(ActionId::sample_full()),
1027 }
1028 }
1029
1030 fn sample_minimal() -> Self {
1031 Self {
1032 action_id: None,
1033 ..Self::sample_full()
1034 }
1035 }
1036}
1037
1038#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1041#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1042#[schemars(crate = "printobserver_types::schemars")]
1043pub struct ChargePendedPayload {
1044 pub pending: PendingCharge,
1046}
1047
1048impl EventPayload for ChargePendedPayload {
1049 const KIND: &'static str = "charge_pended";
1050}
1051
1052impl Sample for ChargePendedPayload {
1053 fn sample_full() -> Self {
1054 Self {
1055 pending: PendingCharge::sample_full(),
1056 }
1057 }
1058
1059 fn sample_minimal() -> Self {
1060 Self {
1061 pending: PendingCharge::sample_minimal(),
1062 }
1063 }
1064}
1065
1066#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1069#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1070#[schemars(crate = "printobserver_types::schemars")]
1071pub struct PrintUntrackedPayload {
1072 pub reason: String,
1074}
1075
1076impl EventPayload for PrintUntrackedPayload {
1077 const KIND: &'static str = "print_untracked";
1078}
1079
1080impl Sample for PrintUntrackedPayload {
1081 fn sample_full() -> Self {
1082 Self {
1083 reason: "the print was already running when spool tracking was installed".to_owned(),
1084 }
1085 }
1086}
1087
1088#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1090#[serde(crate = "printobserver_types::serde", rename_all = "snake_case")]
1091#[schemars(crate = "printobserver_types::schemars")]
1092pub enum RebaselineDisposition {
1093 Accounted,
1095 Unverified,
1098}
1099
1100impl Sample for RebaselineDisposition {
1101 fn sample_full() -> Self {
1102 Self::Unverified
1103 }
1104}
1105
1106#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1112#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1113#[schemars(crate = "printobserver_types::schemars")]
1114pub struct FileTallyRebaselinedPayload {
1115 pub file_name: String,
1117 pub origin: String,
1119 pub old_generation: u32,
1121 pub new_generation: u32,
1123 pub old_successes: i64,
1125 pub old_failures: i64,
1127 pub new_successes: i64,
1129 pub new_failures: i64,
1131 pub disposition: RebaselineDisposition,
1133}
1134
1135impl EventPayload for FileTallyRebaselinedPayload {
1136 const KIND: &'static str = "file_tally_rebaselined";
1137}
1138
1139impl Sample for FileTallyRebaselinedPayload {
1140 fn sample_full() -> Self {
1141 Self {
1142 file_name: "benchy.gcode".to_owned(),
1143 origin: "local".to_owned(),
1144 old_generation: 0,
1145 new_generation: 1,
1146 old_successes: 5,
1147 old_failures: 1,
1148 new_successes: 1,
1149 new_failures: 0,
1150 disposition: RebaselineDisposition::Unverified,
1151 }
1152 }
1153
1154 fn sample_alternates() -> Vec<Self> {
1155 vec![Self {
1156 disposition: RebaselineDisposition::Accounted,
1157 ..Self::sample_full()
1158 }]
1159 }
1160}
1161
1162#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1167#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1168#[schemars(crate = "printobserver_types::schemars")]
1169pub struct PrinterConnectionChangedPayload {
1170 pub from: PrinterState,
1172 pub to: PrinterState,
1174 pub detail: String,
1176}
1177
1178impl EventPayload for PrinterConnectionChangedPayload {
1179 const KIND: &'static str = "printer_connection_changed";
1180}
1181
1182impl Sample for PrinterConnectionChangedPayload {
1183 fn sample_full() -> Self {
1184 Self {
1185 from: PrinterState::Printing,
1186 to: PrinterState::Offline,
1187 detail: "the printer reports Offline after error: SerialTimeoutException: ".to_owned(),
1188 }
1189 }
1190
1191 fn sample_alternates() -> Vec<Self> {
1192 vec![Self {
1193 from: PrinterState::Offline,
1194 to: PrinterState::Operational,
1195 detail: "the printer reports Operational".to_owned(),
1196 }]
1197 }
1198}
1199
1200#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1207#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1208#[schemars(crate = "printobserver_types::schemars")]
1209pub struct PrinterResetPayload {
1210 #[serde(default)]
1212 pub during_print: Option<PrintId>,
1213 pub detail: String,
1215}
1216
1217impl EventPayload for PrinterResetPayload {
1218 const KIND: &'static str = "printer_reset";
1219}
1220
1221impl Sample for PrinterResetPayload {
1222 fn sample_full() -> Self {
1223 Self {
1224 during_print: Some(PrintId::sample_full()),
1225 detail: "the printer pushed a reset".to_owned(),
1226 }
1227 }
1228
1229 fn sample_minimal() -> Self {
1230 Self {
1231 during_print: None,
1232 detail: "the printer pushed a reset".to_owned(),
1233 }
1234 }
1235}
1236
1237#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1239#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1240#[schemars(crate = "printobserver_types::schemars")]
1241pub struct HeatedTool {
1242 pub tool: i64,
1244 pub target_c: f64,
1246}
1247
1248impl Sample for HeatedTool {
1249 fn sample_full() -> Self {
1250 Self {
1251 tool: 0,
1252 target_c: 215.0,
1253 }
1254 }
1255}
1256
1257#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1265#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1266#[schemars(crate = "printobserver_types::schemars")]
1267pub struct UnattendedPrinterActivityPayload {
1268 pub last_print_id: PrintId,
1270 pub tools: Vec<HeatedTool>,
1272 #[serde(default)]
1274 pub bed_target_c: Option<f64>,
1275 #[serde(default)]
1278 pub moved: Option<bool>,
1279 pub detail: String,
1281}
1282
1283impl EventPayload for UnattendedPrinterActivityPayload {
1284 const KIND: &'static str = "unattended_printer_activity";
1285}
1286
1287impl Sample for UnattendedPrinterActivityPayload {
1288 fn sample_full() -> Self {
1289 Self {
1290 last_print_id: PrintId::sample_full(),
1291 tools: vec![HeatedTool::sample_full()],
1292 bed_target_c: Some(60.0),
1293 moved: Some(true),
1294 detail: "tool 0 is heating to 215 °C with no job running".to_owned(),
1295 }
1296 }
1297
1298 fn sample_minimal() -> Self {
1299 Self {
1300 last_print_id: PrintId::sample_full(),
1301 tools: Vec::new(),
1302 bed_target_c: None,
1303 moved: None,
1304 detail: "the print head moved with no job running".to_owned(),
1305 }
1306 }
1307}
1308
1309#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1311#[serde(
1312 crate = "printobserver_types::serde",
1313 rename_all = "snake_case",
1314 deny_unknown_fields
1315)]
1316#[schemars(crate = "printobserver_types::schemars")]
1317pub enum DetectorStatus {
1318 Available,
1320 Unavailable,
1322}
1323
1324impl Sample for DetectorStatus {
1325 fn sample_full() -> Self {
1326 Self::Unavailable
1327 }
1328
1329 fn sample_alternates() -> Vec<Self> {
1330 vec![Self::Available]
1331 }
1332}
1333
1334#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1338#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1339#[schemars(crate = "printobserver_types::schemars")]
1340pub struct DetectorHealthChangedPayload {
1341 pub status: DetectorStatus,
1343 pub detail: String,
1345}
1346
1347impl EventPayload for DetectorHealthChangedPayload {
1348 const KIND: &'static str = "detector_health_changed";
1349}
1350
1351impl Sample for DetectorHealthChangedPayload {
1352 fn sample_full() -> Self {
1353 Self {
1354 status: DetectorStatus::Unavailable,
1355 detail: "the detector's health check answered 503".to_owned(),
1356 }
1357 }
1358
1359 fn sample_alternates() -> Vec<Self> {
1360 vec![Self {
1361 status: DetectorStatus::Available,
1362 detail: "the detector's health check answered 200".to_owned(),
1363 }]
1364 }
1365}