第一次提交至Git
This commit is contained in:
18
AUTS_DataService/UtsWeb/CheckSum.vb
Normal file
18
AUTS_DataService/UtsWeb/CheckSum.vb
Normal file
@@ -0,0 +1,18 @@
|
||||
Public Class CheckSum
|
||||
''' <summary>
|
||||
''' 获取数据包的和校验
|
||||
''' </summary>
|
||||
''' <param name="packet">数据包的内容</param>
|
||||
''' <returns></returns>
|
||||
Public Shared Function GetPacketCheck(packet() As Byte) As Byte
|
||||
Dim result As Integer
|
||||
|
||||
'当packet的相加综合超过INT_MAX则会异常
|
||||
For Each b As Byte In packet
|
||||
result += b
|
||||
Next
|
||||
|
||||
Return CByte(&HFF - (result And &HFF))
|
||||
End Function
|
||||
|
||||
End Class
|
||||
5
AUTS_DataService/UtsWeb/IDataPacket.vb
Normal file
5
AUTS_DataService/UtsWeb/IDataPacket.vb
Normal file
@@ -0,0 +1,5 @@
|
||||
Public Interface IDataPacket
|
||||
Function FillPacket(cmd As Byte, param() As Byte) As Byte()
|
||||
Function CheckPacket(packet() As Byte) As Boolean
|
||||
|
||||
End Interface
|
||||
194
AUTS_DataService/UtsWeb/UtsWebPacket.vb
Normal file
194
AUTS_DataService/UtsWeb/UtsWebPacket.vb
Normal file
@@ -0,0 +1,194 @@
|
||||
Imports System.Net
|
||||
|
||||
Public Class UtsWebPacket
|
||||
Implements IDataPacket
|
||||
|
||||
Private _packetSn As Integer
|
||||
|
||||
Sub New()
|
||||
_packetSn = 0
|
||||
End Sub
|
||||
|
||||
|
||||
Public Function FillPacket(cmd As Byte) As Byte()
|
||||
Dim packet(PacketBits.Command) As Byte
|
||||
packet(PacketBits.Head) = &HAA
|
||||
packet(PacketBits.SerialNumber) = CByte(_packetSn)
|
||||
packet(PacketBits.ParamLength) = &H0
|
||||
packet(PacketBits.ParamLength + 1) = &H0
|
||||
packet(PacketBits.CheckValue) = &H0
|
||||
packet(PacketBits.Command) = cmd
|
||||
packet(PacketBits.CheckValue) = CheckSum.GetPacketCheck(packet)
|
||||
|
||||
_packetSn += 1
|
||||
If _packetSn > &HFF Then _packetSn = 0
|
||||
Return packet
|
||||
End Function
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 用于填充发送包
|
||||
''' </summary>
|
||||
''' <param name="cmd">发送包命令</param>
|
||||
''' <param name="param">发送包参数</param>
|
||||
''' <returns></returns>
|
||||
Public Function FillPacket(cmd As Byte, param() As Byte) As Byte() Implements IDataPacket.FillPacket
|
||||
Dim packet(PacketBits.Command + param.Length) As Byte
|
||||
packet(PacketBits.Head) = &HAA
|
||||
packet(PacketBits.SerialNumber) = CByte(_packetSn)
|
||||
Array.Copy(BitConverter.GetBytes(CShort(param.Length)), 0, packet, PacketBits.ParamLength, 2)
|
||||
packet(PacketBits.CheckValue) = &H0
|
||||
packet(PacketBits.Command) = cmd
|
||||
|
||||
Array.Copy(param, 0, packet, PacketBits.Param, param.Length)
|
||||
packet(PacketBits.CheckValue) = CheckSum.GetPacketCheck(packet)
|
||||
|
||||
_packetSn += 1
|
||||
If _packetSn > &HFF Then _packetSn = 0
|
||||
Return packet
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' 一般用于填充回复包
|
||||
''' </summary>
|
||||
''' <param name="sn">接收包序号</param>
|
||||
''' <param name="cmd">接收包命令</param>
|
||||
''' <param name="param">回复包参数</param>
|
||||
''' <returns></returns>
|
||||
Public Function FillPacket(sn As Byte, cmd As Byte, param() As Byte) As Byte()
|
||||
Dim packet(PacketBits.Command + param.Length) As Byte
|
||||
packet(PacketBits.Head) = &HAA
|
||||
packet(PacketBits.SerialNumber) = sn
|
||||
Array.Copy(BitConverter.GetBytes(CShort(param.Length)), 0, packet, PacketBits.ParamLength, 2)
|
||||
packet(PacketBits.CheckValue) = &H0
|
||||
packet(PacketBits.Command) = cmd
|
||||
|
||||
Array.Copy(param, 0, packet, PacketBits.Param, param.Length)
|
||||
|
||||
packet(PacketBits.CheckValue) = CheckSum.GetPacketCheck(packet)
|
||||
|
||||
Return packet
|
||||
End Function
|
||||
|
||||
|
||||
Public Function CheckPacket(packet() As Byte) As Boolean Implements IDataPacket.CheckPacket
|
||||
If packet(PacketBits.Head) <> &HAA Then
|
||||
Throw New Exception($"Invalid Packet Head!Src:{packet(PacketBits.Head)} Dest:{&HAA}")
|
||||
End If
|
||||
|
||||
'If packet(PacketBits.SerialNumber) <> _packetSn Then
|
||||
' Throw New Exception($"Invalid Packet Sn!Src: {packet(PacketBits.SerialNumber)} Dest:{_packetSn}")
|
||||
'End If
|
||||
|
||||
Dim destLength As Integer = packet.Length - PacketBits.Param
|
||||
|
||||
If BitConverter.ToInt16(packet, PacketBits.ParamLength) <> destLength Then
|
||||
Throw New Exception($"Invalid Packet Lengnt!Src:{packet(PacketBits.ParamLength)} Dest:{destLength}")
|
||||
End If
|
||||
|
||||
If CheckSum.GetPacketCheck(packet) <> &H0 Then
|
||||
Throw New Exception($"Invalid Packet CheckValue!Src:{BitConverter.ToString(packet)}")
|
||||
End If
|
||||
|
||||
Return True
|
||||
End Function
|
||||
|
||||
|
||||
Enum PacketBits
|
||||
''' <summary>包头</summary>
|
||||
Head
|
||||
|
||||
''' <summary>序号</summary>
|
||||
SerialNumber
|
||||
|
||||
''' <summary>包长,两位,小端模式</summary>
|
||||
ParamLength
|
||||
|
||||
''' <summary>校验</summary>
|
||||
CheckValue = ParamLength + 2
|
||||
|
||||
''' <summary>命令</summary>
|
||||
Command
|
||||
|
||||
''' <summary>参数</summary>
|
||||
Param
|
||||
End Enum
|
||||
|
||||
|
||||
<Flags>
|
||||
Enum Commands
|
||||
''' <summary>心跳包</summary>
|
||||
Heartbeat = &H1
|
||||
|
||||
|
||||
''' <summary>设置日志上报</summary>
|
||||
SetLogType = &H2
|
||||
|
||||
''' <summary>读取日志上报</summary>
|
||||
GetLogType = &H3
|
||||
|
||||
|
||||
''' <summary>服务任务状态变化时,主动上报状态</summary>
|
||||
UploadTaskStatus = &H10
|
||||
|
||||
''' <summary>增加服务任务</summary>
|
||||
AddServiceTask = &H11
|
||||
|
||||
''' <summary>删除服务任务</summary>
|
||||
DelServiceTask = &H12
|
||||
|
||||
''' <summary>获取服务任务</summary>
|
||||
GetServiceTask = &H13
|
||||
|
||||
''' <summary>设置服务任务</summary>
|
||||
SetServiceTask = &H14
|
||||
|
||||
''' <summary>开启服务任务</summary>
|
||||
StartServiceTask = &H15
|
||||
|
||||
''' <summary>停止服务任务</summary>
|
||||
StopServiceTask = &H16
|
||||
|
||||
''' <summary>重启服务任务</summary>
|
||||
RestartServiceTask = &H17
|
||||
|
||||
|
||||
''' <summary>上传文件</summary>
|
||||
UploadFile = &H21
|
||||
|
||||
''' <summary>读取指定文件大小</summary>
|
||||
ReadFileSize = &H22
|
||||
|
||||
|
||||
''' <summary>App状态变化时,主动上报状态</summary>
|
||||
UploadAppStatus = &H30
|
||||
|
||||
''' <summary>获取App状态</summary>
|
||||
GetAppStatus = &H31
|
||||
|
||||
''' <summary>设置App状态</summary>
|
||||
SetAppStatus = &H32
|
||||
|
||||
End Enum
|
||||
|
||||
|
||||
Public Class PublicIpChangedEventArgs
|
||||
Inherits EventArgs
|
||||
|
||||
Sub New(ip As IPAddress)
|
||||
PublicIP = ip
|
||||
End Sub
|
||||
|
||||
Public Property PublicIP As IPAddress
|
||||
End Class
|
||||
|
||||
Public Class AddTaskEventArgs
|
||||
Inherits EventArgs
|
||||
|
||||
Sub New(jsonString As String)
|
||||
Me.JsonString = jsonString
|
||||
End Sub
|
||||
|
||||
Public Property JsonString As String
|
||||
End Class
|
||||
End Class
|
||||
Reference in New Issue
Block a user