自定义 HMS 功能

2024-11-14
暂无评分

概述

HMS(健康管理系统)是对飞机各模块的运行健康状态的一个管理系统。在 DJI Pilot 2 已经提供了交互界面,可查看各模块的工作状态是否有异常。PSDK 则提供了基本接口来上报 PSDK 设备异常的自定义错误码,便于开发者在 Pilot 2 上获取 PSDK 设备的工作状态。

基本概念

HMS 错误码

单条 HMS 错误码包括错误 ID,错误的 Index 和错误等级。在 PSDK 上报自定义 HMS 错误码后,Pilot 2 上会显示对应的错误码和文案。

当前自定义 HMS 功能仅支持中英文两种语言。

HMS 错误码的等级从低到高,对应错误码提示的严重程度,0 最轻微,4 最严重。

    DJI_HMS_ERROR_LEVEL_NONE = 0,
    DJI_HMS_ERROR_LEVEL_HINT = 1,
    DJI_HMS_ERROR_LEVEL_WARN = 2,
    DJI_HMS_ERROR_LEVEL_CRITICAL = 3,
    DJI_HMS_ERROR_LEVEL_FATAL = 4,

HMS 自定义文案规范

自定义 HMS 的文案配置信息需要遵循如下的规范要求。在 PSDK 上报自定义 HMS 错误码后,Pilot 2 通过解析自定义 HMS 的文案配置信息,获取到错误码对应的文案。若错误码规范不匹配,则不会显示预期的自定义文案。

  • hms_position_desc:负载位置信息描述
  • hms_error_code_list:负载错误码列表
  • hms_error_code:自定义错误码,可用区间为 0x1E020000 - 0x1E02FFFF
  • hms_interface:Pilot 2 在健康管理系统界面上显示的错误码文案
  • message_title:Pilot 2 在健康管理系统界面上显示的错误码自定义文案标题
  • message_content:Pilot 2 在健康管理系统界面上显示的错误码自定义文案内容
  • fpv_interface:Pilot 2 在 FPV 主界面上显示的错误码文案
  • message_on_the_ground:当无人机在地面时,Pilot 2 在 FPV 主界面上显示的自定义错误码文案
  • is_keep_history_on_the_ground:当无人机在地面时,是否保存错误码历史记录
  • message_in_the_sky:当无人机在空中,Pilot 2 在 FPV 主界面上显示的错误码自定义文案
  • is_keep_history_in_the_sky:当无人机在空中时,是否保存错误码历史记录
    "hms_database": {
    "hms_position_desc": "负载%position_index",
    "hms_error_code_list": [
      {
        "hms_error_code": "0x1E020000",
        "hms_interface": {
          "message_title": "HMS测试文案: 我是错误码标题0",
          "message_content": "HMS测试文案: 我是错误码内容0"
        },
        "fpv_interface": {
          "message_on_the_ground": "HMS测试文案: 我在地面发生了错误0",
          "is_keep_history_on_the_ground": false,
          "message_in_the_sky": "HMS测试文案: 我在空中发生了错误0",
          "is_keep_history_in_the_sky": false
        }
      }
    ]
    }

例如,Pilot 2 在健康管理系统界面上显示的错误码自定义文案标题和内容如下图所示:

当无人机在地面时,Pilot 2 在 FPV 主界面上显示的自定义错误码文案和错误码如下图所示:

使用自定义 HMS 功能

1. 初始化自定义 HMS 功能模块

在使用自定义 HMS 功能的相关接口之前,需要先调用 DjiHmsCustomization_Init 接口初始化自定义 HMS 功能模块。

    returnCode = DjiHmsCustomization_Init();
    if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
        USER_LOG_ERROR("Hms init error, error code:0x%08llX", returnCode);
        return returnCode;
    }

2. 注册自定义 HMS 文案配置

在 Linux 和 RTOS 系统上开发负载设备时,需要注册自定义 HMS 的文案配置信息,如自定义 HMS 默认的文案配置和不同系统语言对应的文案配置文件,以确保 Pilot 2 能够获取并正确显示自定义 HMS 的文案配置信息。

注册负载设备的自定义 HMS 文案配置(Linux)

    //Step 2 : Set hms text Config (Linux environment)
    returnCode = DjiUserUtil_GetCurrentFileDirPath(__FILE__, HMS_DIR_PATH_LEN_MAX, curFileDirPath);
    if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
        USER_LOG_ERROR("Get file current path error, stat = 0x%08llX", returnCode);
        return returnCode;
    }

    if (s_isHmsConfigFileDirPathConfigured == true) {
        snprintf(tempPath, HMS_DIR_PATH_LEN_MAX, "%shms_text/en", s_hmsConfigFileDirPath);
    } else {
        snprintf(tempPath, HMS_DIR_PATH_LEN_MAX, "%shms_text/en", curFileDirPath);
    }

    //Set default hms text config path
    returnCode = DjiHmsCustomization_RegDefaultHmsTextConfigByDirPath(tempPath);
    if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
        USER_LOG_ERROR("Add default hms text config error, stat = 0x%08llX", returnCode);
        return returnCode;
    }

    //Set hms text config for English language
    returnCode = DjiHmsCustomization_RegHmsTextConfigByDirPath(DJI_MOBILE_APP_LANGUAGE_ENGLISH,
                                                               tempPath);
    if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
        USER_LOG_ERROR("Add hms text config error, stat = 0x%08llX", returnCode);
        return returnCode;
    }

    //Set hms text config for Chinese language
    if (s_isHmsConfigFileDirPathConfigured == true) {
        snprintf(tempPath, HMS_DIR_PATH_LEN_MAX, "%shms_text/cn", s_hmsConfigFileDirPath);
    } else {
        snprintf(tempPath, HMS_DIR_PATH_LEN_MAX, "%shms_text/cn", curFileDirPath);
    }

    returnCode = DjiHmsCustomization_RegHmsTextConfigByDirPath(DJI_MOBILE_APP_LANGUAGE_CHINESE,
                                                               tempPath);
    if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
        USER_LOG_ERROR("Add hms text config error, stat = 0x%08llX", returnCode);
        return returnCode;
    }

注册负载设备的自定义 HMS 文案配置(RTOS)

    //Step 2 : Set hms text Config (RTOS environment)
    T_DjiHmsBinaryArrayConfig enHmsTextBinaryArrayConfig = {
        .binaryArrayCount = sizeof(s_EnHmsTextConfigFileBinaryArrayList) / sizeof(T_DjiHmsFileBinaryArray),
        .fileBinaryArrayList = s_EnHmsTextConfigFileBinaryArrayList
    };

    //Set default hms text config
    returnCode = DjiHmsCustomization_RegDefaultHmsTextConfigByBinaryArray(&enHmsTextBinaryArrayConfig);
    if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
        USER_LOG_ERROR("Add default hms text config error, stat = 0x%08llX", returnCode);
        return returnCode;
    }

3. 上报 HMS 错误码

开发者可通过调用 DjiHmsCustomization_InjectHmsErrorCode 接口上报自定义的 HMS 错误码。当 PSDK 设备有错误发生时,开发者可在 Pilot 2 上获取实时的 PSDK 设备的错误码和与之匹配的自定义文案。

    DjiHmsCustomization_InjectHmsErrorCode(0x1E020000, DJI_HMS_ERROR_LEVEL_FATAL);
    DjiHmsCustomization_InjectHmsErrorCode(0x1E020001, DJI_HMS_ERROR_LEVEL_CRITICAL);
    DjiHmsCustomization_InjectHmsErrorCode(0x1E020002, DJI_HMS_ERROR_LEVEL_WARN);
    DjiHmsCustomization_InjectHmsErrorCode(0x1E020003, DJI_HMS_ERROR_LEVEL_HINT);

4. 清除 HMS 错误码

注意:HMS 的错误码当上报后,将一直显示在 Pilot 2 上。若需清除显示,需调用 DjiHmsCustomization_EliminateHmsErrorCode 接口。

开发者可通过调用 DjiHmsCustomization_EliminateHmsErrorCode 接口清除 Pilot 2 上显示的 PSDK 设备自定义错误码。

    DjiHmsCustomization_EliminateHmsErrorCode(0x1E020000);
    DjiHmsCustomization_EliminateHmsErrorCode(0x1E020001);
    DjiHmsCustomization_EliminateHmsErrorCode(0x1E020002);
    DjiHmsCustomization_EliminateHmsErrorCode(0x1E020003);
若您对文档有意见或疑惑,点击可快速反馈,我们会与您联系。