Skip to content

Commit

Permalink
Add ics manager command line app
Browse files Browse the repository at this point in the history
  • Loading branch information
iory committed Nov 12, 2024
1 parent 2da5678 commit 87aa354
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
78 changes: 78 additions & 0 deletions rcb4/apps/ics_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env python

import argparse
import sys

import yaml

from rcb4.ics import ICSServoController


def load_yaml(yaml_path):
try:
with open(yaml_path) as file:
data = yaml.safe_load(file)
print("YAML configuration loaded successfully.")
return data
except FileNotFoundError:
print(f"Error: YAML file not found at path: {yaml_path}")
sys.exit(1)
except yaml.YAMLError as exc:
print(f"Error parsing YAML file: {exc}")
sys.exit(1)


def parse_args():
"""Parse command-line arguments."""
parser = argparse.ArgumentParser(description="ICS Servo Controller CLI Tool")
parser.add_argument(
"--yaml_path",
default=None,
help="Path to YAML configuration file for servo settings"
)
parser.add_argument(
"--baudrate",
type=int,
default=1250000,
choices=[1250000, 625000, 115200],
help="Baud rate for servo connection"
)
parser.add_argument(
"--verbose",
action="store_true",
help="Enable verbose output"
)
return parser.parse_args()


def main():
args = parse_args()

# Verbose output if enabled
if args.verbose:
print(f"Using baud rate: {args.baudrate}")
if args.yaml_path:
print(f"Loading configuration from: {args.yaml_path}")
else:
print("No YAML configuration file specified.")

if args.yaml_path:
load_yaml(args.yaml_path)

# Initialize the ICS Servo Controller
servo_controller = ICSServoController(
baudrate=args.baudrate,
yaml_path=args.yaml_path
)

try:
servo_controller.display_status()
except Exception as e:
print(f"An error occurred while displaying status: {e}")
finally:
servo_controller.close_connection()
print("Connection closed.")


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"console_scripts": [
"rcb4-write-firmware=rcb4.apps.write_firmware:main",
"armh7-tools=rcb4.apps.armh7_tool:main",
"ics-manager=rcb4.apps.ics_manager:main",
],
},
)

0 comments on commit 87aa354

Please sign in to comment.