电源管理

This commit is contained in:
tangchao0503
2023-08-16 18:36:23 +08:00
parent 5938550032
commit c2559f2bbc
2 changed files with 19 additions and 0 deletions

View File

@ -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.");

View File

@ -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);