M350b版本

This commit is contained in:
xin
2026-01-08 16:00:08 +08:00
parent 7396728ea7
commit a76d4b77e9
213 changed files with 8883 additions and 7196579 deletions

View File

@ -61,13 +61,13 @@
{
"hms_error_code": "0x1E020004",
"hms_interface": {
"message_title": "HMS测试文案: 我是错误码标题4",
"message_content": "HMS测试文案: 我是错误码内容4"
"message_title": "负载网络较差",
"message_content": "请检查飞行器周围网络或关闭增强图传"
},
"fpv_interface": {
"message_on_the_ground": "HMS测试文案: 我在地面发生了错误4",
"message_on_the_ground": "负载网络较差,请检查飞行器周围网络或关闭增强图传",
"is_keep_history_on_the_ground": true,
"message_in_the_sky": "HMS测试文案: 我在空中发生了错误4",
"message_in_the_sky": "负载网络较差,请检查飞行器周围网络或关闭增强图传",
"is_keep_history_in_the_sky": true
}
}

View File

@ -61,13 +61,13 @@
{
"hms_error_code": "0x1E020004",
"hms_interface": {
"message_title": "HMS test text: I am error code Title 4",
"message_content": "HMS test text: I am error code Content 4"
"message_title": "Payload Network Poor",
"message_content": "Please check the network around the aircraft or disable Enhanced Transmission"
},
"fpv_interface": {
"message_on_the_ground": "HMS test text: I got error on the ground 4",
"message_on_the_ground": "Payload network is poor. Please check the network around the aircraft or disable Enhanced Transmission",
"is_keep_history_on_the_ground": true,
"message_in_the_sky": "HMS test text: I got error in the sky 4",
"message_in_the_sky": "Payload network is poor. Please check the network around the aircraft or disable Enhanced Transmission",
"is_keep_history_in_the_sky": true
}
}

View File

@ -43,7 +43,11 @@
#define MAX_HMS_ERROR_LEVEL (6)
#define HMS_DIR_PATH_LEN_MAX (256)
#ifdef SYSTEM_ARCH_LINUX
#define DJI_CUSTOM_HMS_CODE_INJECT_ON (0)
#else
#define DJI_CUSTOM_HMS_CODE_INJECT_ON (1)
#endif
/* Private types -------------------------------------------------------------*/
@ -51,11 +55,17 @@
static const char *oldReplaceAlarmIdStr = "%alarmid";
static const char *oldReplaceIndexStr = "%index";
static const char *oldReplaceComponentIndexStr = "%component_index";
static bool isHmsManagerInit = false;
static T_DjiHmsFileBinaryArray s_EnHmsTextConfigFileBinaryArrayList[] = {
{hms_text_config_json_fileName, hms_text_config_json_fileSize, hms_text_config_json_fileBinaryArray},
};
#ifdef SYSTEM_ARCH_LINUX
static uint8_t *s_hmsJsonData = NULL;
static T_DjiMutexHandle s_hmsJsonDataMutex = {0};
#endif
static E_DjiMobileAppLanguage s_hmsLanguage = DJI_MOBILE_APP_LANGUAGE_ENGLISH;
static bool s_isHmsConfigFileDirPathConfigured = false;
static char s_hmsConfigFileDirPath[DJI_FILE_PATH_SIZE_MAX] = {0};
/* Private functions declaration ---------------------------------------------*/
static T_DjiReturnCode DjiTest_HmsManagerInit(void);
@ -63,7 +73,9 @@ static T_DjiReturnCode DjiTest_HmsManagerDeInit(void);
static T_DjiFcSubscriptionFlightStatus DjiTest_GetValueOfFlightStatus(void);
static bool DjiTest_ReplaceStr(char *buffer, uint32_t bufferMaxLen, const char *target, const char *dest);
static bool DjiTest_MarchErrCodeInfoTable(T_DjiHmsInfoTable hmsInfoTable);
#ifdef SYSTEM_ARCH_LINUX
static bool DjiTest_MarchErrCodeInfoTableByJson(T_DjiHmsInfoTable hmsInfoTable);
#endif
static T_DjiReturnCode DjiTest_HmsInfoCallback(T_DjiHmsInfoTable hmsInfoTable);
/* Exported functions definition ---------------------------------------------*/
@ -86,6 +98,7 @@ T_DjiReturnCode DjiTest_HmsManagerRunSample(E_DjiMobileAppLanguage language)
}
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 = DjiHmsManager_RegHmsInfoCallback(DjiTest_HmsInfoCallback);
@ -132,7 +145,11 @@ T_DjiReturnCode DjiTest_HmsCustomizationStartService(void)
return returnCode;
}
snprintf(tempPath, HMS_DIR_PATH_LEN_MAX, "%shms_text/en", curFileDirPath);
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);
@ -150,7 +167,12 @@ T_DjiReturnCode DjiTest_HmsCustomizationStartService(void)
}
//set hms text config for Chinese language
snprintf(tempPath, HMS_DIR_PATH_LEN_MAX, "%shms_text/cn", curFileDirPath);
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) {
@ -174,21 +196,40 @@ T_DjiReturnCode DjiTest_HmsCustomizationStartService(void)
#if DJI_CUSTOM_HMS_CODE_INJECT_ON
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);
#endif
return returnCode;
}
T_DjiReturnCode DjiTest_HmsCustomizationSetConfigFilePath(const char *path)
{
memset(s_hmsConfigFileDirPath, 0, sizeof(s_hmsConfigFileDirPath));
memcpy(s_hmsConfigFileDirPath, path, USER_UTIL_MIN(strlen(path), sizeof(s_hmsConfigFileDirPath) - 1));
s_isHmsConfigFileDirPathConfigured = true;
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/* Private functions definition-----------------------------------------------*/
static T_DjiReturnCode DjiTest_HmsManagerInit(void)
{
T_DjiReturnCode returnCode;
#ifdef SYSTEM_ARCH_LINUX
char curFileDirPath[HMS_DIR_PATH_LEN_MAX];
char tempFileDirPath[HMS_DIR_PATH_LEN_MAX];
uint32_t fileSize = 0;
uint32_t readRealSize = 0;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
returnCode = osalHandler->MutexCreate(&s_hmsJsonDataMutex);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Create mutex error: 0x%08llX.", returnCode);
return returnCode;
}
#endif
returnCode = DjiFcSubscription_Init();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Hms sample init data subscription module failed, error code:0x%08llX", returnCode);
@ -199,13 +240,13 @@ static T_DjiReturnCode DjiTest_HmsManagerInit(void)
returnCode = DjiFcSubscription_SubscribeTopic(DJI_FC_SUBSCRIPTION_TOPIC_STATUS_FLIGHT,
DJI_DATA_SUBSCRIPTION_TOPIC_10_HZ,
NULL);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("HMS sample subscribe topic flight status error, error code:0x%08llX", returnCode);
return returnCode;
}
#ifdef SYSTEM_ARCH_LINUX
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);
@ -230,13 +271,17 @@ static T_DjiReturnCode DjiTest_HmsManagerInit(void)
UtilFile_GetFileDataByPath(tempFileDirPath, 0, fileSize, s_hmsJsonData, &readRealSize);
#endif
isHmsManagerInit = true;
return DjiHmsManager_Init();
}
static T_DjiReturnCode DjiTest_HmsManagerDeInit(void)
{
T_DjiReturnCode returnCode;
#ifdef SYSTEM_ARCH_LINUX
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
#endif
returnCode = DjiFcSubscription_DeInit();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
@ -246,9 +291,19 @@ static T_DjiReturnCode DjiTest_HmsManagerDeInit(void)
}
#ifdef SYSTEM_ARCH_LINUX
osalHandler->MutexLock(s_hmsJsonDataMutex);
osalHandler->Free(s_hmsJsonData);
s_hmsJsonData = NULL;
osalHandler->MutexUnlock(s_hmsJsonDataMutex);
returnCode = osalHandler->MutexDestroy(s_hmsJsonDataMutex);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Destroy mutex error: 0x%08llX.", returnCode);
}
#endif
isHmsManagerInit = false;
return DjiHmsManager_DeInit();
}
@ -258,6 +313,10 @@ static T_DjiFcSubscriptionFlightStatus DjiTest_GetValueOfFlightStatus(void)
T_DjiFcSubscriptionFlightStatus flightStatus;
T_DjiDataTimestamp flightStatusTimestamp = {0};
if (isHmsManagerInit == false) {
return DJI_FC_SUBSCRIPTION_FLIGHT_STATUS_ON_GROUND;
}
returnCode = DjiFcSubscription_GetLatestValueOfTopic(DJI_FC_SUBSCRIPTION_TOPIC_STATUS_FLIGHT,
(uint8_t *) &flightStatus,
sizeof(T_DjiFcSubscriptionFlightStatus),
@ -357,17 +416,29 @@ static bool DjiTest_MarchErrCodeInfoTable(T_DjiHmsInfoTable hmsInfoTable)
return true;
}
#ifdef SYSTEM_ARCH_LINUX
static bool DjiTest_MarchErrCodeInfoTableByJson(T_DjiHmsInfoTable hmsInfoTable)
{
cJSON *hmsJsonRoot = NULL;
cJSON *hmsErrorCode = NULL;
cJSON *hmsLanguage = NULL;
char alarmIdStr[20] = {0};
char sensorIdStr[20] = {0};
char componentIdStr[20] = {0};
char printBuff[256] = {0};
char hmsErrorCodeString[HMS_DIR_PATH_LEN_MAX] = {0};
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
osalHandler->MutexLock(s_hmsJsonDataMutex);
if (s_hmsJsonData == NULL) {
return 0;
}
hmsJsonRoot = cJSON_Parse((char *) s_hmsJsonData);
if (hmsJsonRoot == NULL) {
return 0;
}
osalHandler->MutexUnlock(s_hmsJsonDataMutex);
for (int i = 0; i < hmsInfoTable.hmsInfoNum; i++) {
if (DjiTest_GetValueOfFlightStatus() == DJI_FC_SUBSCRIPTION_FLIGHT_STATUS_IN_AIR) {
@ -388,14 +459,22 @@ static bool DjiTest_MarchErrCodeInfoTableByJson(T_DjiHmsInfoTable hmsInfoTable)
hmsLanguage = cJSON_GetObjectItem(hmsErrorCode, "fr");
}
if (hmsLanguage != NULL) {
snprintf(alarmIdStr, sizeof(alarmIdStr), "%u", hmsInfoTable.hmsInfo[i].errorCode);
snprintf(sensorIdStr, sizeof(sensorIdStr), "%d", hmsInfoTable.hmsInfo[i].componentIndex + 1);
snprintf(componentIdStr, sizeof(componentIdStr), "0x%02X", hmsInfoTable.hmsInfo[i].componentIndex + 1);
snprintf(printBuff, sizeof(printBuff), "%s", hmsLanguage->valuestring);
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,
hmsLanguage->valuestring);
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,
hmsLanguage->valuestring);
printBuff);
}
} else {
USER_LOG_WARN("[ErrorCode: 0x%2x] There are no matching documents for this language for now.",
@ -409,6 +488,7 @@ static bool DjiTest_MarchErrCodeInfoTableByJson(T_DjiHmsInfoTable hmsInfoTable)
cJSON_Delete(hmsJsonRoot);
}
#endif
static T_DjiReturnCode DjiTest_HmsInfoCallback(T_DjiHmsInfoTable hmsInfoTable)
{

View File

@ -41,6 +41,7 @@ extern "C" {
/* Exported functions --------------------------------------------------------*/
T_DjiReturnCode DjiTest_HmsManagerRunSample(E_DjiMobileAppLanguage language);
T_DjiReturnCode DjiTest_HmsCustomizationStartService(void);
T_DjiReturnCode DjiTest_HmsCustomizationSetConfigFilePath(const char *path);
#ifdef __cplusplus
}