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.

109 lines
3.1 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 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?.HeartBeatMsg;
if (VehicleParkingStatusTask)
{
ushort write = resultHeartBeatMsg.handbrake == 1 ? (ushort)2 : (ushort)0;
PlcMgr.WriteVehicleParkingStatus(write);
}
if (LockStatusTask)
{
ushort lockStatus = 0;
if (resultHeartBeatMsg != null)
{
lockStatus = (ushort)(resultHeartBeatMsg?.LockStatus == 1 ? 1000 : 0);
}
PlcMgr.WriteStopCommand(lockStatus);
}
else
{
PlcMgr.WriteStopCommand(0);
}
}
catch (Exception e)
{
Log.Error($" PlcRealTimeTask err e={e}");
}
}
public bool Stoped()
{
return _stop;
}
public void Stop()
{
_stop = true;
}
public void ResetStop()
{
_stop = false;
}
}