You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.6 KiB

using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.AutoTask;
using HybirdFrameworkCore.Entity;
using log4net;
using Repository.Station;
using Service.Execute;
using Service.Execute.Api;
using Service.Execute.Model.Tbox;
using Service.Plc.Client;
using Service.Plc.Msg;
using Service.Station;
using System.Reflection.PortableExecutable;
namespace Service.MyTask;
/// <summary>
/// 电池充电是风扇启停
/// </summary>
[Scope]
public class PlcRealTimeTask : ITask
{
private static readonly ILog Log = LogManager.GetLogger(typeof(PlcRealTimeTask));
public BinInfoRepository _binInfoRepository { get; set; }
private volatile bool _stop;
public static bool cameraTask=false;//相机偏移记录任务(查看通道状态开始,行车回归安全位置结束)
public static bool VehicleParkingStatusTask= false;//车辆驻车状态下发任务
public static bool LockStatusTask = false;//电池包锁状态下发任务
public static bool RollerShutterTask = false;//卷帘门是否保持开启状态
public string Name()
{
return "PlcRealTimeTask";
}
public int Interval()
{
return 1000 * 3;
}
public void Handle()
{
try
{
if (cameraTask)
{
if (PlcMgr.PlcToHostData != null)
{
Log.Info($"PlcRealTimeTask.CameraOffsetValue DeviationX={PlcMgr.PlcToHostData.DeviationX.Value}, DeviationY={PlcMgr.PlcToHostData.DeviationY.Value}" +
$",DeviationZ={PlcMgr.PlcToHostData.DeviationZ.Value},DeviationR={PlcMgr.PlcToHostData.DeviationR.Value},DeviationX2={PlcMgr.PlcToHostData.DeviationX2.Value}," +
$" DeviationY2={PlcMgr.PlcToHostData.DeviationY2.Value},DeviationZ2={PlcMgr.PlcToHostData.DeviationZ2.Value},DeviationR2={PlcMgr.PlcToHostData.DeviationR2.Value}");
}
}
var resultHeartBeatMsg = StationSoftMgr.SwappingStateMachine.BoxCarInfoModel?.CarStatus;
if (VehicleParkingStatusTask)
{
ushort vehicleParkingStatus = 0;
if (resultHeartBeatMsg != null)
{
if (resultHeartBeatMsg?.PowerStatus == 2 && resultHeartBeatMsg.Break == 1)
{
vehicleParkingStatus = 2;
}
else
{
vehicleParkingStatus = 1;
}
}
PlcMgr.WriteVehicleParkingStatus(vehicleParkingStatus);
}
if (LockStatusTask)
{
ushort lockStatus = 0;
if (resultHeartBeatMsg != null)
{
lockStatus = (ushort)(resultHeartBeatMsg?.LockStatus == 1 ? 1000 : 0);
}
PlcMgr.WriteStopCommand(lockStatus);
}
if (RollerShutterTask)
{
if (!PlcMgr.RollerShutterRadar())
{
PlcMgr.WriteRollerShutter(1000);
}
}
//else//需要关闭吗
//{
// PlcMgr.WriteRollerShutter(1010);
//}
}
catch (Exception e)
{
Log.Error($" PlcRealTimeTask err e={e}");
}
}
public bool Stoped()
{
return _stop;
}
public void Stop()
{
_stop = true;
}
public void ResetStop()
{
_stop = false;
}
}