first
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
using Common.Net.Tcp;
|
||||
using System.Net;
|
||||
|
||||
namespace FASS.Extend.Call
|
||||
{
|
||||
public class Command
|
||||
{
|
||||
public TcpClient Client { get; private set; }
|
||||
|
||||
public Command(string ip, string port)
|
||||
{
|
||||
Client = new TcpClient()
|
||||
{
|
||||
RemoteEndPoint = new IPEndPoint(IPAddress.Parse(ip), int.Parse(port)),
|
||||
SendTimeout = 500,
|
||||
ReceiveTimeout = 500
|
||||
};
|
||||
}
|
||||
|
||||
public bool GetButton(string buttonNo)
|
||||
{
|
||||
var result = false;
|
||||
try
|
||||
{
|
||||
Client.Connect();
|
||||
var sendMessage = new SendMessage().SetMessage(byte.Parse(buttonNo));
|
||||
var sendByteArray = sendMessage.GetByteArray();
|
||||
var receiveByteArray = Client.SendAndReceive(sendByteArray);
|
||||
if (receiveByteArray is not null)
|
||||
{
|
||||
var receiveMessage = new ReceiveMessage().GetMessage(receiveByteArray);
|
||||
if (receiveMessage is not null && receiveMessage.ButtonStatus > 0)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
if (receiveByteArray is not null)
|
||||
{
|
||||
if (receiveByteArray.Length == 7 && receiveByteArray[3] > 0)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
if (receiveByteArray.Length == 11 && receiveByteArray[2] > 0)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Client.Disconnect();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>2.4.2</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Common.Net" Version="2.4.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,42 @@
|
||||
namespace FASS.Extend.Call
|
||||
{
|
||||
public class ReceiveMessage
|
||||
{
|
||||
public byte Begin { get; set; }
|
||||
public byte Length { get; set; }
|
||||
public byte ButtonNo { get; set; }
|
||||
public byte ButtonStatus { get; set; }
|
||||
public byte Power { get; set; }
|
||||
public byte RSSI { get; set; }
|
||||
public byte QOS { get; set; }
|
||||
|
||||
public ReceiveMessage? GetMessage(byte[] byteArray)
|
||||
{
|
||||
if (byteArray == null || byteArray.Length != 7)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Begin = byteArray[0];
|
||||
Length = byteArray[1];
|
||||
ButtonNo = byteArray[2];
|
||||
ButtonStatus = byteArray[3];
|
||||
Power = byteArray[4];
|
||||
RSSI = byteArray[5];
|
||||
QOS = byteArray[6];
|
||||
return this;
|
||||
}
|
||||
|
||||
public byte[] GetByteArray()
|
||||
{
|
||||
var byteArray = new byte[7];
|
||||
byteArray[0] = Begin;
|
||||
byteArray[1] = Length;
|
||||
byteArray[2] = ButtonNo;
|
||||
byteArray[3] = ButtonStatus;
|
||||
byteArray[4] = Power;
|
||||
byteArray[5] = RSSI;
|
||||
byteArray[6] = QOS;
|
||||
return byteArray;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
namespace FASS.Extend.Call
|
||||
{
|
||||
public class SendMessage
|
||||
{
|
||||
public byte Begin { get; set; }
|
||||
public byte Length { get; set; }
|
||||
public byte ButtonNo { get; set; }
|
||||
|
||||
public SendMessage SetMessage(byte buttonNo)
|
||||
{
|
||||
Begin = 0x1A;
|
||||
Length = 0x01;
|
||||
ButtonNo = buttonNo;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SendMessage? GetMessage(byte[] byteArray)
|
||||
{
|
||||
if (byteArray == null || byteArray.Length != 3)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Begin = byteArray[0];
|
||||
Length = byteArray[1];
|
||||
ButtonNo = byteArray[2];
|
||||
return this;
|
||||
}
|
||||
|
||||
public byte[] GetByteArray()
|
||||
{
|
||||
var byteArray = new byte[3];
|
||||
byteArray[0] = Begin;
|
||||
byteArray[1] = Length;
|
||||
byteArray[2] = ButtonNo;
|
||||
return byteArray;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using System.Net.Http.Headers;
|
||||
using HttpClient = Common.Net.Http.HttpClient;
|
||||
|
||||
namespace FASS.Extend.Car.Fairyland.Pc
|
||||
{
|
||||
public class Command
|
||||
{
|
||||
public HttpClient Client { get; private set; }
|
||||
public Command(Uri uri)
|
||||
{
|
||||
Client = new HttpClient()
|
||||
{
|
||||
BaseAddress = uri,
|
||||
AuthenticationHeaderValue = new AuthenticationHeaderValue("Bearer", "Token"),
|
||||
Timeout = TimeSpan.FromMilliseconds(500)
|
||||
};
|
||||
Client.Initialize();
|
||||
}
|
||||
|
||||
public string Request(string url, HttpContent content)
|
||||
{
|
||||
var response = Client.PostAsync(url, content).GetAwaiter().GetResult();
|
||||
var responseString = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
|
||||
return responseString;
|
||||
}
|
||||
|
||||
public string Start(HttpContent content) => Request("/car/start", content);
|
||||
public string Stop(HttpContent content) => Request("/car/stop", content);
|
||||
public string EmergencyStop(HttpContent content) => Request("/car/emergencyStop", content);
|
||||
public string Reset(HttpContent content) => Request("/car/reset", content);
|
||||
public string Action(HttpContent content) => Request("/car/action", content);
|
||||
public string Task(HttpContent content) => Request("/car/task", content);
|
||||
public string State(HttpContent content) => Request("/car/state", content);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>2.4.2</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Common.Net" Version="2.4.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace FASS.Extend.Car.Fairyland.Pc.Models.Request
|
||||
{
|
||||
public class Action
|
||||
{
|
||||
public required string Code { get; set; }
|
||||
public required string ActionType { get; set; }
|
||||
public required string BlockingType { get; set; }
|
||||
public List<Parameter> Parameters { get; set; } = [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace FASS.Extend.Car.Fairyland.Pc.Models.Request
|
||||
{
|
||||
public class CarAction
|
||||
{
|
||||
public required string CarCode { get; set; }
|
||||
public List<Action> Actions { get; set; } = [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace FASS.Extend.Car.Fairyland.Pc.Models.Request
|
||||
{
|
||||
public class CarEmergencyStop
|
||||
{
|
||||
public required string CarCode { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace FASS.Extend.Car.Fairyland.Pc.Models.Request
|
||||
{
|
||||
public class CarReset
|
||||
{
|
||||
public required string CarCode { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace FASS.Extend.Car.Fairyland.Pc.Models.Request
|
||||
{
|
||||
public class CarStart
|
||||
{
|
||||
public required string CarCode { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace FASS.Extend.Car.Fairyland.Pc.Models.Request
|
||||
{
|
||||
public class CarState
|
||||
{
|
||||
public required string CarCode { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace FASS.Extend.Car.Fairyland.Pc.Models.Request
|
||||
{
|
||||
public class CarStop
|
||||
{
|
||||
public required string CarCode { get; set; }
|
||||
public int DueTime { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace FASS.Extend.Car.Fairyland.Pc.Models.Request
|
||||
{
|
||||
public class CarTask
|
||||
{
|
||||
public required string CarCode { get; set; }
|
||||
public required string TaskCode { get; set; }
|
||||
public required string TaskType { get; set; }
|
||||
public List<Node> Nodes { get; set; } = [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace FASS.Extend.Car.Fairyland.Pc.Models.Request
|
||||
{
|
||||
public class Node
|
||||
{
|
||||
public required string Code { get; set; }
|
||||
public List<Action> Actions { get; set; } = [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace FASS.Extend.Car.Fairyland.Pc.Models.Request
|
||||
{
|
||||
public class Parameter
|
||||
{
|
||||
public required string Key { get; set; }
|
||||
public string? Value { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace FASS.Extend.Car.Fairyland.Pc.Models.Response
|
||||
{
|
||||
public class Action
|
||||
{
|
||||
public required string Code { get; set; }
|
||||
public required string ActionType { get; set; }
|
||||
public required string BlockingType { get; set; }
|
||||
public required string State { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace FASS.Extend.Car.Fairyland.Pc.Models.Response
|
||||
{
|
||||
public class Alarm
|
||||
{
|
||||
public required string Code { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
namespace FASS.Extend.Car.Fairyland.Pc.Models.Response
|
||||
{
|
||||
public class CarState
|
||||
{
|
||||
public required string Code { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public double Length { get; set; }
|
||||
public double Width { get; set; }
|
||||
public string? CurrState { get; set; }
|
||||
public double Battery { get; set; }
|
||||
public double X { get; set; }
|
||||
public double Y { get; set; }
|
||||
public double Theta { get; set; }
|
||||
public double Speed { get; set; }
|
||||
public string? CurrNodeCode { get; set; }
|
||||
public string? StartNodeCode { get; set; }
|
||||
public string? EndNodeCode { get; set; }
|
||||
public string? CurrEdgeCode { get; set; }
|
||||
public string? StartEdgeCode { get; set; }
|
||||
public string? EndEdgeCode { get; set; }
|
||||
public List<Task> Tasks { get; set; } = [];
|
||||
public List<Action> Actions { get; set; } = [];
|
||||
public List<Alarm> Alarms { get; set; } = [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace FASS.Extend.Car.Fairyland.Pc.Models.Response
|
||||
{
|
||||
public class Node
|
||||
{
|
||||
public required string Code { get; set; }
|
||||
public List<Action> Actions { get; set; } = [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace FASS.Extend.Car.Fairyland.Pc.Models.Response
|
||||
{
|
||||
public class Task
|
||||
{
|
||||
public required string Code { get; set; }
|
||||
public string? State { get; set; }
|
||||
public List<Node> Nodes { get; set; } = [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
using System.Net;
|
||||
using UdpServer = Common.Net.Udp.UdpServer;
|
||||
|
||||
namespace FASS.Extend.Car.Fairyland.Pcb
|
||||
{
|
||||
public class Command
|
||||
{
|
||||
public UdpServer Server { get; private set; }
|
||||
|
||||
public EndPoint Remote { get => Server.RemoteEndPoint; set => Server.RemoteEndPoint = value; }
|
||||
|
||||
public Command(IPEndPoint local)
|
||||
{
|
||||
Server = new UdpServer()
|
||||
{
|
||||
LocalEndPoint = local,
|
||||
SendTimeout = 500,
|
||||
ReceiveTimeout = 500
|
||||
};
|
||||
}
|
||||
|
||||
public void SendState(byte command, ushort car, EndPoint remote)
|
||||
{
|
||||
var sendMessage = new SendControlMessage().SetMessage(command, car, 0);
|
||||
var sendByteArray = sendMessage.GetByteArray();
|
||||
Server.Send(sendByteArray, remote);
|
||||
}
|
||||
public void SendState(EndPoint remote) => SendState(0x00, 0, remote);
|
||||
|
||||
public static ReceiveStateMessage GetReceiveStateMessage(byte[] byteArray) => new ReceiveStateMessage().GetMessage(byteArray);
|
||||
public static byte[] GetReceiveStateByteArray(ReceiveStateMessage message) => message.GetByteArray();
|
||||
|
||||
public void SendControl(byte command, ushort car, ushort param, EndPoint remote)
|
||||
{
|
||||
var sendMessage = new SendControlMessage().SetMessage(command, car, param);
|
||||
var sendByteArray = sendMessage.GetByteArray();
|
||||
Server.Send(sendByteArray, remote);
|
||||
}
|
||||
public void SendControlStart(EndPoint remote, ushort direction = 0x00) => SendControl(0x01, 0, direction, remote);
|
||||
public void SendControlStop(EndPoint remote, ushort second = 0x00) => SendControl(0x02, 0, second, remote);
|
||||
public void SendControlEmergencyStop(EndPoint remote, ushort second = 0x00) => SendControl(0x03, 0, second, remote);
|
||||
public void SendControlReset(EndPoint remote, ushort second = 0x00) => SendControl(0x04, 0, second, remote);
|
||||
public void SendControlRest(EndPoint remote, ushort second = 0x00) => SendControl(0x05, 0, second, remote);
|
||||
public void SendControlShutdown(EndPoint remote, ushort second = 0x00) => SendControl(0x06, 0, second, remote);
|
||||
|
||||
public static SendControlMessage GetSendControlMessage(byte[] byteArray) => new SendControlMessage().GetMessage(byteArray);
|
||||
public static byte[] GetSendControlByteArray(SendControlMessage message) => message.GetByteArray();
|
||||
|
||||
public void SendAction(ushort car, ulong actionId, NodeMessage nodeMessage, EndPoint remote)
|
||||
{
|
||||
var sendMessage = new SendActionMessage().SetMessage(car, actionId, nodeMessage);
|
||||
var sendByteArray = sendMessage.GetByteArray();
|
||||
Server.Send(sendByteArray, remote);
|
||||
}
|
||||
public void SendAction(NodeMessage nodeMessage, EndPoint remote) => SendAction(0, 0, nodeMessage, remote);
|
||||
public void SendActionStartStop(ushort node, byte startStop, EndPoint remote) => SendAction(0, 0, new NodeMessage() { Node = node, StartStop = startStop }, remote);
|
||||
public void SendActionDirection(ushort node, byte direction, EndPoint remote) => SendAction(0, 0, new NodeMessage() { Node = node, Direction = direction }, remote);
|
||||
public void SendActionOrientation(ushort node, byte orientation, EndPoint remote) => SendAction(0, 0, new NodeMessage() { Node = node, Orientation = orientation }, remote);
|
||||
public void SendActionByroad(ushort node, byte byroad, EndPoint remote) => SendAction(0, 0, new NodeMessage() { Node = node, Byroad = byroad }, remote);
|
||||
public void SendActionSpeed(ushort node, ushort speed, EndPoint remote) => SendAction(0, 0, new NodeMessage() { Node = node, Speed = speed }, remote);
|
||||
public void SendActionObstacle(ushort node, byte obstacle, EndPoint remote) => SendAction(0, 0, new NodeMessage() { Node = node, Obstacle = obstacle }, remote);
|
||||
public void SendActionAudio(ushort node, byte audio, EndPoint remote) => SendAction(0, 0, new NodeMessage() { Node = node, Audio = audio }, remote);
|
||||
public void SendActionLight(ushort node, byte light, EndPoint remote) => SendAction(0, 0, new NodeMessage() { Node = node, Light = light }, remote);
|
||||
public void SendActionCharge(ushort node, byte charge, EndPoint remote) => SendAction(0, 0, new NodeMessage() { Node = node, Charge = charge }, remote);
|
||||
public void SendActionRest(ushort node, byte rest, EndPoint remote) => SendAction(0, 0, new NodeMessage() { Node = node, Rest = rest }, remote);
|
||||
public void SendActionLift(ushort node, byte lift, EndPoint remote) => SendAction(0, 0, new NodeMessage() { Node = node, Lift = lift }, remote);
|
||||
public void SendActionClamp(ushort node, byte clamp, EndPoint remote) => SendAction(0, 0, new NodeMessage() { Node = node, Clamp = clamp }, remote);
|
||||
public void SendActionTray(ushort node, byte tray, EndPoint remote) => SendAction(0, 0, new NodeMessage() { Node = node, Tray = tray }, remote);
|
||||
public void SendActionRoll(ushort node, byte roll, EndPoint remote) => SendAction(0, 0, new NodeMessage() { Node = node, Roll = roll }, remote);
|
||||
public void SendActionShutdown(ushort node, byte shutdown, EndPoint remote) => SendAction(0, 0, new NodeMessage() { Node = node, Shutdown = shutdown }, remote);
|
||||
|
||||
public static SendActionMessage GetSendActionMessage(byte[] byteArray) => new SendActionMessage().GetMessage(byteArray);
|
||||
public static byte[] GetSendActionByteArray(SendActionMessage message) => message.GetByteArray();
|
||||
|
||||
public void SendNodes(ushort car, ulong task, ushort count, NodeMessage[] nodeMessages, EndPoint remote)
|
||||
{
|
||||
var sendMessage = new SendNodesMessage().SetMessage(car, task, count, nodeMessages);
|
||||
var sendByteArray = sendMessage.GetByteArray();
|
||||
Server.Send(sendByteArray, remote);
|
||||
}
|
||||
public void SendNodes(ulong task, ushort count, NodeMessage[] nodeMessages, EndPoint remote) => SendNodes(0, task, count, nodeMessages, remote);
|
||||
|
||||
public static SendNodesMessage GetSendNodesMessage(byte[] byteArray) => new SendNodesMessage().GetMessage(byteArray);
|
||||
public static byte[] GetSendNodesByteArray(SendNodesMessage message) => message.GetByteArray();
|
||||
|
||||
public void SendStateResponse(byte command, ushort car, ulong param, EndPoint remote)
|
||||
{
|
||||
var sendMessage = new SendStateResponseMessage().SetMessage(command, car, param);
|
||||
var sendByteArray = sendMessage.GetByteArray();
|
||||
Server.Send(sendByteArray, remote);
|
||||
}
|
||||
|
||||
public static SendStateResponseMessage GetStateResponseMessage(byte[] byteArray) => new SendStateResponseMessage().GetMessage(byteArray);
|
||||
|
||||
public static byte[] GetStateResponseByteArray(SendStateResponseMessage message) => message.GetByteArray();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>2.4.2</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Common.Net" Version="2.4.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,117 @@
|
||||
namespace FASS.Extend.Car.Fairyland.Pcb
|
||||
{
|
||||
public class NodeMessage
|
||||
{
|
||||
public ushort Node { get; set; }
|
||||
public ushort Distance { get; set; }
|
||||
public byte StartStop { get; set; }
|
||||
public byte Direction { get; set; }
|
||||
public byte Orientation { get; set; }
|
||||
public byte Byroad { get; set; }
|
||||
public ushort Speed { get; set; }
|
||||
public byte Obstacle { get; set; }
|
||||
public byte Audio { get; set; }
|
||||
public byte Light { get; set; }
|
||||
public byte Charge { get; set; }
|
||||
public byte Rest { get; set; }
|
||||
public byte Lift { get; set; }
|
||||
public byte Clamp { get; set; }
|
||||
public byte Tray { get; set; }
|
||||
public byte Roll { get; set; }
|
||||
public byte Shutdown { get; set; }
|
||||
public byte[] Reserve { get; set; } = new byte[5];
|
||||
|
||||
public NodeMessage SetMessage(
|
||||
ushort node,
|
||||
ushort distance,
|
||||
byte startStop,
|
||||
byte direction,
|
||||
byte orientation,
|
||||
byte byroad,
|
||||
ushort speed,
|
||||
byte obstacle,
|
||||
byte audio,
|
||||
byte light,
|
||||
byte charge,
|
||||
byte rest,
|
||||
byte lift,
|
||||
byte clamp,
|
||||
byte tray,
|
||||
byte roll,
|
||||
byte shutdown)
|
||||
{
|
||||
Node = node;
|
||||
Distance = distance;
|
||||
StartStop = startStop;
|
||||
Direction = direction;
|
||||
Orientation = orientation;
|
||||
Byroad = byroad;
|
||||
Speed = speed;
|
||||
Obstacle = obstacle;
|
||||
Audio = audio;
|
||||
Light = light;
|
||||
Charge = charge;
|
||||
Rest = rest;
|
||||
Lift = lift;
|
||||
Clamp = clamp;
|
||||
Tray = tray;
|
||||
Roll = roll;
|
||||
Shutdown = shutdown;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NodeMessage GetMessage(byte[] byteArray)
|
||||
{
|
||||
if (byteArray == null || byteArray.Length < 25) throw new Exception($"数据长度错误:{Utility.ByteArrayToHexString(byteArray)}");
|
||||
Node = BitConverter.ToUInt16(byteArray[0..2]);
|
||||
Distance = BitConverter.ToUInt16(byteArray[2..4]);
|
||||
StartStop = byteArray[4];
|
||||
Direction = byteArray[5];
|
||||
Orientation = byteArray[6];
|
||||
Byroad = byteArray[7];
|
||||
Speed = BitConverter.ToUInt16(byteArray[8..10]);
|
||||
Obstacle = byteArray[10];
|
||||
Audio = byteArray[11];
|
||||
Light = byteArray[12];
|
||||
Charge = byteArray[13];
|
||||
Rest = byteArray[14];
|
||||
Lift = byteArray[15];
|
||||
Clamp = byteArray[16];
|
||||
Tray = byteArray[17];
|
||||
Roll = byteArray[18];
|
||||
Shutdown = byteArray[19];
|
||||
Reserve = byteArray[20..];
|
||||
return this;
|
||||
}
|
||||
|
||||
public byte[] GetByteArray()
|
||||
{
|
||||
var byteArray = new byte[25];
|
||||
var node = BitConverter.GetBytes(Node);
|
||||
byteArray[0] = node[0];
|
||||
byteArray[1] = node[1];
|
||||
var distance = BitConverter.GetBytes(Distance);
|
||||
byteArray[2] = distance[0];
|
||||
byteArray[3] = distance[1];
|
||||
byteArray[4] = StartStop;
|
||||
byteArray[5] = Direction;
|
||||
byteArray[6] = Orientation;
|
||||
byteArray[7] = Byroad;
|
||||
var speed = BitConverter.GetBytes(Speed);
|
||||
byteArray[8] = speed[0];
|
||||
byteArray[9] = speed[1];
|
||||
byteArray[10] = Obstacle;
|
||||
byteArray[11] = Audio;
|
||||
byteArray[12] = Light;
|
||||
byteArray[13] = Charge;
|
||||
byteArray[14] = Rest;
|
||||
byteArray[15] = Lift;
|
||||
byteArray[16] = Clamp;
|
||||
byteArray[17] = Tray;
|
||||
byteArray[18] = Roll;
|
||||
byteArray[19] = Shutdown;
|
||||
Array.Copy(Reserve, 0, byteArray, 20, Reserve.Length);
|
||||
return byteArray;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
using System.Text;
|
||||
|
||||
namespace FASS.Extend.Car.Fairyland.Pcb
|
||||
{
|
||||
public class ReceiveStateMessage
|
||||
{
|
||||
public byte Begin { get; set; } = 0xBB;
|
||||
public byte Command { get; set; }
|
||||
public ushort Car { get; set; }
|
||||
public ushort Length { get; set; }
|
||||
public ushort Width { get; set; }
|
||||
public ushort SystemVersion { get; set; }
|
||||
public ushort SupportVersion { get; set; }
|
||||
public string? CarType { get; set; }
|
||||
public byte BatteryCharge { get; set; }
|
||||
public byte BatteryHealth { get; set; }
|
||||
public ushort BatteryCurrent { get; set; }
|
||||
public ushort BatteryVoltage { get; set; }
|
||||
public ushort HeadingAngle { get; set; }
|
||||
public byte State { get; set; }
|
||||
public ulong Alarm { get; set; }
|
||||
public ulong Task { get; set; }
|
||||
public NodeMessage NodeMessage { get; set; } = new NodeMessage();
|
||||
public byte[] Reserve { get; set; } = new byte[20];
|
||||
public byte Check { get; set; }
|
||||
public byte End { get; set; } = 0xEE;
|
||||
|
||||
public ReceiveStateMessage SetMessage(
|
||||
byte command,
|
||||
ushort car,
|
||||
ushort length,
|
||||
ushort width,
|
||||
ushort systemVersion,
|
||||
ushort supportVersion,
|
||||
string carType,
|
||||
byte batteryCharge,
|
||||
byte batteryHealth,
|
||||
ushort batteryCurrent,
|
||||
ushort batteryVoltage,
|
||||
byte state,
|
||||
ulong alarm,
|
||||
ulong task,
|
||||
NodeMessage nodeMessage)
|
||||
{
|
||||
Command = command;
|
||||
Car = car;
|
||||
Length = length;
|
||||
Width = width;
|
||||
SystemVersion = systemVersion;
|
||||
SupportVersion = supportVersion;
|
||||
CarType = carType;
|
||||
BatteryCharge = batteryCharge;
|
||||
BatteryHealth = batteryHealth;
|
||||
BatteryCurrent = batteryCurrent;
|
||||
BatteryVoltage = batteryVoltage;
|
||||
State = state;
|
||||
Alarm = alarm;
|
||||
Task = task;
|
||||
NodeMessage = nodeMessage;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ReceiveStateMessage GetMessage(byte[] byteArray)
|
||||
{
|
||||
if (byteArray == null || byteArray.Length < 100) throw new Exception($"数据长度错误:{Utility.ByteArrayToHexString(byteArray)}");
|
||||
//if (byteArray[98] != Utility.XOR(byteArray[1..^2])) throw new Exception($"数据校验错误:{Utility.ByteArrayToHexString(byteArray)}");
|
||||
if (byteArray[0] != 0xBB || byteArray[99] != 0xEE) throw new Exception($"数据帧头尾错误:{Utility.ByteArrayToHexString(byteArray)}");
|
||||
Begin = byteArray[0];
|
||||
Command = byteArray[1];
|
||||
Car = BitConverter.ToUInt16(byteArray[2..4]);
|
||||
Length = BitConverter.ToUInt16(byteArray[4..6]);
|
||||
Width = BitConverter.ToUInt16(byteArray[6..8]);
|
||||
SystemVersion = BitConverter.ToUInt16(byteArray[8..10]);
|
||||
SupportVersion = BitConverter.ToUInt16(byteArray[10..12]);
|
||||
CarType = Encoding.ASCII.GetString(byteArray[12..28]).PadLeft(16, '0');
|
||||
BatteryCharge = byteArray[28];
|
||||
BatteryHealth = byteArray[29];
|
||||
BatteryCurrent = BitConverter.ToUInt16(byteArray[30..32]);
|
||||
BatteryVoltage = BitConverter.ToUInt16(byteArray[32..34]);
|
||||
HeadingAngle = BitConverter.ToUInt16(byteArray[34..36]);
|
||||
State = byteArray[36];
|
||||
Alarm = BitConverter.ToUInt64(byteArray[37..45]);
|
||||
Task = BitConverter.ToUInt64(byteArray[45..53]);
|
||||
NodeMessage = new NodeMessage().GetMessage(byteArray[53..78]);
|
||||
Reserve = byteArray[78..98];
|
||||
Check = byteArray[98];
|
||||
End = byteArray[99];
|
||||
return this;
|
||||
}
|
||||
|
||||
public byte[] GetByteArray()
|
||||
{
|
||||
var byteArray = new byte[100];
|
||||
byteArray[0] = Begin;
|
||||
byteArray[1] = Command;
|
||||
var car = BitConverter.GetBytes(Car);
|
||||
byteArray[2] = car[0];
|
||||
byteArray[3] = car[1];
|
||||
var length = BitConverter.GetBytes(Length);
|
||||
byteArray[4] = length[0];
|
||||
byteArray[5] = length[1];
|
||||
var width = BitConverter.GetBytes(Width);
|
||||
byteArray[6] = width[0];
|
||||
byteArray[7] = width[1];
|
||||
var systemVersion = BitConverter.GetBytes(SystemVersion);
|
||||
byteArray[8] = systemVersion[0];
|
||||
byteArray[9] = systemVersion[1];
|
||||
var supportVersion = BitConverter.GetBytes(SupportVersion);
|
||||
byteArray[10] = supportVersion[0];
|
||||
byteArray[11] = supportVersion[1];
|
||||
var carType = Encoding.ASCII.GetBytes((CarType ?? string.Empty).PadLeft(16, '0'));
|
||||
byteArray[12] = carType[0];
|
||||
byteArray[13] = carType[1];
|
||||
byteArray[14] = carType[2];
|
||||
byteArray[15] = carType[3];
|
||||
byteArray[16] = carType[4];
|
||||
byteArray[17] = carType[5];
|
||||
byteArray[18] = carType[6];
|
||||
byteArray[19] = carType[7];
|
||||
byteArray[20] = carType[8];
|
||||
byteArray[21] = carType[9];
|
||||
byteArray[22] = carType[10];
|
||||
byteArray[23] = carType[11];
|
||||
byteArray[24] = carType[12];
|
||||
byteArray[25] = carType[13];
|
||||
byteArray[26] = carType[14];
|
||||
byteArray[27] = carType[15];
|
||||
byteArray[28] = BatteryCharge;
|
||||
byteArray[29] = BatteryHealth;
|
||||
var batteryCurrent = BitConverter.GetBytes(BatteryCurrent);
|
||||
byteArray[30] = batteryCurrent[0];
|
||||
byteArray[31] = batteryCurrent[1];
|
||||
var batteryVoltage = BitConverter.GetBytes(BatteryVoltage);
|
||||
byteArray[32] = batteryVoltage[0];
|
||||
byteArray[33] = batteryVoltage[1];
|
||||
var headingAngle = BitConverter.GetBytes(HeadingAngle);
|
||||
byteArray[34] = headingAngle[0];
|
||||
byteArray[35] = headingAngle[1];
|
||||
byteArray[36] = State;
|
||||
var alarm = BitConverter.GetBytes(Alarm);
|
||||
byteArray[37] = alarm[0];
|
||||
byteArray[38] = alarm[1];
|
||||
byteArray[39] = alarm[2];
|
||||
byteArray[40] = alarm[3];
|
||||
byteArray[41] = alarm[4];
|
||||
byteArray[42] = alarm[5];
|
||||
byteArray[43] = alarm[6];
|
||||
byteArray[44] = alarm[7];
|
||||
var task = BitConverter.GetBytes(Task);
|
||||
byteArray[45] = task[0];
|
||||
byteArray[46] = task[1];
|
||||
byteArray[47] = task[2];
|
||||
byteArray[48] = task[3];
|
||||
byteArray[49] = task[4];
|
||||
byteArray[50] = task[5];
|
||||
byteArray[51] = task[6];
|
||||
byteArray[52] = task[7];
|
||||
var nodeMessage = NodeMessage.GetByteArray();
|
||||
Array.Copy(nodeMessage, 0, byteArray, 53, nodeMessage.Length);
|
||||
Array.Copy(Reserve, 0, byteArray, 78, Reserve.Length);
|
||||
//byteArray[98] = Check;
|
||||
byteArray[98] = Utility.XOR(byteArray[1..^2]);
|
||||
byteArray[99] = End;
|
||||
return byteArray;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
namespace FASS.Extend.Car.Fairyland.Pcb
|
||||
{
|
||||
public class SendActionMessage
|
||||
{
|
||||
public byte Begin { get; set; } = 0xBB;
|
||||
public byte Command { get; set; } = 0xA1;
|
||||
public ushort Car { get; set; }
|
||||
public ulong ActionId { get; set; }
|
||||
public byte[] PlaceHolder { get; set; } = new byte[2];
|
||||
public NodeMessage NodeMessage { get; set; } = new NodeMessage();
|
||||
public byte[] Reserve { get; set; } = new byte[25];
|
||||
public byte Check { get; set; }
|
||||
public byte End { get; set; } = 0xEE;
|
||||
|
||||
public SendActionMessage SetMessage(
|
||||
ushort car,
|
||||
ulong actionId,
|
||||
NodeMessage nodeMessage)
|
||||
{
|
||||
Car = car;
|
||||
ActionId = actionId;
|
||||
NodeMessage = nodeMessage;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SendActionMessage GetMessage(byte[] byteArray)
|
||||
{
|
||||
if (byteArray == null || byteArray.Length < 100) throw new Exception($"数据长度错误:{Utility.ByteArrayToHexString(byteArray)}");
|
||||
//if (byteArray[98] != Utility.XOR(byteArray[1..^2])) throw new Exception($"数据校验错误:{Utility.ByteArrayToHexString(byteArray)}");
|
||||
Begin = byteArray[0];
|
||||
Command = byteArray[1];
|
||||
Car = BitConverter.ToUInt16(byteArray[2..4]);
|
||||
ActionId = BitConverter.ToUInt64(byteArray[4..12]);
|
||||
PlaceHolder = byteArray[12..14];
|
||||
NodeMessage = new NodeMessage().GetMessage(byteArray[14..39]);
|
||||
Reserve = byteArray[39..98];
|
||||
Check = byteArray[98];
|
||||
End = byteArray[99];
|
||||
return this;
|
||||
}
|
||||
|
||||
public byte[] GetByteArray()
|
||||
{
|
||||
var byteArray = new byte[100];
|
||||
byteArray[0] = Begin;
|
||||
byteArray[1] = Command;
|
||||
var car = BitConverter.GetBytes(Car);
|
||||
byteArray[2] = car[0];
|
||||
byteArray[3] = car[1];
|
||||
var action = BitConverter.GetBytes(ActionId);
|
||||
byteArray[4] = action[0];
|
||||
byteArray[5] = action[1];
|
||||
byteArray[6] = action[2];
|
||||
byteArray[7] = action[3];
|
||||
byteArray[8] = action[4];
|
||||
byteArray[9] = action[5];
|
||||
byteArray[10] = action[6];
|
||||
byteArray[11] = action[7];
|
||||
//预留两个字节PlaceHolder[12..14]
|
||||
var nodeMessage = NodeMessage.GetByteArray();
|
||||
Array.Copy(nodeMessage, 0, byteArray, 14, nodeMessage.Length);
|
||||
Array.Copy(Reserve, 0, byteArray, 39, Reserve.Length);
|
||||
//byteArray[98] = Check;
|
||||
byteArray[98] = Utility.XOR(byteArray[1..^2]);
|
||||
byteArray[99] = End;
|
||||
return byteArray;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
namespace FASS.Extend.Car.Fairyland.Pcb
|
||||
{
|
||||
public class SendControlMessage
|
||||
{
|
||||
public byte Begin { get; set; } = 0xBB;
|
||||
public byte Command { get; set; } = 0x00;
|
||||
public ushort Car { get; set; }
|
||||
public ushort Param { get; set; }
|
||||
public byte[] Reserve { get; set; } = new byte[41];
|
||||
public byte Check { get; set; }
|
||||
public byte End { get; set; } = 0xEE;
|
||||
|
||||
public SendControlMessage SetMessage(
|
||||
byte command,
|
||||
ushort car,
|
||||
ushort param)
|
||||
{
|
||||
Command = command;
|
||||
Car = car;
|
||||
Param = param;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SendControlMessage GetMessage(byte[] byteArray)
|
||||
{
|
||||
if (byteArray is null || byteArray.Length < 50) throw new Exception($"数据长度错误: {Utility.ByteArrayToHexString(byteArray)}");
|
||||
//if (byteArray[48] != Utility.XOR(byteArray[1..^2])) throw new Exception($"数据校验错误:{Utility.ByteArrayToHexString(byteArray)}");
|
||||
Begin = byteArray[0];
|
||||
Command = byteArray[1];
|
||||
Car = BitConverter.ToUInt16(byteArray[2..4]);
|
||||
Param = BitConverter.ToUInt16(byteArray[4..6]);
|
||||
Reserve = byteArray[6..48];
|
||||
Check = byteArray[48];
|
||||
End = byteArray[49];
|
||||
return this;
|
||||
}
|
||||
|
||||
public byte[] GetByteArray()
|
||||
{
|
||||
var byteArray = new byte[50];
|
||||
byteArray[0] = Begin;
|
||||
byteArray[1] = Command;
|
||||
var car = BitConverter.GetBytes(Car);
|
||||
byteArray[2] = car[0];
|
||||
byteArray[3] = car[1];
|
||||
var param = BitConverter.GetBytes(Param);
|
||||
byteArray[4] = param[0];
|
||||
byteArray[5] = param[1];
|
||||
Array.Copy(Reserve, 0, byteArray, 6, Reserve.Length);
|
||||
//byteArray[48] = Check;
|
||||
byteArray[48] = Utility.XOR(byteArray[1..^2]);
|
||||
byteArray[49] = End;
|
||||
return byteArray;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
using System.Buffers;
|
||||
|
||||
namespace FASS.Extend.Car.Fairyland.Pcb
|
||||
{
|
||||
public class SendNodesMessage
|
||||
{
|
||||
public byte Begin { get; set; } = 0xBB;
|
||||
public byte Command { get; set; } = 0xB1;
|
||||
public ushort Car { get; set; }
|
||||
public ulong Task { get; set; }
|
||||
public ushort Count { get; set; }
|
||||
public NodeMessage[] NodeMessages { get; set; } = new NodeMessage[10]
|
||||
{
|
||||
new NodeMessage(),
|
||||
new NodeMessage(),
|
||||
new NodeMessage(),
|
||||
new NodeMessage(),
|
||||
new NodeMessage(),
|
||||
new NodeMessage(),
|
||||
new NodeMessage(),
|
||||
new NodeMessage(),
|
||||
new NodeMessage(),
|
||||
new NodeMessage()
|
||||
};
|
||||
public byte[] Reserve { get; set; } = new byte[34];
|
||||
public byte Check { get; set; }
|
||||
public byte End { get; set; } = 0xEE;
|
||||
|
||||
public SendNodesMessage SetMessage(
|
||||
ushort car,
|
||||
ulong task,
|
||||
ushort count,
|
||||
NodeMessage[] nodeMessages)
|
||||
{
|
||||
Car = car;
|
||||
Task = task;
|
||||
Count = count;
|
||||
Array.Copy(nodeMessages, 0, NodeMessages, 0, nodeMessages.Length);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SendNodesMessage GetMessage(byte[] byteArray)
|
||||
{
|
||||
if (byteArray == null || byteArray.Length < 300) throw new Exception($"数据长度错误:{Utility.ByteArrayToHexString(byteArray)}");
|
||||
//if (byteArray[298] != Utility.XOR(byteArray[1..^2])) throw new Exception($"数据校验错误:{Utility.ByteArrayToHexString(byteArray)}");
|
||||
Begin = byteArray[0];
|
||||
Command = byteArray[1];
|
||||
Car = BitConverter.ToUInt16(byteArray[2..4]);
|
||||
Task = BitConverter.ToUInt64(byteArray[4..12]);
|
||||
Count = BitConverter.ToUInt16(byteArray[12..14]);
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
var start = i * 25 + 14;
|
||||
var end = start + 25;
|
||||
NodeMessages[i] = new NodeMessage().GetMessage(byteArray[start..end]);
|
||||
}
|
||||
Reserve = byteArray[263..298];
|
||||
Check = byteArray[298];
|
||||
End = byteArray[299];
|
||||
return this;
|
||||
}
|
||||
|
||||
public byte[] GetByteArray()
|
||||
{
|
||||
var byteArray = new byte[300];
|
||||
byteArray[0] = Begin;
|
||||
byteArray[1] = Command;
|
||||
var car = BitConverter.GetBytes(Car);
|
||||
byteArray[2] = car[0];
|
||||
byteArray[3] = car[1];
|
||||
var task = BitConverter.GetBytes(Task);
|
||||
byteArray[4] = task[0];
|
||||
byteArray[5] = task[1];
|
||||
byteArray[6] = task[2];
|
||||
byteArray[7] = task[3];
|
||||
byteArray[8] = task[4];
|
||||
byteArray[9] = task[5];
|
||||
byteArray[10] = task[6];
|
||||
byteArray[11] = task[7];
|
||||
var count = BitConverter.GetBytes(Count);
|
||||
byteArray[12] = count[0];
|
||||
byteArray[13] = count[1];
|
||||
var nodeMessages = NodeMessages.SelectMany(e => e.GetByteArray()).ToArray();
|
||||
Array.Copy(nodeMessages, 0, byteArray, 14, nodeMessages.Length);
|
||||
Array.Copy(Reserve, 0, byteArray, 264, Reserve.Length);
|
||||
//byteArray[298] = Check;
|
||||
byteArray[298] = Utility.XOR(byteArray[1..^2]);
|
||||
byteArray[299] = End;
|
||||
return byteArray;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
namespace FASS.Extend.Car.Fairyland.Pcb
|
||||
{
|
||||
public class SendStateResponseMessage
|
||||
{
|
||||
public byte Begin { get; set; } = 0xBB;
|
||||
public byte Command { get; set; } = 0x10;
|
||||
public ushort Car { get; set; }
|
||||
public ulong TimeStamp { get; set; }
|
||||
public byte[] Reserve { get; set; } = new byte[28];
|
||||
public byte Check { get; set; }
|
||||
public byte End { get; set; } = 0xEE;
|
||||
|
||||
public SendStateResponseMessage SetMessage(
|
||||
byte command,
|
||||
ushort car,
|
||||
ulong param)
|
||||
{
|
||||
Command = command;
|
||||
Car = car;
|
||||
TimeStamp = param;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SendStateResponseMessage GetMessage(byte[] byteArray)
|
||||
{
|
||||
if (byteArray == null || byteArray.Length < 50) throw new Exception($"数据长度错误: {Utility.ByteArrayToHexString(byteArray)}");
|
||||
//if (byteArray[48] != Utility.XOR(byteArray[1..^2])) throw new Exception($"数据校验错误:{Utility.ByteArrayToHexString(byteArray)}");
|
||||
Begin = byteArray[0];
|
||||
Command = byteArray[1];
|
||||
Car = BitConverter.ToUInt16(byteArray[2..4]);
|
||||
TimeStamp = BitConverter.ToUInt64(byteArray[4..12]);
|
||||
Reserve = byteArray[20..48];
|
||||
Check = byteArray[48];
|
||||
End = byteArray[49];
|
||||
return this;
|
||||
}
|
||||
|
||||
public byte[] GetByteArray()
|
||||
{
|
||||
var byteArray = new byte[50];
|
||||
byteArray[0] = Begin;
|
||||
byteArray[1] = Command;
|
||||
var car = BitConverter.GetBytes(Car);
|
||||
byteArray[2] = car[0];
|
||||
byteArray[3] = car[1];
|
||||
var ticks = BitConverter.GetBytes(TimeStamp);
|
||||
byteArray[4] = ticks[0];
|
||||
byteArray[5] = ticks[1];
|
||||
byteArray[6] = ticks[2];
|
||||
byteArray[7] = ticks[3];
|
||||
byteArray[8] = ticks[4];
|
||||
byteArray[9] = ticks[5];
|
||||
byteArray[10] = ticks[6];
|
||||
byteArray[11] = ticks[7];
|
||||
var date = new DateTime(1970, 1, 1, 8, 0, 0).AddMilliseconds(TimeStamp);
|
||||
byteArray[12] = (byte)(date.Year - 1970);
|
||||
byteArray[13] = (byte)(date.Month);
|
||||
byteArray[14] = (byte)(date.Day);
|
||||
byteArray[15] = (byte)(date.Hour);
|
||||
byteArray[16] = (byte)(date.Minute);
|
||||
byteArray[17] = (byte)(date.Second);
|
||||
var millisecond = BitConverter.GetBytes((ushort)(date.Millisecond));
|
||||
byteArray[18] = millisecond[0];
|
||||
byteArray[19] = millisecond[1];
|
||||
Array.Copy(Reserve, 0, byteArray, 20, Reserve.Length);
|
||||
//byteArray[48] = Check;
|
||||
byteArray[48] = Utility.XOR(byteArray[1..^2]);
|
||||
byteArray[49] = End;
|
||||
return byteArray;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace FASS.Extend.Car.Fairyland.Pcb
|
||||
{
|
||||
public static class Utility
|
||||
{
|
||||
public static string ByteArrayToHexString(byte[]? byteArray, string separator = "")
|
||||
{
|
||||
if (byteArray is null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
return string.Join(separator, byteArray.Select(t => t.ToString("X2")));
|
||||
}
|
||||
|
||||
public static byte XOR(byte[] byteArray)
|
||||
{
|
||||
byte xor = 0;
|
||||
for (int i = 0; i < byteArray.Length; i++)
|
||||
{
|
||||
xor ^= byteArray[i];
|
||||
}
|
||||
return xor;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
using System.Net;
|
||||
using TcpClient = Common.Net.Tcp.TcpClient;
|
||||
|
||||
namespace FASS.Extend.Car.Fairyland.Plc
|
||||
{
|
||||
public class Command
|
||||
{
|
||||
public TcpClient Client { get; private set; }
|
||||
|
||||
public Command(IPEndPoint remote)
|
||||
{
|
||||
Client = new TcpClient()
|
||||
{
|
||||
RemoteEndPoint = remote,
|
||||
ConnectTimeout = 500,
|
||||
SendTimeout = 500,
|
||||
ReceiveTimeout = 500
|
||||
};
|
||||
}
|
||||
|
||||
public byte[]? SendState(byte command, ushort car)
|
||||
{
|
||||
var sendMessage = new SendControlMessage().SetMessage(command, car, 0);
|
||||
var sendByteArray = sendMessage.GetByteArray();
|
||||
var receiveByteArray = Client.SendAndReceive(sendByteArray);
|
||||
return receiveByteArray;
|
||||
}
|
||||
public byte[]? SendState() => SendState(0x00, 0);
|
||||
|
||||
public static ReceiveStateMessage GetReceiveStateMessage(byte[] byteArray) => new ReceiveStateMessage().GetMessage(byteArray);
|
||||
public static byte[] GetReceiveStateByteArray(ReceiveStateMessage message) => message.GetByteArray();
|
||||
|
||||
public byte[]? SendControl(byte command, ushort car, ushort param)
|
||||
{
|
||||
var sendMessage = new SendControlMessage().SetMessage(command, car, param);
|
||||
var sendByteArray = sendMessage.GetByteArray();
|
||||
var receiveByteArray = Client.SendAndReceive(sendByteArray);
|
||||
return receiveByteArray;
|
||||
}
|
||||
public byte[]? SendControlStart(ushort direction = 0x00) => SendControl(0x01, 0, direction);
|
||||
public byte[]? SendControlStop(ushort second = 0x00) => SendControl(0x02, 0, second);
|
||||
public byte[]? SendControlEmergencyStop(ushort second = 0x00) => SendControl(0x03, 0, second);
|
||||
public byte[]? SendControlReset(ushort second = 0x00) => SendControl(0x04, 0, second);
|
||||
public byte[]? SendControlRest(ushort second = 0x00) => SendControl(0x05, 0, second);
|
||||
public byte[]? SendControlShutdown(ushort second = 0x00) => SendControl(0x06, 0, second);
|
||||
|
||||
public static SendControlMessage GetSendControlMessage(byte[] byteArray) => new SendControlMessage().GetMessage(byteArray);
|
||||
public static byte[] GetSendControlByteArray(SendControlMessage message) => message.GetByteArray();
|
||||
|
||||
public byte[]? SendAction(ushort car, ulong actionId, NodeMessage nodeMessage)
|
||||
{
|
||||
var sendMessage = new SendActionMessage().SetMessage(car, actionId, nodeMessage);
|
||||
var sendByteArray = sendMessage.GetByteArray();
|
||||
var receiveByteArray = Client.SendAndReceive(sendByteArray);
|
||||
return receiveByteArray;
|
||||
}
|
||||
public byte[]? SendAction(NodeMessage nodeMessage) => SendAction(0, 0, nodeMessage);
|
||||
public byte[]? SendActionStartStop(ushort node, byte startStop) => SendAction(0, 0, new NodeMessage() { Node = node, StartStop = startStop });
|
||||
public byte[]? SendActionDirection(ushort node, byte direction) => SendAction(0, 0, new NodeMessage() { Node = node, Direction = direction });
|
||||
public byte[]? SendActionOrientation(ushort node, byte orientation) => SendAction(0, 0, new NodeMessage() { Node = node, Orientation = orientation });
|
||||
public byte[]? SendActionByroad(ushort node, byte byroad) => SendAction(0, 0, new NodeMessage() { Node = node, Byroad = byroad });
|
||||
public byte[]? SendActionSpeed(ushort node, ushort speed) => SendAction(0, 0, new NodeMessage() { Node = node, Speed = speed });
|
||||
public byte[]? SendActionObstacle(ushort node, byte obstacle) => SendAction(0, 0, new NodeMessage() { Node = node, Obstacle = obstacle });
|
||||
public byte[]? SendActionAudio(ushort node, byte audio) => SendAction(0, 0, new NodeMessage() { Node = node, Audio = audio });
|
||||
public byte[]? SendActionLight(ushort node, byte light) => SendAction(0, 0, new NodeMessage() { Node = node, Light = light });
|
||||
public byte[]? SendActionCharge(ushort node, byte charge) => SendAction(0, 0, new NodeMessage() { Node = node, Charge = charge });
|
||||
public byte[]? SendActionRest(ushort node, byte rest) => SendAction(0, 0, new NodeMessage() { Node = node, Rest = rest });
|
||||
public byte[]? SendActionLift(ushort node, byte lift) => SendAction(0, 0, new NodeMessage() { Node = node, Lift = lift });
|
||||
public byte[]? SendActionClamp(ushort node, byte clamp) => SendAction(0, 0, new NodeMessage() { Node = node, Clamp = clamp });
|
||||
public byte[]? SendActionTray(ushort node, byte tray) => SendAction(0, 0, new NodeMessage() { Node = node, Tray = tray });
|
||||
public byte[]? SendActionRoll(ushort node, byte roll) => SendAction(0, 0, new NodeMessage() { Node = node, Roll = roll });
|
||||
public byte[]? SendActionShutdown(ushort node, byte shutdown) => SendAction(0, 0, new NodeMessage() { Node = node, Shutdown = shutdown });
|
||||
|
||||
public static SendActionMessage GetSendActionMessage(byte[] byteArray) => new SendActionMessage().GetMessage(byteArray);
|
||||
public static byte[] GetSendActionByteArray(SendActionMessage message) => message.GetByteArray();
|
||||
|
||||
public byte[]? SendNodes(ushort car, ulong task, ushort count, NodeMessage[] nodeMessages)
|
||||
{
|
||||
var sendMessage = new SendNodesMessage().SetMessage(car, task, count, nodeMessages);
|
||||
var sendByteArray = sendMessage.GetByteArray();
|
||||
var receiveByteArray = Client.SendAndReceive(sendByteArray);
|
||||
return receiveByteArray;
|
||||
}
|
||||
public byte[]? SendNodes(ulong task, ushort count, NodeMessage[] nodeMessages) => SendNodes(0, task, count, nodeMessages);
|
||||
|
||||
public static SendNodesMessage GetSendNodesMessage(byte[] byteArray) => new SendNodesMessage().GetMessage(byteArray);
|
||||
public static byte[] GetSendNodesByteArray(SendNodesMessage message) => message.GetByteArray();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>2.4.2</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Common.Net" Version="2.4.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,117 @@
|
||||
namespace FASS.Extend.Car.Fairyland.Plc
|
||||
{
|
||||
public class NodeMessage
|
||||
{
|
||||
public ushort Node { get; set; }
|
||||
public ushort Distance { get; set; }
|
||||
public byte StartStop { get; set; }
|
||||
public byte Direction { get; set; }
|
||||
public byte Orientation { get; set; }
|
||||
public byte Byroad { get; set; }
|
||||
public ushort Speed { get; set; }
|
||||
public byte Obstacle { get; set; }
|
||||
public byte Audio { get; set; }
|
||||
public byte Light { get; set; }
|
||||
public byte Charge { get; set; }
|
||||
public byte Rest { get; set; }
|
||||
public byte Lift { get; set; }
|
||||
public byte Clamp { get; set; }
|
||||
public byte Tray { get; set; }
|
||||
public byte Roll { get; set; }
|
||||
public byte Shutdown { get; set; }
|
||||
public byte[] Reserve { get; set; } = new byte[5];
|
||||
|
||||
public NodeMessage SetMessage(
|
||||
ushort node,
|
||||
ushort distance,
|
||||
byte startStop,
|
||||
byte direction,
|
||||
byte orientation,
|
||||
byte byroad,
|
||||
ushort speed,
|
||||
byte obstacle,
|
||||
byte audio,
|
||||
byte light,
|
||||
byte charge,
|
||||
byte rest,
|
||||
byte lift,
|
||||
byte clamp,
|
||||
byte tray,
|
||||
byte roll,
|
||||
byte shutdown)
|
||||
{
|
||||
Node = node;
|
||||
Distance = distance;
|
||||
StartStop = startStop;
|
||||
Direction = direction;
|
||||
Orientation = orientation;
|
||||
Byroad = byroad;
|
||||
Speed = speed;
|
||||
Obstacle = obstacle;
|
||||
Audio = audio;
|
||||
Light = light;
|
||||
Charge = charge;
|
||||
Rest = rest;
|
||||
Lift = lift;
|
||||
Clamp = clamp;
|
||||
Tray = tray;
|
||||
Roll = roll;
|
||||
Shutdown = shutdown;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NodeMessage GetMessage(byte[] byteArray)
|
||||
{
|
||||
if (byteArray == null || byteArray.Length < 25) throw new Exception($"数据长度错误:{Utility.ByteArrayToHexString(byteArray)}");
|
||||
Node = BitConverter.ToUInt16(byteArray[0..2]);
|
||||
Distance = BitConverter.ToUInt16(byteArray[2..4]);
|
||||
StartStop = byteArray[4];
|
||||
Direction = byteArray[5];
|
||||
Orientation = byteArray[6];
|
||||
Byroad = byteArray[7];
|
||||
Speed = BitConverter.ToUInt16(byteArray[8..10]);
|
||||
Obstacle = byteArray[10];
|
||||
Audio = byteArray[11];
|
||||
Light = byteArray[12];
|
||||
Charge = byteArray[13];
|
||||
Rest = byteArray[14];
|
||||
Lift = byteArray[15];
|
||||
Clamp = byteArray[16];
|
||||
Tray = byteArray[17];
|
||||
Roll = byteArray[18];
|
||||
Shutdown = byteArray[19];
|
||||
Reserve = byteArray[20..];
|
||||
return this;
|
||||
}
|
||||
|
||||
public byte[] GetByteArray()
|
||||
{
|
||||
var byteArray = new byte[25];
|
||||
var node = BitConverter.GetBytes(Node);
|
||||
byteArray[0] = node[0];
|
||||
byteArray[1] = node[1];
|
||||
var distance = BitConverter.GetBytes(Distance);
|
||||
byteArray[2] = distance[0];
|
||||
byteArray[3] = distance[1];
|
||||
byteArray[4] = StartStop;
|
||||
byteArray[5] = Direction;
|
||||
byteArray[6] = Orientation;
|
||||
byteArray[7] = Byroad;
|
||||
var speed = BitConverter.GetBytes(Speed);
|
||||
byteArray[8] = speed[0];
|
||||
byteArray[9] = speed[1];
|
||||
byteArray[10] = Obstacle;
|
||||
byteArray[11] = Audio;
|
||||
byteArray[12] = Light;
|
||||
byteArray[13] = Charge;
|
||||
byteArray[14] = Rest;
|
||||
byteArray[15] = Lift;
|
||||
byteArray[16] = Clamp;
|
||||
byteArray[17] = Tray;
|
||||
byteArray[18] = Roll;
|
||||
byteArray[19] = Shutdown;
|
||||
Array.Copy(Reserve, 0, byteArray, 20, Reserve.Length);
|
||||
return byteArray;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
using System.Text;
|
||||
|
||||
namespace FASS.Extend.Car.Fairyland.Plc
|
||||
{
|
||||
public class ReceiveStateMessage
|
||||
{
|
||||
public byte Begin { get; set; } = 0xBB;
|
||||
public byte Command { get; set; }
|
||||
public ushort Car { get; set; }
|
||||
public ushort Length { get; set; }
|
||||
public ushort Width { get; set; }
|
||||
public ushort SystemVersion { get; set; }
|
||||
public ushort SupportVersion { get; set; }
|
||||
public string? CarType { get; set; }
|
||||
public byte BatteryCharge { get; set; }
|
||||
public byte BatteryHealth { get; set; }
|
||||
public ushort BatteryCurrent { get; set; }
|
||||
public ushort BatteryVoltage { get; set; }
|
||||
public ushort HeadingAngle { get; set; }
|
||||
public byte State { get; set; }
|
||||
public ulong Alarm { get; set; }
|
||||
public ulong Task { get; set; }
|
||||
public NodeMessage NodeMessage { get; set; } = new NodeMessage();
|
||||
public byte[] Reserve { get; set; } = new byte[20];
|
||||
public byte Check { get; set; }
|
||||
public byte End { get; set; } = 0xEE;
|
||||
|
||||
public ReceiveStateMessage SetMessage(
|
||||
byte command,
|
||||
ushort car,
|
||||
ushort length,
|
||||
ushort width,
|
||||
ushort systemVersion,
|
||||
ushort supportVersion,
|
||||
string carType,
|
||||
byte batteryCharge,
|
||||
byte batteryHealth,
|
||||
ushort batteryCurrent,
|
||||
ushort batteryVoltage,
|
||||
byte state,
|
||||
ulong alarm,
|
||||
ulong task,
|
||||
NodeMessage nodeMessage)
|
||||
{
|
||||
Command = command;
|
||||
Car = car;
|
||||
Length = length;
|
||||
Width = width;
|
||||
SystemVersion = systemVersion;
|
||||
SupportVersion = supportVersion;
|
||||
CarType = carType;
|
||||
BatteryCharge = batteryCharge;
|
||||
BatteryHealth = batteryHealth;
|
||||
BatteryCurrent = batteryCurrent;
|
||||
BatteryVoltage = batteryVoltage;
|
||||
State = state;
|
||||
Alarm = alarm;
|
||||
Task = task;
|
||||
NodeMessage = nodeMessage;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ReceiveStateMessage GetMessage(byte[] byteArray)
|
||||
{
|
||||
if (byteArray == null || byteArray.Length < 100) throw new Exception($"数据长度错误:{Utility.ByteArrayToHexString(byteArray)}");
|
||||
//if (byteArray[98] != Utility.XOR(byteArray[1..^2])) throw new Exception($"数据校验错误:{Utility.ByteArrayToHexString(byteArray)}");
|
||||
Begin = byteArray[0];
|
||||
Command = byteArray[1];
|
||||
Car = BitConverter.ToUInt16(byteArray[2..4]);
|
||||
Length = BitConverter.ToUInt16(byteArray[4..6]);
|
||||
Width = BitConverter.ToUInt16(byteArray[6..8]);
|
||||
SystemVersion = BitConverter.ToUInt16(byteArray[8..10]);
|
||||
SupportVersion = BitConverter.ToUInt16(byteArray[10..12]);
|
||||
CarType = Encoding.ASCII.GetString(byteArray[12..28]).PadLeft(16, '0');
|
||||
BatteryCharge = byteArray[28];
|
||||
BatteryHealth = byteArray[29];
|
||||
BatteryCurrent = BitConverter.ToUInt16(byteArray[30..32]);
|
||||
BatteryVoltage = BitConverter.ToUInt16(byteArray[32..34]);
|
||||
HeadingAngle = BitConverter.ToUInt16(byteArray[34..36]);
|
||||
State = byteArray[36];
|
||||
Alarm = BitConverter.ToUInt64(byteArray[37..45]);
|
||||
Task = BitConverter.ToUInt64(byteArray[45..53]);
|
||||
NodeMessage = new NodeMessage().GetMessage(byteArray[53..78]);
|
||||
Reserve = byteArray[78..98];
|
||||
Check = byteArray[98];
|
||||
End = byteArray[99];
|
||||
return this;
|
||||
}
|
||||
|
||||
public byte[] GetByteArray()
|
||||
{
|
||||
var byteArray = new byte[100];
|
||||
byteArray[0] = Begin;
|
||||
byteArray[1] = Command;
|
||||
var car = BitConverter.GetBytes(Car);
|
||||
byteArray[2] = car[0];
|
||||
byteArray[3] = car[1];
|
||||
var length = BitConverter.GetBytes(Length);
|
||||
byteArray[4] = length[0];
|
||||
byteArray[5] = length[1];
|
||||
var width = BitConverter.GetBytes(Width);
|
||||
byteArray[6] = width[0];
|
||||
byteArray[7] = width[1];
|
||||
var systemVersion = BitConverter.GetBytes(SystemVersion);
|
||||
byteArray[8] = systemVersion[0];
|
||||
byteArray[9] = systemVersion[1];
|
||||
var supportVersion = BitConverter.GetBytes(SupportVersion);
|
||||
byteArray[10] = supportVersion[0];
|
||||
byteArray[11] = supportVersion[1];
|
||||
var carType = Encoding.ASCII.GetBytes((CarType ?? string.Empty).PadLeft(16, '0'));
|
||||
byteArray[12] = carType[0];
|
||||
byteArray[13] = carType[1];
|
||||
byteArray[14] = carType[2];
|
||||
byteArray[15] = carType[3];
|
||||
byteArray[16] = carType[4];
|
||||
byteArray[17] = carType[5];
|
||||
byteArray[18] = carType[6];
|
||||
byteArray[19] = carType[7];
|
||||
byteArray[20] = carType[8];
|
||||
byteArray[21] = carType[9];
|
||||
byteArray[22] = carType[10];
|
||||
byteArray[23] = carType[11];
|
||||
byteArray[24] = carType[12];
|
||||
byteArray[25] = carType[13];
|
||||
byteArray[26] = carType[14];
|
||||
byteArray[27] = carType[15];
|
||||
byteArray[28] = BatteryCharge;
|
||||
byteArray[29] = BatteryHealth;
|
||||
var batteryCurrent = BitConverter.GetBytes(BatteryCurrent);
|
||||
byteArray[30] = batteryCurrent[0];
|
||||
byteArray[31] = batteryCurrent[1];
|
||||
var batteryVoltage = BitConverter.GetBytes(BatteryVoltage);
|
||||
byteArray[32] = batteryVoltage[0];
|
||||
byteArray[33] = batteryVoltage[1];
|
||||
var headingAngle = BitConverter.GetBytes(HeadingAngle);
|
||||
byteArray[34] = headingAngle[0];
|
||||
byteArray[35] = headingAngle[1];
|
||||
byteArray[36] = State;
|
||||
var alarm = BitConverter.GetBytes(Alarm);
|
||||
byteArray[37] = alarm[0];
|
||||
byteArray[38] = alarm[1];
|
||||
byteArray[39] = alarm[2];
|
||||
byteArray[40] = alarm[3];
|
||||
byteArray[41] = alarm[4];
|
||||
byteArray[42] = alarm[5];
|
||||
byteArray[43] = alarm[6];
|
||||
byteArray[44] = alarm[7];
|
||||
var task = BitConverter.GetBytes(Task);
|
||||
byteArray[45] = task[0];
|
||||
byteArray[46] = task[1];
|
||||
byteArray[47] = task[2];
|
||||
byteArray[48] = task[3];
|
||||
byteArray[49] = task[4];
|
||||
byteArray[50] = task[5];
|
||||
byteArray[51] = task[6];
|
||||
byteArray[52] = task[7];
|
||||
var nodeMessage = NodeMessage.GetByteArray();
|
||||
Array.Copy(nodeMessage, 0, byteArray, 53, nodeMessage.Length);
|
||||
Array.Copy(Reserve, 0, byteArray, 78, Reserve.Length);
|
||||
//byteArray[98] = Check;
|
||||
byteArray[98] = Utility.XOR(byteArray[1..^2]);
|
||||
byteArray[99] = End;
|
||||
return byteArray;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
namespace FASS.Extend.Car.Fairyland.Plc
|
||||
{
|
||||
public class SendActionMessage
|
||||
{
|
||||
public byte Begin { get; set; } = 0xBB;
|
||||
public byte Command { get; set; } = 0xA1;
|
||||
public ushort Car { get; set; }
|
||||
public ulong ActionId { get; set; }
|
||||
public byte[] PlaceHolder { get; set; } = new byte[2];
|
||||
public NodeMessage NodeMessage { get; set; } = new NodeMessage();
|
||||
public byte[] Reserve { get; set; } = new byte[25];
|
||||
public byte Check { get; set; }
|
||||
public byte End { get; set; } = 0xEE;
|
||||
|
||||
public SendActionMessage SetMessage(
|
||||
ushort car,
|
||||
ulong actionId,
|
||||
NodeMessage nodeMessage)
|
||||
{
|
||||
Car = car;
|
||||
ActionId = actionId;
|
||||
NodeMessage = nodeMessage;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SendActionMessage GetMessage(byte[] byteArray)
|
||||
{
|
||||
if (byteArray == null || byteArray.Length < 100) throw new Exception($"数据长度错误:{Utility.ByteArrayToHexString(byteArray)}");
|
||||
//if (byteArray[98] != Utility.XOR(byteArray[1..^2])) throw new Exception($"数据校验错误:{Utility.ByteArrayToHexString(byteArray)}");
|
||||
Begin = byteArray[0];
|
||||
Command = byteArray[1];
|
||||
Car = BitConverter.ToUInt16(byteArray[2..4]);
|
||||
ActionId = BitConverter.ToUInt64(byteArray[4..12]);
|
||||
PlaceHolder = byteArray[12..14];
|
||||
NodeMessage = new NodeMessage().GetMessage(byteArray[14..39]);
|
||||
Reserve = byteArray[39..98];
|
||||
Check = byteArray[98];
|
||||
End = byteArray[99];
|
||||
return this;
|
||||
}
|
||||
|
||||
public byte[] GetByteArray()
|
||||
{
|
||||
var byteArray = new byte[100];
|
||||
byteArray[0] = Begin;
|
||||
byteArray[1] = Command;
|
||||
var car = BitConverter.GetBytes(Car);
|
||||
byteArray[2] = car[0];
|
||||
byteArray[3] = car[1];
|
||||
var action = BitConverter.GetBytes(ActionId);
|
||||
byteArray[4] = action[0];
|
||||
byteArray[5] = action[1];
|
||||
byteArray[6] = action[2];
|
||||
byteArray[7] = action[3];
|
||||
byteArray[8] = action[4];
|
||||
byteArray[9] = action[5];
|
||||
byteArray[10] = action[6];
|
||||
byteArray[11] = action[7];
|
||||
//预留两个字节PlaceHolder[12..14]
|
||||
var nodeMessage = NodeMessage.GetByteArray();
|
||||
Array.Copy(nodeMessage, 0, byteArray, 14, nodeMessage.Length);
|
||||
Array.Copy(Reserve, 0, byteArray, 39, Reserve.Length);
|
||||
//byteArray[98] = Check;
|
||||
byteArray[98] = Utility.XOR(byteArray[1..^2]);
|
||||
byteArray[99] = End;
|
||||
return byteArray;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
namespace FASS.Extend.Car.Fairyland.Plc
|
||||
{
|
||||
public class SendControlMessage
|
||||
{
|
||||
public byte Begin { get; set; } = 0xBB;
|
||||
public byte Command { get; set; } = 0x00;
|
||||
public ushort Car { get; set; }
|
||||
public ushort Param { get; set; }
|
||||
public byte[] Reserve { get; set; } = new byte[41];
|
||||
public byte Check { get; set; }
|
||||
public byte End { get; set; } = 0xEE;
|
||||
|
||||
public SendControlMessage SetMessage(
|
||||
byte command,
|
||||
ushort car,
|
||||
ushort param)
|
||||
{
|
||||
Command = command;
|
||||
Car = car;
|
||||
Param = param;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SendControlMessage GetMessage(byte[] byteArray)
|
||||
{
|
||||
if (byteArray == null || byteArray.Length < 50) throw new Exception($"数据长度错误: {Utility.ByteArrayToHexString(byteArray)}");
|
||||
//if (byteArray[48] != Utility.XOR(byteArray[1..^2])) throw new Exception($"数据校验错误:{Utility.ByteArrayToHexString(byteArray)}");
|
||||
Begin = byteArray[0];
|
||||
Command = byteArray[1];
|
||||
Car = BitConverter.ToUInt16(byteArray[2..4]);
|
||||
Param = BitConverter.ToUInt16(byteArray[4..6]);
|
||||
Reserve = byteArray[6..48];
|
||||
Check = byteArray[48];
|
||||
End = byteArray[49];
|
||||
return this;
|
||||
}
|
||||
|
||||
public byte[] GetByteArray()
|
||||
{
|
||||
var byteArray = new byte[50];
|
||||
byteArray[0] = Begin;
|
||||
byteArray[1] = Command;
|
||||
var car = BitConverter.GetBytes(Car);
|
||||
byteArray[2] = car[0];
|
||||
byteArray[3] = car[1];
|
||||
var param = BitConverter.GetBytes(Param);
|
||||
byteArray[4] = param[0];
|
||||
byteArray[5] = param[1];
|
||||
Array.Copy(Reserve, 0, byteArray, 6, Reserve.Length);
|
||||
//byteArray[48] = Check;
|
||||
byteArray[48] = Utility.XOR(byteArray[1..^2]);
|
||||
byteArray[49] = End;
|
||||
return byteArray;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
using System.Buffers;
|
||||
|
||||
namespace FASS.Extend.Car.Fairyland.Plc
|
||||
{
|
||||
public class SendNodesMessage
|
||||
{
|
||||
public byte Begin { get; set; } = 0xBB;
|
||||
public byte Command { get; set; } = 0xB1;
|
||||
public ushort Car { get; set; }
|
||||
public ulong Task { get; set; }
|
||||
public ushort Count { get; set; }
|
||||
public NodeMessage[] NodeMessages { get; set; } = new NodeMessage[10]
|
||||
{
|
||||
new NodeMessage(),
|
||||
new NodeMessage(),
|
||||
new NodeMessage(),
|
||||
new NodeMessage(),
|
||||
new NodeMessage(),
|
||||
new NodeMessage(),
|
||||
new NodeMessage(),
|
||||
new NodeMessage(),
|
||||
new NodeMessage(),
|
||||
new NodeMessage()
|
||||
};
|
||||
public byte[] Reserve { get; set; } = new byte[34];
|
||||
public byte Check { get; set; }
|
||||
public byte End { get; set; } = 0xEE;
|
||||
|
||||
public SendNodesMessage SetMessage(
|
||||
ushort car,
|
||||
ulong task,
|
||||
ushort count,
|
||||
NodeMessage[] nodeMessages)
|
||||
{
|
||||
Car = car;
|
||||
Task = task;
|
||||
Count = count;
|
||||
Array.Copy(nodeMessages, 0, NodeMessages, 0, nodeMessages.Length);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SendNodesMessage GetMessage(byte[] byteArray)
|
||||
{
|
||||
if (byteArray == null || byteArray.Length < 300) throw new Exception($"数据长度错误:{Utility.ByteArrayToHexString(byteArray)}");
|
||||
//if (byteArray[298] != Utility.XOR(byteArray[1..^2])) throw new Exception($"数据校验错误:{Utility.ByteArrayToHexString(byteArray)}");
|
||||
Begin = byteArray[0];
|
||||
Command = byteArray[1];
|
||||
Car = BitConverter.ToUInt16(byteArray[2..4]);
|
||||
Task = BitConverter.ToUInt64(byteArray[4..12]);
|
||||
Count = BitConverter.ToUInt16(byteArray[12..14]);
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
var start = i * 25 + 14;
|
||||
var end = start + 25;
|
||||
NodeMessages[i] = new NodeMessage().GetMessage(byteArray[start..end]);
|
||||
}
|
||||
Reserve = byteArray[263..298];
|
||||
Check = byteArray[298];
|
||||
End = byteArray[299];
|
||||
return this;
|
||||
}
|
||||
|
||||
public byte[] GetByteArray()
|
||||
{
|
||||
var byteArray = new byte[300];
|
||||
byteArray[0] = Begin;
|
||||
byteArray[1] = Command;
|
||||
var car = BitConverter.GetBytes(Car);
|
||||
byteArray[2] = car[0];
|
||||
byteArray[3] = car[1];
|
||||
var task = BitConverter.GetBytes(Task);
|
||||
byteArray[4] = task[0];
|
||||
byteArray[5] = task[1];
|
||||
byteArray[6] = task[2];
|
||||
byteArray[7] = task[3];
|
||||
byteArray[8] = task[4];
|
||||
byteArray[9] = task[5];
|
||||
byteArray[10] = task[6];
|
||||
byteArray[11] = task[7];
|
||||
var count = BitConverter.GetBytes(Count);
|
||||
byteArray[12] = count[0];
|
||||
byteArray[13] = count[1];
|
||||
var nodeMessages = NodeMessages.SelectMany(e => e.GetByteArray()).ToArray();
|
||||
Array.Copy(nodeMessages, 0, byteArray, 14, nodeMessages.Length);
|
||||
Array.Copy(Reserve, 0, byteArray, 264, Reserve.Length);
|
||||
//byteArray[298] = Check;
|
||||
byteArray[298] = Utility.XOR(byteArray[1..^2]);
|
||||
byteArray[299] = End;
|
||||
return byteArray;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace FASS.Extend.Car.Fairyland.Plc
|
||||
{
|
||||
public static class Utility
|
||||
{
|
||||
public static string ByteArrayToHexString(byte[]? byteArray, string separator = "")
|
||||
{
|
||||
if (byteArray is null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
return string.Join(separator, byteArray.Select(t => t.ToString("X2")));
|
||||
}
|
||||
|
||||
public static byte XOR(byte[] byteArray)
|
||||
{
|
||||
byte xor = 0;
|
||||
for (int i = 0; i < byteArray.Length; i++)
|
||||
{
|
||||
xor ^= byteArray[i];
|
||||
}
|
||||
return xor;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using System.Net;
|
||||
using TcpClient = Common.Net.Tcp.TcpClient;
|
||||
|
||||
namespace FASS.Extend.Car.Fairyland.Plc_v1
|
||||
{
|
||||
public class Command
|
||||
{
|
||||
public TcpClient Client { get; private set; }
|
||||
|
||||
public Command(IPEndPoint remote)
|
||||
{
|
||||
Client = new TcpClient()
|
||||
{
|
||||
RemoteEndPoint = remote,
|
||||
ConnectTimeout = 500,
|
||||
SendTimeout = 500,
|
||||
ReceiveTimeout = 500
|
||||
};
|
||||
}
|
||||
|
||||
public byte[]? SendState(byte command, ushort car)
|
||||
{
|
||||
var sendMessage = new SendControlMessage().SetMessage(command, car, 0);
|
||||
var sendByteArray = sendMessage.GetByteArray();
|
||||
var receiveByteArray = Client.SendAndReceive(sendByteArray);
|
||||
return receiveByteArray;
|
||||
}
|
||||
|
||||
public byte[]? SendControl(byte command, ushort car, ushort param)
|
||||
{
|
||||
var sendMessage = new SendControlMessage().SetMessage(command, car, param);
|
||||
var sendByteArray = sendMessage.GetByteArray();
|
||||
var receiveByteArray = Client.SendAndReceive(sendByteArray);
|
||||
return receiveByteArray;
|
||||
}
|
||||
|
||||
public static ReceiveStateMessage GetReceiveStateMessage(byte[] byteArray) => new ReceiveStateMessage().GetMessage(byteArray);
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>2.4.2</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Common.Net" Version="2.4.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,118 @@
|
||||
using System.Buffers.Binary;
|
||||
|
||||
namespace FASS.Extend.Car.Fairyland.Plc_v1
|
||||
{
|
||||
public class ReceiveStateMessage
|
||||
{
|
||||
public byte Begin { get; set; } = 0xBB;
|
||||
public byte Command { get; set; }
|
||||
public ushort Car { get; set; }
|
||||
public ushort CurrentNode { get; set; }
|
||||
public ulong Alarm { get; set; }
|
||||
public byte State { get; set; }
|
||||
public byte BatterySoc { get; set; }
|
||||
public float BatteryCurrent { get; set; }
|
||||
public float BatteryVoltage { get; set; }
|
||||
public byte Speed { get; set; }
|
||||
public ushort Angle { get; set; }
|
||||
public byte TaskState { get; set; }
|
||||
public byte LiftState { get; set; }
|
||||
public byte RollerState { get; set; }
|
||||
public byte Check { get; set; }
|
||||
public byte End { get; set; } = 0xEE;
|
||||
|
||||
public ReceiveStateMessage SetMessage(
|
||||
byte command,
|
||||
ushort car,
|
||||
ushort currentNode,
|
||||
ulong alarm,
|
||||
byte state,
|
||||
byte batterySoc,
|
||||
float batteryCurrent,
|
||||
float batteryVoltage,
|
||||
byte speed,
|
||||
ushort angle,
|
||||
byte taskState,
|
||||
byte liftState,
|
||||
byte rollerState)
|
||||
{
|
||||
Command = command;
|
||||
Car = car;
|
||||
CurrentNode = currentNode;
|
||||
Alarm = alarm;
|
||||
State = state;
|
||||
BatterySoc = batterySoc;
|
||||
BatteryCurrent = batteryCurrent;
|
||||
BatteryVoltage = batteryVoltage;
|
||||
Speed = speed;
|
||||
Angle = angle;
|
||||
TaskState = taskState;
|
||||
LiftState = liftState;
|
||||
RollerState = rollerState;
|
||||
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ReceiveStateMessage GetMessage(byte[] byteArray)
|
||||
{
|
||||
if (byteArray == null || byteArray.Length < 32 || byteArray[0] != 0xBB)
|
||||
throw new Exception($"数据长度错误:{Utility.ByteArrayToHexString(byteArray)}");
|
||||
//if (byteArray[98] != Utility.XOR(byteArray[1..^2])) throw new Exception($"数据校验错误:{Utility.ByteArrayToHexString(byteArray)}");
|
||||
Begin = byteArray[0];
|
||||
Command = byteArray[1];
|
||||
//Car = BitConverter.ToUInt16(byteArray[2..4]);
|
||||
Car = BinaryPrimitives.ReadUInt16BigEndian(byteArray.AsSpan(2));
|
||||
//CurrentNode = BitConverter.ToUInt16(byteArray[4..6]);
|
||||
CurrentNode = BinaryPrimitives.ReadUInt16BigEndian(byteArray.AsSpan(4));
|
||||
Alarm = BitConverter.ToUInt64(byteArray[6..14]);
|
||||
//Alarm = BinaryPrimitives.ReadUInt64BigEndian(byteArray.AsSpan(6));
|
||||
State = byteArray[14];
|
||||
BatterySoc = byteArray[15];
|
||||
//BatteryCurrent = BitConverter.ToSingle(byteArray[16..20]);
|
||||
BatteryCurrent = BinaryPrimitives.ReadSingleBigEndian(byteArray.AsSpan(16));
|
||||
//BatteryVoltage = BitConverter.ToSingle(byteArray[20..24]);
|
||||
BatteryVoltage = BinaryPrimitives.ReadSingleBigEndian(byteArray.AsSpan(20));
|
||||
Speed = byteArray[24];
|
||||
//Angle = BitConverter.ToUInt16(byteArray[25..27]);
|
||||
Angle = BinaryPrimitives.ReadUInt16BigEndian(byteArray.AsSpan(25));
|
||||
TaskState = byteArray[27];
|
||||
LiftState = byteArray[28];
|
||||
RollerState = byteArray[29];
|
||||
Check = byteArray[30];
|
||||
End = byteArray[31];
|
||||
return this;
|
||||
}
|
||||
|
||||
public byte[] GetByteArray()
|
||||
{
|
||||
var byteArray = new byte[100];
|
||||
byteArray[0] = Begin;
|
||||
byteArray[1] = Command;
|
||||
var car = BitConverter.GetBytes(Car);
|
||||
byteArray[2] = car[0];
|
||||
byteArray[3] = car[1];
|
||||
var currentNode = BitConverter.GetBytes(CurrentNode);
|
||||
byteArray[4] = currentNode[0];
|
||||
byteArray[5] = currentNode[1];
|
||||
var alarm = BitConverter.GetBytes(Alarm);
|
||||
Array.Copy(alarm, 0, byteArray, 6, alarm.Length);
|
||||
byteArray[14] = State;
|
||||
byteArray[15] = BatterySoc;
|
||||
var batteryCurrent = BitConverter.GetBytes(BatteryCurrent);
|
||||
Array.Copy(batteryCurrent, 0, byteArray, 16, batteryCurrent.Length);
|
||||
var batteryVoltage = BitConverter.GetBytes(BatteryVoltage);
|
||||
Array.Copy(batteryVoltage, 0, byteArray, 20, batteryVoltage.Length);
|
||||
byteArray[24] = Speed;
|
||||
var angle = BitConverter.GetBytes(Angle);
|
||||
byteArray[25] = angle[0];
|
||||
byteArray[26] = angle[1];
|
||||
byteArray[27] = TaskState;
|
||||
byteArray[28] = LiftState;
|
||||
byteArray[29] = RollerState;
|
||||
byteArray[30] = Utility.XOR(byteArray[1..^2]);
|
||||
byteArray[31] = End;
|
||||
return byteArray;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
namespace FASS.Extend.Car.Fairyland.Plc_v1
|
||||
{
|
||||
public class SendControlMessage
|
||||
{
|
||||
public byte Begin { get; set; } = 0xBB;
|
||||
public byte Command { get; set; } = 0x00;
|
||||
public ushort Car { get; set; }
|
||||
public ushort Param { get; set; }
|
||||
public byte[] Reserve { get; set; } = new byte[24];
|
||||
public byte Check { get; set; }
|
||||
public byte End { get; set; } = 0xEE;
|
||||
|
||||
public SendControlMessage SetMessage(
|
||||
byte command,
|
||||
ushort car,
|
||||
ushort param)
|
||||
{
|
||||
Command = command;
|
||||
Car = car;
|
||||
Param = param;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SendControlMessage GetMessage(byte[] byteArray)
|
||||
{
|
||||
if (byteArray == null || byteArray.Length < 50) throw new Exception($"数据长度错误: {Utility.ByteArrayToHexString(byteArray)}");
|
||||
//if (byteArray[48] != Utility.XOR(byteArray[1..^2])) throw new Exception($"数据校验错误:{Utility.ByteArrayToHexString(byteArray)}");
|
||||
Begin = byteArray[0];
|
||||
Command = byteArray[1];
|
||||
Car = BitConverter.ToUInt16(byteArray[2..4]);
|
||||
Param = BitConverter.ToUInt16(byteArray[4..6]);
|
||||
Reserve = byteArray[6..48];
|
||||
Check = byteArray[48];
|
||||
End = byteArray[49];
|
||||
return this;
|
||||
}
|
||||
|
||||
public byte[] GetByteArray()
|
||||
{
|
||||
var byteArray = new byte[32];
|
||||
byteArray[0] = Begin;
|
||||
byteArray[1] = Command;
|
||||
var car = BitConverter.GetBytes(Car);
|
||||
byteArray[2] = car[0];
|
||||
byteArray[3] = car[1];
|
||||
var param = BitConverter.GetBytes(Param);
|
||||
byteArray[4] = param[0];
|
||||
byteArray[5] = param[1];
|
||||
Array.Copy(Reserve, 0, byteArray, 6, Reserve.Length);
|
||||
//byteArray[48] = Check;
|
||||
byteArray[30] = Utility.XOR(byteArray[1..^2]);
|
||||
byteArray[31] = End;
|
||||
return byteArray;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace FASS.Extend.Car.Fairyland.Plc_v1
|
||||
{
|
||||
public static class Utility
|
||||
{
|
||||
public static string ByteArrayToHexString(byte[]? byteArray, string separator = "")
|
||||
{
|
||||
if (byteArray is null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
return string.Join(separator, byteArray.Select(t => t.ToString("X2")));
|
||||
}
|
||||
|
||||
public static byte XOR(byte[] byteArray)
|
||||
{
|
||||
byte xor = 0;
|
||||
for (int i = 0; i < byteArray.Length; i++)
|
||||
{
|
||||
xor ^= byteArray[i];
|
||||
}
|
||||
return xor;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace FASS.Extend.Car.Geekplus.Generic
|
||||
{
|
||||
public class Command
|
||||
{
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>2.4.2</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace FASS.Extend.Car.Hikrobot.Generic
|
||||
{
|
||||
public class Command
|
||||
{
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>2.4.2</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace FASS.Extend.Car.Kc.Generic
|
||||
{
|
||||
public class Command
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>2.4.2</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace FASS.Extend.Car.Seer.Generic
|
||||
{
|
||||
public class Command
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>2.4.2</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace FASS.Extend.Car.Standard.Cmr
|
||||
{
|
||||
public class Command
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>2.4.2</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,31 @@
|
||||
using MQTTnet;
|
||||
using MqttClient = Common.Net.Mqtt.MqttClient;
|
||||
|
||||
namespace FASS.Extend.Car.Standard.Vda5050
|
||||
{
|
||||
public class Command
|
||||
{
|
||||
public uint HeaderId { get; set; } = 0;
|
||||
public MqttClient Client { get; private set; }
|
||||
public Command(string host, int? port = null)
|
||||
{
|
||||
Client = new MqttClient() { Host = host, Port = port };
|
||||
Client.Initialize();
|
||||
}
|
||||
|
||||
public uint GetHeaderId()
|
||||
{
|
||||
return HeaderId == uint.MaxValue ? 1 : HeaderId++;
|
||||
}
|
||||
|
||||
public void SendOrder(string manufacturer, string serialNumber, string data, string interfaceName = "frld", string majorVersion = "v2.0")
|
||||
{
|
||||
Client.Client.PublishStringAsync($"{interfaceName}/{majorVersion}/{manufacturer}/{serialNumber}/order", data).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
public void SendInstantActions(string manufacturer, string serialNumber, string data, string interfaceName = "frld", string majorVersion = "v2.0")
|
||||
{
|
||||
Client.Client.PublishStringAsync($"{interfaceName}/{majorVersion}/{manufacturer}/{serialNumber}/instantActions", data).GetAwaiter().GetResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>2.4.2</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Common.Net" Version="2.4.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace FASS.Extend.Car.Standard.Vda5050.Models.Connection
|
||||
{
|
||||
public class Connection : Header
|
||||
{
|
||||
//public required Header Header { get; set; }
|
||||
public required string ConnectionState { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
namespace FASS.Extend.Car.Standard.Vda5050.Models
|
||||
{
|
||||
public class Enums
|
||||
{
|
||||
public class Action
|
||||
{
|
||||
public class BlockingType
|
||||
{
|
||||
public const string NONE = "NONE";
|
||||
public const string SOFT = "SOFT";
|
||||
public const string HARD = "HARD";
|
||||
}
|
||||
|
||||
public class ActionType
|
||||
{
|
||||
public const string stateRequest = "stateRequest";
|
||||
public const string factsheetRequest = "factsheetRequest";
|
||||
public const string startPause = "startPause";
|
||||
public const string stopPause = "stopPause";
|
||||
public const string cancelOrder = "cancelOrder";
|
||||
public const string recognize = "recognize";
|
||||
public const string liftFork = "liftFork";
|
||||
public const string turntableAction = "turntableAction";
|
||||
public const string preloadMap = "preloadMap";
|
||||
public const string switchMap = "switchMap";
|
||||
public const string switchMode = "switchMode";
|
||||
public const string readValue = "readValue";
|
||||
public const string writeValue = "writeValue";
|
||||
public const string doLocate = "doLocate";
|
||||
public const string doLocateConfirm = "doLocateConfirm";
|
||||
public const string palletLift = "palletLift";
|
||||
}
|
||||
}
|
||||
public class State
|
||||
{
|
||||
public class OperatingMode
|
||||
{
|
||||
public const string AUTOMATIC = "AUTOMATIC";
|
||||
public const string MANUAL = "MANUAL";
|
||||
}
|
||||
}
|
||||
public class ActionState
|
||||
{
|
||||
public class ActionStatus
|
||||
{
|
||||
public const string WAITING = "WAITING";
|
||||
public const string INITIALIZING = "INITIALIZING";
|
||||
public const string RUNNING = "RUNNING";
|
||||
public const string PAUSED = "PAUSED";
|
||||
public const string FINISHED = "FINISHED";
|
||||
public const string FAILED = "FAILED";
|
||||
}
|
||||
}
|
||||
public class Error
|
||||
{
|
||||
public class ErrorLevel
|
||||
{
|
||||
public const string WARNING = "WARNING";
|
||||
public const string FATAL = "FATAL";
|
||||
}
|
||||
}
|
||||
public class Info
|
||||
{
|
||||
public class InfoLevel
|
||||
{
|
||||
public const string DEBUG = "DEBUG";
|
||||
public const string INFO = "INFO";
|
||||
}
|
||||
}
|
||||
public class SafetyState
|
||||
{
|
||||
public class EStop
|
||||
{
|
||||
public const string AUTOACK = "AUTOACK";
|
||||
public const string MANUAL = "MANUAL";
|
||||
public const string REMOTE = "REMOTE";
|
||||
public const string NONE = "NONE";
|
||||
}
|
||||
}
|
||||
public class Connection
|
||||
{
|
||||
public class ConnectionState
|
||||
{
|
||||
public const string ONLINE = "ONLINE";
|
||||
public const string OFFLINE = "OFFLINE";
|
||||
public const string CONNECTIONBROKEN = "CONNECTIONBROKEN";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace FASS.Extend.Car.Standard.Vda5050.Models.Factsheet
|
||||
{
|
||||
public class Factsheet : Header
|
||||
{
|
||||
//public required Header Header { get; set; }
|
||||
public required ProtocolLimits ProtocolLimits { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace FASS.Extend.Car.Standard.Vda5050.Models.Factsheet
|
||||
{
|
||||
public class MaxArrayLens
|
||||
{
|
||||
[JsonPropertyName("order.nodes")]
|
||||
public required uint OrderNodes { get; set; }
|
||||
[JsonPropertyName("order.edges")]
|
||||
public required uint OrderEdges { get; set; }
|
||||
[JsonPropertyName("node.actions")]
|
||||
public required uint NodeActions { get; set; }
|
||||
[JsonPropertyName("edge.actions")]
|
||||
public required uint EdgeActions { get; set; }
|
||||
[JsonPropertyName("actions.actionsParameters")]
|
||||
public required uint ActionsActionsParameters { get; set; }
|
||||
[JsonPropertyName("instantActions")]
|
||||
public required uint InstantActions { get; set; }
|
||||
[JsonPropertyName("state.nodeStates")]
|
||||
public required uint StateNodeStates { get; set; }
|
||||
[JsonPropertyName("state.edgeStates")]
|
||||
public required uint StateEdgeStates { get; set; }
|
||||
[JsonPropertyName("state.loads")]
|
||||
public required uint StateLoads { get; set; }
|
||||
[JsonPropertyName("state.actionStates")]
|
||||
public required uint StateActionStates { get; set; }
|
||||
[JsonPropertyName("state.errors")]
|
||||
public required uint StateErrors { get; set; }
|
||||
[JsonPropertyName("state.information")]
|
||||
public required uint StateInformations { get; set; }
|
||||
[JsonPropertyName("error.errorReferences")]
|
||||
public required uint ErrorErrorReferences { get; set; }
|
||||
[JsonPropertyName("information.infoReferences")]
|
||||
public required uint InformationsInfoReferences { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace FASS.Extend.Car.Standard.Vda5050.Models.Factsheet
|
||||
{
|
||||
public class MaxStringLens
|
||||
{
|
||||
public required uint MsgLen { get; set; }
|
||||
public required uint TopicSerialLen { get; set; }
|
||||
public required uint TopicElemLen { get; set; }
|
||||
public required uint IdLen { get; set; }
|
||||
public required bool IdNumericalOnly { get; set; }
|
||||
public required uint EnumLen { get; set; }
|
||||
public required uint LoadIdLen { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace FASS.Extend.Car.Standard.Vda5050.Models.Factsheet
|
||||
{
|
||||
public class ProtocolLimits
|
||||
{
|
||||
public required MaxStringLens MaxStringLens { get; set; }
|
||||
public required MaxArrayLens MaxArrayLens { get; set; }
|
||||
public required Timing Timing { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace FASS.Extend.Car.Standard.Vda5050.Models.Factsheet
|
||||
{
|
||||
public class Timing
|
||||
{
|
||||
public required double MinOrderInterval { get; set; }
|
||||
public required double MinStateInterval { get; set; }
|
||||
public required double DefaultStateInterval { get; set; }
|
||||
public required double VisualizationInterval { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace FASS.Extend.Car.Standard.Vda5050.Models
|
||||
{
|
||||
public class Header
|
||||
{
|
||||
public required uint HeaderId { get; set; }
|
||||
public required string Timestamp { get; set; }
|
||||
public required string Version { get; set; }
|
||||
public required string Manufacturer { get; set; }
|
||||
public required string SerialNumber { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace FASS.Extend.Car.Standard.Vda5050.Models.Order
|
||||
{
|
||||
public class Action
|
||||
{
|
||||
public required string ActionType { get; set; }
|
||||
public required string ActionId { get; set; }
|
||||
public required string ActionDescription { get; set; }
|
||||
public required string BlockingType { get; set; }
|
||||
public required List<ActionParameter> ActionParameters { get; set; } = [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace FASS.Extend.Car.Standard.Vda5050.Models.Order
|
||||
{
|
||||
public class ActionParameter
|
||||
{
|
||||
public required string Key { get; set; }
|
||||
public required string Value { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace FASS.Extend.Car.Standard.Vda5050.Models.Order
|
||||
{
|
||||
public class Edge
|
||||
{
|
||||
public required string EdgeId { get; set; }
|
||||
public required uint SequenceId { get; set; }
|
||||
public string? EdgeDescription { get; set; }
|
||||
public required bool Released { get; set; }
|
||||
public required string StartNodeId { get; set; }
|
||||
public required string EndNodeId { get; set; }
|
||||
public double? MaxSpeed { get; set; }
|
||||
public required List<Action> Actions { get; set; } = [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace FASS.Extend.Car.Standard.Vda5050.Models.Order
|
||||
{
|
||||
public class Node
|
||||
{
|
||||
public required string NodeId { get; set; }
|
||||
public required uint SequenceId { get; set; }
|
||||
public string? NodeDescription { get; set; }
|
||||
public required bool Released { get; set; }
|
||||
public NodePosition? NodePosition { get; set; }
|
||||
public required List<Action> Actions { get; set; } = [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace FASS.Extend.Car.Standard.Vda5050.Models.Order
|
||||
{
|
||||
public class NodePosition
|
||||
{
|
||||
public double? Theta { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace FASS.Extend.Car.Standard.Vda5050.Models.Order
|
||||
{
|
||||
public class Order : Header
|
||||
{
|
||||
//public required Header Header { get; set; }
|
||||
public required string OrderId { get; set; }
|
||||
public required uint OrderUpdateId { get; set; }
|
||||
public required List<Node> Nodes { get; set; } = [];
|
||||
public required List<Edge> Edges { get; set; } = [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace FASS.Extend.Car.Standard.Vda5050.Models.State
|
||||
{
|
||||
public class ActionState
|
||||
{
|
||||
public required string ActionId { get; set; }
|
||||
public string? ActionType { get; set; }
|
||||
public string? ActionDescription { get; set; }
|
||||
public required string ActionStatus { get; set; }
|
||||
public required string ResultDescription { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace FASS.Extend.Car.Standard.Vda5050.Models.State
|
||||
{
|
||||
public class AgvPosition
|
||||
{
|
||||
public required bool PositionInitialized { get; set; }
|
||||
public double? LocalizationScore { get; set; }
|
||||
public required double X { get; set; }
|
||||
public required double Y { get; set; }
|
||||
public required double Theta { get; set; }
|
||||
public required string MapId { get; set; }
|
||||
public string? MapDescription { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace FASS.Extend.Car.Standard.Vda5050.Models.State
|
||||
{
|
||||
public class BatteryState
|
||||
{
|
||||
public required double BatteryCharge { get; set; }
|
||||
public double? BatteryVoltage { get; set; }
|
||||
public required bool Charging { get; set; }
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
namespace FASS.Extend.Car.Standard.Vda5050.Models.State
|
||||
{
|
||||
public class BoundingBoxReference
|
||||
{
|
||||
public required double X { get; set; }
|
||||
public required double Y { get; set; }
|
||||
public required double Z { get; set; }
|
||||
public double? Theta { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace FASS.Extend.Car.Standard.Vda5050.Models.State
|
||||
{
|
||||
public class EdgeState
|
||||
{
|
||||
public required string EdgeId { get; set; }
|
||||
public required int SequenceId { get; set; }
|
||||
public string? EdgeDescription { get; set; }
|
||||
public required bool Released { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace FASS.Extend.Car.Standard.Vda5050.Models.State
|
||||
{
|
||||
public class Error
|
||||
{
|
||||
public required string ErrorType { get; set; }
|
||||
public required List<ErrorReference> ErrorReferences { get; set; } = [];
|
||||
public string? ErrorDescription { get; set; }
|
||||
public required string ErrorLevel { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace FASS.Extend.Car.Standard.Vda5050.Models.State
|
||||
{
|
||||
public class ErrorReference
|
||||
{
|
||||
public required string ReferenceKey { get; set; }
|
||||
public required string ReferenceValue { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace FASS.Extend.Car.Standard.Vda5050.Models.State
|
||||
{
|
||||
public class Info
|
||||
{
|
||||
public required string InfoType { get; set; }
|
||||
public required List<InfoReference> InfoReferences { get; set; } = [];
|
||||
public string? InfoDescription { get; set; }
|
||||
public required string InfoLevel { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace FASS.Extend.Car.Standard.Vda5050.Models.State
|
||||
{
|
||||
public class InfoReference
|
||||
{
|
||||
public required string ReferenceKey { get; set; }
|
||||
public required string ReferenceValue { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace FASS.Extend.Car.Standard.Vda5050.Models.State
|
||||
{
|
||||
public class Load
|
||||
{
|
||||
public string? LoadId { get; set; }
|
||||
public required string LoadType { get; set; }
|
||||
public string? LoadPosition { get; set; }
|
||||
public required BoundingBoxReference BoundingBoxReference { get; set; }
|
||||
public required LoadDimensions LoadDimensions { get; set; }
|
||||
public required double Weight { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace FASS.Extend.Car.Standard.Vda5050.Models.State
|
||||
{
|
||||
public class LoadDimensions
|
||||
{
|
||||
public required double Length { get; set; }
|
||||
public required double Width { get; set; }
|
||||
public required double Height { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace FASS.Extend.Car.Standard.Vda5050.Models.State
|
||||
{
|
||||
public class NodeState
|
||||
{
|
||||
public required string NodeId { get; set; }
|
||||
public required int SequenceId { get; set; }
|
||||
public string? NodeDescription { get; set; }
|
||||
public required bool Released { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace FASS.Extend.Car.Standard.Vda5050.Models.State
|
||||
{
|
||||
public class SafetyState
|
||||
{
|
||||
public required string EStop { get; set; }
|
||||
public required bool FieldViolation { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
namespace FASS.Extend.Car.Standard.Vda5050.Models.State
|
||||
{
|
||||
public class State : Header
|
||||
{
|
||||
//public required Header Header { get; set; }
|
||||
public required string OrderId { get; set; }
|
||||
public required uint OrderUpdateId { get; set; }
|
||||
public required string LastNodeId { get; set; }
|
||||
public required uint LastNodeSequenceId { get; set; }
|
||||
public required List<NodeState> NodeStates { get; set; } = [];
|
||||
public required List<EdgeState> EdgeStates { get; set; } = [];
|
||||
public AgvPosition? AgvPosition { get; set; }
|
||||
public required Velocity Velocity { get; set; }
|
||||
public required List<Load> Loads { get; set; } = [];
|
||||
public required bool Driving { get; set; }
|
||||
public required bool Paused { get; set; }
|
||||
public required List<ActionState> ActionStates { get; set; } = [];
|
||||
public required BatteryState BatteryState { get; set; }
|
||||
public required string OperatingMode { get; set; }
|
||||
public required List<Error> Errors { get; set; } = [];
|
||||
public required List<Info> Information { get; set; } = [];
|
||||
public required SafetyState SafetyState { get; set; } = null!;
|
||||
public float? KcForkHeight { get; set; }//KC定制
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace FASS.Extend.Car.Standard.Vda5050.Models.State
|
||||
{
|
||||
public class Velocity
|
||||
{
|
||||
public required double Vx { get; set; }
|
||||
public required double Vy { get; set; }
|
||||
public required double Omega { get; set; }
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
using FASS.Extend.Car.Standard.Vda5050.Models.State;
|
||||
|
||||
namespace FASS.Extend.Car.Standard.Vda5050.Models.Visualization
|
||||
{
|
||||
public class Visualization : Header
|
||||
{
|
||||
//public required Header Header { get; set; }
|
||||
public required AgvPosition AgvPosition { get; set; }
|
||||
public required Velocity Velocity { get; set; }
|
||||
public required string LastNodeId { get; set; }
|
||||
public required uint LastNodeSequenceId { get; set; }
|
||||
public required List<NodeState> NodeStates { get; set; } = [];
|
||||
public required List<EdgeState> EdgeStates { get; set; } = [];
|
||||
public required List<ActionState> ActionStates { get; set; } = [];
|
||||
public required BatteryState BatteryState { get; set; }
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
using Action = FASS.Extend.Car.Standard.Vda5050.Models.Order.Action;
|
||||
|
||||
namespace FASS.Extend.Car.Standard.Vda5050.Models.InstantActions
|
||||
{
|
||||
public class InstantActions : Header
|
||||
{
|
||||
//public required Header Header { get; set; }
|
||||
public required List<Action> Actions { get; set; } = [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace FASS.Extend.Car.Standard.Vda5050
|
||||
{
|
||||
public static class Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// 计算AGV的合成速度(标量)
|
||||
/// </summary>
|
||||
/// <param name="vx">X轴速度分量</param>
|
||||
/// <param name="vy">Y轴速度分量</param>
|
||||
/// <returns>合成速度值</returns>
|
||||
public static double CalculateSpeed(double vx, double vy)
|
||||
{
|
||||
return Math.Sqrt(vx * vx + vy * vy);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算AGV运动方向角度(弧度制,范围[-π, π])
|
||||
/// </summary>
|
||||
public static double CalculateDirection(double vx, double vy)
|
||||
{
|
||||
return Math.Atan2(vy, vx);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using Common.Net.Tcp;
|
||||
using System.Net;
|
||||
|
||||
namespace FASS.Extend.Charge
|
||||
{
|
||||
public class Command
|
||||
{
|
||||
public TcpClient Client { get; private set; }
|
||||
|
||||
public Command(string ip, string port)
|
||||
{
|
||||
Client = new TcpClient()
|
||||
{
|
||||
RemoteEndPoint = new IPEndPoint(IPAddress.Parse(ip), int.Parse(port)),
|
||||
SendTimeout = 500,
|
||||
ReceiveTimeout = 500
|
||||
};
|
||||
}
|
||||
|
||||
public byte[]? SendCharge(byte command, ushort car, float chargeElectric, float chargeVoltage, ushort chargeTimeSpan, ushort soc, float electricCurrent, float voltage)
|
||||
{
|
||||
var sendMessage = new SendMessage().SetMessage(command, car, chargeElectric, chargeVoltage, chargeTimeSpan, soc, electricCurrent, voltage);
|
||||
var sendByteArray = sendMessage.GetByteArray();
|
||||
var receiveByteArray = Client.SendAndReceive(sendByteArray);
|
||||
return receiveByteArray;
|
||||
}
|
||||
|
||||
public static ReceiveMessage GetReceiveMessage(byte[] byteArray) => new ReceiveMessage().GetMessage(byteArray);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>2.4.2</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Common.Net" Version="2.4.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,92 @@
|
||||
namespace FASS.Extend.Charge
|
||||
{
|
||||
public class ReceiveMessage
|
||||
{
|
||||
// 起始码
|
||||
public byte Begin { get; set; } = 0xBB;
|
||||
|
||||
// 实际充电电流
|
||||
public float CurrentElectric { get; set; }
|
||||
|
||||
// 实际充电电压
|
||||
public float CurrentVoltage { get; set; }
|
||||
|
||||
// 实际充电时长(s)
|
||||
public ushort ChargeTimeSpan { get; set; }
|
||||
|
||||
// 充电桩状态 3 充电中 2 停止中
|
||||
public byte ChargeState { get; set; }
|
||||
|
||||
// 异常状态
|
||||
public ushort ExceptionState { get; set; }
|
||||
|
||||
// 侧充状态 1 伸出位, 2 缩回位 3 运动位
|
||||
public byte ElectrodeState { get; set; }
|
||||
|
||||
// 校验位
|
||||
public byte Check { get; set; }
|
||||
|
||||
// 结束码
|
||||
public byte End { get; set; } = 0xEE;
|
||||
|
||||
public ReceiveMessage SetMessage(
|
||||
float chargeElectric,
|
||||
float chargeVoltage,
|
||||
ushort chargeTimeSpan,
|
||||
byte chargeState,
|
||||
ushort exceptionState,
|
||||
byte electrodeState)
|
||||
{
|
||||
CurrentElectric = chargeElectric;
|
||||
CurrentVoltage = chargeVoltage;
|
||||
ChargeTimeSpan = chargeTimeSpan;
|
||||
ChargeState = chargeState;
|
||||
ExceptionState = exceptionState;
|
||||
ElectrodeState = electrodeState;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ReceiveMessage GetMessage(byte[] byteArray)
|
||||
{
|
||||
if (byteArray == null || byteArray.Length < 32) throw new Exception($"数据长度错误:{Utility.ByteArrayToHexString(byteArray)}");
|
||||
//if (byteArray[30] != Utility.CheckSum(byteArray[1..^2])) throw new Exception($"数据校验错误:{Utility.ByteArrayToHexString(byteArray)}");
|
||||
Begin = byteArray[0];
|
||||
CurrentElectric = BitConverter.ToSingle(new byte[] { byteArray[4], byteArray[3], byteArray[2], byteArray[1] }, 0);
|
||||
CurrentVoltage = BitConverter.ToSingle(new byte[] { byteArray[8], byteArray[7], byteArray[6], byteArray[5] }, 0);
|
||||
ChargeTimeSpan = BitConverter.ToUInt16(new byte[] { byteArray[10], byteArray[9] }, 0);
|
||||
ChargeState = byteArray[14];
|
||||
ExceptionState = BitConverter.ToUInt16(new byte[] { byteArray[16], byteArray[15] }, 0);
|
||||
ElectrodeState = byteArray[28];
|
||||
Check = byteArray[30];
|
||||
End = byteArray[31];
|
||||
return this;
|
||||
}
|
||||
|
||||
public byte[] GetByteArray()
|
||||
{
|
||||
var byteArray = new byte[32];
|
||||
byteArray[0] = Begin;
|
||||
var chargeElectric = BitConverter.GetBytes(CurrentElectric);
|
||||
byteArray[1] = chargeElectric[3];
|
||||
byteArray[2] = chargeElectric[2];
|
||||
byteArray[3] = chargeElectric[1];
|
||||
byteArray[4] = chargeElectric[0];
|
||||
var chargeVoltage = BitConverter.GetBytes(CurrentVoltage);
|
||||
byteArray[5] = chargeVoltage[3];
|
||||
byteArray[6] = chargeVoltage[2];
|
||||
byteArray[7] = chargeVoltage[1];
|
||||
byteArray[8] = chargeVoltage[0];
|
||||
var chargeTimeSpan = BitConverter.GetBytes(ChargeTimeSpan);
|
||||
byteArray[9] = chargeTimeSpan[1];
|
||||
byteArray[10] = chargeTimeSpan[0];
|
||||
byteArray[14] = ChargeState;
|
||||
var exception = BitConverter.GetBytes(ExceptionState);
|
||||
byteArray[15] = exception[1];
|
||||
byteArray[16] = exception[0];
|
||||
byteArray[28] = ElectrodeState;
|
||||
//byteArray[30] = Utility.CheckSum(byteArray[1..^2]);
|
||||
byteArray[31] = End;
|
||||
return byteArray;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
namespace FASS.Extend.Charge
|
||||
{
|
||||
public class SendMessage
|
||||
{
|
||||
// 起始码
|
||||
public byte Begin { get; set; } = 0xBB;
|
||||
|
||||
// 充电动作 0查询、1启动,2停止,3急停(预留功能)
|
||||
public byte Command { get; set; }
|
||||
|
||||
// 充电电流
|
||||
public float ChargeElectric { get; set; }
|
||||
|
||||
// 充电电压
|
||||
public float ChargeVoltage { get; set; }
|
||||
|
||||
// 充电时长
|
||||
public ushort ChargeTimeSpan { get; set; }
|
||||
|
||||
// 车辆编号
|
||||
public ushort Car { get; set; }
|
||||
|
||||
// 电池电量
|
||||
public ushort Soc { get; set; }
|
||||
|
||||
// 电池电流
|
||||
public float ElectricCurrent { get; set; }
|
||||
|
||||
// 电池电压
|
||||
public float Voltage { get; set; }
|
||||
|
||||
// 预留
|
||||
public byte[] Reserve { get; set; } = new byte[7];
|
||||
|
||||
public byte End { get; set; } = 0xEE;
|
||||
|
||||
|
||||
public SendMessage SetMessage(
|
||||
byte command,
|
||||
ushort car,
|
||||
float chargeElectric,
|
||||
float chargeVoltage,
|
||||
ushort chargeTimeSpan,
|
||||
ushort soc,
|
||||
float electricCurrent,
|
||||
float voltage)
|
||||
{
|
||||
Command = command;
|
||||
Car = car;
|
||||
ChargeElectric = chargeElectric;
|
||||
ChargeVoltage = chargeVoltage;
|
||||
ChargeTimeSpan = chargeTimeSpan;
|
||||
Soc = soc;
|
||||
ElectricCurrent = electricCurrent;
|
||||
Voltage = voltage;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SendMessage GetMessage(byte[] byteArray)
|
||||
{
|
||||
if (byteArray == null || byteArray.Length < 32) throw new Exception($"数据长度错误: {Utility.ByteArrayToHexString(byteArray)}");
|
||||
//if (byteArray[30] != Utility.CheckSum(byteArray[1..^2])) throw new Exception($"数据校验错误:{Utility.ByteArrayToHexString(byteArray)}");
|
||||
Begin = byteArray[0];
|
||||
Command = byteArray[1];
|
||||
ChargeElectric = BitConverter.ToSingle(new byte[] { byteArray[5], byteArray[4], byteArray[3], byteArray[2] }, 0);
|
||||
ChargeElectric = BitConverter.ToSingle(new byte[] { byteArray[9], byteArray[8], byteArray[7], byteArray[6] }, 0);
|
||||
ChargeTimeSpan = BitConverter.ToUInt16(new byte[] { byteArray[11], byteArray[10] }, 0);
|
||||
Car = BitConverter.ToUInt16(new byte[] { byteArray[13], byteArray[12] }, 0);
|
||||
Soc = BitConverter.ToUInt16(new byte[] { byteArray[15], byteArray[14] }, 0);
|
||||
ElectricCurrent = BitConverter.ToSingle(new byte[] { byteArray[19], byteArray[18], byteArray[17], byteArray[16] }, 0);
|
||||
Voltage = BitConverter.ToSingle(new byte[] { byteArray[23], byteArray[22], byteArray[21], byteArray[20] }, 0);
|
||||
Reserve = byteArray[24..31];
|
||||
End = byteArray[31];
|
||||
return this;
|
||||
}
|
||||
|
||||
public byte[] GetByteArray()
|
||||
{
|
||||
var byteArray = new byte[32];
|
||||
byteArray[0] = Begin;
|
||||
byteArray[1] = Command;
|
||||
var chargeElectric = BitConverter.GetBytes(ChargeElectric);
|
||||
byteArray[2] = chargeElectric[3];
|
||||
byteArray[3] = chargeElectric[2];
|
||||
byteArray[4] = chargeElectric[1];
|
||||
byteArray[5] = chargeElectric[0];
|
||||
var chargeVoltage = BitConverter.GetBytes(ChargeVoltage);
|
||||
byteArray[6] = chargeVoltage[3];
|
||||
byteArray[7] = chargeVoltage[2];
|
||||
byteArray[8] = chargeVoltage[1];
|
||||
byteArray[9] = chargeVoltage[0];
|
||||
var chargeTimeSpan = BitConverter.GetBytes(ChargeTimeSpan);
|
||||
byteArray[10] = chargeTimeSpan[1];
|
||||
byteArray[11] = chargeTimeSpan[0];
|
||||
var car = BitConverter.GetBytes(Car);
|
||||
byteArray[12] = car[1];
|
||||
byteArray[13] = car[0];
|
||||
var soc = BitConverter.GetBytes(Soc);
|
||||
byteArray[14] = soc[1];
|
||||
byteArray[15] = soc[0];
|
||||
var electricCurrent = BitConverter.GetBytes(ElectricCurrent);
|
||||
byteArray[16] = electricCurrent[3];
|
||||
byteArray[17] = electricCurrent[2];
|
||||
byteArray[18] = electricCurrent[1];
|
||||
byteArray[19] = electricCurrent[0];
|
||||
var voltage = BitConverter.GetBytes(Voltage);
|
||||
byteArray[20] = voltage[3];
|
||||
byteArray[21] = voltage[2];
|
||||
byteArray[22] = voltage[1];
|
||||
byteArray[23] = voltage[0];
|
||||
Array.Copy(Reserve, 0, byteArray, 24, Reserve.Length);
|
||||
byteArray[31] = End;
|
||||
return byteArray;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
namespace FASS.Extend.Charge
|
||||
{
|
||||
public static class Utility
|
||||
{
|
||||
public static string ByteArrayToHexString(byte[]? byteArray, string separator = "")
|
||||
{
|
||||
if (byteArray is null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
return string.Join(separator, byteArray.Select(t => t.ToString("X2")));
|
||||
}
|
||||
|
||||
public static byte XOR(byte[] byteArray)
|
||||
{
|
||||
byte xor = 0;
|
||||
for (int i = 0; i < byteArray.Length; i++)
|
||||
{
|
||||
xor ^= byteArray[i];
|
||||
}
|
||||
return xor;
|
||||
}
|
||||
|
||||
public static byte CheckSum(byte[] byteArray)
|
||||
{
|
||||
byte sum = 0;
|
||||
for (int i = 0; i < byteArray.Length - 1; i++)
|
||||
{
|
||||
sum += byteArray[i];
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,299 @@
|
||||
using Common.Device.Clients.PLC;
|
||||
using Common.Device.Clients.PLC.Enums;
|
||||
|
||||
namespace FASS.Extend.Conveyor
|
||||
{
|
||||
public class Command
|
||||
{
|
||||
public SiemensClient Client { get; private set; }
|
||||
|
||||
public Command(string ip, string port)
|
||||
{
|
||||
Client = new SiemensClient(SiemensVersion.S7_1200, ip, int.Parse(port), timeout: 500);
|
||||
}
|
||||
|
||||
public bool LeftInRequest()
|
||||
{
|
||||
var result = false;
|
||||
try
|
||||
{
|
||||
Client.Open();
|
||||
Client.Write("DB6.1.3", false);
|
||||
Client.Write("DB6.1.0", true);
|
||||
if (Client.ReadBoolean("DB6.3.0").Value)
|
||||
{
|
||||
Client.Write("DB6.1.0", false);
|
||||
Client.Write("DB6.1.1", true);
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Client.Close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool LeftOutRequest()
|
||||
{
|
||||
var result = false;
|
||||
try
|
||||
{
|
||||
Client.Open();
|
||||
Client.Write("DB6.1.1", false);
|
||||
Client.Write("DB6.1.2", true);
|
||||
if (Client.ReadBoolean("DB6.3.2").Value)
|
||||
{
|
||||
Client.Write("DB6.1.2", false);
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Client.Close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool LeftOutReponse()
|
||||
{
|
||||
var result = false;
|
||||
try
|
||||
{
|
||||
Client.Open();
|
||||
Client.Write("DB6.1.3", true);
|
||||
result = true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Client.Close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool RightInRequest()
|
||||
{
|
||||
var result = false;
|
||||
try
|
||||
{
|
||||
Client.Open();
|
||||
Client.Write("DB6.1.7", false);
|
||||
Client.Write("DB6.1.4", true);
|
||||
if (Client.ReadBoolean("DB6.3.1").Value)
|
||||
{
|
||||
Client.Write("DB6.1.4", false);
|
||||
Client.Write("DB6.1.5", true);
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Client.Close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool RightOutRequest()
|
||||
{
|
||||
var result = false;
|
||||
try
|
||||
{
|
||||
Client.Open();
|
||||
Client.Write("DB6.1.5", false);
|
||||
Client.Write("DB6.1.6", true);
|
||||
if (Client.ReadBoolean("DB6.3.3").Value)
|
||||
{
|
||||
Client.Write("DB6.1.6", false);
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Client.Close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool RightOutReponse()
|
||||
{
|
||||
var result = false;
|
||||
try
|
||||
{
|
||||
Client.Open();
|
||||
Client.Write("DB6.1.7", true);
|
||||
result = true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Client.Close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//public bool LeftInRequest()
|
||||
//{
|
||||
// var result = false;
|
||||
// try
|
||||
// {
|
||||
// Client.Open();
|
||||
// Client.Write("DB6.0.0", true);
|
||||
// if (Client.ReadBoolean("DB6.2.0").Value)
|
||||
// {
|
||||
// Client.Write("DB6.0.0", false);
|
||||
// Client.Write("DB6.0.1", true);
|
||||
// result = true;
|
||||
// }
|
||||
// }
|
||||
// catch
|
||||
// {
|
||||
// result = false;
|
||||
// }
|
||||
// finally
|
||||
// {
|
||||
// Client.Close();
|
||||
// }
|
||||
// return result;
|
||||
//}
|
||||
|
||||
//public bool LeftOutRequest()
|
||||
//{
|
||||
// var result = false;
|
||||
// try
|
||||
// {
|
||||
// Client.Open();
|
||||
// Client.Write("DB6.0.1", false);
|
||||
// Client.Write("DB6.0.2", true);
|
||||
// if (Client.ReadBoolean("DB6.2.2").Value)
|
||||
// {
|
||||
// Client.Write("DB6.0.2", false);
|
||||
// result = true;
|
||||
// }
|
||||
// }
|
||||
// catch
|
||||
// {
|
||||
// result = false;
|
||||
// }
|
||||
// finally
|
||||
// {
|
||||
// Client.Close();
|
||||
// }
|
||||
// return result;
|
||||
//}
|
||||
|
||||
//public bool LeftOutReponse()
|
||||
//{
|
||||
// var result = false;
|
||||
// try
|
||||
// {
|
||||
// Client.Open();
|
||||
// Client.Write("DB6.0.3", true);
|
||||
// Thread.Sleep(1000);
|
||||
// Client.Write("DB6.0.3", false);
|
||||
// result = true;
|
||||
// }
|
||||
// catch
|
||||
// {
|
||||
// result = false;
|
||||
// }
|
||||
// finally
|
||||
// {
|
||||
// Client.Close();
|
||||
// }
|
||||
// return result;
|
||||
//}
|
||||
|
||||
//public bool RightInRequest()
|
||||
//{
|
||||
// var result = false;
|
||||
// try
|
||||
// {
|
||||
// Client.Open();
|
||||
// Client.Write("DB6.0.4", true);
|
||||
// if (Client.ReadBoolean("DB6.2.1").Value)
|
||||
// {
|
||||
// Client.Write("DB6.0.4", false);
|
||||
// Client.Write("DB6.0.5", true);
|
||||
// result = true;
|
||||
// }
|
||||
// }
|
||||
// catch
|
||||
// {
|
||||
// result = false;
|
||||
// }
|
||||
// finally
|
||||
// {
|
||||
// Client.Close();
|
||||
// }
|
||||
// return result;
|
||||
//}
|
||||
|
||||
//public bool RightOutRequest()
|
||||
//{
|
||||
// var result = false;
|
||||
// try
|
||||
// {
|
||||
// Client.Open();
|
||||
// Client.Write("DB6.0.5", false);
|
||||
// Client.Write("DB6.0.6", true);
|
||||
// if (Client.ReadBoolean("DB6.2.3").Value)
|
||||
// {
|
||||
// Client.Write("DB6.0.6", false);
|
||||
// result = true;
|
||||
// }
|
||||
// }
|
||||
// catch
|
||||
// {
|
||||
// result = false;
|
||||
// }
|
||||
// finally
|
||||
// {
|
||||
// Client.Close();
|
||||
// }
|
||||
// return result;
|
||||
//}
|
||||
|
||||
//public bool RightOutReponse()
|
||||
//{
|
||||
// var result = false;
|
||||
// try
|
||||
// {
|
||||
// Client.Open();
|
||||
// Client.Write("DB6.0.7", true);
|
||||
// result = true;
|
||||
// }
|
||||
// catch
|
||||
// {
|
||||
// result = false;
|
||||
// }
|
||||
// finally
|
||||
// {
|
||||
// Client.Close();
|
||||
// }
|
||||
// return result;
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>2.4.2</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Common.Device" Version="2.4.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace FASS.Extend.Door
|
||||
{
|
||||
internal class Command
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>2.4.2</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace FASS.Extend.Elevator
|
||||
{
|
||||
public class Command
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>2.4.2</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,47 @@
|
||||
using Common.Device.Clients.Modbus;
|
||||
using System.IO.Ports;
|
||||
|
||||
namespace FASS.Extend.Light
|
||||
{
|
||||
public class Command
|
||||
{
|
||||
public ModbusRtuClient Client { get; private set; }
|
||||
|
||||
public byte StationNumber { get; private set; }
|
||||
|
||||
public Command(string portName, string baudRate, string stationNumber)
|
||||
{
|
||||
Client = new ModbusRtuClient(portName, int.Parse(baudRate), 8, StopBits.One, Parity.None, 500);
|
||||
StationNumber = byte.Parse(stationNumber);
|
||||
}
|
||||
|
||||
public bool Switch(string close, string open)
|
||||
{
|
||||
var result = false;
|
||||
try
|
||||
{
|
||||
Client.Open();
|
||||
Client.Write(close, false, StationNumber);
|
||||
Client.Write(open, true, StationNumber);
|
||||
var closeResult = Client.ReadCoil(close, StationNumber);
|
||||
var openResult = Client.ReadCoil(open, StationNumber);
|
||||
if (closeResult.IsSucceed && openResult.IsSucceed)
|
||||
{
|
||||
if (closeResult.Value == false && openResult.Value == true)
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Client.Close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>2.4.2</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Common.Device" Version="2.4.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user