优化udp通信代码,增加配电系统通信解析,增加能源系统状态定义

This commit is contained in:
zjk
2024-11-20 18:38:45 +08:00
parent 4693ce2619
commit eb2877f03f
9 changed files with 1123 additions and 153 deletions
+17 -8
View File
@@ -1,8 +1,8 @@
import socket
import time
import struct
from udpmsg import msg_CcuStateFbMsg
from udpmsg import msg_CcuSetParamFbMsg
from udpmsg import *
# 目标IP地址和端口
target_ip = '127.0.0.1'
target_port = 5000
@@ -10,9 +10,11 @@ target_port = 5000
mTest = msg_CcuStateFbMsg()
mTest2 = msg_CcuSetParamFbMsg()
mTest3 = msg_disHighVolBusFbMsg()
valid_msg = mTest.pack()
valid_msg2 = mTest2.pack()
valid_msg3 = mTest3.pack()
print(valid_msg)
@@ -21,22 +23,29 @@ sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# 要发送的信息
# message = "Hello, this is a test message."
message = valid_msg
message = valid_msg3
# 发送信息的次数
num_messages = 10
# 发送信息的时间间隔(秒)
interval = 1
interval = 0.1
for i in range(num_messages):
# 发送信息
sock.sendto(message, (target_ip, target_port))
sock.sendto(msg_CcuStateFbMsg().pack(), (target_ip, target_port))
time.sleep(interval)
sock.sendto(msg_CcuSetParamFbMsg().pack(), (target_ip, target_port))
time.sleep(interval)
sock.sendto(msg_disHighVolBusFbMsg().pack(), (target_ip, target_port))
time.sleep(interval)
sock.sendto(msg_disHighAVolBusFbMsg().pack(), (target_ip, target_port))
time.sleep(interval)
sock.sendto(msg_disHighBVolBusFbMsg().pack(), (target_ip, target_port))
time.sleep(interval)
sock.sendto(msg_disLowBusFbMsg().pack(), (target_ip, target_port))
# 打印发送的信息和目标地址
print(f"Sent message to {target_ip}:{target_port}")
# 等待一段时间
time.sleep(interval)
# sock.sendto(valid_msg2, (target_ip, target_port))
time.sleep(interval)