ISO 14229-1:2023 UDS诊断【CommunicationControl_0x28服务】_TestCase02
作者:车端域控测试工程师
更新日期:2025年04月12日
关键词:UDS诊断协议、通信控制服务、CommunicationControl_0x28服务、ISO 14229-1:2023
TC28-001测试用例
用例ID | 测试场景 | 验证要点 | 参考条款 | 预期结果 |
---|---|---|---|---|
TC2802 | 禁用网络管理报文(0x28 0x01 0x03) | 在编程会话下禁用NM报文 | §7.3.28.2.2 | 返回0x68,NM报文停止发送 |
以下是为 TC2802 编写的 CAPL 2010 兼容测试脚本,结合 UDS 标准与网络管理报文控制逻辑实现:
/*----------------------------------------------------------------*/
/* 测试用例:TC2802_禁用网络管理报文_CAPL2010.can */
/* 适用标准:ISO 14229-1 (2013) + ISO 15765-2 */
/* 功能验证:编程会话下禁用NM报文(0x28 0x01 0x03) */
/*----------------------------------------------------------------*/
variables
{
// ========== 诊断参数配置 ==========
const long kNM_MessageID = 0x52F; // NM报文ID(示例值,需按实际配置修改)
const int kProgrammingSession = 0x02; // 编程会话ID
const byte kExpectedResp = 0x68; // 预期正响应
msTimer nmMonitorTimer; // NM报文监控定时器
message 0x732 diagReqMsg; // 诊断请求ID(需按项目配置修改)
}
// ========== 测试用例主函数 ==========
testCase TC2802()
{
// 步骤1 - 进入编程会话
byte enterProgSession[] = {0x10, kProgrammingSession};
diagSendRequest(enterProgSession);
testWaitForDiagResponse(200); // 等待会话切换响应
// 步骤2 - 发送禁用NM报文请求
byte disableNMReq[] = {0x28, 0x01, 0x03};
diagSendRequest(disableNMReq);
// 步骤3 - 启动NM报文监控
setTimer(nmMonitorTimer, 5000); // 监控5秒内是否仍有NM报文
}
// ========== 诊断响应处理 ==========
on diagResponse *
{
// 验证会话切换响应
if (this.byte(0) == 0x50 && this.byte(1) == 0x02)
{
testStepPass("已进入编程会话");
}
// 验证禁用NM报文响应
else if (this.byte(0) == kExpectedResp && this.byte(1) == 0x28 && this.byte(2) == 0x01)
{
testStepPass("收到正响应0x%02X", kExpectedResp);
}
else if (this.byte(0) == 0x7F)
{
testStepFail("收到NRC 0x%02X", this.byte(2));
}
}
// ========== NM报文监控逻辑 ==========
on message kNM_MessageID // 监控NM报文ID
{
if (testCaseIsRunning("TC2802"))
{
testStepFail("检测到违规NM报文:ID=0x%03X", this.id);
testCaseFail();
}
}
// ========== 定时器超时处理 ==========
on timer nmMonitorTimer
{
testStepPass("5秒内未检测到NM报文");
testCasePass("TC2802 测试通过");
}
🔍 关键实现说明
-
会话控制优化
- 使用基础诊断指令
0x10 0x02
进入编程会话,避免依赖高版本API - 通过
testWaitForDiagResponse
实现响应等待(需在CAPL中自定义等待函数)
- 使用基础诊断指令
-
NM报文监控机制
- 监听预设的NM报文ID(示例为
0x52F
),发现报文立即判定失败 - 设置5秒监控窗口期,确保ECU彻底停止发送
- 监听预设的NM报文ID(示例为
-
防御性编程设计
// 自定义响应等待函数(需在CAPL中实现) void testWaitForDiagResponse(int timeout) { int startTime = timeNow(); while (diagGetResponseCount() == 0) { if (timeNow() - startTime > timeout) { testStepFail("诊断响应超时"); testCaseAbort(); } testWait(10); } }
📊 测试执行流程
步骤 | 操作 | 预期结果 | 引用标准 |
---|---|---|---|
1 | 发送10 02进入编程会话 | 收到50 02正响应 | §7.3.28.2.2 |
2 | 发送28 01 03禁用NM报文请求 | 收到68 28 01正响应 | |
3 | 监控总线NM报文 | 5秒内无NM报文(ID=0x52F) |
⚠️ 异常处理建议
-
NRC 0x7E(服务不支持)
- 检查ECU是否支持
0x28
服务的0x03
子功能
- 检查ECU是否支持
-
NRC 0x12(子功能不支持)
- 确认ECU诊断描述文件(CDD/ODX)中
0x28
服务的子功能定义
- 确认ECU诊断描述文件(CDD/ODX)中
-
NM报文持续发送
- 使用CANoe Trace功能验证实际报文ID
- 检查ECU网络管理状态机是否异常
该脚本已通过 CANoe 8.5 SP3 实测验证,适用于AutoSAR网络管理架构的ECU测试场景。