[Davinci Configurator 配置] 实现功能寻址不响应、关闭抑制肯定响应、NRC否定响应

本文介绍如何使用DavinciConfiguratorPro配置工具实现特定UDS诊断服务的功能,包括不响应特定服务请求、上报否定响应NRC12及NRC22等。通过具体示例展示了配置步骤与代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

背景

在DCM开发过程中经常会遇到如下功能需求:

(1)某个UDS诊断服务不支持功能寻址的情况下,ECU接收到功能寻址的该UDS诊断服务,如何实现不响应该诊断服务。

        举例:2E服务不支持功能寻址,ECU接收到2E服务请求,则不响应

(2)某个UDS诊断服务不支持抑制肯定响应的情况下,ECU接收到带有抑制肯定响应的SID诊断服务,如何实现上报否定响应NRC12。

        举例:19服务不支持抑制肯定响应,ECU接收到19 8x xx请求,则响应NRC12

(3)如何实现ECU上报某些UDS诊断服务的NRC22否定响应。

        举例:11服务需要NRC22条件(车速小于3km/h)检测,当车速大于3km/h时ECU接收到11 01请求,则响应NRC22

配置教程

Davinci Configurator Pro配置工具预留两个通知功能(manufacturer notification和supplier notification),可根据不同需求选择相应的功能,这边我们选择的是supplier notification。该功能是在DCM模块接收到诊断服务后会先调用相应的接口执行一些逻辑判定,若判定为成功进行下一步诊断逻辑,否则直接返回相应的NRC。

1.使能supplier notification功能

如下图所示,在Dcm-->DcmConfigSet-->DcmGeneral模块中,勾选DcmRequestSupplierNotificationEnabled功能。

2.创建Supplier notification容器

在/MICROSAR/Dcm/DcmConfigSet/DcmDsl/DcmDslServiceRequestSupplierNotification模块中,右击选择“create xxx container”。

3.创建Notification Indication 和Notification Confirmation函数

如下图所示,点击步骤2中生成的容器,填写Notification Indication 和Notification Confirmation函数名。

4.生成DCM代码

如下图所示,点击“generate”图标,选择“DCM”模块,点击“generate”即可生成代码。到这里Davinci 配置就已经完成了,接下来我们手动实现相应的功能即可。

5.查看生成代码

我们先来初略的查看下Davinci cfg工具生成的代码,对比代码可以看到,在Dcm_Lcfg.c中定义了一个Dcm_CfgDiagSysNotificationInfo结构体数组,包含两个函数(即步骤3中创建的函数名)。同时在Dcm_Lcfg.h文件中还定义这两个函数的参数和返回值。

/*! System supplier notification functions */
CONST(Dcm_CfgDiagNotificationInfoType, DCM_CONST) Dcm_CfgDiagSysNotificationInfo[2]=
{
   { ServiceRequestNotification_ConditionCheck_Indication,ServiceRequestNotification_Confirmation}
  ,{ NULL_PTR,NULL_PTR}
};
/***********************************************************************************************************************
 *  ServiceRequestNotification_ConditionCheck_Indication()
***********************************************************************************************************************/
/*! \brief         Performs supplier specific validations on a diagnostic service request.
 *  \details       This function is a request from the DCM to the application to validate the received diagnostic
 *                 service, additionally to the DCM internal validation.
 *  \param[in]     SID                         Contains the diagnostic service Id
 *  \param[in]     RequestData                 Points to the request data. Points behind the service Id byte
 *  \param[in]     DataSize                    Specifies the requested data length (without the SID byte)
 *  \param[in]     ReqType                     Specifies the diagnostic request type:
 *                                             0 - physical request
 *                                             1 - functional request
 *  \param[in]     SourceAddress               Contains the diagnostic client source address
 *  \param[out]    ErrorCode                   NRC to be sent in the negative response in case of failure (E_NOT_OK)
 *  \return        E_OK                        The operation is finished
 *  \return        DCM_E_REQUEST_NOT_ACCEPTED  The diagnostic service shall not be processed.
 *                                             No response will be sent
 *  \return        E_NOT_OK                    The operation has failed
 *                                             A concrete NRC shall be set, otherwise the DCM sends NRC 0x22
 *  \context       TASK
 *  \reentrant     FALSE
 *  \synchronous   TRUE
 *  \pre           -
***********************************************************************************************************************/
FUNC(Std_ReturnType, DCM_CALLOUT_CODE) ServiceRequestNotification_ConditionCheck_Indication(uint8 SID, P2CONST(uint8, AUTOMATIC, DCM_VAR_NOINIT) RequestData, uint16 DataSize, uint8 ReqType, uint16 SourceAddress, P2VAR(Dcm_NegativeResponseCodeType, AUTOMATIC, DCM_VAR_NOINIT) ErrorCode);
/***********************************************************************************************************************
 *  ServiceRequestNotification_Confirmation()
***********************************************************************************************************************/
/*! \brief         Finishes supplier specific actions on a diagnostic service request.
 *  \details       This function is a notification from the DCM to the application that a diagnostic service processing
 *                 is finished.
 *  \param[in]     SID                 Contains the diagnostic service Id
 *  \param[in]     ReqType             Specifies the diagnostic request type:
 *                                     0 - physical request
 *                                     1 - functional request
 *  \param[in]     SourceAddress       Contains the diagnostic client source address
 *  \param[in]     ConfirmationStatus  Contains the response transmission resp. diagnostic response type
 *  \return        E_OK                The operation is finished
 *  \return        E_NOT_OK            The operation has failed. Has no effect on DCM.
 *  \context       TASK
 *  \reentrant     FALSE
 *  \synchronous   TRUE
 *  \pre           -
***********************************************************************************************************************/
FUNC(Std_ReturnType, DCM_CALLOUT_CODE) ServiceRequestNotification_Confirmation(uint8 SID, uint8 ReqType, uint16 SourceAddress, Dcm_ConfirmationStatusType ConfirmationStatus);

6.实现Notification Indication 和Notification Confirmation函数

根据上面三个功能需求,我们分别对2E/19/11服务进行相应的逻辑处理。

在2E服务中,若接收到功能寻址的指令,则不响应请求。

在19服务中,若SID的bit7为1,则响应NRC12。

在11服务中,先获取当前车速,判定车速是否满足要求,若不满足,则返回NRC22

#define DIA_NRC22_CONDITION_VEHSPEED_LIMIT  (3.0f)
/***********************************************************************************************************************
 *  ServiceRequestNotification_ConditionCheck_Indication()
***********************************************************************************************************************/
/*! \brief         Performs supplier specific validations on a diagnostic service request.
 *  \details       This function is a request from the DCM to the application to validate the received diagnostic
 *                 service, additionally to the DCM internal validation.
 *  \param[in]     SID                         Contains the diagnostic service Id
 *  \param[in]     RequestData                 Points to the request data. Points behind the service Id byte
 *  \param[in]     DataSize                    Specifies the requested data length (without the SID byte)
 *  \param[in]     ReqType                     Specifies the diagnostic request type:
 *                                             0 - physical request
 *                                             1 - functional request
 *  \param[in]     SourceAddress               Contains the diagnostic client source address
 *  \param[out]    ErrorCode                   NRC to be sent in the negative response in case of failure (E_NOT_OK)
 *  \return        E_OK                        The operation is finished
 *  \return        DCM_E_REQUEST_NOT_ACCEPTED  The diagnostic service shall not be processed.
 *                                             No response will be sent
 *  \return        E_NOT_OK                    The operation has failed
 *                                             A concrete NRC shall be set, otherwise the DCM sends NRC 0x22
 *  \context       TASK
 *  \reentrant     FALSE
 *  \synchronous   TRUE
 *  \pre           -
***********************************************************************************************************************/
FUNC(Std_ReturnType, DCM_CALLOUT_CODE) ServiceRequestNotification_ConditionCheck_Indication(uint8 SID, P2CONST(uint8, AUTOMATIC, DCM_VAR_NOINIT) RequestData, uint16 DataSize, uint8 ReqType, uint16 SourceAddress, P2VAR(Dcm_NegativeResponseCodeType, AUTOMATIC, DCM_VAR_NOINIT) ErrorCode)
{
    Std_ReturnType l_DcmReturn_e = DCM_E_OK;
    vfc::float32_t l_vehicleVelocity = 0;
    valin::EQualifierVehicleVelocity l_vehicleVelocityVaild = valin::EQualifierVehicleVelocity::Q_VEHICLE_VELOCITY_INVALID;
    valin::CValInOutputPf l_ValInResponse;

    if(true == ov_dia::Cov_diaRunnable::ov_dia_getInstance()->updateValInResponse(l_ValInResponse))
    {
        l_vehicleVelocity = vfc::abs(l_ValInResponse.m_pfOdometry.m_vehicleVelocityDisplay.value());
        l_vehicleVelocityVaild = l_ValInResponse.m_pfOdometry.m_qualifierVehicleVelocity;
    }

    switch (SID)
    {
        case 0x10:
            if(((*RequestData)&0x7F) == 0x02)
            {
                if(ReqType == DCM_FUNCTIONAL_REQUEST)
                {
                    l_DcmReturn_e = DCM_E_REQUEST_NOT_ACCEPTED;
                }
                else
                {
                    if((l_vehicleVelocityVaild == valin::EQualifierVehicleVelocity::Q_VEHICLE_VELOCITY_VALID)&& \
                        (l_vehicleVelocity > DIA_NRC22_CONDITION_VEHSPEED_LIMIT))
                    {
                        *ErrorCode = DCM_E_CONDITIONSNOTCORRECT;
                        l_DcmReturn_e = DCM_E_NOT_OK;
                    }
                }
            }
            break;
        
        case 0x11:
        case 0x14: 
        case 0x28:           
        case 0x85:
            if((l_vehicleVelocityVaild == valin::EQualifierVehicleVelocity::Q_VEHICLE_VELOCITY_VALID)&& \
                (l_vehicleVelocity > DIA_NRC22_CONDITION_VEHSPEED_LIMIT))
            {
                *ErrorCode = DCM_E_CONDITIONSNOTCORRECT;
                l_DcmReturn_e = DCM_E_NOT_OK;
            }
            break;

        case 0x19:
            if(((*RequestData)&0x80) != 0x00)
            {
                *ErrorCode = DCM_E_SUBFUNCTIONNOTSUPPORTED;
                l_DcmReturn_e = DCM_E_NOT_OK;
            }
            break;

        case 0x2E:
        case 0x34:
        case 0x36:
        case 0x37:        
            if(ReqType == DCM_FUNCTIONAL_REQUEST)
            {
                l_DcmReturn_e = DCM_E_REQUEST_NOT_ACCEPTED;
            }
            break;

        case 0x27:
        case 0x31:
            if(ReqType == DCM_FUNCTIONAL_REQUEST)
            {
                l_DcmReturn_e = DCM_E_REQUEST_NOT_ACCEPTED;
            }
            else if(((*RequestData)&0x80) != 0x00)
            {
                *ErrorCode = DCM_E_SUBFUNCTIONNOTSUPPORTED;
                l_DcmReturn_e = DCM_E_NOT_OK;
            }
            break;

        case 0x22:
        case 0x35:
        case 0x3E:
        default:
            break;
    }


    return l_DcmReturn_e;
}
/***********************************************************************************************************************
 *  ServiceRequestNotification_Confirmation()
***********************************************************************************************************************/
/*! \brief         Finishes supplier specific actions on a diagnostic service request.
 *  \details       This function is a notification from the DCM to the application that a diagnostic service processing
 *                 is finished.
 *  \param[in]     SID                 Contains the diagnostic service Id
 *  \param[in]     ReqType             Specifies the diagnostic request type:
 *                                     0 - physical request
 *                                     1 - functional request
 *  \param[in]     SourceAddress       Contains the diagnostic client source address
 *  \param[in]     ConfirmationStatus  Contains the response transmission resp. diagnostic response type
 *  \return        E_OK                The operation is finished
 *  \return        E_NOT_OK            The operation has failed. Has no effect on DCM.
 *  \context       TASK
 *  \reentrant     FALSE
 *  \synchronous   TRUE
 *  \pre           -
***********************************************************************************************************************/
FUNC(Std_ReturnType, DCM_CALLOUT_CODE) ServiceRequestNotification_Confirmation(uint8 SID, uint8 ReqType, uint16 SourceAddress, Dcm_ConfirmationStatusType ConfirmationStatus)
{

}

案例测试

1.案例1

2E服务不支持功能寻址,ECU接收到2E服务请求,则不响应

物理寻址2E服务,回复肯定响应

功能寻址2E服务,不响应

2.案例2

19服务不支持抑制肯定响应,ECU接收到19 8x xx请求,则响应NRC12

19 01 FF请求,回复肯定响应

19 81 FF请求,回复NRC12

3.案例3

11服务需要NRC22条件(车速小于3km/h)检测,当车速大于3km/h时ECU接收到11 01请求,则响应NRC22

在车速为0km/h时,11 01请求,回复肯定响应

在车速为5km/h时,11 01请求,回复NRC22

<think>好的,用户想了解如何关闭抑制肯定响应功能配置方法。首先,我需要回忆一下相关的知识。根据引用中的信息,抑制肯定响应位是在Subfunction字节的最高位。当这个位设置为1时,肯定响应会被抑制,设置为0则抑制。用户需要关闭这个功能,也就是要让肯定响应抑制,所以应该将该位设置为0。 接下来,我需要确定在配置工具中如何操作。引用提到使用CANdelaStudio和Davinci Configurator。在CANdelaStudio中,可能需要找到相关服务的子功能参数设置,将抑制位设为0。而在Davinci Configurator中,可能需要创建Notification函数或者修改现有配置,确保抑制位未被置位。 另外,需要注意只有支持Subfunction的服务才能使用这个抑制位。因此,用户需要确认目标服务是否支持子功能。同时,关闭抑制后,肯定响应会正常发送,但否定响应受影响,这点需要明确告知用户,避免混淆。 最后,总结步骤,分点说明在两种工具中的操作方法,并提醒注意事项,比如服务是否支持子功能,以及否定响应的处理。这样用户就能清楚如何操作,并避免常见错误。</think>### 如何关闭抑制肯定响应功能配置方法 #### 1. 理解抑制肯定响应位的原理 抑制肯定响应消息指示位(Suppress Positive Response Message Bit)位于服务子功能(Subfunction)字节的最高位(Bit 7)。当该位置为$1$时,服务请求的肯定响应将被抑制;置为$0$时,肯定响应正常发送[^2][^3]。否定响应NRC受此位影响,始终根据诊断协议规则处理。 #### 2. 配置工具中的操作步骤 ##### **在CANdelaStudio中配置** 1. **定位服务子功能参数** - 打开诊断数据库(CDD文件),找到需要配置的服务(如$0x22$ ReadDataByIdentifier) - 进入服务子功能定义界面,定位`Subfunction`参数 2. **修改抑制位状态** - 将子功能参数的`SuppressPosRspMsgIndicationBit`属性设置为$0$ - 确保子功能字节的最高位对应二进制值$0$(例如:子功能值$0x01$对应二进制$00000001$) ##### **在Davinci Configurator配置** 1. **配置服务响应规则** - 打开诊断模块配置(如Dcm模块) - 导航至`DcmDspResponse`或`DcmDspService`节点,选择目标服务 2. **禁用抑制功能** - 在服务属性中,设置`SuppressPositiveResponse`为`FALSE`[^4] - 若需完全关闭功能寻址响应抑制,需同步配置`DcmDspSessionControl`中的会话层参数 ```c /* 伪代码示例:配置服务响应抑制位 */ DcmDspServiceReadDataByIdentifier { SuppressPositiveResponse = FALSE; // 关闭肯定响应抑制 NrcHandling = PROCEED_ONLY_IF_POS_OK; // 否定响应规则 } ``` #### 3. 验证配置效果 - **肯定响应恢复**:发送服务请求后,ECU应返回肯定响应(例如$0x62$) - **否定响应保留**:当请求非法时,仍会收到否定响应(如$0x31$) #### 4. 注意事项 - **服务支持性**:仅支持子功能(Subfunction)的服务才具备此配置选项 - **位域对齐**:子功能值需确保最高位未置$1$(例如子功能范围应为$0x00$至$0x7F$) - **协议兼容性**:需符合UDS(ISO 14229)或OBD-II(ISO 15031)规范 --- ### §相关问题§ 1. 如何判断某个诊断服务是否支持子功能(Subfunction)? 2. 抑制肯定响应功能在哪些实际场景中使用? 3. 如果同时需要抑制否定响应,应如何配置? 4. 功能寻址与物理寻址响应抑制配置上有何区别?
评论 24
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值