param( [string]$OutputDirectory = 'D:\HC-PMP-SW\Power_ControlPannel\MP_Control_sw_405\拖拽式平台\docs' ) $ErrorActionPreference = 'Stop' function New-Criteria { param([int]$VoltageToleranceMv, [int]$CurrentToleranceMa) [ordered]@{ VoltageToleranceMv = $VoltageToleranceMv CurrentToleranceMa = $CurrentToleranceMa ShortVoltageMinMv = 0 ShortVoltageMaxMv = 1000 ShortCurrentMinMa = 0 ShortCurrentMaxMa = 1000 OcpVoltageMinMv = 0 OcpVoltageMaxMv = 5000 OcpCurrentMinMa = 4500 OcpCurrentMaxMa = 5500 DynamicVpkPlusMinMv = 0 DynamicVpkPlusMaxMv = 65535 DynamicVpkMinusMinMv = 0 DynamicVpkMinusMaxMv = 65535 } } function New-DmpItem { param( [string]$Name, [int]$Channel, [string]$Protocol, [int]$VoltageMv, [int]$ProtocolCurrentMa, [int]$LoadCurrentMa, [int]$VoltageToleranceMv, [int]$CurrentToleranceMa, [int]$QueryDelayMs, [string]$OutputAction = 'Start', [int]$Gear = 0, [int]$CcSelection = -1, [string]$SinkFunction = 'StandardLoad' ) [ordered]@{ Id = [guid]::NewGuid().ToString() Name = $Name Channel = $Channel Direction = 'Sink' OutputAction = $OutputAction Protocol = $Protocol Mode = 'ConstantCurrent' PdoType = 'Fpdo' SinkFunction = $SinkFunction Gear = $Gear CcSelection = if ($CcSelection -ge 0) { $CcSelection } elseif ($Channel -eq 2) { 1 } else { 0 } MinVoltageMv = 3300 VoltageMv = $VoltageMv CurrentMa = $ProtocolCurrentMa LoadVoltageMv = $VoltageMv LoadCurrentMa = $LoadCurrentMa VonVoltageMv = 100 ShortHoldTimeMs = 1000 HoldAfterTest = $false OcpStartCurrentMa = 1000 OcpEndCurrentMa = 5000 OcpStepCurrentMa = 100 OcpStepTimeMs = 10 OcpRecoveryTimeMs = 1000 OcpStopVoltageMv = 4000 OcpRecoveryWithLoad = $true DynamicCurrent1Ma = 1000 DynamicTime1 = 100 DynamicCurrent2Ma = 5000 DynamicTime2 = 100 DynamicRiseSlope = 1 DynamicFallSlope = 1 ApplyDelayMs = 500 QueryDelayMs = $QueryDelayMs DurationMs = 1000 StopOnFault = $true Criteria = New-Criteria $VoltageToleranceMv $CurrentToleranceMa Status = 'Pending' Result = '' Verdict = '' MeasuredVoltageMv = $null MeasuredCurrentMa = $null QueryTime = $null Measurements = @() } } function New-PortConfig { param( [string]$Port, [int]$Channel, [string]$Protocol, [int]$VoltageMv, [int]$ProtocolCurrentMa, [int]$LoadCurrentMa, [int]$VoltageToleranceMv, [int]$CurrentToleranceMa, [int]$Gear = 0 ) [pscustomobject]@{ Port = $Port Channel = $Channel Protocol = $Protocol VoltageMv = $VoltageMv ProtocolCurrentMa = $ProtocolCurrentMa LoadCurrentMa = $LoadCurrentMa VoltageToleranceMv = $VoltageToleranceMv CurrentToleranceMa = $CurrentToleranceMa Gear = $Gear } } function Add-SingleTest { param( [System.Collections.Generic.List[object]]$Items, [string]$Prefix, [pscustomobject]$Config, [int]$CcSelection = -1 ) $voltage = $Config.VoltageMv / 1000 $current = $Config.LoadCurrentMa / 1000 $Items.Add((New-DmpItem "$Prefix-$($Config.Port)-$voltage`V-$current`A" $Config.Channel $Config.Protocol ` $Config.VoltageMv $Config.ProtocolCurrentMa $Config.LoadCurrentMa ` $Config.VoltageToleranceMv $Config.CurrentToleranceMa 10000 'Start' $Config.Gear $CcSelection)) $Items.Add((New-DmpItem "$Prefix-$($Config.Port)-停止" $Config.Channel $Config.Protocol ` $Config.VoltageMv $Config.ProtocolCurrentMa $Config.LoadCurrentMa 0 0 1000 'Stop' $Config.Gear $CcSelection)) } function Add-SequencedPortTest { param( [System.Collections.Generic.List[object]]$Items, [string]$Face, [int]$CcSelection, [pscustomobject]$Case, [string]$Port, [int]$Channel ) $sinkFunction = if ($Case.SinkFunction) { $Case.SinkFunction } else { 'StandardLoad' } $namePrefix = "$Face-$($Case.Label)-$Port" $start = New-DmpItem "$namePrefix-启动" $Channel $Case.Protocol $Case.Voltage ` $Case.ProtocolCurrent $Case.LoadCurrent $Case.VTol $Case.ITol 5000 'Start' 0 $CcSelection $sinkFunction if ($sinkFunction -eq 'ShortCircuit') { $start.Criteria.ShortVoltageMinMv = 0 $start.Criteria.ShortVoltageMaxMv = 3000 $start.Criteria.ShortCurrentMinMa = 0 $start.Criteria.ShortCurrentMaxMa = 65535 } $Items.Add($start) $Items.Add((New-DmpItem "$namePrefix-停止" $Channel $Case.Protocol $Case.Voltage ` $Case.ProtocolCurrent $Case.LoadCurrent 0 0 5000 'Stop' 0 $CcSelection $sinkFunction)) } function Add-CombinationTest { param( [System.Collections.Generic.List[object]]$Items, [string]$Prefix, [object[]]$Configs ) foreach ($config in $Configs) { $Items.Add((New-DmpItem "$Prefix-$($config.Port)-配置" $config.Channel $config.Protocol ` $config.VoltageMv $config.ProtocolCurrentMa $config.LoadCurrentMa 0 0 100 'Start' $config.Gear)) } for ($index = 0; $index -lt $Configs.Count; $index++) { $config = $Configs[$index] $delay = if ($index -eq 0) { 10000 } else { 1000 } $Items.Add((New-DmpItem "$Prefix-$($config.Port)-验证" $config.Channel $config.Protocol ` $config.VoltageMv $config.ProtocolCurrentMa $config.LoadCurrentMa ` $config.VoltageToleranceMv $config.CurrentToleranceMa $delay 'Start' $config.Gear)) } foreach ($config in $Configs) { $Items.Add((New-DmpItem "$Prefix-$($config.Port)-停止" $config.Channel $config.Protocol ` $config.VoltageMv $config.ProtocolCurrentMa $config.LoadCurrentMa 0 0 1000 'Stop' $config.Gear)) } } function Write-Plan { param([string]$FileName, [string]$Name, [System.Collections.Generic.List[object]]$Items) $plan = [ordered]@{ ProductId = 'DMP' Name = $Name Communication = [ordered]@{ PortName = 'COM6' BaudRate = 115200 DataBits = 8 Parity = 'None' StopBits = 1 SlaveAddress = 1 TimeoutMs = 500 RetryCount = 2 } Items = $Items } $path = Join-Path $OutputDirectory $FileName $json = $plan | ConvertTo-Json -Depth 20 [System.IO.File]::WriteAllText($path, $json, [System.Text.UTF8Encoding]::new($false)) Get-Item -LiteralPath $path } $c1 = 1 $c2 = 2 $a1 = 3 # 1. C1/C2同时插入,但依次对单个通道带载。先测A面(CC1),再测B面(CC2)。 $items = [System.Collections.Generic.List[object]]::new() $dualCases = @( [pscustomobject]@{ Label = '5V3A'; Protocol = 'Standard'; Voltage = 5000; ProtocolCurrent = 3000; LoadCurrent = 3000; VTol = 240; ITol = 300; SinkFunction = 'StandardLoad' }, [pscustomobject]@{ Label = '5V3.8A过载'; Protocol = 'Standard'; Voltage = 5000; ProtocolCurrent = 3000; LoadCurrent = 3800; VTol = 0; ITol = 0; SinkFunction = 'StandardLoad' }, [pscustomobject]@{ Label = '5V0A空载'; Protocol = 'Standard'; Voltage = 5000; ProtocolCurrent = 3000; LoadCurrent = 0; VTol = 240; ITol = 0; SinkFunction = 'StandardLoad' }, [pscustomobject]@{ Label = '5V-QC2.0'; Protocol = 'Qc20'; Voltage = 5000; ProtocolCurrent = 3000; LoadCurrent = 0; VTol = 240; ITol = 0; SinkFunction = 'StandardLoad' }, [pscustomobject]@{ Label = '5V短路'; Protocol = 'Standard'; Voltage = 5000; ProtocolCurrent = 3000; LoadCurrent = 0; VTol = 0; ITol = 0; SinkFunction = 'ShortCircuit' }, [pscustomobject]@{ Label = '5V0A短路恢复'; Protocol = 'Standard'; Voltage = 5000; ProtocolCurrent = 3000; LoadCurrent = 0; VTol = 240; ITol = 0; SinkFunction = 'StandardLoad' }, [pscustomobject]@{ Label = '9V3A'; Protocol = 'Pdo'; Voltage = 9000; ProtocolCurrent = 3000; LoadCurrent = 3000; VTol = 440; ITol = 300; SinkFunction = 'StandardLoad' }, [pscustomobject]@{ Label = '15V3A'; Protocol = 'Pdo'; Voltage = 15000; ProtocolCurrent = 3000; LoadCurrent = 3000; VTol = 740; ITol = 300; SinkFunction = 'StandardLoad' }, [pscustomobject]@{ Label = '20V2.25A'; Protocol = 'Pdo'; Voltage = 20000; ProtocolCurrent = 2250; LoadCurrent = 2250; VTol = 790; ITol = 225; SinkFunction = 'StandardLoad' }, [pscustomobject]@{ Label = '20V0A空载'; Protocol = 'Pdo'; Voltage = 20000; ProtocolCurrent = 2250; LoadCurrent = 0; VTol = 790; ITol = 0; SinkFunction = 'StandardLoad' }, [pscustomobject]@{ Label = '20V2.82A过载'; Protocol = 'Pdo'; Voltage = 20000; ProtocolCurrent = 2250; LoadCurrent = 2820; VTol = 0; ITol = 0; SinkFunction = 'StandardLoad' } ) foreach ($face in @( [pscustomobject]@{ Name = 'A面'; CcSelection = 1 }, [pscustomobject]@{ Name = 'B面'; CcSelection = 2 } )) { foreach ($case in $dualCases) { Add-SequencedPortTest $items $face.Name $face.CcSelection $case 'C1' $c1 Add-SequencedPortTest $items $face.Name $face.CcSelection $case 'C2' $c2 } } Write-Plan '01_C1-C2双口同时插入测试.json' '01 C1/C2双口同时插入、依次单口负载测试' $items # 2. A1单口:5V标准,9V/12V使用QC2.0。 $items = [System.Collections.Generic.List[object]]::new() $a1Cases = @( [pscustomobject]@{ Label = '264VAC'; Protocol = 'Standard'; Voltage = 5000; Current = 3000; VTol = 240; ITol = 300 }, [pscustomobject]@{ Label = '264VAC'; Protocol = 'Qc20'; Voltage = 9000; Current = 2000; VTol = 440; ITol = 200 }, [pscustomobject]@{ Label = '264VAC'; Protocol = 'Qc20'; Voltage = 12000; Current = 1500; VTol = 590; ITol = 150 }, [pscustomobject]@{ Label = '90VAC'; Protocol = 'Standard'; Voltage = 5000; Current = 3000; VTol = 240; ITol = 300 }, [pscustomobject]@{ Label = '90VAC'; Protocol = 'Qc20'; Voltage = 12000; Current = 1500; VTol = 590; ITol = 150 } ) foreach ($case in $a1Cases) { Add-SingleTest $items $case.Label (New-PortConfig 'A1' $a1 $case.Protocol $case.Voltage ` $case.Current $case.Current $case.VTol $case.ITol) } Add-SingleTest $items 'SCP-10V2.25A' (New-PortConfig 'A1' $a1 'Scp' 10000 2250 2250 490 225) Write-Plan '02_A1单口测试.json' '02 A1单口测试' $items # 3. C1/C2单口多协议。先测A面(CC1),再测B面(CC2)。 # PPS3-5没有规格值,仅做9V空载握手,避免未确认的大电流带载。 $items = [System.Collections.Generic.List[object]]::new() $multiProtocolCases = @( [pscustomobject]@{ Label = '标准5V3A'; Protocol = 'Standard'; Gear = 0; Voltage = 5000; ProtocolCurrent = 3000; LoadCurrent = 3000; VTol = 240; ITol = 300 }, [pscustomobject]@{ Label = 'PDO9V3A'; Protocol = 'Pdo'; Gear = 0; Voltage = 9000; ProtocolCurrent = 3000; LoadCurrent = 3000; VTol = 440; ITol = 300 }, [pscustomobject]@{ Label = 'PDO15V3A'; Protocol = 'Pdo'; Gear = 0; Voltage = 15000; ProtocolCurrent = 3000; LoadCurrent = 3000; VTol = 740; ITol = 300 }, [pscustomobject]@{ Label = 'PDO20V2.25A'; Protocol = 'Pdo'; Gear = 0; Voltage = 20000; ProtocolCurrent = 2250; LoadCurrent = 2250; VTol = 790; ITol = 225 }, [pscustomobject]@{ Label = 'PPS1-9V4.5A'; Protocol = 'Pps'; Gear = 1; Voltage = 9000; ProtocolCurrent = 4500; LoadCurrent = 4500; VTol = 450; ITol = 225 }, [pscustomobject]@{ Label = 'PPS2-19V2A'; Protocol = 'Pps'; Gear = 2; Voltage = 19000; ProtocolCurrent = 2000; LoadCurrent = 2000; VTol = 950; ITol = 150 }, [pscustomobject]@{ Label = 'PPS3-9V空载握手'; Protocol = 'Pps'; Gear = 3; Voltage = 9000; ProtocolCurrent = 1000; LoadCurrent = 0; VTol = 450; ITol = 100 }, [pscustomobject]@{ Label = 'PPS4-9V空载握手'; Protocol = 'Pps'; Gear = 4; Voltage = 9000; ProtocolCurrent = 1000; LoadCurrent = 0; VTol = 450; ITol = 100 }, [pscustomobject]@{ Label = 'PPS5-9V空载握手'; Protocol = 'Pps'; Gear = 5; Voltage = 9000; ProtocolCurrent = 1000; LoadCurrent = 0; VTol = 450; ITol = 100 } ) $avsCases = @( [pscustomobject]@{ Label = 'AVS-9V3A'; Protocol = 'Avs'; Gear = 0; Voltage = 9000; ProtocolCurrent = 3000; LoadCurrent = 3000; VTol = 150; ITol = 300 }, [pscustomobject]@{ Label = 'AVS-20V2.25A'; Protocol = 'Avs'; Gear = 0; Voltage = 20000; ProtocolCurrent = 2250; LoadCurrent = 2250; VTol = 650; ITol = 225 } ) $cPorts = @([pscustomobject]@{ Name = 'C1'; Channel = $c1 }, [pscustomobject]@{ Name = 'C2'; Channel = $c2 }) foreach ($face in @( [pscustomobject]@{ Name = 'A面'; CcSelection = 1 }, [pscustomobject]@{ Name = 'B面'; CcSelection = 2 } )) { foreach ($case in $multiProtocolCases) { foreach ($port in $cPorts) { Add-SingleTest $items "$($face.Name)-$($case.Label)" (New-PortConfig $port.Name $port.Channel $case.Protocol ` $case.Voltage $case.ProtocolCurrent $case.LoadCurrent $case.VTol $case.ITol $case.Gear) $face.CcSelection } } foreach ($case in $avsCases) { Add-SingleTest $items "$($face.Name)-$($case.Label)" (New-PortConfig 'C1' $c1 $case.Protocol ` $case.Voltage $case.ProtocolCurrent $case.LoadCurrent $case.VTol $case.ITol $case.Gear) $face.CcSelection } } Write-Plan '03_C1-C2单口多协议测试.json' '03 C1/C2单口多协议A/B面测试(含PPS1~5、AVS)' $items # 4. 两口组合:只有20V项目使用PDO,其余5V均为标准协议。 $items = [System.Collections.Generic.List[object]]::new() Add-CombinationTest $items '组合1-C1+C2' @( (New-PortConfig 'C1' $c1 'Pdo' 20000 1500 1500 990 150), (New-PortConfig 'C2' $c2 'Standard' 5000 3000 3000 240 300) ) Add-CombinationTest $items '组合2-C1+A1' @( (New-PortConfig 'C1' $c1 'Pdo' 20000 1500 1500 990 150), (New-PortConfig 'A1' $a1 'Standard' 5000 3000 3000 240 300) ) Add-CombinationTest $items '组合3-C2+A1' @( (New-PortConfig 'C2' $c2 'Standard' 5000 1500 1500 240 150), (New-PortConfig 'A1' $a1 'Standard' 5000 1500 1500 240 150) ) Write-Plan '04_两口组合输出测试.json' '04 两口组合输出测试' $items # 5. 三口组合:C1为PD 20V,C2/A1为标准5V。 $items = [System.Collections.Generic.List[object]]::new() Add-CombinationTest $items '三口组合-C1+C2+A1' @( (New-PortConfig 'C1' $c1 'Pdo' 20000 1500 1500 990 150), (New-PortConfig 'C2' $c2 'Standard' 5000 1500 1500 240 150), (New-PortConfig 'A1' $a1 'Standard' 5000 1500 1500 240 150) ) Write-Plan '05_C1-C2-A1三口组合输出测试.json' '05 C1/C2/A1三口组合输出测试' $items