Common main
This commit is contained in:
4
Makefile
4
Makefile
@ -1,6 +1,6 @@
|
|||||||
run-pelican:
|
run-pelican:
|
||||||
@ uv run python pelican.py --port /dev/ttyUSB0 --baud 115200
|
@ uv run python main.py pelican --port /dev/ttyUSB0 --baud 115200
|
||||||
|
|
||||||
|
|
||||||
run-glory:
|
run-glory:
|
||||||
@ uv run python glory.py --port /dev/ttyUSB0 --baud 115200
|
@ uv run python main.py glory --port /dev/ttyUSB0 --baud 115200
|
||||||
|
|||||||
92
main.py
Normal file
92
main.py
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
#!/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()
|
||||||
2
uv.lock
generated
2
uv.lock
generated
@ -3,7 +3,7 @@ revision = 3
|
|||||||
requires-python = ">=3.8"
|
requires-python = ">=3.8"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pelican-simulator"
|
name = "coin-counter-simulators"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = { virtual = "." }
|
source = { virtual = "." }
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
|||||||
Reference in New Issue
Block a user