using HH.WCS.DaYang.device;
using HH.WCS.DaYang.dispatch;
using HH.WCS.DaYang.util;
using HH.WCS.DaYang.wms;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Policy;
using System.Threading;
using static HH.WCS.DaYang.api.ApiModel;
using static HH.WCS.DaYang.util.Settings;
namespace HH.WCS.DaYang.process
{
///
/// 设备信号处理,主要是tcp信号,我们做server被动接收信号来处理,根据项目定制的
///
internal class DeviceProcess
{
internal static void Analysis(string data, string ip)
{
if (data.Length >= 6)
{
//去掉消息头3F 00
data = data.Substring(4);
//Console.WriteLine($"{ip}-{data}");
var plc = Settings.deviceInfos.Where(a => a.address == ip && a.enable == 1).FirstOrDefault();
if (plc != null)
{
if (plc.deviceType == 1)
{
}
else if (plc.deviceType == 2)
{
//出库缓存位的光电信息
//如果有缓存位是空的状态,我们先判断有没有任务终点分配到这里,如果没有,就找一条出库任务,终点是虚拟点的任务,分配到这个空位
//修改任务终点
}
}
else
{
Console.WriteLine($"TCP信号处理:未查询到IP为{ip}的数据,请检查deviceInfo配置中心是否存在该IP的数据!");
}
}
}
///
/// 自动门
///
///
///
///
private static Dictionary doorStatus = new Dictionary();
internal static void AnalysisDoor(string xh, string data, Settings.deviceInfo plc)
{
LogHelper.Info($"自动门状态:{xh},地址为:{plc.address},门号:{plc.deviceName}", "自动门");
if (data.Length / 2 == plc.deviceNo.Length)//2 2
{
for (int i = 0; i < plc.deviceNo.Length; i++)
{
var state = data.Substring(i * 2 + 1, 1);
//Console.WriteLine($"门{plc.DEVICENO[i]}的状态{state}");
if (doorStatus.Keys.Contains(plc.deviceNo[i]))
{
doorStatus[plc.deviceNo[i]].info = state;
doorStatus[plc.deviceNo[i]].modify = DateTime.Now;
}
else
{
doorStatus.Add(plc.deviceNo[i], new signalInfo { info = state, modify = DateTime.Now });
}
}
}
}
public class signalInfo
{
public string info { get; set; }
public DateTime modify { get; set; }
}
internal static void Traffic(string forkliftNo, string zone, bool occupy)
{
var plc = Settings.deviceInfos.Where(a => a.deviceNo.Contains(zone)).FirstOrDefault();
if (plc != null)
{
var index = 1;
for (int i = 0; i < plc.deviceNo.Length; i++)
{
if (plc.deviceNo[i] == zone)
{
index = i + 1;
break;
}
}
LogHelper.Info($"安全门开门请求,门号:{zone},index:{index}");
if (occupy)
{
//开门请求 3F 00 11 20 0d 0a( 3F 00 10 21 0d 0a)
var req = $"3f 00 {index}1 0d 0a";
PlcHelper.SendHex(plc.address, req);
var msg = $"安全门开门请求,门号:{zone},index:{index},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},index:{index}", "自动门");
NDCHelper.Traffic(zone, forkliftNo);
}
}
}
else
{
//关门信号 3F 00 10 20 0d 0a
var req = $"3f 00 {index}0 0d 0a";
PlcHelper.SendHex(plc.address, req);
var msg = $"安全门关门请求,门号:{zone},index:{index},ip={plc.address}, data={req}";
LogHelper.Info(msg, "发送信号");
}
}
}
///
/// 叠盘机补空托
///
internal static void DijStatus()
{
var db = new SqlHelper