Skip to content

Commit

Permalink
added enum for command types
Browse files Browse the repository at this point in the history
  • Loading branch information
ashum68 committed Jun 22, 2024
1 parent 390cca2 commit c3f2345
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions modules/decision_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,52 @@
Command data structure used by decision module.
"""

import enum

class DecisionCommand:
"""
Contains list of commands to send to drone.
Contains command to send to drone.
The following are valid command constructors:
* DecisionCommand.create_stop_command
* DecisionCommand.create_resume_command
"""

__create_key = object()

class CommandType(enum.Enum):
"""
Valid commands.
"""
STOP = 0
RESUME = 1


@classmethod
def create(cls, command: "str") -> "tuple[bool, DecisionCommand | None]":
def create_stop_command(cls) -> "tuple[bool, DecisionCommand | None]":
"""
Creates a list of commands to send to the drone.
Command to stop and loiter the drone.
"""
if command is None:
return False, None
return True, DecisionCommand(cls.__create_key, command)
return True, DecisionCommand(cls.__create_key, DecisionCommand.CommandType.STOP)

@classmethod
def create_resume_command(cls) -> "tuple[bool, DecisionCommand | None]":
"""
Command to resume auto mission.
"""
return True, DecisionCommand(cls.__create_key, DecisionCommand.CommandType.RESUME)

def __init__(self, create_key: object, command: str) -> None:
def __init__(self, create_key: object, command: CommandType) -> None:
"""
Private constructor, use create() method.
"""
assert create_key is DecisionCommand.__create_key, "Use create() method"

self.command = command

def __str__(self):
pass
def __str__(self) -> str:
"""
String representation
"""
return f"{self.__class__.__name__}: {self.command}"

0 comments on commit c3f2345

Please sign in to comment.