-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Phase 4 - Device Discovery Framework (Issue #49) #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Implements device discovery functionality as specified in Issue #49. ## New Features ### Device Discovery Interfaces - `IDeviceFinder` - Interface for device discovery mechanisms with async support - `IDeviceInfo` - Interface for discovered device metadata - `DeviceInfo` - Implementation class for device information - `DeviceDiscoveredEventArgs` - Event args for device discovered events - `DeviceType` enum (Unknown, Daqifi, Nyquist) - `ConnectionType` enum (Unknown, WiFi, Serial, Hid) ### WiFi Device Discovery - `WiFiDeviceFinder` - Discovers DAQiFi devices on network using UDP broadcast - UDP broadcast on configurable port (default 30303) - Parses protobuf responses from devices (IP, MAC, port, hostname, serial, firmware) - Network interface enumeration for subnet-directed broadcasts - Timeout and cancellation token support - Event-based discovery notifications (DeviceDiscovered, DiscoveryCompleted) - Duplicate device detection based on MAC address or serial number ### Serial Device Discovery - `SerialDeviceFinder` - Discovers DAQiFi devices connected via USB/Serial ports - Enumerates available serial ports - Configurable baud rate (default 115200) - Async discovery with cancellation support - Note: Full device info retrieval deferred to Phase 6 (Protocol Implementation) ### HID Device Discovery - `HidDeviceFinder` - Framework for bootloader mode device discovery - VendorId: 0x4D8, ProductId: 0x03C - Basic structure in place (full implementation requires HID library dependency) - Note: HID enumeration deferred until HID library is added to core ## Testing - 23 new unit tests covering all discovery functionality - xUnit test framework (matching existing test structure) - Tests for WiFi, Serial, and HID device finders - Tests for DeviceInfo formatting and default values - All tests passing on .NET 8 and .NET 9 - Proper async/await patterns with cancellation token support ## Implementation Notes - Leverages existing `UdpTransport` for WiFi discovery - Leverages existing `SerialStreamTransport.GetAvailablePortNames()` for serial enumeration - Uses existing protobuf message types (`DaqifiOutMessage`) for device discovery responses - Cross-platform compatible (no Windows-specific dependencies) - Follows existing code patterns and architecture from Phase 3 ## Desktop Migration Impact Once deployed, daqifi-desktop can: - Replace `DaqifiDeviceFinder` with `WiFiDeviceFinder` from core - Replace `SerialDeviceFinder` with core implementation - Replace `HidDeviceFinder` with core implementation (when HID support added) - Remove device enumeration logic from desktop ## Related Issues - Closes #49 (Phase 4: Device Discovery Framework) - Part of migration plan documented in DAQIFI_CORE_MIGRATION_PLAN.md - Depends on Phase 3 (Connection Management - UDP transport) - Blocks Phase 5 (Channel Management) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||
…imeout behavior ## Changes ### Concurrency Protection (Importance: 8/10) - Added `SemaphoreSlim` to all three device finders (WiFi, Serial, HID) - Prevents race conditions when multiple threads call `DiscoverAsync()` simultaneously - Ensures only one discovery operation runs at a time per finder instance - Added proper disposal of semaphore in `Dispose()` methods ### Timeout Behavior Fix (Importance: 6/10) - Fixed `WiFiDeviceFinder.DiscoverAsync(CancellationToken)` to use `Timeout.InfiniteTimeSpan` - Previously hardcoded 5-second timeout, now properly respects cancellation token only - Consolidated timeout logic in private `DiscoverAsync(TimeSpan, CancellationToken)` method - Added conditional timeout application: only calls `CancelAfter()` when timeout is not infinite ## Testing - All 23 tests passing on .NET 8.0 and .NET 9.0 - Verified builds successfully ## Qodo PR Review - ✅ Suggestion #1: Add SemaphoreSlim (importance 8/10) - ✅ Suggestion #2: Fix timeout behavior (importance 6/10) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
## Changes ### Feature Status Section - Split features into "✅ Available Now" and "🚧 In Development" - Moved Device Discovery from roadmap to available features - Added Transport Layer and Protocol Buffers to available features - Clarified cross-platform support (.NET 8.0 and 9.0) ### Quick Start Guide - Added practical device discovery code examples - Demonstrated WiFi discovery with event handling - Showed serial device enumeration - Included real output examples for developers ### Advanced Usage - Cancellation token examples for fine-grained control - Custom UDP port configuration - Error handling patterns ### Documentation Additions - Supported device types (Nyquist, DAQiFi, Unknown) - Connection types (WiFi, Serial, HID) - Real-world usage section highlighting daqifi-desktop - Requirements section with firewall/port notes ## Motivation The README was outdated - it listed device discovery as a "roadmap" feature when Phase 4 implementation is now complete. External developers building apps with DAQiFi need clear, accurate documentation showing: - What's available today vs. planned - How to actually use the library - Real code examples they can copy/paste This update provides the practical guidance developers need to integrate DAQiFi devices into their applications. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Removed misleading "DAQiFi vs Nyquist" distinction. There are only two DAQiFi hardware products: Nyquist 1 and Nyquist 3. Both are identified by their part number prefix during discovery. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
…Nyquist3) ## Changes ### DeviceType Enum Update - Changed from generic `Nyquist` and non-existent `Daqifi` types - Updated to specific `Nyquist1` and `Nyquist3` to match actual DAQiFi hardware - Aligns with daqifi-desktop implementation for consistency ### Device Type Detection Logic - Updated `WiFiDeviceFinder.GetDeviceType()` to use exact part number matching - "Nq1" → DeviceType.Nyquist1 - "Nq3" → DeviceType.Nyquist3 - Case-insensitive matching using pattern matching switch - Removed unused "Daq" prefix detection (no such devices exist) ## Motivation The previous enum was inaccurate: 1. **DeviceType.Daqifi** - No devices with "Daq" part number prefix exist 2. **DeviceType.Nyquist** - Too generic, can't distinguish Nyquist 1 vs Nyquist 3 DAQiFi only manufactures two devices: Nyquist 1 and Nyquist 3. Applications may need to handle them differently based on their capabilities, so the enum should reflect the actual hardware models. This matches the proven implementation in daqifi-desktop where DeviceType has been Nyquist1 and Nyquist3 since September 2025. ## Testing - All 215 tests passing on .NET 8.0 and .NET 9.0 - No test changes required (no tests directly referenced enum values) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
## Changes ### Package Updates - Upgraded `Daqifi.Core` from 0.4.1 to 0.5.0 in: - Daqifi.Desktop.IO/Daqifi.Desktop.IO.csproj - Daqifi.Desktop/Daqifi.Desktop.csproj ### Documentation - Added `CORE_0.5.0_UPGRADE.md` with: - Overview of Phase 4 device discovery features - DeviceType enum compatibility notes - Optional integration examples - Migration guidance ## What's New in Core 0.5.0 ### Device Discovery Framework (Phase 4) - `IDeviceFinder` interface with async discovery - `WiFiDeviceFinder` - UDP broadcast discovery (port 30303) - `SerialDeviceFinder` - USB/Serial port enumeration - `HidDeviceFinder` - HID bootloader detection (stub) - `IDeviceInfo` interface for discovered device metadata ### DeviceType Enum Update Core updated enum to match desktop's existing implementation: - `Unknown` (0) - `Nyquist1` (1) - was "Daqifi" in 0.4.1 - `Nyquist3` (2) - was "Nyquist" in 0.4.1 **No breaking changes** - Desktop already uses Nyquist1/Nyquist3. ## Compatibility ✅ **Build successful** - 0 errors related to core upgrade ✅ **No code changes required** - DeviceType enum already compatible ✅ **All desktop functionality preserved** - Fully backward compatible ## Testing - Desktop builds successfully with Core 0.5.0 - Core 0.5.0 has 215/215 tests passing on .NET 8.0 and 9.0 - DeviceType enum values match between core and desktop ## Migration Status Per [DAQIFI_CORE_MIGRATION_PLAN.md](DAQIFI_CORE_MIGRATION_PLAN.md): - ✅ Phase 1: Foundation (Complete) - ✅ Phase 2: Message System (Complete) - ✅ Phase 3: Connection Management (Complete) - ✅ Phase 4: Device Discovery (Complete in core, optional for desktop) - ⏳ Phase 5-7: Pending - ⏳ Phase 8: Full desktop integration (future) ## Optional Integration Desktop can optionally start using Core's device discovery, but this is NOT required. Current desktop device finders continue to work. Full integration is planned for Phase 8. See `CORE_0.5.0_UPGRADE.md` for examples of using Core device discovery. ## References - Core 0.5.0 Release: https://www.nuget.org/packages/Daqifi.Core/0.5.0 - Core Phase 4 PR: daqifi/daqifi-core#54 - Migration Plan: DAQIFI_CORE_MIGRATION_PLAN.md 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
User description
Summary
Implements Phase 4 of the migration plan: Device Discovery Framework as specified in Issue #49.
This PR adds comprehensive device discovery functionality to daqifi-core, enabling discovery of DAQiFi devices via WiFi/UDP, Serial/USB, and HID (bootloader mode).
New Features
🔍 Device Discovery Interfaces
IDeviceFinder- Interface for device discovery mechanisms with async/await and cancellation supportIDeviceInfo- Interface for discovered device metadataDeviceInfo- Concrete implementation with support for WiFi, Serial, and HID devicesDeviceDiscoveredEventArgs- Event args for real-time discovery notificationsDeviceType(Unknown, Daqifi, Nyquist)ConnectionType(Unknown, WiFi, Serial, Hid)📡 WiFi Device Discovery (
WiFiDeviceFinder)DeviceDiscovered,DiscoveryCompleted)🔌 Serial Device Discovery (
SerialDeviceFinder)SerialStreamTransport🛠️ HID Device Discovery (
HidDeviceFinder)Testing
Added 23 new unit tests covering all discovery functionality:
Test Coverage
WiFiDeviceFinderTests- 7 tests covering async discovery, cancellation, events, disposalSerialDeviceFinderTests- 7 tests for serial enumeration and lifecycleHidDeviceFinderTests- 5 tests for HID discovery frameworkDeviceInfoTests- 4 tests for device info formatting and defaultsTest Results
Implementation Details
Leverages Existing Infrastructure
UdpTransportfrom Phase 3 for WiFi discoverySerialStreamTransport.GetAvailablePortNames()for serial enumerationDaqifiOutMessage) for device discovery responsesCross-Platform Compatible
Code Quality
IDisposableDesktop Migration Impact
Once this is deployed to NuGet as Core 0.6.0, daqifi-desktop can migrate:
Before (Desktop):
After (Core):
Desktop Code Reduction
DaqifiDeviceFinder→ replaced withWiFiDeviceFinder(remove ~255 lines)SerialDeviceFinder→ replaced with core implementation (remove ~154 lines)HidDeviceFinder→ replaced with core implementation (remove ~83 lines)Migration Plan Progress
Breaking Changes
None - This is purely additive functionality.
Dependencies
Related Issues
DAQIFI_CORE_MIGRATION_PLAN.mdChecklist
🤖 Generated with Claude Code
PR Type
Enhancement, Tests
Description
Implements Phase 4 device discovery framework with WiFi, Serial, and HID support
Adds
IDeviceFinderinterface and concrete implementations for three connection typesIncludes
DeviceInfoclass and enumerations for device/connection typesProvides 23 comprehensive unit tests covering all discovery mechanisms
Diagram Walkthrough
File Walkthrough
7 files
Device discovery interface with async supportDevice metadata interface and type enumerationsConcrete device information implementationEvent arguments for device discovery notificationsUDP broadcast WiFi device discovery implementationSerial port enumeration device discoveryHID bootloader mode discovery framework4 files
WiFi discovery async and event testsSerial discovery lifecycle and baud rate testsHID discovery framework and disposal testsDevice info formatting and default value tests