From 360ba8a616cb525053f288ec5dc3fc9719734282 Mon Sep 17 00:00:00 2001
From: wu_xinjun <bent20140204@outlook.com>
Date: 星期一, 07 三月 2022 15:27:37 +0800
Subject: [PATCH] temp
---
src/protos/aerial.proto | 41 +++++++++++++
pipeline.pptx | 0
src/engine/__init__.py | 2
src/engine/MessageThreads.py | 32 +++++++++-
src/engine/AcquisitionMain.py | 18 +++++
src/engine/devices.py | 54 ++++++++++-------
6 files changed, 119 insertions(+), 28 deletions(-)
diff --git a/pipeline.pptx b/pipeline.pptx
new file mode 100644
index 0000000..6e4a0fe
--- /dev/null
+++ b/pipeline.pptx
Binary files differ
diff --git a/src/engine/AcquisitionMain.py b/src/engine/AcquisitionMain.py
index 1644666..bd680f1 100644
--- a/src/engine/AcquisitionMain.py
+++ b/src/engine/AcquisitionMain.py
@@ -13,7 +13,7 @@
from .ControllThread import ControllThread
from .MicroWaveUDPThread import MicroWaveUDPThread
from . import MessageThreads as ths
-from .CameraDevice import cameraController
+from .devices import cameraController
# add python path of src to sys.path
src_path = os.path.join(__file__, *(['..'] * 2))
@@ -145,6 +145,19 @@
"ply_data":self.ply_data_queue
}
+ # device
+ self.cc = None # camera controller
+ self.mc = None # microwave controller
+ self.dc = None # dust cleaner controller
+ self.rc = None # rotation device controler
+
+ self.controller_dict = {
+ "camera": self.cc,
+ "microwave":self.mc,
+ "dustcleaner":self.dc,
+ "rotation": self.rc
+ }
+
def _connect_to_MQ(self):
credentials = pika.PlainCredentials(self.MQuser, self.MQpassword)
@@ -241,7 +254,7 @@
# connecting to camera via opencv
cc.open_cameras()
# capture the data, and wrap it to data queue
- # cc._start_captureThread()
+ cc._start_captureThread()
def connecting_microwave(self):
@@ -276,6 +289,7 @@
self._stop_alarm_state_up_msg_sender_thread()
self.stop
print("main thread end.")
+ return 0
diff --git a/src/engine/MessageThreads.py b/src/engine/MessageThreads.py
index 13356ed..1e0da3f 100644
--- a/src/engine/MessageThreads.py
+++ b/src/engine/MessageThreads.py
@@ -1,6 +1,15 @@
+import os
import threading
import pika
import time
+import os
+
+# add python path of src to sys.path
+src_path = os.path.join(__file__, *(['..'] * 2))
+src_path = os.path.abspath(src_path)
+sys.path.insert(0, src_path)
+
+from protos import aerial_pb2 as pb
@@ -36,9 +45,10 @@
while True:
try:
if not self.queue.empty():
- msg = self.queue.get()
- if isinstance(msg,str):
- print(msg)
+ data= self.queue.get()
+ if isinstance(data, pb.CapturedData):
+ msg = pb.DataMessage()
+ msg.
else:
body = msg.body
routing_key = msg.routing_key
@@ -230,6 +240,22 @@
ch.basic_ack(delivery_tag = method.delivery_tag)
+class image_data_senderThread(senderThread):
+ def __init__(self,
+ MQparameters,
+ input_msg_queue,
+ sender_id,
+ ):
+ super(command_response_senderThread,self).__init__(
+ MQparameters, \
+ input_msg_queue,
+ sender_id,
+ "image_data",
+ "fanout"
+ )
+
+
+
diff --git a/src/engine/__init__.py b/src/engine/__init__.py
index 777c4fd..965b63f 100644
--- a/src/engine/__init__.py
+++ b/src/engine/__init__.py
@@ -7,4 +7,4 @@
from .MessageQueueThread import *
from .MicroWaveUDPThread import *
from .MessageThreads import *
-from .CameraDevice import *
\ No newline at end of file
+from .devices import *
\ No newline at end of file
diff --git a/src/engine/CameraDevice.py b/src/engine/devices.py
similarity index 76%
rename from src/engine/CameraDevice.py
rename to src/engine/devices.py
index 4361740..a61b5bf 100644
--- a/src/engine/CameraDevice.py
+++ b/src/engine/devices.py
@@ -1,3 +1,4 @@
+from lib2to3.pytree import convert
import cv2
import time
import threading
@@ -57,7 +58,7 @@
"""start capture thread"""
if self._capture_thread is None:
self._capture_thread = \
- CaptureThread(self.cameras,self.image_data_queue,interval=10)
+ CaptureThread(self.cameras,self.image_data_queue,self.device_id,interval=10)
self._capture_thread.setDaemon(True)
self._capture_thread.start()
@@ -68,11 +69,18 @@
self._capture_thread = None
+class microwaveController(object):
+ pass
+
+class dustCleanerController(object):
+ pass
+
+
class CaptureThread(threading.Thread):
"""
camera capture thread
"""
- def __init__(self, cameras, msg_queue, interval, image_quality = 95):
+ def __init__(self, cameras, msg_queue, interval, device_id,image_quality = 95):
"""init the thread"""
threading.Thread.__init__(self)
self.cameras = cameras
@@ -80,43 +88,45 @@
self.interval = interval
self.image_quality = image_quality
self.is_stop = False
-
+ self.device_id = device_id
+
def stop(self):
"""stop the thread"""
self.is_stop = True
def run(self):
print("CaptureThread started")
+ encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), self.image_quality]
self.next_time = time.time() + self.interval
while not self.is_stop:
this_time = time.time()
if this_time > self.next_time:
- data1 = pb.ImagesMessage()
for i in range(len(self.cameras)):
_, frame = self.cameras[i].read()
- encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), self.image_quality]
+ capture_time = time.time()
_, encimg = cv2.imencode('.jpg', frame, encode_param)
if frame is not None:
np_array = np.asarray(encimg) # frame 杞崲涓簄umpy鏁扮粍
byte_array = np_array.tobytes() # numpy鏁扮粍杞崲涓篵yte鏁扮粍
- if i == 0:
- data1.image1 = byte_array
- elif i == 1:
- data1.image2 = byte_array
- elif i == 2:
- data1.image3 = byte_array
- elif i == 3:
- data1.image4 = byte_array
- data1_str = data1.SerializeToString()
+ # convert the image to pb.DataField
+ imagedata = pb.DataField()
+ imagedata.data = byte_array
+ imagedata.length = len(byte_array)
- # create protobuf message
- req = pb.RequestCommand()
- req.sys_command = pb.SysCommand.FIVE_G_COMMAND
- req.sub_command = pb.SubCommand.FIVE_G_SEND_IMAGE_SUB_COMMAND
- req.data1.length = len(data1_str)
- req.data1.data = data1_str
- # add message to queue
- self.msg_queue.put(req)
+ data_str = imagedata.SerializeToString()
+
+ # create protobuf message
+ data_msg = pb.CapturedData()
+ data_msg.generate_time = capture_time
+ data_msg.generate_device = self.device_id
+ data_msg.camera_port = i
+ data_msg.image_data = data_str
+
+
+
+ # add message to queue
+ self.msg_queue.put(data_msg)
+
self.next_time += self.interval
time.sleep(0.1)
for camera in self.cameras:
diff --git a/src/protos/aerial.proto b/src/protos/aerial.proto
index 2f56188..4ed8048 100644
--- a/src/protos/aerial.proto
+++ b/src/protos/aerial.proto
@@ -76,6 +76,29 @@
int32 checksum = 3; // 鏍¢獙鐮�
}
+message CapturedData {
+ int64 capture_time = 1; // 閲囬泦鏃堕棿
+ string capture_device =2; // 閲囬泦璁惧
+ int32 capture_port = 3; // 閲囬泦璁惧搴忓彿
+ DataField DataField = 4;
+ string data_type = 5; // 閲囬泦鏁版嵁
+
+}
+
+message DataMessage{
+ int64 sending_time = 1;
+ string sending_device = 2;
+ string target_device = 3;
+ CapturedData CapturedData = 5;
+
+}
+
+message CommandMessage {
+
+}
+
+
+
message ImagesMessage
{
bytes image1 = 1;
@@ -91,6 +114,24 @@
bytes data = 2; // 鏁版嵁鍐呭
}
+message CommandRequest{
+
+}
+
+message StateMessage{
+ string message_type = 1;
+ int64 generate_time = 2;
+ string generate_device = 3;
+ string target_device = 4;
+ string message_uuid = 5;
+ string str_body = 6;
+}
+
+
+
+
+
+
message RequestCommand {
int32 sync_word = 1; // 鍚屾瀛�
string device_id = 2; // 璁惧ID
--
Gitblit v1.9.1