Expand description
§mabi-scenario
Scenario engine for the OTSIM protocol simulator.
This crate provides:
- Scenario definition and parsing (YAML/JSON)
- Pattern generators (Sine, Ramp, Step, Random, Follow, Replay)
- Scenario player with time scaling
- Event triggers and conditions
- Comprehensive schema validation
- Industrial scenario templates
§Architecture
┌─────────────────────────────────────────────────────────────┐
│ Scenario Engine │
│ (Parser, Validator, Player, Event Manager) │
└─────────────────────────────────────────────────────────────┘
│
┌──────────────────┼──────────────────┐
▼ ▼ ▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Patterns │ │ Events │ │ Templates │
│ (Generator) │ │ (Triggers/Acts) │ │ (Industrial) │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│ │
▼ ▼
┌─────────────────┐ ┌─────────────────┐
│ Follow/Replay │ │ Validation │
│ (Advanced) │ │ (Schema Check) │
└─────────────────┘ └─────────────────┘§Quick Start
ⓘ
use mabi_scenario::prelude::*;
// Load scenario from file
let scenario = ScenarioParser::parse_file("scenario.yaml")?;
// Validate
let validator = ScenarioValidator::new();
let result = validator.validate(&scenario);
if !result.is_valid() {
for error in result.errors() {
eprintln!("{}: {}", error.path, error.message);
}
}
// Create player and run
let mut player = ScenarioPlayer::new(scenario, PlayerConfig::default());
let mut rx = player.subscribe();
tokio::spawn(async move {
player.run().await;
});
// Process updates
while let Ok(update) = rx.recv().await {
println!("{}: {}", update.point_id, update.value);
}Re-exports§
pub use generator::PatternGenerator;pub use generator::PatternType;pub use parser::ScenarioParser;pub use player::PlayerConfig;pub use player::ScenarioPlayer;pub use schema::Scenario;pub use schema::ScenarioEvent;pub use schema::ScenarioPoint;
Modules§
- bacnet_
templates - BACnet-specific scenario templates.
- event
- Event system with triggers and actions.
- executor
- Scenario Executor - Bridge between scenario player and devices.
- follow
- Follow pattern implementation with source tracking and delay buffer.
- generator
- Pattern generators for scenario simulation.
- parser
- Scenario parser.
- player
- Scenario player.
- prelude
- replay
- Replay pattern implementation with file parsing and interpolation.
- schema
- Scenario schema definitions.
- templates
- Industrial scenario templates.
- validation
- Comprehensive schema validation for scenarios.
Enums§
- Scenario
Error - Scenario error types.
Type Aliases§
- Scenario
Result - Scenario result type.