Skip to content

Latest commit

 

History

History
509 lines (363 loc) · 22.1 KB

File metadata and controls

509 lines (363 loc) · 22.1 KB

OpenAstroFirmware Architectural Design Specification

Document Version: 1.0
Date: August 2, 2025
Project: OpenAstroFirmware - Zephyr RTOS-based Telescope Mount Control System
Requirements Reference: specs/requirements.md

1. INTRODUCTION

1.1 Purpose

This document defines the high-level architectural design for OpenAstroFirmware, establishing the fundamental system structure, architectural patterns, and design principles that guide the implementation of requirements specified in the OpenAstroFirmware Requirements Specification.

1.2 Architectural Philosophy

The OpenAstroFirmware architecture is founded on the following core principles:

  • Layered Architecture: Clear separation of concerns through well-defined abstraction layers
  • Modular Design: Loosely coupled, highly cohesive components with standardized interfaces
  • Hardware Abstraction: Platform-independent core logic with pluggable hardware drivers
  • Real-time Determinism: Predictable timing behavior for tracking and control operations
  • Extensibility by Design: Plugin-based architecture supporting future expansion
  • Safety-First Approach: Fail-safe mechanisms and comprehensive error handling integrated at all levels

1.3 Document Scope

This document presents the architectural view of the system, focusing on:

  • System decomposition and component relationships
  • Architectural patterns and design decisions
  • Data flow and control flow architectures
  • Interface specifications and contracts
  • Concurrency and threading models
  • Extensibility mechanisms and plugin architectures

2. ARCHITECTURAL OVERVIEW

2.1 System Architecture Pattern

OpenAstroFirmware employs a Multi-Layered Service-Oriented Architecture with the following characteristics:

┌─────────────────────────────────────────────────────────────┐
│                    PRESENTATION LAYER                       │
│   External Protocols │ User Interfaces │ Network Services   │
├─────────────────────────────────────────────────────────────┤
│                     APPLICATION LAYER                       │
│  Command Processing │ State Management │ Event Coordination │
├─────────────────────────────────────────────────────────────┤
│                      SERVICE LAYER                          │
│   Mount Control   │   Sensor Mgmt   │   Config Service      │
├─────────────────────────────────────────────────────────────┤
│                       CORE LAYER                            │
│   Tracking Engine │ Safety Monitor │ Hardware Controllers   │
├─────────────────────────────────────────────────────────────┤
│                 HARDWARE ABSTRACTION LAYER                  │
│    Driver Interface   │   Device Abstraction   │  Platform  │
├─────────────────────────────────────────────────────────────┤
│                     PLATFORM LAYER                          │
│           Zephyr RTOS │ Hardware Platform │ BSP             │
└─────────────────────────────────────────────────────────────┘

Layer Responsibilities:

  1. Presentation Layer: External communication interfaces and user interaction
  2. Application Layer: System orchestration and global state management
  3. Service Layer: Domain-specific business logic and high-level services
  4. Core Layer: Real-time operations and fundamental system capabilities
  5. Hardware Abstraction Layer: Platform-independent hardware access
  6. Platform Layer: Zephyr RTOS and hardware-specific implementations

Architectural Characteristics:

  • Unidirectional Dependencies: Higher layers depend only on lower layers
  • Interface-Based Communication: Well-defined contracts between layers
  • Plugin Integration Points: Extensibility mechanisms at each layer
  • Service Composition: Complex operations built from simpler services

Addresses Requirements: REQ-EXT-001, REQ-HW-EXT-001, REQ-STEP-EXT-001, REQ-SNS-EXT-001

2.2 Architectural Drivers

The architecture is shaped by the following key requirements and constraints:

Performance Drivers (REQ-PERF-001 to REQ-PERF-007):

  • Sub-arcsecond tracking precision
  • 100ms command response time
  • Real-time deterministic behavior
  • Concurrent multi-axis operations

Extensibility Drivers (REQ-EXT-001 to REQ-EXT-012):

  • Support for multiple hardware platforms
  • Plugin-based driver architecture
  • Future feature expansion capability

Safety and Reliability Drivers (REQ-SAF-001 to REQ-REL-007):

  • Fail-safe operation modes
  • Comprehensive error handling
  • System state consistency
  • Hardware protection mechanisms

Integration Drivers (REQ-COMPAT-001 to REQ-COMPAT-008):

  • LX200 protocol compliance
  • Multiple astronomy software compatibility
  • Legacy hardware support

3. LAYER-BY-LAYER ARCHITECTURAL DESIGN

3.1 Presentation Layer Architecture

Addresses Requirements: REQ-COM-001 to REQ-COM-024, REQ-WEB-001 to REQ-WEB-008, REQ-UI-001 to REQ-UI-003

The presentation layer provides external interfaces and manages all communication with external systems and users.

3.1.1 Protocol Handlers Subsystem

  • LX200 Protocol Engine: Stateless command parser and response generator
  • Network Protocol Stack: HTTP/WebSocket services for web-based control
  • Extension Protocol Framework: Pluggable protocol support for future additions

3.1.2 User Interface Subsystem

  • Display Abstraction: Unified interface for various display technologies
  • Input Device Framework: Event-driven input handling with device abstraction
  • UI State Management: Screen navigation and context preservation

3.1.3 Design Patterns

  • Command Pattern: LX200 commands as executable objects
  • Observer Pattern: UI updates driven by system state changes
  • Adapter Pattern: Protocol-specific adapters for unified internal interfaces

3.2 Application Layer Architecture

Addresses Requirements: REQ-COM-007, REQ-MON-001, REQ-CFG-005 to REQ-CFG-008

The application layer orchestrates system behavior and maintains global state.

3.2.1 Command Processing Subsystem

  • Command Queue Manager: Asynchronous command processing with priority handling
  • State Machine Controller: Global system state management and transitions
  • Event Dispatcher: Centralized event routing and handling

3.2.2 System Coordination Subsystem

  • Resource Manager: Coordinate access to shared system resources
  • Configuration Coordinator: Runtime configuration management and persistence
  • Diagnostics Engine: System health monitoring and reporting

3.2.3 Design Patterns

  • State Pattern: System behavior changes based on operational states
  • Mediator Pattern: Component communication through central coordinator
  • Chain of Responsibility: Command processing pipeline

3.3 Service Layer Architecture

Addresses Requirements: REQ-MNT-001 to REQ-MNT-012, REQ-TRK-001 to REQ-COORD-005, REQ-CFG-001 to REQ-NVM-008

The service layer provides high-level domain services and business logic.

3.3.1 Mount Control Service

  • Coordinate Transformation Engine: Celestial to mechanical coordinate conversion
  • Motion Planning Service: Trajectory calculation and optimization
  • Position Management Service: Current position tracking and synchronization

3.3.2 Tracking Service

  • Tracking Rate Calculator: Sidereal, solar, and lunar rate computation
  • Guiding Correction Engine: Precision adjustment processing
  • Time and Location Service: Astronomical time calculations

3.3.3 Configuration Service

  • Persistent Settings Manager: Non-volatile memory management
  • Configuration Validation Engine: Settings validation and migration
  • Backup and Restore Service: Configuration data protection

3.3.4 Design Patterns

  • Strategy Pattern: Different tracking algorithms and mount types
  • Template Method: Common configuration management patterns
  • Facade Pattern: Simplified interfaces to complex subsystems

3.4 Core Layer Architecture

Addresses Requirements: REQ-STEP-001 to REQ-STEP-018, REQ-SNS-001 to REQ-SNS-006, REQ-SAF-001 to REQ-SAF-005

The core layer implements fundamental system capabilities and real-time operations.

3.4.1 Motion Control Subsystem

  • Stepper Motor Controller: Abstract motor control with driver plugins
  • Axis Control Engine: Independent RA/DEC axis management
  • Motion Synchronization Service: Coordinated multi-axis movements

3.4.2 Sensor Management Subsystem

  • Sensor Data Pipeline: Unified sensor reading and processing
  • Sensor Fusion Engine: Multi-sensor data integration
  • Calibration Management: Sensor-specific calibration procedures

3.4.3 Safety Monitoring Subsystem

  • Limit Enforcement Engine: Software and hardware limit checking
  • Emergency Stop Controller: Immediate motion cessation capability
  • System Health Monitor: Continuous system status evaluation

3.4.4 Design Patterns

  • Factory Pattern: Driver instantiation based on configuration
  • Observer Pattern: Sensor data distribution to interested components
  • Proxy Pattern: Safety checks intercept motion commands

3.5 Hardware Abstraction Layer Architecture

Addresses Requirements: REQ-HW-EXT-001 to REQ-HW-EXT-004, REQ-STEP-EXT-001 to REQ-STEP-EXT-005, REQ-SNS-EXT-001 to REQ-SNS-EXT-006

The HAL provides a consistent interface to diverse hardware platforms and devices.

3.5.1 Driver Framework

  • Device Driver Interface: Standardized contract for all hardware drivers
  • Driver Registry: Dynamic driver discovery and registration
  • Hardware Abstraction Interface: Platform-independent hardware access

3.5.2 Platform Abstraction

  • Board Support Framework: Hardware-specific initialization and configuration
  • Peripheral Access Layer: Unified interface to MCU peripherals
  • Device Tree Integration: Zephyr device tree utilization for hardware description

3.5.3 Design Patterns

  • Abstract Factory: Platform-specific driver creation
  • Bridge Pattern: Separation of hardware interface from implementation
  • Plugin Architecture: Runtime driver loading and registration

4. CONCURRENCY AND THREADING ARCHITECTURE

Addresses Requirements: REQ-PERF-004, REQ-PERF-007, REQ-STEP-004

4.1 Threading Model

The system employs a Priority-Based Multi-Threading Architecture with clear thread responsibilities:

Thread Hierarchy and Communication:
┌─────────────────┬─────────────────┬─────────────────┬──────────────┐
│  Safety Thread  │ Tracking Thread │ Control Thread  │ Comms Thread │
│ (Highest Prio)  │  (High Prio)    │ (Medium Prio)   │ (Low Prio)   │
├─────────────────┼─────────────────┼─────────────────┼──────────────┤
│ • Limit Checks  │ • Sidereal      │ • Command Exec  │ • LX200      │
│ • Emergency Stop│ • Position      │ • State Mgmt    │ • Network    │
│ • Health Monitor│ • Rate Calc     │ • Coordination  │ • UI Updates │
└─────────────────┴─────────────────┴─────────────────┴──────────────┘

4.2 Inter-Thread Communication Patterns

4.2.1 Message Passing Architecture

  • Lock-Free Queues: High-performance thread communication
  • Event Broadcasting: Publish-subscribe event distribution
  • Shared Memory Protection: Mutex-protected critical sections

4.2.2 Synchronization Strategy

  • Priority Inheritance: Prevention of priority inversion
  • Timeout-Based Operations: Deadlock prevention mechanisms
  • Atomic Operations: Lock-free data access where possible

4.3 Real-Time Constraints Management

  • Deterministic Scheduling: Predictable thread execution patterns
  • Interrupt Service Isolation: Minimal ISR processing with deferred work
  • Memory Pool Allocation: Predictable memory allocation patterns

5. DATA ARCHITECTURE AND INFORMATION FLOW

Addresses Requirements: REQ-COM-006, REQ-COORD-001 to REQ-COORD-005, REQ-NVM-001 to REQ-NVM-008

5.1 Data Flow Architecture

The system processes information through well-defined data pipelines:

External Data Flow:
Commands → Parser → Validator → Executor → Response Generator → Output

Internal Data Flow:
Sensors → Filter → Transform → State Update → Event Broadcast → Actions

5.2 Data Management Patterns

5.2.1 Configuration Data Architecture

  • Hierarchical Configuration: Layered settings with inheritance
  • Versioned Data Structures: Backward compatibility and migration
  • Atomic Updates: Transaction-like configuration changes

5.2.2 Sensor Data Architecture

  • Pipeline Processing: Staged data transformation and filtering
  • Temporal Data Handling: Time-series data management
  • Data Fusion Patterns: Multi-source data integration

5.2.3 State Management Architecture

  • Centralized State Store: Single source of truth for system state
  • State Change Notifications: Event-driven state propagation
  • State Persistence: Critical state preservation across power cycles

5.3 Memory Architecture

  • Memory Pool Strategy: Fixed-size pools for predictable allocation
  • Buffer Management: Circular buffers for streaming data
  • Stack Management: Per-thread stack monitoring and protection

6. EXTENSIBILITY ARCHITECTURE

Addresses Requirements: REQ-EXT-001 to REQ-EXT-012, REQ-HW-EXT-001 to REQ-HW-EXT-004

6.1 Plugin Architecture Framework

The system supports extensibility through a comprehensive plugin architecture:

6.1.1 Driver Plugin System

  • Standardized Driver Interface: Common contract for all hardware drivers
  • Dynamic Driver Discovery: Runtime detection and registration
  • Driver Capability Reporting: Self-describing driver capabilities

6.1.2 Protocol Extension Framework

  • Protocol Handler Registration: Runtime protocol addition
  • Command Extension Points: New command family integration
  • Response Format Extensibility: Custom response format support

6.1.3 Feature Plugin Architecture

  • Service Plugin Interface: High-level feature additions
  • Hook Points: Integration points throughout the system
  • Dependency Management: Plugin dependency resolution

6.2 Configuration-Driven Architecture

  • Feature Flags: Runtime feature enabling/disabling
  • Hardware Capability Detection: Automatic feature adaptation
  • Compilation Variants: Build-time feature selection

6.3 Future-Proofing Strategies

  • Abstract Interface Design: Interfaces designed for extensibility
  • Versioning Strategy: Forward and backward compatibility planning
  • Migration Framework: Automated upgrade path provision

7. SAFETY AND RELIABILITY ARCHITECTURE

Addresses Requirements: REQ-SAF-001 to REQ-SAF-005, REQ-REL-001 to REQ-REL-007

7.1 Safety-by-Design Architecture

7.1.1 Layered Safety Model

  • Hardware Safety Layer: Physical limit switches and emergency stops
  • Software Safety Layer: Algorithmic limit checking and validation
  • Protocol Safety Layer: Command validation and confirmation

7.1.2 Fail-Safe Architecture

  • Safe State Definition: Well-defined safe system states
  • Graceful Degradation: Reduced functionality under fault conditions
  • Recovery Procedures: Automatic and manual recovery mechanisms

7.2 Error Handling Architecture

7.2.1 Hierarchical Error Handling

  • Local Error Handling: Component-level error management
  • Service-Level Error Handling: Cross-component error coordination
  • System-Level Error Handling: Global error management and recovery

7.2.2 Error Propagation Patterns

  • Error Code Propagation: Structured error information flow
  • Exception Safety: Resource management under error conditions
  • Error Event Broadcasting: System-wide error notification

7.3 Reliability Patterns

  • Watchdog Architecture: Multi-level system monitoring
  • Health Check Framework: Continuous system health assessment
  • Redundancy Patterns: Critical path redundancy where feasible

8. PERFORMANCE ARCHITECTURE

Addresses Requirements: REQ-PERF-001 to REQ-PERF-007

8.1 Real-Time Performance Architecture

8.1.1 Timing Architecture

  • Deterministic Execution Paths: Predictable timing behavior
  • Priority-Based Scheduling: Critical task prioritization
  • Interrupt Management: Minimal interrupt latency patterns

8.1.2 Resource Management Architecture

  • Memory Pool Strategy: Predictable memory allocation
  • CPU Usage Monitoring: Resource utilization tracking
  • Resource Contention Resolution: Fair resource access patterns

8.2 Optimization Strategies

  • Algorithm Selection: Performance-appropriate algorithm choices
  • Caching Architecture: Strategic data caching for performance
  • Lazy Evaluation: Deferred computation where appropriate

9. INTEGRATION ARCHITECTURE

Addresses Requirements: REQ-COMPAT-001 to REQ-COMPAT-008, REQ-COMP-001 to REQ-COMP-003

9.1 External System Integration

9.1.1 Astronomy Software Integration

  • Standard Protocol Compliance: Full LX200 protocol implementation
  • Extension Protocol Support: Enhanced functionality while maintaining compatibility
  • Multiple Client Support: Concurrent connection handling

9.1.2 Hardware Integration Patterns

  • Legacy Hardware Support: Backward compatibility with existing hardware
  • Modern Hardware Exploitation: Advanced feature utilization
  • Cross-Platform Compatibility: Consistent behavior across platforms

9.2 Standards Compliance Architecture

  • Protocol Compliance Framework: Automated compliance verification
  • Testing Architecture: Comprehensive compatibility testing
  • Certification Support: Standards compliance documentation

10. DEPLOYMENT AND CONFIGURATION ARCHITECTURE

Addresses Requirements: REQ-FW-BUILD-001 to REQ-UX-005, REQ-CFG-001 to REQ-CFG-004

10.1 Build and Deployment Architecture

10.1.1 Multi-Target Build System

  • Platform Abstraction: Single codebase, multiple targets
  • Feature Configuration: Compile-time feature selection
  • Automated Build Pipeline: Continuous integration and deployment

10.1.2 Firmware Distribution Architecture

  • Secure Update Mechanism: Signed firmware with verification
  • Rollback Capability: Safe update with recovery options
  • Configuration Preservation: Settings maintained across updates

10.2 Runtime Configuration Architecture

  • Hierarchical Configuration: Multiple configuration layers
  • Dynamic Reconfiguration: Runtime setting changes
  • Configuration Validation: Settings verification and migration

11. ARCHITECTURAL DECISION RECORDS

11.1 Key Architectural Decisions

ADR-001: Multi-Layered Architecture

  • Decision: Adopt layered architecture with clear abstraction boundaries
  • Rationale: Separation of concerns, testability, maintainability
  • Trade-offs: Performance overhead vs. code organization

ADR-002: Plugin-Based Extensibility

  • Decision: Implement comprehensive plugin architecture
  • Rationale: Future extensibility, hardware diversity support
  • Trade-offs: Complexity vs. flexibility

ADR-003: Priority-Based Threading

  • Decision: Use priority-based multi-threading with Zephyr RTOS
  • Rationale: Real-time performance, deterministic behavior
  • Trade-offs: Complexity vs. performance guarantees

ADR-004: Event-Driven Communication

  • Decision: Implement event-driven inter-component communication
  • Rationale: Loose coupling, scalability, maintainability
  • Trade-offs: Debugging complexity vs. architectural flexibility

12. CONCLUSION AND NEXT STEPS

12.1 Architectural Summary

The OpenAstroFirmware architecture provides a robust, extensible, and maintainable foundation for telescope mount control systems. The design emphasizes:

  • Modularity through clear layer separation and component isolation
  • Extensibility via comprehensive plugin architectures
  • Performance through real-time design patterns and optimization
  • Safety via fail-safe mechanisms and comprehensive error handling
  • Standards Compliance through well-defined protocol implementations

12.2 Implementation Guidance

This architectural design provides the framework for detailed design and implementation. The next phases should focus on:

  1. Detailed Interface Specifications: Define precise contracts between components
  2. Implementation Planning: Break down architecture into implementable components
  3. Prototype Development: Validate architectural decisions through prototyping
  4. Testing Strategy: Develop comprehensive testing approaches for each layer

13. REVISION HISTORY

Version Date Author Description
1.0 August 2, 2025 Andre Stefanov Initial architectural design specification

This document establishes the architectural foundation for OpenAstroFirmware implementation, providing guidance for detailed design and development phases.