|
|
|
|
using Entity.Constant;
|
|
|
|
|
using HslCommunication.Enthernet;
|
|
|
|
|
using HybirdFrameworkCore.Autofac.Attribute;
|
|
|
|
|
using HybirdFrameworkCore.Entity;
|
|
|
|
|
using HybirdFrameworkDriver.TcpClient;
|
|
|
|
|
using log4net;
|
|
|
|
|
using Service.Execute;
|
|
|
|
|
using Service.Execute.Model;
|
|
|
|
|
using Decoder = Service.Padar.Codec.Decoder;
|
|
|
|
|
using Encoder = Service.Padar.Codec.Encoder;
|
|
|
|
|
|
|
|
|
|
namespace Service.Padar.Client;
|
|
|
|
|
|
|
|
|
|
[Scope]
|
|
|
|
|
public class PadarClient : TcpClient<IBaseHandler, Decoder, Encoder>
|
|
|
|
|
{
|
|
|
|
|
private readonly String DEVICE_CODE = "radar";
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 0-雷达不工作;1-无车;2-无电池,3-角度偏移过大;4-车辆靠后;5-车辆靠前;6-车辆到位
|
|
|
|
|
/// </summary>
|
|
|
|
|
public byte CarState = new byte();
|
|
|
|
|
|
|
|
|
|
public static readonly byte[] StartChar = { 0xFE, 0x68 };
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
public static byte serialNum = 0;
|
|
|
|
|
|
|
|
|
|
private static readonly ILog Log = LogManager.GetLogger(typeof(PadarClient));
|
|
|
|
|
|
|
|
|
|
public bool Connect()
|
|
|
|
|
{
|
|
|
|
|
base.BaseConnect();
|
|
|
|
|
Log.Info($"padar connect succeed");
|
|
|
|
|
return Connected;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 0-关闭雷达 1-开启
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="byte3">0-关闭雷达 1-开启雷达</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public Result<bool> PadarControl(byte byte3)
|
|
|
|
|
{
|
|
|
|
|
byte[] sendBytes = new byte[4];
|
|
|
|
|
sendBytes[0] = 0xFE;
|
|
|
|
|
sendBytes[1] = 0x68;
|
|
|
|
|
if (serialNum > byte.MaxValue)
|
|
|
|
|
serialNum = 0;
|
|
|
|
|
sendBytes[2] = serialNum;
|
|
|
|
|
serialNum++;
|
|
|
|
|
sendBytes[3] = byte3;
|
|
|
|
|
this.Channel.WriteAndFlushAsync(sendBytes);
|
|
|
|
|
|
|
|
|
|
StationSoftMgr.PutDeviceLog((int)StationConstant.DeviceCode.Radar,
|
|
|
|
|
byte3 == 0 ? SwapConstant.RadarProtocol.Close : SwapConstant.RadarProtocol.Open,
|
|
|
|
|
sendBytes.ToString(), (int)SwapConstant.CommunicationType.Send);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Result<bool>.Success();
|
|
|
|
|
}
|
|
|
|
|
}
|