1use crate::records::{
26 AcknowledgementDisposition, ActionId, Actor, ChargeKey, ChargeMethod, ChargedFilament,
27 ClearedMark, FilePosition, InterventionId, InterventionOutcome, LoadedSpool, PendingCharge,
28 PendingTaken, PolicyDecision, Preflight, PrintAction, PrintOutcome, RecoveryAction,
29 RecoveryRejection, SpoolCommand, SpoolId, SpoolRecord, UnverifiedReason,
30};
31use printobserver_printer_api::{Adjustable, JobSnapshot, PrinterSnapshot, PrinterState};
32use printobserver_supervisor_api::AgentAssessment;
33use printobserver_types::contract::Sample;
34use printobserver_types::schemars::JsonSchema;
35use printobserver_types::serde::{Deserialize, Serialize};
36use printobserver_types::{EventId, EventKind, EventPayload, EventSource, PrintId, Timestamp};
37
38pub const SYSTEM_SOURCE: &str = "system";
40
41pub const OPERATOR_SOURCE: &str = "operator";
43
44pub const AGENT_SOURCE: &str = "agent";
46
47#[must_use]
49pub fn system_source() -> EventSource {
50 EventSource::new(SYSTEM_SOURCE)
51}
52
53#[must_use]
55pub fn operator_source() -> EventSource {
56 EventSource::new(OPERATOR_SOURCE)
57}
58
59#[must_use]
61pub fn agent_source() -> EventSource {
62 EventSource::new(AGENT_SOURCE)
63}
64
65#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
67#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
68#[schemars(crate = "printobserver_types::schemars")]
69pub struct ActionRequestedPayload {
70 pub action_id: ActionId,
72 pub action: PrintAction,
74 pub actor: Actor,
76}
77
78impl EventPayload for ActionRequestedPayload {
79 const KIND: &'static str = "action_requested";
80}
81
82impl Sample for ActionRequestedPayload {
83 fn sample_full() -> Self {
84 Self {
85 action_id: ActionId::sample_full(),
86 action: PrintAction::sample_full(),
87 actor: Actor::sample_full(),
88 }
89 }
90
91 fn sample_minimal() -> Self {
92 Self {
93 action: PrintAction::sample_minimal(),
94 ..Self::sample_full()
95 }
96 }
97}
98
99#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
101#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
102#[schemars(crate = "printobserver_types::schemars")]
103pub struct ActionExecutedPayload {
104 pub action_id: ActionId,
106 #[serde(default, skip_serializing_if = "Option::is_none")]
108 pub intervention_id: Option<InterventionId>,
109}
110
111impl EventPayload for ActionExecutedPayload {
112 const KIND: &'static str = "action_executed";
113}
114
115impl Sample for ActionExecutedPayload {
116 fn sample_full() -> Self {
117 Self {
118 action_id: ActionId::sample_full(),
119 intervention_id: Some(InterventionId::sample_full()),
120 }
121 }
122
123 fn sample_minimal() -> Self {
124 Self {
125 action_id: ActionId::sample_full(),
126 intervention_id: None,
127 }
128 }
129}
130
131#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
133#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
134#[schemars(crate = "printobserver_types::schemars")]
135pub struct ActionRejectedPayload {
136 pub action_id: ActionId,
138 pub decision: PolicyDecision,
140}
141
142impl EventPayload for ActionRejectedPayload {
143 const KIND: &'static str = "action_rejected";
144}
145
146impl Sample for ActionRejectedPayload {
147 fn sample_full() -> Self {
148 Self {
149 action_id: ActionId::sample_full(),
150 decision: PolicyDecision::sample_full(),
151 }
152 }
153}
154
155#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
157#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
158#[schemars(crate = "printobserver_types::schemars")]
159pub struct InterventionExpiredPayload {
160 pub intervention_id: InterventionId,
162 pub adjustable: Adjustable,
164 pub outcome: InterventionOutcome,
166}
167
168impl EventPayload for InterventionExpiredPayload {
169 const KIND: &'static str = "intervention_expired";
170}
171
172impl Sample for InterventionExpiredPayload {
173 fn sample_full() -> Self {
174 Self {
175 intervention_id: InterventionId::sample_full(),
176 adjustable: Adjustable::Feedrate,
177 outcome: InterventionOutcome::Restored,
178 }
179 }
180}
181
182#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
184#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
185#[schemars(crate = "printobserver_types::schemars")]
186pub struct AgentAssessmentPayload {
187 pub session_name: String,
189 pub assessment: AgentAssessment,
191}
192
193impl EventPayload for AgentAssessmentPayload {
194 const KIND: &'static str = "agent_assessment";
195}
196
197impl Sample for AgentAssessmentPayload {
198 fn sample_full() -> Self {
199 Self {
200 session_name: "print-0191f0a0".to_owned(),
201 assessment: AgentAssessment::sample_full(),
202 }
203 }
204}
205
206#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
208#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
209#[schemars(crate = "printobserver_types::schemars")]
210pub struct OperatorAcknowledgementPayload {
211 pub acknowledged_event_id: EventId,
213 pub disposition: AcknowledgementDisposition,
215}
216
217impl EventPayload for OperatorAcknowledgementPayload {
218 const KIND: &'static str = "operator_acknowledgement";
219}
220
221impl Sample for OperatorAcknowledgementPayload {
222 fn sample_full() -> Self {
223 Self {
224 acknowledged_event_id: EventId::sample_full(),
225 disposition: AcknowledgementDisposition::Watch,
226 }
227 }
228}
229
230#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
236#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
237#[schemars(crate = "printobserver_types::schemars")]
238pub struct CameraLookPayload {
239 pub waited_s: u32,
242 #[serde(default)]
245 pub delivered: Vec<EventId>,
246}
247
248impl EventPayload for CameraLookPayload {
249 const KIND: &'static str = "camera_look";
250}
251
252impl Sample for CameraLookPayload {
253 fn sample_full() -> Self {
254 Self {
255 waited_s: 60,
256 delivered: vec![EventId::sample_full()],
257 }
258 }
259
260 fn sample_minimal() -> Self {
261 Self {
262 waited_s: 0,
263 delivered: Vec::new(),
264 }
265 }
266}
267
268#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
278#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
279#[schemars(crate = "printobserver_types::schemars")]
280pub struct PeriodicObservationPayload {
281 pub interval_s: u64,
283 #[serde(default, skip_serializing_if = "Option::is_none")]
286 pub printer: Option<PrinterSnapshot>,
287 #[serde(default, skip_serializing_if = "Option::is_none")]
290 pub job: Option<JobSnapshot>,
291}
292
293impl EventPayload for PeriodicObservationPayload {
294 const KIND: &'static str = "periodic_observation";
295}
296
297impl Sample for PeriodicObservationPayload {
298 fn sample_full() -> Self {
299 Self {
300 interval_s: 120,
301 printer: Some(PrinterSnapshot::sample_full()),
302 job: Some(JobSnapshot::sample_full()),
303 }
304 }
305
306 fn sample_minimal() -> Self {
307 Self {
308 interval_s: 120,
309 printer: None,
310 job: None,
311 }
312 }
313}
314
315#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
317#[serde(
318 crate = "printobserver_types::serde",
319 rename_all = "snake_case",
320 deny_unknown_fields
321)]
322#[schemars(crate = "printobserver_types::schemars")]
323pub enum FrameCause {
324 Blank,
327 Undecodable,
329}
330
331impl Sample for FrameCause {
332 fn sample_full() -> Self {
333 Self::Blank
334 }
335
336 fn sample_alternates() -> Vec<Self> {
337 vec![Self::Undecodable]
338 }
339}
340
341#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
347#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
348#[schemars(crate = "printobserver_types::schemars")]
349pub struct CameraDegradedPayload {
350 pub attempts: u32,
352 pub cause: FrameCause,
354 pub detail: String,
356}
357
358impl EventPayload for CameraDegradedPayload {
359 const KIND: &'static str = "camera_degraded";
360}
361
362impl Sample for CameraDegradedPayload {
363 fn sample_full() -> Self {
364 Self {
365 attempts: 3,
366 cause: FrameCause::Blank,
367 detail: "every frame was near-uniform grey (grey-level spread 2.1 below 36.5)"
368 .to_owned(),
369 }
370 }
371
372 fn sample_alternates() -> Vec<Self> {
373 vec![Self {
374 cause: FrameCause::Undecodable,
375 detail: "every frame failed a strict decode: the image ends early".to_owned(),
376 ..Self::sample_full()
377 }]
378 }
379}
380
381#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
390#[serde(
391 crate = "printobserver_types::serde",
392 rename_all = "snake_case",
393 deny_unknown_fields
394)]
395#[schemars(crate = "printobserver_types::schemars")]
396pub enum PortFailureSite {
397 PrinterSnapshot,
399 PrinterJob,
401 ImageWrite,
403 SupervisionTurn,
405 CameraLook,
408 DetectorAcknowledgement,
410}
411
412impl Sample for PortFailureSite {
413 fn sample_full() -> Self {
414 Self::PrinterSnapshot
415 }
416}
417
418#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
426#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
427#[schemars(crate = "printobserver_types::schemars")]
428pub struct PortFailurePayload {
429 pub event_id: EventId,
431 pub site: PortFailureSite,
433 pub detail: String,
435}
436
437impl EventPayload for PortFailurePayload {
438 const KIND: &'static str = "port_failure";
439}
440
441impl Sample for PortFailurePayload {
442 fn sample_full() -> Self {
443 Self {
444 event_id: EventId::sample_full(),
445 site: PortFailureSite::sample_full(),
446 detail: "the printer is unreachable: connection refused".to_owned(),
447 }
448 }
449}
450
451pub const TIMELINE_KINDS: [&str; 23] = [
455 PrintStartedPayload::KIND,
456 PrintEndedPayload::KIND,
457 FilamentConsumedPayload::KIND,
458 SpoolRegisteredPayload::KIND,
459 SpoolLoadedPayload::KIND,
460 SpoolUnloadedPayload::KIND,
461 SpoolAdjustedPayload::KIND,
462 SpoolRetiredPayload::KIND,
463 SpoolCommandRejectedPayload::KIND,
464 SpoolUnverifiedPayload::KIND,
465 FilamentChangeSignalledPayload::KIND,
466 UnaccountedPrintPayload::KIND,
467 PreflightCheckedPayload::KIND,
468 ChargePendedPayload::KIND,
469 PrintUntrackedPayload::KIND,
470 FileTallyRebaselinedPayload::KIND,
471 PrinterConnectionChangedPayload::KIND,
472 PrinterResetPayload::KIND,
473 UnattendedPrinterActivityPayload::KIND,
474 DetectorHealthChangedPayload::KIND,
475 RecoveryRequestedPayload::KIND,
476 RecoveryExecutedPayload::KIND,
477 RecoveryRejectedPayload::KIND,
478];
479
480fn sample_spool_id() -> SpoolId {
482 SpoolId::sample_full()
483}
484
485fn sample_reason() -> String {
487 "the spool on the shelf changed".to_owned()
488}
489
490#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
492#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
493#[schemars(crate = "printobserver_types::schemars")]
494pub struct PrintStartedPayload {
495 #[serde(default, skip_serializing_if = "Option::is_none")]
497 pub file_name: Option<String>,
498 #[serde(default, skip_serializing_if = "Option::is_none")]
501 pub started_by: Option<ActionId>,
502 pub loaded: Vec<LoadedSpool>,
504 #[serde(default, skip_serializing_if = "Option::is_none")]
506 pub preflight: Option<Preflight>,
507}
508
509impl EventPayload for PrintStartedPayload {
510 const KIND: &'static str = "print_started";
511}
512
513impl Sample for PrintStartedPayload {
514 fn sample_full() -> Self {
515 Self {
516 file_name: Some("benchy.gcode".to_owned()),
517 started_by: Some(ActionId::sample_full()),
518 loaded: vec![LoadedSpool::sample_full()],
519 preflight: Some(Preflight::sample_full()),
520 }
521 }
522
523 fn sample_minimal() -> Self {
524 Self {
525 file_name: None,
526 started_by: None,
527 loaded: Vec::new(),
528 preflight: None,
529 }
530 }
531}
532
533#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
535#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
536#[schemars(crate = "printobserver_types::schemars")]
537pub struct PrintEndedPayload {
538 pub outcome: PrintOutcome,
540 pub state: PrinterState,
542 pub reason: String,
544 #[serde(default, skip_serializing_if = "Option::is_none")]
546 pub last_position: Option<FilePosition>,
547}
548
549impl EventPayload for PrintEndedPayload {
550 const KIND: &'static str = "print_ended";
551}
552
553impl Sample for PrintEndedPayload {
554 fn sample_full() -> Self {
555 Self {
556 outcome: PrintOutcome::Cancelled,
557 state: PrinterState::Cancelling,
558 reason: "the operator cancelled it".to_owned(),
559 last_position: Some(FilePosition::sample_full()),
560 }
561 }
562
563 fn sample_minimal() -> Self {
564 Self {
565 outcome: PrintOutcome::Completed,
566 state: PrinterState::Operational,
567 reason: "finished".to_owned(),
568 last_position: None,
569 }
570 }
571}
572
573#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
575#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
576#[schemars(crate = "printobserver_types::schemars")]
577pub struct FilamentConsumedPayload {
578 pub charge_key: ChargeKey,
580 pub tool: i64,
582 pub method: ChargeMethod,
584 pub length_mm: f64,
586 #[serde(default, skip_serializing_if = "Option::is_none")]
590 pub charged: Option<ChargedFilament>,
591 #[serde(default, skip_serializing_if = "Option::is_none")]
593 pub analysed_length_mm: Option<f64>,
594 #[serde(default, skip_serializing_if = "Option::is_none")]
596 pub position: Option<FilePosition>,
597 #[serde(default, skip_serializing_if = "Option::is_none")]
599 pub note: Option<String>,
600}
601
602impl EventPayload for FilamentConsumedPayload {
603 const KIND: &'static str = "filament_consumed";
604}
605
606impl Sample for FilamentConsumedPayload {
607 fn sample_full() -> Self {
608 Self {
609 charge_key: ChargeKey::sample_full(),
610 tool: 0,
611 method: ChargeMethod::GcodeExtrusion,
612 length_mm: 1_000.0,
613 charged: Some(ChargedFilament::sample_full()),
614 analysed_length_mm: Some(5_120.0),
615 position: Some(FilePosition::sample_full()),
616 note: Some("charged up to the filament change".to_owned()),
617 }
618 }
619
620 fn sample_minimal() -> Self {
621 Self {
622 charge_key: ChargeKey::sample_full(),
623 tool: 0,
624 method: ChargeMethod::SlicerEstimate,
625 length_mm: 5_120.0,
626 charged: None,
627 analysed_length_mm: None,
628 position: None,
629 note: None,
630 }
631 }
632}
633
634#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
636#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
637#[schemars(crate = "printobserver_types::schemars")]
638pub struct SpoolRegisteredPayload {
639 pub spool: SpoolRecord,
641 pub actor: Actor,
643 pub reason: String,
645}
646
647impl EventPayload for SpoolRegisteredPayload {
648 const KIND: &'static str = "spool_registered";
649}
650
651impl Sample for SpoolRegisteredPayload {
652 fn sample_full() -> Self {
653 Self {
654 spool: SpoolRecord::sample_full(),
655 actor: Actor::Operator,
656 reason: sample_reason(),
657 }
658 }
659
660 fn sample_minimal() -> Self {
661 Self {
662 spool: SpoolRecord::sample_minimal(),
663 ..Self::sample_full()
664 }
665 }
666}
667
668#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
670#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
671#[schemars(crate = "printobserver_types::schemars")]
672pub struct SpoolLoadedPayload {
673 pub spool_id: SpoolId,
675 pub tool: i64,
677 #[serde(default, skip_serializing_if = "Option::is_none")]
679 pub replaced: Option<SpoolId>,
680 #[serde(default, skip_serializing_if = "Vec::is_empty")]
683 pub took_pending: Vec<PendingTaken>,
684 #[serde(default, skip_serializing_if = "Vec::is_empty")]
686 pub cleared_marks: Vec<ClearedMark>,
687 pub actor: Actor,
689 pub reason: String,
691}
692
693impl EventPayload for SpoolLoadedPayload {
694 const KIND: &'static str = "spool_loaded";
695}
696
697impl Sample for SpoolLoadedPayload {
698 fn sample_full() -> Self {
699 Self {
700 spool_id: sample_spool_id(),
701 tool: 0,
702 replaced: Some(ClearedMark::sample_full().spool_id),
703 took_pending: vec![PendingTaken::sample_full()],
704 cleared_marks: vec![ClearedMark::sample_full()],
705 actor: Actor::Operator,
706 reason: sample_reason(),
707 }
708 }
709
710 fn sample_minimal() -> Self {
711 Self {
712 replaced: None,
713 took_pending: Vec::new(),
714 cleared_marks: Vec::new(),
715 ..Self::sample_full()
716 }
717 }
718}
719
720#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
722#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
723#[schemars(crate = "printobserver_types::schemars")]
724pub struct SpoolUnloadedPayload {
725 pub spool_id: SpoolId,
727 pub tool: i64,
729 pub actor: Actor,
731 pub reason: String,
733}
734
735impl EventPayload for SpoolUnloadedPayload {
736 const KIND: &'static str = "spool_unloaded";
737}
738
739impl Sample for SpoolUnloadedPayload {
740 fn sample_full() -> Self {
741 Self {
742 spool_id: sample_spool_id(),
743 tool: 0,
744 actor: Actor::Operator,
745 reason: sample_reason(),
746 }
747 }
748}
749
750#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
752#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
753#[schemars(crate = "printobserver_types::schemars")]
754pub struct SpoolAdjustedPayload {
755 pub spool_id: SpoolId,
757 pub remaining_before_g: f64,
759 pub remaining_after_g: f64,
761 #[serde(default, skip_serializing_if = "Option::is_none")]
764 pub gross_g: Option<f64>,
765 #[serde(default, skip_serializing_if = "Vec::is_empty")]
768 pub took_pending: Vec<PendingTaken>,
769 #[serde(default, skip_serializing_if = "Vec::is_empty")]
771 pub cleared_marks: Vec<ClearedMark>,
772 pub actor: Actor,
774 pub reason: String,
776}
777
778impl EventPayload for SpoolAdjustedPayload {
779 const KIND: &'static str = "spool_adjusted";
780}
781
782impl Sample for SpoolAdjustedPayload {
783 fn sample_full() -> Self {
784 Self {
785 spool_id: sample_spool_id(),
786 remaining_before_g: 742.5,
787 remaining_after_g: 700.0,
788 gross_g: Some(950.0),
789 took_pending: vec![PendingTaken::sample_full()],
790 cleared_marks: vec![ClearedMark {
791 spool_id: sample_spool_id(),
792 reason: UnverifiedReason::sample_full(),
793 }],
794 actor: Actor::Operator,
795 reason: sample_reason(),
796 }
797 }
798
799 fn sample_minimal() -> Self {
800 Self {
801 gross_g: None,
802 took_pending: Vec::new(),
803 cleared_marks: Vec::new(),
804 ..Self::sample_full()
805 }
806 }
807}
808
809#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
811#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
812#[schemars(crate = "printobserver_types::schemars")]
813pub struct SpoolRetiredPayload {
814 pub spool_id: SpoolId,
816 pub remaining_g: f64,
818 pub actor: Actor,
820 pub reason: String,
822}
823
824impl EventPayload for SpoolRetiredPayload {
825 const KIND: &'static str = "spool_retired";
826}
827
828impl Sample for SpoolRetiredPayload {
829 fn sample_full() -> Self {
830 Self {
831 spool_id: sample_spool_id(),
832 remaining_g: 12.5,
833 actor: Actor::Operator,
834 reason: "the spool is empty".to_owned(),
835 }
836 }
837}
838
839#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
841#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
842#[schemars(crate = "printobserver_types::schemars")]
843pub struct SpoolCommandRejectedPayload {
844 pub command: SpoolCommand,
846 pub decision: PolicyDecision,
848}
849
850impl EventPayload for SpoolCommandRejectedPayload {
851 const KIND: &'static str = "spool_command_rejected";
852}
853
854impl Sample for SpoolCommandRejectedPayload {
855 fn sample_full() -> Self {
856 Self {
857 command: SpoolCommand::sample_full(),
858 decision: PolicyDecision::Rejected(crate::records::RejectionReason::SpoolRefused {
859 cause: crate::records::SpoolRefusalCause::DensityRequired {
860 spool_id: None,
861 material: "PEEK".to_owned(),
862 },
863 message: "PEEK has no known density, so the spool needs one".to_owned(),
864 }),
865 }
866 }
867
868 fn sample_minimal() -> Self {
869 Self {
870 command: SpoolCommand::sample_minimal(),
871 ..Self::sample_full()
872 }
873 }
874}
875
876#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
878#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
879#[schemars(crate = "printobserver_types::schemars")]
880pub struct SpoolUnverifiedPayload {
881 pub spool_id: SpoolId,
883 pub reason: UnverifiedReason,
885}
886
887impl EventPayload for SpoolUnverifiedPayload {
888 const KIND: &'static str = "spool_unverified";
889}
890
891impl Sample for SpoolUnverifiedPayload {
892 fn sample_full() -> Self {
893 Self {
894 spool_id: sample_spool_id(),
895 reason: UnverifiedReason::sample_full(),
896 }
897 }
898}
899
900#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
902#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
903#[schemars(crate = "printobserver_types::schemars")]
904pub struct FilamentChangeSignalledPayload {
905 #[serde(default, skip_serializing_if = "Option::is_none")]
907 pub tool: Option<i64>,
908 #[serde(default, skip_serializing_if = "Option::is_none")]
910 pub spool_id: Option<SpoolId>,
911 pub source_kind: EventKind,
913 #[serde(default, skip_serializing_if = "Option::is_none")]
916 pub position: Option<SignalPosition>,
917}
918
919#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
921#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
922#[schemars(crate = "printobserver_types::schemars")]
923pub struct SignalPosition {
924 pub position: FilePosition,
926 pub freshness: PositionFreshness,
929}
930
931#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
933#[serde(crate = "printobserver_types::serde", rename_all = "snake_case")]
934#[schemars(crate = "printobserver_types::schemars")]
935pub enum PositionFreshness {
936 ReadAtSignal,
938 LastRecorded,
941}
942
943impl EventPayload for FilamentChangeSignalledPayload {
944 const KIND: &'static str = "filament_change_signalled";
945}
946
947impl Sample for FilamentChangeSignalledPayload {
948 fn sample_full() -> Self {
949 Self {
950 tool: Some(0),
951 spool_id: Some(sample_spool_id()),
952 source_kind: EventKind::new("obico_printer_notification").expect("a kind name"),
953 position: Some(SignalPosition {
954 position: FilePosition::sample_full(),
955 freshness: PositionFreshness::ReadAtSignal,
956 }),
957 }
958 }
959
960 fn sample_minimal() -> Self {
961 Self {
962 tool: None,
963 spool_id: None,
964 position: None,
965 ..Self::sample_full()
966 }
967 }
968}
969
970#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
972#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
973#[schemars(crate = "printobserver_types::schemars")]
974pub struct UnaccountedPrintPayload {
975 pub file_name: String,
977 #[serde(default, skip_serializing_if = "Option::is_none")]
979 pub printed_at: Option<Timestamp>,
980 pub success: bool,
983 pub charged: bool,
986}
987
988impl EventPayload for UnaccountedPrintPayload {
989 const KIND: &'static str = "unaccounted_print";
990}
991
992impl Sample for UnaccountedPrintPayload {
993 fn sample_full() -> Self {
994 Self {
995 file_name: "benchy.gcode".to_owned(),
996 printed_at: Some(Timestamp::sample_full()),
997 success: true,
998 charged: true,
999 }
1000 }
1001
1002 fn sample_minimal() -> Self {
1003 Self {
1004 printed_at: None,
1005 success: false,
1006 charged: false,
1007 ..Self::sample_full()
1008 }
1009 }
1010}
1011
1012#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1014#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1015#[schemars(crate = "printobserver_types::schemars")]
1016pub struct PreflightCheckedPayload {
1017 pub preflight: Preflight,
1019 #[serde(default, skip_serializing_if = "Option::is_none")]
1021 pub action_id: Option<ActionId>,
1022}
1023
1024impl EventPayload for PreflightCheckedPayload {
1025 const KIND: &'static str = "preflight_checked";
1026}
1027
1028impl Sample for PreflightCheckedPayload {
1029 fn sample_full() -> Self {
1030 Self {
1031 preflight: Preflight::sample_full(),
1032 action_id: Some(ActionId::sample_full()),
1033 }
1034 }
1035
1036 fn sample_minimal() -> Self {
1037 Self {
1038 action_id: None,
1039 ..Self::sample_full()
1040 }
1041 }
1042}
1043
1044#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1047#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1048#[schemars(crate = "printobserver_types::schemars")]
1049pub struct ChargePendedPayload {
1050 pub pending: PendingCharge,
1052}
1053
1054impl EventPayload for ChargePendedPayload {
1055 const KIND: &'static str = "charge_pended";
1056}
1057
1058impl Sample for ChargePendedPayload {
1059 fn sample_full() -> Self {
1060 Self {
1061 pending: PendingCharge::sample_full(),
1062 }
1063 }
1064
1065 fn sample_minimal() -> Self {
1066 Self {
1067 pending: PendingCharge::sample_minimal(),
1068 }
1069 }
1070}
1071
1072#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1075#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1076#[schemars(crate = "printobserver_types::schemars")]
1077pub struct PrintUntrackedPayload {
1078 pub reason: String,
1080}
1081
1082impl EventPayload for PrintUntrackedPayload {
1083 const KIND: &'static str = "print_untracked";
1084}
1085
1086impl Sample for PrintUntrackedPayload {
1087 fn sample_full() -> Self {
1088 Self {
1089 reason: "the print was already running when spool tracking was installed".to_owned(),
1090 }
1091 }
1092}
1093
1094#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1096#[serde(crate = "printobserver_types::serde", rename_all = "snake_case")]
1097#[schemars(crate = "printobserver_types::schemars")]
1098pub enum RebaselineDisposition {
1099 Accounted,
1101 Unverified,
1104}
1105
1106impl Sample for RebaselineDisposition {
1107 fn sample_full() -> Self {
1108 Self::Unverified
1109 }
1110}
1111
1112#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1118#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1119#[schemars(crate = "printobserver_types::schemars")]
1120pub struct FileTallyRebaselinedPayload {
1121 pub file_name: String,
1123 pub origin: String,
1125 pub old_generation: u32,
1127 pub new_generation: u32,
1129 pub old_successes: i64,
1131 pub old_failures: i64,
1133 pub new_successes: i64,
1135 pub new_failures: i64,
1137 pub disposition: RebaselineDisposition,
1139}
1140
1141impl EventPayload for FileTallyRebaselinedPayload {
1142 const KIND: &'static str = "file_tally_rebaselined";
1143}
1144
1145impl Sample for FileTallyRebaselinedPayload {
1146 fn sample_full() -> Self {
1147 Self {
1148 file_name: "benchy.gcode".to_owned(),
1149 origin: "local".to_owned(),
1150 old_generation: 0,
1151 new_generation: 1,
1152 old_successes: 5,
1153 old_failures: 1,
1154 new_successes: 1,
1155 new_failures: 0,
1156 disposition: RebaselineDisposition::Unverified,
1157 }
1158 }
1159
1160 fn sample_alternates() -> Vec<Self> {
1161 vec![Self {
1162 disposition: RebaselineDisposition::Accounted,
1163 ..Self::sample_full()
1164 }]
1165 }
1166}
1167
1168#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1173#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1174#[schemars(crate = "printobserver_types::schemars")]
1175pub struct PrinterConnectionChangedPayload {
1176 pub from: PrinterState,
1178 pub to: PrinterState,
1180 pub detail: String,
1182}
1183
1184impl EventPayload for PrinterConnectionChangedPayload {
1185 const KIND: &'static str = "printer_connection_changed";
1186}
1187
1188impl Sample for PrinterConnectionChangedPayload {
1189 fn sample_full() -> Self {
1190 Self {
1191 from: PrinterState::Printing,
1192 to: PrinterState::Offline,
1193 detail: "the printer reports Offline after error: SerialTimeoutException: ".to_owned(),
1194 }
1195 }
1196
1197 fn sample_alternates() -> Vec<Self> {
1198 vec![Self {
1199 from: PrinterState::Offline,
1200 to: PrinterState::Operational,
1201 detail: "the printer reports Operational".to_owned(),
1202 }]
1203 }
1204}
1205
1206#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1213#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1214#[schemars(crate = "printobserver_types::schemars")]
1215pub struct PrinterResetPayload {
1216 #[serde(default)]
1218 pub during_print: Option<PrintId>,
1219 pub detail: String,
1221}
1222
1223impl EventPayload for PrinterResetPayload {
1224 const KIND: &'static str = "printer_reset";
1225}
1226
1227impl Sample for PrinterResetPayload {
1228 fn sample_full() -> Self {
1229 Self {
1230 during_print: Some(PrintId::sample_full()),
1231 detail: "the printer pushed a reset".to_owned(),
1232 }
1233 }
1234
1235 fn sample_minimal() -> Self {
1236 Self {
1237 during_print: None,
1238 detail: "the printer pushed a reset".to_owned(),
1239 }
1240 }
1241}
1242
1243#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1245#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1246#[schemars(crate = "printobserver_types::schemars")]
1247pub struct HeatedTool {
1248 pub tool: i64,
1250 pub target_c: f64,
1252}
1253
1254impl Sample for HeatedTool {
1255 fn sample_full() -> Self {
1256 Self {
1257 tool: 0,
1258 target_c: 215.0,
1259 }
1260 }
1261}
1262
1263#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1271#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1272#[schemars(crate = "printobserver_types::schemars")]
1273pub struct UnattendedPrinterActivityPayload {
1274 pub last_print_id: PrintId,
1276 pub tools: Vec<HeatedTool>,
1278 #[serde(default)]
1280 pub bed_target_c: Option<f64>,
1281 #[serde(default)]
1284 pub moved: Option<bool>,
1285 pub detail: String,
1287}
1288
1289impl EventPayload for UnattendedPrinterActivityPayload {
1290 const KIND: &'static str = "unattended_printer_activity";
1291}
1292
1293impl Sample for UnattendedPrinterActivityPayload {
1294 fn sample_full() -> Self {
1295 Self {
1296 last_print_id: PrintId::sample_full(),
1297 tools: vec![HeatedTool::sample_full()],
1298 bed_target_c: Some(60.0),
1299 moved: Some(true),
1300 detail: "tool 0 is heating to 215 °C with no job running".to_owned(),
1301 }
1302 }
1303
1304 fn sample_minimal() -> Self {
1305 Self {
1306 last_print_id: PrintId::sample_full(),
1307 tools: Vec::new(),
1308 bed_target_c: None,
1309 moved: None,
1310 detail: "the print head moved with no job running".to_owned(),
1311 }
1312 }
1313}
1314
1315#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1317#[serde(
1318 crate = "printobserver_types::serde",
1319 rename_all = "snake_case",
1320 deny_unknown_fields
1321)]
1322#[schemars(crate = "printobserver_types::schemars")]
1323pub enum DetectorStatus {
1324 Available,
1326 Unavailable,
1328}
1329
1330impl Sample for DetectorStatus {
1331 fn sample_full() -> Self {
1332 Self::Unavailable
1333 }
1334
1335 fn sample_alternates() -> Vec<Self> {
1336 vec![Self::Available]
1337 }
1338}
1339
1340#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1344#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1345#[schemars(crate = "printobserver_types::schemars")]
1346pub struct DetectorHealthChangedPayload {
1347 pub status: DetectorStatus,
1349 pub detail: String,
1351}
1352
1353impl EventPayload for DetectorHealthChangedPayload {
1354 const KIND: &'static str = "detector_health_changed";
1355}
1356
1357impl Sample for DetectorHealthChangedPayload {
1358 fn sample_full() -> Self {
1359 Self {
1360 status: DetectorStatus::Unavailable,
1361 detail: "the detector's health check answered 503".to_owned(),
1362 }
1363 }
1364
1365 fn sample_alternates() -> Vec<Self> {
1366 vec![Self {
1367 status: DetectorStatus::Available,
1368 detail: "the detector's health check answered 200".to_owned(),
1369 }]
1370 }
1371}
1372
1373#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1377#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1378#[schemars(crate = "printobserver_types::schemars")]
1379pub struct RecoveryRequestedPayload {
1380 pub action: RecoveryAction,
1382 pub actor: Actor,
1384 pub reason: String,
1386}
1387
1388impl EventPayload for RecoveryRequestedPayload {
1389 const KIND: &'static str = "recovery_requested";
1390}
1391
1392impl Sample for RecoveryRequestedPayload {
1393 fn sample_full() -> Self {
1394 Self {
1395 action: RecoveryAction::sample_full(),
1396 actor: Actor::Operator,
1397 reason: "free the nozzle from the part".to_owned(),
1398 }
1399 }
1400}
1401
1402#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1404#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1405#[schemars(crate = "printobserver_types::schemars")]
1406pub struct RecoveryExecutedPayload {
1407 pub action: RecoveryAction,
1409 pub actor: Actor,
1411 pub reason: String,
1413 pub outcome: crate::records::ExecutionOutcome,
1415}
1416
1417impl EventPayload for RecoveryExecutedPayload {
1418 const KIND: &'static str = "recovery_executed";
1419}
1420
1421impl Sample for RecoveryExecutedPayload {
1422 fn sample_full() -> Self {
1423 Self {
1424 action: RecoveryAction::RecoverLift { mm: 10.0 },
1425 actor: Actor::Operator,
1426 reason: "free the nozzle from the part".to_owned(),
1427 outcome: crate::records::ExecutionOutcome::Succeeded,
1428 }
1429 }
1430
1431 fn sample_alternates() -> Vec<Self> {
1432 vec![Self {
1433 outcome: crate::records::ExecutionOutcome::Failed {
1434 reason: "the printer is unreachable: connection refused".to_owned(),
1435 },
1436 ..Self::sample_full()
1437 }]
1438 }
1439}
1440
1441#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1443#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1444#[schemars(crate = "printobserver_types::schemars")]
1445pub struct RecoveryRejectedPayload {
1446 pub action: RecoveryAction,
1448 pub actor: Actor,
1450 pub reason: String,
1452 pub rejection: RecoveryRejection,
1454}
1455
1456impl EventPayload for RecoveryRejectedPayload {
1457 const KIND: &'static str = "recovery_rejected";
1458}
1459
1460impl Sample for RecoveryRejectedPayload {
1461 fn sample_full() -> Self {
1462 Self {
1463 action: RecoveryAction::RecoverPark {
1464 clearance_asserted: false,
1465 },
1466 actor: Actor::Operator,
1467 reason: "move the head off the part".to_owned(),
1468 rejection: RecoveryRejection::sample_full(),
1469 }
1470 }
1471}