From aa8a0ba3a86ff5dbbdfcd68c72a5e70e1c52e877 Mon Sep 17 00:00:00 2001
From: wu_xinjun <bent20140204@outlook.com>
Date: 星期二, 07 六月 2022 10:50:50 +0800
Subject: [PATCH] optimize for mq
---
src/engine/DustCleanerThread.py | 10 +-
src/engine/MicroWaveUDPThread.py | 2
scripts/mqClient.py | 54 ++++++++++
src/engine/MessageQueueThread.py | 12 +-
scripts_launch/TEST_startClient.bat | 4
src/__init__.py | 5 +
src/engine/AcquisitionMain.py | 10 +-
src/engine/ControllThread.py | 10 +-
scripts/mqServer.py | 33 ++++++
src/engine/CaptureThread.py | 10 +-
src/Client.py | 84 ++++++++--------
src/Server.py | 29 -----
scripts_launch/TEST_startServer.bat | 5
13 files changed, 170 insertions(+), 98 deletions(-)
diff --git a/scripts/mqClient.py b/scripts/mqClient.py
new file mode 100644
index 0000000..56f546c
--- /dev/null
+++ b/scripts/mqClient.py
@@ -0,0 +1,54 @@
+import signal
+import os, sys
+
+# 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(1, src_path)
+
+
+from src.engine.AcquisitionMain import AcquisitionMain
+from src.engine.AcquisitionMain import Config
+
+def quit(signum, frame):
+ print('You choose to stop me.')
+ sys.exit()
+
+if __name__ == '__main__':
+ def help():
+ print("Usage: Client.py [MQhost] [MQuser] [MQpassword] [QUEUEname] [DEVICEname] [SERVERhost] [MICROWAVEhost]")
+ print("EXAMPLE: Client.py 172.17.17.206 chai password123 aerial_rpc pod1 http://172.17.17.206/api 192.168.2.65")
+ exit(1)
+
+ if len(sys.argv) != 8:
+ help()
+ try:
+ MQhost = str(sys.argv[1])
+ MQuser = str(sys.argv[2])
+ MQpassword = str(sys.argv[3])
+ QUEUEname = str(sys.argv[4])
+ DEVICEname = str(sys.argv[5])
+ SERVERhost = str(sys.argv[6])
+ MICROWAVEhost = str(sys.argv[7])
+
+ except Exception as e:
+ print(e)
+ help()
+
+ print("Start AcquisitionMain")
+ signal.signal(signal.SIGINT, quit)
+ signal.signal(signal.SIGTERM, quit)
+ # client = AcquisitionMain('192.168.3.54', 'chai',
+ # 'password123', 'aerial_rpc', 'pod1', 'http://192.168.3.54:5000/api', 10)
+ config_dir = os.path.join(__file__, "..", "../src/config.json" )
+ config_path = os.path.abspath(config_dir)
+ config = Config(config_path)
+ client = AcquisitionMain(MQhost,
+ MQuser,
+ MQpassword,
+ QUEUEname,
+ DEVICEname,
+ SERVERhost,
+ MICROWAVEhost, # udp server host, 192.168.2.65 for production
+ config)
+ client.start()
diff --git a/scripts/mqServer.py b/scripts/mqServer.py
new file mode 100644
index 0000000..d1db978
--- /dev/null
+++ b/scripts/mqServer.py
@@ -0,0 +1,33 @@
+import sys
+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(1, src_path)
+
+from src.Server import MyServer
+
+
+if __name__ == "__main__":
+ def help():
+ print("Usage: Server.py [MQhost] [MQuser] [MQpassword] [QUEUEname] [WEBport] [SAVEfolder]")
+ print("EXAMPLE: Server.py localhost chai password123 aerial_rpc 5000 ./Images")
+ exit(1)
+
+ if len(sys.argv) != 7:
+ help()
+ try:
+ MQhost = str(sys.argv[1])
+ MQuser = str(sys.argv[2])
+ MQpassword = str(sys.argv[3])
+ QUEUEname = str(sys.argv[4])
+ WEBport = int(sys.argv[5])
+ SAVEfolder = str(sys.argv[6])
+ save_folder = SAVEfolder
+
+ except Exception as e:
+ print(e)
+ help()
+ server = MyServer(host=MQhost, user=MQuser, password=MQpassword, queue=QUEUEname, port=WEBport, SAVEfolder=save_folder)
+ server.run_all()
\ No newline at end of file
diff --git a/scripts_launch/TEST_startClient.bat b/scripts_launch/TEST_startClient.bat
index 065dd95..f399e0d 100644
--- a/scripts_launch/TEST_startClient.bat
+++ b/scripts_launch/TEST_startClient.bat
@@ -16,7 +16,7 @@
echo change to path: %cd%
-set MQhost=192.168.1.224
+set MQhost=localhost
set MQuser=chai
set MQpassword=password123
set QUEUEname=aerial_rpc
@@ -30,6 +30,6 @@
echo Client.py is running ...
@REM -------- Usage: Client.py [MQhost] [MQuser] [MQpassword] [QUEUEname] [DEVICEname] [SERVERhost] [MICROWAVEhost]
@REM %aerialpython% ./src/Client.py %MQhost% %MQuser% %MQpassword% %QUEUEname% %DEVICEname% %SERVERhost% %MICROWAVEhost% >> %LOGfile%
-%aerialpython% ./src/Client.py %MQhost% %MQuser% %MQpassword% %QUEUEname% %DEVICEname% %SERVERhost% %MICROWAVEhost%
+%aerialpython% ./scripts/mqClient.py %MQhost% %MQuser% %MQpassword% %QUEUEname% %DEVICEname% %SERVERhost% %MICROWAVEhost%
echo Client.py has been terminited.
pause
diff --git a/scripts_launch/TEST_startServer.bat b/scripts_launch/TEST_startServer.bat
index c648595..c1939c3 100644
--- a/scripts_launch/TEST_startServer.bat
+++ b/scripts_launch/TEST_startServer.bat
@@ -16,7 +16,8 @@
echo change to path: %cd%
-set MQhost=localhost
+@REM set MQhost=localhost
+set MQhost=47.92.33.19
set MQuser=chai
set MQpassword=password123
set QUEUEname=aerial_rpc
@@ -29,7 +30,7 @@
echo the log file will be saved in the [%LOGfile%] file
echo Server.py is running ...
@REM -------- Usage: Server.py [MQhost] [MQuser] [MQpassword] [QUEUEname] [WEBport] [SAVEfolder]")
-%aerialpython% ./src/Server.py %MQhost% %MQuser% %MQpassword% %QUEUEname% %WEBport% %SAVEfolder% >> %LOGfile%
+%aerialpython% ./scripts/mqServer.py %MQhost% %MQuser% %MQpassword% %QUEUEname% %WEBport% %SAVEfolder%
echo Server.py has been terminited.
pause
diff --git a/src/Client.py b/src/Client.py
index 4bb0efb..6fa9ebd 100644
--- a/src/Client.py
+++ b/src/Client.py
@@ -1,49 +1,49 @@
-import signal
-import os, sys
+# import signal
+# import os, sys
-from .engine.AcquisitionMain import AcquisitionMain
-from .engine.AcquisitionMain import Config
+# from .engine.AcquisitionMain import AcquisitionMain
+# from .engine.AcquisitionMain import Config
-def quit(signum, frame):
- print('You choose to stop me.')
- sys.exit()
+# def quit(signum, frame):
+# print('You choose to stop me.')
+# sys.exit()
-if __name__ == '__main__':
- def help():
- print("Usage: Client.py [MQhost] [MQuser] [MQpassword] [QUEUEname] [DEVICEname] [SERVERhost] [MICROWAVEhost]")
- print("EXAMPLE: Client.py 172.17.17.206 chai password123 aerial_rpc pod1 http://172.17.17.206/api 192.168.2.65")
- exit(1)
+# if __name__ == '__main__':
+# def help():
+# print("Usage: Client.py [MQhost] [MQuser] [MQpassword] [QUEUEname] [DEVICEname] [SERVERhost] [MICROWAVEhost]")
+# print("EXAMPLE: Client.py 172.17.17.206 chai password123 aerial_rpc pod1 http://172.17.17.206/api 192.168.2.65")
+# exit(1)
- if len(sys.argv) != 8:
- help()
- try:
- MQhost = str(sys.argv[1])
- MQuser = str(sys.argv[2])
- MQpassword = str(sys.argv[3])
- QUEUEname = str(sys.argv[4])
- DEVICEname = str(sys.argv[5])
- SERVERhost = str(sys.argv[6])
- MICROWAVEhost = str(sys.argv[7])
+# if len(sys.argv) != 8:
+# help()
+# try:
+# MQhost = str(sys.argv[1])
+# MQuser = str(sys.argv[2])
+# MQpassword = str(sys.argv[3])
+# QUEUEname = str(sys.argv[4])
+# DEVICEname = str(sys.argv[5])
+# SERVERhost = str(sys.argv[6])
+# MICROWAVEhost = str(sys.argv[7])
- except Exception as e:
- print(e)
- help()
+# except Exception as e:
+# print(e)
+# help()
- print("Start AcquisitionMain")
- signal.signal(signal.SIGINT, quit)
- signal.signal(signal.SIGTERM, quit)
- # client = AcquisitionMain('192.168.3.54', 'chai',
- # 'password123', 'aerial_rpc', 'pod1', 'http://192.168.3.54:5000/api', 10)
- config_dir = os.path.join(__file__, "..", "config.json" )
- config_path = os.path.abspath(config_dir)
- config = Config(config_path)
- client = AcquisitionMain(MQhost,
- MQuser,
- MQpassword,
- QUEUEname,
- DEVICEname,
- SERVERhost,
- MICROWAVEhost, # udp server host, 192.168.2.65 for production
- config)
- client.start()
+# print("Start AcquisitionMain")
+# signal.signal(signal.SIGINT, quit)
+# signal.signal(signal.SIGTERM, quit)
+# # client = AcquisitionMain('192.168.3.54', 'chai',
+# # 'password123', 'aerial_rpc', 'pod1', 'http://192.168.3.54:5000/api', 10)
+# config_dir = os.path.join(__file__, "..", "config.json" )
+# config_path = os.path.abspath(config_dir)
+# config = Config(config_path)
+# client = AcquisitionMain(MQhost,
+# MQuser,
+# MQpassword,
+# QUEUEname,
+# DEVICEname,
+# SERVERhost,
+# MICROWAVEhost, # udp server host, 192.168.2.65 for production
+# config)
+# client.start()
diff --git a/src/Server.py b/src/Server.py
index 3f1e26e..813bb0c 100644
--- a/src/Server.py
+++ b/src/Server.py
@@ -9,13 +9,16 @@
class MyServer(Flask):
- def __init__(self, host, user, password, queue, port):
+ def __init__(self, host, user, password, queue, port, SAVEfolder):
Flask.__init__(self, __name__)
self.host = host
self.user = user
self.password = password
self.queue = queue
self.port = port
+ global save_folder
+ save_folder = SAVEfolder
+
self.route('/api', methods=['POST'])(self.api)
self.route('/', methods=['GET'])(self.hello)
@@ -84,27 +87,3 @@
msg.data1.length = len(data1_str)
msg.data1.data = data1_str
-
-if __name__ == "__main__":
- def help():
- print("Usage: Server.py [MQhost] [MQuser] [MQpassword] [QUEUEname] [WEBport] [SAVEfolder]")
- print("EXAMPLE: Server.py localhost chai password123 aerial_rpc 5000 ./Images")
- exit(1)
-
- if len(sys.argv) != 7:
- help()
- try:
- MQhost = str(sys.argv[1])
- MQuser = str(sys.argv[2])
- MQpassword = str(sys.argv[3])
- QUEUEname = str(sys.argv[4])
- WEBport = int(sys.argv[5])
- SAVEfolder = str(sys.argv[6])
- global save_folder
- save_folder = SAVEfolder
-
- except Exception as e:
- print(e)
- help()
- server = MyServer(host="localhost", user='chai', password='password123', queue='aerial_rpc', port=5000)
- server.run_all()
diff --git a/src/__init__.py b/src/__init__.py
index e69de29..29a8a06 100644
--- a/src/__init__.py
+++ b/src/__init__.py
@@ -0,0 +1,5 @@
+from .engine import *
+from .microwave import *
+from .protos import *
+from .slam import *
+from .utils import *
\ No newline at end of file
diff --git a/src/engine/AcquisitionMain.py b/src/engine/AcquisitionMain.py
index 4373fa6..ef126b3 100644
--- a/src/engine/AcquisitionMain.py
+++ b/src/engine/AcquisitionMain.py
@@ -12,12 +12,12 @@
from .ControllThread import ControllThread
from .MicroWaveUDPThread import MicroWaveUDPThread
-# 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)
+# # 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
+from ..protos import aerial_pb2 as pb
IMAGE_WIDTH = 3840
diff --git a/src/engine/CaptureThread.py b/src/engine/CaptureThread.py
index f6d588b..240229f 100644
--- a/src/engine/CaptureThread.py
+++ b/src/engine/CaptureThread.py
@@ -6,12 +6,12 @@
import time
-# 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)
+# # 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
+from ..protos import aerial_pb2 as pb
class CaptureThread(threading.Thread):
diff --git a/src/engine/ControllThread.py b/src/engine/ControllThread.py
index 3de30b8..97912c0 100644
--- a/src/engine/ControllThread.py
+++ b/src/engine/ControllThread.py
@@ -6,12 +6,12 @@
import threading
from .DustCleanerThread import DustCleanerThread
-# 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)
+# # 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
+from ..protos import aerial_pb2 as pb
class ControllThread(threading.Thread):
"""
diff --git a/src/engine/DustCleanerThread.py b/src/engine/DustCleanerThread.py
index 2405305..c733cf1 100644
--- a/src/engine/DustCleanerThread.py
+++ b/src/engine/DustCleanerThread.py
@@ -5,12 +5,12 @@
from .DustCleaner import DustCleaner
-# 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)
+# # 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
+from ..protos import aerial_pb2 as pb
diff --git a/src/engine/MessageQueueThread.py b/src/engine/MessageQueueThread.py
index 16396af..680a988 100644
--- a/src/engine/MessageQueueThread.py
+++ b/src/engine/MessageQueueThread.py
@@ -5,13 +5,13 @@
from ctypes import sizeof
from .DeviceManager import DeviceManager
-# 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)
+# # 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 microwave.components import HeaderBlock
-from protos import aerial_pb2 as pb
+from ..microwave.components import HeaderBlock
+from ..protos import aerial_pb2 as pb
class MessageQueueThread(threading.Thread):
def __init__(self,
diff --git a/src/engine/MicroWaveUDPThread.py b/src/engine/MicroWaveUDPThread.py
index 7ec90ba..478afc2 100644
--- a/src/engine/MicroWaveUDPThread.py
+++ b/src/engine/MicroWaveUDPThread.py
@@ -6,7 +6,7 @@
src_path = os.path.abspath(src_path)
sys.path.insert(0, src_path)
-from microwave.servers import MicroWaveUDPServer
+from ..microwave.servers import MicroWaveUDPServer
class MicroWaveUDPThread (threading.Thread):
--
Gitblit v1.9.1