From c2559f2bbc54d767d4136c4585345157048405bd Mon Sep 17 00:00:00 2001 From: tangchao0503 <735056338@qq.com> Date: Wed, 16 Aug 2023 18:36:23 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=B5=E6=BA=90=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../power_management/test_power_management.c | 17 +++++++++++++++++ .../power_management/test_power_management.h | 2 ++ 2 files changed, 19 insertions(+) diff --git a/samples/sample_c/module_sample/power_management/test_power_management.c b/samples/sample_c/module_sample/power_management/test_power_management.c index 0af54fd..6af7530 100644 --- a/samples/sample_c/module_sample/power_management/test_power_management.c +++ b/samples/sample_c/module_sample/power_management/test_power_management.c @@ -33,9 +33,12 @@ /* Private types -------------------------------------------------------------*/ /* Private functions declaration ---------------------------------------------*/ +//需要自己写的函数:功能是负载设备关机前需要执行的命令 +//https://developer.dji.com/doc/payload-sdk-tutorial/cn/function-set/basic-function/power-management.html static T_DjiReturnCode DjiTest_PowerOffNotificationCallback(bool *powerOffPreparationFlag); /* Private variables ---------------------------------------------------------*/ +//此变量是函数DjiTest_RegApplyHighPowerHandler先判断然后内存拷贝过来的 static T_DjiTestApplyHighPowerHandler s_applyHighPowerHandler; /* Exported functions definition ---------------------------------------------*/ @@ -48,6 +51,9 @@ static T_DjiTestApplyHighPowerHandler s_applyHighPowerHandler; */ T_DjiReturnCode DjiTest_RegApplyHighPowerHandler(T_DjiTestApplyHighPowerHandler *applyHighPowerHandler) { + //此函数的功能:验证这两个函数指针指向的函数是否可用 → 结构体T_PsdkTestApplyHighPowerHandler中有两个函数指针,分别为pinInit和pinWrite + + //1、先判断两个函数指针是否为空,如果为空就报错 if (applyHighPowerHandler->pinInit == NULL) { USER_LOG_ERROR("reg apply high power handler pinInit error"); return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER; @@ -58,6 +64,7 @@ T_DjiReturnCode DjiTest_RegApplyHighPowerHandler(T_DjiTestApplyHighPowerHandler return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER; } + //2、如果不为空就内存拷贝到本文件的静态变量中 memcpy(&s_applyHighPowerHandler, applyHighPowerHandler, sizeof(T_DjiTestApplyHighPowerHandler)); return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS; @@ -72,6 +79,10 @@ T_DjiReturnCode DjiTest_RegApplyHighPowerHandler(T_DjiTestApplyHighPowerHandler */ T_DjiReturnCode DjiTest_PowerManagementStartService(void) { + //此函数的功能: + //1、申请高功率。如果要申请高功率,需要在执行本函数前,先执行DjiTest_RegApplyHighPowerHandler函数 + //2、负载设备关机前需要执行的操作 + T_DjiReturnCode returnCode; T_DjiAircraftInfoBaseInfo baseInfo = {0}; @@ -92,6 +103,7 @@ T_DjiReturnCode DjiTest_PowerManagementStartService(void) (baseInfo.djiAdapterType == DJI_SDK_ADAPTER_TYPE_SKYPORT_V2 || baseInfo.djiAdapterType == DJI_SDK_ADAPTER_TYPE_XPORT)) { // apply high power + //如果函数指针为空(没有指向函数),就返回错误代码:DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN if (s_applyHighPowerHandler.pinInit == NULL) { USER_LOG_ERROR("apply high power pin init interface is NULL error"); return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN; @@ -102,18 +114,21 @@ T_DjiReturnCode DjiTest_PowerManagementStartService(void) return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN; } + //如果函数指针不为空(指向了一个函数),就执行函数,并根据返回值判断是否成功 returnCode = s_applyHighPowerHandler.pinInit(); if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { USER_LOG_ERROR("apply high power pin init error"); return returnCode; } + //注册高电压返回函数 returnCode = DjiPowerManagement_RegWriteHighPowerApplyPinCallback(s_applyHighPowerHandler.pinWrite); if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { USER_LOG_ERROR("register WriteHighPowerApplyPinCallback error."); return returnCode; } + //执行高电压请求 returnCode = DjiPowerManagement_ApplyHighPowerSync(); if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { USER_LOG_ERROR("apply high power error"); @@ -122,6 +137,7 @@ T_DjiReturnCode DjiTest_PowerManagementStartService(void) } // register power off notification callback function + //负载设备关机前需要执行的操作 returnCode = DjiPowerManagement_RegPowerOffNotificationCallback(DjiTest_PowerOffNotificationCallback); if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { USER_LOG_ERROR("register power off notification callback function error"); @@ -145,6 +161,7 @@ T_DjiReturnCode DjiTest_PowerManagementStopService(void) } /* Private functions definition-----------------------------------------------*/ +//详细说明见函数申明处 static T_DjiReturnCode DjiTest_PowerOffNotificationCallback(bool *powerOffPreparationFlag) { USER_LOG_INFO("aircraft will power off soon."); diff --git a/samples/sample_c/module_sample/power_management/test_power_management.h b/samples/sample_c/module_sample/power_management/test_power_management.h index 63cc432..a7bd2a7 100644 --- a/samples/sample_c/module_sample/power_management/test_power_management.h +++ b/samples/sample_c/module_sample/power_management/test_power_management.h @@ -39,6 +39,8 @@ extern "C" { /* Exported types ------------------------------------------------------------*/ +//里面的两个函数指针例子见下方网页中:PsdkTest_HighPowerApplyPinInit + PsdkTest_WriteHighPowerApplyPin +//https://developer.dji.com/doc/payload-sdk-tutorial/cn/function-set/basic-function/power-management.html typedef struct { T_DjiReturnCode (*pinInit)(void); T_DjiReturnCode (*pinWrite)(E_DjiPowerManagementPinState pinState);