| | |
| | | "python": "${workspaceFolder}/env/aerial_deploy/python.exe", |
| | | "program": "${workspaceFolder}/src/Client.py", |
| | | "args": [ |
| | | "192.168.1.224", |
| | | "192.168.1.14", |
| | | "chai", |
| | | "password123", |
| | | "aerial_rpc", |
| | |
| | | import queue |
| | | import requests |
| | | import time |
| | | import threading |
| | | |
| | | from .CaptureThread import CaptureThread |
| | | from .ControllThread import ControllThread |
| | |
| | | # connecting to camera via opencv |
| | | cc.open_cameras() |
| | | # capture the data, and wrap it to data queue |
| | | cc._start_captureThread() |
| | | pass |
| | | # cc._start_captureThread() |
| | | |
| | | |
| | | def connecting_microwave(self): |
| | | pass |
| | |
| | | |
| | | |
| | | def run_all(self): |
| | | |
| | | # connecting to MQ server,launching the message delivery queues |
| | | self.run_rabbitmq() |
| | | # connecting to devices and wrap data to the corressponding queue |
| | | self.run_device() |
| | | |
| | | def stop_all(self): |
| | | self._stop_alarm_state_up_msg_sender_thread() |
| | | self._stop_device_state_up_msg_sender_thread() |
| | | self._stop_command_request_receiver_thread() |
| | | self._start_command_response_sender_thread() |
| | | |
| | | |
| | | def start(self): |
| | | self.run_all() |
| | | try: |
| | | self.run_all() |
| | | self._device_state_sender_thread.join() |
| | | except Exception as e: |
| | | print("running error, stop all threads") |
| | | |
| | | self._stop_alarm_state_up_msg_sender_thread() |
| | | self.stop |
| | | print("main thread end.") |
| | | |
| | | |
| | | |
| | | |
| | | |
| | |
| | | class cameraController(object): |
| | | |
| | | def __init__(self,IMAGE_WIDTH,IMAGE_HEIGHT,CAMERA_COUNT,device_id,queue_dict): |
| | | self.image_width = IMAGE_WIDTH |
| | | self.image_height = IMAGE_HEIGHT |
| | | self.camera_count = CAMERA_COUNT |
| | | self.IMAGE_WIDTH = IMAGE_WIDTH |
| | | self.IMAGE_HEIGHT = IMAGE_HEIGHT |
| | | self.CAMERA_COUNT = CAMERA_COUNT |
| | | self.device_id = device_id |
| | | self.queue_dict = queue_dict |
| | | self.device_state_queue = self.queue_dict["device_state"] |
| | |
| | | self.working_ports.append(dev_port) |
| | | self.cameras.append(camera) |
| | | msg = f"{time.asctime()} {self.device_id} camera port {dev_port} is working and reads images ({h} x {w})" |
| | | |
| | | else: |
| | | msg = f"{time.asctime()} {self.device_id} camera port {dev_port} is not working" |
| | | msg = f"{time.asctime()} {self.device_id} camera port {dev_port} can not work" |
| | | else: |
| | | msg = f"{time.asctime()} {self.device_id} camera port {dev_port} can not found" |
| | | |
| | | # add msg to queue |
| | | self.device_state_queue.put(msg) |
| | | print(msg) |
| | | # add msg to queue |
| | | self.device_state_queue.put(msg) |
| | | print(msg) |
| | | |
| | | |
| | | def _start_captureThread(self): |
| | |
| | | while True: |
| | | try: |
| | | if not self.queue.empty(): |
| | | msg = self.msg_queue.get() |
| | | body = msg.body |
| | | routing_key = msg.routing_key |
| | | channel.basic_publish(exchange=self.exchangeName, routing_key=routing_key, body=body) |
| | | msg = self.queue.get() |
| | | if isinstance(msg,str): |
| | | print(msg) |
| | | else: |
| | | body = msg.body |
| | | routing_key = msg.routing_key |
| | | channel.basic_publish(exchange=self.exchangeName, routing_key=routing_key, body=body) |
| | | |
| | | response_tag = f"{time.asctime()},{self.sender_id} send {self.exchangeName} message to {routing_key}" |
| | | |
| | | response_tag = f"{time.asctime()},{self.sender_id} send {self.exchangeName} message to {routing_key}" |
| | | |
| | | print(response_tag) |
| | | print(response_tag) |
| | | |
| | | elif self.queue.empty(): |
| | | time.sleep(1) |
| | | except Exception as e: |
| | | print(e) |
| | | break |
| | | |
| | | class receiverThread(threading.Thread): |