using ClassLibrary1;
|
using DeviceITisation;
|
using LB_VisionProcesses.Communicators;
|
using LB_VisionProcesses.Communicators.Tcom;
|
using Newtonsoft.Json;
|
using System.Collections.Concurrent;
|
using System.Diagnostics;
|
|
namespace LB_VisionProcesses.Communicators.USerCommunicator.T306CommandTool
|
{
|
public class T306CommandTool : CommunicatorConfig
|
{
|
string HDCP14CHECK = "0422CCF2";
|
string HDCP22CHECK = "0422C2E8";
|
string HDCPOFF = "05229900C0";
|
string ok = "031114";
|
|
bool isFirstRun = true;
|
string lastHDMIType = "HDMI1";
|
bool lastCheckHDCP14 = true;
|
bool lastCheckHDCP22 = true;
|
|
public T306CommandTool(ConcurrentDictionary<string, BaseCommunicator> dicCommunicators)
|
: base(dicCommunicators)
|
{
|
strProcessName = "T306通讯";
|
strProcessClass = "LB_VisionProcesses.Communicators.T306CommandTool";
|
|
Params.Inputs.Add("通讯口名", "");
|
Params.Inputs.Add("HDMI口", "HDMI1");
|
Params.Inputs.Add("HDCP1.4", false);
|
Params.Inputs.Add("HDCP2.2", false);
|
Params.Outputs.Add("收到消息", "");
|
|
Params.Inputs.Add("SN", "");
|
Params.Inputs.Add("BOM", "");
|
Params.Inputs.Add("是否自动切换HDCP检查", true);
|
|
//修改基类CommunicatorConfig的默认值
|
Params.Inputs.Add("通讯类型", CommunicatorType.Sender);
|
Params.Inputs.Add("是否启用CRC校验", false);
|
Params.Inputs.Add("通讯消息", "");
|
}
|
|
public override bool Run()
|
{
|
string strHDMIType = Params.Inputs["HDMI口"]?.ToString();
|
bool isCheckHDCP14 = Convert.ToBoolean(Params.Inputs["HDCP1.4"]);
|
bool isCheckHDCP22 = Convert.ToBoolean(Params.Inputs["HDCP2.2"]);
|
|
try
|
{
|
InitRunParams();
|
Params.Inputs.Add("通讯消息", "");
|
Params.Outputs.Add("收到消息", "");
|
|
string CommunicatorName = Params.Inputs["通讯口名"].ToString();
|
|
if (!dicCommunicators.ContainsKey(CommunicatorName))
|
{
|
Msg = $"通讯口[{CommunicatorName}]不存在";
|
Result = false;
|
return Result;
|
}
|
|
BaseCommunicator BaseCommunicator = dicCommunicators[CommunicatorName];
|
|
if (BaseCommunicator == null)
|
{
|
Msg = $"通讯口[{CommunicatorName}]未实例化";
|
Result = false;
|
return Result;
|
}
|
|
if (!(BaseCommunicator is UARTPort port))
|
{
|
Msg = $"通讯口[{CommunicatorName}]不是UART串口";
|
Result = false;
|
return Result;
|
}
|
|
if (!BaseCommunicator.bConnected)
|
{
|
Msg = $"通讯口[{CommunicatorName}]未连接";
|
Result = false;
|
return Result;
|
}
|
|
// 首次运行或HDMI口切换时 发送切换命令
|
if (isFirstRun || lastHDMIType != strHDMIType)
|
{
|
switch (strHDMIType)
|
{
|
case "HDMI1":
|
port.SendMessage(BaseCommunicator.strToHexByte("41"));
|
break;
|
default:
|
port.SendMessage(BaseCommunicator.strToHexByte("14"));
|
break;
|
}
|
}
|
|
try
|
{
|
// 自动切换HDCP检查
|
if (Convert.ToBoolean(Params.Inputs["是否自动切换HDCP检查"]?.ToString()))
|
{
|
string SN = Params.Inputs["SN"]?.ToString();
|
string BOM = Params.Inputs["BOM"].ToString();
|
|
// SN为空 则不处理
|
if (string.IsNullOrEmpty(SN))
|
return true;
|
|
if (Class1.GetBOMAndODF(SN, out string NowBOM, out string NowODF))
|
{
|
string bomstring = Class1.getBOMDesc(NowBOM);
|
REject re = JsonConvert.DeserializeObject<REject>(bomstring);
|
eClass eClass = re.E_CLASS;
|
string BP = eClass.BP.ToUpper();
|
if (NowBOM != BOM)
|
{
|
Params.Inputs["BOM"] = NowBOM;
|
|
// 小米关闭HDCP检查 其余至少开启HDCP1.4检查
|
if (BP.Contains("MI"))
|
{
|
Params.Inputs.Add("HDCP1.4", false);
|
Params.Inputs.Add("HDCP2.2", false);
|
return CheckHDMIHDCP(port, false, false);
|
}
|
else
|
{
|
Params.Inputs.Add("HDCP1.4", true);
|
return CheckHDMIHDCP(port, true, false);
|
}
|
}
|
else
|
{
|
// BOM未变化 复查HDCP勾选项是否正确
|
|
// 小米关闭HDCP检查 其余至少开启HDCP1.4检查
|
if (BP.Contains("MI"))
|
{
|
if (isCheckHDCP14 || isCheckHDCP22)
|
{
|
Params.Inputs.Add("HDCP1.4", false);
|
Params.Inputs.Add("HDCP2.2", false);
|
return CheckHDMIHDCP(port, false, false);
|
}
|
return true;
|
}
|
else
|
{
|
if (!isCheckHDCP14)
|
{
|
Params.Inputs.Add("HDCP1.4", true);
|
return CheckHDMIHDCP(port, true, false);
|
}
|
}
|
}
|
}
|
return false;
|
}
|
}
|
catch { }
|
|
// 不切换HDCP检查时 执行以下逻辑
|
if (!isCheckHDCP14 && !isCheckHDCP22)
|
{
|
// 关闭HDCP检测
|
if (!CheckHDMIHDCP(port, false, false))
|
{
|
Msg = $"关闭HDCP检测失败";
|
Result = false;
|
return Result;
|
}
|
}
|
else
|
{
|
if (isCheckHDCP14)
|
{
|
if (!CheckHDMIHDCP(port, true, false))
|
{
|
Msg = $"HDCP1.4检测失败";
|
Result = false;
|
return Result;
|
}
|
}
|
if (isCheckHDCP22)
|
{
|
if (!CheckHDMIHDCP(port, false, true))
|
{
|
Msg = $"HDCP2.2检测失败";
|
Result = false;
|
return Result;
|
}
|
}
|
}
|
|
}
|
catch (Exception ex)
|
{
|
Msg = $"通讯异常,原因是:{ex.Message}";
|
Result = false;
|
}
|
finally
|
{
|
isFirstRun = false;
|
lastHDMIType = strHDMIType;
|
lastCheckHDCP14 = (bool)Params.Inputs["HDCP1.4"];
|
lastCheckHDCP22 = (bool)Params.Inputs["HDCP2.2"];
|
}
|
return Result;
|
}
|
|
bool CheckHDMIHDCP(UARTPort port, bool check14, bool check22)
|
{
|
string SendMsg = string.Empty;
|
try
|
{
|
string response = string.Empty;
|
|
response = string.Empty;
|
|
// 关闭HDCP检测
|
if (!check14 && !check22)
|
SendMsg = HDCPOFF;
|
else
|
{
|
// 检测HDCP1.4
|
if (check14 && !check22)
|
SendMsg = HDCP14CHECK;
|
|
// 检测HDCP2.2
|
if (!check14 && check22)
|
SendMsg = HDCP22CHECK;
|
}
|
|
for (int i = 0; i < 3; i++)
|
{
|
port.SendMessage(BaseCommunicator.strToHexByte(SendMsg));
|
response += port.ReceiveMsg();
|
if (response.Contains(ok))
|
return true;
|
}
|
|
return false;
|
}
|
catch (Exception e) { Debug.WriteLine($"CheckHDMIHDCP:{e.Message}[{e.StackTrace}]"); return false; }
|
finally
|
{
|
Params.Inputs.Add("通讯消息", SendMsg);
|
Params.Outputs.Add("收到消息", port.ReceiveMsg());
|
}
|
}
|
}
|
}
|