Files
STM32F4-Base/IEC60870-Slave/scripts/build.ps1
T
STF 4c55544f05
CI / L0 静态门禁 (pre-commit) (push) Failing after 45s
CI / L0.5 主机侧单测 (MSVC) (push) Failing after 42s
通信协议代码
2026-10-26 08:31:48 -04:00

46 lines
2.4 KiB
PowerShell

param(
[switch]$Test,
[string]$Compiler = 'gcc'
)
$ErrorActionPreference = 'Stop'
$projectRoot = Split-Path -Parent $PSScriptRoot
$protocolInclude = Join-Path $projectRoot '104'
$commonInclude = Join-Path $projectRoot 'common'
$exampleBuild = Join-Path $projectRoot '.build/slave-example'
New-Item -ItemType Directory -Path $exampleBuild -Force | Out-Null
Get-Command $Compiler -ErrorAction Stop | Out-Null
# Shared dependencies; the example adds the actual TCP and Windows Net implementations.
$libraryNames = @(
'104/IEC104_Interrogation.c', '104/IEC104_Slave.c',
'common/IEC60870_Slave.c', 'common/IEC60870_Asdu.c',
'common/IEC60870_InformationObjects.c', 'common/IEC60870_Time.c', 'common/IEC60870_Codec.c',
'104/IEC104_Connection.c', '104/IEC104_Receiver.c', '104/IEC104_SendManager.c',
'104/IEC104_SendBuffer.c', '104/IEC104_AsduQueue.c', '104/IEC104_Codec.c',
'104/IEC104_Link.c', '104/IEC104_Link_Slave_StartStop.c'
)
$librarySources = @($libraryNames | ForEach-Object { Join-Path $projectRoot $_ })
$compileFlags = @('-std=c11', '-O2', '-Wall', '-Wextra', '-Werror', "-I$protocolInclude", "-I$commonInclude")
$exampleOutput = Join-Path $exampleBuild 'iec104_slave_example.exe'
$exampleSources = @(
(Join-Path $projectRoot 'examples/iec104_slave_example.c'),
(Join-Path $projectRoot '104/IEC104_TcpServer.c'),
(Join-Path $projectRoot '104/IEC104_Net_Windows.c')
) + $librarySources
& $Compiler @compileFlags @exampleSources -o $exampleOutput -lws2_32
if ($LASTEXITCODE -ne 0) { throw 'Slave example build failed' }
Write-Output "Built: $exampleOutput"
if ($Test) {
# The controlled-backend test includes TcpServer.c itself. Do not link a second TCP/Net implementation.
$testOutput = Join-Path $exampleBuild 'iec104_slave_example_test.exe'
$testSources = @((Join-Path $projectRoot 'test/iec104_slave_example_test.c')) + $librarySources
& $Compiler @compileFlags -DIEC104_TCP_HIGH_CAPACITY=251 -DIEC104_INTERROGATION_EVENT_CAPACITY=2 @testSources -o $testOutput
if ($LASTEXITCODE -ne 0) { throw 'Slave example test build failed' }
& $testOutput
if ($LASTEXITCODE -ne 0) { throw 'Slave example tests failed' }
Get-Command node -ErrorAction Stop | Out-Null
& node (Join-Path $projectRoot 'test/slave_example_loopback_test.cjs') $exampleOutput
if ($LASTEXITCODE -ne 0) { throw 'Slave example TCP loopback test failed' }
}