作者 ookk303

修改了zy部分内容

正在显示 29 个修改的文件 包含 2015 行增加51 行删除
... ... @@ -3,8 +3,11 @@
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/linux_kernel/include/**"
"${workspaceFolder}/JZsdk_Common/**",
"${workspaceFolder}/JZsdk_Config/**",
"${workspaceFolder}/JZsdk_hal/**",
"${workspaceFolder}/Module/**",
//"${workspaceFolder}/linux_kernel/include/**"
],
"defines": [
"_DEBUG",
... ... @@ -12,7 +15,8 @@
"_UNICODE"
],
"cStandard": "c99",
"intelliSenseMode": "${default}"
//"intelliSenseMode": "${default}"
"intelliSenseMode": "${Tag Parser}"
}
],
"version": 4
... ...
... ... @@ -172,7 +172,9 @@
"ifybak3": "c",
"jz_h150a.h": "c",
"jzsdk_framesequencequeue.h": "c",
"searchlighttemcontrol.h": "c"
"searchlighttemcontrol.h": "c",
"*.bak已改好": "c",
"ziyan_platform.h": "c"
},
"Codegeex.GenerationPreference": "automatic",
"C_Cpp.dimInactiveRegions": false,
... ...
... ... @@ -155,6 +155,7 @@ typedef enum {
JZ_INSCODE_5AFRAME_SEARCHLIGHT_MESSAGE_SUBSCRIPTION_CONTROL = 0x10000E21,//探照灯消息订阅控制
JZ_INSCODE_5AFRAME_WARNINGLIGHT_CONTROL = 0x10000F00, //警示灯模式控制
JZ_INSCODE_5AFRAME_WARNINGLIGHT_CONTROL_2 = 0x10000F01, //警示灯模式控制2
JZ_INSCODE_5AFRAME_WARNINGLIGHT_COLOUR = 0x10000F10, //警示灯颜色控制
JZ_INSCODE_5AFRAME_OUTPUTPOWER_CONTROL = 0x10001000, //对外供电开关
... ...
... ... @@ -193,6 +193,15 @@ int JZsdk_GetFrameTemplate(int InsCode ,char *str, int *str_len)
}
break;
case JZ_INSCODE_5AFRAME_WARNINGLIGHT_CONTROL_2:
{
char sendbuf[12] = {0x5A ,0x5A ,0x77 ,0x00 ,0x0C ,0x00 ,0x00 ,0x66 ,0x52 ,0x00 ,0x00 ,0x23};
memcpy(str, sendbuf, 12);
*str_len = 12;
}
break;
case JZ_INSCODE_5AFRAME_WARNINGLIGHT_COLOUR:
{
char sendbuf[13] = {0x5A ,0x5A ,0x77 ,0x00 ,0x0D ,0x00 ,0x00 ,0x67 ,0x51 ,0x00 ,0x00 ,0x00 ,0x23};
... ...
... ... @@ -71,21 +71,45 @@ static T_JZsdkReturnCode JZsdk_Check_Src32(unsigned char *DIR, unsigned char *ch
static T_JZsdkReturnCode JZsdk_Check_Md5(unsigned char *DIR, unsigned char *checksum, unsigned int checksum_len)
{
T_JZsdkReturnCode ret = JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
// 验证输入有效性
if (!DIR || !checksum || checksum_len != 32) {
JZSDK_LOG_ERROR("无效的输入参数");
return JZ_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
//1、获取文件的md5校验码
unsigned char cmd[256];
unsigned char md5[32];
unsigned char raw_output[128] = {0}; // 存储完整命令行输出
unsigned char md5[33];
memset(cmd,0,sizeof(cmd));
snprintf(cmd, sizeof(cmd), "md5sum %s", DIR);
JZsdk_RunSystemCmd_ReturnResult_Str(cmd, md5);
// 构造安全命令
snprintf(cmd, sizeof(cmd), "md5sum '%.200s'", DIR);
// 执行命令获取输出
if (JZsdk_RunSystemCmd_ReturnResult_Str(cmd, raw_output, sizeof(raw_output))
!= JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE;
}
// 提取MD5部分 (格式: "d41d8cd98f00b204e9800998ecf8427e filename")
if (sscanf((const char*)raw_output, "%32s", md5) != 1) {
JZSDK_LOG_ERROR("MD5解析失败: %s", raw_output);
return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE;
}
JZSDK_LOG_INFO("md5校验 原校验码:%s 下载文件校验码:%s", checksum, md5);
//对比校验码
if (memcmp(md5, checksum, 21) != 0)
if (memcmp(md5, checksum, 32) != 0)
{
JZSDK_LOG_ERROR("checksum error\n");
return JZ_ERROR_SYSTEM_MODULE_CODE_CHECK_CODE_ERROR;
}
JZSDK_LOG_INFO("md5 checksum success\n");
return ret;
}
... ...
... ... @@ -82,25 +82,22 @@ T_JZsdkReturnCode JZsdk_RunSystemCmd_ReturnResult(char *systemCmd, unsigned int
运行命令 并读取返回值
*/
T_JZsdkReturnCode JZsdk_RunSystemCmd_ReturnResult_Str(char *systemCmd, unsigned char *str)
T_JZsdkReturnCode JZsdk_RunSystemCmd_ReturnResult_Str(const char *systemCmd, unsigned char *buffer, int buf_size)
{
FILE *fp;
double temp = 0;
FILE *fp = popen(systemCmd, "r");
if (!fp) {
JZSDK_LOG_ERROR("执行命令失败: %s", systemCmd);
return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE;
}
fp = popen(systemCmd, "r");
if (fp == NULL) {
printf("Failed to run command\n");
return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE;
// 安全读取单行输出
if (!fgets((char*)buffer, buf_size, fp)) {
JZSDK_LOG_ERROR("命令无输出: %s", systemCmd);
pclose(fp);
return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE;
}
// 读取命令的输出
while (fgets(str, sizeof(str)-1, fp) != NULL)
{
printf("%s", str);
}
pclose(fp);
return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
... ...
... ... @@ -92,7 +92,7 @@ T_JZsdkReturnCode JZsdk_check_directory_exists_posix(const char* directory_path)
T_JZsdkReturnCode JZsdk_Fs_ReadFileSize(const unsigned char* FilePath, int *FileSize);
T_JZsdkReturnCode JZsdk_copy_file_byC(const char* source_path, const char* dest_path);
T_JZsdkReturnCode JZsdk_RunSystemCmd_ReturnResult(char *systemCmd, unsigned int *result);
T_JZsdkReturnCode JZsdk_RunSystemCmd_ReturnResult_Str(char *systemCmd, unsigned char *str);
T_JZsdkReturnCode JZsdk_RunSystemCmd_ReturnResult_Str(const char *systemCmd, unsigned char *buffer, int buf_size);
T_JZsdkReturnCode JZsdk_Sync();
T_JZsdkReturnCode JZsdk_Osal_Stat(const char *filePath, T_JZsdkFileInfo *fileInfo);
T_JZsdkReturnCode JZsdk_Osal_Rename(const char *oldFilePath, const char *newFilePath);
... ...
... ... @@ -337,9 +337,9 @@ T_JZsdkReturnCode JZ_T40_init(int mode)
.Device = UART_DEV_2,
.FrameSequence = 0x20,
};
//警灯模块初始化
WarnLight_Init(WarnLightInfo);
//激光初始化
SideLaser_Init();
... ...
... ... @@ -10,20 +10,20 @@
#define DEVICE_VERSION JZ_H150A
//禁止修改行 选择是串口程序 还是 psdk程序
#define APP_VERSION APP_UART
#define APP_VERSION APP_PSDK
//禁止修改行 板子型号
#define PLATFORM_VERSION PLATFORM_V3S
//禁止修改行 串口连接程序的软件版本号
#define MAJOR_VERSION_TEN_POSITION 0
#define MAJOR_VERSION_ONE_POSITION 0
#define MAJOR_VERSION_ONE_POSITION 2
#define MINOR_VERSION_TEN_POSITION 0
#define MINOR_VERSION_ONE_POSITION 0
#define MINOR_VERSION_ONE_POSITION 1
#define MODIFY_VERSION_TEN_POSITION 0
#define MODIFY_VERSION_ONE_POSITION 2
#define DEBUG_VERSION_TEN_POSITION 2
#define DEBUG_VERSION_ONE_POSITION 2
#define MODIFY_VERSION_ONE_POSITION 1
#define DEBUG_VERSION_TEN_POSITION 0
#define DEBUG_VERSION_ONE_POSITION 0
... ...
... ... @@ -665,6 +665,7 @@ static T_JZsdkReturnCode RecvDeal_SaveAudioFileTrans_stop_and_check(int Port, ch
int FrameSequence = JZsdk_Get_FrameSequence(getbuf);
unsigned char checkCode[128];
memset(checkCode, 0, 128);
int frameLenth = ((int)getbuf[3]) << 8 | (int)getbuf[4];
int CodeLenth = frameLenth - 10 - 2;
if (CodeLenth != 0)
... ... @@ -1093,10 +1094,23 @@ static T_JZsdkReturnCode RecvDeal_CheckStatus_AudioDetailMessage(int Port, char
}
//获取文件的md5码
unsigned char md5[16];
unsigned char cmd[256];
unsigned char raw_output[128] = {0}; // 存储完整命令行输出
unsigned char md5[33];
memset(cmd,0,sizeof(cmd));
snprintf(cmd, sizeof(cmd), "md5sum /root/sdcard/audio/%s", AudioDetailMessage.FileName);
JZsdk_RunSystemCmd_ReturnResult_Str(cmd, md5);
// 执行命令获取输出
if (JZsdk_RunSystemCmd_ReturnResult_Str(cmd, raw_output, sizeof(raw_output))
!= JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE;
}
// 提取MD5部分 (格式: "d41d8cd98f00b204e9800998ecf8427e filename")
if (sscanf((const char*)raw_output, "%32s", md5) != 1) {
JZSDK_LOG_ERROR("MD5解析失败: %s", raw_output);
}
//3、发送歌曲详细信息
// JZSDK_LOG_INFO("即将发送%s, %d, %d, %s",
... ... @@ -2397,6 +2411,7 @@ static T_JZsdkReturnCode RecvDeal_OpusTrans_stop_and_check(int Port, char *getbu
unsigned char checkCode[128];
memset(checkCode, 0, 128);
int frameLenth = ((int)getbuf[3]) << 8 | (int)getbuf[4];
int CodeLenth = frameLenth - 10 - 2;
if (CodeLenth != 0)
... ... @@ -4074,6 +4089,12 @@ static T_JZsdkReturnCode RecvDeal_ObtainTimeStamp(int Port, unsigned char *getbu
| ((uint64_t)getbuf[12] << 32) | ((uint64_t)getbuf[11] << 40)
| ((uint64_t)getbuf[10] << 48) | ((uint64_t)getbuf[9] << 56));
// 打印原始字节数据
// JZSDK_LOG_INFO("原始数据 [9-16]:");
// for (int i = 9; i <= 16; i++) {
// JZSDK_LOG_INFO(" getbuf[%d] = 0x%02X", i, (unsigned char)getbuf[i]);
// }
JZSDK_LOG_INFO("获得时间戳 %llu",TimeStamp);
// 转换为time_t(注意:这里假设TimeStamp是以秒为单位的Unix时间戳)
... ... @@ -4089,11 +4110,15 @@ static T_JZsdkReturnCode RecvDeal_ObtainTimeStamp(int Port, unsigned char *getbu
}
// 提取年、月、日
int year = tm_info->tm_year + 1980; // 注意:tm_year是从1980年开始的
int year = tm_info->tm_year + 1900;
int month = tm_info->tm_mon + 1; // 注意:tm_mon是从0开始的(0=1月,11=12月)
int day = tm_info->tm_mday + 6;
int day = tm_info->tm_mday;
int hour = tm_info->tm_hour;
int minute = tm_info->tm_min;
int second = tm_info->tm_sec;
JZSDK_LOG_INFO("获得年份: %d, 月份: %d, 日期: %d", year, month, day);
JZSDK_LOG_INFO("获得小时: %d, 分钟: %d, 秒: %d", hour, minute, second);
struct timeval tv;
tv.tv_sec = (time_t)TimeStamp; // 注意:这里可能会有截断,如果TimeStamp非常大
... ...
... ... @@ -1456,6 +1456,29 @@ T_JZsdkReturnCode HalSend_type1Send_Set_WarningLight_Status(int Uartport, int fr
/*************
*
* 设置警灯状态类型Ⅱ
*
* ************/
T_JZsdkReturnCode HalSend_type1Send_Set_WarningLight_Status_2(int Uartport, int frameSequence, int mode)
{
printf("发送设置警灯状态 类型2\n");
unsigned char sendbuf[256];
int send_buf_len;
//1、获取帧样板
JZsdk_GetFrameTemplate(JZ_INSCODE_5AFRAME_WARNINGLIGHT_CONTROL_2, sendbuf, &send_buf_len);
//2、写入数据
sendbuf[6] = frameSequence;
sendbuf[9] = mode;
//3、发送帧
HalSend_SendData(Uartport ,sendbuf, send_buf_len, MULTI_THREAD_SEND);
}
/*************
*
* 设置警灯颜色
*
* **************/
... ...
... ... @@ -25,8 +25,10 @@ T_JZsdkReturnCode DebugInfo_Init()
return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
#endif
if (JZsdk_check_file_exists("/root/ShakedownTest") != JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
{
JZSDK_LOG_DEBUG("未存在调试文件");
return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
... ... @@ -38,7 +40,6 @@ T_JZsdkReturnCode DebugInfo_Init()
JZSDK_LOG_ERROR("移除调试模式失败");
}
return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
... ... @@ -60,7 +61,7 @@ T_JZsdkReturnCode DebugInfo_ModeSet(int mode)
return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
if (mode == JZ_FLAGCODE_OFF)
else if (mode == JZ_FLAGCODE_OFF)
{
if(JZsdk_Osal_delete("/root/ShakedownTest") == JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS)
{
... ...
... ... @@ -826,6 +826,7 @@ T_JZsdkReturnCode AudioFile_SaveAudioFileStop(int checkFlag, unsigned char *Chec
fflush(g_AudioFile_SaveAudioFile_NameFp);
fclose(g_AudioFile_SaveAudioFile_NameFp);
g_AudioFile_SaveAudioFile_NameFp = NULL;
JZSDK_LOG_INFO("传输得到的音频大小为:%d", g_AudioFile_SaveAudioFile_len);
g_AudioFile_SaveAudioFile_len = 0; //置零长度
JZsdk_Sync();
... ...
... ... @@ -34,7 +34,15 @@ T_JZsdkReturnCode WarnLight_Set_StatusAndMode(int status, int mode)
U8_t FrameSequence = g_WarnLightInfo.FrameSequence;
osalHandle->GetFrameSequenceQueueNum(&FrameSequence);
HalSend_type1Send_Set_WarningLight_Status(g_WarnLightInfo.Device, FrameSequence, status, mode);
//模式版本
if(g_WarnLightInfo.mode_version == 0)
{
HalSend_type1Send_Set_WarningLight_Status(g_WarnLightInfo.Device, FrameSequence, status, mode);
}
else if(g_WarnLightInfo.mode_version == 1)
{
}
g_WarnLightInfo.Attribute.mode = mode;
g_WarnLightInfo.Attribute.status = status;
... ...
... ... @@ -23,7 +23,7 @@ extern "C" {
/* Exported types ------------------------------------------------------------*/
typedef struct T_JzWarnLightAttribute{
int mode; //模式
int mode_version; //模式的版本
int status; //状态
int Color1; //颜色1
int Color2; //颜色2
... ... @@ -53,6 +53,14 @@ typedef enum E_JzWarnLightMode{
E_JZ_WARNLIGHT_MODE_SIMULTANEOUS_SLOW_FALSHING = 4, //同时慢速闪烁
}E_JzWarnLightMode;
typedef enum E_JzWarnLightMode2{
E_JZ_WARNLIGHT_MODE_2_RED_BULE_WARN = 1, //红蓝警示模式
E_JZ_WARNLIGHT_MODE_2_YELLOW_WARN = 2, //黄闪减速模式
E_JZ_WARNLIGHT_MODE_2_RED_WARN = 3, //红闪停车模式
E_JZ_WARNLIGHT_MODE_2_GREEN_WARN = 4, //绿闪通行模式
E_JZ_WARNLIGHT_MODE_2_RAINBOW_WARN = 5, //彩色闪烁模式
}E_JzWarnLightMode2;
/* Exported functions --------------------------------------------------------*/
T_JZsdkReturnCode WarnLight_Set_StatusAndMode(int status, int mode);
T_JZsdkReturnCode WarnLight_Set_Color(int Color1, int Color2);
... ...
... ... @@ -37,7 +37,7 @@ extern "C" {
#define DJI_VERSION_MINOR 12 /*!< DJI SDK minor version num, when add functionality in a backwards compatible manner changes. Range from 0 to 99. */
#define DJI_VERSION_MODIFY 0 /*!< DJI SDK modify version num, when have backwards compatible bug fixes changes. Range from 0 to 99. */
#define DJI_VERSION_BETA 0 /*!< DJI SDK version beta info, release version will be 0, when beta version release changes. Range from 0 to 255. */
#define DJI_VERSION_BUILD 2254 /*!< DJI SDK version build info, when jenkins trigger build changes. Range from 0 to 65535. */
#define DJI_VERSION_BUILD 2257 /*!< DJI SDK version build info, when jenkins trigger build changes. Range from 0 to 65535. */
/* Exported types ------------------------------------------------------------*/
... ...
... ... @@ -52,6 +52,18 @@
#endif
#ifdef WARNLIGHT_STATUS_ON
#include "WarnLight/WarnLight.h"
#endif
#ifdef SEARCHLIGHT_STATUS_ON
#include "SearchLight/SearchLight.h"
#endif
#include "MediaProc/MediaProc.h"
#include "DeviceInfo/DeviceInfo.h"
... ... @@ -156,14 +168,7 @@ static const T_DjiWidgetHandlerListItem s_widgetHandlerList[] = {
};
static const uint32_t s_widgetHandlerListCount = sizeof(s_widgetHandlerList) / sizeof(T_DjiWidgetHandlerListItem);
int32_t s_widgetValueList[] = { OFF, OFF, PLAY_PAUSE, 30, 30, PLAY_SPEED_X1, 0, OFF,OFF,OFF, //喊话器部分
OFF, OFF, OFF, OFF, 50, OFF, //探照灯部分
0, 0, 2, //警灯部分
100, 100 ,ON ,OFF,OFF, //云台部分
OFF ,OFF, //系统部分
OFF,OFF, //调试部分
0,0,
0,0,0,0}; //调试部分
int32_t s_widgetValueList[s_widgetHandlerListCount = sizeof(s_widgetHandlerList) / sizeof(T_DjiWidgetHandlerListItem)] = {0};
#endif
... ... @@ -203,7 +208,58 @@ static const T_DjiWidgetHandlerListItem s_widgetHandlerList[] = {
};
static const uint32_t s_widgetHandlerListCount = sizeof(s_widgetHandlerList) / sizeof(T_DjiWidgetHandlerListItem);
int32_t s_widgetValueList[] = {VIDEOMGMT_STREAMING_FLOW_INDEX_FIRST, //视频流
int32_t s_widgetValueList[sizeof(s_widgetHandlerList) / sizeof(T_DjiWidgetHandlerListItem)] = {0};
#endif
static T_JZsdkReturnCode WidgetRead()
{
//将设备里的控件值读到控件结构体中
int WidetTempList[sizeof(s_widgetHandlerList) / sizeof(T_DjiWidgetHandlerListItem)] = {0};
#ifdef MEGAPHONE_CONFIG_STATUS_ON
//赋予控件结构体初始值
WidetTempList[] = { OFF, OFF, PLAY_PAUSE, 30, 30, PLAY_SPEED_X1, 0, OFF,OFF,OFF, //喊话器部分
OFF, OFF, OFF, OFF, 50, OFF, //探照灯部分
0, 0, 2, //警灯部分
100, 100 ,ON ,OFF,OFF, //云台部分
OFF ,OFF, //系统部分
OFF,OFF, //调试部分
0,0,
0,0,0,0}; //调试部分
//读取探照灯部分
#ifdef SEARCHLIGHT_STATUS_ON
T_JzSearchLightAttribute SearchLightInfo;
SearchLight_Get_SearchLightAttribute(&SearchLightInfo);
WidetTempList[10] = JZ_MATH_MAX(SearchLightInfo.LeftBrightness, SearchLightInfo.RightBrightness);
WidetTempList[11] = JZ_MATH_MAX(SearchLightInfo.LeftBrightness, SearchLightInfo.RightBrightness);
WidetTempList[12] = SearchLightInfo.Mode;
WidetTempList[14] = SearchLightInfo.Frequency;
#endif
//读取警灯部分
#ifdef WARNLIGHT_STATUS_ON
T_JzWarnLightAttribute WarnLightInfo;
WarnLight_Get_Attribute(&WarnLightInfo);
WidetTempList[16] = WarnLightInfo.mode;
WidetTempList[17] = WarnLightInfo.Color1;
WidetTempList[18] = WarnLightInfo.Color2;
#endif
//将控件结构体中的值写入设备
memcpy(s_widgetValueList, WidetTempList, sizeof(s_widgetValueList));
#endif
#ifdef IRC_CONFIG_STATUS_ON
//赋予控件结构体初始值
WidetTempList[] = {VIDEOMGMT_STREAMING_FLOW_INDEX_FIRST, //视频流
OFF, //测温模式
ON, //光圈开关
OFF, //冻结开关
... ... @@ -225,17 +281,24 @@ int32_t s_widgetValueList[] = {VIDEOMGMT_STREAMING_FLOW_INDEX_FIRST, //视频
OFF,
OFF,
OFF,
OFF
};
OFF}; //调试部分
//将控件结构体中的值写入设备
memcpy(s_widgetValueList, WidetTempList, sizeof(s_widgetValueList));
#endif
return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/* Exported functions definition ---------------导出函数定义——------------------------------*/
T_DjiReturnCode DjiTest_WidgetStartService(void)
{
//将设备里的控件值读到控件结构体中
WidgetRead();
T_DjiReturnCode djiStat;
T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler();
... ...
... ... @@ -47,7 +47,8 @@ extern "C" {
/* Exported constants --------------------------------------------------------*/
//User can config dev based on there environmental conditions
#define LINUX_UART_DEV1 UART_DEV1_NUM
//#define LINUX_UART_DEV1 UART_DEV1_NUM
#define LINUX_UART_DEV1 "/dev/ttyS1"
#define LINUX_UART_DEV2 "/dev/ttyACM0"
/* Exported types ------------------------------------------------------------*/
... ...
cmake_minimum_required(VERSION 3.5)
project(zydemo C)
set(CMAKE_C_FLAGS "-pthread -std=gnu99")
set(CMAKE_CXX_FLAGS "-std=c++11 -pthread")
set(CMAKE_EXE_LINKER_FLAGS "-pthread")
set(CMAKE_C_COMPILER "/usr/local/arm/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc")
set(CMAKE_CXX_COMPILER "/usr/local/arm/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++")
add_definitions(-D_GNU_SOURCE)
#Strengthen Compilation Warnings - Treat All Warnings as Errors
#Purpose: Minimize potential issues caused by syntax and compiler-specific features
# add_definitions(-Werror)
# add_definitions(-Wno-error=implicit-function-declaration)
if (NOT USE_SYSTEM_ARCH)
add_definitions(-DSYSTEM_ARCH_LINUX)
endif ()
if (BUILD_TEST_CASES_ON MATCHES TRUE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage -lgcov")
endif ()
set(PACKAGE_NAME payloadsdk)
## "uname -m" to auto distinguish Manifold2-G or Manifold2-C
execute_process(COMMAND uname -m
OUTPUT_VARIABLE DEVICE_SYSTEM_ID)
# if (DEVICE_SYSTEM_ID MATCHES x86_64)
# set(TOOLCHAIN_NAME x86_64-linux-gnu)
# add_definitions(-DPLATFORM_ARCH_x86_64=1)
# elseif (DEVICE_SYSTEM_ID MATCHES aarch64)
# set(TOOLCHAIN_NAME aarch64-linux-gnu)
# add_definitions(-DPLATFORM_ARCH_aarch64=1)
# elseif (DEVICE_SYSTEM_ID MATCHES armv7l)
set(TOOLCHAIN_NAME arm-linux-gnueabihf)
# add_definitions(-DPLATFORM_ARCH_arm=1)
# else ()
# message(FATAL_ERROR "FATAL: Please confirm your platform. SYSTEM_ID:${DEVICE_SYSTEM_ID}")
# endif ()
file(GLOB_RECURSE MODULE_COMMON_SRC ../common/*.c)
file(GLOB_RECURSE MODULE_HAL_SRC hal/*.c)
file(GLOB_RECURSE MODULE_APP_SRC application/*.c)
file(GLOB_RECURSE MODULE_SAMPLE_SRC ../../../module_sample/*.c)
include_directories(../../../module_sample)
include_directories(../common)
include_directories(../manifold2/application)
include_directories(../../../../../psdk_lib/include)
link_directories(../../../../../psdk_lib/lib/${TOOLCHAIN_NAME})
link_libraries(${CMAKE_CURRENT_LIST_DIR}/../../../../../psdk_lib/lib/${TOOLCHAIN_NAME}/lib${PACKAGE_NAME}.a)
if (NOT EXECUTABLE_OUTPUT_PATH)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
endif ()
add_executable(${PROJECT_NAME}
${MODULE_APP_SRC}
${MODULE_SAMPLE_SRC}
${MODULE_COMMON_SRC}
${MODULE_HAL_SRC})
target_link_libraries(${PROJECT_NAME} m stdc++)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../common/3rdparty)
# find_package(OPUS REQUIRED)
# if (OPUS_FOUND)
# message(STATUS "Found OPUS installed in the system")
# message(STATUS " - Includes: ${OPUS_INCLUDE_DIR}")
# message(STATUS " - Libraries: ${OPUS_LIBRARY}")
# add_definitions(-DOPUS_INSTALLED)
# target_link_libraries(${PROJECT_NAME} ${OPUS_LIBRARY})
# else ()
# message(STATUS "Cannot Find OPUS")
# endif (OPUS_FOUND)
# find_package(ASOUND REQUIRED)
# if (ASOUND_FOUND)
# message(STATUS "Found ASOUND installed in the system")
# message(STATUS " - Includes: ${ASOUND_INCLUDE_DIR}")
# message(STATUS " - Libraries: ${ASOUND_LIBRARY}")
# add_definitions(-DASOUND_INSTALLED)
# include_directories(${ASOUND_INCLUDE_DIR})
# target_link_libraries(${PROJECT_NAME} ${ASOUND_LIBRARIES})
# else()
# message(STATUS "Cannot Find ASOUND")
# endif()
# find_package(LIBUSB REQUIRED)
# if (LIBUSB_FOUND)
# message(STATUS "Found LIBUSB installed in the system")
# message(STATUS " - Includes: ${LIBUSB_INCLUDE_DIR}")
# message(STATUS " - Libraries: ${LIBUSB_LIBRARY}")
# add_definitions(-DLIBUSB_INSTALLED)
# target_link_libraries(${PROJECT_NAME} ${LIBUSB_LIBRARY})
# else ()
# message(STATUS "Cannot Find LIBUSB")
# endif (LIBUSB_FOUND)
# find_package(FFMPEG REQUIRED)
# if(FFMPEG_FOUND)
# message(STATUS "Found FFMPEG installed in the system")
# message(STATUS " - Includes: ${FFMPEG_INCLUDE_DIR}")
# message(STATUS " - Libraries: ${FFMPEG_LIBRARIES}")
# ADD_DEFINITIONS(-DFFMPEG_INSTALLED)
# target_link_libraries(${PROJECT_NAME} ${FFMPEG_LIBRARIES} m stdc++)
# else ()
# message(STATUS "Cannot Find FFMPEG")
# endif (FFMPEG_FOUND)
# # 查找 FFmpeg 库
# find_package(PkgConfig REQUIRED)
# pkg_check_modules(AVFORMAT REQUIRED libavformat)
# pkg_check_modules(AVCODEC REQUIRED libavcodec)
# pkg_check_modules(AVUTIL REQUIRED libavutil)
# # 包含 FFmpeg 头文件路径
# include_directories(${AVFORMAT_INCLUDE_DIRS})
# include_directories(${AVCODEC_INCLUDE_DIRS})
# include_directories(${AVUTIL_INCLUDE_DIRS})
# # 链接 FFmpeg 库
# target_link_libraries(${PROJECT_NAME} ${AVFORMAT_LIBRARIES} ${AVCODEC_LIBRARIES} ${AVUTIL_LIBRARIES})
# target_link_libraries(${PROJECT_NAME} m)
# target_link_libraries(${PROJECT_NAME} stdc++)
# add_custom_command(TARGET ${PROJECT_NAME}
# PRE_LINK COMMAND cmake ..
# WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
... ...
/**
********************************************************************
* @file main.c
* @brief
*
* @copyright (c) 2021 ZIYAN. All rights reserved.
*
* All information contained herein is, and remains, the property of ZIYAN.
* The intellectual and technical concepts contained herein are proprietary
* to ZIYAN 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 ZIYAN.
*
* If you receive this source code without ZIYAN’s authorization, you may not
* further disseminate the information, and you must immediately remove the
* source code and notify ZIYAN of its removal. ZIYAN 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 <ziyan_platform.h>
#include <ziyan_logger.h>
#include <ziyan_core.h>
#include <utils/util_misc.h>
#include <errno.h>
#include <signal.h>
#include "monitor/sys_monitor.h"
#include "osal/osal.h"
#include "osal/osal_fs.h"
#include "osal/osal_socket.h"
#include "../hal/hal_uart.h"
#include "../hal/hal_network.h"
#include "../hal/hal_usb_bulk.h"
#include "ziyan_sdk_app_info.h"
#include "ziyan_aircraft_info.h"
#include "widget/test_widget.h"
#include "ziyan_sdk_config.h"
/* Private constants ---------------------------------------------------------*/
#define ZIYAN_LOG_PATH "Logs/ZIYAN"
#define ZIYAN_LOG_INDEX_FILE_NAME "Logs/latest"
#define ZIYAN_LOG_FOLDER_NAME "Logs"
#define ZIYAN_LOG_PATH_MAX_SIZE (128)
#define ZIYAN_LOG_FOLDER_NAME_MAX_SIZE (32)
#define ZIYAN_LOG_MAX_COUNT (10)
#define ZIYAN_SYSTEM_CMD_STR_MAX_SIZE (64)
#define ZIYAN_SYSTEM_RESULT_STR_MAX_SIZE (128)
#define ZIYAN_USE_WIDGET_INTERACTION 0
/* Private types -------------------------------------------------------------*/
typedef struct {
pid_t tid;
char name[16];
float pcpu;
} T_ThreadAttribute;
/* Private values -------------------------------------------------------------*/
static FILE *s_ziyanLogFile;
static FILE *s_ziyanLogFileCnt;
static pthread_t s_monitorThread = 0;
/* Private functions declaration ---------------------------------------------*/
static T_ZiyanReturnCode ZiyanUser_PrepareSystemEnvironment(void);
static T_ZiyanReturnCode ZiyanUser_FillInUserInfo(T_ZiyanUserInfo *userInfo);
static T_ZiyanReturnCode ZiyanUser_PrintConsole(const uint8_t *data, uint16_t dataLen);
static T_ZiyanReturnCode ZiyanUser_LocalWrite(const uint8_t *data, uint16_t dataLen);
static T_ZiyanReturnCode ZiyanUser_LocalWriteFsInit(const char *path);
// static void *ZiyanUser_MonitorTask(void *argument);
// static T_ZiyanReturnCode ZiyanTest_HighPowerApplyPinInit();
// static T_ZiyanReturnCode ZiyanTest_WriteHighPowerApplyPin(E_ZiyanPowerManagementPinState pinState);
static void ZiyanUser_NormalExitHandler(int signalNum);
/* Exported functions definition ---------------------------------------------*/
int main(int argc, char **argv)
{
T_ZiyanReturnCode returnCode;
T_ZiyanUserInfo userInfo;
T_ZiyanAircraftInfoBaseInfo aircraftInfoBaseInfo;
T_ZiyanAircraftVersion aircraftInfoVersion;
T_ZiyanFirmwareVersion firmwareVersion = {
.majorVersion = 1,
.minorVersion = 0,
.modifyVersion = 0,
.debugVersion = 0,
};
USER_UTIL_UNUSED(argc);
USER_UTIL_UNUSED(argv);
// attention: when the program is hand up ctrl-c will generate the coredump file
signal(SIGTERM, ZiyanUser_NormalExitHandler);
/*!< Step 1: Prepare system environment, such as osal, hal uart, console function and so on. */
returnCode = ZiyanUser_PrepareSystemEnvironment();
if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Prepare system environment error");
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
/*!< Step 2: Fill your application information in ziyan_sdk_app_info.h and use this interface to fill it. */
returnCode = ZiyanUser_FillInUserInfo(&userInfo);
if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Fill user info error, please check user info config");
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
// /*!< Step 3: Initialize the Payload SDK core by your application information. */
returnCode = ZiyanCore_Init(&userInfo);
if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Core init error");
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
returnCode = ZiyanAircraftInfo_GetBaseInfo(&aircraftInfoBaseInfo);
if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("get aircraft base info error");
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
// returnCode = ZiyanAircraftInfo_GetAircraftVersion(&aircraftInfoVersion);
// if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
// USER_LOG_ERROR("get aircraft version info error");
// } else {
// USER_LOG_INFO("Aircraft version is V%02d.%02d.%02d.%02d", aircraftInfoVersion.majorVersion,
// aircraftInfoVersion.minorVersion, aircraftInfoVersion.modifyVersion,
// aircraftInfoVersion.debugVersion);
// }
// returnCode = ZiyanCore_SetAlias("PSDK_APPALIAS");
// if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
// USER_LOG_ERROR("set alias error");
// return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
// }
// returnCode = ZiyanCore_SetFirmwareVersion(firmwareVersion);
// if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
// USER_LOG_ERROR("set firmware version error");
// return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
// }
// returnCode = ZiyanCore_SetSerialNumber("PSDK12345678XX");
// if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
// USER_LOG_ERROR("set serial number error");
// return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
// }
// /*!< Step 4: Initialize the selected modules by macros in ziyan_sdk_config.h . */
// #ifdef CONFIG_MODULE_SAMPLE_POWER_MANAGEMENT_ON
// T_ZiyanTestApplyHighPowerHandler applyHighPowerHandler = {
// .pinInit = ZiyanTest_HighPowerApplyPinInit,
// .pinWrite = ZiyanTest_WriteHighPowerApplyPin,
// };
// returnCode = ZiyanTest_RegApplyHighPowerHandler(&applyHighPowerHandler);
// if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
// USER_LOG_ERROR("regsiter apply high power handler error");
// }
// returnCode = ZiyanTest_PowerManagementStartService();
// if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
// USER_LOG_ERROR("power management init error");
// }
// #endif
// #ifdef CONFIG_MODULE_SAMPLE_DATA_TRANSMISSION_ON
// returnCode = ZiyanTest_DataTransmissionStartService();
// if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
// USER_LOG_ERROR("widget sample init error");
// }
// #endif
// if (aircraftInfoBaseInfo.mountPosition == ZIYAN_MOUNT_POSITION_EXTENSION_PORT &&
// aircraftInfoBaseInfo.aircraftType == ZIYAN_AIRCRAFT_TYPE_M300_RTK) {
// returnCode = ZiyanTest_WidgetInteractionStartService();
// if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
// USER_LOG_ERROR("widget interaction sample init error");
// }
// returnCode = ZiyanTest_WidgetSpeakerStartService();
// if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
// USER_LOG_ERROR("widget speaker test init error");
// }
// } else {
#ifdef CONFIG_MODULE_SAMPLE_CAMERA_EMU_ON
returnCode = ZiyanTest_CameraEmuBaseStartService();
if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("camera emu common init error");
}
#endif
#ifdef CONFIG_MODULE_SAMPLE_CAMERA_MEDIA_ON
returnCode = ZiyanTest_CameraEmuMediaStartService();
if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("camera emu media init error");
}
#endif
#ifdef CONFIG_MODULE_SAMPLE_FC_SUBSCRIPTION_ON
returnCode = ZiyanTest_FcSubscriptionStartService();
if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("data subscription sample init error\n");
}
#endif
// #ifdef CONFIG_MODULE_SAMPLE_GIMBAL_EMU_ON
// #if DEVICE_VERSION == JZ_H150S || DEVICE_VERSION == JZ_H150T
// // if (aircraftInfoBaseInfo.ziyanAdapterType == ZIYAN_SDK_ADAPTER_TYPE_NONE ||
// // aircraftInfoBaseInfo.ziyanAdapterType == ZIYAN_SDK_ADAPTER_TYPE_UNKNOWN) {
// if (ZiyanTest_GimbalStartService() != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
// USER_LOG_ERROR("psdk gimbal init error");
// }
// //}
// #endif
// #ifdef CONFIG_MODULE_SAMPLE_XPORT_ON
// if (aircraftInfoBaseInfo.ziyanAdapterType == ZIYAN_SDK_ADAPTER_TYPE_XPORT) {
// if (ZiyanTest_XPortStartService() != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
// USER_LOG_ERROR("psdk xport init error");
// }
// }
// #endif
#ifdef CONFIG_MODULE_SAMPLE_WIDGET_ON
ZiyanTest_WidgetSetConfigFilePath("/root/");
#if ZIYAN_USE_WIDGET_INTERACTION
returnCode = ZiyanTest_WidgetInteractionStartService();
if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("widget interaction test init error");
}
#else
returnCode = ZiyanTest_WidgetStartService();
if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("widget sample init error");
}
#endif
#endif
#ifdef CONFIG_MODULE_SAMPLE_WIDGET_SPEAKER_ON
returnCode = ZiyanTest_WidgetSpeakerStartService();
if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("widget speaker test init error");
}
#endif
// #ifdef CONFIG_MODULE_SAMPLE_MOP_CHANNEL_ON
// returnCode = ZiyanTest_MopChannelStartService();
// if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
// USER_LOG_ERROR("mop channel sample init error");
// }
// #endif
// #ifdef CONFIG_MODULE_SAMPLE_PAYLOAD_COLLABORATION_ON
// if (aircraftInfoBaseInfo.ziyanAdapterType == ZIYAN_SDK_ADAPTER_TYPE_SKYPORT_V2 ||
// aircraftInfoBaseInfo.ziyanAdapterType == ZIYAN_SDK_ADAPTER_TYPE_XPORT) {
// returnCode = ZiyanTest_PayloadCollaborationStartService();
// if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
// USER_LOG_ERROR("Payload collaboration sample init error\n");
// }
// }
// #endif
// #ifdef CONFIG_MODULE_SAMPLE_UPGRADE_ON
// T_ZiyanTestUpgradePlatformOpt linuxUpgradePlatformOpt = {
// .rebootSystem = ZiyanUpgradePlatformLinux_RebootSystem,
// .cleanUpgradeProgramFileStoreArea = ZiyanUpgradePlatformLinux_CleanUpgradeProgramFileStoreArea,
// .createUpgradeProgramFile = ZiyanUpgradePlatformLinux_CreateUpgradeProgramFile,
// .writeUpgradeProgramFile = ZiyanUpgradePlatformLinux_WriteUpgradeProgramFile,
// .readUpgradeProgramFile = ZiyanUpgradePlatformLinux_ReadUpgradeProgramFile,
// .closeUpgradeProgramFile = ZiyanUpgradePlatformLinux_CloseUpgradeProgramFile,
// .replaceOldProgram = ZiyanUpgradePlatformLinux_ReplaceOldProgram,
// .setUpgradeRebootState = ZiyanUpgradePlatformLinux_SetUpgradeRebootState,
// .getUpgradeRebootState = ZiyanUpgradePlatformLinux_GetUpgradeRebootState,
// .cleanUpgradeRebootState = ZiyanUpgradePlatformLinux_CleanUpgradeRebootState,
// };
// T_ZiyanTestUpgradeConfig testUpgradeConfig = {
// .firmwareVersion = firmwareVersion,
// .transferType = ZIYAN_FIRMWARE_TRANSFER_TYPE_DCFTP,
// .needReplaceProgramBeforeReboot = true
// };
// if (ZiyanTest_UpgradeStartService(&linuxUpgradePlatformOpt, testUpgradeConfig) !=
// ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
// USER_LOG_ERROR("psdk upgrade init error");
// }
// #endif
// #ifdef CONFIG_MODULE_SAMPLE_HMS_CUSTOMIZATION_ON
// returnCode = ZiyanTest_HmsCustomizationStartService();
// if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
// USER_LOG_ERROR("hms test init error");
// }
// #endif
// }
// /*!< Step 5: Tell the ZIYAN Pilot you are ready. */
returnCode = ZiyanCore_ApplicationStart();
if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("start sdk application error");
}
// if (pthread_create(&s_monitorThread, NULL, ZiyanUser_MonitorTask, NULL) != 0) {
// USER_LOG_ERROR("create monitor task fail.");
// }
// if (pthread_setname_np(s_monitorThread, "monitor task") != 0) {
// USER_LOG_ERROR("set name for monitor task fail.");
// }
while (1) {
sleep(1);
}
}
/* Private functions definition-----------------------------------------------*/
static T_ZiyanReturnCode ZiyanUser_PrepareSystemEnvironment(void)
{
T_ZiyanReturnCode returnCode;
T_ZiyanOsalHandler osalHandler = {
.TaskCreate = Osal_TaskCreate,
.TaskDestroy = Osal_TaskDestroy,
.TaskSleepMs = Osal_TaskSleepMs,
.MutexCreate= Osal_MutexCreate,
.MutexDestroy = Osal_MutexDestroy,
.MutexLock = Osal_MutexLock,
.MutexUnlock = Osal_MutexUnlock,
.SemaphoreCreate = Osal_SemaphoreCreate,
.SemaphoreDestroy = Osal_SemaphoreDestroy,
.SemaphoreWait = Osal_SemaphoreWait,
.SemaphoreTimedWait = Osal_SemaphoreTimedWait,
.SemaphorePost = Osal_SemaphorePost,
.Malloc = Osal_Malloc,
.Free = Osal_Free,
.GetRandomNum = Osal_GetRandomNum,
.GetTimeMs = Osal_GetTimeMs,
.GetTimeUs = Osal_GetTimeUs,
};
T_ZiyanLoggerConsole printConsole = {
.func = ZiyanUser_PrintConsole,
.consoleLevel = ZIYAN_LOGGER_CONSOLE_LOG_LEVEL_INFO,
.isSupportColor = true,
};
T_ZiyanLoggerConsole localRecordConsole = {
.consoleLevel = ZIYAN_LOGGER_CONSOLE_LOG_LEVEL_DEBUG,
.func = ZiyanUser_LocalWrite,
.isSupportColor = true,
};
T_ZiyanHalUartHandler uartHandler = {
.UartInit = HalUart_Init,
.UartDeInit = HalUart_DeInit,
.UartWriteData = HalUart_WriteData,
.UartReadData = HalUart_ReadData,
.UartGetStatus = HalUart_GetStatus,
};
T_ZiyanHalNetworkHandler networkHandler = {
.NetworkInit = HalNetWork_Init,
.NetworkDeInit = HalNetWork_DeInit,
.NetworkGetDeviceInfo = HalNetWork_GetDeviceInfo,
};
T_ZiyanHalUsbBulkHandler usbBulkHandler = {
.UsbBulkInit = HalUsbBulk_Init,
.UsbBulkDeInit = HalUsbBulk_DeInit,
.UsbBulkWriteData = HalUsbBulk_WriteData,
.UsbBulkReadData = HalUsbBulk_ReadData,
.UsbBulkGetDeviceInfo = HalUsbBulk_GetDeviceInfo,
};
T_ZiyanFileSystemHandler fileSystemHandler = {
.FileOpen = Osal_FileOpen,
.FileClose = Osal_FileClose,
.FileWrite = Osal_FileWrite,
.FileRead = Osal_FileRead,
.FileSync = Osal_FileSync,
.FileSeek = Osal_FileSeek,
.DirOpen = Osal_DirOpen,
.DirClose = Osal_DirClose,
.DirRead = Osal_DirRead,
.Mkdir = Osal_Mkdir,
.Unlink = Osal_Unlink,
.Rename = Osal_Rename,
.Stat = Osal_Stat,
};
T_ZiyanSocketHandler socketHandler = {
.Socket = Osal_Socket,
.Bind = Osal_Bind,
.Close = Osal_Close,
.UdpSendData = Osal_UdpSendData,
.UdpRecvData = Osal_UdpRecvData,
.TcpListen = Osal_TcpListen,
.TcpAccept = Osal_TcpAccept,
.TcpConnect = Osal_TcpConnect,
.TcpSendData = Osal_TcpSendData,
.TcpRecvData = Osal_TcpRecvData,
};
returnCode = ZiyanPlatform_RegOsalHandler(&osalHandler);
if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
printf("register osal handler error");
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
returnCode = ZiyanPlatform_RegHalUartHandler(&uartHandler);
if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
printf("register hal uart handler error");
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
if (ZiyanUser_LocalWriteFsInit(ZIYAN_LOG_PATH) != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
printf("file system init error");
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
returnCode = ZiyanLogger_AddConsole(&printConsole);
if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
printf("add printf console error");
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
returnCode = ZiyanLogger_AddConsole(&localRecordConsole);
if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
printf("add printf console error");
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
#if (CONFIG_HARDWARE_CONNECTION == ZIYAN_USE_UART_AND_USB_BULK_DEVICE)
returnCode = ZiyanPlatform_RegHalUsbBulkHandler(&usbBulkHandler);
if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
printf("register hal usb bulk handler error");
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
#elif (CONFIG_HARDWARE_CONNECTION == ZIYAN_USE_UART_AND_NETWORK_DEVICE)
returnCode = ZiyanPlatform_RegHalNetworkHandler(&networkHandler);
if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
printf("register hal network handler error");
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
//Attention: if you want to use camera stream view function, please uncomment it.
returnCode = ZiyanPlatform_RegSocketHandler(&socketHandler);
if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
printf("register osal socket handler error");
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
#elif (CONFIG_HARDWARE_CONNECTION == ZIYAN_USE_ONLY_UART)
/*!< Attention: Only use uart hardware connection.
*/
#endif
returnCode = ZiyanPlatform_RegFileSystemHandler(&fileSystemHandler);
if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
printf("register osal filesystem handler error");
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
static T_ZiyanReturnCode ZiyanUser_FillInUserInfo(T_ZiyanUserInfo *userInfo)
{
if (userInfo == NULL) {
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
memset(userInfo->appName, 0, sizeof(userInfo->appName));
memset(userInfo->appId, 0, sizeof(userInfo->appId));
memset(userInfo->appKey, 0, sizeof(userInfo->appKey));
memset(userInfo->appLicense, 0, sizeof(userInfo->appLicense));
memset(userInfo->developerAccount, 0, sizeof(userInfo->developerAccount));
memset(userInfo->baudRate, 0, sizeof(userInfo->baudRate));
if (strlen(USER_APP_NAME) >= sizeof(userInfo->appName) ||
strlen(USER_APP_ID) > sizeof(userInfo->appId) ||
strlen(USER_APP_KEY) > sizeof(userInfo->appKey) ||
strlen(USER_APP_LICENSE) > sizeof(userInfo->appLicense) ||
strlen(USER_DEVELOPER_ACCOUNT) >= sizeof(userInfo->developerAccount) ||
strlen(USER_BAUD_RATE) > sizeof(userInfo->baudRate)) {
USER_LOG_ERROR("Length of user information string is beyond limit. Please check.");
sleep(1);
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
if (!strcmp(USER_APP_NAME, "your_app_name") ||
!strcmp(USER_APP_ID, "your_app_id") ||
!strcmp(USER_APP_KEY, "your_app_key") ||
!strcmp(USER_BAUD_RATE, "your_app_license") ||
!strcmp(USER_DEVELOPER_ACCOUNT, "your_developer_account") ||
!strcmp(USER_BAUD_RATE, "your_baud_rate")) {
USER_LOG_ERROR(
"Please fill in correct user information to 'samples/sample_c/platform/linux/manifold2/application/ziyan_sdk_app_info.h' file.");
sleep(1);
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
strncpy(userInfo->appName, USER_APP_NAME, sizeof(userInfo->appName) - 1);
memcpy(userInfo->appId, USER_APP_ID, USER_UTIL_MIN(sizeof(userInfo->appId), strlen(USER_APP_ID)));
memcpy(userInfo->appKey, USER_APP_KEY, USER_UTIL_MIN(sizeof(userInfo->appKey), strlen(USER_APP_KEY)));
memcpy(userInfo->appLicense, USER_APP_LICENSE,
USER_UTIL_MIN(sizeof(userInfo->appLicense), strlen(USER_APP_LICENSE)));
memcpy(userInfo->baudRate, USER_BAUD_RATE, USER_UTIL_MIN(sizeof(userInfo->baudRate), strlen(USER_BAUD_RATE)));
strncpy(userInfo->developerAccount, USER_DEVELOPER_ACCOUNT, sizeof(userInfo->developerAccount) - 1);
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
static T_ZiyanReturnCode ZiyanUser_PrintConsole(const uint8_t *data, uint16_t dataLen)
{
USER_UTIL_UNUSED(dataLen);
printf("%s", data);
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
static T_ZiyanReturnCode ZiyanUser_LocalWrite(const uint8_t *data, uint16_t dataLen)
{
uint32_t realLen;
if (s_ziyanLogFile == NULL) {
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
realLen = fwrite(data, 1, dataLen, s_ziyanLogFile);
fflush(s_ziyanLogFile);
if (realLen == dataLen) {
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
} else {
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
}
static T_ZiyanReturnCode ZiyanUser_LocalWriteFsInit(const char *path)
{
T_ZiyanReturnCode ziyanReturnCode = ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
char filePath[ZIYAN_LOG_PATH_MAX_SIZE];
char systemCmd[ZIYAN_SYSTEM_CMD_STR_MAX_SIZE];
char folderName[ZIYAN_LOG_FOLDER_NAME_MAX_SIZE];
time_t currentTime = time(NULL);
struct tm *localTime = localtime(&currentTime);
uint16_t logFileIndex = 0;
uint16_t currentLogFileIndex;
uint8_t ret;
if (localTime == NULL) {
printf("Get local time error.\r\n");
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
if (access(ZIYAN_LOG_FOLDER_NAME, F_OK) != 0) {
sprintf(folderName, "mkdir %s", ZIYAN_LOG_FOLDER_NAME);
ret = system(folderName);
if (ret != 0) {
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
}
s_ziyanLogFileCnt = fopen(ZIYAN_LOG_INDEX_FILE_NAME, "rb+");
if (s_ziyanLogFileCnt == NULL) {
s_ziyanLogFileCnt = fopen(ZIYAN_LOG_INDEX_FILE_NAME, "wb+");
if (s_ziyanLogFileCnt == NULL) {
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
} else {
ret = fseek(s_ziyanLogFileCnt, 0, SEEK_SET);
if (ret != 0) {
printf("Seek log count file error, ret: %d, errno: %d.\r\n", ret, errno);
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
ret = fread((uint16_t *) &logFileIndex, 1, sizeof(uint16_t), s_ziyanLogFileCnt);
if (ret != sizeof(uint16_t)) {
printf("Read log file index error.\r\n");
}
}
currentLogFileIndex = logFileIndex;
logFileIndex++;
ret = fseek(s_ziyanLogFileCnt, 0, SEEK_SET);
if (ret != 0) {
printf("Seek log file error, ret: %d, errno: %d.\r\n", ret, errno);
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
ret = fwrite((uint16_t *) &logFileIndex, 1, sizeof(uint16_t), s_ziyanLogFileCnt);
if (ret != sizeof(uint16_t)) {
printf("Write log file index error.\r\n");
fclose(s_ziyanLogFileCnt);
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
fclose(s_ziyanLogFileCnt);
sprintf(filePath, "%s_%04d_%04d%02d%02d_%02d-%02d-%02d.log", path, currentLogFileIndex,
localTime->tm_year + 1900, localTime->tm_mon + 1, localTime->tm_mday,
localTime->tm_hour, localTime->tm_min, localTime->tm_sec);
s_ziyanLogFile = fopen(filePath, "wb+");
if (s_ziyanLogFile == NULL) {
USER_LOG_ERROR("Open filepath time error.");
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
if (logFileIndex >= ZIYAN_LOG_MAX_COUNT) {
sprintf(systemCmd, "rm -rf %s_%04d*.log", path, currentLogFileIndex - ZIYAN_LOG_MAX_COUNT);
ret = system(systemCmd);
if (ret != 0) {
printf("Remove file error, ret:%d.\r\n", ret);
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
}
return ziyanReturnCode;
}
// #pragma GCC diagnostic push
// #pragma GCC diagnostic ignored "-Wmissing-noreturn"
// #pragma GCC diagnostic ignored "-Wreturn-type"
// static void *ZiyanUser_MonitorTask(void *argument)
// {
// unsigned int i = 0;
// unsigned int threadCount = 0;
// pid_t *tidList = NULL;
// T_ThreadAttribute *threadAttribute = NULL;
// T_ZiyanOsalHandler *osalHandler = ZiyanPlatform_GetOsalHandler();
// USER_UTIL_UNUSED(argument);
// while (1) {
// threadCount = Monitor_GetThreadCountOfProcess(getpid());
// tidList = osalHandler->Malloc(threadCount * sizeof(pid_t));
// if (tidList == NULL) {
// USER_LOG_ERROR("malloc fail.");
// goto delay;
// }
// Monitor_GetTidListOfProcess(getpid(), tidList, threadCount);
// threadAttribute = osalHandler->Malloc(threadCount * sizeof(T_ThreadAttribute));
// if (threadAttribute == NULL) {
// USER_LOG_ERROR("malloc fail.");
// goto freeTidList;
// }
// for (i = 0; i < threadCount; ++i) {
// threadAttribute[i].tid = tidList[i];
// }
// USER_LOG_DEBUG("thread pcpu:");
// USER_LOG_DEBUG("tid\tname\tpcpu");
// for (i = 0; i < threadCount; ++i) {
// threadAttribute[i].pcpu = Monitor_GetPcpuOfThread(getpid(), tidList[i]);
// Monitor_GetNameOfThread(getpid(), tidList[i], threadAttribute[i].name, sizeof(threadAttribute[i].name));
// USER_LOG_DEBUG("%d\t%15s\t%f %%.", threadAttribute[i].tid, threadAttribute[i].name,
// threadAttribute[i].pcpu);
// }
// USER_LOG_DEBUG("heap used: %d B.", Monitor_GetHeapUsed(getpid()));
// USER_LOG_DEBUG("stack used: %d B.", Monitor_GetStackUsed(getpid()));
// osalHandler->Free(threadAttribute);
// freeTidList:
// osalHandler->Free(tidList);
// delay:
// sleep(10);
// }
// }
// // static T_ZiyanReturnCode ZiyanTest_HighPowerApplyPinInit()
// // {
// // return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
// // }
// // static T_ZiyanReturnCode ZiyanTest_WriteHighPowerApplyPin(E_ZiyanPowerManagementPinState pinState)
// // {
// // //attention: please pull up the HWPR pin state by hardware.
// // return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
// // }
static void ZiyanUser_NormalExitHandler(int signalNum)
{
USER_UTIL_UNUSED(signalNum);
exit(0);
}
#pragma GCC diagnostic pop
/****************** (C) COPYRIGHT ZIYAN Innovations *****END OF FILE****/
... ...
/**
********************************************************************
* @file ziyan_sdk_app_info.h
* @brief This is the header file for defining the structure and (exported) function prototypes.
*
* @copyright (c) 2018 ZIYAN. All rights reserved.
*
* All information contained herein is, and remains, the property of ZIYAN.
* The intellectual and technical concepts contained herein are proprietary
* to ZIYAN 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 ZIYAN.
*
* If you receive this source code without ZIYAN’s authorization, you may not
* further disseminate the information, and you must immediately remove the
* source code and notify ZIYAN of its removal. ZIYAN 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 ZIYAN_SDK_APP_INFO_H
#define ZIYAN_SDK_APP_INFO_H
/* Includes ------------------------------------------------------------------*/
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
// ATTENTION: User must goto https://developer.ziyan.com/user/apps/#all to create your own ziyan sdk application, get ziyan sdk application
// information then fill in the application information here.
#define USER_APP_NAME "app_name_ziyan"
#define USER_APP_ID "app_id_ziyan"
#define USER_APP_KEY "app_key_ziyan"
#define USER_APP_LICENSE "app_license_ziyan"
#define USER_DEVELOPER_ACCOUNT "developer_account_ziyan"
#define USER_BAUD_RATE "921600"
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
#ifdef __cplusplus
}
#endif
#endif // ZIYAN_SDK_APP_INFO_H
/************************ (C) COPYRIGHT ZIYAN Innovations *******END OF FILE******/
... ...
/**
********************************************************************
* @file ziyan_sdk_config.h
* @brief This is the header file for "ziyan_config.c", defining the structure and
* (exported) function prototypes.
*
* @copyright (c) 2021 ZIYAN. All rights reserved.
*
* All information contained herein is, and remains, the property of ZIYAN.
* The intellectual and technical concepts contained herein are proprietary
* to ZIYAN 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 ZIYAN.
*
* If you receive this source code without ZIYAN’s authorization, you may not
* further disseminate the information, and you must immediately remove the
* source code and notify ZIYAN of its removal. ZIYAN 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 ZIYAN_SDK_CONFIG_H
#define ZIYAN_SDK_CONFIG_H
/* Includes ------------------------------------------------------------------*/
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
#define ZIYAN_USE_ONLY_UART (0)
#define ZIYAN_USE_UART_AND_USB_BULK_DEVICE (1)
#define ZIYAN_USE_UART_AND_NETWORK_DEVICE (2)
/*!< Attention: Select your hardware connection mode here.
* */
#define CONFIG_HARDWARE_CONNECTION ZIYAN_USE_ONLY_UART
/*!< Attention: Select the sample you want to run here.
* */
// #define CONFIG_MODULE_SAMPLE_POWER_MANAGEMENT_ON
// #define CONFIG_MODULE_SAMPLE_CAMERA_EMU_ON
// #define CONFIG_MODULE_SAMPLE_CAMERA_MEDIA_ON
// #define CONFIG_MODULE_SAMPLE_GIMBAL_EMU_ON
// #define CONFIG_MODULE_SAMPLE_XPORT_ON
#define CONFIG_MODULE_SAMPLE_WIDGET_ON
#define CONFIG_MODULE_SAMPLE_WIDGET_SPEAKER_ON
// #define CONFIG_MODULE_SAMPLE_DATA_TRANSMISSION_ON
// #define CONFIG_MODULE_SAMPLE_UPGRADE_ON
// #define CONFIG_MODULE_SAMPLE_HMS_CUSTOMIZATION_ON
#define CONFIG_MODULE_SAMPLE_FC_SUBSCRIPTION_ON
/*!< Attention: This function needs to be used together with mobile sdk mop sample.
* */
//#define CONFIG_MODULE_SAMPLE_MOP_CHANNEL_ON
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
#ifdef __cplusplus
}
#endif
#endif // ZIYAN_SDK_CONFIG_H
/************************ (C) COPYRIGHT ZIYAN Innovations *******END OF FILE******/
... ...
/**
********************************************************************
* @file hal_network.c
* @brief
*
* @copyright (c) 2021 ZIYAN. All rights reserved.
*
* All information contained herein is, and remains, the property of ZIYAN.
* The intellectual and technical concepts contained herein are proprietary
* to ZIYAN 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 ZIYAN.
*
* If you receive this source code without ZIYAN’s authorization, you may not
* further disseminate the information, and you must immediately remove the
* source code and notify ZIYAN of its removal. ZIYAN 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 "string.h"
#include "stdlib.h"
#include "stdio.h"
#include "hal_network.h"
#include "ziyan_logger.h"
/* Private constants ---------------------------------------------------------*/
/* Private types -------------------------------------------------------------*/
/* Private values -------------------------------------------------------------*/
/* Private functions declaration ---------------------------------------------*/
/* Exported functions definition ---------------------------------------------*/
T_ZiyanReturnCode HalNetWork_Init(const char *ipAddr, const char *netMask, T_ZiyanNetworkHandle *halObj)
{
int32_t ret;
char cmdStr[LINUX_CMD_STR_MAX_SIZE];
if (ipAddr == NULL || netMask == NULL) {
USER_LOG_ERROR("hal network config param error");
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
//Attention: need root permission to config ip addr and netmask.
memset(cmdStr, 0, sizeof(cmdStr));
snprintf(cmdStr, sizeof(cmdStr), "ifconfig %s up", LINUX_NETWORK_DEV);
ret = system(cmdStr);
if (ret != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Can't open the network."
"Probably the program not execute with root permission."
"Please use the root permission to execute the program.");
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
snprintf(cmdStr, sizeof(cmdStr), "ifconfig %s %s netmask %s", LINUX_NETWORK_DEV, ipAddr, netMask);
ret = system(cmdStr);
if (ret != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Can't config the ip address of network."
"Probably the program not execute with root permission."
"Please use the root permission to execute the program.");
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_ZiyanReturnCode HalNetWork_DeInit(T_ZiyanNetworkHandle halObj)
{
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_ZiyanReturnCode HalNetWork_GetDeviceInfo(T_ZiyanHalNetworkDeviceInfo *deviceInfo)
{
deviceInfo->usbNetAdapter.vid = USB_NET_ADAPTER_VID;
deviceInfo->usbNetAdapter.pid = USB_NET_ADAPTER_PID;
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/* Private functions definition-----------------------------------------------*/
/****************** (C) COPYRIGHT ZIYAN Innovations *****END OF FILE****/
... ...
/**
********************************************************************
* @file hal_network.h
* @brief This is the header file for "hal_network.c", defining the structure and
* (exported) function prototypes.
*
* @copyright (c) 2021 ZIYAN. All rights reserved.
*
* All information contained herein is, and remains, the property of ZIYAN.
* The intellectual and technical concepts contained herein are proprietary
* to ZIYAN 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 ZIYAN.
*
* If you receive this source code without ZIYAN’s authorization, you may not
* further disseminate the information, and you must immediately remove the
* source code and notify ZIYAN of its removal. ZIYAN 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 HAL_NETWORK_H
#define HAL_NETWORK_H
/* Includes ------------------------------------------------------------------*/
#include "ziyan_platform.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
/** @attention User can config network card name here, if your device is not MF2C/G, please comment below and add your
* NIC name micro define as #define 'LINUX_NETWORK_DEV "your NIC name"'.
*/
#ifdef PLATFORM_ARCH_x86_64
#define LINUX_NETWORK_DEV "enxf8e43b7bbc2c"
#else
#define LINUX_NETWORK_DEV "l4tbr0"
#endif
/**
* @attention
*/
#ifdef PLATFORM_ARCH_x86_64
#define USB_NET_ADAPTER_VID (0x0B95)
#define USB_NET_ADAPTER_PID (0x1790)
#else
#define USB_NET_ADAPTER_VID (0x0955)
#define USB_NET_ADAPTER_PID (0x7020)
#endif
#define LINUX_CMD_STR_MAX_SIZE (128)
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
T_ZiyanReturnCode HalNetWork_Init(const char *ipAddr, const char *netMask, T_ZiyanNetworkHandle *halObj);
T_ZiyanReturnCode HalNetWork_DeInit(T_ZiyanNetworkHandle halObj);
T_ZiyanReturnCode HalNetWork_GetDeviceInfo(T_ZiyanHalNetworkDeviceInfo *deviceInfo);
#ifdef __cplusplus
}
#endif
#endif // HAL_NETWORK_H
/************************ (C) COPYRIGHT ZIYAN Innovations *******END OF FILE******/
... ...
/**
********************************************************************
* @file hal_uart.c
* @brief
*
* @copyright (c) 2021 ZIYAN. All rights reserved.
*
* All information contained herein is, and remains, the property of ZIYAN.
* The intellectual and technical concepts contained herein are proprietary
* to ZIYAN 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 ZIYAN.
*
* If you receive this source code without ZIYAN’s authorization, you may not
* further disseminate the information, and you must immediately remove the
* source code and notify ZIYAN of its removal. ZIYAN 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 <ziyan_logger.h>
#include "hal_uart.h"
/* Private constants ---------------------------------------------------------*/
#define UART_DEV_NAME_STR_SIZE (128)
#define ZIYAN_SYSTEM_CMD_STR_MAX_SIZE (128)
#define ZIYAN_SYSTEM_RESULT_STR_MAX_SIZE (128)
/* Private types -------------------------------------------------------------*/
typedef struct {
int32_t uartFd;
} T_UartHandleStruct;
/* Private values -------------------------------------------------------------*/
/* Private functions declaration ---------------------------------------------*/
/* Exported functions definition ---------------------------------------------*/
T_ZiyanReturnCode HalUart_Init(E_ZiyanHalUartNum uartNum, uint32_t baudRate, T_ZiyanUartHandle *uartHandle)
{
T_UartHandleStruct *uartHandleStruct = NULL;
struct termios options;
struct flock lock;
T_ZiyanReturnCode returnCode = ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
char uartName[UART_DEV_NAME_STR_SIZE];
char systemCmd[ZIYAN_SYSTEM_CMD_STR_MAX_SIZE + 32];
char *ret = NULL;
char lineBuf[ZIYAN_SYSTEM_RESULT_STR_MAX_SIZE] = {0};
FILE *fp;
uartHandleStruct = malloc(sizeof(T_UartHandleStruct));
if (uartHandleStruct == NULL) {
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED;
}
if (uartNum == ZIYAN_HAL_UART_NUM_0) {
strcpy(uartName, LINUX_UART_DEV1);
} else if (uartNum == ZIYAN_HAL_UART_NUM_1) {
strcpy(uartName, LINUX_UART_DEV2);
} else {
goto free_uart_handle;
}
#ifdef USE_CLION_DEBUG
sprintf(systemCmd, "ls -l %s", uartName);
fp = popen(systemCmd, "r");
if (fp == NULL) {
goto free_uart_handle;
}
ret = fgets(lineBuf, sizeof(lineBuf), fp);
if (ret == NULL) {
goto close_fp;
}
if (strstr(lineBuf, "crwxrwxrwx") == NULL) {
USER_LOG_ERROR("Can't operation the device. "
"Probably the device has not operation permission. "
"Please execute command 'sudo chmod 777 %s' to add permission. ", uartName);
goto close_fp;
}
#else
sprintf(systemCmd, "chmod 777 %s", uartName);
fp = popen(systemCmd, "r");
if (fp == NULL) {
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
#endif
uartHandleStruct->uartFd = open(uartName, (unsigned) O_RDWR | (unsigned) O_NOCTTY | (unsigned) O_NDELAY);
if (uartHandleStruct->uartFd == -1) {
goto close_fp;
}
// Forbid multiple psdk programs to access the serial port
lock.l_type = F_WRLCK;
lock.l_pid = getpid();
lock.l_whence = SEEK_SET;
lock.l_start = 0;
lock.l_len = 0;
if (fcntl(uartHandleStruct->uartFd, F_GETLK, &lock) < 0) {
goto close_uart_fd;
}
if (lock.l_type != F_UNLCK) {
goto close_uart_fd;
}
lock.l_type = F_WRLCK;
lock.l_pid = getpid();
lock.l_whence = SEEK_SET;
lock.l_start = 0;
lock.l_len = 0;
if (fcntl(uartHandleStruct->uartFd, F_SETLKW, &lock) < 0) {
goto close_uart_fd;
}
if (tcgetattr(uartHandleStruct->uartFd, &options) != 0) {
goto close_uart_fd;
}
switch (baudRate) {
case 115200:
cfsetispeed(&options, B115200);
cfsetospeed(&options, B115200);
break;
case 230400:
cfsetispeed(&options, B230400);
cfsetospeed(&options, B230400);
break;
case 460800:
cfsetispeed(&options, B460800);
cfsetospeed(&options, B460800);
break;
case 921600:
cfsetispeed(&options, B921600);
cfsetospeed(&options, B921600);
break;
case 1000000:
cfsetispeed(&options, B1000000);
cfsetospeed(&options, B1000000);
break;
default:
goto close_uart_fd;
}
options.c_cflag |= (unsigned) CLOCAL;
options.c_cflag |= (unsigned) CREAD;
options.c_cflag &= ~(unsigned) CRTSCTS;
options.c_cflag &= ~(unsigned) CSIZE;
options.c_cflag |= (unsigned) CS8;
options.c_cflag &= ~(unsigned) PARENB;
options.c_iflag &= ~(unsigned) INPCK;
options.c_cflag &= ~(unsigned) CSTOPB;
options.c_oflag &= ~(unsigned) OPOST;
options.c_lflag &= ~((unsigned) ICANON | (unsigned) ECHO | (unsigned) ECHOE | (unsigned) ISIG);
options.c_iflag &= ~((unsigned) BRKINT | (unsigned) ICRNL | (unsigned) INPCK | (unsigned) ISTRIP | (unsigned) IXON);
options.c_cc[VTIME] = 0;
options.c_cc[VMIN] = 0;
tcflush(uartHandleStruct->uartFd, TCIFLUSH);
if (tcsetattr(uartHandleStruct->uartFd, TCSANOW, &options) != 0) {
goto close_uart_fd;
}
*uartHandle = uartHandleStruct;
pclose(fp);
return returnCode;
close_uart_fd:
close(uartHandleStruct->uartFd);
close_fp:
pclose(fp);
free_uart_handle:
free(uartHandleStruct);
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
T_ZiyanReturnCode HalUart_DeInit(T_ZiyanUartHandle uartHandle)
{
int32_t ret;
T_UartHandleStruct *uartHandleStruct = (T_UartHandleStruct *) uartHandle;
if (uartHandle == NULL) {
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
}
ret = close(uartHandleStruct->uartFd);
if (ret < 0) {
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
free(uartHandleStruct);
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_ZiyanReturnCode HalUart_WriteData(T_ZiyanUartHandle uartHandle, const uint8_t *buf, uint32_t len, uint32_t *realLen)
{
int32_t ret;
T_UartHandleStruct *uartHandleStruct = (T_UartHandleStruct *) uartHandle;
if (uartHandle == NULL || buf == NULL || len == 0 || realLen == NULL) {
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
ret = write(uartHandleStruct->uartFd, buf, len);
if (ret >= 0) {
*realLen = ret;
} else {
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_ZiyanReturnCode HalUart_ReadData(T_ZiyanUartHandle uartHandle, uint8_t *buf, uint32_t len, uint32_t *realLen)
{
int32_t ret;
T_UartHandleStruct *uartHandleStruct = (T_UartHandleStruct *) uartHandle;
if (uartHandle == NULL || buf == NULL || len == 0 || realLen == NULL) {
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
ret = read(uartHandleStruct->uartFd, buf, len);
if (ret >= 0) {
*realLen = ret;
} else {
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_ZiyanReturnCode HalUart_GetStatus(E_ZiyanHalUartNum uartNum, T_ZiyanUartStatus *status)
{
if (uartNum == ZIYAN_HAL_UART_NUM_0) {
status->isConnect = true;
} else if (uartNum == ZIYAN_HAL_UART_NUM_1) {
status->isConnect = true;
} else {
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
}
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/* Private functions definition-----------------------------------------------*/
/****************** (C) COPYRIGHT ZIYAN Innovations *****END OF FILE****/
... ...
/**
********************************************************************
* @file hal_uart.h
* @brief This is the header file for "hal_uart.c", defining the structure and
* (exported) function prototypes.
*
* @copyright (c) 2021 ZIYAN. All rights reserved.
*
* All information contained herein is, and remains, the property of ZIYAN.
* The intellectual and technical concepts contained herein are proprietary
* to ZIYAN 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 ZIYAN.
*
* If you receive this source code without ZIYAN’s authorization, you may not
* further disseminate the information, and you must immediately remove the
* source code and notify ZIYAN of its removal. ZIYAN 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 HAL_UART_H
#define HAL_UART_H
/* Includes ------------------------------------------------------------------*/
#include "stdint.h"
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
#include <string.h>
#include "stdlib.h"
#include "ziyan_platform.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
//User can config dev based on there environmental conditions
#define LINUX_UART_DEV1 "/dev/ttyS1"
#define LINUX_UART_DEV2 "/dev/ttyACM0"
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
T_ZiyanReturnCode HalUart_Init(E_ZiyanHalUartNum uartNum, uint32_t baudRate, T_ZiyanUartHandle *uartHandle);
T_ZiyanReturnCode HalUart_DeInit(T_ZiyanUartHandle uartHandle);
T_ZiyanReturnCode HalUart_WriteData(T_ZiyanUartHandle uartHandle, const uint8_t *buf, uint32_t len, uint32_t *realLen);
T_ZiyanReturnCode HalUart_ReadData(T_ZiyanUartHandle uartHandle, uint8_t *buf, uint32_t len, uint32_t *realLen);
T_ZiyanReturnCode HalUart_GetStatus(E_ZiyanHalUartNum uartNum, T_ZiyanUartStatus *status);
#ifdef __cplusplus
}
#endif
#endif // HAL_UART_H
/************************ (C) COPYRIGHT ZIYAN Innovations *******END OF FILE******/
... ...
/**
********************************************************************
* @file hal_usb_bulk.c
* @brief
*
* @copyright (c) 2021 ZIYAN. All rights reserved.
*
* All information contained herein is, and remains, the property of ZIYAN.
* The intellectual and technical concepts contained herein are proprietary
* to ZIYAN 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 ZIYAN.
*
* If you receive this source code without ZIYAN’s authorization, you may not
* further disseminate the information, and you must immediately remove the
* source code and notify ZIYAN of its removal. ZIYAN 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 "hal_usb_bulk.h"
#include "ziyan_logger.h"
/* Private constants ---------------------------------------------------------*/
#define LINUX_USB_BULK_TRANSFER_TIMEOUT_MS (50)
#define LINUX_USB_BULK_TRANSFER_WAIT_FOREVER (-1)
/* Private types -------------------------------------------------------------*/
typedef struct {
#ifdef LIBUSB_INSTALLED
libusb_device_handle *handle;
#else
void *handle;
#endif
int32_t ep1;
int32_t ep2;
uint32_t interfaceNum;
T_ZiyanHalUsbBulkInfo usbBulkInfo;
} T_HalUsbBulkObj;
/* Private values -------------------------------------------------------------*/
/* Private functions declaration ---------------------------------------------*/
/* Exported functions definition ---------------------------------------------*/
T_ZiyanReturnCode HalUsbBulk_Init(T_ZiyanHalUsbBulkInfo usbBulkInfo, T_ZiyanUsbBulkHandle *usbBulkHandle)
{
int32_t ret;
struct libusb_device_handle *handle = NULL;
*usbBulkHandle = malloc(sizeof(T_HalUsbBulkObj));
if (*usbBulkHandle == NULL) {
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
if (usbBulkInfo.isUsbHost == true) {
#ifdef LIBUSB_INSTALLED
ret = libusb_init(NULL);
if (ret < 0) {
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
handle = libusb_open_device_with_vid_pid(NULL, usbBulkInfo.vid, usbBulkInfo.pid);
if (handle == NULL) {
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
ret = libusb_claim_interface(handle, usbBulkInfo.channelInfo.interfaceNum);
if (ret != LIBUSB_SUCCESS) {
printf("libusb claim interface error");
libusb_close(handle);
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
((T_HalUsbBulkObj *) *usbBulkHandle)->handle = handle;
memcpy(&((T_HalUsbBulkObj *) *usbBulkHandle)->usbBulkInfo, &usbBulkInfo, sizeof(usbBulkInfo));
#endif
} else {
((T_HalUsbBulkObj *) *usbBulkHandle)->handle = handle;
memcpy(&((T_HalUsbBulkObj *) *usbBulkHandle)->usbBulkInfo, &usbBulkInfo, sizeof(usbBulkInfo));
((T_HalUsbBulkObj *) *usbBulkHandle)->interfaceNum = usbBulkInfo.channelInfo.interfaceNum;
if (usbBulkInfo.channelInfo.interfaceNum == LINUX_USB_BULK1_INTERFACE_NUM) {
((T_HalUsbBulkObj *) *usbBulkHandle)->ep1 = open(LINUX_USB_BULK1_EP_OUT_FD, O_RDWR);
if (((T_HalUsbBulkObj *) *usbBulkHandle)->ep1 < 0) {
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
((T_HalUsbBulkObj *) *usbBulkHandle)->ep2 = open(LINUX_USB_BULK1_EP_IN_FD, O_RDWR);
if (((T_HalUsbBulkObj *) *usbBulkHandle)->ep2 < 0) {
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
} else if (usbBulkInfo.channelInfo.interfaceNum == LINUX_USB_BULK2_INTERFACE_NUM) {
((T_HalUsbBulkObj *) *usbBulkHandle)->ep1 = open(LINUX_USB_BULK2_EP_OUT_FD, O_RDWR);
if (((T_HalUsbBulkObj *) *usbBulkHandle)->ep1 < 0) {
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
((T_HalUsbBulkObj *) *usbBulkHandle)->ep2 = open(LINUX_USB_BULK2_EP_IN_FD, O_RDWR);
if (((T_HalUsbBulkObj *) *usbBulkHandle)->ep2 < 0) {
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
}
}
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_ZiyanReturnCode HalUsbBulk_DeInit(T_ZiyanUsbBulkHandle usbBulkHandle)
{
struct libusb_device_handle *handle = NULL;
T_ZiyanOsalHandler *osalHandler = ZiyanPlatform_GetOsalHandler();
if (usbBulkHandle == NULL) {
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
handle = ((T_HalUsbBulkObj *) usbBulkHandle)->handle;
if (((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.isUsbHost == true) {
#ifdef LIBUSB_INSTALLED
libusb_release_interface(handle, ((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.channelInfo.interfaceNum);
osalHandler->TaskSleepMs(100);
libusb_exit(NULL);
#endif
} else {
close(((T_HalUsbBulkObj *) usbBulkHandle)->ep1);
close(((T_HalUsbBulkObj *) usbBulkHandle)->ep2);
}
free(usbBulkHandle);
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_ZiyanReturnCode HalUsbBulk_WriteData(T_ZiyanUsbBulkHandle usbBulkHandle, const uint8_t *buf, uint32_t len,
uint32_t *realLen)
{
int32_t ret;
int32_t actualLen;
struct libusb_device_handle *handle = NULL;
if (usbBulkHandle == NULL) {
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
handle = ((T_HalUsbBulkObj *) usbBulkHandle)->handle;
if (((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.isUsbHost == true) {
#ifdef LIBUSB_INSTALLED
ret = libusb_bulk_transfer(handle, ((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.channelInfo.endPointOut,
(uint8_t *) buf, len, &actualLen, LINUX_USB_BULK_TRANSFER_TIMEOUT_MS);
if (ret < 0) {
USER_LOG_ERROR("Write usb bulk data failed, errno = %d", ret);
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
*realLen = actualLen;
#endif
} else {
*realLen = write(((T_HalUsbBulkObj *) usbBulkHandle)->ep1, buf, len);
}
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_ZiyanReturnCode HalUsbBulk_ReadData(T_ZiyanUsbBulkHandle usbBulkHandle, uint8_t *buf, uint32_t len,
uint32_t *realLen)
{
int32_t ret;
struct libusb_device_handle *handle = NULL;
int32_t actualLen;
if (usbBulkHandle == NULL) {
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
handle = ((T_HalUsbBulkObj *) usbBulkHandle)->handle;
if (((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.isUsbHost == true) {
#ifdef LIBUSB_INSTALLED
ret = libusb_bulk_transfer(handle, ((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.channelInfo.endPointIn,
buf, len, &actualLen, LINUX_USB_BULK_TRANSFER_WAIT_FOREVER);
if (ret < 0) {
USER_LOG_ERROR("Read usb bulk data failed, errno = %d", ret);
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR;
}
*realLen = actualLen;
#endif
} else {
*realLen = read(((T_HalUsbBulkObj *) usbBulkHandle)->ep2, buf, len);
}
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
T_ZiyanReturnCode HalUsbBulk_GetDeviceInfo(T_ZiyanHalUsbBulkDeviceInfo *deviceInfo)
{
//attention: this interface only be called in usb device mode.
deviceInfo->vid = LINUX_USB_VID;
deviceInfo->pid = LINUX_USB_PID;
// This bulk channel is used to obtain ZIYAN camera video stream and push 3rd-party camera video stream.
deviceInfo->channelInfo[ZIYAN_HAL_USB_BULK_NUM_0].interfaceNum = LINUX_USB_BULK1_INTERFACE_NUM;
deviceInfo->channelInfo[ZIYAN_HAL_USB_BULK_NUM_0].endPointIn = LINUX_USB_BULK1_END_POINT_IN;
deviceInfo->channelInfo[ZIYAN_HAL_USB_BULK_NUM_0].endPointOut = LINUX_USB_BULK1_END_POINT_OUT;
// This bulk channel is used to obtain ZIYAN perception image and download camera media file.
deviceInfo->channelInfo[ZIYAN_HAL_USB_BULK_NUM_1].interfaceNum = LINUX_USB_BULK2_INTERFACE_NUM;
deviceInfo->channelInfo[ZIYAN_HAL_USB_BULK_NUM_1].endPointIn = LINUX_USB_BULK2_END_POINT_IN;
deviceInfo->channelInfo[ZIYAN_HAL_USB_BULK_NUM_1].endPointOut = LINUX_USB_BULK2_END_POINT_OUT;
return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
/* Private functions definition-----------------------------------------------*/
/****************** (C) COPYRIGHT ZIYAN Innovations *****END OF FILE****/
... ...
/**
********************************************************************
* @file hal_usb_bulk.h
* @brief This is the header file for "hal_usb_bulk.c", defining the structure and
* (exported) function prototypes.
*
* @copyright (c) 2021 ZIYAN. All rights reserved.
*
* All information contained herein is, and remains, the property of ZIYAN.
* The intellectual and technical concepts contained herein are proprietary
* to ZIYAN 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 ZIYAN.
*
* If you receive this source code without ZIYAN’s authorization, you may not
* further disseminate the information, and you must immediately remove the
* source code and notify ZIYAN of its removal. ZIYAN 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 HAL_USB_BULK_H
#define HAL_USB_BULK_H
/* Includes ------------------------------------------------------------------*/
#include "stdint.h"
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#ifdef LIBUSB_INSTALLED
#include <libusb-1.0/libusb.h>
#endif
#include "ziyan_platform.h"
#ifdef __cplusplus
extern "C" {
#endif
/* Exported constants --------------------------------------------------------*/
#define LINUX_USB_BULK1_EP_OUT_FD "/dev/usb-ffs/bulk1/ep1"
#define LINUX_USB_BULK1_EP_IN_FD "/dev/usb-ffs/bulk1/ep2"
#define LINUX_USB_BULK1_INTERFACE_NUM (7)
#define LINUX_USB_BULK1_END_POINT_IN (0x88)
#define LINUX_USB_BULK1_END_POINT_OUT (5)
#define LINUX_USB_BULK2_EP_OUT_FD "/dev/usb-ffs/bulk2/ep1"
#define LINUX_USB_BULK2_EP_IN_FD "/dev/usb-ffs/bulk2/ep2"
#define LINUX_USB_BULK2_INTERFACE_NUM (8)
#define LINUX_USB_BULK2_END_POINT_IN (0x89)
#define LINUX_USB_BULK2_END_POINT_OUT (6)
#ifdef PLATFORM_ARCH_x86_64
#define LINUX_USB_VID (0x0B95)
#define LINUX_USB_PID (0x1790)
#else
#define LINUX_USB_VID (0x0955)
#define LINUX_USB_PID (0x7020)
#endif
/* Exported types ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
T_ZiyanReturnCode HalUsbBulk_Init(T_ZiyanHalUsbBulkInfo usbBulkInfo, T_ZiyanUsbBulkHandle *usbBulkHandle);
T_ZiyanReturnCode HalUsbBulk_DeInit(T_ZiyanUsbBulkHandle usbBulkHandle);
T_ZiyanReturnCode HalUsbBulk_WriteData(T_ZiyanUsbBulkHandle usbBulkHandle, const uint8_t *buf, uint32_t len,
uint32_t *realLen);
T_ZiyanReturnCode HalUsbBulk_ReadData(T_ZiyanUsbBulkHandle usbBulkHandle, uint8_t *buf, uint32_t len, uint32_t *realLen);
T_ZiyanReturnCode HalUsbBulk_GetDeviceInfo(T_ZiyanHalUsbBulkDeviceInfo *deviceInfo);
#ifdef __cplusplus
}
#endif
#endif // HAL_USB_BULK_H
/************************ (C) COPYRIGHT ZIYAN Innovations *******END OF FILE******/
... ...