Commands Processor
This module provides functionality for parsing and executing drone commands from JSON-formatted strings. It serves as the main interface between command input and concrete command implementations.
Functions
- process_command
Main command processing pipeline
- parse_command
JSON command validation and parsing
- select_command
Command object instantiation based on type
Exceptions
- ValueError
Raised for invalid JSON command format
- commands_processor.process_command(command_str: str)[source]
Execute full command processing pipeline.
Parse input string to command dictionary
Instantiate appropriate command object
Execute command logic
Return formatted results
- Parameters:
command_str (str) – JSON-formatted command string
- Returns:
Tuple containing (command_id, result_data, latitude, longitude)
- Return type:
tuple
- Raises:
ValueError – If input string contains invalid JSON
Example
Process a takeoff command:
result = process_command('{"command_type": "NAV_TAKEOFF, ...}')
- commands_processor.parse_command(command_str: str)[source]
Validate and parse JSON command string to dictionary.
- Parameters:
command_str (str) – Input command string in JSON format
- Returns:
Validated command dictionary
- Return type:
dict
- Raises:
ValueError – If JSON parsing fails
- commands_processor.select_command(command_dict: dict)[source]
Instantiate appropriate command subclass based on command type.
Supported command types: - NAV_TAKEOFF: Nav_TakeOff - NAV_LAND: Nav_Land - NAV_WAYPOINT: Nav_Waypoint - NAV_HOME: Nav_Home - CAMERA_IMAGE: Camera_Image - ANALYZE_IMAGE: Analyze_Image - SPRAY: Spray
- Parameters:
command_dict (dict) – Validated command dictionary
- Returns:
Concrete command instance
- Return type: