Skip to content

Commit 2c6b3e1

Browse files
authored
Implement list_flies method for file listing
Added a method to list files in a specified directory.
1 parent 11881a6 commit 2c6b3e1

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

cri_lib/cri_controller.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ class CRIController:
3737
def __init__(self) -> None:
3838
self.robot_state: RobotState = RobotState()
3939
self.robot_state_lock = threading.Lock()
40+
41+
self.program_list: list = []
42+
self.program_list_lock: Lock = threading.Lock()
4043

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

@@ -1514,6 +1517,36 @@ def get_motor_temperatures(
15141517
else:
15151518
return False
15161519

1520+
def list_flies(self, target_directory: str = "Programs" ) -> bool:
1521+
"""request a list of all files in the directory, which is relative to the /Data/ directory.
1522+
1523+
Parameters
1524+
----------
1525+
directory : str
1526+
directory on iRC `/Data/<target_directory>` in which files are located, e.g. `Programs` for normal robot programs
1527+
1528+
Returns
1529+
-------
1530+
a list of files?
1531+
"""
1532+
1533+
command = f"CMD ListFiles {target_directory}"
1534+
1535+
if (
1536+
self._send_command(command=command, register_answer=True, fixed_answer_name="info_flielist")
1537+
is not None
1538+
):
1539+
if (
1540+
error_msg := self._wait_for_answer(
1541+
"info_flielist", timeout=self.DEFAULT_ANSWER_TIMEOUT
1542+
)
1543+
) is not None:
1544+
logger.debug("Error in GetBoardTemp command: %s", error_msg)
1545+
return False
1546+
else:
1547+
return True
1548+
else:
1549+
return False
15171550

15181551
# Monkey patch to maintain backward compatibility
15191552
CRIController.MotionType = MotionType # type: ignore

0 commit comments

Comments
 (0)