wu_xinjun
2022-03-04 6d4be793db7bfe31ad12b10c9468d4ef1a5e8f52
second commit
4个文件已修改
61 ■■■■ 已修改文件
.vscode/launch.json 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/engine/AcquisitionMain.py 24 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/engine/CameraDevice.py 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/engine/MessageThreads.py 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.vscode/launch.json
@@ -11,7 +11,7 @@
            "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",
src/engine/AcquisitionMain.py
@@ -7,6 +7,7 @@
import queue
import requests
import time
import threading
from .CaptureThread import CaptureThread
from .ControllThread import ControllThread
@@ -240,8 +241,8 @@
        # 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
@@ -252,14 +253,31 @@
    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.")
src/engine/CameraDevice.py
@@ -14,9 +14,9 @@
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"]
@@ -42,12 +42,15 @@
                    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):
src/engine/MessageThreads.py
@@ -36,18 +36,22 @@
            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):