-
Notifications
You must be signed in to change notification settings - Fork 0
/
Command_Parser.py
37 lines (26 loc) · 1002 Bytes
/
Command_Parser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from os import read
from Command import Command, MissionDownlinkCommand
class Command_Parser():
def __init__(self):
pass
def parse(self, read_command):
# Debug to check ascii code of each char in string
# print(f"read command is {[ord(c) for c in read_command]}")
# If empty command
if len(read_command) == 0:
return Command("blank")
list_read = read_command.split(' ')
if "md" in list_read:
mission_type = list_read[0]
start_timestamp = list_read[1]
num = list_read[2]
interval = list_read[3]
down_timestamp = list_read[4]
try:
parsed_command = MissionDownlinkCommand(
mission_type, num, interval, start_timestamp, down_timestamp)
except ValueError:
parsed_command = Command("unknown")
else:
parsed_command = Command("unknown")
return parsed_command