1、操作遥控器按钮,psdk进程通过socket发送命令给相机进程 来控制高光谱采集系统;

2、通过FFmpeg采集摄像头视频流并编码为h264,利用psdk推流到遥控器;
This commit is contained in:
tangchao0503
2022-06-22 16:48:50 +08:00
commit 109e0a8f2b
89 changed files with 17079 additions and 0 deletions

View File

@ -0,0 +1,371 @@
/**
********************************************************************
* @file test_upgrade.c
* @version V2.0.0
* @date 3/4/20
* @brief
*
* @copyright (c) 2018-2019 DJI. All rights reserved.
*
* All information contained herein is, and remains, the property of DJI.
* The intellectual and technical concepts contained herein are proprietary
* to DJI and may be covered by U.S. and foreign patents, patents in process,
* and protected by trade secret or copyright law. Dissemination of this
* information, including but not limited to data and other proprietary
* material(s) incorporated within the information, in any form, is strictly
* prohibited without the express written consent of DJI.
*
* If you receive this source code without DJIs authorization, you may not
* further disseminate the information, and you must immediately remove the
* source code and notify DJI of its removal. DJI reserves the right to pursue
* legal actions against you for any loss(es) or damage(s) caused by your
* failure to do so.
*
*********************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "test_upgrade_common.h"
#include <psdk_logger.h>
#include <psdk_platform.h>
#include <utils/util_misc.h>
#include "test_upgrade_common_file_transfer.h"
#include "test_upgrade_platform_opt.h"
/* Private constants ---------------------------------------------------------*/
#define UPGRADE_TASK_STACK_SIZE (2048)
#define PSDK_TEST_UPGRADE_TASK_FREQ 50
#define PSDK_TEST_ENTER_UPGRADE_WAIT_TIME 10 //wait 10s for enter upgrade process
#define PSDK_TEST_UPGRADE_REBOOT_TIMEOUT 30 //reboot timeout 30s
/* Private types -------------------------------------------------------------*/
/* Private values -------------------------------------------------------------*/
static T_PsdkUpgradeState s_upgradeState = {0};
static T_PsdkMutexHandle s_upgradeStateMutex = {0};
static T_PsdkTaskHandle s_upgradeProcessThread;
static T_PsdkTaskHandle s_enterUpgradeModeProcessThread;
static bool s_isNeedEnterUpgradeModeProcess = false;
/* Private functions declaration ---------------------------------------------*/
static T_PsdkReturnCode PsdkTest_EnterUpgradeMode(uint16_t *waitTime);
static T_PsdkReturnCode PsdkTest_CheckFirmware(void);
static T_PsdkReturnCode PsdkTest_StartUpgrade(void);
static T_PsdkReturnCode PsdkTest_FinishUpgrade(void);
static void *PsdkTest_UpgradeProcessTask(void *arg);
static void *PsdkTest_EnterUpgradeModeProcessTask(void *arg);
/* Exported functions definition ---------------------------------------------*/
T_PsdkReturnCode PsdkTest_UpgradeInit(const T_PsdkTestUpgradePlatformOpt *upgradePlatformOpt)
{
T_PsdkReturnCode returnCode;
bool isUpgradeReboot = false;
T_PsdkUpgradeEndInfo upgradeEndInfo = {0};
T_PsdkUpgradeConfig upgradeConfig = {
.currentFirmwareVersion = {PSDK_TEST_FIRMWARE_VERSION_MAJOR, PSDK_TEST_FIRMWARE_VERSION_MINOR,
PSDK_TEST_FIRMWARE_VERSION_MODIFY, PSDK_TEST_FIRMWARE_VERSION_DEBUG},
#if PSDK_TEST_UPGRADE_USE_FTP_TRANSFER
.firmwareTransferInfo = {
.transferType = PSDK_PAYLOAD_FIRMWARE_TRANSFER_TYPE_FTP,
.ftpTransferInfo.port = 21, // use default ftp port
}
#else
.firmwareTransferInfo = {
.transferType = PSDK_PAYLOAD_FIRMWARE_TRANSFER_TYPE_DCFTP,
.dcftpFileTransferOpt = {
.start = PsdkTestCommonFileTransfer_Start,
.transfer = PsdkTestCommonFileTransfer_Transfer,
.finish = PsdkTestCommonFileTransfer_Finish,
}
}
#endif
};
T_PsdkUpgradeHandler s_upgradeHandler = {
.EnterUpgradeMode = PsdkTest_EnterUpgradeMode,
.CheckFirmware = PsdkTest_CheckFirmware,
.StartUpgrade = PsdkTest_StartUpgrade,
.FinishUpgrade = PsdkTest_FinishUpgrade
};
returnCode = PsdkTest_RegUpgradePlatformOpt(upgradePlatformOpt);
if (returnCode != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
PsdkLogger_UserLogError("Reg upgrade platform opt error, return code = 0x%08llX", returnCode);
return returnCode;
}
returnCode = PsdkOsal_MutexCreate(&s_upgradeStateMutex);
if (returnCode != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
PsdkLogger_UserLogError("Create mutex error");
return returnCode;
}
returnCode = PsdkTest_GetUpgradeRebootState(&isUpgradeReboot, &upgradeEndInfo);
if (returnCode != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
PsdkLogger_UserLogError("Get upgrade reboot state error");
isUpgradeReboot = false;
}
returnCode = PsdkTest_CleanUpgradeRebootState();
if (returnCode != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
PsdkLogger_UserLogError("Clean upgrade reboot state error");
}
PsdkOsal_MutexLock(s_upgradeStateMutex);
if (isUpgradeReboot == true) {
s_upgradeState.upgradeStage = PSDK_UPGRADE_STAGE_END;
s_upgradeState.upgradeEndInfo = upgradeEndInfo;
} else {
s_upgradeState.upgradeStage = PSDK_UPGRADE_STAGE_IDLE;
}
PsdkOsal_MutexUnlock(s_upgradeStateMutex);
returnCode = PsdkUpgrade_Init(&upgradeConfig);
if (returnCode != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
PsdkLogger_UserLogError("PsdkUpgrade_Init error, return code = %d", returnCode);
return returnCode;
}
returnCode = PsdkUpgrade_RegHandler(&s_upgradeHandler);
if (returnCode != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
PsdkLogger_UserLogError("PsdkUpgrade_RegHandler error, return code = %d", returnCode);
return returnCode;
}
returnCode = PsdkUpgrade_EnableLocalUpgrade();
if (returnCode != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
PsdkLogger_UserLogError("PsdkUpgrade_EnableLocalUpgrade error, return code = %d", returnCode);
return returnCode;
}
if (PsdkOsal_TaskCreate(&s_upgradeProcessThread, PsdkTest_UpgradeProcessTask, "upgrade_task",
UPGRADE_TASK_STACK_SIZE, NULL) != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
PsdkLogger_UserLogError("Psdk upgrade test task create error.");
return PSDK_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
if (PsdkOsal_TaskCreate(&s_enterUpgradeModeProcessThread, PsdkTest_EnterUpgradeModeProcessTask,
"enter_upgrade_mode_task", UPGRADE_TASK_STACK_SIZE, NULL) !=
PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
PsdkLogger_UserLogError("Psdk upgrade test task create error.");
return PSDK_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/* Private functions definition-----------------------------------------------*/
static T_PsdkReturnCode PsdkTest_EnterUpgradeMode(uint16_t *waitTime)
{
// need 10s for upgrade preprocess work.
*waitTime = PSDK_TEST_ENTER_UPGRADE_WAIT_TIME;
// enable is need enter upgrade mode process, the process is in PsdkTest_EnterUpgradeModeProcessTask
s_isNeedEnterUpgradeModeProcess = true;
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
static T_PsdkReturnCode PsdkTest_CheckFirmware(void)
{
// you can do decrypt and check firmware in this stage
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
static T_PsdkReturnCode PsdkTest_StartUpgrade(void)
{
PsdkOsal_MutexLock(s_upgradeStateMutex);
s_upgradeState.upgradeOngoingInfo.upgradeProgress = 0;
s_upgradeState.upgradeStage = PSDK_UPGRADE_STAGE_ONGOING;
PsdkOsal_MutexUnlock(s_upgradeStateMutex);
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
static T_PsdkReturnCode PsdkTest_FinishUpgrade(void)
{
PsdkOsal_MutexLock(s_upgradeStateMutex);
s_upgradeState.upgradeStage = PSDK_UPGRADE_STAGE_IDLE;
PsdkOsal_MutexUnlock(s_upgradeStateMutex);
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
#ifndef __CC_ARM
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-noreturn"
#pragma GCC diagnostic ignored "-Wreturn-type"
#endif
static void *PsdkTest_EnterUpgradeModeProcessTask(void *arg)
{
T_PsdkReturnCode returnCode;
USER_UTIL_UNUSED(arg);
while (1) {
if (s_isNeedEnterUpgradeModeProcess) {
// prepare enter upgrade mode
// you can do some thing before enter upgrade mode.
// clear upgrade program file store area
returnCode = PsdkTest_CleanUpgradeProgramFileStoreArea();
if (returnCode != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
PsdkLogger_UserLogError("Clean upgrade file dir error, please check dir permission");
}
s_isNeedEnterUpgradeModeProcess = false;
}
PsdkOsal_TaskSleepMs(1000 / PSDK_TEST_UPGRADE_TASK_FREQ);
}
}
#ifndef __CC_ARM
#pragma GCC diagnostic pop
#endif
#ifndef __CC_ARM
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-noreturn"
#pragma GCC diagnostic ignored "-Wreturn-type"
#endif
static void *PsdkTest_UpgradeProcessTask(void *arg)
{
T_PsdkUpgradeState tempUpgradeState;
T_PsdkUpgradeEndInfo upgradeEndInfo;
T_PsdkReturnCode returnCode;
USER_UTIL_UNUSED(arg);
while (1) {
PsdkOsal_MutexLock(s_upgradeStateMutex);
tempUpgradeState = s_upgradeState;
PsdkOsal_MutexUnlock(s_upgradeStateMutex);
if (tempUpgradeState.upgradeStage == PSDK_UPGRADE_STAGE_ONGOING) {
#if PSDK_TEST_REPLACE_PROGRAM_BEFORE_REBOOT
// Step 1 : Replace old program
returnCode = PsdkTest_ReplaceOldProgram();
if (returnCode != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
PsdkLogger_UserLogError("Replace firmware error, return code = 0x%08llX", returnCode);
PsdkOsal_MutexLock(s_upgradeStateMutex);
s_upgradeState.upgradeStage = PSDK_UPGRADE_STAGE_END;
s_upgradeState.upgradeEndInfo.upgradeEndState = PSDK_UPGRADE_END_STATE_UNKNOWN_ERROR;
PsdkOsal_MutexUnlock(s_upgradeStateMutex);
continue;
}
PsdkOsal_TaskSleepMs(1000);
PsdkOsal_MutexLock(s_upgradeStateMutex);
s_upgradeState.upgradeStage = PSDK_UPGRADE_STAGE_ONGOING;
s_upgradeState.upgradeOngoingInfo.upgradeProgress = 20;
PsdkUpgrade_PushUpgradeState(&s_upgradeState);
PsdkOsal_MutexUnlock(s_upgradeStateMutex);
// Step 2 : Clean upgrade program file store area
returnCode = PsdkTest_CleanUpgradeProgramFileStoreArea();
if (returnCode != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
PsdkLogger_UserLogError("Clean upgrade file dir error, please check dir permission");
PsdkOsal_MutexLock(s_upgradeStateMutex);
s_upgradeState.upgradeStage = PSDK_UPGRADE_STAGE_END;
s_upgradeState.upgradeEndInfo.upgradeEndState = PSDK_UPGRADE_END_STATE_UNKNOWN_ERROR;
PsdkOsal_MutexUnlock(s_upgradeStateMutex);
continue;
}
PsdkOsal_TaskSleepMs(1000);
PsdkOsal_MutexLock(s_upgradeStateMutex);
s_upgradeState.upgradeStage = PSDK_UPGRADE_STAGE_ONGOING;
s_upgradeState.upgradeOngoingInfo.upgradeProgress = 30;
PsdkUpgrade_PushUpgradeState(&s_upgradeState);
PsdkOsal_MutexUnlock(s_upgradeStateMutex);
#endif
//attention emulation upgrade progress, user don't need this process
do {
PsdkOsal_TaskSleepMs(1000);
PsdkOsal_MutexLock(s_upgradeStateMutex);
s_upgradeState.upgradeStage = PSDK_UPGRADE_STAGE_ONGOING;
s_upgradeState.upgradeOngoingInfo.upgradeProgress += 10;
tempUpgradeState = s_upgradeState;
PsdkUpgrade_PushUpgradeState(&s_upgradeState);
PsdkOsal_MutexUnlock(s_upgradeStateMutex);
} while (tempUpgradeState.upgradeOngoingInfo.upgradeProgress < 100);
// Step 3 : Reboot device
PsdkOsal_MutexLock(s_upgradeStateMutex);
s_upgradeState.upgradeStage = PSDK_UPGRADE_STAGE_DEVICE_REBOOT;
s_upgradeState.upgradeRebootInfo.rebootTimeout = PSDK_TEST_UPGRADE_REBOOT_TIMEOUT;
PsdkUpgrade_PushUpgradeState(&s_upgradeState);
PsdkOsal_MutexUnlock(s_upgradeStateMutex);
PsdkOsal_TaskSleepMs(1000); // sleep 1000ms to ensure push send terminal.
upgradeEndInfo.upgradeEndState = PSDK_UPGRADE_END_STATE_SUCCESS;
returnCode = PsdkTest_SetUpgradeRebootState(&upgradeEndInfo);
if (returnCode != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
PsdkLogger_UserLogError("Set Upgrade reboot state error");
PsdkOsal_MutexLock(s_upgradeStateMutex);
s_upgradeState.upgradeStage = PSDK_UPGRADE_STAGE_END;
s_upgradeState.upgradeEndInfo.upgradeEndState = PSDK_UPGRADE_END_STATE_UNKNOWN_ERROR;
PsdkOsal_MutexUnlock(s_upgradeStateMutex);
continue;
}
#if PSDK_TEST_UPGRADE_NO_REBOOT_EMU
bool isUpgradeReboot;
returnCode = PsdkTest_GetUpgradeRebootState(&isUpgradeReboot, &upgradeEndInfo);
if (returnCode != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
PsdkLogger_UserLogError("Get upgrade reboot state error");
PsdkOsal_MutexLock(s_upgradeStateMutex);
s_upgradeState.upgradeStage = PSDK_UPGRADE_STAGE_END;
s_upgradeState.upgradeEndInfo.upgradeEndState = PSDK_UPGRADE_END_STATE_UNKNOWN_ERROR;
PsdkOsal_MutexUnlock(s_upgradeStateMutex);
continue;
}
returnCode = PsdkTest_CleanUpgradeRebootState();
if (returnCode != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
PsdkLogger_UserLogError("Clean upgrade reboot state error");
PsdkOsal_MutexLock(s_upgradeStateMutex);
s_upgradeState.upgradeStage = PSDK_UPGRADE_STAGE_END;
s_upgradeState.upgradeEndInfo.upgradeEndState = PSDK_UPGRADE_END_STATE_UNKNOWN_ERROR;
PsdkOsal_MutexUnlock(s_upgradeStateMutex);
continue;
}
PsdkOsal_MutexLock(s_upgradeStateMutex);
if (isUpgradeReboot == true) {
s_upgradeState.upgradeStage = PSDK_UPGRADE_STAGE_END;
s_upgradeState.upgradeEndInfo = upgradeEndInfo;
} else {
s_upgradeState.upgradeStage = PSDK_UPGRADE_STAGE_IDLE;
}
PsdkOsal_MutexUnlock(s_upgradeStateMutex);
continue;
#else
returnCode = PsdkTest_RebootSystem();
if (returnCode != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
PsdkLogger_UserLogError("Reboot system error");
PsdkOsal_MutexLock(s_upgradeStateMutex);
s_upgradeState.upgradeStage = PSDK_UPGRADE_STAGE_END;
s_upgradeState.upgradeEndInfo.upgradeEndState = PSDK_UPGRADE_END_STATE_UNKNOWN_ERROR;
PsdkOsal_MutexUnlock(s_upgradeStateMutex);
continue;
}
while (1) {
PsdkOsal_TaskSleepMs(500);
}
#endif
} else if (s_upgradeState.upgradeStage == PSDK_UPGRADE_STAGE_END) {
PsdkOsal_MutexLock(s_upgradeStateMutex);
PsdkUpgrade_PushUpgradeState(&s_upgradeState);
PsdkOsal_MutexUnlock(s_upgradeStateMutex);
}
PsdkOsal_TaskSleepMs(500);
}
}
#ifndef __CC_ARM
#pragma GCC diagnostic pop
#endif
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,52 @@
/**
********************************************************************
* @file test_upgrade.h
* @version V2.0.0
* @date 3/4/20
* @brief This is the header file for "test_upgrade.c", defining the structure and
* (exported) function prototypes.
*
* @copyright (c) 2018-2019 DJI. All rights reserved.
*
* All information contained herein is, and remains, the property of DJI.
* The intellectual and technical concepts contained herein are proprietary
* to DJI and may be covered by U.S. and foreign patents, patents in process,
* and protected by trade secret or copyright law. Dissemination of this
* information, including but not limited to data and other proprietary
* material(s) incorporated within the information, in any form, is strictly
* prohibited without the express written consent of DJI.
*
* If you receive this source code without DJIs authorization, you may not
* further disseminate the information, and you must immediately remove the
* source code and notify DJI of its removal. DJI reserves the right to pursue
* legal actions against you for any loss(es) or damage(s) caused by your
* failure to do so.
*
*********************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef TEST_UPGRADE_H
#define TEST_UPGRADE_H
/* Includes ------------------------------------------------------------------*/
#include <psdk_upgrade.h>
#include "test_upgrade_platform_opt.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
T_PsdkReturnCode PsdkTest_UpgradeInit(const T_PsdkTestUpgradePlatformOpt *upgradePlatformOpt);
#ifdef __cplusplus
}
#endif
#endif
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,74 @@
/**
********************************************************************
* @file test_upgrade_common.h
* @version V2.0.0
* @date 3/12/20
* @brief This is the header file for "test_upgrade_linux_common.c", defining the structure and
* (exported) function prototypes.
*
* @copyright (c) 2018-2019 DJI. All rights reserved.
*
* All information contained herein is, and remains, the property of DJI.
* The intellectual and technical concepts contained herein are proprietary
* to DJI and may be covered by U.S. and foreign patents, patents in process,
* and protected by trade secret or copyright law. Dissemination of this
* information, including but not limited to data and other proprietary
* material(s) incorporated within the information, in any form, is strictly
* prohibited without the express written consent of DJI.
*
* If you receive this source code without DJIs authorization, you may not
* further disseminate the information, and you must immediately remove the
* source code and notify DJI of its removal. DJI reserves the right to pursue
* legal actions against you for any loss(es) or damage(s) caused by your
* failure to do so.
*
*********************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef TEST_UPGRADE_COMMON_H
#define TEST_UPGRADE_COMMON_H
/* Includes ------------------------------------------------------------------*/
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
// firmware version
#define PSDK_TEST_FIRMWARE_VERSION_MAJOR 2
#define PSDK_TEST_FIRMWARE_VERSION_MINOR 1
#define PSDK_TEST_FIRMWARE_VERSION_MODIFY 0
#define PSDK_TEST_FIRMWARE_VERSION_DEBUG 3
// define if only emulate upgrade, no system reboot
#define PSDK_TEST_UPGRADE_NO_REBOOT_EMU 0
#if PSDK_ARCH_SYS_LINUX
// define if replace program before reboot
#define PSDK_TEST_REPLACE_PROGRAM_BEFORE_REBOOT 1
// define if use ftp transfer, only support linux
#define PSDK_TEST_UPGRADE_USE_FTP_TRANSFER 1
#else
// for mcu, program is on flash , need replace program in loader, not before reboot
#define PSDK_TEST_REPLACE_PROGRAM_BEFORE_REBOOT 0
// define if use ftp transfer
#define PSDK_TEST_UPGRADE_USE_FTP_TRANSFER 0
#endif
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
#ifdef __cplusplus
}
#endif
#endif // TEST_UPGRADE_LINUX_COMMON_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,151 @@
/**
********************************************************************
* @file test_upgrade_common_file_transfer.c
* @version V2.0.0
* @date 3/12/20
* @brief
*
* @copyright (c) 2018-2019 DJI. All rights reserved.
*
* All information contained herein is, and remains, the property of DJI.
* The intellectual and technical concepts contained herein are proprietary
* to DJI and may be covered by U.S. and foreign patents, patents in process,
* and protected by trade secret or copyright law. Dissemination of this
* information, including but not limited to data and other proprietary
* material(s) incorporated within the information, in any form, is strictly
* prohibited without the express written consent of DJI.
*
* If you receive this source code without DJIs authorization, you may not
* further disseminate the information, and you must immediately remove the
* source code and notify DJI of its removal. DJI reserves the right to pursue
* legal actions against you for any loss(es) or damage(s) caused by your
* failure to do so.
*
*********************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "test_upgrade_common_file_transfer.h"
#include "psdk_logger.h"
#include <utils/util_md5.h>
#include "test_upgrade_platform_opt.h"
/* Private constants ---------------------------------------------------------*/
#define PSDK_TEST_FILE_MD5_BUFFER_SIZE 256
/* Private types -------------------------------------------------------------*/
/* Private values -------------------------------------------------------------*/
static T_PsdkUpgradeFileInfo s_upgradeFileInfo = {0};
static uint32_t s_alreadyTransferFileSize = 0;
/* Private functions declaration ---------------------------------------------*/
static T_PsdkReturnCode PsdkTestFile_GetUpgradeFileMd5(uint8_t md5[PSDK_MD5_BUFFER_LEN]);
/* Exported functions definition ---------------------------------------------*/
T_PsdkReturnCode PsdkTestCommonFileTransfer_Start(const T_PsdkUpgradeFileInfo *fileInfo)
{
T_PsdkReturnCode returnCode;
s_upgradeFileInfo.fileSize = 0;
memset(s_upgradeFileInfo.fileName, 0, sizeof(s_upgradeFileInfo.fileName));
s_alreadyTransferFileSize = 0;
returnCode = PsdkTest_CreateUpgradeProgramFile(fileInfo);
if (returnCode != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
PsdkLogger_UserLogError("Create upgrade program file error");
return returnCode;
}
s_upgradeFileInfo = *fileInfo;
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_PsdkReturnCode PsdkTestCommonFileTransfer_Transfer(const uint8_t *data, uint16_t dataLen)
{
T_PsdkReturnCode returnCode;
if (s_alreadyTransferFileSize >= s_upgradeFileInfo.fileSize) {
PsdkLogger_UserLogError("Already transfer file size is more than file real size");
return PSDK_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
returnCode = PsdkTest_WriteUpgradeProgramFile(s_alreadyTransferFileSize, data, dataLen);
if (returnCode != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
PsdkLogger_UserLogError("Write upgrade program file error, return code = 0x%08llX", returnCode);
return PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
s_alreadyTransferFileSize += dataLen;
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_PsdkReturnCode PsdkTestCommonFileTransfer_Finish(const uint8_t md5[PSDK_MD5_BUFFER_LEN])
{
uint8_t localFileMd5[PSDK_MD5_BUFFER_LEN] = {0};
T_PsdkReturnCode returnCode;
if (s_alreadyTransferFileSize != s_upgradeFileInfo.fileSize) {
PsdkLogger_UserLogError("Transfer finish error, transfer file size is not equal");
return PSDK_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
returnCode = PsdkTestFile_GetUpgradeFileMd5(localFileMd5);
if (returnCode != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
PsdkLogger_UserLogError("Get file md5 error, return code = 0x%08llX", returnCode);
goto out;
}
if (memcmp(md5, localFileMd5, PSDK_MD5_BUFFER_LEN) == 0) {
returnCode = PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
} else {
returnCode = PSDK_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
out:
PsdkTest_CloseUpgradeProgramFile();
s_upgradeFileInfo.fileSize = 0;
memset(s_upgradeFileInfo.fileName, 0, sizeof(s_upgradeFileInfo.fileName));
s_alreadyTransferFileSize = 0;
return returnCode;
}
/* Private functions definition-----------------------------------------------*/
static T_PsdkReturnCode PsdkTestFile_GetUpgradeFileMd5(uint8_t md5[PSDK_MD5_BUFFER_LEN])
{
uint8_t fileBuffer[PSDK_TEST_FILE_MD5_BUFFER_SIZE] = {0};
T_PsdkReturnCode returnCode;
uint32_t offset;
MD5_CTX fileMd5Ctx;
uint16_t realLen = 0;
offset = 0;
UtilMd5_Init(&fileMd5Ctx);
while (s_upgradeFileInfo.fileSize - offset > PSDK_TEST_FILE_MD5_BUFFER_SIZE) {
returnCode = PsdkTest_ReadUpgradeProgramFile(offset, PSDK_TEST_FILE_MD5_BUFFER_SIZE,
fileBuffer, &realLen);
if (returnCode != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS || realLen != PSDK_TEST_FILE_MD5_BUFFER_SIZE) {
PsdkLogger_UserLogError("Get file data error, return code = 0x%08llX", returnCode);
return returnCode;
}
UtilMd5_Update(&fileMd5Ctx, fileBuffer, PSDK_TEST_FILE_MD5_BUFFER_SIZE);
offset += PSDK_TEST_FILE_MD5_BUFFER_SIZE;
}
returnCode = PsdkTest_ReadUpgradeProgramFile(offset, s_upgradeFileInfo.fileSize - offset, fileBuffer, &realLen);
if (returnCode != PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS || realLen != s_upgradeFileInfo.fileSize - offset) {
PsdkLogger_UserLogError("Get file data error, return code = 0x%08llX", returnCode);
return returnCode;
}
UtilMd5_Update(&fileMd5Ctx, fileBuffer, s_upgradeFileInfo.fileSize - offset);
UtilMd5_Final(&fileMd5Ctx, md5);
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,53 @@
/**
********************************************************************
* @file test_upgrade_common_file_transfer.h
* @version V2.0.0
* @date 3/12/20
* @brief This is the header file for "test_upgrade_common_file_transfer.c", defining the structure and
* (exported) function prototypes.
*
* @copyright (c) 2018-2019 DJI. All rights reserved.
*
* All information contained herein is, and remains, the property of DJI.
* The intellectual and technical concepts contained herein are proprietary
* to DJI and may be covered by U.S. and foreign patents, patents in process,
* and protected by trade secret or copyright law. Dissemination of this
* information, including but not limited to data and other proprietary
* material(s) incorporated within the information, in any form, is strictly
* prohibited without the express written consent of DJI.
*
* If you receive this source code without DJIs authorization, you may not
* further disseminate the information, and you must immediately remove the
* source code and notify DJI of its removal. DJI reserves the right to pursue
* legal actions against you for any loss(es) or damage(s) caused by your
* failure to do so.
*
*********************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef TEST_UPGRADE_COMMON_FILE_TRANSFER_H
#define TEST_UPGRADE_COMMON_FILE_TRANSFER_H
/* Includes ------------------------------------------------------------------*/
#include <psdk_upgrade.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
T_PsdkReturnCode PsdkTestCommonFileTransfer_Start(const T_PsdkUpgradeFileInfo *fileInfo);
T_PsdkReturnCode PsdkTestCommonFileTransfer_Transfer(const uint8_t *data, uint16_t dataLen);
T_PsdkReturnCode PsdkTestCommonFileTransfer_Finish(const uint8_t md5[PSDK_MD5_BUFFER_LEN]);
#ifdef __cplusplus
}
#endif
#endif // TEST_UPGRADE_COMMON_FILE_TRANSFER_LINUX_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/

View File

@ -0,0 +1,141 @@
/**
********************************************************************
* @file test_upgrade_platform_opt.c
* @version V1.0.0
* @date 2019/01/01
* @brief
*
* @copyright (c) 2017-2018 DJI. All rights reserved.
*
* All information contained herein is, and remains, the property of DJI.
* The intellectual and technical concepts contained herein are proprietary
* to DJI and may be covered by U.S. and foreign patents, patents in process,
* and protected by trade secret or copyright law. Dissemination of this
* information, including but not limited to data and other proprietary
* material(s) incorporated within the information, in any form, is strictly
* prohibited without the express written consent of DJI.
*
* If you receive this source code without DJIs authorization, you may not
* further disseminate the information, and you must immediately remove the
* source code and notify DJI of its removal. DJI reserves the right to pursue
* legal actions against you for any loss(es) or damage(s) caused by your
* failure to do so.
*
*********************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "test_upgrade_platform_opt.h"
#include <psdk_logger.h>
/* Private constants ---------------------------------------------------------*/
/* Private types -------------------------------------------------------------*/
/* Private values -------------------------------------------------------------*/
static T_PsdkTestUpgradePlatformOpt s_upgradePlatformOpt = {0};
/* Private functions declaration ---------------------------------------------*/
/* Exported functions definition ---------------------------------------------*/
T_PsdkReturnCode PsdkTest_RegUpgradePlatformOpt(const T_PsdkTestUpgradePlatformOpt *upgradePlatformOpt)
{
if (upgradePlatformOpt->rebootSystem == NULL) {
PsdkLogger_UserLogError("rebootSystem callback can't be NULL");
return PSDK_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
if (upgradePlatformOpt->cleanUpgradeProgramFileStoreArea == NULL) {
PsdkLogger_UserLogError("cleanUpgradeProgramFileStoreArea callback can't be NULL");
return PSDK_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
if (upgradePlatformOpt->createUpgradeProgramFile == NULL) {
PsdkLogger_UserLogError("createUpgradeProgramFile callback can't be NULL");
return PSDK_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
if (upgradePlatformOpt->readUpgradeProgramFile == NULL) {
PsdkLogger_UserLogError("readUpgradeProgramFile callback can't be NULL");
return PSDK_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
if (upgradePlatformOpt->writeUpgradeProgramFile == NULL) {
PsdkLogger_UserLogError("writeUpgradeProgramFile callback can't be NULL");
return PSDK_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
if (upgradePlatformOpt->closeUpgradeProgramFile == NULL) {
PsdkLogger_UserLogError("closeUpgradeProgramFile callback can't be NULL");
return PSDK_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
if (upgradePlatformOpt->replaceOldProgram == NULL) {
PsdkLogger_UserLogError("replaceOldProgram callback can't be NULL");
return PSDK_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
if (upgradePlatformOpt->setUpgradeRebootState == NULL) {
PsdkLogger_UserLogError("setUpgradeRebootState callback can't be NULL");
return PSDK_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
if (upgradePlatformOpt->getUpgradeRebootState == NULL) {
PsdkLogger_UserLogError("getUpgradeRebootState callback can't be NULL");
return PSDK_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
if (upgradePlatformOpt->cleanUpgradeRebootState == NULL) {
PsdkLogger_UserLogError("cleanUpgradeRebootState callback can't be NULL");
return PSDK_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
s_upgradePlatformOpt = *upgradePlatformOpt;
return PSDK_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_PsdkReturnCode PsdkTest_RebootSystem(void)
{
return s_upgradePlatformOpt.rebootSystem();
}
T_PsdkReturnCode PsdkTest_CleanUpgradeProgramFileStoreArea(void)
{
return s_upgradePlatformOpt.cleanUpgradeProgramFileStoreArea();
}
T_PsdkReturnCode PsdkTest_CreateUpgradeProgramFile(const T_PsdkUpgradeFileInfo *fileInfo)
{
return s_upgradePlatformOpt.createUpgradeProgramFile(fileInfo);
}
T_PsdkReturnCode PsdkTest_WriteUpgradeProgramFile(uint32_t offset, const uint8_t *data, uint16_t dataLen)
{
return s_upgradePlatformOpt.writeUpgradeProgramFile(offset, data, dataLen);
}
T_PsdkReturnCode PsdkTest_ReadUpgradeProgramFile(uint32_t offset, uint16_t readDataLen, uint8_t *data,
uint16_t *realLen)
{
return s_upgradePlatformOpt.readUpgradeProgramFile(offset, readDataLen, data, realLen);
}
T_PsdkReturnCode PsdkTest_CloseUpgradeProgramFile(void)
{
return s_upgradePlatformOpt.closeUpgradeProgramFile();
}
T_PsdkReturnCode PsdkTest_ReplaceOldProgram(void)
{
return s_upgradePlatformOpt.replaceOldProgram();
}
T_PsdkReturnCode PsdkTest_SetUpgradeRebootState(const T_PsdkUpgradeEndInfo *upgradeEndInfo)
{
return s_upgradePlatformOpt.setUpgradeRebootState(upgradeEndInfo);
}
T_PsdkReturnCode PsdkTest_GetUpgradeRebootState(bool *isUpgradeReboot, T_PsdkUpgradeEndInfo *upgradeEndInfo)
{
return s_upgradePlatformOpt.getUpgradeRebootState(isUpgradeReboot, upgradeEndInfo);
}
T_PsdkReturnCode PsdkTest_CleanUpgradeRebootState(void)
{
return s_upgradePlatformOpt.cleanUpgradeRebootState();
}
/****************** (C) COPYRIGHT DJI Innovations *****END OF FILE****/

View File

@ -0,0 +1,86 @@
/**
********************************************************************
* @file test_upgrade_platform_opt.h
* @version V0.0.0
* @date 2019/01/01
* @brief This is the header file for "test_upgrade_platform_opt.c", defining the structure and
* (exported) function prototypes.
*
* @copyright (c) 2017-2018 DJI. All rights reserved.
*
* All information contained herein is, and remains, the property of DJI.
* The intellectual and technical concepts contained herein are proprietary
* to DJI and may be covered by U.S. and foreign patents, patents in process,
* and protected by trade secret or copyright law. Dissemination of this
* information, including but not limited to data and other proprietary
* material(s) incorporated within the information, in any form, is strictly
* prohibited without the express written consent of DJI.
*
* If you receive this source code without DJIs authorization, you may not
* further disseminate the information, and you must immediately remove the
* source code and notify DJI of its removal. DJI reserves the right to pursue
* legal actions against you for any loss(es) or damage(s) caused by your
* failure to do so.
*
*********************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef TEST_UPGRADE_PLATFORM_OPT_H
#define TEST_UPGRADE_PLATFORM_OPT_H
#include <psdk_typedef.h>
#include <psdk_upgrade.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
typedef struct {
T_PsdkReturnCode (*rebootSystem)(void);
T_PsdkReturnCode (*cleanUpgradeProgramFileStoreArea)(void);
T_PsdkReturnCode (*createUpgradeProgramFile)(const T_PsdkUpgradeFileInfo *fileInfo);
T_PsdkReturnCode (*writeUpgradeProgramFile)(uint32_t offset, const uint8_t *data, uint16_t dataLen);
T_PsdkReturnCode (*readUpgradeProgramFile)(uint32_t offset, uint16_t readDataLen, uint8_t *data,
uint16_t *realLen);
T_PsdkReturnCode (*closeUpgradeProgramFile)(void);
T_PsdkReturnCode (*replaceOldProgram)(void);
T_PsdkReturnCode (*setUpgradeRebootState)(const T_PsdkUpgradeEndInfo *upgradeEndInfo);
T_PsdkReturnCode (*getUpgradeRebootState)(bool *isUpgradeReboot, T_PsdkUpgradeEndInfo *upgradeEndInfo);
T_PsdkReturnCode (*cleanUpgradeRebootState)(void);
} T_PsdkTestUpgradePlatformOpt;
/* Exported functions --------------------------------------------------------*/
T_PsdkReturnCode PsdkTest_RegUpgradePlatformOpt(const T_PsdkTestUpgradePlatformOpt *upgradePlatformOpt);
T_PsdkReturnCode PsdkTest_RebootSystem(void);
T_PsdkReturnCode PsdkTest_CleanUpgradeProgramFileStoreArea(void);
T_PsdkReturnCode PsdkTest_CreateUpgradeProgramFile(const T_PsdkUpgradeFileInfo *fileInfo);
T_PsdkReturnCode PsdkTest_WriteUpgradeProgramFile(uint32_t offset, const uint8_t *data, uint16_t dataLen);
T_PsdkReturnCode PsdkTest_ReadUpgradeProgramFile(uint32_t offset, uint16_t readDataLen, uint8_t *data,
uint16_t *realLen);
T_PsdkReturnCode PsdkTest_CloseUpgradeProgramFile(void);
T_PsdkReturnCode PsdkTest_ReplaceOldProgram(void);
T_PsdkReturnCode PsdkTest_SetUpgradeRebootState(const T_PsdkUpgradeEndInfo *upgradeEndInfo);
T_PsdkReturnCode PsdkTest_GetUpgradeRebootState(bool *isUpgradeReboot, T_PsdkUpgradeEndInfo *upgradeEndInfo);
T_PsdkReturnCode PsdkTest_CleanUpgradeRebootState(void);
#ifdef __cplusplus
}
#endif
#endif // TEST_UPGRADE_PLATFORM_OPT_H
/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/