From 6d4be793db7bfe31ad12b10c9468d4ef1a5e8f52 Mon Sep 17 00:00:00 2001
From: wu_xinjun <bent20140204@outlook.com>
Date: 星期五, 04 三月 2022 17:30:55 +0800
Subject: [PATCH] second commit

---
 .vscode/launch.json           |    2 
 src/engine/CameraDevice.py    |   17 +++++---
 src/engine/MessageThreads.py  |   18 +++++---
 src/engine/AcquisitionMain.py |   24 ++++++++++-
 4 files changed, 43 insertions(+), 18 deletions(-)

diff --git a/.vscode/launch.json b/.vscode/launch.json
index df02b89..cae8c1f 100644
--- a/.vscode/launch.json
+++ b/.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",
diff --git a/src/engine/AcquisitionMain.py b/src/engine/AcquisitionMain.py
index dfdbe31..1644666 100644
--- a/src/engine/AcquisitionMain.py
+++ b/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.")
+ 
+            
 
 
 
diff --git a/src/engine/CameraDevice.py b/src/engine/CameraDevice.py
index 627ebf4..4361740 100644
--- a/src/engine/CameraDevice.py
+++ b/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):
diff --git a/src/engine/MessageThreads.py b/src/engine/MessageThreads.py
index 0fd459d..13356ed 100644
--- a/src/engine/MessageThreads.py
+++ b/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):

--
Gitblit v1.9.1