Skip to content

Commit b24a3d7

Browse files
committed
style: rename things
Renamed some things to be more clear. Also, now any save files such as message history are stored under the `save-data/` directory.
1 parent 4c63d9e commit b24a3d7

File tree

6 files changed

+21
-16
lines changed

6 files changed

+21
-16
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
messages.json
88
camera_data.txt
99
*.jpeg
10+
save-data/
1011

1112
###############################################################################
1213
# VSCode

soti-cli/__main__.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import os
99
import serial.tools.list_ports
1010

11-
from cli_utils import help_strings
12-
from cli_utils.constants import NodeID, CmdID, COMM_INFO, MSG_HISTORY_FILENAME
11+
from utils import help_strings
12+
from utils.constants import SAVE_DATA_DIR, NodeID, CmdID, COMM_INFO, MSG_HISTORY_PATH
1313

1414
from serial_reader import serial_reader
1515
from message_parser import parser
@@ -79,7 +79,7 @@ def do_query(self, arg):
7979
"""Queries the telemetry."""
8080
print(f"\nSearching message history for {arg} commands...")
8181

82-
with open(MSG_HISTORY_FILENAME, encoding="utf_8") as history:
82+
with open(MSG_HISTORY_PATH, encoding="utf_8") as history:
8383
msgs = json.load(history)
8484

8585
num_results = 0
@@ -94,7 +94,7 @@ def do_query(self, arg):
9494

9595
def do_clear(self, _):
9696
"""Clears the json message history file."""
97-
with open(MSG_HISTORY_FILENAME, 'w', encoding="utf_8") as history:
97+
with open(MSG_HISTORY_PATH, 'w', encoding="utf_8") as history:
9898
history.write("[]")
9999
history.flush()
100100
print("The json message history file has been cleared.\n")
@@ -128,8 +128,11 @@ def do_exit(self, _):
128128

129129
def init_json():
130130
"""Initializes the JSON file which logs all messages."""
131-
if (not os.path.exists(MSG_HISTORY_FILENAME)) or (os.path.getsize(MSG_HISTORY_FILENAME) == 0):
132-
with open(MSG_HISTORY_FILENAME, 'w', encoding="utf_8") as history:
131+
if not os.path.exists(SAVE_DATA_DIR):
132+
os.mkdir(SAVE_DATA_DIR)
133+
134+
if (not os.path.exists(MSG_HISTORY_PATH)) or (os.path.getsize(MSG_HISTORY_PATH) == 0):
135+
with open(MSG_HISTORY_PATH, 'w', encoding="utf_8") as history:
133136
history.write("[]")
134137

135138

soti-cli/message_parser.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import datetime
44
import json
55
import struct
6-
from cli_utils.constants import NodeID, CmdID, MSG_HISTORY_FILENAME
6+
from utils.constants import NodeID, CmdID, MSG_HISTORY_PATH
77

88

99
def parser(in_msg_queue):
@@ -13,10 +13,10 @@ def parser(in_msg_queue):
1313
new_msg_raw = in_msg_queue.get()
1414
new_msg_json = parse_message(new_msg_raw)
1515
print(f"Message Parsed: {new_msg_json}")
16-
with open(MSG_HISTORY_FILENAME, encoding="utf_8") as history:
16+
with open(MSG_HISTORY_PATH, encoding="utf_8") as history:
1717
history_json = json.load(history)
1818
history_json.append(new_msg_json)
19-
with open(MSG_HISTORY_FILENAME, 'w', encoding="utf_8") as history:
19+
with open(MSG_HISTORY_PATH, 'w', encoding="utf_8") as history:
2020
json.dump(history_json, history, indent=4)
2121

2222

soti-cli/serial_reader.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from queue import Empty
44
import serial
5-
from cli_utils.constants import MSG_SIZE
5+
from utils.constants import MSG_SIZE
66

77

88
def serial_reader(in_msg_queue, out_msg_queue, soti_port):

soti-cli/cli_utils/constants.py renamed to soti-cli/utils/constants.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55

66
ROOT_DIR = Path(__file__).resolve().parent.parent
77

8-
# files
9-
MSG_HISTORY_FILENAME = ROOT_DIR / "messages.json"
8+
SAVE_DATA_DIR = ROOT_DIR / "save-data"
109

11-
# message size
10+
MSG_HISTORY_PATH = SAVE_DATA_DIR / "messages.json"
11+
12+
# The length of a serialized message in bytes.
1213
MSG_SIZE = 11
1314

1415

@@ -18,15 +19,15 @@ class NodeID(Enum):
1819
PWR = 1
1920
ADCS = 2
2021
PLD = 3
21-
22+
2223
def get_display_name(self) -> str:
2324
"""
2425
Returns a friendlier name for each enum member.
2526
2627
Example Usage:
2728
print(Node.CDH.get_display_name())
2829
"""
29-
30+
3031
display_names = {
3132
NodeID.CDH: "CDH",
3233
NodeID.PWR: "Power",

soti-cli/cli_utils/help_strings.py renamed to soti-cli/utils/help_strings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Includes strings used in help messages."""
22

3-
from cli_utils.constants import CmdID
3+
from utils.constants import CmdID
44

55

66
HELP_MESSAGE = """

0 commit comments

Comments
 (0)