优化代码
This commit is contained in:
@@ -47,10 +47,11 @@ namespace WinISP
|
|||||||
private string _monitorChipName = String.Empty;
|
private string _monitorChipName = String.Empty;
|
||||||
private string _monitorPanelName = String.Empty;
|
private string _monitorPanelName = String.Empty;
|
||||||
private string _monitorBoardName = String.Empty;
|
private string _monitorBoardName = String.Empty;
|
||||||
private string _fwModelName = String.Empty;
|
private string _monitorVersionFromDDC = String.Empty;
|
||||||
private string _fwChipName = String.Empty;
|
//private string _fwModelName = String.Empty;
|
||||||
private string _fwPanelName = String.Empty;
|
//private string _fwChipName = String.Empty;
|
||||||
private string _fwBoardName = String.Empty;
|
//private string _fwPanelName = String.Empty;
|
||||||
|
//private string _fwBoardName = String.Empty;
|
||||||
private bool _IsRunISP = false;
|
private bool _IsRunISP = false;
|
||||||
ISimI2CCtrl _simI2cCtrl;
|
ISimI2CCtrl _simI2cCtrl;
|
||||||
private bool _IsHDMIConnect = false;
|
private bool _IsHDMIConnect = false;
|
||||||
@@ -481,53 +482,7 @@ namespace WinISP
|
|||||||
return raw.Substring(0, end);
|
return raw.Substring(0, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool TryReadMonitorIdentity(int retryCount = 5, int delayMs = 80)
|
|
||||||
{
|
|
||||||
// Name commands are more stable in non-tool mode on some GPU/DDC paths.
|
|
||||||
DDC_SetToolFlag(false);
|
|
||||||
|
|
||||||
for (int i = 0; i < retryCount; i++)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrWhiteSpace(_fwModelName))
|
|
||||||
{
|
|
||||||
string rawModel = DDC_GetMonitorName(MS_GET_MODEL_NAME);
|
|
||||||
if (string.Equals(NormalizeMonitorInfo(rawModel), PlaceholderMonitorModelName, StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
WriteLog("Placeholder model detected, applying legacy field remapping", "debug");
|
|
||||||
_fwModelName = LegacyMonitorModelName;
|
|
||||||
_fwChipName = "MST9U";
|
|
||||||
_fwPanelName = "Panel_SG315GD01_2_eDP";
|
|
||||||
_fwVersionFromDDC = "FW.033";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_fwModelName = NormalizeMonitorModelName(rawModel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (string.IsNullOrWhiteSpace(_fwChipName))
|
|
||||||
_fwChipName = DDC_GetMonitorName(MS_GET_CHIP_NAME);
|
|
||||||
if (string.IsNullOrWhiteSpace(_fwPanelName))
|
|
||||||
{
|
|
||||||
WinIOLib.DelayMs(50);
|
|
||||||
_fwPanelName = DDC_GetMonitorName(MS_GET_PANEL_NAME);
|
|
||||||
}
|
|
||||||
if (string.IsNullOrWhiteSpace(_fwBoardName))
|
|
||||||
_fwBoardName = DDC_GetMonitorName(MS_GET_BOARD_NAME);
|
|
||||||
if (string.IsNullOrWhiteSpace(_fwVersionFromDDC))
|
|
||||||
{
|
|
||||||
_fwVersionFromDDC = DDC_GetMonitorName(MS_GET_FW_VERSION);
|
|
||||||
frmISP.WriteLog($"DDC_GetMonitorName:_fwVersionFromDDC{_fwVersionFromDDC}", "debug");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Only model name (0x36) is required; chip/panel/board may not be supported on all DDC paths.
|
|
||||||
if (!string.IsNullOrWhiteSpace(_fwModelName))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
WinIOLib.DelayMs(delayMs);
|
|
||||||
}
|
|
||||||
|
|
||||||
return !string.IsNullOrWhiteSpace(_fwModelName);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void FormISP_MSI_FormClosing(object sender, FormClosingEventArgs e)
|
private void FormISP_MSI_FormClosing(object sender, FormClosingEventArgs e)
|
||||||
{
|
{
|
||||||
@@ -626,47 +581,32 @@ namespace WinISP
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
bool isAmdOrIntel = IsAmdOrIntelPath();
|
if (IsAmdOrIntelPath())
|
||||||
bool legacyRemapped = false;
|
|
||||||
|
|
||||||
// 型号名
|
|
||||||
{
|
{
|
||||||
string rawModelName;
|
// ── A卡 / I卡:走稳健多轮读取 ────────────────────────────
|
||||||
if (isAmdOrIntel)
|
string rawModelName = ReadMonitorFieldRobust(CmdGetModelName, MonitorModelNameLength);
|
||||||
rawModelName = ReadMonitorFieldRobust(CmdGetModelName, MonitorModelNameLength); // >>> A/I 走稳健版
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// N 卡保持原逻辑
|
|
||||||
Byte[] cmd = { MStarCommand, CmdGetModelName };
|
|
||||||
Byte[] recv = MTKDebugCmd.DDC_Read(cmd, MonitorModelNameLength + 2, 500)
|
|
||||||
?? MTKDebugCmd.DDC_Read(cmd, MonitorModelNameLength + 2, 2000)
|
|
||||||
?? MTKDebugCmd.DDC_Read(cmd, MonitorModelNameLength + 2, 5000);
|
|
||||||
rawModelName = (recv != null && recv.Length >= MonitorModelNameLength + 2)
|
|
||||||
? Encoding.ASCII.GetString(recv, 2, MonitorModelNameLength).TrimEnd('\0')
|
|
||||||
: string.Empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.Equals(rawModelName.Trim(), PlaceholderMonitorModelName, StringComparison.OrdinalIgnoreCase))
|
if (string.Equals(rawModelName.Trim(), PlaceholderMonitorModelName, StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
legacyRemapped = true;
|
WriteLog("Placeholder model detected, legacy remapping ...", "debug");
|
||||||
_monitorModelName = LegacyMonitorModelName;
|
_monitorModelName = LegacyMonitorModelName;
|
||||||
_monitorChipName = "MST9U";
|
_monitorChipName = "MST9U";
|
||||||
_monitorPanelName = "Panel_SG315GD01_2_eDP";
|
_monitorPanelName = "Panel_SG315GD01_2_eDP";
|
||||||
WriteLog("Placeholder model detected, legacy remapping ...", "debug");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_monitorModelName = NormalizeMonitorModelName(rawModelName);
|
_monitorModelName = NormalizeMonitorModelName(rawModelName);
|
||||||
|
_monitorChipName = ReadMonitorFieldRobust(CmdGetChipName, MonitorChipNameLength);
|
||||||
|
_monitorPanelName = ReadMonitorFieldRobust(CmdGetPanelName, MonitorPanelNameLength);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 芯片名 / 面板名 / 板卡名:A/I 卡同样走稳健版
|
_monitorBoardName = ReadMonitorFieldRobust(CmdGetBoardName, MonitorBoardNameLength);
|
||||||
if (!legacyRemapped)
|
}
|
||||||
{
|
else
|
||||||
_monitorChipName = isAmdOrIntel ? ReadMonitorFieldRobust(CmdGetChipName, MonitorChipNameLength) : /* N卡原逻辑 */ _monitorChipName;
|
{
|
||||||
_monitorPanelName = isAmdOrIntel ? ReadMonitorFieldRobust(CmdGetPanelName, MonitorPanelNameLength) : /* N卡原逻辑 */ _monitorPanelName;
|
// ── N卡:走 TryReadMonitorIdentity,结果直接写入 _monitor* ─
|
||||||
|
TryReadMonitorIdentity(10, 100);
|
||||||
}
|
}
|
||||||
_monitorBoardName = isAmdOrIntel ? ReadMonitorFieldRobust(CmdGetBoardName, MonitorBoardNameLength) : /* N卡原逻辑 */ _monitorBoardName;
|
|
||||||
|
|
||||||
WriteLog("MonitorModelName=" + _monitorModelName, "info");
|
WriteLog("MonitorModelName=" + _monitorModelName, "info");
|
||||||
WriteLog("MonitorChipName=" + _monitorChipName, "info");
|
WriteLog("MonitorChipName=" + _monitorChipName, "info");
|
||||||
@@ -679,6 +619,67 @@ namespace WinISP
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool TryReadMonitorIdentity(int retryCount = 5, int delayMs = 80)
|
||||||
|
{
|
||||||
|
DDC_SetToolFlag(false);
|
||||||
|
|
||||||
|
for (int i = 0; i < retryCount; i++)
|
||||||
|
{
|
||||||
|
// ── ModelName ─────────────────────────────────────────────────
|
||||||
|
if (string.IsNullOrWhiteSpace(_monitorModelName))
|
||||||
|
{
|
||||||
|
string rawModel = DDC_GetMonitorName(MS_GET_MODEL_NAME);
|
||||||
|
if (string.Equals(NormalizeMonitorInfo(rawModel), PlaceholderMonitorModelName,
|
||||||
|
StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
WriteLog("Placeholder model detected, applying legacy field remapping", "debug");
|
||||||
|
_monitorModelName = LegacyMonitorModelName;
|
||||||
|
_monitorChipName = "MST9U";
|
||||||
|
_monitorPanelName = "Panel_SG315GD01_2_eDP";
|
||||||
|
_monitorVersionFromDDC = "FW.033";
|
||||||
|
return true; // Placeholder 场景字段已全部填充,直接返回
|
||||||
|
}
|
||||||
|
_monitorModelName = NormalizeMonitorModelName(rawModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── ChipName ──────────────────────────────────────────────────
|
||||||
|
if (string.IsNullOrWhiteSpace(_monitorChipName))
|
||||||
|
_monitorChipName = DDC_GetMonitorName(MS_GET_CHIP_NAME);
|
||||||
|
|
||||||
|
// ── PanelName ─────────────────────────────────────────────────
|
||||||
|
if (string.IsNullOrWhiteSpace(_monitorPanelName))
|
||||||
|
{
|
||||||
|
WinIOLib.DelayMs(50);
|
||||||
|
_monitorPanelName = DDC_GetMonitorName(MS_GET_PANEL_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── BoardName ─────────────────────────────────────────────────
|
||||||
|
if (string.IsNullOrWhiteSpace(_monitorBoardName))
|
||||||
|
_monitorBoardName = DDC_GetMonitorName(MS_GET_BOARD_NAME);
|
||||||
|
|
||||||
|
// ── FwVersion ─────────────────────────────────────────────────
|
||||||
|
if (string.IsNullOrWhiteSpace(_monitorVersionFromDDC))
|
||||||
|
{
|
||||||
|
_monitorVersionFromDDC = DDC_GetMonitorName(MS_GET_FW_VERSION);
|
||||||
|
frmISP.WriteLog($"DDC_GetMonitorName:_monitorVersionFromDDC={_monitorVersionFromDDC}", "debug");
|
||||||
|
}
|
||||||
|
|
||||||
|
frmISP.WriteLog(
|
||||||
|
$"[NV-Identity] retry#{i} " +
|
||||||
|
$"Model={_monitorModelName}, Chip={_monitorChipName}, " +
|
||||||
|
$"Panel={_monitorPanelName}, Board={_monitorBoardName}, Ver={_monitorVersionFromDDC}",
|
||||||
|
"debug");
|
||||||
|
|
||||||
|
// ModelName 是必须字段
|
||||||
|
if (!string.IsNullOrWhiteSpace(_monitorModelName))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
WinIOLib.DelayMs(delayMs);
|
||||||
|
}
|
||||||
|
|
||||||
|
return !string.IsNullOrWhiteSpace(_monitorModelName);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// AMD/Intel 友好的型号读取:带响应有效性校验 + 多轮重试。
|
/// AMD/Intel 友好的型号读取:带响应有效性校验 + 多轮重试。
|
||||||
/// AMD ADL DDC 读命中率低(约 4 错 1 对),需要足够重试次数才能读到完整字符串。
|
/// AMD ADL DDC 读命中率低(约 4 错 1 对),需要足够重试次数才能读到完整字符串。
|
||||||
@@ -902,7 +903,7 @@ namespace WinISP
|
|||||||
// Intel IGCL and AMD can complete the FE handshake but still time out on optional
|
// Intel IGCL and AMD can complete the FE handshake but still time out on optional
|
||||||
// identity queries during connect. Skip those reads here so connect stays usable.
|
// identity queries during connect. Skip those reads here so connect stays usable.
|
||||||
// 所有显卡都要读,不要忽视
|
// 所有显卡都要读,不要忽视
|
||||||
QueryConnectedMonitorInfo();
|
//QueryConnectedMonitorInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsConnect == false)
|
if (IsConnect == false)
|
||||||
@@ -1676,30 +1677,16 @@ namespace WinISP
|
|||||||
private bool ValidateMonitorVsBin(out string errMsg)
|
private bool ValidateMonitorVsBin(out string errMsg)
|
||||||
{
|
{
|
||||||
errMsg = String.Empty;
|
errMsg = String.Empty;
|
||||||
bool isAmdOrIntel = IsAmdOrIntelPath();
|
bool isAmdOrIntel = IsAmdOrIntelPath();
|
||||||
|
|
||||||
// >>> 优先采用 QueryConnectedMonitorInfo 已读到的真实显示器信息
|
QueryConnectedMonitorInfo();
|
||||||
// (AMD/Intel 路径在 Connect 时已通过 ReadMonitorFieldRobust 读取)
|
|
||||||
if (string.IsNullOrWhiteSpace(_fwModelName) && !string.IsNullOrWhiteSpace(_monitorModelName))
|
|
||||||
_fwModelName = _monitorModelName;
|
|
||||||
if (string.IsNullOrWhiteSpace(_fwChipName) && !string.IsNullOrWhiteSpace(_monitorChipName))
|
|
||||||
_fwChipName = _monitorChipName;
|
|
||||||
if (string.IsNullOrWhiteSpace(_fwPanelName) && !string.IsNullOrWhiteSpace(_monitorPanelName))
|
|
||||||
_fwPanelName = _monitorPanelName;
|
|
||||||
if (string.IsNullOrWhiteSpace(_fwBoardName) && !string.IsNullOrWhiteSpace(_monitorBoardName))
|
|
||||||
_fwBoardName = _monitorBoardName;
|
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(_fwVersionFromDDC))
|
if (string.IsNullOrWhiteSpace(_fwVersionFromDDC))
|
||||||
{
|
{
|
||||||
_fwVersionFromDDC = DDC_GetMonitorName(MS_GET_FW_VERSION);
|
_fwVersionFromDDC = DDC_GetMonitorName(MS_GET_FW_VERSION);
|
||||||
frmISP.WriteLog($"DDC_GetMonitorName:_fwVersionFromDDC{_fwVersionFromDDC}", "debug");
|
frmISP.WriteLog($"DDC_GetMonitorName:_fwVersionFromDDC{_fwVersionFromDDC}", "debug");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(_fwModelName))
|
|
||||||
{
|
|
||||||
TryReadMonitorIdentity(10, 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
// Legacy-batch fallback: old monitors shipped before DDC identity commands
|
// Legacy-batch fallback: old monitors shipped before DDC identity commands
|
||||||
// were implemented do not respond to MS_GET_MODEL_NAME / CHIP / PANEL / BOARD.
|
// were implemented do not respond to MS_GET_MODEL_NAME / CHIP / PANEL / BOARD.
|
||||||
@@ -1717,19 +1704,19 @@ namespace WinISP
|
|||||||
const string PlaceholderModelName = "MST9U6_PanelCM";
|
const string PlaceholderModelName = "MST9U6_PanelCM";
|
||||||
|
|
||||||
// Placeholder detection: match exact string or any valid prefix of it (DDC reads may be truncated).
|
// Placeholder detection: match exact string or any valid prefix of it (DDC reads may be truncated).
|
||||||
string _fwModelTrim = (_fwModelName ?? string.Empty).Trim();
|
string _fwModelTrim = (_monitorModelName ?? string.Empty).Trim();
|
||||||
bool fwModelIsPlaceholder =
|
bool fwModelIsPlaceholder =
|
||||||
(_fwModelTrim.Length >= 8 && PlaceholderModelName.StartsWith(_fwModelTrim, StringComparison.OrdinalIgnoreCase))
|
(_fwModelTrim.Length >= 8 && PlaceholderModelName.StartsWith(_fwModelTrim, StringComparison.OrdinalIgnoreCase))
|
||||||
|| string.Equals(_fwModelTrim, PlaceholderModelName, StringComparison.OrdinalIgnoreCase);
|
|| string.Equals(_fwModelTrim, PlaceholderModelName, StringComparison.OrdinalIgnoreCase);
|
||||||
if (fwModelIsPlaceholder)
|
if (fwModelIsPlaceholder)
|
||||||
frmISP.WriteLog("Monitor firmware返回占位符model名 '" + _fwModelName + "',使用LegacyFallback进行四项校验", "debug");
|
frmISP.WriteLog("Monitor firmware返回占位符model名 '" + _monitorModelName + "',使用LegacyFallback进行四项校验", "debug");
|
||||||
|
|
||||||
bool usingLegacyFallback = string.IsNullOrWhiteSpace(_fwModelName) || fwModelIsPlaceholder;
|
bool usingLegacyFallback = string.IsNullOrWhiteSpace(_monitorModelName) || fwModelIsPlaceholder;
|
||||||
|
|
||||||
string effModel = usingLegacyFallback ? LegacyModel : _fwModelName;
|
string effModel = usingLegacyFallback ? LegacyModel : _monitorModelName;
|
||||||
string effChip = !string.IsNullOrWhiteSpace(_fwChipName) ? _fwChipName
|
string effChip = !string.IsNullOrWhiteSpace(_monitorChipName) ? _monitorChipName
|
||||||
: (usingLegacyFallback ? LegacyChip : string.Empty);
|
: (usingLegacyFallback ? LegacyChip : string.Empty);
|
||||||
string effPanel = !string.IsNullOrWhiteSpace(_fwPanelName) ? _fwPanelName
|
string effPanel = !string.IsNullOrWhiteSpace(_monitorPanelName) ? _monitorPanelName
|
||||||
: (usingLegacyFallback ? LegacyPanel : string.Empty);
|
: (usingLegacyFallback ? LegacyPanel : string.Empty);
|
||||||
|
|
||||||
// effVer: prefer actual DDC read; fall back to LegacyFWVer when in legacy-fallback mode
|
// effVer: prefer actual DDC read; fall back to LegacyFWVer when in legacy-fallback mode
|
||||||
@@ -1884,8 +1871,7 @@ namespace WinISP
|
|||||||
}
|
}
|
||||||
frmISP.WriteLog("flashSectorInfo built. sectorCount = " + flashSectorInfo.Count + ", sectorSize = " + _flashSectorSize, "debug");
|
frmISP.WriteLog("flashSectorInfo built. sectorCount = " + flashSectorInfo.Count + ", sectorSize = " + _flashSectorSize, "debug");
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryConnectedMonitorInfo();
|
|
||||||
string checkErr;
|
string checkErr;
|
||||||
if (!ValidateMonitorVsBin(out checkErr))
|
if (!ValidateMonitorVsBin(out checkErr))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user