# physical-event > 物理デバイスからのイベントを統一的に処理するためのスキルセット - Author: Mako - Repository: chronista-club/unison - Version: 20251216220509 - Stars: 3 - Forks: 0 - Last Updated: 2026-02-08 - Source: https://github.com/chronista-club/unison - Web: https://mule.run/skillshub/@@chronista-club/unison~physical-event:20251216220509 --- --- title: Physical Event Skills description: 物理デバイスからのイベントを統一的に処理するためのスキルセット version: 1.0.0 author: Vantage Hub Contributors created_at: 2025-11-02 updated_at: 2025-11-02 tags: - physical-event - iot - hardware - gpio - usb - serial - network-discovery - event-driven - sensors - embedded categories: - skill - hardware-integration - event-processing --- # Physical Event Skills 物理デバイスからのイベントを統一的に処理し、Vantage Hubシステムと連携させるためのスキルセットです。 ## 概要 Physical Event Systemは、GPIO、USB、シリアル通信、ネットワークデバイスなど、様々な物理デバイスからのイベントを統一的なインターフェースで扱うためのシステムです。イベント駆動アーキテクチャにより、リアルタイムで効率的なイベント処理を実現します。 ## 主要コンポーネント ### 1. Event Manager すべてのイベントソースとハンドラーを統合管理する中央コンポーネント。 ### 2. Event Bus 非同期でイベントを配信するメッセージングシステム。 ### 3. Event Sources - **GPIO**: ピン状態の変化を監視 - **USB**: デバイスの接続/切断を検出 - **Serial**: シリアルポートからのデータ受信 - **Network**: mDNSによるデバイス発見 ### 4. Event Handlers イベントを受信して処理するコンポーネント。 ## クイックスタート ### 基本的な使用例 ```rust use physical_event::{PhysicalEventManager, EventBus, Config}; #[tokio::main] async fn main() -> Result<()> { // 設定を作成 let config = Config::default(); // イベントバスを作成 let event_bus = EventBus::new(config.event_bus)?; // マネージャーを作成 let mut manager = PhysicalEventManager::new( Arc::new(event_bus), config )?; // ハンドラーを登録 manager.register_handler(Box::new(LoggerHandler::new())).await?; // 開始 manager.start().await?; Ok(()) } ``` ### GPIO監視の設定 ```rust #[cfg(feature = "gpio")] use physical_event::gpio::GpioEventSource; let gpio_source = GpioEventSource::builder() .id("door_sensor") .pins(vec![17, 27]) .debounce_ms(50) .build()?; manager.register_source(Box::new(gpio_source)).await?; ``` ## サポートするイベントタイプ ### 1. GPIOイベント - ピンの状態変化(HIGH/LOW) - エッジ検出(立ち上がり/立ち下がり) ### 2. USBイベント - デバイス接続 - デバイス切断 - ベンダーID/プロダクトIDによる識別 ### 3. シリアル通信イベント - データ受信 - 設定可能なバッファサイズ - 複数のポート同時監視 ### 4. ネットワークイベント - mDNSデバイス発見 - サービスタイプ別の検出 - デバイスの消失検出 ### 5. カスタムイベント - 任意のJSONデータ - カテゴリ別の分類 - 拡張可能なメタデータ ## いつ使うか ### Physical Eventが適している場合 ✅ **IoTデバイスの統合** - センサーデータの収集 - アクチュエータの制御 - デバイス状態の監視 ✅ **ホームオートメーション** - ドア/窓センサー - 温度/湿度センサー - モーション検知 ✅ **産業用アプリケーション** - 機器の状態監視 - アラーム検知 - データ収集 ✅ **プロトタイピング** - ハードウェアの動作検証 - センサーデータの可視化 - リアルタイムモニタリング ## 実装パターン ### フィルタリング ```rust let filter = EventFilter::new() .with_sources(vec!["gpio".to_string()]) .with_time_range(Some(start_time), None); ``` ### バッチ処理 ```rust let batch_handler = BatchHandler::new( 100, // バッチサイズ Duration::from_secs(1), // タイムアウト |events| process_batch(events) ); ``` ### エラーハンドリング ```rust let retry_handler = RetryHandler::new( inner_handler, 3, // 最大リトライ回数 Duration::from_millis(100) // リトライ間隔 ); ``` ## トラブルシューティング ### よくある問題 **権限エラー** ```bash # GPIO権限の問題 sudo usermod -a -G gpio $USER # ログアウト後に再ログイン ``` **デバイスが見つからない** ```bash # デバッグログを有効化 RUST_LOG=physical_event=debug cargo run # 利用可能なデバイスをリスト ls /dev/tty* # シリアルポート lsusb # USBデバイス ``` **イベントの欠落** - バッファサイズを増やす - 処理時間を最適化 - 非同期処理を活用 ## パフォーマンス考慮事項 ### 1. イベントレート - 高頻度のイベントはバッチ処理 - 適切なデバウンス設定 - バッファサイズの調整 ### 2. リソース使用 - CPUとメモリの監視 - 並行処理の最適化 - イベントフィルタリング ### 3. レイテンシ - リアルタイム要件の確認 - 処理優先度の設定 - 非同期処理の活用 ## セキュリティ - イベントソースの認証 - 機密データの暗号化 - アクセス制御の実装 - 監査ログの記録 ## 関連ドキュメント - [Physical Event仕様書](../../docs/specs/physical-event/README.md) - [イベント定義詳細](../../docs/specs/physical-event/event-definitions.md) - [アーキテクチャガイド](../../docs/specs/physical-event/architecture-guide.md) - [実装ガイド](../../docs/specs/physical-event/implementation-guide.md) - [APIリファレンス](../../docs/specs/physical-event/api-reference.md) ## 参考資料 ### ハードウェア関連 - [Raspberry Pi GPIO Documentation](https://www.raspberrypi.org/documentation/usage/gpio/) - [USB.org Specifications](https://www.usb.org/documents) - [Serial Programming Guide](https://www.cmrr.umn.edu/~strupp/serial.html) ### Rustライブラリ - [rppal - Raspberry Pi Peripheral Access Library](https://github.com/golemparts/rppal) - [rusb - Rust USB Library](https://github.com/a1ien/rusb) - [serialport-rs](https://github.com/serialport/serialport-rs) - [mdns - Multicast DNS Library](https://github.com/dylanmckay/mdns) ### イベント駆動アーキテクチャ - [Event Sourcing Pattern](https://martinfowler.com/eaaDev/EventSourcing.html) - [Reactive Manifesto](https://www.reactivemanifesto.org/) - [CloudEvents Specification](https://cloudevents.io/)