Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions cri_lib/cri_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class CRIController:
def __init__(self) -> None:
self.robot_state: RobotState = RobotState()
self.robot_state_lock = threading.Lock()

self.program_list: list = []
self.program_list_lock: Lock = threading.Lock()

self.parser = CRIProtocolParser(self.robot_state, self.robot_state_lock)

Expand Down Expand Up @@ -1514,6 +1517,36 @@ def get_motor_temperatures(
else:
return False

def list_flies(self, target_directory: str = "Programs" ) -> bool:
"""request a list of all files in the directory, which is relative to the /Data/ directory.

Parameters
----------
directory : str
directory on iRC `/Data/<target_directory>` in which files are located, e.g. `Programs` for normal robot programs

Returns
-------
a list of files?
"""

command = f"CMD ListFiles {target_directory}"

if (
self._send_command(command=command, register_answer=True, fixed_answer_name="info_flielist")
is not None
):
if (
error_msg := self._wait_for_answer(
"info_flielist", timeout=self.DEFAULT_ANSWER_TIMEOUT
)
) is not None:
logger.debug("Error in GetBoardTemp command: %s", error_msg)
return False
else:
return True
else:
return False

# Monkey patch to maintain backward compatibility
CRIController.MotionType = MotionType # type: ignore
11 changes: 10 additions & 1 deletion cri_lib/cri_protocol_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
class CRIProtocolParser:
"""Class handling the parsing of CRI messages to the robot state."""

def __init__(self, robot_state: RobotState, robot_state_lock: Lock):
def __init__(self, robot_state: RobotState, robot_state_lock: Lock, program_list : list, program_list_lock: Lock):
self.robot_state = robot_state
self.robot_state_lock = robot_state_lock
self.program_list = program_list
self.program_list_lock = program_list_lock

def parse_message(
self, message: str
Expand Down Expand Up @@ -598,6 +600,13 @@ def _parse_info(self, parameters: list[str]) -> str | None:
self.robot_state.motor_temps = temperatures

return "info_motortemp"
elif parameters[0] == "FileList":
with self.program_list_lock:
self.program_list.clear() # direct point to parameters[] will break the shared reference
self.program_list.extend(parameters[2:]) # first element is the target_folder
print(self.program_list)
return "info_flielist"

else:
return None

Expand Down