prototype for a camera server client plus CLI control script
This commit is contained in:
98
clicamesh.py
Executable file
98
clicamesh.py
Executable file
@@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import argparse
|
||||
from time import sleep
|
||||
|
||||
from cameras.cameraclient import CameraClient
|
||||
|
||||
|
||||
def main():
|
||||
commands = ["restart", "roi", "status", "test"]
|
||||
commands.sort()
|
||||
printable_commands = ", ".join(commands)
|
||||
|
||||
parser = argparse.ArgumentParser(description="CLI Cam (esh)")
|
||||
parser.add_argument("-c", "--camera", help="camera name", default="SATES24-CAMS161-M1")
|
||||
parser.add_argument("-v", "--verbose", help="verbose output", action="store_true")
|
||||
|
||||
subparsers = parser.add_subparsers(title="commands", dest="command", help=printable_commands)
|
||||
subparser_restart = subparsers.add_parser("restart", description="Restart camera server")
|
||||
subparser_roi = subparsers.add_parser("roi", description="Set ROI")
|
||||
subparser_status = subparsers.add_parser("status", description="Print status")
|
||||
subparser_test = subparsers.add_parser("test", description="Test setting ROIs")
|
||||
|
||||
for sp in subparsers.choices.values():
|
||||
sp.add_argument("-v", "--verbose", help="verbose output", action="store_true")
|
||||
|
||||
subparser_restart.add_argument("-r", "--reset", help="reset ROI", action="store_true")
|
||||
|
||||
subparser_roi.add_argument("xmin", type=int, help="x min")
|
||||
subparser_roi.add_argument("xmax", type=int, help="x max")
|
||||
subparser_roi.add_argument("ymin", type=int, help="y min")
|
||||
subparser_roi.add_argument("ymax", type=int, help="y max")
|
||||
|
||||
clargs = parser.parse_args()
|
||||
command = clargs.command
|
||||
if command is None:
|
||||
parser.print_help()
|
||||
raise SystemExit(1)
|
||||
|
||||
camera = CameraClient(clargs.camera)
|
||||
|
||||
if clargs.verbose:
|
||||
print(camera)
|
||||
print(f"command: {command}")
|
||||
# print(clargs)
|
||||
|
||||
if command == "restart":
|
||||
do_restart(camera, clargs)
|
||||
elif command == "roi":
|
||||
do_roi(camera, clargs)
|
||||
elif command == "test":
|
||||
do_test(camera, clargs)
|
||||
elif command == "status":
|
||||
do_status(camera, clargs)
|
||||
else:
|
||||
print(f"nothing assigned to command: {command}")
|
||||
parser.print_help()
|
||||
raise SystemExit(2)
|
||||
|
||||
|
||||
|
||||
def do_restart(camera, clargs):
|
||||
if not clargs.reset:
|
||||
roi = camera.get_roi()
|
||||
camera.restart()
|
||||
if not clargs.reset:
|
||||
camera.set_roi(*roi, debug=clargs.verbose) #TODO: workaround! why does the first try always set to: [101, 2400, 100, 2061]?
|
||||
camera.set_roi(*roi, debug=clargs.verbose)
|
||||
|
||||
def do_roi(camera, clargs):
|
||||
camera.set_roi(clargs.xmin, clargs.xmax, clargs.ymin, clargs.ymax, debug=clargs.verbose)
|
||||
|
||||
def do_status(camera, clargs):
|
||||
camera.status
|
||||
|
||||
def do_test(camera, _clargs):
|
||||
camera.reset_roi() # [1, 2560, 1, 2160]
|
||||
print(camera.get_roi())
|
||||
|
||||
for i in (1, 10, 100, 200, 300, 999, 1000, 1001):
|
||||
camera.set_roi(i, 1500, i, 1900, debug=True)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
#CA client library tcp receive thread terminating due to a non-standard C++ exception
|
||||
#FATAL: exception not rethrown
|
||||
#Aborted (core dumped)
|
||||
|
||||
# "solved" by
|
||||
sleep(0.0001)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user