add basic web protocol
This commit is contained in:
parent
351aad8300
commit
f455af3589
|
@ -8,6 +8,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.OpenApi" Version="1.6.23" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
@ -6,9 +6,29 @@ class UDPClientPool
|
|||
{
|
||||
private static IPAddress localhost = IPAddress.Parse("127.0.0.1");
|
||||
|
||||
public UDPClientPool()
|
||||
public static void SendString(IPEndPoint endPoint, string[] stringArray)
|
||||
{
|
||||
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
|
||||
|
||||
byte[] sendbuf = Encoding.ASCII.GetBytes(stringArray[0]);
|
||||
|
||||
socket.SendTo(sendbuf, endPoint);
|
||||
}
|
||||
|
||||
public async static void AsyncSendString(IPEndPoint endPoint, string[] stringArray)
|
||||
{
|
||||
await Task.Run(() => { SendString(endPoint, stringArray); });
|
||||
}
|
||||
|
||||
public static void SendBytes(IPEndPoint endPoint, byte[] buf)
|
||||
{
|
||||
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
|
||||
socket.SendTo(buf, endPoint);
|
||||
}
|
||||
|
||||
public async static void AsyncSendBytes(IPEndPoint endPoint, byte[] buf)
|
||||
{
|
||||
await Task.Run(() => { SendBytes(endPoint, buf); });
|
||||
}
|
||||
|
||||
public static void SendLocalHost(int port, string[] stringArray)
|
||||
|
@ -34,8 +54,4 @@ class UDPClientPool
|
|||
Thread.Sleep(sleepMilliSeconds);
|
||||
}
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
namespace WebProtocol
|
||||
{
|
||||
|
||||
public enum PackSign
|
||||
{
|
||||
SendAddr = 0x00,
|
||||
SendData = 0xFF,
|
||||
RecvData = 0x0F,
|
||||
RecvResp = 0xF0,
|
||||
}
|
||||
|
||||
public enum BurstType
|
||||
{
|
||||
ExtendBurst = 0b00,
|
||||
FixedBurst = 0b01,
|
||||
}
|
||||
|
||||
public struct SendAddrPackage
|
||||
{
|
||||
readonly byte Sign = (byte)PackSign.SendAddr;
|
||||
readonly byte commandType;
|
||||
readonly byte burstLength;
|
||||
readonly byte _reserved;
|
||||
readonly UInt32 address;
|
||||
|
||||
|
||||
public SendAddrPackage(BurstType burstType, byte commandID, bool isWrite)
|
||||
{
|
||||
commandType = (
|
||||
((byte)burstType << 5) |
|
||||
((commandID & (byte)0x03) << 3) |
|
||||
(isWrite ? (byte)0x01 : (byte)0x00)
|
||||
);
|
||||
}
|
||||
|
||||
public void toBytes()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public struct RecvRackage
|
||||
{
|
||||
|
||||
public void toBytes()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue