93 lines
2.5 KiB
Python
93 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Unified Device Simulator
|
|
Entry point for running Pelican or Glory device simulators.
|
|
"""
|
|
|
|
import argparse
|
|
import sys
|
|
|
|
from glory import GlorySimulator
|
|
|
|
# Import simulators
|
|
from pelican import PelicanSimulator
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(
|
|
description="Device Simulator - Run Pelican or Glory MACH6 simulator",
|
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
epilog="""
|
|
Examples:
|
|
# Run Pelican simulator
|
|
python main.py pelican --port /dev/ttyUSB0
|
|
|
|
# Run Glory simulator
|
|
python main.py glory --port /dev/ttyUSB1 --baudrate 9600
|
|
|
|
# Get help for specific simulator
|
|
python main.py pelican --help
|
|
python main.py glory --help
|
|
""",
|
|
)
|
|
|
|
# Add subparsers for each simulator type
|
|
subparsers = parser.add_subparsers(
|
|
dest="simulator", help="Simulator type to run", required=True
|
|
)
|
|
|
|
# Pelican simulator subcommand
|
|
pelican_parser = subparsers.add_parser(
|
|
"pelican", help="Run Pelican coin counter simulator"
|
|
)
|
|
pelican_parser.add_argument(
|
|
"--port",
|
|
"-p",
|
|
default="/dev/ttyUSB0",
|
|
help="Serial port (default: /dev/ttyUSB0)",
|
|
)
|
|
pelican_parser.add_argument(
|
|
"--baudrate", "-b", type=int, default=115200, help="Baud rate (default: 115200)"
|
|
)
|
|
|
|
# Glory simulator subcommand
|
|
glory_parser = subparsers.add_parser(
|
|
"glory", help="Run Glory MACH6 coin counter simulator"
|
|
)
|
|
glory_parser.add_argument(
|
|
"--port",
|
|
"-p",
|
|
default="/dev/ttyUSB0",
|
|
help="Serial port (default: /dev/ttyUSB0)",
|
|
)
|
|
glory_parser.add_argument(
|
|
"--baudrate", "-b", type=int, default=115200, help="Baud rate (default: 115200)"
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
|
|
# Run the appropriate simulator
|
|
try:
|
|
if args.simulator == "pelican":
|
|
print(
|
|
f"Starting Pelican simulator on {args.port} at {args.baudrate} baud..."
|
|
)
|
|
simulator = PelicanSimulator(args.port, args.baudrate)
|
|
simulator.run()
|
|
elif args.simulator == "glory":
|
|
print(
|
|
f"Starting Glory MACH6 simulator on {args.port} at {args.baudrate} baud..."
|
|
)
|
|
simulator = GlorySimulator(args.port, args.baudrate)
|
|
simulator.run()
|
|
except KeyboardInterrupt:
|
|
print("\nSimulator stopped by user")
|
|
sys.exit(0)
|
|
except Exception as e:
|
|
print(f"Error: {e}", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|