From 74c96c72625aff6613d69c7168e1a7d76da22870 Mon Sep 17 00:00:00 2001
From: wu_xinjun <bent20140204@outlook.com>
Date: 星期五, 24 六月 2022 17:18:31 +0800
Subject: [PATCH] add taskuuid
---
src/engine/AcquisitionMain.py | 78 +++++++++++++++++++++++++++++++++++---
1 files changed, 71 insertions(+), 7 deletions(-)
diff --git a/src/engine/AcquisitionMain.py b/src/engine/AcquisitionMain.py
index e2a580c..af152a0 100644
--- a/src/engine/AcquisitionMain.py
+++ b/src/engine/AcquisitionMain.py
@@ -1,7 +1,9 @@
import sys # NOQA: E402
import os
+from time import sleep
import pika
import queue
+from datetime import datetime
# from .CaptureThread import CaptureThread
# from .ControllThread import ControllThread
@@ -14,7 +16,7 @@
# src_path = os.path.abspath(src_path)
# sys.path.insert(0, src_path)
-# from ..protos import aerial_pb2 as pb
+from ..protos import aerial_pb2 as pb
IMAGE_WIDTH = 3840
@@ -116,7 +118,7 @@
def _connect_to_MQ(self):
credentials = pika.PlainCredentials(self.MQuser, self.MQpassword)
self.parameters = pika.ConnectionParameters(
- credentials=credentials, host=self.MQhost)
+ credentials=credentials, host=self.MQhost,heartbeat=0)
# 杩炴帴闃熷垪鏈嶅姟鍣�
try:
self.connection = pika.BlockingConnection(self.parameters)
@@ -133,7 +135,7 @@
MQparams=self.parameters,
exchange_name='commands_topic',
exchange_type='topic',
- MQqueue_name="server0_commands_queue",
+ MQqueue_name=f"{self.device_id}_commands_queue",
binding_keys=[f"{self.device_id}"],
message_queue=self.CommandsReceiver_queue
)
@@ -206,19 +208,80 @@
timeout=self.timeout,
logs_queue=self.LogsSender_queue,
device_id=self.device_id,
- routing_key="server0"
+ init_binding_key=self.device_id,
+ init_routing_key="server0"
)
self.mc = microwaveController(
MicrowaveHost=self.MICROWAVEhost,
MicrowavePort=self.MICROWAVEport,
init_packet_threshold=100,
- init_timeusage_threshold=3,
+ init_timeusage_threshold=0.2,
device_id=self.device_id,
logs_queue=self.LogsSender_queue,
plys_queue=self.PlysSender_queue,
- routing_key="server0"
+ init_binding_key=self.device_id,
+ init_routing_key="server0"
)
+
+ def command_control(self):
+ while True:
+
+ try:
+ while not self.CommandsReceiver_queue.empty():
+ command_bytes= self.CommandsReceiver_queue.get()
+
+ # parse the command from bytes to the pb object
+ req_command = pb.CommandMessage()
+ req_command.ParseFromString(command_bytes)
+
+ # extracting some info for use
+ source = req_command.source
+ generatetime = req_command.generatetime
+ syscommand = req_command.syscommand
+ subcommand = req_command.subcommand
+ targetclient = req_command.targetclient
+ returnserver = req_command.returnserver
+ taskuuid = req_command.taskuuid
+
+ curr_time = datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
+ print(f"[x] {curr_time}|(From {source}): task [{taskuuid}] received!" )
+
+ # command for camera
+ if syscommand == pb.SysCommand.CAMERA_COMMAND:
+ # capture image
+ if subcommand == pb.SubCommand.ONE_TIME_CAPTURE:
+ self.cc.capture(routing_key=returnserver,taskuuid=taskuuid)
+ # unknown command
+ else:
+ pass
+
+ # command for microwave device
+ elif syscommand == pb.SysCommand.MICROWAVE_COMMAND:
+ if subcommand == pb.SubCommand.ONE_CIRCLE_SCAN:
+ self.mc.scan(routing_key=returnserver,taskuuid=taskuuid)
+ # unknown command
+ else:
+ pass
+
+ # command for dust cleaner
+ elif syscommand == pb.Syscommand.DUSTCLEANER_COMMAND:
+ if subcommand == pb.SubCommand.ONE_CLEAN_SCAN:
+ self.dc.clean(routing_key=returnserver,taskuuid=taskuuid)
+ # unknown command
+ else:
+ pass
+ # unknown command
+ else:
+ pass
+
+ else:
+ sleep(1)
+
+ except:
+
+ break
+
def run_rabbitmq(self):
@@ -236,6 +299,8 @@
self.run_rabbitmq()
# connecting to devices and wrap data to the corressponding queue
self.run_device()
+ sleep(10)
+ self.command_control()
def stop_all(self):
@@ -254,7 +319,6 @@
# self.stop_all()
# print("main thread end.")
self.run_all()
- self.CommandsReceiver_Thread.join()
return 0
--
Gitblit v1.9.1