use crate::gcode_index::PlannedChange;
use crate::records::{
AcknowledgementDisposition, ActionId, Actor, ChargeKey, ChargeMethod, ChargedFilament,
ClearedMark, FilePosition, InterventionId, InterventionOutcome, LoadedSpool, PendingCharge,
PendingTaken, PolicyDecision, Preflight, PrintAction, PrintOutcome, RecoveryAction,
RecoveryRejection, SpoolCommand, SpoolId, SpoolRecord, UnverifiedReason,
};
use printobserver_printer_api::{Adjustable, JobSnapshot, PrinterSnapshot, PrinterState};
use printobserver_supervisor_api::AgentAssessment;
use printobserver_types::contract::Sample;
use printobserver_types::schemars::JsonSchema;
use printobserver_types::serde::{Deserialize, Serialize};
use printobserver_types::{
EventId, EventKind, EventPayload, EventSource, FileName, PrintId, Timestamp,
};
pub const SYSTEM_SOURCE: &str = "system";
pub const OPERATOR_SOURCE: &str = "operator";
pub const AGENT_SOURCE: &str = "agent";
#[must_use]
pub fn system_source() -> EventSource {
EventSource::new(SYSTEM_SOURCE)
}
#[must_use]
pub fn operator_source() -> EventSource {
EventSource::new(OPERATOR_SOURCE)
}
#[must_use]
pub fn agent_source() -> EventSource {
EventSource::new(AGENT_SOURCE)
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct ActionRequestedPayload {
pub action_id: ActionId,
pub action: PrintAction,
pub actor: Actor,
}
impl EventPayload for ActionRequestedPayload {
const KIND: &'static str = "action_requested";
}
impl Sample for ActionRequestedPayload {
fn sample_full() -> Self {
Self {
action_id: ActionId::sample_full(),
action: PrintAction::sample_full(),
actor: Actor::sample_full(),
}
}
fn sample_minimal() -> Self {
Self {
action: PrintAction::sample_minimal(),
..Self::sample_full()
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct ActionExecutedPayload {
pub action_id: ActionId,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub intervention_id: Option<InterventionId>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub file_position_bytes: Option<i64>,
}
impl EventPayload for ActionExecutedPayload {
const KIND: &'static str = "action_executed";
}
impl Sample for ActionExecutedPayload {
fn sample_full() -> Self {
Self {
action_id: ActionId::sample_full(),
intervention_id: Some(InterventionId::sample_full()),
file_position_bytes: Some(4_096),
}
}
fn sample_minimal() -> Self {
Self {
action_id: ActionId::sample_full(),
intervention_id: None,
file_position_bytes: None,
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct ActionRejectedPayload {
pub action_id: ActionId,
pub decision: PolicyDecision,
}
impl EventPayload for ActionRejectedPayload {
const KIND: &'static str = "action_rejected";
}
impl Sample for ActionRejectedPayload {
fn sample_full() -> Self {
Self {
action_id: ActionId::sample_full(),
decision: PolicyDecision::sample_full(),
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct InterventionExpiredPayload {
pub intervention_id: InterventionId,
pub adjustable: Adjustable,
pub outcome: InterventionOutcome,
}
impl EventPayload for InterventionExpiredPayload {
const KIND: &'static str = "intervention_expired";
}
impl Sample for InterventionExpiredPayload {
fn sample_full() -> Self {
Self {
intervention_id: InterventionId::sample_full(),
adjustable: Adjustable::Feedrate,
outcome: InterventionOutcome::Restored,
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct AgentAssessmentPayload {
pub session_name: String,
pub assessment: AgentAssessment,
}
impl EventPayload for AgentAssessmentPayload {
const KIND: &'static str = "agent_assessment";
}
impl Sample for AgentAssessmentPayload {
fn sample_full() -> Self {
Self {
session_name: "print-0191f0a0".to_owned(),
assessment: AgentAssessment::sample_full(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct AgentStopUnactedPayload {
pub event_id: EventId,
pub session_name: String,
pub summary: String,
}
impl EventPayload for AgentStopUnactedPayload {
const KIND: &'static str = "agent_stop_unacted";
}
impl Sample for AgentStopUnactedPayload {
fn sample_full() -> Self {
Self {
event_id: EventId::sample_full(),
session_name: "print-0191f0a0".to_owned(),
summary: "The part has moved off its planned place.".to_owned(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct OperatorAcknowledgementPayload {
pub acknowledged_event_id: EventId,
pub disposition: AcknowledgementDisposition,
}
impl EventPayload for OperatorAcknowledgementPayload {
const KIND: &'static str = "operator_acknowledgement";
}
impl Sample for OperatorAcknowledgementPayload {
fn sample_full() -> Self {
Self {
acknowledged_event_id: EventId::sample_full(),
disposition: AcknowledgementDisposition::Watch,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct CameraLookPayload {
pub waited_s: u32,
#[serde(default)]
pub delivered: Vec<EventId>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub frame_captured_at: Option<Timestamp>,
}
impl EventPayload for CameraLookPayload {
const KIND: &'static str = "camera_look";
}
impl Sample for CameraLookPayload {
fn sample_full() -> Self {
Self {
waited_s: 60,
delivered: vec![EventId::sample_full()],
frame_captured_at: Some(Timestamp::sample_full()),
}
}
fn sample_minimal() -> Self {
Self {
waited_s: 0,
delivered: Vec::new(),
frame_captured_at: None,
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct PeriodicObservationPayload {
pub interval_s: u64,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub printer: Option<PrinterSnapshot>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub job: Option<JobSnapshot>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub frame_captured_at: Option<Timestamp>,
}
impl EventPayload for PeriodicObservationPayload {
const KIND: &'static str = "periodic_observation";
}
impl Sample for PeriodicObservationPayload {
fn sample_full() -> Self {
Self {
interval_s: 120,
printer: Some(PrinterSnapshot::sample_full()),
job: Some(JobSnapshot::sample_full()),
frame_captured_at: Some(Timestamp::sample_full()),
}
}
fn sample_minimal() -> Self {
Self {
interval_s: 120,
printer: None,
job: None,
frame_captured_at: None,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct CameraRetryPayload {
pub attempt: u32,
pub attempts: u32,
pub status: u16,
pub excerpt: String,
pub backoff_ms: u64,
}
impl EventPayload for CameraRetryPayload {
const KIND: &'static str = "camera_retry";
}
impl Sample for CameraRetryPayload {
fn sample_full() -> Self {
Self {
attempt: 1,
attempts: 4,
status: 500,
excerpt: "exit status 69".to_owned(),
backoff_ms: 500,
}
}
fn sample_minimal() -> Self {
Self {
excerpt: String::new(),
..Self::sample_full()
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(
crate = "printobserver_types::serde",
rename_all = "snake_case",
deny_unknown_fields
)]
#[schemars(crate = "printobserver_types::schemars")]
pub enum FrameCause {
Blank,
Undecodable,
}
impl Sample for FrameCause {
fn sample_full() -> Self {
Self::Blank
}
fn sample_alternates() -> Vec<Self> {
vec![Self::Undecodable]
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct CameraDegradedPayload {
pub attempts: u32,
pub cause: FrameCause,
pub detail: String,
}
impl EventPayload for CameraDegradedPayload {
const KIND: &'static str = "camera_degraded";
}
impl Sample for CameraDegradedPayload {
fn sample_full() -> Self {
Self {
attempts: 3,
cause: FrameCause::Blank,
detail: "every frame was near-uniform grey (grey-level spread 2.1 below 36.5)"
.to_owned(),
}
}
fn sample_alternates() -> Vec<Self> {
vec![Self {
cause: FrameCause::Undecodable,
detail: "every frame failed a strict decode: the image ends early".to_owned(),
..Self::sample_full()
}]
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct GcodeIndexedPayload {
pub file_name: FileName,
pub bytes: u64,
pub layers: u64,
}
impl EventPayload for GcodeIndexedPayload {
const KIND: &'static str = "gcode_indexed";
}
impl Sample for GcodeIndexedPayload {
fn sample_full() -> Self {
Self {
file_name: FileName::sample_full(),
bytes: 440_608,
layers: 150,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(
crate = "printobserver_types::serde",
rename_all = "snake_case",
deny_unknown_fields
)]
#[schemars(crate = "printobserver_types::schemars")]
pub enum PortFailureSite {
PrinterSnapshot,
PrinterJob,
ImageWrite,
SupervisionTurn,
CameraLook,
DetectorAcknowledgement,
DetectorHealthCheck,
DetectorScoringRead,
}
impl Sample for PortFailureSite {
fn sample_full() -> Self {
Self::PrinterSnapshot
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct PortFailurePayload {
pub event_id: EventId,
pub site: PortFailureSite,
pub detail: String,
}
impl EventPayload for PortFailurePayload {
const KIND: &'static str = "port_failure";
}
impl Sample for PortFailurePayload {
fn sample_full() -> Self {
Self {
event_id: EventId::sample_full(),
site: PortFailureSite::sample_full(),
detail: "the printer is unreachable: connection refused".to_owned(),
}
}
}
pub const TIMELINE_KINDS: [&str; 24] = [
PrintStartedPayload::KIND,
PrintEndedPayload::KIND,
FilamentConsumedPayload::KIND,
SpoolRegisteredPayload::KIND,
SpoolLoadedPayload::KIND,
SpoolUnloadedPayload::KIND,
SpoolAdjustedPayload::KIND,
SpoolRetiredPayload::KIND,
SpoolCommandRejectedPayload::KIND,
SpoolUnverifiedPayload::KIND,
FilamentChangeSignalledPayload::KIND,
UnaccountedPrintPayload::KIND,
PreflightCheckedPayload::KIND,
ChargePendedPayload::KIND,
PrintUntrackedPayload::KIND,
FileTallyRebaselinedPayload::KIND,
PrinterConnectionChangedPayload::KIND,
PrinterResetPayload::KIND,
UnattendedPrinterActivityPayload::KIND,
DetectorHealthChangedPayload::KIND,
RecoveryRequestedPayload::KIND,
RecoveryExecutedPayload::KIND,
RecoveryRejectedPayload::KIND,
BedClearAssertedPayload::KIND,
];
fn sample_spool_id() -> SpoolId {
SpoolId::sample_full()
}
fn sample_reason() -> String {
"the spool on the shelf changed".to_owned()
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct PrintStartedPayload {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub file_name: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub started_by: Option<ActionId>,
pub loaded: Vec<LoadedSpool>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub preflight: Option<Preflight>,
}
impl EventPayload for PrintStartedPayload {
const KIND: &'static str = "print_started";
}
impl Sample for PrintStartedPayload {
fn sample_full() -> Self {
Self {
file_name: Some("benchy.gcode".to_owned()),
started_by: Some(ActionId::sample_full()),
loaded: vec![LoadedSpool::sample_full()],
preflight: Some(Preflight::sample_full()),
}
}
fn sample_minimal() -> Self {
Self {
file_name: None,
started_by: None,
loaded: Vec::new(),
preflight: None,
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct PrintEndedPayload {
pub outcome: PrintOutcome,
pub state: PrinterState,
pub reason: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub last_position: Option<FilePosition>,
}
impl EventPayload for PrintEndedPayload {
const KIND: &'static str = "print_ended";
}
impl Sample for PrintEndedPayload {
fn sample_full() -> Self {
Self {
outcome: PrintOutcome::Cancelled,
state: PrinterState::Cancelling,
reason: "the operator cancelled it".to_owned(),
last_position: Some(FilePosition::sample_full()),
}
}
fn sample_minimal() -> Self {
Self {
outcome: PrintOutcome::Completed,
state: PrinterState::Operational,
reason: "finished".to_owned(),
last_position: None,
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct FilamentConsumedPayload {
pub charge_key: ChargeKey,
pub tool: i64,
pub method: ChargeMethod,
pub length_mm: f64,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub charged: Option<ChargedFilament>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub analysed_length_mm: Option<f64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub position: Option<FilePosition>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub note: Option<String>,
}
impl EventPayload for FilamentConsumedPayload {
const KIND: &'static str = "filament_consumed";
}
impl Sample for FilamentConsumedPayload {
fn sample_full() -> Self {
Self {
charge_key: ChargeKey::sample_full(),
tool: 0,
method: ChargeMethod::GcodeExtrusion,
length_mm: 1_000.0,
charged: Some(ChargedFilament::sample_full()),
analysed_length_mm: Some(5_120.0),
position: Some(FilePosition::sample_full()),
note: Some("charged up to the filament change".to_owned()),
}
}
fn sample_minimal() -> Self {
Self {
charge_key: ChargeKey::sample_full(),
tool: 0,
method: ChargeMethod::SlicerEstimate,
length_mm: 5_120.0,
charged: None,
analysed_length_mm: None,
position: None,
note: None,
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct SpoolRegisteredPayload {
pub spool: SpoolRecord,
pub actor: Actor,
pub reason: String,
}
impl EventPayload for SpoolRegisteredPayload {
const KIND: &'static str = "spool_registered";
}
impl Sample for SpoolRegisteredPayload {
fn sample_full() -> Self {
Self {
spool: SpoolRecord::sample_full(),
actor: Actor::Operator,
reason: sample_reason(),
}
}
fn sample_minimal() -> Self {
Self {
spool: SpoolRecord::sample_minimal(),
..Self::sample_full()
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct SpoolLoadedPayload {
pub spool_id: SpoolId,
pub tool: i64,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub replaced: Option<SpoolId>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub took_pending: Vec<PendingTaken>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub cleared_marks: Vec<ClearedMark>,
pub actor: Actor,
pub reason: String,
}
impl EventPayload for SpoolLoadedPayload {
const KIND: &'static str = "spool_loaded";
}
impl Sample for SpoolLoadedPayload {
fn sample_full() -> Self {
Self {
spool_id: sample_spool_id(),
tool: 0,
replaced: Some(ClearedMark::sample_full().spool_id),
took_pending: vec![PendingTaken::sample_full()],
cleared_marks: vec![ClearedMark::sample_full()],
actor: Actor::Operator,
reason: sample_reason(),
}
}
fn sample_minimal() -> Self {
Self {
replaced: None,
took_pending: Vec::new(),
cleared_marks: Vec::new(),
..Self::sample_full()
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct SpoolUnloadedPayload {
pub spool_id: SpoolId,
pub tool: i64,
pub actor: Actor,
pub reason: String,
}
impl EventPayload for SpoolUnloadedPayload {
const KIND: &'static str = "spool_unloaded";
}
impl Sample for SpoolUnloadedPayload {
fn sample_full() -> Self {
Self {
spool_id: sample_spool_id(),
tool: 0,
actor: Actor::Operator,
reason: sample_reason(),
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct SpoolAdjustedPayload {
pub spool_id: SpoolId,
pub remaining_before_g: f64,
pub remaining_after_g: f64,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub gross_g: Option<f64>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub took_pending: Vec<PendingTaken>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub cleared_marks: Vec<ClearedMark>,
pub actor: Actor,
pub reason: String,
}
impl EventPayload for SpoolAdjustedPayload {
const KIND: &'static str = "spool_adjusted";
}
impl Sample for SpoolAdjustedPayload {
fn sample_full() -> Self {
Self {
spool_id: sample_spool_id(),
remaining_before_g: 742.5,
remaining_after_g: 700.0,
gross_g: Some(950.0),
took_pending: vec![PendingTaken::sample_full()],
cleared_marks: vec![ClearedMark {
spool_id: sample_spool_id(),
reason: UnverifiedReason::sample_full(),
}],
actor: Actor::Operator,
reason: sample_reason(),
}
}
fn sample_minimal() -> Self {
Self {
gross_g: None,
took_pending: Vec::new(),
cleared_marks: Vec::new(),
..Self::sample_full()
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct SpoolRetiredPayload {
pub spool_id: SpoolId,
pub remaining_g: f64,
pub actor: Actor,
pub reason: String,
}
impl EventPayload for SpoolRetiredPayload {
const KIND: &'static str = "spool_retired";
}
impl Sample for SpoolRetiredPayload {
fn sample_full() -> Self {
Self {
spool_id: sample_spool_id(),
remaining_g: 12.5,
actor: Actor::Operator,
reason: "the spool is empty".to_owned(),
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct SpoolCommandRejectedPayload {
pub command: SpoolCommand,
pub decision: PolicyDecision,
}
impl EventPayload for SpoolCommandRejectedPayload {
const KIND: &'static str = "spool_command_rejected";
}
impl Sample for SpoolCommandRejectedPayload {
fn sample_full() -> Self {
Self {
command: SpoolCommand::sample_full(),
decision: PolicyDecision::Rejected(crate::records::RejectionReason::SpoolRefused {
cause: crate::records::SpoolRefusalCause::DensityRequired {
spool_id: None,
material: "PEEK".to_owned(),
},
message: "PEEK has no known density, so the spool needs one".to_owned(),
}),
}
}
fn sample_minimal() -> Self {
Self {
command: SpoolCommand::sample_minimal(),
..Self::sample_full()
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct SpoolUnverifiedPayload {
pub spool_id: SpoolId,
pub reason: UnverifiedReason,
}
impl EventPayload for SpoolUnverifiedPayload {
const KIND: &'static str = "spool_unverified";
}
impl Sample for SpoolUnverifiedPayload {
fn sample_full() -> Self {
Self {
spool_id: sample_spool_id(),
reason: UnverifiedReason::sample_full(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct FilamentChangeSignalledPayload {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub tool: Option<i64>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub spool_id: Option<SpoolId>,
pub source_kind: EventKind,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub position: Option<SignalPosition>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub planned_change: Option<u32>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct SignalPosition {
pub position: FilePosition,
pub freshness: PositionFreshness,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", rename_all = "snake_case")]
#[schemars(crate = "printobserver_types::schemars")]
pub enum PositionFreshness {
ReadAtSignal,
LastRecorded,
}
impl EventPayload for FilamentChangeSignalledPayload {
const KIND: &'static str = "filament_change_signalled";
}
impl Sample for FilamentChangeSignalledPayload {
fn sample_full() -> Self {
Self {
tool: Some(0),
spool_id: Some(sample_spool_id()),
source_kind: EventKind::new("obico_printer_notification").expect("a kind name"),
position: Some(SignalPosition {
position: FilePosition::sample_full(),
freshness: PositionFreshness::ReadAtSignal,
}),
planned_change: Some(0),
}
}
fn sample_minimal() -> Self {
Self {
tool: None,
spool_id: None,
position: None,
planned_change: None,
..Self::sample_full()
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", rename_all = "snake_case")]
#[schemars(crate = "printobserver_types::schemars")]
pub enum PlannedChangeTrigger {
Signal,
Position,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(
crate = "printobserver_types::schemars",
transform = crate::gcode_index::null_is_sent
)]
pub struct FilamentChangePlannedReachedPayload {
pub change: PlannedChange,
pub previous_color: Option<String>,
pub trigger: PlannedChangeTrigger,
pub position: FilePosition,
pub spool_id: Option<SpoolId>,
pub next_spool_id: Option<SpoolId>,
pub next_segment_filament_mm: f64,
}
impl EventPayload for FilamentChangePlannedReachedPayload {
const KIND: &'static str = "filament_change_planned_reached";
}
impl Sample for FilamentChangePlannedReachedPayload {
fn sample_full() -> Self {
Self {
change: PlannedChange::sample_full(),
previous_color: Some("#FFFFFF".to_owned()),
trigger: PlannedChangeTrigger::Position,
position: FilePosition::sample_full(),
spool_id: Some(sample_spool_id()),
next_spool_id: Some(sample_spool_id()),
next_segment_filament_mm: 812.4,
}
}
fn sample_alternates() -> Vec<Self> {
vec![Self {
previous_color: None,
trigger: PlannedChangeTrigger::Signal,
spool_id: None,
next_spool_id: None,
..Self::sample_full()
}]
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(
crate = "printobserver_types::schemars",
transform = crate::gcode_index::null_is_sent
)]
pub struct FilamentChangePlannedResumedPayload {
pub change: PlannedChange,
pub previous_color: Option<String>,
pub waited_s: i64,
pub position: FilePosition,
}
impl EventPayload for FilamentChangePlannedResumedPayload {
const KIND: &'static str = "filament_change_planned_resumed";
}
impl Sample for FilamentChangePlannedResumedPayload {
fn sample_full() -> Self {
Self {
change: PlannedChange::sample_full(),
previous_color: Some("#FFFFFF".to_owned()),
waited_s: 412,
position: FilePosition::sample_full(),
}
}
fn sample_alternates() -> Vec<Self> {
vec![Self {
previous_color: None,
..Self::sample_full()
}]
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct UnaccountedPrintPayload {
pub file_name: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub printed_at: Option<Timestamp>,
pub success: bool,
pub charged: bool,
}
impl EventPayload for UnaccountedPrintPayload {
const KIND: &'static str = "unaccounted_print";
}
impl Sample for UnaccountedPrintPayload {
fn sample_full() -> Self {
Self {
file_name: "benchy.gcode".to_owned(),
printed_at: Some(Timestamp::sample_full()),
success: true,
charged: true,
}
}
fn sample_minimal() -> Self {
Self {
printed_at: None,
success: false,
charged: false,
..Self::sample_full()
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct PreflightCheckedPayload {
pub preflight: Preflight,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub action_id: Option<ActionId>,
}
impl EventPayload for PreflightCheckedPayload {
const KIND: &'static str = "preflight_checked";
}
impl Sample for PreflightCheckedPayload {
fn sample_full() -> Self {
Self {
preflight: Preflight::sample_full(),
action_id: Some(ActionId::sample_full()),
}
}
fn sample_minimal() -> Self {
Self {
action_id: None,
..Self::sample_full()
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct ChargePendedPayload {
pub pending: PendingCharge,
}
impl EventPayload for ChargePendedPayload {
const KIND: &'static str = "charge_pended";
}
impl Sample for ChargePendedPayload {
fn sample_full() -> Self {
Self {
pending: PendingCharge::sample_full(),
}
}
fn sample_minimal() -> Self {
Self {
pending: PendingCharge::sample_minimal(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct PrintUntrackedPayload {
pub reason: String,
}
impl EventPayload for PrintUntrackedPayload {
const KIND: &'static str = "print_untracked";
}
impl Sample for PrintUntrackedPayload {
fn sample_full() -> Self {
Self {
reason: "the print was already running when spool tracking was installed".to_owned(),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", rename_all = "snake_case")]
#[schemars(crate = "printobserver_types::schemars")]
pub enum RebaselineDisposition {
Accounted,
Unverified,
}
impl Sample for RebaselineDisposition {
fn sample_full() -> Self {
Self::Unverified
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct FileTallyRebaselinedPayload {
pub file_name: String,
pub origin: String,
pub old_generation: u32,
pub new_generation: u32,
pub old_successes: i64,
pub old_failures: i64,
pub new_successes: i64,
pub new_failures: i64,
pub disposition: RebaselineDisposition,
}
impl EventPayload for FileTallyRebaselinedPayload {
const KIND: &'static str = "file_tally_rebaselined";
}
impl Sample for FileTallyRebaselinedPayload {
fn sample_full() -> Self {
Self {
file_name: "benchy.gcode".to_owned(),
origin: "local".to_owned(),
old_generation: 0,
new_generation: 1,
old_successes: 5,
old_failures: 1,
new_successes: 1,
new_failures: 0,
disposition: RebaselineDisposition::Unverified,
}
}
fn sample_alternates() -> Vec<Self> {
vec![Self {
disposition: RebaselineDisposition::Accounted,
..Self::sample_full()
}]
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct PrinterConnectionChangedPayload {
pub from: PrinterState,
pub to: PrinterState,
pub detail: String,
}
impl EventPayload for PrinterConnectionChangedPayload {
const KIND: &'static str = "printer_connection_changed";
}
impl Sample for PrinterConnectionChangedPayload {
fn sample_full() -> Self {
Self {
from: PrinterState::Printing,
to: PrinterState::Offline,
detail: "the printer reports Offline after error: SerialTimeoutException: ".to_owned(),
}
}
fn sample_alternates() -> Vec<Self> {
vec![Self {
from: PrinterState::Offline,
to: PrinterState::Operational,
detail: "the printer reports Operational".to_owned(),
}]
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct PrinterResetPayload {
#[serde(default)]
pub during_print: Option<PrintId>,
pub detail: String,
}
impl EventPayload for PrinterResetPayload {
const KIND: &'static str = "printer_reset";
}
impl Sample for PrinterResetPayload {
fn sample_full() -> Self {
Self {
during_print: Some(PrintId::sample_full()),
detail: "the printer pushed a reset".to_owned(),
}
}
fn sample_minimal() -> Self {
Self {
during_print: None,
detail: "the printer pushed a reset".to_owned(),
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct HeatedTool {
pub tool: i64,
pub target_c: f64,
}
impl Sample for HeatedTool {
fn sample_full() -> Self {
Self {
tool: 0,
target_c: 215.0,
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct UnattendedPrinterActivityPayload {
pub last_print_id: PrintId,
pub tools: Vec<HeatedTool>,
#[serde(default)]
pub bed_target_c: Option<f64>,
#[serde(default)]
pub moved: Option<bool>,
pub detail: String,
}
impl EventPayload for UnattendedPrinterActivityPayload {
const KIND: &'static str = "unattended_printer_activity";
}
impl Sample for UnattendedPrinterActivityPayload {
fn sample_full() -> Self {
Self {
last_print_id: PrintId::sample_full(),
tools: vec![HeatedTool::sample_full()],
bed_target_c: Some(60.0),
moved: Some(true),
detail: "tool 0 is heating to 215 °C with no job running".to_owned(),
}
}
fn sample_minimal() -> Self {
Self {
last_print_id: PrintId::sample_full(),
tools: Vec::new(),
bed_target_c: None,
moved: None,
detail: "the print head moved with no job running".to_owned(),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(
crate = "printobserver_types::serde",
rename_all = "snake_case",
deny_unknown_fields
)]
#[schemars(crate = "printobserver_types::schemars")]
pub enum DetectorStatus {
Available,
Unavailable,
}
impl Sample for DetectorStatus {
fn sample_full() -> Self {
Self::Unavailable
}
fn sample_alternates() -> Vec<Self> {
vec![Self::Available]
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct DetectorHealthChangedPayload {
pub status: DetectorStatus,
pub detail: String,
}
impl EventPayload for DetectorHealthChangedPayload {
const KIND: &'static str = "detector_health_changed";
}
impl Sample for DetectorHealthChangedPayload {
fn sample_full() -> Self {
Self {
status: DetectorStatus::Unavailable,
detail: "the detector's health check answered 503".to_owned(),
}
}
fn sample_alternates() -> Vec<Self> {
vec![Self {
status: DetectorStatus::Available,
detail: "the detector's health check answered 200".to_owned(),
}]
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct RecoveryRequestedPayload {
pub action: RecoveryAction,
pub actor: Actor,
pub reason: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub bed_clear: Option<EventId>,
}
impl EventPayload for RecoveryRequestedPayload {
const KIND: &'static str = "recovery_requested";
}
impl Sample for RecoveryRequestedPayload {
fn sample_full() -> Self {
Self {
action: RecoveryAction::sample_full(),
actor: Actor::Operator,
reason: "free the nozzle from the part".to_owned(),
bed_clear: Some(EventId::sample_full()),
}
}
fn sample_minimal() -> Self {
Self {
bed_clear: None,
..Self::sample_full()
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct RecoveryExecutedPayload {
pub action: RecoveryAction,
pub actor: Actor,
pub reason: String,
pub outcome: crate::records::ExecutionOutcome,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub bed_clear: Option<EventId>,
}
impl EventPayload for RecoveryExecutedPayload {
const KIND: &'static str = "recovery_executed";
}
impl Sample for RecoveryExecutedPayload {
fn sample_full() -> Self {
Self {
action: RecoveryAction::RecoverLift { mm: 10.0 },
actor: Actor::Operator,
reason: "free the nozzle from the part".to_owned(),
outcome: crate::records::ExecutionOutcome::Succeeded,
bed_clear: Some(EventId::sample_full()),
}
}
fn sample_minimal() -> Self {
Self {
bed_clear: None,
..Self::sample_full()
}
}
fn sample_alternates() -> Vec<Self> {
vec![Self {
outcome: crate::records::ExecutionOutcome::Failed {
reason: "the printer is unreachable: connection refused".to_owned(),
},
..Self::sample_full()
}]
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct RecoveryRejectedPayload {
pub action: RecoveryAction,
pub actor: Actor,
pub reason: String,
pub rejection: RecoveryRejection,
}
impl EventPayload for RecoveryRejectedPayload {
const KIND: &'static str = "recovery_rejected";
}
impl Sample for RecoveryRejectedPayload {
fn sample_full() -> Self {
Self {
action: RecoveryAction::RecoverPark {
clearance_asserted: false,
},
actor: Actor::Operator,
reason: "move the head off the part".to_owned(),
rejection: RecoveryRejection::sample_full(),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
#[schemars(crate = "printobserver_types::schemars")]
pub struct BedClearAssertedPayload {
pub actor: BedClearActor,
pub reason: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(crate = "printobserver_types::serde", rename_all = "snake_case")]
#[schemars(crate = "printobserver_types::schemars")]
pub enum BedClearActor {
Operator,
}
impl BedClearActor {
#[must_use]
pub const fn actor(self) -> Actor {
match self {
Self::Operator => Actor::Operator,
}
}
}
impl EventPayload for BedClearAssertedPayload {
const KIND: &'static str = "bed_clear_asserted";
}
impl Sample for BedClearAssertedPayload {
fn sample_full() -> Self {
Self {
actor: BedClearActor::Operator,
reason: "the cancelled print is off the bed and nothing else is on it".to_owned(),
}
}
}