电源管理
This commit is contained in:
@ -33,9 +33,12 @@
|
|||||||
/* Private types -------------------------------------------------------------*/
|
/* Private types -------------------------------------------------------------*/
|
||||||
|
|
||||||
/* Private functions declaration ---------------------------------------------*/
|
/* 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);
|
static T_DjiReturnCode DjiTest_PowerOffNotificationCallback(bool *powerOffPreparationFlag);
|
||||||
|
|
||||||
/* Private variables ---------------------------------------------------------*/
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
//此变量是函数DjiTest_RegApplyHighPowerHandler先判断然后内存拷贝过来的
|
||||||
static T_DjiTestApplyHighPowerHandler s_applyHighPowerHandler;
|
static T_DjiTestApplyHighPowerHandler s_applyHighPowerHandler;
|
||||||
|
|
||||||
/* Exported functions definition ---------------------------------------------*/
|
/* Exported functions definition ---------------------------------------------*/
|
||||||
@ -48,6 +51,9 @@ static T_DjiTestApplyHighPowerHandler s_applyHighPowerHandler;
|
|||||||
*/
|
*/
|
||||||
T_DjiReturnCode DjiTest_RegApplyHighPowerHandler(T_DjiTestApplyHighPowerHandler *applyHighPowerHandler)
|
T_DjiReturnCode DjiTest_RegApplyHighPowerHandler(T_DjiTestApplyHighPowerHandler *applyHighPowerHandler)
|
||||||
{
|
{
|
||||||
|
//此函数的功能:验证这两个函数指针指向的函数是否可用 → 结构体T_PsdkTestApplyHighPowerHandler中有两个函数指针,分别为pinInit和pinWrite
|
||||||
|
|
||||||
|
//1、先判断两个函数指针是否为空,如果为空就报错
|
||||||
if (applyHighPowerHandler->pinInit == NULL) {
|
if (applyHighPowerHandler->pinInit == NULL) {
|
||||||
USER_LOG_ERROR("reg apply high power handler pinInit error");
|
USER_LOG_ERROR("reg apply high power handler pinInit error");
|
||||||
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
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;
|
return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//2、如果不为空就内存拷贝到本文件的静态变量中
|
||||||
memcpy(&s_applyHighPowerHandler, applyHighPowerHandler, sizeof(T_DjiTestApplyHighPowerHandler));
|
memcpy(&s_applyHighPowerHandler, applyHighPowerHandler, sizeof(T_DjiTestApplyHighPowerHandler));
|
||||||
|
|
||||||
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
|
||||||
@ -72,6 +79,10 @@ T_DjiReturnCode DjiTest_RegApplyHighPowerHandler(T_DjiTestApplyHighPowerHandler
|
|||||||
*/
|
*/
|
||||||
T_DjiReturnCode DjiTest_PowerManagementStartService(void)
|
T_DjiReturnCode DjiTest_PowerManagementStartService(void)
|
||||||
{
|
{
|
||||||
|
//此函数的功能:
|
||||||
|
//1、申请高功率。如果要申请高功率,需要在执行本函数前,先执行DjiTest_RegApplyHighPowerHandler函数
|
||||||
|
//2、负载设备关机前需要执行的操作
|
||||||
|
|
||||||
T_DjiReturnCode returnCode;
|
T_DjiReturnCode returnCode;
|
||||||
T_DjiAircraftInfoBaseInfo baseInfo = {0};
|
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_SKYPORT_V2 ||
|
||||||
baseInfo.djiAdapterType == DJI_SDK_ADAPTER_TYPE_XPORT)) {
|
baseInfo.djiAdapterType == DJI_SDK_ADAPTER_TYPE_XPORT)) {
|
||||||
// apply high power
|
// apply high power
|
||||||
|
//如果函数指针为空(没有指向函数),就返回错误代码:DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN
|
||||||
if (s_applyHighPowerHandler.pinInit == NULL) {
|
if (s_applyHighPowerHandler.pinInit == NULL) {
|
||||||
USER_LOG_ERROR("apply high power pin init interface is NULL error");
|
USER_LOG_ERROR("apply high power pin init interface is NULL error");
|
||||||
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||||
@ -102,18 +114,21 @@ T_DjiReturnCode DjiTest_PowerManagementStartService(void)
|
|||||||
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//如果函数指针不为空(指向了一个函数),就执行函数,并根据返回值判断是否成功
|
||||||
returnCode = s_applyHighPowerHandler.pinInit();
|
returnCode = s_applyHighPowerHandler.pinInit();
|
||||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||||
USER_LOG_ERROR("apply high power pin init error");
|
USER_LOG_ERROR("apply high power pin init error");
|
||||||
return returnCode;
|
return returnCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//注册高电压返回函数
|
||||||
returnCode = DjiPowerManagement_RegWriteHighPowerApplyPinCallback(s_applyHighPowerHandler.pinWrite);
|
returnCode = DjiPowerManagement_RegWriteHighPowerApplyPinCallback(s_applyHighPowerHandler.pinWrite);
|
||||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||||
USER_LOG_ERROR("register WriteHighPowerApplyPinCallback error.");
|
USER_LOG_ERROR("register WriteHighPowerApplyPinCallback error.");
|
||||||
return returnCode;
|
return returnCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//执行高电压请求
|
||||||
returnCode = DjiPowerManagement_ApplyHighPowerSync();
|
returnCode = DjiPowerManagement_ApplyHighPowerSync();
|
||||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||||
USER_LOG_ERROR("apply high power error");
|
USER_LOG_ERROR("apply high power error");
|
||||||
@ -122,6 +137,7 @@ T_DjiReturnCode DjiTest_PowerManagementStartService(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// register power off notification callback function
|
// register power off notification callback function
|
||||||
|
//负载设备关机前需要执行的操作
|
||||||
returnCode = DjiPowerManagement_RegPowerOffNotificationCallback(DjiTest_PowerOffNotificationCallback);
|
returnCode = DjiPowerManagement_RegPowerOffNotificationCallback(DjiTest_PowerOffNotificationCallback);
|
||||||
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
|
||||||
USER_LOG_ERROR("register power off notification callback function error");
|
USER_LOG_ERROR("register power off notification callback function error");
|
||||||
@ -145,6 +161,7 @@ T_DjiReturnCode DjiTest_PowerManagementStopService(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Private functions definition-----------------------------------------------*/
|
/* Private functions definition-----------------------------------------------*/
|
||||||
|
//详细说明见函数申明处
|
||||||
static T_DjiReturnCode DjiTest_PowerOffNotificationCallback(bool *powerOffPreparationFlag)
|
static T_DjiReturnCode DjiTest_PowerOffNotificationCallback(bool *powerOffPreparationFlag)
|
||||||
{
|
{
|
||||||
USER_LOG_INFO("aircraft will power off soon.");
|
USER_LOG_INFO("aircraft will power off soon.");
|
||||||
|
@ -39,6 +39,8 @@ extern "C" {
|
|||||||
|
|
||||||
|
|
||||||
/* Exported types ------------------------------------------------------------*/
|
/* Exported types ------------------------------------------------------------*/
|
||||||
|
//里面的两个函数指针例子见下方网页中:PsdkTest_HighPowerApplyPinInit + PsdkTest_WriteHighPowerApplyPin
|
||||||
|
//https://developer.dji.com/doc/payload-sdk-tutorial/cn/function-set/basic-function/power-management.html
|
||||||
typedef struct {
|
typedef struct {
|
||||||
T_DjiReturnCode (*pinInit)(void);
|
T_DjiReturnCode (*pinInit)(void);
|
||||||
T_DjiReturnCode (*pinWrite)(E_DjiPowerManagementPinState pinState);
|
T_DjiReturnCode (*pinWrite)(E_DjiPowerManagementPinState pinState);
|
||||||
|
Reference in New Issue
Block a user