From dfe24d63ccca74c1093349e8b9e9977ac0d82278 Mon Sep 17 00:00:00 2001
From: wu_xinjun <bent20140204@outlook.com>
Date: 星期三, 16 二月 2022 17:18:30 +0800
Subject: [PATCH] auto setting env and getting udp data
---
src/Microwave/demo/MicroWaveUDPServerTest.py | 28 ++++++++
src/Microwave/demo/AutoSendAndGetTest.bat | 16 +++++
src/protos/compile.bat | 2
src/Microwave/demo/MicroWaveReceiverTest.py | 1
src/Microwave/demo/AutoSendUDPtest.bat | 22 +++++++
src/Microwave/demo/udp_test_get.py | 30 +++++++--
src/engine/__init__.py | 8 ++
env/JustDoubleClickMe.bat | 12 +++
src/Microwave/demo/udp_test_send.py | 1
src/Microwave/demo/AutoGetUDPtest.bat | 22 +++++++
src/Microwave/demo/AutoGetUDP.bat | 22 +++++++
11 files changed, 152 insertions(+), 12 deletions(-)
diff --git a/env/JustDoubleClickMe.bat b/env/JustDoubleClickMe.bat
index 65863eb..3fa2128 100644
--- a/env/JustDoubleClickMe.bat
+++ b/env/JustDoubleClickMe.bat
@@ -1,4 +1,14 @@
+@echo off
+
cd %~dp0
-SettingEnv.bat
+echo ========== Setting Env ==============
+call SettingEnv.bat
+echo setting done!
+echo ========== Testing Env ==============
+echo test it with hello word...
+set aerialpython=%cd%/aerial_deploy/python.exe
+%aerialpython% -c "import cv2, pika, flask, pika; print('hello world!')"
+echo =========== ALL DONE ================
+
echo Press any key to exit this windiow.
pause
\ No newline at end of file
diff --git a/src/Microwave/demo/AutoGetUDP.bat b/src/Microwave/demo/AutoGetUDP.bat
new file mode 100644
index 0000000..50193ba
--- /dev/null
+++ b/src/Microwave/demo/AutoGetUDP.bat
@@ -0,0 +1,22 @@
+@echo off
+
+@REM change to the filepath
+cd %~dp0
+echo change to path: %cd%
+
+set aerialpython=%cd%/../../../env/aerial_deploy/python.exe
+set envsetting=%cd%/env/SettingEnv.bat
+
+@REM Setting the env
+if not exist %aerialpython% (
+ %envsetting%
+)
+
+echo All data will be save in '%cd%/saveUDPData/' folder
+
+%aerialpython% udp_test_get.py test
+
+echo =========== ALL DONE ================
+
+echo Press any key to exit this windiow.
+pause
diff --git a/src/Microwave/demo/AutoGetUDPtest.bat b/src/Microwave/demo/AutoGetUDPtest.bat
new file mode 100644
index 0000000..23bba97
--- /dev/null
+++ b/src/Microwave/demo/AutoGetUDPtest.bat
@@ -0,0 +1,22 @@
+@echo off
+
+@REM change to the filepath
+cd %~dp0
+echo change to path: %cd%
+
+set aerialpython=%cd%/../../../env/aerial_deploy/python.exe
+set envsetting=%cd%/env/SettingEnv.bat
+
+@REM Setting the env
+if not exist %aerialpython% (
+ %envsetting%
+)
+
+echo All data will be saved in '%cd%/saveUDPData/' folder
+
+%aerialpython% udp_test_get.py test
+
+echo =========== ALL GET DONE ================
+
+echo Press any key to exit this windiow.
+pause
diff --git a/src/Microwave/demo/AutoSendAndGetTest.bat b/src/Microwave/demo/AutoSendAndGetTest.bat
new file mode 100644
index 0000000..c3029c1
--- /dev/null
+++ b/src/Microwave/demo/AutoSendAndGetTest.bat
@@ -0,0 +1,16 @@
+@echo off
+
+@REM change to the filepath
+cd %~dp0
+echo change to path: %cd%
+
+set aerialpython=%cd%/../../../env/aerial_deploy/python.exe
+set envsetting=%cd%/env/SettingEnv.bat
+
+@REM Setting the env
+if not exist %aerialpython% (
+ %envsetting%
+)
+
+start AutoGetUDPtest.bat
+start AutoSendUDPtest.bat
diff --git a/src/Microwave/demo/AutoSendUDPtest.bat b/src/Microwave/demo/AutoSendUDPtest.bat
new file mode 100644
index 0000000..79ca0d8
--- /dev/null
+++ b/src/Microwave/demo/AutoSendUDPtest.bat
@@ -0,0 +1,22 @@
+@echo off
+
+@REM change to the filepath
+cd %~dp0
+echo change to path: %cd%
+
+set aerialpython=%cd%/../../../env/aerial_deploy/python.exe
+set envsetting=%cd%/env/SettingEnv.bat
+
+@REM Setting the env
+if not exist %aerialpython% (
+ %envsetting%
+)
+
+echo All data saved in '%cd%/demoUDPData/' folder will be sent to 127.0.0.1:9911
+
+%aerialpython% udp_test_send.py
+
+echo =========== ALL SEND DONE ================
+
+echo Press any key to exit this windiow.
+pause
diff --git a/src/Microwave/demo/MicroWaveReceiverTest.py b/src/Microwave/demo/MicroWaveReceiverTest.py
index 56a3713..b7f8c21 100644
--- a/src/Microwave/demo/MicroWaveReceiverTest.py
+++ b/src/Microwave/demo/MicroWaveReceiverTest.py
@@ -28,3 +28,4 @@
print("Frame {} ready".format(frame_number))
with open(bin_name, "wb") as bin_file:
bin_file.write(receiver.DataFrame)
+ bin_file.close()
diff --git a/src/Microwave/demo/MicroWaveUDPServerTest.py b/src/Microwave/demo/MicroWaveUDPServerTest.py
index e35b64e..ddc2dd3 100644
--- a/src/Microwave/demo/MicroWaveUDPServerTest.py
+++ b/src/Microwave/demo/MicroWaveUDPServerTest.py
@@ -1,13 +1,37 @@
import sys
import time
import os
+from socketserver import BaseRequestHandler, UDPServer
# add python path of microwave to sys.path
microwave_path = os.path.join(__file__, *(['..'] * 3))
microwave_path = os.path.abspath(microwave_path)
sys.path.insert(0, microwave_path)
-from microwave.servers import MicroWaveUDPServer
+from microwave.servers import MicroWaveReceiver
+
+
+class MicroWaveRequestHandlertest(BaseRequestHandler):
+ def handle(self):
+ # Get message and client socket
+ buf, _ = self.request
+ receiver = self.server.Receiver
+ receiver.AddBuf(buf)
+ if receiver.DataFrameReady:
+ # data frame ready
+ frame_number = receiver.Header.FrameNumber
+ bin_name = os.path.join(self.server.OutputFolder, "{}.bin".format(frame_number))
+ print("Frame {} ready".format(frame_number))
+ with open(bin_name, "wb") as bin_file:
+ bin_file.write(receiver.DataFrame)
+
+
+class MicroWaveUDPServertest(UDPServer):
+ def __init__(self, server_address, output_folder):
+ super().__init__(server_address, MicroWaveRequestHandlertest)
+ # create receiver instance
+ self.Receiver = MicroWaveReceiver()
+ self.OutputFolder = output_folder
if __name__ == '__main__':
if len(sys.argv) == 2:
@@ -18,7 +42,7 @@
# host = '192.168.2.65'
host = ''
port = 9911
- server = MicroWaveUDPServer((host, port), output_folder)
+ server = MicroWaveUDPServertest((host, port), output_folder)
server.packed_count = 0
print(time.asctime(),'Server started on port', port)
print('....')
diff --git a/src/Microwave/demo/udp_test_get.py b/src/Microwave/demo/udp_test_get.py
index 26b0c16..c5bc283 100644
--- a/src/Microwave/demo/udp_test_get.py
+++ b/src/Microwave/demo/udp_test_get.py
@@ -1,6 +1,6 @@
from socketserver import BaseRequestHandler, UDPServer
import time
-import os
+import os, sys
cudir,_ = os.path.split(__file__)
@@ -12,30 +12,44 @@
packed_count = 0
-class PointCloudUDPServer(BaseRequestHandler):
+class PointCloudUDPRequestHandler(BaseRequestHandler):
def handle(self):
global packed_count
- print('Got connection from {}, {}'.format(self.client_address, packed_count))
+ print(time.asctime(),' Got connection from {}, {}'.format(self.client_address, packed_count))
# Get message and client socket
msg, sock = self.request
- f = open('{}/packet{:000006}.udp'.format(file_folder,packed_count), 'wb')
+ f = open('{}/packet{}.udp'.format(file_folder,packed_count), 'wb')
f.write(msg)
f.close()
packed_count += 1
- if packed_count >= 100:
+ if packed_count >= 1000000:
UDPServer.server_close(server)
if __name__ == '__main__':
+ def help():
+ print("Usage: udp_test_get.py [host]. host can be 'test' or 'microwave' ")
+ exit(1)
+
+ if len(sys.argv) == 2:
+ if sys.argv[1] == 'test':
+ host = ''
+ elif sys.argv[1] == 'microwave':
+ host = '192.168.2.65'
+ else:
+ help()
+ else:
+ help()
+
global server
- host = ''
- # host = '192.168.2.65'
+ # host = ''
+ # host = '192.168.2.65' # use this host to get the udp data from microwave device
port = 9911
- server =UDPServer((host, port), PointCloudUDPServer)
+ server =UDPServer((host, port), PointCloudUDPRequestHandler)
print(time.asctime(),'Server started on port', port)
print('....')
print('ctrl-c to quit server.')
diff --git a/src/Microwave/demo/udp_test_send.py b/src/Microwave/demo/udp_test_send.py
index 9911fc2..d23f81a 100644
--- a/src/Microwave/demo/udp_test_send.py
+++ b/src/Microwave/demo/udp_test_send.py
@@ -16,5 +16,6 @@
client_socket.settimeout(1.0)
addr = ("127.0.0.1", 9911)
client_socket.sendto(message, addr)
+ print (time.asctime(), f' Sending {file} to {addr} ...')
time.sleep(0.1)
print('Done!')
diff --git a/src/engine/__init__.py b/src/engine/__init__.py
index e69de29..2a904ab 100644
--- a/src/engine/__init__.py
+++ b/src/engine/__init__.py
@@ -0,0 +1,8 @@
+from .AcquisitionMain import *
+from .CaptureThread import *
+from .ControllThread import *
+from .DeviceManager import *
+from .DustCleaner import *
+from .DustCleanerThread import *
+from .MessageQueueThread import *
+from .MicroWaveUDPThread import *
\ No newline at end of file
diff --git a/src/protos/compile.bat b/src/protos/compile.bat
index 745ae31..530cd7a 100644
--- a/src/protos/compile.bat
+++ b/src/protos/compile.bat
@@ -4,7 +4,7 @@
cd %~dp0
echo change to path: %cd%
-set protoc=%cd%\..\..\env\aerial_deploy\Library\bin\protoc.exe
+set protoc=%cd%/../../env/aerial_deploy/Library/bin/protoc.exe
%protoc% aerial.proto --python_out=%cd%
--
Gitblit v1.9.1