|
|
|
|
@ -13,29 +13,93 @@ import mavlinkObject as mo
|
|
|
|
|
|
|
|
|
|
# ====================== 分割線 =====================
|
|
|
|
|
|
|
|
|
|
test_item = 3
|
|
|
|
|
test_item = 12
|
|
|
|
|
print('test_item : ', test_item)
|
|
|
|
|
|
|
|
|
|
if test_item == 1:
|
|
|
|
|
# 測試 updateMultiplexingList 的輸出
|
|
|
|
|
print('===> Start of Program .Test ', test_item)
|
|
|
|
|
mavlink_object_none = mo.mavlink_object(None)
|
|
|
|
|
|
|
|
|
|
print('=====================')
|
|
|
|
|
print('正常範例')
|
|
|
|
|
mavlink_object_none.multiplexingToAnalysis = []
|
|
|
|
|
mavlink_object_none.multiplexingToReturn = []
|
|
|
|
|
# mavlink_object_none.multiplexingToSwap = [[]]
|
|
|
|
|
ret = mavlink_object_none.updateMultiplexingList()
|
|
|
|
|
print('execute result : ', ret)
|
|
|
|
|
print('multiplexingList : ', mavlink_object_none._multiplexingList)
|
|
|
|
|
|
|
|
|
|
print('=====================')
|
|
|
|
|
print('錯誤範例 長度不一致')
|
|
|
|
|
mavlink_object_none.multiplexingToSwap = [[-1], [11,12,13], [14,15,16],]
|
|
|
|
|
ret = mavlink_object_none.updateMultiplexingList()
|
|
|
|
|
print('execute result : ', ret)
|
|
|
|
|
|
|
|
|
|
print('=====================')
|
|
|
|
|
print('正常範例')
|
|
|
|
|
mo.swap_queues.append(queue.Queue())
|
|
|
|
|
mo.swap_queues.append(queue.Queue())
|
|
|
|
|
mavlink_object_none.multiplexingToAnalysis = [0, 1, 2, 3, 4, 5]
|
|
|
|
|
mavlink_object_none.multiplexingToReturn = [6, 7, 8, 9, 10]
|
|
|
|
|
mavlink_object_none.multiplexingToSwap = [[-1], [11,12,13], [14,15,16],]
|
|
|
|
|
ret = mavlink_object_none.updateMultiplexingList()
|
|
|
|
|
print('execute result : ', ret)
|
|
|
|
|
print('multiplexingList : ', mavlink_object_none._multiplexingList)
|
|
|
|
|
|
|
|
|
|
print('=====================')
|
|
|
|
|
print('錯誤範例 multiplexingToAnalysis 不可以有 -1')
|
|
|
|
|
mavlink_object_none.multiplexingToAnalysis = [-1, 1, 2, 3, 4, 5]
|
|
|
|
|
ret = mavlink_object_none.updateMultiplexingList()
|
|
|
|
|
print('execute result : ', ret)
|
|
|
|
|
|
|
|
|
|
print('End of Program')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elif test_item == 2:
|
|
|
|
|
# 測試 updateMultiplexingList 的輸出
|
|
|
|
|
print('===> Start of Program .Test ', test_item)
|
|
|
|
|
mavlink_object_none1 = mo.mavlink_object(None)
|
|
|
|
|
mavlink_object_none2 = mo.mavlink_object(None)
|
|
|
|
|
mavlink_object_none3 = mo.mavlink_object(None)
|
|
|
|
|
del mavlink_object_none2
|
|
|
|
|
|
|
|
|
|
print(len(mo.swap_queues))
|
|
|
|
|
|
|
|
|
|
mavlink_object_none2 = mo.mavlink_object(None)
|
|
|
|
|
print(len(mo.swap_queues))
|
|
|
|
|
|
|
|
|
|
print(mavlink_object_none1._multiplexingList)
|
|
|
|
|
|
|
|
|
|
print('End of Program')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elif test_item == 10:
|
|
|
|
|
# 這邊是測試代碼 運行10秒 過程中把三個 queue 的資料印出來
|
|
|
|
|
# 只啟用了 mavlink_object 的功能
|
|
|
|
|
print('Start of Program .Test 1')
|
|
|
|
|
print('===> Start of Program .Test ', test_item)
|
|
|
|
|
mavlink_object_none = mo.mavlink_object(None)
|
|
|
|
|
|
|
|
|
|
connection_string="udp:127.0.0.1:14550"
|
|
|
|
|
mavlink_socket = mavutil.mavlink_connection(connection_string)
|
|
|
|
|
|
|
|
|
|
mavlink_object1 = mo.mavlink_object(mavlink_socket)
|
|
|
|
|
|
|
|
|
|
print(mavlink_object1.multiplexingToSwap)
|
|
|
|
|
print(mo.swap_queues)
|
|
|
|
|
mavlink_object1.multiplexingToAnalysis = [30] # only ATTITUDE
|
|
|
|
|
mavlink_object1.multiplexingToReturn = [0] # only HEARTBEAT
|
|
|
|
|
mavlink_object1.multiplexingToConvert = [[74,]] # only VFR_HUD
|
|
|
|
|
mavlink_object1.multiplexingToSwap[0] = [74, ] # only VFR_HUD
|
|
|
|
|
# mavlink_object1.multiplexingToSwap[0] = [-1, ] # all
|
|
|
|
|
|
|
|
|
|
# 做一個空的 queue list 驗證 multiplexingToConvert
|
|
|
|
|
mo.swap_queues.append(queue.Queue())
|
|
|
|
|
# 啟動連線的模組
|
|
|
|
|
mavlink_object1.run()
|
|
|
|
|
|
|
|
|
|
print(mavlink_object1._multiplexingList)
|
|
|
|
|
|
|
|
|
|
# 運行幾秒並印出 queue 的資料
|
|
|
|
|
start_time = time.time()
|
|
|
|
|
while time.time() - start_time < 2:
|
|
|
|
|
while time.time() - start_time < 3:
|
|
|
|
|
while not mo.fixed_stream_bridge_queue.empty():
|
|
|
|
|
print('fixed_stream_bridge_queue:')
|
|
|
|
|
t = mo.fixed_stream_bridge_queue.get()
|
|
|
|
|
@ -43,32 +107,35 @@ if test_item == 1:
|
|
|
|
|
while not mo.return_packet_processor_queue.empty():
|
|
|
|
|
print('return_packet_processor_queue:')
|
|
|
|
|
t = mo.return_packet_processor_queue.get()
|
|
|
|
|
# print('from {} : {}'.format(t[0],t[2]))
|
|
|
|
|
print(t[2].type)
|
|
|
|
|
print('from {} : {}'.format(t[0],t[2]))
|
|
|
|
|
# print(t[2].get_msgbuf())
|
|
|
|
|
# print(t[2].type)
|
|
|
|
|
|
|
|
|
|
for q in mo.swap_queues:
|
|
|
|
|
for n in range(len(mo.swap_queues)):
|
|
|
|
|
q = mo.swap_queues[n]
|
|
|
|
|
while not q.empty():
|
|
|
|
|
print('swap_queues:')
|
|
|
|
|
t = q.get()
|
|
|
|
|
print('from {} : {}'.format(t[0],t[2]))
|
|
|
|
|
print('{} gets : {}'.format(n,t))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 結束程式 退出所有 thread
|
|
|
|
|
mavlink_object1.running = False
|
|
|
|
|
mavlink_object1.thread.join()
|
|
|
|
|
mavlink_socket.close()
|
|
|
|
|
print('End of Program .Test 1')
|
|
|
|
|
print('End of Program')
|
|
|
|
|
|
|
|
|
|
elif test_item == 2:
|
|
|
|
|
|
|
|
|
|
elif test_item == 11:
|
|
|
|
|
# 這邊是測試代碼 確認 analyzer 運行後對於 device object 的建立與封包統計狀況
|
|
|
|
|
# 啟用 mavlink_object 與 mavlink_bridge的thread區塊 的功能
|
|
|
|
|
print('Start of Program .Test 2')
|
|
|
|
|
print('===> Start of Program .Test ', test_item)
|
|
|
|
|
connection_string="udp:127.0.0.1:14550"
|
|
|
|
|
mavlink_socket = mavutil.mavlink_connection(connection_string)
|
|
|
|
|
|
|
|
|
|
mavlink_object2 = mo.mavlink_object(mavlink_socket)
|
|
|
|
|
mavlink_object2.multiplexingToAnalysis = [0] # only HEARTBEAT
|
|
|
|
|
mavlink_object2.multiplexingToReturn = [] # only HEARTBEAT
|
|
|
|
|
mavlink_object2.multiplexingToConvert = [] #
|
|
|
|
|
mavlink_object2.multiplexingToReturn = []
|
|
|
|
|
|
|
|
|
|
# 啟動 mavlink_bridge
|
|
|
|
|
analyzer = mo.mavlink_bridge()
|
|
|
|
|
@ -105,11 +172,137 @@ elif test_item == 2:
|
|
|
|
|
analyzer = mo.mavlink_bridge() # 這邊是測試是否只有一個 instance
|
|
|
|
|
analyzer.thread.join()
|
|
|
|
|
mavlink_socket.close()
|
|
|
|
|
print('End of Program .Test 2')
|
|
|
|
|
print('End of Program')
|
|
|
|
|
|
|
|
|
|
elif test_item == 12:
|
|
|
|
|
# 我這邊會測試 mavlink object 作為交換器的功能
|
|
|
|
|
print('===> Start of Program .Test ', test_item)
|
|
|
|
|
|
|
|
|
|
# 初始化兩個通道
|
|
|
|
|
connection_string_in="udp:127.0.0.1:15551"
|
|
|
|
|
mavlink_socket_in = mavutil.mavlink_connection(connection_string_in)
|
|
|
|
|
|
|
|
|
|
mavlink_object_in = mo.mavlink_object(mavlink_socket_in)
|
|
|
|
|
mavlink_object_in.multiplexingToAnalysis = [0] # only HEARTBEAT
|
|
|
|
|
|
|
|
|
|
connection_string_out="udpout:127.0.0.1:14553"
|
|
|
|
|
mavlink_socket_out = mavutil.mavlink_connection(connection_string_out, source_system=17, source_component=200)
|
|
|
|
|
|
|
|
|
|
mavlink_object_out = mo.mavlink_object(mavlink_socket_out)
|
|
|
|
|
mavlink_object_out.multiplexingToAnalysis = [0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 讓兩個通道互相傳輸
|
|
|
|
|
mavlink_object_in.multiplexingToSwap[mavlink_object_out.socket_id] = [-1, ] # all
|
|
|
|
|
mavlink_object_out.multiplexingToSwap[mavlink_object_in.socket_id] = [-1, ] # all
|
|
|
|
|
|
|
|
|
|
# 做一個空的通道驗證
|
|
|
|
|
mavlink_object_none = mo.mavlink_object(None)
|
|
|
|
|
# mavlink_object_out.multiplexingToSwap[mavlink_object_none.socket_id] = [-1, ] # all
|
|
|
|
|
|
|
|
|
|
# 啟動連線的模組
|
|
|
|
|
analyzer = mo.mavlink_bridge()
|
|
|
|
|
|
|
|
|
|
# 啟動通道
|
|
|
|
|
mavlink_object_in.run()
|
|
|
|
|
mavlink_object_out.run()
|
|
|
|
|
|
|
|
|
|
start_time = time.time()
|
|
|
|
|
show_time = time.time()
|
|
|
|
|
print("connection established!")
|
|
|
|
|
|
|
|
|
|
print(type(mavlink_socket_out))
|
|
|
|
|
print(type(mavlink_socket_out.mav))
|
|
|
|
|
|
|
|
|
|
while time.time() - start_time < 10:
|
|
|
|
|
try:
|
|
|
|
|
test = mo.swap_queues[mavlink_object_none.socket_id].get(block=False)
|
|
|
|
|
print('none object : ', test)
|
|
|
|
|
except queue.Empty:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
if (time.time() - show_time) >= 2:
|
|
|
|
|
show_time = time.time()
|
|
|
|
|
for sysid in analyzer.mavlink_systems:
|
|
|
|
|
for compid in analyzer.mavlink_systems[sysid].components:
|
|
|
|
|
print("Sysid : {} ,目前收到的訊息數量 : {}".format(sysid, analyzer.mavlink_systems[sysid].components[compid].msg_count))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
analyzer.mavlink_systems[sysid].resetComponentPacketCount(compid)
|
|
|
|
|
print("===================")
|
|
|
|
|
|
|
|
|
|
print('目前所有的系統 : ')
|
|
|
|
|
for sysid in analyzer.mavlink_systems:
|
|
|
|
|
print(analyzer.mavlink_systems[sysid])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 結束程式 退出所有 thread
|
|
|
|
|
mavlink_object_in.stop()
|
|
|
|
|
mavlink_object_in.thread.join()
|
|
|
|
|
mavlink_object_out.stop()
|
|
|
|
|
mavlink_object_out.thread.join()
|
|
|
|
|
mavlink_socket_in.close()
|
|
|
|
|
mavlink_socket_out.close()
|
|
|
|
|
|
|
|
|
|
analyzer.stop()
|
|
|
|
|
print('End of Program')
|
|
|
|
|
|
|
|
|
|
elif test_item == 20:
|
|
|
|
|
sysid = 1
|
|
|
|
|
compid = 1
|
|
|
|
|
|
|
|
|
|
# 這邊測試 node 生成 topic 的功能
|
|
|
|
|
rclpy.init() # 注意要初始化 rclpy 才能使用 node
|
|
|
|
|
# mavlink_object_none = mo.mavlink_object(None)
|
|
|
|
|
|
|
|
|
|
# 啟動 mavlink_bridge
|
|
|
|
|
analyzer = mo.mavlink_bridge()
|
|
|
|
|
|
|
|
|
|
from pymavlink.dialects.v20 import common as mavlink2
|
|
|
|
|
|
|
|
|
|
mav = mavlink2.MAVLink(None)
|
|
|
|
|
mav.srcSystem = sysid
|
|
|
|
|
mav.srcComponent = compid
|
|
|
|
|
|
|
|
|
|
# 這是一個 heartbeat 封包
|
|
|
|
|
fake_heartbeat = mavlink2.MAVLink_heartbeat_message(
|
|
|
|
|
type=mavlink2.MAV_TYPE_QUADROTOR,
|
|
|
|
|
autopilot=mavlink2.MAV_AUTOPILOT_ARDUPILOTMEGA,
|
|
|
|
|
base_mode=3,
|
|
|
|
|
custom_mode=0,
|
|
|
|
|
system_status=0,
|
|
|
|
|
mavlink_version=3
|
|
|
|
|
)
|
|
|
|
|
mavlink_bytes = fake_heartbeat.pack(mav)
|
|
|
|
|
fake_heartbeat_msg = mav.parse_char(mavlink_bytes)
|
|
|
|
|
|
|
|
|
|
print(analyzer.mavlink_systems)
|
|
|
|
|
|
|
|
|
|
mo.fixed_stream_bridge_queue.put((0, 0, fake_heartbeat_msg)) # socket id, timestamp, data
|
|
|
|
|
time.sleep(0.1)
|
|
|
|
|
print(analyzer.mavlink_systems)
|
|
|
|
|
|
|
|
|
|
analyzer._init_node()
|
|
|
|
|
|
|
|
|
|
analyzer.create_flightMode(sysid, analyzer.mavlink_systems[sysid].components[compid]) # sysid, compid
|
|
|
|
|
print("topic created")
|
|
|
|
|
time.sleep(5)
|
|
|
|
|
|
|
|
|
|
analyzer.emit_info()
|
|
|
|
|
|
|
|
|
|
# 結束程式
|
|
|
|
|
analyzer.running = False
|
|
|
|
|
analyzer.destroy_node()
|
|
|
|
|
|
|
|
|
|
rclpy.shutdown()
|
|
|
|
|
analyzer.stop()
|
|
|
|
|
analyzer.thread.join()
|
|
|
|
|
print('End of Program')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elif test_item == 3:
|
|
|
|
|
elif test_item == 21:
|
|
|
|
|
# 這邊是測試代碼 引入 rclpy 來測試 node 的運行
|
|
|
|
|
print('Start of Program .Test 3')
|
|
|
|
|
print('===> Start of Program .Test ', test_item)
|
|
|
|
|
rclpy.init() # 注意要初始化 rclpy 才能使用 node
|
|
|
|
|
connection_string="udp:127.0.0.1:14550"
|
|
|
|
|
mavlink_socket = mavutil.mavlink_connection(connection_string)
|
|
|
|
|
@ -117,7 +310,7 @@ elif test_item == 3:
|
|
|
|
|
mavlink_object3 = mo.mavlink_object(mavlink_socket)
|
|
|
|
|
mavlink_object3.multiplexingToAnalysis = [0] # only HEARTBEAT
|
|
|
|
|
mavlink_object3.multiplexingToReturn = [] # only HEARTBEAT
|
|
|
|
|
mavlink_object3.multiplexingToConvert = [] #
|
|
|
|
|
mavlink_object3.multiplexingToSwap = [] #
|
|
|
|
|
|
|
|
|
|
# 啟動 mavlink_bridge
|
|
|
|
|
analyzer = mo.mavlink_bridge()
|
|
|
|
|
@ -163,4 +356,4 @@ elif test_item == 3:
|
|
|
|
|
analyzer.thread.join()
|
|
|
|
|
|
|
|
|
|
mavlink_socket.close()
|
|
|
|
|
print('End of Program .Test 3')
|
|
|
|
|
print('End of Program')
|
|
|
|
|
|