HMS Function

No Rating


HMS (Health Management System) is a monitoring system for the operational health status of each module of the aircraft. An interactive interface has been provided on DJI Pilot to check whether the working status of each module is abnormal. PSDK provides a basic interface to obtain abnormal error information of each module, so that the PSDK program can know the working status of each module of the aircraft.

Basic Concept

HMS error message

A single HMS error message includes an error ID, an error Index and an error level. After subscribing to the HMS information, these error messages will be packaged and sent to the PSDK. PSDK parses the error message data into a string and prints it out from the terminal.

Using the HMS function

1. Initialize the HMS function module

Before using the related interfaces of the HMS function, you need to call the DjiTest_HmsInit interface to initialize the HMS function module.

returnCode = DjiTest_HmsInit();
USER_LOG_ERROR("Hms sample init error, error code:0x%08llX", returnCode);
goto out;

2. Subscribe to flight status information

In the HMS module, it will be judged whether the aircraft is in the air according to the subscription data of TOPIC_STATUS_FLIGHT, so as to distinguish whether the HMS information is received during the flight or received on the ground.

T_DjiReturnCode returnCode;

returnCode = DjiFcSubscription_Init();
USER_LOG_ERROR("Hms sample init data subscription module failed, error code:0x%08llX", returnCode);
return returnCode;

/*! subscribe fc data */
returnCode = DjiFcSubscription_SubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_STATUS_FLIGHT,

USER_LOG_ERROR("HMS sample subscribe topic flight status error, error code:0x%08llX", returnCode);
return returnCode;

3. Register HMS information callback

Developers can get real-time HMS error information push by calling the DjiHms_RegHmsInfoCallback interface to register HMS information callback. When an HMS error occurs, users can get specific HMS information in the DjiTest_HmsInfoCallback callback function.

osalHandler = DjiPlatform_GetOsalHandler();
USER_LOG_INFO("--> Step 2: Register callback function of push HMS information");
DjiTest_WidgetLogAppend("--> Step 2: Register callback function of push HMS information");
returnCode = DjiHms_RegHmsInfoCallback(DjiTest_HmsInfoCallback);
USER_LOG_ERROR("Register callback function of push HMS information failed, error code:0x%08llX", returnCode);
goto out;


4. Parse HMS information

When the user receives the error code of the HMS information, he needs to obtain it by looking up the table. Through the error code and distinguishing whether the aircraft is in the air, the corresponding error string information can be obtained. Combined with the corresponding error code, corresponding measures can be taken. Ensure the flight safety of the aircraft.

char alarmIdStr[20] = {0};
char sensorIdStr[20] = {0};
char componentIdStr[20] = {0};
char printBuff[256] = {0};
const char *originalAlarmInfo = NULL;
uint8_t hmsCodeMatchFlag = 0;

if (!hmsInfoTable.hmsInfo) {
USER_LOG_ERROR("Hms info table is null");
return false;

for (int i = 0; i < hmsInfoTable.hmsInfoNum; i++) {
hmsCodeMatchFlag = 0;
for (int j = 0; j < sizeof(hmsErrCodeInfoTbl) / sizeof(T_DjiHmsErrCodeInfo); j++) {
if (hmsInfoTable.hmsInfo[i].errorCode == hmsErrCodeInfoTbl[j].alarmId) {
hmsCodeMatchFlag = 1;
snprintf(alarmIdStr, sizeof(alarmIdStr), "%u", hmsInfoTable.hmsInfo[i].errorCode);
//note:sensor_idx:[0,5].In order to be consistent with the display of pilot, add one.
snprintf(sensorIdStr, sizeof(sensorIdStr), "%d", hmsInfoTable.hmsInfo[i].componentIndex + 1);
snprintf(componentIdStr, sizeof(componentIdStr), "0x%02X", hmsInfoTable.hmsInfo[i].componentIndex + 1);
if (DjiTest_GetValueOfFlightStatus() == DJI_FC_SUBSCRIPTION_FLIGHT_STATUS_IN_AIR) {
originalAlarmInfo = hmsErrCodeInfoTbl[j].flyAlarmInfo;
} else {
originalAlarmInfo = hmsErrCodeInfoTbl[j].groundAlarmInfo;
originalAlarmInfo = hmsErrCodeInfoTbl[j].groundAlarmInfo;
if (strlen(originalAlarmInfo)) {
snprintf(printBuff, sizeof(printBuff), "%s", originalAlarmInfo);
DjiTest_ReplaceStr(printBuff, sizeof(printBuff), oldReplaceAlarmIdStr, alarmIdStr);
DjiTest_ReplaceStr(printBuff, sizeof(printBuff), oldReplaceIndexStr, sensorIdStr);
DjiTest_ReplaceStr(printBuff, sizeof(printBuff), oldReplaceComponentIndexStr, componentIdStr);
if (hmsInfoTable.hmsInfo[i].errorLevel > MIN_HMS_ERROR_LEVEL &&
hmsInfoTable.hmsInfo[i].errorLevel < MID_HMS_ERROR_LEVEL) {
USER_LOG_WARN("[ErrorCode:0x%2x] %s", hmsInfoTable.hmsInfo[i].errorCode, printBuff);
} else if (hmsInfoTable.hmsInfo[i].errorLevel >= MID_HMS_ERROR_LEVEL &&
hmsInfoTable.hmsInfo[i].errorLevel < MAX_HMS_ERROR_LEVEL) {
USER_LOG_ERROR("[ErrorCode:0x%2x] %s", hmsInfoTable.hmsInfo[i].errorCode, printBuff);
if (!hmsCodeMatchFlag) {
USER_LOG_WARN("[ErrorCode:0x%2x] There are no matching documents in the current hmsErrCodeInfoTbl for now.",

return true;