using LB_VisionProcesses.Communicators.TCom;
|
using Newtonsoft.Json;
|
using System;
|
using System.Collections.Concurrent;
|
using System.Collections.Generic;
|
using System.Diagnostics;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace LB_VisionProcesses.Communicators.UserCommunicator.T306Command
|
{
|
[JsonObject(MemberSerialization.OptOut)]
|
internal class T306CommandTool : CommunicatorConfig
|
{
|
string HDCP14CHECK = "0422CCF2";
|
string HDCP22CHECK = "0422C2E8";
|
string ok = "031114";
|
|
public T306CommandTool(ConcurrentDictionary<string, BaseCommunicator> dicCommunicators)
|
: base(dicCommunicators)
|
{
|
strProcessName = "T306通讯";
|
strProcessClass = "LB_VisionProcesses.Communicators.T306CommandTool";
|
|
Params.Inputs.Add("通讯口名", "");
|
Params.Inputs.Add("HDMI1", false);
|
Params.Inputs.Add("HDMI2", false);
|
Params.Inputs.Add("HDCP1.4", false);
|
Params.Inputs.Add("HDCP2.2", false);
|
Params.Outputs.Add("收到消息", "");
|
|
//修改基类CommunicatorConfig的默认值
|
Params.Inputs.Add("通讯类型", CommunicatorType.Sender);
|
Params.Inputs.Add("是否启用CRC校验", false);
|
Params.Inputs.Add("通讯消息", "T306系统预设指令");
|
}
|
|
public override bool Run()
|
{
|
try
|
{
|
InitRunParams();
|
Params.Outputs["收到消息"] = "";
|
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}]不是串口";
|
Result = false;
|
return Result;
|
}
|
|
if (!BaseCommunicator.bConnected)
|
{
|
Msg = $"通讯口[{CommunicatorName}]未连接";
|
Result = false;
|
return Result;
|
}
|
|
bool isCheckHDMI1 = (bool)Params.Inputs["HDMI1"];
|
bool isCheckHDMI2 = (bool)Params.Inputs["HDMI2"];
|
bool isCheckHDCP14 = (bool)Params.Inputs["HDCP1.4"];
|
bool isCheckHDCP22 = (bool)Params.Inputs["HDCP2.2"];
|
bool bHDMI1 = true, bHDMI2 = true;
|
|
if (isCheckHDMI1 && isCheckHDCP14)
|
bHDMI1 = CheckHDMIHDCP(port, "HDMI1", true, false);
|
|
if (isCheckHDMI2 && bHDMI1 && isCheckHDCP22)
|
bHDMI2 = CheckHDMIHDCP(port, "HDMI2", false, false);
|
|
if (!bHDMI1 || !bHDMI2)
|
{
|
Msg = !bHDMI1 ? $"HDCP1.4检测失败" : $"HDCP2.2检测失败";
|
Result = false;
|
return Result;
|
}
|
}
|
catch (Exception ex)
|
{
|
Msg = $"通讯异常,原因是:{ex.Message}";
|
Result = false;
|
}
|
return Result;
|
}
|
|
bool CheckHDMIHDCP(UARTPort port, string strHDMI, bool check14, bool check22)
|
{
|
try
|
{
|
string response = string.Empty;
|
switch (strHDMI)
|
{
|
case "HDMI1":
|
port.SendMessageBytes(BaseCommunicator.strToHexByte("41"));
|
break;
|
case "HDMI2":
|
port.SendMessageBytes(BaseCommunicator.strToHexByte("14"));
|
break;
|
default:
|
return false;
|
}
|
|
response = string.Empty;
|
for (int i = 0; i < 3; i++)
|
{
|
if (check14)
|
{
|
port.SendMessageBytes(BaseCommunicator.strToHexByte(HDCP14CHECK));
|
response += port.ReceiveMsg();
|
if (response.Contains(ok))
|
return true;
|
}
|
|
if (check22)
|
{
|
port.SendMessageBytes(BaseCommunicator.strToHexByte(HDCP22CHECK));
|
response += port.ReceiveMsg();
|
if (response.Contains(ok))
|
return true;
|
}
|
}
|
|
return false;
|
}
|
catch (Exception e) { Debug.WriteLine($"CheckHDMIHDCP:{e.Message}[{e.StackTrace}]"); return false; }
|
}
|
}
|
|
}
|