using HH.WCS.ZhongCeJinTan.device;
using HH.WCS.ZhongCeJinTan.dispatch;
using HH.WCS.ZhongCeJinTan.util;
using HH.WCS.ZhongCeJinTan.wms;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using SqlSugar;
using System.Security.Policy;
using Newtonsoft.Json;
using static HH.WCS.ZhongCeJinTan.api.ApiModel;
using System.Reflection;
using static HH.WCS.ZhongCeJinTan.process.TaskProcess;
using static HH.WCS.ZhongCeJinTan.wms.WcsModel;
using HH.WCS.Mobox3.ZhongCeJinTan.dispatch;
using static HH.WCS.ZhongCeJinTan.util.Settings;
namespace HH.WCS.ZhongCeJinTan.process
{
///
/// 设备信号处理
///
internal class DeviceProcess
{
private static Dictionary times = new Dictionary();
private static Dictionary LineState = new Dictionary();
public class statemodel
{
public int status { get; set; }
public DateTime modify { get; set; }
}
internal static void Analysis(string data, string ip)
{
if (data.Length >= 6)
{
//去掉消息头3F 00
data = data.Substring(4);
var plc = Settings.deviceInfos.Where(a => a.address == ip && a.enable == 1).FirstOrDefault();
if (plc != null)
{
if (plc.enable == 1)
{
if (plc.deviceType == 1)
{
AnalysisDoor(data, plc);
}
}
}
else
{
Console.WriteLine($"TCP信号处理:未查询到IP为{ip}的数据,请检查deviceInfo配置中心是否存在该IP的数据!");
}
}
}
private static Dictionary doorRecord = new Dictionary();
///
/// 交管请求
///
///
///
///
internal static bool Traffic(string zone, int occupy,bool flag)
{
var plc = Settings.deviceInfos.Where(a => a.location[0].Contains(zone)).FirstOrDefault();
if (plc != null)
{
LogHelper.Info($"安全门对接:门:{zone}", "自动门");
if (flag)
{
if (occupy == 1)
{
//开门请求 3F 00 11 20 0d 0a
var req = $"3f 00 11 0d 0a";
PlcHelper.SendHex(plc.address, req);
var msg = $"安全门开门请求,门号:{zone},ip={plc.address}, data={req}";
LogHelper.Info(msg, "自动门");
//车子请求一次就发一次开门请求
if (doorStatus.Keys.Contains(zone) && DateTime.Now.Subtract(doorStatus[zone].modify).TotalSeconds < 5)
{
if (doorStatus[zone].info == "1")
{
LogHelper.Info($"安全门已经打开:门:{zone}", "自动门");
return true;
}
}
}
if (occupy == 4)
{
//关门信号 3F 00 10 20 0d 0a
var req = $"3f 00 10 0d 0a";
PlcHelper.SendHex(plc.address, req);
var msg = $"安全门关门请求,门号:{zone},ip={plc.address}, data={req}";
LogHelper.Info(msg, "自动门");
return true;
}
}
else {
if (occupy == 1)
{
if (doorStatus[zone].info == "1")
{
LogHelper.Info($"安全门已经打开:门:{zone}", "自动门");
return true;
}
else
{
LogHelper.Info($"安全门已经关闭:门:{zone}", "自动门");
return false;
}
}
if (occupy == 4) {
return true;
}
}
}
return false;
}
private static Dictionary doorStatus = new Dictionary();
///
/// 自动门
///
///
///
internal static void AnalysisDoor(string data, Settings.deviceInfo plc)
{
LogHelper.Info($"自动门状态:{data},地址为:{plc.address}", "自动门");
var state = data.Substring(1, 1);
LogHelper.Info($"门{plc.location[0]}的状态{state}", "自动门");
if (doorStatus.Keys.Contains(plc.location[0]))
{
doorStatus[plc.location[0]].info = state;
doorStatus[plc.location[0]].modify = DateTime.Now;
}
else
{
doorStatus.Add(plc.location[0] , new signalInfo { info = state, modify = DateTime.Now });
}
}
internal static void QuLiao(WMSTask mst,string fkNo, int state)
{
try
{
var newDb = new SqlHelper