Files
protocol_convert_software_BD3/core/link_manager.py

287 lines
11 KiB
Python
Raw Normal View History

# import threading
# from core.forward_engine import UdpForward, Tcp2UdpForward
# from config.settings import LOCAL_PORT, REMOTE
# # 导入转换器
# from converter.b_to_d import B2DConverter
# from converter.a_to_b import A2BConverter
# from converter.b_to_e import B2EConverter
# from converter.a_to_c import A2CConverter
# class LinkManager:
# def __init__(self):
# self.links = []
# def register_all(self):
# # B→D
# self.links.append(
# Tcp2UdpForward(
# remote_tcp_ip=REMOTE["B"]["ip"],
# remote_tcp_port=REMOTE["B"]["port"],
# udp_ip=REMOTE["D"]["ip"],
# udp_port=REMOTE["D"]["port"],
# converter=B2DConverter()
# )
# )
# # A→B
# self.links.append(
# UdpForward(
# local_port=LOCAL_PORT["A_B"],
# remote_ip=REMOTE["B"]["ip"],
# remote_port=REMOTE["B"]["port"],
# converter=A2BConverter()
# )
# )
# # A→C
# self.links.append(
# UdpForward(LOCAL_PORT["A_C"], REMOTE["C"]["ip"], REMOTE["C"]["port"], A2CConverter())
# )
# # B→E
# self.links.append(
# UdpForward(LOCAL_PORT["B_E"], REMOTE["E"]["ip"], REMOTE["E"]["port"], B2EConverter())
# )
# def start(self):
# for link in self.links:
# threading.Thread(target=link.loop, daemon=True).start()
import threading
from core.forward_engine import UdpForward, Tcp2UdpForward
from config.settings import LOCAL_PORT, REMOTE
from config_loader import cfg
from converter.b_to_d import B2DConverter
from converter.a_to_b import A2BConverter
from converter.b_to_e import B2EConverter
from converter.a_to_c import A2CConverter
# ==================== 新增导入 ====================
from converter.c_to_b import C2BConverter
from converter.c_to_a import C2AConverter
from core.single_to_dual import SingleToDualForward
from core.tcp_single_to_dual import TcpSingleToDualForward
#from core.a_to_b_forward import A2BForward
from core.a2b_forward import A2BForward
#from core.udp_c_remote import UdpRemoteC
from core.udp_c_remote import UdpCRemote
from core.f_to_a_forward import FToAForward # 新增导入
class LinkManager:
def __init__(self):
self.links = []
def register_all(self):
# # B→D
# self.links.append(
# Tcp2UdpForward(
# remote_tcp_ip=REMOTE["B"]["ip"],
# remote_tcp_port=REMOTE["B"]["port"],
# udp_ip=REMOTE["D"]["ip"],
# udp_port=REMOTE["D"]["port"],
# converter=B2DConverter()
# )
# )
# B → D转换 + B → C无条件转发2026/4/2 B软件换双端TC,TM后停用
# self.links.append(Tcp2UdpForward(
# remote_tcp_ip=REMOTE["B"]["ip"], remote_tcp_port=REMOTE["B"]["port"],
# udp_ip=REMOTE["D"]["ip"], udp_port=REMOTE["D"]["port"],
# converter=B2DConverter(),
# # 👇 新增:同时转发给 C
# forward_c_ip=REMOTE["C"]["ip"],
# forward_c_port=REMOTE["C"]["port"]
# ))
# ========== 1. B 遥测 3078 → D + C ==========2026/4/2更新 B软件换双端TC,TM
# self.links.append(Tcp2UdpForward(
# b_ip=REMOTE["B"]["ip"],
# b_telem_port=REMOTE["B"]["port_telem"], # 3078
# udp_d_ip=REMOTE["D"]["ip"],
# udp_d_port=REMOTE["D"]["port"],
# converter=B2DConverter(),
# c_ip=REMOTE["C"]["ip"],
# c_port=REMOTE["C"]["port"]
# ))
self.links.append(Tcp2UdpForward(
# 2026/4/7更新 使用config.ini配置文件
b_ip=cfg.get("REMOTE", "B_IP"),
b_telem_port=cfg.get_int("REMOTE", "B_TELEM_PORT"), # 3078
udp_d_ip=cfg.get("REMOTE", "D_IP"),
udp_d_port=cfg.get_int("REMOTE", "D_PORT"),
converter=B2DConverter(),
c_ip=cfg.get("REMOTE", "C_IP"),
c_port=cfg.get_int("REMOTE", "C_PORT"),
#2026/4/30新增G软件-数字卫星C通道遥测遥控转发
g_ip = cfg.get("REMOTE", "B2G_IP"),
g_port = cfg.get_int("REMOTE", "B2G_PORT"),
g_cmd_ip = cfg.get("REMOTE", "G_CMD_IP"),
g_cmd_port = cfg.get_int("REMOTE", "G_CMD_PORT"),
#2026/5/11 新增E软件遥控转发
e_ip = cfg.get("REMOTE", "E_IP"),
e_port = cfg.get_int("REMOTE", "E_PORT"),
))
# A→B 2026/4/2停用
# self.links.append(
# UdpForward(
# local_port=LOCAL_PORT["A_B"],
# remote_ip=REMOTE["B"]["ip"],
# remote_port=REMOTE["B"]["port_remote"], ### 暂时是遥控接口,以后要改
# converter=A2BConverter()
# )
# )
# A→C
self.links.append(
#UdpForward(LOCAL_PORT["A_C"], REMOTE["C"]["ip"], REMOTE["C"]["port"], A2CConverter())
UdpForward(cfg.get_int("LOCAL","A_C"), cfg.get("REMOTE","C_IP"), cfg.get_int("REMOTE","C_PORT"), A2CConverter())#2026/4/7更新 使用config.ini配置文件
)
# B→E
self.links.append(
#UdpForward(LOCAL_PORT["B_E"], REMOTE["E"]["ip"], REMOTE["E"]["port"], B2EConverter())
UdpForward(cfg.get_int("LOCAL","B_E"),cfg.get("REMOTE","E_IP"), cfg.get_int("REMOTE","E_PORT"), B2EConverter())#2026/4/7更新 使用config.ini配置文件
)
# # ==================== 新增两条链路 ====================
# # C → B 透传
# self.links.append(
# UdpForward(
# local_port=LOCAL_PORT["C_B"],
# remote_ip=REMOTE["B"]["ip"],
# remote_port=REMOTE["B"]["port"],
# converter=C2BConverter()
# )
# )
# # C → A 转发
# self.links.append(
# UdpForward(
# local_port=LOCAL_PORT["C_A"],
# remote_ip=REMOTE["A"]["ip"],
# remote_port=REMOTE["A"]["port"],
# converter=C2AConverter()
# )
# )
# ===================== 核心修改 =====================
# # C 单端口 → 同时发给 B 和 A
# self.links.append(SingleToDualForward(
# local_port=LOCAL_PORT["C"],
# # 发给 B
# tcp_target_ip=REMOTE["B"]["ip"],
# tcp_target_port=REMOTE["B"]["port"],
# converter_tcp=C2BConverter(),
# # 发给 A
# udp_target_ip=REMOTE["A"]["ip"],
# udp_target_port=REMOTE["A"]["port"],
# converter_udp=C2AConverter()
# ))
# ===================== 【C 改为 TCP】 2026/3/31停用=====================
# self.links.append(TcpSingleToDualForward(
# local_port=LOCAL_PORT["C"],
# # 转发 B
# tcp_target_ip=REMOTE["B"]["ip"],
# tcp_target_port=REMOTE["B"]["port"],
# converter_tcp=C2BConverter(),
# # 转发 A
# udp_target_ip=REMOTE["A"]["ip"],
# udp_target_port=REMOTE["A"]["port"],
# converter_udp=C2AConverter()
# ))
# # 在 register_all 中添加:
# self.links.append(
# A2BForward(
# local_port=LOCAL_PORT["A_LISTEN"],
# tcp_target_ip=REMOTE["B"]["ip"],
# tcp_target_port=REMOTE["B"]["port"]
# )
# )
'''
# 在 register_all 末尾加A-B
self.links.append(
A2BForward(
#local_port=7100,
local_port=LOCAL_PORT["A_B"], #2026/4/2改
tcp_ip=REMOTE["B"]["ip"],
#tcp_port=REMOTE["B"]["port"]
tcp_port=REMOTE["B"]["port_remote"] ##2026/4/2暂时改为遥控接口以后要改
)
)
'''
# A-B 2026/4/3
self.links.append(
A2BForward(
#local_port=LOCAL_PORT["A_B"], #REMOTE["A"]["port"], #2026/4/3改
local_port=cfg.get_int("LOCAL", "A_B"),
#b_ip=REMOTE["B"]["ip"],
b_ip=cfg.get("REMOTE", "B_IP"),#2026/4/7
#b_udp_port=REMOTE["B"]["port_udp"] # B UDP 端口
b_udp_port=cfg.get_int("REMOTE", "B_UDP_PORT")#2026/4/7
)
)
# ===================== C(UDP)遥控 → A + B =====================2026/4/2停用 B软件换双端TC,TM
# self.links.append(
# UdpRemoteC(
# local_port=6004, # C 发指令的 UDP 目标端口
# a_ip=REMOTE["A"]["ip"],
# a_port=REMOTE["A"]["port"],
# b_ip=REMOTE["B"]["ip"],
# b_port=REMOTE["B"]["port"],
# converter=C2AConverter() # 你原有遥控指令转换器
# )
# )
# ========== 2. C UDP 遥控 → A + B 3028 ========== 2026/4/2更新 B软件换双端TC,TM
self.links.append(
#UdpRemoteC(
UdpCRemote(
# local_udp_port=6004,
# a_ip=REMOTE["A"]["ip"],
# a_port=REMOTE["A"]["port"],
# b_ip=REMOTE["B"]["ip"],
# b_remote_port=REMOTE["B"]["port_remote"], # 3028
#local_udp_port=cfg.get_int("LOCAL", "C_AB"),#2026/4/7,
local_port=cfg.get_int("LOCAL", "C_AB"),#2026/4/7,
a_ip=cfg.get("REMOTE", "A_IP"),
a_port=cfg.get_int("REMOTE", "A_PORT"),
b_ip=cfg.get("REMOTE", "B_IP"),
b_remote_port=cfg.get_int("REMOTE", "B_REMOTE_PORT"), # 3028
b_gis_port = cfg.get_int("REMOTE","B_DICE_PORT"), # 2026/4/11新增
converter=C2AConverter(),
#2026/4//30新增E专项G测控C通道软件转发
e_ip=cfg.get("REMOTE", "E_IP"),
e_port=cfg.get_int("REMOTE", "E_PORT"),
g_ip=cfg.get("REMOTE", "G_CMD_IP"),
g_port=cfg.get_int("REMOTE", "G_CMD_PORT")
))
# ========== F → A 转发 新增 ==========2026/4/11废弃
# self.links.append(
# FToAForward(
# local_port=cfg.get_int("LOCAL", "UDP_F_LISTEN_PORT"),
# a_ip=cfg.get("REMOTE", "A_IP"),
# a_port=cfg.get_int("REMOTE", "A_PORT")
# )
# )
self.links.append(#7786
FToAForward(
f_ip=cfg.get("REMOTE", "F_IP"),
f_port=cfg.get_int("REMOTE", "F_PORT"),
a_ip=cfg.get("REMOTE", "A_IP"),
a_port=cfg.get_int("REMOTE", "A_FROM_B_PORT")
)
)
def start(self):
for link in self.links:
threading.Thread(target=link.loop, daemon=True).start()