正在显示
29 个修改的文件
包含
2015 行增加
和
51 行删除
| @@ -3,8 +3,11 @@ | @@ -3,8 +3,11 @@ | ||
| 3 | { | 3 | { |
| 4 | "name": "Win32", | 4 | "name": "Win32", |
| 5 | "includePath": [ | 5 | "includePath": [ |
| 6 | - "${workspaceFolder}/**", | ||
| 7 | - "${workspaceFolder}/linux_kernel/include/**" | 6 | + "${workspaceFolder}/JZsdk_Common/**", |
| 7 | + "${workspaceFolder}/JZsdk_Config/**", | ||
| 8 | + "${workspaceFolder}/JZsdk_hal/**", | ||
| 9 | + "${workspaceFolder}/Module/**", | ||
| 10 | + //"${workspaceFolder}/linux_kernel/include/**" | ||
| 8 | ], | 11 | ], |
| 9 | "defines": [ | 12 | "defines": [ |
| 10 | "_DEBUG", | 13 | "_DEBUG", |
| @@ -12,7 +15,8 @@ | @@ -12,7 +15,8 @@ | ||
| 12 | "_UNICODE" | 15 | "_UNICODE" |
| 13 | ], | 16 | ], |
| 14 | "cStandard": "c99", | 17 | "cStandard": "c99", |
| 15 | - "intelliSenseMode": "${default}" | 18 | + //"intelliSenseMode": "${default}" |
| 19 | + "intelliSenseMode": "${Tag Parser}" | ||
| 16 | } | 20 | } |
| 17 | ], | 21 | ], |
| 18 | "version": 4 | 22 | "version": 4 |
| @@ -172,7 +172,9 @@ | @@ -172,7 +172,9 @@ | ||
| 172 | "ifybak3": "c", | 172 | "ifybak3": "c", |
| 173 | "jz_h150a.h": "c", | 173 | "jz_h150a.h": "c", |
| 174 | "jzsdk_framesequencequeue.h": "c", | 174 | "jzsdk_framesequencequeue.h": "c", |
| 175 | - "searchlighttemcontrol.h": "c" | 175 | + "searchlighttemcontrol.h": "c", |
| 176 | + "*.bak已改好": "c", | ||
| 177 | + "ziyan_platform.h": "c" | ||
| 176 | }, | 178 | }, |
| 177 | "Codegeex.GenerationPreference": "automatic", | 179 | "Codegeex.GenerationPreference": "automatic", |
| 178 | "C_Cpp.dimInactiveRegions": false, | 180 | "C_Cpp.dimInactiveRegions": false, |
| @@ -155,6 +155,7 @@ typedef enum { | @@ -155,6 +155,7 @@ typedef enum { | ||
| 155 | JZ_INSCODE_5AFRAME_SEARCHLIGHT_MESSAGE_SUBSCRIPTION_CONTROL = 0x10000E21,//探照灯消息订阅控制 | 155 | JZ_INSCODE_5AFRAME_SEARCHLIGHT_MESSAGE_SUBSCRIPTION_CONTROL = 0x10000E21,//探照灯消息订阅控制 |
| 156 | 156 | ||
| 157 | JZ_INSCODE_5AFRAME_WARNINGLIGHT_CONTROL = 0x10000F00, //警示灯模式控制 | 157 | JZ_INSCODE_5AFRAME_WARNINGLIGHT_CONTROL = 0x10000F00, //警示灯模式控制 |
| 158 | + JZ_INSCODE_5AFRAME_WARNINGLIGHT_CONTROL_2 = 0x10000F01, //警示灯模式控制2 | ||
| 158 | JZ_INSCODE_5AFRAME_WARNINGLIGHT_COLOUR = 0x10000F10, //警示灯颜色控制 | 159 | JZ_INSCODE_5AFRAME_WARNINGLIGHT_COLOUR = 0x10000F10, //警示灯颜色控制 |
| 159 | 160 | ||
| 160 | JZ_INSCODE_5AFRAME_OUTPUTPOWER_CONTROL = 0x10001000, //对外供电开关 | 161 | JZ_INSCODE_5AFRAME_OUTPUTPOWER_CONTROL = 0x10001000, //对外供电开关 |
| @@ -193,6 +193,15 @@ int JZsdk_GetFrameTemplate(int InsCode ,char *str, int *str_len) | @@ -193,6 +193,15 @@ int JZsdk_GetFrameTemplate(int InsCode ,char *str, int *str_len) | ||
| 193 | } | 193 | } |
| 194 | break; | 194 | break; |
| 195 | 195 | ||
| 196 | + case JZ_INSCODE_5AFRAME_WARNINGLIGHT_CONTROL_2: | ||
| 197 | + { | ||
| 198 | + char sendbuf[12] = {0x5A ,0x5A ,0x77 ,0x00 ,0x0C ,0x00 ,0x00 ,0x66 ,0x52 ,0x00 ,0x00 ,0x23}; | ||
| 199 | + memcpy(str, sendbuf, 12); | ||
| 200 | + *str_len = 12; | ||
| 201 | + } | ||
| 202 | + break; | ||
| 203 | + | ||
| 204 | + | ||
| 196 | case JZ_INSCODE_5AFRAME_WARNINGLIGHT_COLOUR: | 205 | case JZ_INSCODE_5AFRAME_WARNINGLIGHT_COLOUR: |
| 197 | { | 206 | { |
| 198 | char sendbuf[13] = {0x5A ,0x5A ,0x77 ,0x00 ,0x0D ,0x00 ,0x00 ,0x67 ,0x51 ,0x00 ,0x00 ,0x00 ,0x23}; | 207 | 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 | @@ -71,21 +71,45 @@ static T_JZsdkReturnCode JZsdk_Check_Src32(unsigned char *DIR, unsigned char *ch | ||
| 71 | static T_JZsdkReturnCode JZsdk_Check_Md5(unsigned char *DIR, unsigned char *checksum, unsigned int checksum_len) | 71 | static T_JZsdkReturnCode JZsdk_Check_Md5(unsigned char *DIR, unsigned char *checksum, unsigned int checksum_len) |
| 72 | { | 72 | { |
| 73 | T_JZsdkReturnCode ret = JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | 73 | T_JZsdkReturnCode ret = JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; |
| 74 | + | ||
| 75 | + // 验证输入有效性 | ||
| 76 | + if (!DIR || !checksum || checksum_len != 32) { | ||
| 77 | + JZSDK_LOG_ERROR("无效的输入参数"); | ||
| 78 | + return JZ_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER; | ||
| 79 | + } | ||
| 74 | 80 | ||
| 75 | //1、获取文件的md5校验码 | 81 | //1、获取文件的md5校验码 |
| 76 | unsigned char cmd[256]; | 82 | unsigned char cmd[256]; |
| 77 | - unsigned char md5[32]; | 83 | + unsigned char raw_output[128] = {0}; // 存储完整命令行输出 |
| 84 | + unsigned char md5[33]; | ||
| 78 | memset(cmd,0,sizeof(cmd)); | 85 | memset(cmd,0,sizeof(cmd)); |
| 79 | - snprintf(cmd, sizeof(cmd), "md5sum %s", DIR); | ||
| 80 | - JZsdk_RunSystemCmd_ReturnResult_Str(cmd, md5); | 86 | + |
| 87 | + // 构造安全命令 | ||
| 88 | + snprintf(cmd, sizeof(cmd), "md5sum '%.200s'", DIR); | ||
| 89 | + | ||
| 90 | + // 执行命令获取输出 | ||
| 91 | + if (JZsdk_RunSystemCmd_ReturnResult_Str(cmd, raw_output, sizeof(raw_output)) | ||
| 92 | + != JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 93 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + // 提取MD5部分 (格式: "d41d8cd98f00b204e9800998ecf8427e filename") | ||
| 97 | + if (sscanf((const char*)raw_output, "%32s", md5) != 1) { | ||
| 98 | + JZSDK_LOG_ERROR("MD5解析失败: %s", raw_output); | ||
| 99 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + JZSDK_LOG_INFO("md5校验 原校验码:%s 下载文件校验码:%s", checksum, md5); | ||
| 81 | 103 | ||
| 82 | //对比校验码 | 104 | //对比校验码 |
| 83 | - if (memcmp(md5, checksum, 21) != 0) | 105 | + if (memcmp(md5, checksum, 32) != 0) |
| 84 | { | 106 | { |
| 85 | JZSDK_LOG_ERROR("checksum error\n"); | 107 | JZSDK_LOG_ERROR("checksum error\n"); |
| 86 | return JZ_ERROR_SYSTEM_MODULE_CODE_CHECK_CODE_ERROR; | 108 | return JZ_ERROR_SYSTEM_MODULE_CODE_CHECK_CODE_ERROR; |
| 87 | } | 109 | } |
| 88 | 110 | ||
| 111 | + JZSDK_LOG_INFO("md5 checksum success\n"); | ||
| 112 | + | ||
| 89 | return ret; | 113 | return ret; |
| 90 | } | 114 | } |
| 91 | 115 |
| @@ -82,25 +82,22 @@ T_JZsdkReturnCode JZsdk_RunSystemCmd_ReturnResult(char *systemCmd, unsigned int | @@ -82,25 +82,22 @@ T_JZsdkReturnCode JZsdk_RunSystemCmd_ReturnResult(char *systemCmd, unsigned int | ||
| 82 | 运行命令 并读取返回值 | 82 | 运行命令 并读取返回值 |
| 83 | 83 | ||
| 84 | */ | 84 | */ |
| 85 | -T_JZsdkReturnCode JZsdk_RunSystemCmd_ReturnResult_Str(char *systemCmd, unsigned char *str) | 85 | +T_JZsdkReturnCode JZsdk_RunSystemCmd_ReturnResult_Str(const char *systemCmd, unsigned char *buffer, int buf_size) |
| 86 | { | 86 | { |
| 87 | - FILE *fp; | ||
| 88 | - double temp = 0; | 87 | + FILE *fp = popen(systemCmd, "r"); |
| 88 | + if (!fp) { | ||
| 89 | + JZSDK_LOG_ERROR("执行命令失败: %s", systemCmd); | ||
| 90 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 91 | + } | ||
| 89 | 92 | ||
| 90 | - fp = popen(systemCmd, "r"); | ||
| 91 | - if (fp == NULL) { | ||
| 92 | - printf("Failed to run command\n"); | ||
| 93 | - return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | 93 | + // 安全读取单行输出 |
| 94 | + if (!fgets((char*)buffer, buf_size, fp)) { | ||
| 95 | + JZSDK_LOG_ERROR("命令无输出: %s", systemCmd); | ||
| 96 | + pclose(fp); | ||
| 97 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 94 | } | 98 | } |
| 95 | - | ||
| 96 | - // 读取命令的输出 | ||
| 97 | - while (fgets(str, sizeof(str)-1, fp) != NULL) | ||
| 98 | - { | ||
| 99 | - printf("%s", str); | ||
| 100 | - } | ||
| 101 | 99 | ||
| 102 | pclose(fp); | 100 | pclose(fp); |
| 103 | - | ||
| 104 | return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | 101 | return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; |
| 105 | } | 102 | } |
| 106 | 103 |
| @@ -92,7 +92,7 @@ T_JZsdkReturnCode JZsdk_check_directory_exists_posix(const char* directory_path) | @@ -92,7 +92,7 @@ T_JZsdkReturnCode JZsdk_check_directory_exists_posix(const char* directory_path) | ||
| 92 | T_JZsdkReturnCode JZsdk_Fs_ReadFileSize(const unsigned char* FilePath, int *FileSize); | 92 | T_JZsdkReturnCode JZsdk_Fs_ReadFileSize(const unsigned char* FilePath, int *FileSize); |
| 93 | T_JZsdkReturnCode JZsdk_copy_file_byC(const char* source_path, const char* dest_path); | 93 | T_JZsdkReturnCode JZsdk_copy_file_byC(const char* source_path, const char* dest_path); |
| 94 | T_JZsdkReturnCode JZsdk_RunSystemCmd_ReturnResult(char *systemCmd, unsigned int *result); | 94 | T_JZsdkReturnCode JZsdk_RunSystemCmd_ReturnResult(char *systemCmd, unsigned int *result); |
| 95 | -T_JZsdkReturnCode JZsdk_RunSystemCmd_ReturnResult_Str(char *systemCmd, unsigned char *str); | 95 | +T_JZsdkReturnCode JZsdk_RunSystemCmd_ReturnResult_Str(const char *systemCmd, unsigned char *buffer, int buf_size); |
| 96 | T_JZsdkReturnCode JZsdk_Sync(); | 96 | T_JZsdkReturnCode JZsdk_Sync(); |
| 97 | T_JZsdkReturnCode JZsdk_Osal_Stat(const char *filePath, T_JZsdkFileInfo *fileInfo); | 97 | T_JZsdkReturnCode JZsdk_Osal_Stat(const char *filePath, T_JZsdkFileInfo *fileInfo); |
| 98 | T_JZsdkReturnCode JZsdk_Osal_Rename(const char *oldFilePath, const char *newFilePath); | 98 | T_JZsdkReturnCode JZsdk_Osal_Rename(const char *oldFilePath, const char *newFilePath); |
| @@ -337,9 +337,9 @@ T_JZsdkReturnCode JZ_T40_init(int mode) | @@ -337,9 +337,9 @@ T_JZsdkReturnCode JZ_T40_init(int mode) | ||
| 337 | .Device = UART_DEV_2, | 337 | .Device = UART_DEV_2, |
| 338 | .FrameSequence = 0x20, | 338 | .FrameSequence = 0x20, |
| 339 | }; | 339 | }; |
| 340 | + //警灯模块初始化 | ||
| 340 | WarnLight_Init(WarnLightInfo); | 341 | WarnLight_Init(WarnLightInfo); |
| 341 | 342 | ||
| 342 | - | ||
| 343 | //激光初始化 | 343 | //激光初始化 |
| 344 | SideLaser_Init(); | 344 | SideLaser_Init(); |
| 345 | 345 |
| @@ -10,20 +10,20 @@ | @@ -10,20 +10,20 @@ | ||
| 10 | #define DEVICE_VERSION JZ_H150A | 10 | #define DEVICE_VERSION JZ_H150A |
| 11 | 11 | ||
| 12 | //禁止修改行 选择是串口程序 还是 psdk程序 | 12 | //禁止修改行 选择是串口程序 还是 psdk程序 |
| 13 | -#define APP_VERSION APP_UART | 13 | +#define APP_VERSION APP_PSDK |
| 14 | 14 | ||
| 15 | //禁止修改行 板子型号 | 15 | //禁止修改行 板子型号 |
| 16 | #define PLATFORM_VERSION PLATFORM_V3S | 16 | #define PLATFORM_VERSION PLATFORM_V3S |
| 17 | 17 | ||
| 18 | //禁止修改行 串口连接程序的软件版本号 | 18 | //禁止修改行 串口连接程序的软件版本号 |
| 19 | #define MAJOR_VERSION_TEN_POSITION 0 | 19 | #define MAJOR_VERSION_TEN_POSITION 0 |
| 20 | -#define MAJOR_VERSION_ONE_POSITION 0 | 20 | +#define MAJOR_VERSION_ONE_POSITION 2 |
| 21 | #define MINOR_VERSION_TEN_POSITION 0 | 21 | #define MINOR_VERSION_TEN_POSITION 0 |
| 22 | -#define MINOR_VERSION_ONE_POSITION 0 | 22 | +#define MINOR_VERSION_ONE_POSITION 1 |
| 23 | #define MODIFY_VERSION_TEN_POSITION 0 | 23 | #define MODIFY_VERSION_TEN_POSITION 0 |
| 24 | -#define MODIFY_VERSION_ONE_POSITION 2 | ||
| 25 | -#define DEBUG_VERSION_TEN_POSITION 2 | ||
| 26 | -#define DEBUG_VERSION_ONE_POSITION 2 | 24 | +#define MODIFY_VERSION_ONE_POSITION 1 |
| 25 | +#define DEBUG_VERSION_TEN_POSITION 0 | ||
| 26 | +#define DEBUG_VERSION_ONE_POSITION 0 | ||
| 27 | 27 | ||
| 28 | 28 | ||
| 29 | 29 |
| @@ -665,6 +665,7 @@ static T_JZsdkReturnCode RecvDeal_SaveAudioFileTrans_stop_and_check(int Port, ch | @@ -665,6 +665,7 @@ static T_JZsdkReturnCode RecvDeal_SaveAudioFileTrans_stop_and_check(int Port, ch | ||
| 665 | int FrameSequence = JZsdk_Get_FrameSequence(getbuf); | 665 | int FrameSequence = JZsdk_Get_FrameSequence(getbuf); |
| 666 | 666 | ||
| 667 | unsigned char checkCode[128]; | 667 | unsigned char checkCode[128]; |
| 668 | + memset(checkCode, 0, 128); | ||
| 668 | int frameLenth = ((int)getbuf[3]) << 8 | (int)getbuf[4]; | 669 | int frameLenth = ((int)getbuf[3]) << 8 | (int)getbuf[4]; |
| 669 | int CodeLenth = frameLenth - 10 - 2; | 670 | int CodeLenth = frameLenth - 10 - 2; |
| 670 | if (CodeLenth != 0) | 671 | if (CodeLenth != 0) |
| @@ -1093,10 +1094,23 @@ static T_JZsdkReturnCode RecvDeal_CheckStatus_AudioDetailMessage(int Port, char | @@ -1093,10 +1094,23 @@ static T_JZsdkReturnCode RecvDeal_CheckStatus_AudioDetailMessage(int Port, char | ||
| 1093 | } | 1094 | } |
| 1094 | 1095 | ||
| 1095 | //获取文件的md5码 | 1096 | //获取文件的md5码 |
| 1096 | - unsigned char md5[16]; | ||
| 1097 | unsigned char cmd[256]; | 1097 | unsigned char cmd[256]; |
| 1098 | + unsigned char raw_output[128] = {0}; // 存储完整命令行输出 | ||
| 1099 | + unsigned char md5[33]; | ||
| 1100 | + memset(cmd,0,sizeof(cmd)); | ||
| 1101 | + | ||
| 1098 | snprintf(cmd, sizeof(cmd), "md5sum /root/sdcard/audio/%s", AudioDetailMessage.FileName); | 1102 | snprintf(cmd, sizeof(cmd), "md5sum /root/sdcard/audio/%s", AudioDetailMessage.FileName); |
| 1099 | - JZsdk_RunSystemCmd_ReturnResult_Str(cmd, md5); | 1103 | + |
| 1104 | + // 执行命令获取输出 | ||
| 1105 | + if (JZsdk_RunSystemCmd_ReturnResult_Str(cmd, raw_output, sizeof(raw_output)) | ||
| 1106 | + != JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 1107 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 1108 | + } | ||
| 1109 | + | ||
| 1110 | + // 提取MD5部分 (格式: "d41d8cd98f00b204e9800998ecf8427e filename") | ||
| 1111 | + if (sscanf((const char*)raw_output, "%32s", md5) != 1) { | ||
| 1112 | + JZSDK_LOG_ERROR("MD5解析失败: %s", raw_output); | ||
| 1113 | + } | ||
| 1100 | 1114 | ||
| 1101 | //3、发送歌曲详细信息 | 1115 | //3、发送歌曲详细信息 |
| 1102 | // JZSDK_LOG_INFO("即将发送%s, %d, %d, %s", | 1116 | // JZSDK_LOG_INFO("即将发送%s, %d, %d, %s", |
| @@ -2397,6 +2411,7 @@ static T_JZsdkReturnCode RecvDeal_OpusTrans_stop_and_check(int Port, char *getbu | @@ -2397,6 +2411,7 @@ static T_JZsdkReturnCode RecvDeal_OpusTrans_stop_and_check(int Port, char *getbu | ||
| 2397 | 2411 | ||
| 2398 | 2412 | ||
| 2399 | unsigned char checkCode[128]; | 2413 | unsigned char checkCode[128]; |
| 2414 | + memset(checkCode, 0, 128); | ||
| 2400 | int frameLenth = ((int)getbuf[3]) << 8 | (int)getbuf[4]; | 2415 | int frameLenth = ((int)getbuf[3]) << 8 | (int)getbuf[4]; |
| 2401 | int CodeLenth = frameLenth - 10 - 2; | 2416 | int CodeLenth = frameLenth - 10 - 2; |
| 2402 | if (CodeLenth != 0) | 2417 | if (CodeLenth != 0) |
| @@ -4074,6 +4089,12 @@ static T_JZsdkReturnCode RecvDeal_ObtainTimeStamp(int Port, unsigned char *getbu | @@ -4074,6 +4089,12 @@ static T_JZsdkReturnCode RecvDeal_ObtainTimeStamp(int Port, unsigned char *getbu | ||
| 4074 | | ((uint64_t)getbuf[12] << 32) | ((uint64_t)getbuf[11] << 40) | 4089 | | ((uint64_t)getbuf[12] << 32) | ((uint64_t)getbuf[11] << 40) |
| 4075 | | ((uint64_t)getbuf[10] << 48) | ((uint64_t)getbuf[9] << 56)); | 4090 | | ((uint64_t)getbuf[10] << 48) | ((uint64_t)getbuf[9] << 56)); |
| 4076 | 4091 | ||
| 4092 | + // 打印原始字节数据 | ||
| 4093 | + // JZSDK_LOG_INFO("原始数据 [9-16]:"); | ||
| 4094 | + // for (int i = 9; i <= 16; i++) { | ||
| 4095 | + // JZSDK_LOG_INFO(" getbuf[%d] = 0x%02X", i, (unsigned char)getbuf[i]); | ||
| 4096 | + // } | ||
| 4097 | + | ||
| 4077 | JZSDK_LOG_INFO("获得时间戳 %llu",TimeStamp); | 4098 | JZSDK_LOG_INFO("获得时间戳 %llu",TimeStamp); |
| 4078 | 4099 | ||
| 4079 | // 转换为time_t(注意:这里假设TimeStamp是以秒为单位的Unix时间戳) | 4100 | // 转换为time_t(注意:这里假设TimeStamp是以秒为单位的Unix时间戳) |
| @@ -4089,11 +4110,15 @@ static T_JZsdkReturnCode RecvDeal_ObtainTimeStamp(int Port, unsigned char *getbu | @@ -4089,11 +4110,15 @@ static T_JZsdkReturnCode RecvDeal_ObtainTimeStamp(int Port, unsigned char *getbu | ||
| 4089 | } | 4110 | } |
| 4090 | 4111 | ||
| 4091 | // 提取年、月、日 | 4112 | // 提取年、月、日 |
| 4092 | - int year = tm_info->tm_year + 1980; // 注意:tm_year是从1980年开始的 | 4113 | + int year = tm_info->tm_year + 1900; |
| 4093 | int month = tm_info->tm_mon + 1; // 注意:tm_mon是从0开始的(0=1月,11=12月) | 4114 | int month = tm_info->tm_mon + 1; // 注意:tm_mon是从0开始的(0=1月,11=12月) |
| 4094 | - int day = tm_info->tm_mday + 6; | 4115 | + int day = tm_info->tm_mday; |
| 4116 | + int hour = tm_info->tm_hour; | ||
| 4117 | + int minute = tm_info->tm_min; | ||
| 4118 | + int second = tm_info->tm_sec; | ||
| 4095 | 4119 | ||
| 4096 | JZSDK_LOG_INFO("获得年份: %d, 月份: %d, 日期: %d", year, month, day); | 4120 | JZSDK_LOG_INFO("获得年份: %d, 月份: %d, 日期: %d", year, month, day); |
| 4121 | + JZSDK_LOG_INFO("获得小时: %d, 分钟: %d, 秒: %d", hour, minute, second); | ||
| 4097 | 4122 | ||
| 4098 | struct timeval tv; | 4123 | struct timeval tv; |
| 4099 | tv.tv_sec = (time_t)TimeStamp; // 注意:这里可能会有截断,如果TimeStamp非常大 | 4124 | tv.tv_sec = (time_t)TimeStamp; // 注意:这里可能会有截断,如果TimeStamp非常大 |
| @@ -1456,6 +1456,29 @@ T_JZsdkReturnCode HalSend_type1Send_Set_WarningLight_Status(int Uartport, int fr | @@ -1456,6 +1456,29 @@ T_JZsdkReturnCode HalSend_type1Send_Set_WarningLight_Status(int Uartport, int fr | ||
| 1456 | 1456 | ||
| 1457 | /************* | 1457 | /************* |
| 1458 | * | 1458 | * |
| 1459 | + * 设置警灯状态类型Ⅱ | ||
| 1460 | + * | ||
| 1461 | + * ************/ | ||
| 1462 | +T_JZsdkReturnCode HalSend_type1Send_Set_WarningLight_Status_2(int Uartport, int frameSequence, int mode) | ||
| 1463 | +{ | ||
| 1464 | + printf("发送设置警灯状态 类型2\n"); | ||
| 1465 | + | ||
| 1466 | + unsigned char sendbuf[256]; | ||
| 1467 | + int send_buf_len; | ||
| 1468 | + | ||
| 1469 | + //1、获取帧样板 | ||
| 1470 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5AFRAME_WARNINGLIGHT_CONTROL_2, sendbuf, &send_buf_len); | ||
| 1471 | + | ||
| 1472 | + //2、写入数据 | ||
| 1473 | + sendbuf[6] = frameSequence; | ||
| 1474 | + sendbuf[9] = mode; | ||
| 1475 | + | ||
| 1476 | + //3、发送帧 | ||
| 1477 | + HalSend_SendData(Uartport ,sendbuf, send_buf_len, MULTI_THREAD_SEND); | ||
| 1478 | +} | ||
| 1479 | + | ||
| 1480 | +/************* | ||
| 1481 | + * | ||
| 1459 | * 设置警灯颜色 | 1482 | * 设置警灯颜色 |
| 1460 | * | 1483 | * |
| 1461 | * **************/ | 1484 | * **************/ |
| @@ -25,8 +25,10 @@ T_JZsdkReturnCode DebugInfo_Init() | @@ -25,8 +25,10 @@ T_JZsdkReturnCode DebugInfo_Init() | ||
| 25 | return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | 25 | return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; |
| 26 | 26 | ||
| 27 | #endif | 27 | #endif |
| 28 | + | ||
| 28 | if (JZsdk_check_file_exists("/root/ShakedownTest") != JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS) | 29 | if (JZsdk_check_file_exists("/root/ShakedownTest") != JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS) |
| 29 | { | 30 | { |
| 31 | + JZSDK_LOG_DEBUG("未存在调试文件"); | ||
| 30 | return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | 32 | return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; |
| 31 | } | 33 | } |
| 32 | 34 | ||
| @@ -38,7 +40,6 @@ T_JZsdkReturnCode DebugInfo_Init() | @@ -38,7 +40,6 @@ T_JZsdkReturnCode DebugInfo_Init() | ||
| 38 | JZSDK_LOG_ERROR("移除调试模式失败"); | 40 | JZSDK_LOG_ERROR("移除调试模式失败"); |
| 39 | } | 41 | } |
| 40 | 42 | ||
| 41 | - | ||
| 42 | return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | 43 | return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; |
| 43 | } | 44 | } |
| 44 | 45 | ||
| @@ -60,7 +61,7 @@ T_JZsdkReturnCode DebugInfo_ModeSet(int mode) | @@ -60,7 +61,7 @@ T_JZsdkReturnCode DebugInfo_ModeSet(int mode) | ||
| 60 | return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | 61 | return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; |
| 61 | } | 62 | } |
| 62 | 63 | ||
| 63 | - if (mode == JZ_FLAGCODE_OFF) | 64 | + else if (mode == JZ_FLAGCODE_OFF) |
| 64 | { | 65 | { |
| 65 | if(JZsdk_Osal_delete("/root/ShakedownTest") == JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS) | 66 | if(JZsdk_Osal_delete("/root/ShakedownTest") == JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS) |
| 66 | { | 67 | { |
| @@ -826,6 +826,7 @@ T_JZsdkReturnCode AudioFile_SaveAudioFileStop(int checkFlag, unsigned char *Chec | @@ -826,6 +826,7 @@ T_JZsdkReturnCode AudioFile_SaveAudioFileStop(int checkFlag, unsigned char *Chec | ||
| 826 | fflush(g_AudioFile_SaveAudioFile_NameFp); | 826 | fflush(g_AudioFile_SaveAudioFile_NameFp); |
| 827 | fclose(g_AudioFile_SaveAudioFile_NameFp); | 827 | fclose(g_AudioFile_SaveAudioFile_NameFp); |
| 828 | g_AudioFile_SaveAudioFile_NameFp = NULL; | 828 | g_AudioFile_SaveAudioFile_NameFp = NULL; |
| 829 | + JZSDK_LOG_INFO("传输得到的音频大小为:%d", g_AudioFile_SaveAudioFile_len); | ||
| 829 | g_AudioFile_SaveAudioFile_len = 0; //置零长度 | 830 | g_AudioFile_SaveAudioFile_len = 0; //置零长度 |
| 830 | 831 | ||
| 831 | JZsdk_Sync(); | 832 | JZsdk_Sync(); |
| @@ -34,7 +34,15 @@ T_JZsdkReturnCode WarnLight_Set_StatusAndMode(int status, int mode) | @@ -34,7 +34,15 @@ T_JZsdkReturnCode WarnLight_Set_StatusAndMode(int status, int mode) | ||
| 34 | U8_t FrameSequence = g_WarnLightInfo.FrameSequence; | 34 | U8_t FrameSequence = g_WarnLightInfo.FrameSequence; |
| 35 | osalHandle->GetFrameSequenceQueueNum(&FrameSequence); | 35 | osalHandle->GetFrameSequenceQueueNum(&FrameSequence); |
| 36 | 36 | ||
| 37 | - HalSend_type1Send_Set_WarningLight_Status(g_WarnLightInfo.Device, FrameSequence, status, mode); | 37 | + //模式版本 |
| 38 | + if(g_WarnLightInfo.mode_version == 0) | ||
| 39 | + { | ||
| 40 | + HalSend_type1Send_Set_WarningLight_Status(g_WarnLightInfo.Device, FrameSequence, status, mode); | ||
| 41 | + } | ||
| 42 | + else if(g_WarnLightInfo.mode_version == 1) | ||
| 43 | + { | ||
| 44 | + | ||
| 45 | + } | ||
| 38 | 46 | ||
| 39 | g_WarnLightInfo.Attribute.mode = mode; | 47 | g_WarnLightInfo.Attribute.mode = mode; |
| 40 | g_WarnLightInfo.Attribute.status = status; | 48 | g_WarnLightInfo.Attribute.status = status; |
| @@ -23,7 +23,7 @@ extern "C" { | @@ -23,7 +23,7 @@ extern "C" { | ||
| 23 | /* Exported types ------------------------------------------------------------*/ | 23 | /* Exported types ------------------------------------------------------------*/ |
| 24 | typedef struct T_JzWarnLightAttribute{ | 24 | typedef struct T_JzWarnLightAttribute{ |
| 25 | int mode; //模式 | 25 | int mode; //模式 |
| 26 | - | 26 | + int mode_version; //模式的版本 |
| 27 | int status; //状态 | 27 | int status; //状态 |
| 28 | int Color1; //颜色1 | 28 | int Color1; //颜色1 |
| 29 | int Color2; //颜色2 | 29 | int Color2; //颜色2 |
| @@ -53,6 +53,14 @@ typedef enum E_JzWarnLightMode{ | @@ -53,6 +53,14 @@ typedef enum E_JzWarnLightMode{ | ||
| 53 | E_JZ_WARNLIGHT_MODE_SIMULTANEOUS_SLOW_FALSHING = 4, //同时慢速闪烁 | 53 | E_JZ_WARNLIGHT_MODE_SIMULTANEOUS_SLOW_FALSHING = 4, //同时慢速闪烁 |
| 54 | }E_JzWarnLightMode; | 54 | }E_JzWarnLightMode; |
| 55 | 55 | ||
| 56 | +typedef enum E_JzWarnLightMode2{ | ||
| 57 | + E_JZ_WARNLIGHT_MODE_2_RED_BULE_WARN = 1, //红蓝警示模式 | ||
| 58 | + E_JZ_WARNLIGHT_MODE_2_YELLOW_WARN = 2, //黄闪减速模式 | ||
| 59 | + E_JZ_WARNLIGHT_MODE_2_RED_WARN = 3, //红闪停车模式 | ||
| 60 | + E_JZ_WARNLIGHT_MODE_2_GREEN_WARN = 4, //绿闪通行模式 | ||
| 61 | + E_JZ_WARNLIGHT_MODE_2_RAINBOW_WARN = 5, //彩色闪烁模式 | ||
| 62 | +}E_JzWarnLightMode2; | ||
| 63 | + | ||
| 56 | /* Exported functions --------------------------------------------------------*/ | 64 | /* Exported functions --------------------------------------------------------*/ |
| 57 | T_JZsdkReturnCode WarnLight_Set_StatusAndMode(int status, int mode); | 65 | T_JZsdkReturnCode WarnLight_Set_StatusAndMode(int status, int mode); |
| 58 | T_JZsdkReturnCode WarnLight_Set_Color(int Color1, int Color2); | 66 | T_JZsdkReturnCode WarnLight_Set_Color(int Color1, int Color2); |
| @@ -37,7 +37,7 @@ extern "C" { | @@ -37,7 +37,7 @@ extern "C" { | ||
| 37 | #define DJI_VERSION_MINOR 12 /*!< DJI SDK minor version num, when add functionality in a backwards compatible manner changes. Range from 0 to 99. */ | 37 | #define DJI_VERSION_MINOR 12 /*!< DJI SDK minor version num, when add functionality in a backwards compatible manner changes. Range from 0 to 99. */ |
| 38 | #define DJI_VERSION_MODIFY 0 /*!< DJI SDK modify version num, when have backwards compatible bug fixes changes. Range from 0 to 99. */ | 38 | #define DJI_VERSION_MODIFY 0 /*!< DJI SDK modify version num, when have backwards compatible bug fixes changes. Range from 0 to 99. */ |
| 39 | #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. */ | 39 | #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. */ |
| 40 | -#define DJI_VERSION_BUILD 2254 /*!< DJI SDK version build info, when jenkins trigger build changes. Range from 0 to 65535. */ | 40 | +#define DJI_VERSION_BUILD 2257 /*!< DJI SDK version build info, when jenkins trigger build changes. Range from 0 to 65535. */ |
| 41 | 41 | ||
| 42 | /* Exported types ------------------------------------------------------------*/ | 42 | /* Exported types ------------------------------------------------------------*/ |
| 43 | 43 |
| @@ -52,6 +52,18 @@ | @@ -52,6 +52,18 @@ | ||
| 52 | 52 | ||
| 53 | #endif | 53 | #endif |
| 54 | 54 | ||
| 55 | +#ifdef WARNLIGHT_STATUS_ON | ||
| 56 | + | ||
| 57 | +#include "WarnLight/WarnLight.h" | ||
| 58 | + | ||
| 59 | +#endif | ||
| 60 | + | ||
| 61 | +#ifdef SEARCHLIGHT_STATUS_ON | ||
| 62 | + | ||
| 63 | +#include "SearchLight/SearchLight.h" | ||
| 64 | + | ||
| 65 | +#endif | ||
| 66 | + | ||
| 55 | #include "MediaProc/MediaProc.h" | 67 | #include "MediaProc/MediaProc.h" |
| 56 | #include "DeviceInfo/DeviceInfo.h" | 68 | #include "DeviceInfo/DeviceInfo.h" |
| 57 | 69 | ||
| @@ -156,14 +168,7 @@ static const T_DjiWidgetHandlerListItem s_widgetHandlerList[] = { | @@ -156,14 +168,7 @@ static const T_DjiWidgetHandlerListItem s_widgetHandlerList[] = { | ||
| 156 | }; | 168 | }; |
| 157 | 169 | ||
| 158 | static const uint32_t s_widgetHandlerListCount = sizeof(s_widgetHandlerList) / sizeof(T_DjiWidgetHandlerListItem); | 170 | static const uint32_t s_widgetHandlerListCount = sizeof(s_widgetHandlerList) / sizeof(T_DjiWidgetHandlerListItem); |
| 159 | -int32_t s_widgetValueList[] = { OFF, OFF, PLAY_PAUSE, 30, 30, PLAY_SPEED_X1, 0, OFF,OFF,OFF, //喊话器部分 | ||
| 160 | - OFF, OFF, OFF, OFF, 50, OFF, //探照灯部分 | ||
| 161 | - 0, 0, 2, //警灯部分 | ||
| 162 | - 100, 100 ,ON ,OFF,OFF, //云台部分 | ||
| 163 | - OFF ,OFF, //系统部分 | ||
| 164 | - OFF,OFF, //调试部分 | ||
| 165 | - 0,0, | ||
| 166 | - 0,0,0,0}; //调试部分 | 171 | +int32_t s_widgetValueList[s_widgetHandlerListCount = sizeof(s_widgetHandlerList) / sizeof(T_DjiWidgetHandlerListItem)] = {0}; |
| 167 | 172 | ||
| 168 | #endif | 173 | #endif |
| 169 | 174 | ||
| @@ -203,7 +208,58 @@ static const T_DjiWidgetHandlerListItem s_widgetHandlerList[] = { | @@ -203,7 +208,58 @@ static const T_DjiWidgetHandlerListItem s_widgetHandlerList[] = { | ||
| 203 | }; | 208 | }; |
| 204 | 209 | ||
| 205 | static const uint32_t s_widgetHandlerListCount = sizeof(s_widgetHandlerList) / sizeof(T_DjiWidgetHandlerListItem); | 210 | static const uint32_t s_widgetHandlerListCount = sizeof(s_widgetHandlerList) / sizeof(T_DjiWidgetHandlerListItem); |
| 206 | -int32_t s_widgetValueList[] = {VIDEOMGMT_STREAMING_FLOW_INDEX_FIRST, //视频流 | 211 | +int32_t s_widgetValueList[sizeof(s_widgetHandlerList) / sizeof(T_DjiWidgetHandlerListItem)] = {0}; |
| 212 | + | ||
| 213 | +#endif | ||
| 214 | + | ||
| 215 | + | ||
| 216 | +static T_JZsdkReturnCode WidgetRead() | ||
| 217 | +{ | ||
| 218 | + //将设备里的控件值读到控件结构体中 | ||
| 219 | + int WidetTempList[sizeof(s_widgetHandlerList) / sizeof(T_DjiWidgetHandlerListItem)] = {0}; | ||
| 220 | + | ||
| 221 | +#ifdef MEGAPHONE_CONFIG_STATUS_ON | ||
| 222 | + | ||
| 223 | + //赋予控件结构体初始值 | ||
| 224 | + WidetTempList[] = { OFF, OFF, PLAY_PAUSE, 30, 30, PLAY_SPEED_X1, 0, OFF,OFF,OFF, //喊话器部分 | ||
| 225 | + OFF, OFF, OFF, OFF, 50, OFF, //探照灯部分 | ||
| 226 | + 0, 0, 2, //警灯部分 | ||
| 227 | + 100, 100 ,ON ,OFF,OFF, //云台部分 | ||
| 228 | + OFF ,OFF, //系统部分 | ||
| 229 | + OFF,OFF, //调试部分 | ||
| 230 | + 0,0, | ||
| 231 | + 0,0,0,0}; //调试部分 | ||
| 232 | + | ||
| 233 | + | ||
| 234 | + //读取探照灯部分 | ||
| 235 | + #ifdef SEARCHLIGHT_STATUS_ON | ||
| 236 | + T_JzSearchLightAttribute SearchLightInfo; | ||
| 237 | + SearchLight_Get_SearchLightAttribute(&SearchLightInfo); | ||
| 238 | + | ||
| 239 | + WidetTempList[10] = JZ_MATH_MAX(SearchLightInfo.LeftBrightness, SearchLightInfo.RightBrightness); | ||
| 240 | + WidetTempList[11] = JZ_MATH_MAX(SearchLightInfo.LeftBrightness, SearchLightInfo.RightBrightness); | ||
| 241 | + WidetTempList[12] = SearchLightInfo.Mode; | ||
| 242 | + WidetTempList[14] = SearchLightInfo.Frequency; | ||
| 243 | + #endif | ||
| 244 | + | ||
| 245 | + //读取警灯部分 | ||
| 246 | + #ifdef WARNLIGHT_STATUS_ON | ||
| 247 | + T_JzWarnLightAttribute WarnLightInfo; | ||
| 248 | + WarnLight_Get_Attribute(&WarnLightInfo); | ||
| 249 | + | ||
| 250 | + WidetTempList[16] = WarnLightInfo.mode; | ||
| 251 | + WidetTempList[17] = WarnLightInfo.Color1; | ||
| 252 | + WidetTempList[18] = WarnLightInfo.Color2; | ||
| 253 | + #endif | ||
| 254 | + | ||
| 255 | + //将控件结构体中的值写入设备 | ||
| 256 | + memcpy(s_widgetValueList, WidetTempList, sizeof(s_widgetValueList)); | ||
| 257 | +#endif | ||
| 258 | + | ||
| 259 | +#ifdef IRC_CONFIG_STATUS_ON | ||
| 260 | + | ||
| 261 | + //赋予控件结构体初始值 | ||
| 262 | + WidetTempList[] = {VIDEOMGMT_STREAMING_FLOW_INDEX_FIRST, //视频流 | ||
| 207 | OFF, //测温模式 | 263 | OFF, //测温模式 |
| 208 | ON, //光圈开关 | 264 | ON, //光圈开关 |
| 209 | OFF, //冻结开关 | 265 | OFF, //冻结开关 |
| @@ -225,17 +281,24 @@ int32_t s_widgetValueList[] = {VIDEOMGMT_STREAMING_FLOW_INDEX_FIRST, //视频 | @@ -225,17 +281,24 @@ int32_t s_widgetValueList[] = {VIDEOMGMT_STREAMING_FLOW_INDEX_FIRST, //视频 | ||
| 225 | OFF, | 281 | OFF, |
| 226 | OFF, | 282 | OFF, |
| 227 | OFF, | 283 | OFF, |
| 228 | - OFF | ||
| 229 | -}; | 284 | + OFF}; //调试部分 |
| 285 | + | ||
| 286 | + //将控件结构体中的值写入设备 | ||
| 287 | + memcpy(s_widgetValueList, WidetTempList, sizeof(s_widgetValueList)); | ||
| 230 | #endif | 288 | #endif |
| 231 | 289 | ||
| 232 | 290 | ||
| 233 | 291 | ||
| 292 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 293 | +} | ||
| 234 | 294 | ||
| 235 | 295 | ||
| 236 | /* Exported functions definition ---------------导出函数定义——------------------------------*/ | 296 | /* Exported functions definition ---------------导出函数定义——------------------------------*/ |
| 237 | T_DjiReturnCode DjiTest_WidgetStartService(void) | 297 | T_DjiReturnCode DjiTest_WidgetStartService(void) |
| 238 | { | 298 | { |
| 299 | + //将设备里的控件值读到控件结构体中 | ||
| 300 | + WidgetRead(); | ||
| 301 | + | ||
| 239 | T_DjiReturnCode djiStat; | 302 | T_DjiReturnCode djiStat; |
| 240 | T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler(); | 303 | T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler(); |
| 241 | 304 |
| @@ -47,7 +47,8 @@ extern "C" { | @@ -47,7 +47,8 @@ extern "C" { | ||
| 47 | 47 | ||
| 48 | /* Exported constants --------------------------------------------------------*/ | 48 | /* Exported constants --------------------------------------------------------*/ |
| 49 | //User can config dev based on there environmental conditions | 49 | //User can config dev based on there environmental conditions |
| 50 | -#define LINUX_UART_DEV1 UART_DEV1_NUM | 50 | +//#define LINUX_UART_DEV1 UART_DEV1_NUM |
| 51 | +#define LINUX_UART_DEV1 "/dev/ttyS1" | ||
| 51 | #define LINUX_UART_DEV2 "/dev/ttyACM0" | 52 | #define LINUX_UART_DEV2 "/dev/ttyACM0" |
| 52 | 53 | ||
| 53 | /* Exported types ------------------------------------------------------------*/ | 54 | /* Exported types ------------------------------------------------------------*/ |
不能预览此文件类型
| 1 | +cmake_minimum_required(VERSION 3.5) | ||
| 2 | +project(zydemo C) | ||
| 3 | + | ||
| 4 | +set(CMAKE_C_FLAGS "-pthread -std=gnu99") | ||
| 5 | +set(CMAKE_CXX_FLAGS "-std=c++11 -pthread") | ||
| 6 | +set(CMAKE_EXE_LINKER_FLAGS "-pthread") | ||
| 7 | +set(CMAKE_C_COMPILER "/usr/local/arm/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc") | ||
| 8 | +set(CMAKE_CXX_COMPILER "/usr/local/arm/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++") | ||
| 9 | +add_definitions(-D_GNU_SOURCE) | ||
| 10 | + | ||
| 11 | + | ||
| 12 | +#Strengthen Compilation Warnings - Treat All Warnings as Errors | ||
| 13 | +#Purpose: Minimize potential issues caused by syntax and compiler-specific features | ||
| 14 | +# add_definitions(-Werror) | ||
| 15 | +# add_definitions(-Wno-error=implicit-function-declaration) | ||
| 16 | + | ||
| 17 | + | ||
| 18 | +if (NOT USE_SYSTEM_ARCH) | ||
| 19 | + add_definitions(-DSYSTEM_ARCH_LINUX) | ||
| 20 | +endif () | ||
| 21 | + | ||
| 22 | +if (BUILD_TEST_CASES_ON MATCHES TRUE) | ||
| 23 | + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") | ||
| 24 | + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage") | ||
| 25 | + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage -lgcov") | ||
| 26 | +endif () | ||
| 27 | + | ||
| 28 | +set(PACKAGE_NAME payloadsdk) | ||
| 29 | + | ||
| 30 | +## "uname -m" to auto distinguish Manifold2-G or Manifold2-C | ||
| 31 | +execute_process(COMMAND uname -m | ||
| 32 | + OUTPUT_VARIABLE DEVICE_SYSTEM_ID) | ||
| 33 | + | ||
| 34 | +# if (DEVICE_SYSTEM_ID MATCHES x86_64) | ||
| 35 | +# set(TOOLCHAIN_NAME x86_64-linux-gnu) | ||
| 36 | +# add_definitions(-DPLATFORM_ARCH_x86_64=1) | ||
| 37 | +# elseif (DEVICE_SYSTEM_ID MATCHES aarch64) | ||
| 38 | +# set(TOOLCHAIN_NAME aarch64-linux-gnu) | ||
| 39 | +# add_definitions(-DPLATFORM_ARCH_aarch64=1) | ||
| 40 | +# elseif (DEVICE_SYSTEM_ID MATCHES armv7l) | ||
| 41 | + set(TOOLCHAIN_NAME arm-linux-gnueabihf) | ||
| 42 | +# add_definitions(-DPLATFORM_ARCH_arm=1) | ||
| 43 | +# else () | ||
| 44 | +# message(FATAL_ERROR "FATAL: Please confirm your platform. SYSTEM_ID:${DEVICE_SYSTEM_ID}") | ||
| 45 | +# endif () | ||
| 46 | + | ||
| 47 | + | ||
| 48 | + | ||
| 49 | +file(GLOB_RECURSE MODULE_COMMON_SRC ../common/*.c) | ||
| 50 | +file(GLOB_RECURSE MODULE_HAL_SRC hal/*.c) | ||
| 51 | +file(GLOB_RECURSE MODULE_APP_SRC application/*.c) | ||
| 52 | +file(GLOB_RECURSE MODULE_SAMPLE_SRC ../../../module_sample/*.c) | ||
| 53 | + | ||
| 54 | +include_directories(../../../module_sample) | ||
| 55 | +include_directories(../common) | ||
| 56 | +include_directories(../manifold2/application) | ||
| 57 | + | ||
| 58 | +include_directories(../../../../../psdk_lib/include) | ||
| 59 | +link_directories(../../../../../psdk_lib/lib/${TOOLCHAIN_NAME}) | ||
| 60 | +link_libraries(${CMAKE_CURRENT_LIST_DIR}/../../../../../psdk_lib/lib/${TOOLCHAIN_NAME}/lib${PACKAGE_NAME}.a) | ||
| 61 | + | ||
| 62 | +if (NOT EXECUTABLE_OUTPUT_PATH) | ||
| 63 | + set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) | ||
| 64 | +endif () | ||
| 65 | + | ||
| 66 | +add_executable(${PROJECT_NAME} | ||
| 67 | + ${MODULE_APP_SRC} | ||
| 68 | + ${MODULE_SAMPLE_SRC} | ||
| 69 | + ${MODULE_COMMON_SRC} | ||
| 70 | + ${MODULE_HAL_SRC}) | ||
| 71 | + | ||
| 72 | +target_link_libraries(${PROJECT_NAME} m stdc++) | ||
| 73 | + | ||
| 74 | +set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../common/3rdparty) | ||
| 75 | +# find_package(OPUS REQUIRED) | ||
| 76 | +# if (OPUS_FOUND) | ||
| 77 | +# message(STATUS "Found OPUS installed in the system") | ||
| 78 | +# message(STATUS " - Includes: ${OPUS_INCLUDE_DIR}") | ||
| 79 | +# message(STATUS " - Libraries: ${OPUS_LIBRARY}") | ||
| 80 | + | ||
| 81 | +# add_definitions(-DOPUS_INSTALLED) | ||
| 82 | +# target_link_libraries(${PROJECT_NAME} ${OPUS_LIBRARY}) | ||
| 83 | +# else () | ||
| 84 | +# message(STATUS "Cannot Find OPUS") | ||
| 85 | +# endif (OPUS_FOUND) | ||
| 86 | + | ||
| 87 | + | ||
| 88 | +# find_package(ASOUND REQUIRED) | ||
| 89 | +# if (ASOUND_FOUND) | ||
| 90 | +# message(STATUS "Found ASOUND installed in the system") | ||
| 91 | +# message(STATUS " - Includes: ${ASOUND_INCLUDE_DIR}") | ||
| 92 | +# message(STATUS " - Libraries: ${ASOUND_LIBRARY}") | ||
| 93 | + | ||
| 94 | +# add_definitions(-DASOUND_INSTALLED) | ||
| 95 | +# include_directories(${ASOUND_INCLUDE_DIR}) | ||
| 96 | +# target_link_libraries(${PROJECT_NAME} ${ASOUND_LIBRARIES}) | ||
| 97 | +# else() | ||
| 98 | +# message(STATUS "Cannot Find ASOUND") | ||
| 99 | +# endif() | ||
| 100 | + | ||
| 101 | + | ||
| 102 | + | ||
| 103 | +# find_package(LIBUSB REQUIRED) | ||
| 104 | +# if (LIBUSB_FOUND) | ||
| 105 | +# message(STATUS "Found LIBUSB installed in the system") | ||
| 106 | +# message(STATUS " - Includes: ${LIBUSB_INCLUDE_DIR}") | ||
| 107 | +# message(STATUS " - Libraries: ${LIBUSB_LIBRARY}") | ||
| 108 | + | ||
| 109 | +# add_definitions(-DLIBUSB_INSTALLED) | ||
| 110 | +# target_link_libraries(${PROJECT_NAME} ${LIBUSB_LIBRARY}) | ||
| 111 | +# else () | ||
| 112 | +# message(STATUS "Cannot Find LIBUSB") | ||
| 113 | +# endif (LIBUSB_FOUND) | ||
| 114 | + | ||
| 115 | + | ||
| 116 | + | ||
| 117 | +# find_package(FFMPEG REQUIRED) | ||
| 118 | +# if(FFMPEG_FOUND) | ||
| 119 | +# message(STATUS "Found FFMPEG installed in the system") | ||
| 120 | +# message(STATUS " - Includes: ${FFMPEG_INCLUDE_DIR}") | ||
| 121 | +# message(STATUS " - Libraries: ${FFMPEG_LIBRARIES}") | ||
| 122 | + | ||
| 123 | +# ADD_DEFINITIONS(-DFFMPEG_INSTALLED) | ||
| 124 | +# target_link_libraries(${PROJECT_NAME} ${FFMPEG_LIBRARIES} m stdc++) | ||
| 125 | +# else () | ||
| 126 | +# message(STATUS "Cannot Find FFMPEG") | ||
| 127 | +# endif (FFMPEG_FOUND) | ||
| 128 | + | ||
| 129 | + | ||
| 130 | + | ||
| 131 | +# # 查找 FFmpeg 库 | ||
| 132 | +# find_package(PkgConfig REQUIRED) | ||
| 133 | +# pkg_check_modules(AVFORMAT REQUIRED libavformat) | ||
| 134 | +# pkg_check_modules(AVCODEC REQUIRED libavcodec) | ||
| 135 | +# pkg_check_modules(AVUTIL REQUIRED libavutil) | ||
| 136 | + | ||
| 137 | +# # 包含 FFmpeg 头文件路径 | ||
| 138 | +# include_directories(${AVFORMAT_INCLUDE_DIRS}) | ||
| 139 | +# include_directories(${AVCODEC_INCLUDE_DIRS}) | ||
| 140 | +# include_directories(${AVUTIL_INCLUDE_DIRS}) | ||
| 141 | + | ||
| 142 | +# # 链接 FFmpeg 库 | ||
| 143 | +# target_link_libraries(${PROJECT_NAME} ${AVFORMAT_LIBRARIES} ${AVCODEC_LIBRARIES} ${AVUTIL_LIBRARIES}) | ||
| 144 | + | ||
| 145 | + | ||
| 146 | +# target_link_libraries(${PROJECT_NAME} m) | ||
| 147 | + | ||
| 148 | +# target_link_libraries(${PROJECT_NAME} stdc++) | ||
| 149 | + | ||
| 150 | +# add_custom_command(TARGET ${PROJECT_NAME} | ||
| 151 | +# PRE_LINK COMMAND cmake .. | ||
| 152 | +# WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) | ||
| 153 | + |
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file main.c | ||
| 4 | + * @brief | ||
| 5 | + * | ||
| 6 | + * @copyright (c) 2021 ZIYAN. All rights reserved. | ||
| 7 | + * | ||
| 8 | + * All information contained herein is, and remains, the property of ZIYAN. | ||
| 9 | + * The intellectual and technical concepts contained herein are proprietary | ||
| 10 | + * to ZIYAN and may be covered by U.S. and foreign patents, patents in process, | ||
| 11 | + * and protected by trade secret or copyright law. Dissemination of this | ||
| 12 | + * information, including but not limited to data and other proprietary | ||
| 13 | + * material(s) incorporated within the information, in any form, is strictly | ||
| 14 | + * prohibited without the express written consent of ZIYAN. | ||
| 15 | + * | ||
| 16 | + * If you receive this source code without ZIYAN’s authorization, you may not | ||
| 17 | + * further disseminate the information, and you must immediately remove the | ||
| 18 | + * source code and notify ZIYAN of its removal. ZIYAN reserves the right to pursue | ||
| 19 | + * legal actions against you for any loss(es) or damage(s) caused by your | ||
| 20 | + * failure to do so. | ||
| 21 | + * | ||
| 22 | + ********************************************************************* | ||
| 23 | + */ | ||
| 24 | + | ||
| 25 | +/* Includes ------------------------------------------------------------------*/ | ||
| 26 | +#include <ziyan_platform.h> | ||
| 27 | +#include <ziyan_logger.h> | ||
| 28 | +#include <ziyan_core.h> | ||
| 29 | +#include <utils/util_misc.h> | ||
| 30 | +#include <errno.h> | ||
| 31 | +#include <signal.h> | ||
| 32 | +#include "monitor/sys_monitor.h" | ||
| 33 | +#include "osal/osal.h" | ||
| 34 | +#include "osal/osal_fs.h" | ||
| 35 | +#include "osal/osal_socket.h" | ||
| 36 | +#include "../hal/hal_uart.h" | ||
| 37 | +#include "../hal/hal_network.h" | ||
| 38 | +#include "../hal/hal_usb_bulk.h" | ||
| 39 | +#include "ziyan_sdk_app_info.h" | ||
| 40 | +#include "ziyan_aircraft_info.h" | ||
| 41 | +#include "widget/test_widget.h" | ||
| 42 | +#include "ziyan_sdk_config.h" | ||
| 43 | + | ||
| 44 | +/* Private constants ---------------------------------------------------------*/ | ||
| 45 | +#define ZIYAN_LOG_PATH "Logs/ZIYAN" | ||
| 46 | +#define ZIYAN_LOG_INDEX_FILE_NAME "Logs/latest" | ||
| 47 | +#define ZIYAN_LOG_FOLDER_NAME "Logs" | ||
| 48 | +#define ZIYAN_LOG_PATH_MAX_SIZE (128) | ||
| 49 | +#define ZIYAN_LOG_FOLDER_NAME_MAX_SIZE (32) | ||
| 50 | +#define ZIYAN_LOG_MAX_COUNT (10) | ||
| 51 | +#define ZIYAN_SYSTEM_CMD_STR_MAX_SIZE (64) | ||
| 52 | +#define ZIYAN_SYSTEM_RESULT_STR_MAX_SIZE (128) | ||
| 53 | + | ||
| 54 | +#define ZIYAN_USE_WIDGET_INTERACTION 0 | ||
| 55 | + | ||
| 56 | +/* Private types -------------------------------------------------------------*/ | ||
| 57 | +typedef struct { | ||
| 58 | + pid_t tid; | ||
| 59 | + char name[16]; | ||
| 60 | + float pcpu; | ||
| 61 | +} T_ThreadAttribute; | ||
| 62 | + | ||
| 63 | +/* Private values -------------------------------------------------------------*/ | ||
| 64 | +static FILE *s_ziyanLogFile; | ||
| 65 | +static FILE *s_ziyanLogFileCnt; | ||
| 66 | +static pthread_t s_monitorThread = 0; | ||
| 67 | + | ||
| 68 | +/* Private functions declaration ---------------------------------------------*/ | ||
| 69 | +static T_ZiyanReturnCode ZiyanUser_PrepareSystemEnvironment(void); | ||
| 70 | +static T_ZiyanReturnCode ZiyanUser_FillInUserInfo(T_ZiyanUserInfo *userInfo); | ||
| 71 | +static T_ZiyanReturnCode ZiyanUser_PrintConsole(const uint8_t *data, uint16_t dataLen); | ||
| 72 | +static T_ZiyanReturnCode ZiyanUser_LocalWrite(const uint8_t *data, uint16_t dataLen); | ||
| 73 | +static T_ZiyanReturnCode ZiyanUser_LocalWriteFsInit(const char *path); | ||
| 74 | +// static void *ZiyanUser_MonitorTask(void *argument); | ||
| 75 | +// static T_ZiyanReturnCode ZiyanTest_HighPowerApplyPinInit(); | ||
| 76 | +// static T_ZiyanReturnCode ZiyanTest_WriteHighPowerApplyPin(E_ZiyanPowerManagementPinState pinState); | ||
| 77 | +static void ZiyanUser_NormalExitHandler(int signalNum); | ||
| 78 | + | ||
| 79 | +/* Exported functions definition ---------------------------------------------*/ | ||
| 80 | +int main(int argc, char **argv) | ||
| 81 | +{ | ||
| 82 | + T_ZiyanReturnCode returnCode; | ||
| 83 | + T_ZiyanUserInfo userInfo; | ||
| 84 | + T_ZiyanAircraftInfoBaseInfo aircraftInfoBaseInfo; | ||
| 85 | + T_ZiyanAircraftVersion aircraftInfoVersion; | ||
| 86 | + T_ZiyanFirmwareVersion firmwareVersion = { | ||
| 87 | + .majorVersion = 1, | ||
| 88 | + .minorVersion = 0, | ||
| 89 | + .modifyVersion = 0, | ||
| 90 | + .debugVersion = 0, | ||
| 91 | + }; | ||
| 92 | + | ||
| 93 | + USER_UTIL_UNUSED(argc); | ||
| 94 | + USER_UTIL_UNUSED(argv); | ||
| 95 | + | ||
| 96 | + // attention: when the program is hand up ctrl-c will generate the coredump file | ||
| 97 | + signal(SIGTERM, ZiyanUser_NormalExitHandler); | ||
| 98 | + | ||
| 99 | + /*!< Step 1: Prepare system environment, such as osal, hal uart, console function and so on. */ | ||
| 100 | + returnCode = ZiyanUser_PrepareSystemEnvironment(); | ||
| 101 | + if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 102 | + USER_LOG_ERROR("Prepare system environment error"); | ||
| 103 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + /*!< Step 2: Fill your application information in ziyan_sdk_app_info.h and use this interface to fill it. */ | ||
| 107 | + returnCode = ZiyanUser_FillInUserInfo(&userInfo); | ||
| 108 | + if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 109 | + USER_LOG_ERROR("Fill user info error, please check user info config"); | ||
| 110 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + // /*!< Step 3: Initialize the Payload SDK core by your application information. */ | ||
| 114 | + returnCode = ZiyanCore_Init(&userInfo); | ||
| 115 | + if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 116 | + USER_LOG_ERROR("Core init error"); | ||
| 117 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + returnCode = ZiyanAircraftInfo_GetBaseInfo(&aircraftInfoBaseInfo); | ||
| 121 | + if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 122 | + USER_LOG_ERROR("get aircraft base info error"); | ||
| 123 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + // returnCode = ZiyanAircraftInfo_GetAircraftVersion(&aircraftInfoVersion); | ||
| 127 | + // if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 128 | + // USER_LOG_ERROR("get aircraft version info error"); | ||
| 129 | + // } else { | ||
| 130 | + // USER_LOG_INFO("Aircraft version is V%02d.%02d.%02d.%02d", aircraftInfoVersion.majorVersion, | ||
| 131 | + // aircraftInfoVersion.minorVersion, aircraftInfoVersion.modifyVersion, | ||
| 132 | + // aircraftInfoVersion.debugVersion); | ||
| 133 | + // } | ||
| 134 | + | ||
| 135 | + // returnCode = ZiyanCore_SetAlias("PSDK_APPALIAS"); | ||
| 136 | + // if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 137 | + // USER_LOG_ERROR("set alias error"); | ||
| 138 | + // return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 139 | + // } | ||
| 140 | + | ||
| 141 | + // returnCode = ZiyanCore_SetFirmwareVersion(firmwareVersion); | ||
| 142 | + // if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 143 | + // USER_LOG_ERROR("set firmware version error"); | ||
| 144 | + // return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 145 | + // } | ||
| 146 | + | ||
| 147 | + // returnCode = ZiyanCore_SetSerialNumber("PSDK12345678XX"); | ||
| 148 | + // if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 149 | + // USER_LOG_ERROR("set serial number error"); | ||
| 150 | + // return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 151 | + // } | ||
| 152 | + | ||
| 153 | +// /*!< Step 4: Initialize the selected modules by macros in ziyan_sdk_config.h . */ | ||
| 154 | +// #ifdef CONFIG_MODULE_SAMPLE_POWER_MANAGEMENT_ON | ||
| 155 | +// T_ZiyanTestApplyHighPowerHandler applyHighPowerHandler = { | ||
| 156 | +// .pinInit = ZiyanTest_HighPowerApplyPinInit, | ||
| 157 | +// .pinWrite = ZiyanTest_WriteHighPowerApplyPin, | ||
| 158 | +// }; | ||
| 159 | + | ||
| 160 | +// returnCode = ZiyanTest_RegApplyHighPowerHandler(&applyHighPowerHandler); | ||
| 161 | +// if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 162 | +// USER_LOG_ERROR("regsiter apply high power handler error"); | ||
| 163 | +// } | ||
| 164 | + | ||
| 165 | +// returnCode = ZiyanTest_PowerManagementStartService(); | ||
| 166 | +// if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 167 | +// USER_LOG_ERROR("power management init error"); | ||
| 168 | +// } | ||
| 169 | +// #endif | ||
| 170 | + | ||
| 171 | +// #ifdef CONFIG_MODULE_SAMPLE_DATA_TRANSMISSION_ON | ||
| 172 | +// returnCode = ZiyanTest_DataTransmissionStartService(); | ||
| 173 | +// if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 174 | +// USER_LOG_ERROR("widget sample init error"); | ||
| 175 | +// } | ||
| 176 | +// #endif | ||
| 177 | + | ||
| 178 | +// if (aircraftInfoBaseInfo.mountPosition == ZIYAN_MOUNT_POSITION_EXTENSION_PORT && | ||
| 179 | +// aircraftInfoBaseInfo.aircraftType == ZIYAN_AIRCRAFT_TYPE_M300_RTK) { | ||
| 180 | +// returnCode = ZiyanTest_WidgetInteractionStartService(); | ||
| 181 | +// if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 182 | +// USER_LOG_ERROR("widget interaction sample init error"); | ||
| 183 | +// } | ||
| 184 | + | ||
| 185 | +// returnCode = ZiyanTest_WidgetSpeakerStartService(); | ||
| 186 | +// if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 187 | +// USER_LOG_ERROR("widget speaker test init error"); | ||
| 188 | +// } | ||
| 189 | +// } else { | ||
| 190 | +#ifdef CONFIG_MODULE_SAMPLE_CAMERA_EMU_ON | ||
| 191 | + returnCode = ZiyanTest_CameraEmuBaseStartService(); | ||
| 192 | + if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 193 | + USER_LOG_ERROR("camera emu common init error"); | ||
| 194 | + } | ||
| 195 | +#endif | ||
| 196 | + | ||
| 197 | +#ifdef CONFIG_MODULE_SAMPLE_CAMERA_MEDIA_ON | ||
| 198 | + returnCode = ZiyanTest_CameraEmuMediaStartService(); | ||
| 199 | + if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 200 | + USER_LOG_ERROR("camera emu media init error"); | ||
| 201 | + } | ||
| 202 | +#endif | ||
| 203 | + | ||
| 204 | +#ifdef CONFIG_MODULE_SAMPLE_FC_SUBSCRIPTION_ON | ||
| 205 | + returnCode = ZiyanTest_FcSubscriptionStartService(); | ||
| 206 | + if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 207 | + USER_LOG_ERROR("data subscription sample init error\n"); | ||
| 208 | + } | ||
| 209 | +#endif | ||
| 210 | + | ||
| 211 | +// #ifdef CONFIG_MODULE_SAMPLE_GIMBAL_EMU_ON | ||
| 212 | + | ||
| 213 | +// #if DEVICE_VERSION == JZ_H150S || DEVICE_VERSION == JZ_H150T | ||
| 214 | + | ||
| 215 | +// // if (aircraftInfoBaseInfo.ziyanAdapterType == ZIYAN_SDK_ADAPTER_TYPE_NONE || | ||
| 216 | +// // aircraftInfoBaseInfo.ziyanAdapterType == ZIYAN_SDK_ADAPTER_TYPE_UNKNOWN) { | ||
| 217 | + | ||
| 218 | +// if (ZiyanTest_GimbalStartService() != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 219 | +// USER_LOG_ERROR("psdk gimbal init error"); | ||
| 220 | +// } | ||
| 221 | +// //} | ||
| 222 | +// #endif | ||
| 223 | + | ||
| 224 | +// #ifdef CONFIG_MODULE_SAMPLE_XPORT_ON | ||
| 225 | +// if (aircraftInfoBaseInfo.ziyanAdapterType == ZIYAN_SDK_ADAPTER_TYPE_XPORT) { | ||
| 226 | +// if (ZiyanTest_XPortStartService() != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 227 | +// USER_LOG_ERROR("psdk xport init error"); | ||
| 228 | +// } | ||
| 229 | +// } | ||
| 230 | +// #endif | ||
| 231 | + | ||
| 232 | +#ifdef CONFIG_MODULE_SAMPLE_WIDGET_ON | ||
| 233 | + | ||
| 234 | + ZiyanTest_WidgetSetConfigFilePath("/root/"); | ||
| 235 | + | ||
| 236 | +#if ZIYAN_USE_WIDGET_INTERACTION | ||
| 237 | + returnCode = ZiyanTest_WidgetInteractionStartService(); | ||
| 238 | + if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 239 | + USER_LOG_ERROR("widget interaction test init error"); | ||
| 240 | + } | ||
| 241 | +#else | ||
| 242 | + returnCode = ZiyanTest_WidgetStartService(); | ||
| 243 | + if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 244 | + USER_LOG_ERROR("widget sample init error"); | ||
| 245 | + } | ||
| 246 | +#endif | ||
| 247 | +#endif | ||
| 248 | + | ||
| 249 | +#ifdef CONFIG_MODULE_SAMPLE_WIDGET_SPEAKER_ON | ||
| 250 | + returnCode = ZiyanTest_WidgetSpeakerStartService(); | ||
| 251 | + if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 252 | + USER_LOG_ERROR("widget speaker test init error"); | ||
| 253 | + } | ||
| 254 | +#endif | ||
| 255 | + | ||
| 256 | +// #ifdef CONFIG_MODULE_SAMPLE_MOP_CHANNEL_ON | ||
| 257 | +// returnCode = ZiyanTest_MopChannelStartService(); | ||
| 258 | +// if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 259 | +// USER_LOG_ERROR("mop channel sample init error"); | ||
| 260 | +// } | ||
| 261 | +// #endif | ||
| 262 | + | ||
| 263 | +// #ifdef CONFIG_MODULE_SAMPLE_PAYLOAD_COLLABORATION_ON | ||
| 264 | +// if (aircraftInfoBaseInfo.ziyanAdapterType == ZIYAN_SDK_ADAPTER_TYPE_SKYPORT_V2 || | ||
| 265 | +// aircraftInfoBaseInfo.ziyanAdapterType == ZIYAN_SDK_ADAPTER_TYPE_XPORT) { | ||
| 266 | +// returnCode = ZiyanTest_PayloadCollaborationStartService(); | ||
| 267 | +// if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 268 | +// USER_LOG_ERROR("Payload collaboration sample init error\n"); | ||
| 269 | +// } | ||
| 270 | +// } | ||
| 271 | +// #endif | ||
| 272 | + | ||
| 273 | +// #ifdef CONFIG_MODULE_SAMPLE_UPGRADE_ON | ||
| 274 | +// T_ZiyanTestUpgradePlatformOpt linuxUpgradePlatformOpt = { | ||
| 275 | +// .rebootSystem = ZiyanUpgradePlatformLinux_RebootSystem, | ||
| 276 | +// .cleanUpgradeProgramFileStoreArea = ZiyanUpgradePlatformLinux_CleanUpgradeProgramFileStoreArea, | ||
| 277 | +// .createUpgradeProgramFile = ZiyanUpgradePlatformLinux_CreateUpgradeProgramFile, | ||
| 278 | +// .writeUpgradeProgramFile = ZiyanUpgradePlatformLinux_WriteUpgradeProgramFile, | ||
| 279 | +// .readUpgradeProgramFile = ZiyanUpgradePlatformLinux_ReadUpgradeProgramFile, | ||
| 280 | +// .closeUpgradeProgramFile = ZiyanUpgradePlatformLinux_CloseUpgradeProgramFile, | ||
| 281 | +// .replaceOldProgram = ZiyanUpgradePlatformLinux_ReplaceOldProgram, | ||
| 282 | +// .setUpgradeRebootState = ZiyanUpgradePlatformLinux_SetUpgradeRebootState, | ||
| 283 | +// .getUpgradeRebootState = ZiyanUpgradePlatformLinux_GetUpgradeRebootState, | ||
| 284 | +// .cleanUpgradeRebootState = ZiyanUpgradePlatformLinux_CleanUpgradeRebootState, | ||
| 285 | +// }; | ||
| 286 | +// T_ZiyanTestUpgradeConfig testUpgradeConfig = { | ||
| 287 | +// .firmwareVersion = firmwareVersion, | ||
| 288 | +// .transferType = ZIYAN_FIRMWARE_TRANSFER_TYPE_DCFTP, | ||
| 289 | +// .needReplaceProgramBeforeReboot = true | ||
| 290 | +// }; | ||
| 291 | +// if (ZiyanTest_UpgradeStartService(&linuxUpgradePlatformOpt, testUpgradeConfig) != | ||
| 292 | +// ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 293 | +// USER_LOG_ERROR("psdk upgrade init error"); | ||
| 294 | +// } | ||
| 295 | +// #endif | ||
| 296 | + | ||
| 297 | +// #ifdef CONFIG_MODULE_SAMPLE_HMS_CUSTOMIZATION_ON | ||
| 298 | +// returnCode = ZiyanTest_HmsCustomizationStartService(); | ||
| 299 | +// if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 300 | +// USER_LOG_ERROR("hms test init error"); | ||
| 301 | +// } | ||
| 302 | +// #endif | ||
| 303 | +// } | ||
| 304 | + | ||
| 305 | + // /*!< Step 5: Tell the ZIYAN Pilot you are ready. */ | ||
| 306 | + returnCode = ZiyanCore_ApplicationStart(); | ||
| 307 | + if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 308 | + USER_LOG_ERROR("start sdk application error"); | ||
| 309 | + } | ||
| 310 | + | ||
| 311 | + // if (pthread_create(&s_monitorThread, NULL, ZiyanUser_MonitorTask, NULL) != 0) { | ||
| 312 | + // USER_LOG_ERROR("create monitor task fail."); | ||
| 313 | + // } | ||
| 314 | + | ||
| 315 | + // if (pthread_setname_np(s_monitorThread, "monitor task") != 0) { | ||
| 316 | + // USER_LOG_ERROR("set name for monitor task fail."); | ||
| 317 | + // } | ||
| 318 | + | ||
| 319 | + while (1) { | ||
| 320 | + sleep(1); | ||
| 321 | + } | ||
| 322 | +} | ||
| 323 | + | ||
| 324 | +/* Private functions definition-----------------------------------------------*/ | ||
| 325 | +static T_ZiyanReturnCode ZiyanUser_PrepareSystemEnvironment(void) | ||
| 326 | +{ | ||
| 327 | + T_ZiyanReturnCode returnCode; | ||
| 328 | + T_ZiyanOsalHandler osalHandler = { | ||
| 329 | + .TaskCreate = Osal_TaskCreate, | ||
| 330 | + .TaskDestroy = Osal_TaskDestroy, | ||
| 331 | + .TaskSleepMs = Osal_TaskSleepMs, | ||
| 332 | + .MutexCreate= Osal_MutexCreate, | ||
| 333 | + .MutexDestroy = Osal_MutexDestroy, | ||
| 334 | + .MutexLock = Osal_MutexLock, | ||
| 335 | + .MutexUnlock = Osal_MutexUnlock, | ||
| 336 | + .SemaphoreCreate = Osal_SemaphoreCreate, | ||
| 337 | + .SemaphoreDestroy = Osal_SemaphoreDestroy, | ||
| 338 | + .SemaphoreWait = Osal_SemaphoreWait, | ||
| 339 | + .SemaphoreTimedWait = Osal_SemaphoreTimedWait, | ||
| 340 | + .SemaphorePost = Osal_SemaphorePost, | ||
| 341 | + .Malloc = Osal_Malloc, | ||
| 342 | + .Free = Osal_Free, | ||
| 343 | + .GetRandomNum = Osal_GetRandomNum, | ||
| 344 | + .GetTimeMs = Osal_GetTimeMs, | ||
| 345 | + .GetTimeUs = Osal_GetTimeUs, | ||
| 346 | + }; | ||
| 347 | + | ||
| 348 | + T_ZiyanLoggerConsole printConsole = { | ||
| 349 | + .func = ZiyanUser_PrintConsole, | ||
| 350 | + .consoleLevel = ZIYAN_LOGGER_CONSOLE_LOG_LEVEL_INFO, | ||
| 351 | + .isSupportColor = true, | ||
| 352 | + }; | ||
| 353 | + | ||
| 354 | + T_ZiyanLoggerConsole localRecordConsole = { | ||
| 355 | + .consoleLevel = ZIYAN_LOGGER_CONSOLE_LOG_LEVEL_DEBUG, | ||
| 356 | + .func = ZiyanUser_LocalWrite, | ||
| 357 | + .isSupportColor = true, | ||
| 358 | + }; | ||
| 359 | + | ||
| 360 | + T_ZiyanHalUartHandler uartHandler = { | ||
| 361 | + .UartInit = HalUart_Init, | ||
| 362 | + .UartDeInit = HalUart_DeInit, | ||
| 363 | + .UartWriteData = HalUart_WriteData, | ||
| 364 | + .UartReadData = HalUart_ReadData, | ||
| 365 | + .UartGetStatus = HalUart_GetStatus, | ||
| 366 | + }; | ||
| 367 | + | ||
| 368 | + T_ZiyanHalNetworkHandler networkHandler = { | ||
| 369 | + .NetworkInit = HalNetWork_Init, | ||
| 370 | + .NetworkDeInit = HalNetWork_DeInit, | ||
| 371 | + .NetworkGetDeviceInfo = HalNetWork_GetDeviceInfo, | ||
| 372 | + }; | ||
| 373 | + | ||
| 374 | + T_ZiyanHalUsbBulkHandler usbBulkHandler = { | ||
| 375 | + .UsbBulkInit = HalUsbBulk_Init, | ||
| 376 | + .UsbBulkDeInit = HalUsbBulk_DeInit, | ||
| 377 | + .UsbBulkWriteData = HalUsbBulk_WriteData, | ||
| 378 | + .UsbBulkReadData = HalUsbBulk_ReadData, | ||
| 379 | + .UsbBulkGetDeviceInfo = HalUsbBulk_GetDeviceInfo, | ||
| 380 | + }; | ||
| 381 | + | ||
| 382 | + T_ZiyanFileSystemHandler fileSystemHandler = { | ||
| 383 | + .FileOpen = Osal_FileOpen, | ||
| 384 | + .FileClose = Osal_FileClose, | ||
| 385 | + .FileWrite = Osal_FileWrite, | ||
| 386 | + .FileRead = Osal_FileRead, | ||
| 387 | + .FileSync = Osal_FileSync, | ||
| 388 | + .FileSeek = Osal_FileSeek, | ||
| 389 | + .DirOpen = Osal_DirOpen, | ||
| 390 | + .DirClose = Osal_DirClose, | ||
| 391 | + .DirRead = Osal_DirRead, | ||
| 392 | + .Mkdir = Osal_Mkdir, | ||
| 393 | + .Unlink = Osal_Unlink, | ||
| 394 | + .Rename = Osal_Rename, | ||
| 395 | + .Stat = Osal_Stat, | ||
| 396 | + }; | ||
| 397 | + | ||
| 398 | + T_ZiyanSocketHandler socketHandler = { | ||
| 399 | + .Socket = Osal_Socket, | ||
| 400 | + .Bind = Osal_Bind, | ||
| 401 | + .Close = Osal_Close, | ||
| 402 | + .UdpSendData = Osal_UdpSendData, | ||
| 403 | + .UdpRecvData = Osal_UdpRecvData, | ||
| 404 | + .TcpListen = Osal_TcpListen, | ||
| 405 | + .TcpAccept = Osal_TcpAccept, | ||
| 406 | + .TcpConnect = Osal_TcpConnect, | ||
| 407 | + .TcpSendData = Osal_TcpSendData, | ||
| 408 | + .TcpRecvData = Osal_TcpRecvData, | ||
| 409 | + }; | ||
| 410 | + | ||
| 411 | + returnCode = ZiyanPlatform_RegOsalHandler(&osalHandler); | ||
| 412 | + if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 413 | + printf("register osal handler error"); | ||
| 414 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 415 | + } | ||
| 416 | + | ||
| 417 | + returnCode = ZiyanPlatform_RegHalUartHandler(&uartHandler); | ||
| 418 | + if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 419 | + printf("register hal uart handler error"); | ||
| 420 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 421 | + } | ||
| 422 | + | ||
| 423 | + if (ZiyanUser_LocalWriteFsInit(ZIYAN_LOG_PATH) != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 424 | + printf("file system init error"); | ||
| 425 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_UNKNOWN; | ||
| 426 | + } | ||
| 427 | + | ||
| 428 | + returnCode = ZiyanLogger_AddConsole(&printConsole); | ||
| 429 | + if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 430 | + printf("add printf console error"); | ||
| 431 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 432 | + } | ||
| 433 | + | ||
| 434 | + returnCode = ZiyanLogger_AddConsole(&localRecordConsole); | ||
| 435 | + if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 436 | + printf("add printf console error"); | ||
| 437 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 438 | + } | ||
| 439 | + | ||
| 440 | + | ||
| 441 | +#if (CONFIG_HARDWARE_CONNECTION == ZIYAN_USE_UART_AND_USB_BULK_DEVICE) | ||
| 442 | + returnCode = ZiyanPlatform_RegHalUsbBulkHandler(&usbBulkHandler); | ||
| 443 | + if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 444 | + printf("register hal usb bulk handler error"); | ||
| 445 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 446 | + } | ||
| 447 | +#elif (CONFIG_HARDWARE_CONNECTION == ZIYAN_USE_UART_AND_NETWORK_DEVICE) | ||
| 448 | + returnCode = ZiyanPlatform_RegHalNetworkHandler(&networkHandler); | ||
| 449 | + if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 450 | + printf("register hal network handler error"); | ||
| 451 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 452 | + } | ||
| 453 | + | ||
| 454 | + //Attention: if you want to use camera stream view function, please uncomment it. | ||
| 455 | + returnCode = ZiyanPlatform_RegSocketHandler(&socketHandler); | ||
| 456 | + if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 457 | + printf("register osal socket handler error"); | ||
| 458 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 459 | + } | ||
| 460 | +#elif (CONFIG_HARDWARE_CONNECTION == ZIYAN_USE_ONLY_UART) | ||
| 461 | + /*!< Attention: Only use uart hardware connection. | ||
| 462 | + */ | ||
| 463 | +#endif | ||
| 464 | + | ||
| 465 | + returnCode = ZiyanPlatform_RegFileSystemHandler(&fileSystemHandler); | ||
| 466 | + if (returnCode != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 467 | + printf("register osal filesystem handler error"); | ||
| 468 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 469 | + } | ||
| 470 | + | ||
| 471 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 472 | +} | ||
| 473 | + | ||
| 474 | +static T_ZiyanReturnCode ZiyanUser_FillInUserInfo(T_ZiyanUserInfo *userInfo) | ||
| 475 | +{ | ||
| 476 | + if (userInfo == NULL) { | ||
| 477 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER; | ||
| 478 | + } | ||
| 479 | + | ||
| 480 | + memset(userInfo->appName, 0, sizeof(userInfo->appName)); | ||
| 481 | + memset(userInfo->appId, 0, sizeof(userInfo->appId)); | ||
| 482 | + memset(userInfo->appKey, 0, sizeof(userInfo->appKey)); | ||
| 483 | + memset(userInfo->appLicense, 0, sizeof(userInfo->appLicense)); | ||
| 484 | + memset(userInfo->developerAccount, 0, sizeof(userInfo->developerAccount)); | ||
| 485 | + memset(userInfo->baudRate, 0, sizeof(userInfo->baudRate)); | ||
| 486 | + | ||
| 487 | + if (strlen(USER_APP_NAME) >= sizeof(userInfo->appName) || | ||
| 488 | + strlen(USER_APP_ID) > sizeof(userInfo->appId) || | ||
| 489 | + strlen(USER_APP_KEY) > sizeof(userInfo->appKey) || | ||
| 490 | + strlen(USER_APP_LICENSE) > sizeof(userInfo->appLicense) || | ||
| 491 | + strlen(USER_DEVELOPER_ACCOUNT) >= sizeof(userInfo->developerAccount) || | ||
| 492 | + strlen(USER_BAUD_RATE) > sizeof(userInfo->baudRate)) { | ||
| 493 | + USER_LOG_ERROR("Length of user information string is beyond limit. Please check."); | ||
| 494 | + sleep(1); | ||
| 495 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER; | ||
| 496 | + } | ||
| 497 | + | ||
| 498 | + if (!strcmp(USER_APP_NAME, "your_app_name") || | ||
| 499 | + !strcmp(USER_APP_ID, "your_app_id") || | ||
| 500 | + !strcmp(USER_APP_KEY, "your_app_key") || | ||
| 501 | + !strcmp(USER_BAUD_RATE, "your_app_license") || | ||
| 502 | + !strcmp(USER_DEVELOPER_ACCOUNT, "your_developer_account") || | ||
| 503 | + !strcmp(USER_BAUD_RATE, "your_baud_rate")) { | ||
| 504 | + USER_LOG_ERROR( | ||
| 505 | + "Please fill in correct user information to 'samples/sample_c/platform/linux/manifold2/application/ziyan_sdk_app_info.h' file."); | ||
| 506 | + sleep(1); | ||
| 507 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER; | ||
| 508 | + } | ||
| 509 | + | ||
| 510 | + strncpy(userInfo->appName, USER_APP_NAME, sizeof(userInfo->appName) - 1); | ||
| 511 | + memcpy(userInfo->appId, USER_APP_ID, USER_UTIL_MIN(sizeof(userInfo->appId), strlen(USER_APP_ID))); | ||
| 512 | + memcpy(userInfo->appKey, USER_APP_KEY, USER_UTIL_MIN(sizeof(userInfo->appKey), strlen(USER_APP_KEY))); | ||
| 513 | + memcpy(userInfo->appLicense, USER_APP_LICENSE, | ||
| 514 | + USER_UTIL_MIN(sizeof(userInfo->appLicense), strlen(USER_APP_LICENSE))); | ||
| 515 | + memcpy(userInfo->baudRate, USER_BAUD_RATE, USER_UTIL_MIN(sizeof(userInfo->baudRate), strlen(USER_BAUD_RATE))); | ||
| 516 | + strncpy(userInfo->developerAccount, USER_DEVELOPER_ACCOUNT, sizeof(userInfo->developerAccount) - 1); | ||
| 517 | + | ||
| 518 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 519 | +} | ||
| 520 | + | ||
| 521 | +static T_ZiyanReturnCode ZiyanUser_PrintConsole(const uint8_t *data, uint16_t dataLen) | ||
| 522 | +{ | ||
| 523 | + USER_UTIL_UNUSED(dataLen); | ||
| 524 | + | ||
| 525 | + printf("%s", data); | ||
| 526 | + | ||
| 527 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 528 | +} | ||
| 529 | + | ||
| 530 | +static T_ZiyanReturnCode ZiyanUser_LocalWrite(const uint8_t *data, uint16_t dataLen) | ||
| 531 | +{ | ||
| 532 | + uint32_t realLen; | ||
| 533 | + | ||
| 534 | + if (s_ziyanLogFile == NULL) { | ||
| 535 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_UNKNOWN; | ||
| 536 | + } | ||
| 537 | + | ||
| 538 | + realLen = fwrite(data, 1, dataLen, s_ziyanLogFile); | ||
| 539 | + fflush(s_ziyanLogFile); | ||
| 540 | + if (realLen == dataLen) { | ||
| 541 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 542 | + } else { | ||
| 543 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_UNKNOWN; | ||
| 544 | + } | ||
| 545 | +} | ||
| 546 | + | ||
| 547 | +static T_ZiyanReturnCode ZiyanUser_LocalWriteFsInit(const char *path) | ||
| 548 | +{ | ||
| 549 | + T_ZiyanReturnCode ziyanReturnCode = ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 550 | + char filePath[ZIYAN_LOG_PATH_MAX_SIZE]; | ||
| 551 | + char systemCmd[ZIYAN_SYSTEM_CMD_STR_MAX_SIZE]; | ||
| 552 | + char folderName[ZIYAN_LOG_FOLDER_NAME_MAX_SIZE]; | ||
| 553 | + time_t currentTime = time(NULL); | ||
| 554 | + struct tm *localTime = localtime(¤tTime); | ||
| 555 | + uint16_t logFileIndex = 0; | ||
| 556 | + uint16_t currentLogFileIndex; | ||
| 557 | + uint8_t ret; | ||
| 558 | + | ||
| 559 | + if (localTime == NULL) { | ||
| 560 | + printf("Get local time error.\r\n"); | ||
| 561 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 562 | + } | ||
| 563 | + | ||
| 564 | + if (access(ZIYAN_LOG_FOLDER_NAME, F_OK) != 0) { | ||
| 565 | + sprintf(folderName, "mkdir %s", ZIYAN_LOG_FOLDER_NAME); | ||
| 566 | + ret = system(folderName); | ||
| 567 | + if (ret != 0) { | ||
| 568 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 569 | + } | ||
| 570 | + } | ||
| 571 | + | ||
| 572 | + s_ziyanLogFileCnt = fopen(ZIYAN_LOG_INDEX_FILE_NAME, "rb+"); | ||
| 573 | + if (s_ziyanLogFileCnt == NULL) { | ||
| 574 | + s_ziyanLogFileCnt = fopen(ZIYAN_LOG_INDEX_FILE_NAME, "wb+"); | ||
| 575 | + if (s_ziyanLogFileCnt == NULL) { | ||
| 576 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 577 | + } | ||
| 578 | + } else { | ||
| 579 | + ret = fseek(s_ziyanLogFileCnt, 0, SEEK_SET); | ||
| 580 | + if (ret != 0) { | ||
| 581 | + printf("Seek log count file error, ret: %d, errno: %d.\r\n", ret, errno); | ||
| 582 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 583 | + } | ||
| 584 | + | ||
| 585 | + ret = fread((uint16_t *) &logFileIndex, 1, sizeof(uint16_t), s_ziyanLogFileCnt); | ||
| 586 | + if (ret != sizeof(uint16_t)) { | ||
| 587 | + printf("Read log file index error.\r\n"); | ||
| 588 | + } | ||
| 589 | + } | ||
| 590 | + | ||
| 591 | + currentLogFileIndex = logFileIndex; | ||
| 592 | + logFileIndex++; | ||
| 593 | + | ||
| 594 | + ret = fseek(s_ziyanLogFileCnt, 0, SEEK_SET); | ||
| 595 | + if (ret != 0) { | ||
| 596 | + printf("Seek log file error, ret: %d, errno: %d.\r\n", ret, errno); | ||
| 597 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 598 | + } | ||
| 599 | + | ||
| 600 | + ret = fwrite((uint16_t *) &logFileIndex, 1, sizeof(uint16_t), s_ziyanLogFileCnt); | ||
| 601 | + if (ret != sizeof(uint16_t)) { | ||
| 602 | + printf("Write log file index error.\r\n"); | ||
| 603 | + fclose(s_ziyanLogFileCnt); | ||
| 604 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 605 | + } | ||
| 606 | + | ||
| 607 | + fclose(s_ziyanLogFileCnt); | ||
| 608 | + | ||
| 609 | + sprintf(filePath, "%s_%04d_%04d%02d%02d_%02d-%02d-%02d.log", path, currentLogFileIndex, | ||
| 610 | + localTime->tm_year + 1900, localTime->tm_mon + 1, localTime->tm_mday, | ||
| 611 | + localTime->tm_hour, localTime->tm_min, localTime->tm_sec); | ||
| 612 | + | ||
| 613 | + s_ziyanLogFile = fopen(filePath, "wb+"); | ||
| 614 | + if (s_ziyanLogFile == NULL) { | ||
| 615 | + USER_LOG_ERROR("Open filepath time error."); | ||
| 616 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 617 | + } | ||
| 618 | + | ||
| 619 | + if (logFileIndex >= ZIYAN_LOG_MAX_COUNT) { | ||
| 620 | + sprintf(systemCmd, "rm -rf %s_%04d*.log", path, currentLogFileIndex - ZIYAN_LOG_MAX_COUNT); | ||
| 621 | + ret = system(systemCmd); | ||
| 622 | + if (ret != 0) { | ||
| 623 | + printf("Remove file error, ret:%d.\r\n", ret); | ||
| 624 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 625 | + } | ||
| 626 | + } | ||
| 627 | + | ||
| 628 | + return ziyanReturnCode; | ||
| 629 | +} | ||
| 630 | + | ||
| 631 | +// #pragma GCC diagnostic push | ||
| 632 | +// #pragma GCC diagnostic ignored "-Wmissing-noreturn" | ||
| 633 | +// #pragma GCC diagnostic ignored "-Wreturn-type" | ||
| 634 | + | ||
| 635 | +// static void *ZiyanUser_MonitorTask(void *argument) | ||
| 636 | +// { | ||
| 637 | +// unsigned int i = 0; | ||
| 638 | +// unsigned int threadCount = 0; | ||
| 639 | +// pid_t *tidList = NULL; | ||
| 640 | +// T_ThreadAttribute *threadAttribute = NULL; | ||
| 641 | +// T_ZiyanOsalHandler *osalHandler = ZiyanPlatform_GetOsalHandler(); | ||
| 642 | + | ||
| 643 | +// USER_UTIL_UNUSED(argument); | ||
| 644 | + | ||
| 645 | +// while (1) { | ||
| 646 | +// threadCount = Monitor_GetThreadCountOfProcess(getpid()); | ||
| 647 | +// tidList = osalHandler->Malloc(threadCount * sizeof(pid_t)); | ||
| 648 | +// if (tidList == NULL) { | ||
| 649 | +// USER_LOG_ERROR("malloc fail."); | ||
| 650 | +// goto delay; | ||
| 651 | +// } | ||
| 652 | +// Monitor_GetTidListOfProcess(getpid(), tidList, threadCount); | ||
| 653 | + | ||
| 654 | +// threadAttribute = osalHandler->Malloc(threadCount * sizeof(T_ThreadAttribute)); | ||
| 655 | +// if (threadAttribute == NULL) { | ||
| 656 | +// USER_LOG_ERROR("malloc fail."); | ||
| 657 | +// goto freeTidList; | ||
| 658 | +// } | ||
| 659 | +// for (i = 0; i < threadCount; ++i) { | ||
| 660 | +// threadAttribute[i].tid = tidList[i]; | ||
| 661 | +// } | ||
| 662 | + | ||
| 663 | +// USER_LOG_DEBUG("thread pcpu:"); | ||
| 664 | +// USER_LOG_DEBUG("tid\tname\tpcpu"); | ||
| 665 | +// for (i = 0; i < threadCount; ++i) { | ||
| 666 | +// threadAttribute[i].pcpu = Monitor_GetPcpuOfThread(getpid(), tidList[i]); | ||
| 667 | +// Monitor_GetNameOfThread(getpid(), tidList[i], threadAttribute[i].name, sizeof(threadAttribute[i].name)); | ||
| 668 | +// USER_LOG_DEBUG("%d\t%15s\t%f %%.", threadAttribute[i].tid, threadAttribute[i].name, | ||
| 669 | +// threadAttribute[i].pcpu); | ||
| 670 | +// } | ||
| 671 | + | ||
| 672 | +// USER_LOG_DEBUG("heap used: %d B.", Monitor_GetHeapUsed(getpid())); | ||
| 673 | +// USER_LOG_DEBUG("stack used: %d B.", Monitor_GetStackUsed(getpid())); | ||
| 674 | + | ||
| 675 | +// osalHandler->Free(threadAttribute); | ||
| 676 | +// freeTidList: | ||
| 677 | +// osalHandler->Free(tidList); | ||
| 678 | + | ||
| 679 | +// delay: | ||
| 680 | +// sleep(10); | ||
| 681 | +// } | ||
| 682 | +// } | ||
| 683 | + | ||
| 684 | +// // static T_ZiyanReturnCode ZiyanTest_HighPowerApplyPinInit() | ||
| 685 | +// // { | ||
| 686 | +// // return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 687 | +// // } | ||
| 688 | + | ||
| 689 | +// // static T_ZiyanReturnCode ZiyanTest_WriteHighPowerApplyPin(E_ZiyanPowerManagementPinState pinState) | ||
| 690 | +// // { | ||
| 691 | +// // //attention: please pull up the HWPR pin state by hardware. | ||
| 692 | +// // return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 693 | +// // } | ||
| 694 | + | ||
| 695 | +static void ZiyanUser_NormalExitHandler(int signalNum) | ||
| 696 | +{ | ||
| 697 | + USER_UTIL_UNUSED(signalNum); | ||
| 698 | + exit(0); | ||
| 699 | +} | ||
| 700 | + | ||
| 701 | +#pragma GCC diagnostic pop | ||
| 702 | + | ||
| 703 | +/****************** (C) COPYRIGHT ZIYAN Innovations *****END OF FILE****/ |
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file ziyan_sdk_app_info.h | ||
| 4 | + * @brief This is the header file for defining the structure and (exported) function prototypes. | ||
| 5 | + * | ||
| 6 | + * @copyright (c) 2018 ZIYAN. All rights reserved. | ||
| 7 | + * | ||
| 8 | + * All information contained herein is, and remains, the property of ZIYAN. | ||
| 9 | + * The intellectual and technical concepts contained herein are proprietary | ||
| 10 | + * to ZIYAN and may be covered by U.S. and foreign patents, patents in process, | ||
| 11 | + * and protected by trade secret or copyright law. Dissemination of this | ||
| 12 | + * information, including but not limited to data and other proprietary | ||
| 13 | + * material(s) incorporated within the information, in any form, is strictly | ||
| 14 | + * prohibited without the express written consent of ZIYAN. | ||
| 15 | + * | ||
| 16 | + * If you receive this source code without ZIYAN’s authorization, you may not | ||
| 17 | + * further disseminate the information, and you must immediately remove the | ||
| 18 | + * source code and notify ZIYAN of its removal. ZIYAN reserves the right to pursue | ||
| 19 | + * legal actions against you for any loss(es) or damage(s) caused by your | ||
| 20 | + * failure to do so. | ||
| 21 | + * | ||
| 22 | + ********************************************************************* | ||
| 23 | + */ | ||
| 24 | + | ||
| 25 | +/* Define to prevent recursive inclusion -------------------------------------*/ | ||
| 26 | +#ifndef ZIYAN_SDK_APP_INFO_H | ||
| 27 | +#define ZIYAN_SDK_APP_INFO_H | ||
| 28 | + | ||
| 29 | +/* Includes ------------------------------------------------------------------*/ | ||
| 30 | + | ||
| 31 | +#ifdef __cplusplus | ||
| 32 | +extern "C" { | ||
| 33 | +#endif | ||
| 34 | + | ||
| 35 | +/* Exported constants --------------------------------------------------------*/ | ||
| 36 | +// ATTENTION: User must goto https://developer.ziyan.com/user/apps/#all to create your own ziyan sdk application, get ziyan sdk application | ||
| 37 | +// information then fill in the application information here. | ||
| 38 | +#define USER_APP_NAME "app_name_ziyan" | ||
| 39 | +#define USER_APP_ID "app_id_ziyan" | ||
| 40 | +#define USER_APP_KEY "app_key_ziyan" | ||
| 41 | +#define USER_APP_LICENSE "app_license_ziyan" | ||
| 42 | +#define USER_DEVELOPER_ACCOUNT "developer_account_ziyan" | ||
| 43 | +#define USER_BAUD_RATE "921600" | ||
| 44 | + | ||
| 45 | +/* Exported types ------------------------------------------------------------*/ | ||
| 46 | + | ||
| 47 | +/* Exported functions --------------------------------------------------------*/ | ||
| 48 | + | ||
| 49 | + | ||
| 50 | +#ifdef __cplusplus | ||
| 51 | +} | ||
| 52 | +#endif | ||
| 53 | + | ||
| 54 | +#endif // ZIYAN_SDK_APP_INFO_H | ||
| 55 | +/************************ (C) COPYRIGHT ZIYAN Innovations *******END OF FILE******/ |
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file ziyan_sdk_config.h | ||
| 4 | + * @brief This is the header file for "ziyan_config.c", defining the structure and | ||
| 5 | + * (exported) function prototypes. | ||
| 6 | + * | ||
| 7 | + * @copyright (c) 2021 ZIYAN. All rights reserved. | ||
| 8 | + * | ||
| 9 | + * All information contained herein is, and remains, the property of ZIYAN. | ||
| 10 | + * The intellectual and technical concepts contained herein are proprietary | ||
| 11 | + * to ZIYAN and may be covered by U.S. and foreign patents, patents in process, | ||
| 12 | + * and protected by trade secret or copyright law. Dissemination of this | ||
| 13 | + * information, including but not limited to data and other proprietary | ||
| 14 | + * material(s) incorporated within the information, in any form, is strictly | ||
| 15 | + * prohibited without the express written consent of ZIYAN. | ||
| 16 | + * | ||
| 17 | + * If you receive this source code without ZIYAN’s authorization, you may not | ||
| 18 | + * further disseminate the information, and you must immediately remove the | ||
| 19 | + * source code and notify ZIYAN of its removal. ZIYAN reserves the right to pursue | ||
| 20 | + * legal actions against you for any loss(es) or damage(s) caused by your | ||
| 21 | + * failure to do so. | ||
| 22 | + * | ||
| 23 | + ********************************************************************* | ||
| 24 | + */ | ||
| 25 | + | ||
| 26 | +/* Define to prevent recursive inclusion -------------------------------------*/ | ||
| 27 | +#ifndef ZIYAN_SDK_CONFIG_H | ||
| 28 | +#define ZIYAN_SDK_CONFIG_H | ||
| 29 | + | ||
| 30 | +/* Includes ------------------------------------------------------------------*/ | ||
| 31 | + | ||
| 32 | +#ifdef __cplusplus | ||
| 33 | +extern "C" { | ||
| 34 | +#endif | ||
| 35 | + | ||
| 36 | +/* Exported constants --------------------------------------------------------*/ | ||
| 37 | +#define ZIYAN_USE_ONLY_UART (0) | ||
| 38 | +#define ZIYAN_USE_UART_AND_USB_BULK_DEVICE (1) | ||
| 39 | +#define ZIYAN_USE_UART_AND_NETWORK_DEVICE (2) | ||
| 40 | + | ||
| 41 | +/*!< Attention: Select your hardware connection mode here. | ||
| 42 | +* */ | ||
| 43 | +#define CONFIG_HARDWARE_CONNECTION ZIYAN_USE_ONLY_UART | ||
| 44 | + | ||
| 45 | +/*!< Attention: Select the sample you want to run here. | ||
| 46 | +* */ | ||
| 47 | +// #define CONFIG_MODULE_SAMPLE_POWER_MANAGEMENT_ON | ||
| 48 | + | ||
| 49 | +// #define CONFIG_MODULE_SAMPLE_CAMERA_EMU_ON | ||
| 50 | + | ||
| 51 | +// #define CONFIG_MODULE_SAMPLE_CAMERA_MEDIA_ON | ||
| 52 | + | ||
| 53 | +// #define CONFIG_MODULE_SAMPLE_GIMBAL_EMU_ON | ||
| 54 | + | ||
| 55 | +// #define CONFIG_MODULE_SAMPLE_XPORT_ON | ||
| 56 | + | ||
| 57 | +#define CONFIG_MODULE_SAMPLE_WIDGET_ON | ||
| 58 | + | ||
| 59 | +#define CONFIG_MODULE_SAMPLE_WIDGET_SPEAKER_ON | ||
| 60 | + | ||
| 61 | +// #define CONFIG_MODULE_SAMPLE_DATA_TRANSMISSION_ON | ||
| 62 | + | ||
| 63 | +// #define CONFIG_MODULE_SAMPLE_UPGRADE_ON | ||
| 64 | + | ||
| 65 | +// #define CONFIG_MODULE_SAMPLE_HMS_CUSTOMIZATION_ON | ||
| 66 | + | ||
| 67 | +#define CONFIG_MODULE_SAMPLE_FC_SUBSCRIPTION_ON | ||
| 68 | + | ||
| 69 | +/*!< Attention: This function needs to be used together with mobile sdk mop sample. | ||
| 70 | +* */ | ||
| 71 | +//#define CONFIG_MODULE_SAMPLE_MOP_CHANNEL_ON | ||
| 72 | + | ||
| 73 | +/* Exported types ------------------------------------------------------------*/ | ||
| 74 | + | ||
| 75 | +/* Exported functions --------------------------------------------------------*/ | ||
| 76 | + | ||
| 77 | +#ifdef __cplusplus | ||
| 78 | +} | ||
| 79 | +#endif | ||
| 80 | + | ||
| 81 | +#endif // ZIYAN_SDK_CONFIG_H | ||
| 82 | +/************************ (C) COPYRIGHT ZIYAN Innovations *******END OF FILE******/ |
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file hal_network.c | ||
| 4 | + * @brief | ||
| 5 | + * | ||
| 6 | + * @copyright (c) 2021 ZIYAN. All rights reserved. | ||
| 7 | + * | ||
| 8 | + * All information contained herein is, and remains, the property of ZIYAN. | ||
| 9 | + * The intellectual and technical concepts contained herein are proprietary | ||
| 10 | + * to ZIYAN and may be covered by U.S. and foreign patents, patents in process, | ||
| 11 | + * and protected by trade secret or copyright law. Dissemination of this | ||
| 12 | + * information, including but not limited to data and other proprietary | ||
| 13 | + * material(s) incorporated within the information, in any form, is strictly | ||
| 14 | + * prohibited without the express written consent of ZIYAN. | ||
| 15 | + * | ||
| 16 | + * If you receive this source code without ZIYAN’s authorization, you may not | ||
| 17 | + * further disseminate the information, and you must immediately remove the | ||
| 18 | + * source code and notify ZIYAN of its removal. ZIYAN reserves the right to pursue | ||
| 19 | + * legal actions against you for any loss(es) or damage(s) caused by your | ||
| 20 | + * failure to do so. | ||
| 21 | + * | ||
| 22 | + ********************************************************************* | ||
| 23 | + */ | ||
| 24 | + | ||
| 25 | +/* Includes ------------------------------------------------------------------*/ | ||
| 26 | +#include "string.h" | ||
| 27 | +#include "stdlib.h" | ||
| 28 | +#include "stdio.h" | ||
| 29 | +#include "hal_network.h" | ||
| 30 | +#include "ziyan_logger.h" | ||
| 31 | + | ||
| 32 | +/* Private constants ---------------------------------------------------------*/ | ||
| 33 | + | ||
| 34 | +/* Private types -------------------------------------------------------------*/ | ||
| 35 | + | ||
| 36 | +/* Private values -------------------------------------------------------------*/ | ||
| 37 | + | ||
| 38 | +/* Private functions declaration ---------------------------------------------*/ | ||
| 39 | + | ||
| 40 | +/* Exported functions definition ---------------------------------------------*/ | ||
| 41 | +T_ZiyanReturnCode HalNetWork_Init(const char *ipAddr, const char *netMask, T_ZiyanNetworkHandle *halObj) | ||
| 42 | +{ | ||
| 43 | + int32_t ret; | ||
| 44 | + char cmdStr[LINUX_CMD_STR_MAX_SIZE]; | ||
| 45 | + | ||
| 46 | + if (ipAddr == NULL || netMask == NULL) { | ||
| 47 | + USER_LOG_ERROR("hal network config param error"); | ||
| 48 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER; | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + //Attention: need root permission to config ip addr and netmask. | ||
| 52 | + memset(cmdStr, 0, sizeof(cmdStr)); | ||
| 53 | + | ||
| 54 | + snprintf(cmdStr, sizeof(cmdStr), "ifconfig %s up", LINUX_NETWORK_DEV); | ||
| 55 | + ret = system(cmdStr); | ||
| 56 | + if (ret != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 57 | + USER_LOG_ERROR("Can't open the network." | ||
| 58 | + "Probably the program not execute with root permission." | ||
| 59 | + "Please use the root permission to execute the program."); | ||
| 60 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + snprintf(cmdStr, sizeof(cmdStr), "ifconfig %s %s netmask %s", LINUX_NETWORK_DEV, ipAddr, netMask); | ||
| 64 | + ret = system(cmdStr); | ||
| 65 | + if (ret != ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 66 | + USER_LOG_ERROR("Can't config the ip address of network." | ||
| 67 | + "Probably the program not execute with root permission." | ||
| 68 | + "Please use the root permission to execute the program."); | ||
| 69 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 73 | +} | ||
| 74 | + | ||
| 75 | +T_ZiyanReturnCode HalNetWork_DeInit(T_ZiyanNetworkHandle halObj) | ||
| 76 | +{ | ||
| 77 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 78 | +} | ||
| 79 | + | ||
| 80 | +T_ZiyanReturnCode HalNetWork_GetDeviceInfo(T_ZiyanHalNetworkDeviceInfo *deviceInfo) | ||
| 81 | +{ | ||
| 82 | + deviceInfo->usbNetAdapter.vid = USB_NET_ADAPTER_VID; | ||
| 83 | + deviceInfo->usbNetAdapter.pid = USB_NET_ADAPTER_PID; | ||
| 84 | + | ||
| 85 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 86 | +} | ||
| 87 | + | ||
| 88 | +/* Private functions definition-----------------------------------------------*/ | ||
| 89 | + | ||
| 90 | +/****************** (C) COPYRIGHT ZIYAN Innovations *****END OF FILE****/ |
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file hal_network.h | ||
| 4 | + * @brief This is the header file for "hal_network.c", defining the structure and | ||
| 5 | + * (exported) function prototypes. | ||
| 6 | + * | ||
| 7 | + * @copyright (c) 2021 ZIYAN. All rights reserved. | ||
| 8 | + * | ||
| 9 | + * All information contained herein is, and remains, the property of ZIYAN. | ||
| 10 | + * The intellectual and technical concepts contained herein are proprietary | ||
| 11 | + * to ZIYAN and may be covered by U.S. and foreign patents, patents in process, | ||
| 12 | + * and protected by trade secret or copyright law. Dissemination of this | ||
| 13 | + * information, including but not limited to data and other proprietary | ||
| 14 | + * material(s) incorporated within the information, in any form, is strictly | ||
| 15 | + * prohibited without the express written consent of ZIYAN. | ||
| 16 | + * | ||
| 17 | + * If you receive this source code without ZIYAN’s authorization, you may not | ||
| 18 | + * further disseminate the information, and you must immediately remove the | ||
| 19 | + * source code and notify ZIYAN of its removal. ZIYAN reserves the right to pursue | ||
| 20 | + * legal actions against you for any loss(es) or damage(s) caused by your | ||
| 21 | + * failure to do so. | ||
| 22 | + * | ||
| 23 | + ********************************************************************* | ||
| 24 | + */ | ||
| 25 | + | ||
| 26 | +/* Define to prevent recursive inclusion -------------------------------------*/ | ||
| 27 | +#ifndef HAL_NETWORK_H | ||
| 28 | +#define HAL_NETWORK_H | ||
| 29 | + | ||
| 30 | +/* Includes ------------------------------------------------------------------*/ | ||
| 31 | +#include "ziyan_platform.h" | ||
| 32 | + | ||
| 33 | +#ifdef __cplusplus | ||
| 34 | +extern "C" { | ||
| 35 | +#endif | ||
| 36 | + | ||
| 37 | +/* Exported constants --------------------------------------------------------*/ | ||
| 38 | + | ||
| 39 | +/** @attention User can config network card name here, if your device is not MF2C/G, please comment below and add your | ||
| 40 | + * NIC name micro define as #define 'LINUX_NETWORK_DEV "your NIC name"'. | ||
| 41 | + */ | ||
| 42 | +#ifdef PLATFORM_ARCH_x86_64 | ||
| 43 | +#define LINUX_NETWORK_DEV "enxf8e43b7bbc2c" | ||
| 44 | +#else | ||
| 45 | +#define LINUX_NETWORK_DEV "l4tbr0" | ||
| 46 | +#endif | ||
| 47 | +/** | ||
| 48 | + * @attention | ||
| 49 | + */ | ||
| 50 | + | ||
| 51 | +#ifdef PLATFORM_ARCH_x86_64 | ||
| 52 | +#define USB_NET_ADAPTER_VID (0x0B95) | ||
| 53 | +#define USB_NET_ADAPTER_PID (0x1790) | ||
| 54 | +#else | ||
| 55 | +#define USB_NET_ADAPTER_VID (0x0955) | ||
| 56 | +#define USB_NET_ADAPTER_PID (0x7020) | ||
| 57 | +#endif | ||
| 58 | + | ||
| 59 | +#define LINUX_CMD_STR_MAX_SIZE (128) | ||
| 60 | + | ||
| 61 | +/* Exported types ------------------------------------------------------------*/ | ||
| 62 | + | ||
| 63 | +/* Exported functions --------------------------------------------------------*/ | ||
| 64 | +T_ZiyanReturnCode HalNetWork_Init(const char *ipAddr, const char *netMask, T_ZiyanNetworkHandle *halObj); | ||
| 65 | +T_ZiyanReturnCode HalNetWork_DeInit(T_ZiyanNetworkHandle halObj); | ||
| 66 | +T_ZiyanReturnCode HalNetWork_GetDeviceInfo(T_ZiyanHalNetworkDeviceInfo *deviceInfo); | ||
| 67 | + | ||
| 68 | +#ifdef __cplusplus | ||
| 69 | +} | ||
| 70 | +#endif | ||
| 71 | + | ||
| 72 | +#endif // HAL_NETWORK_H | ||
| 73 | +/************************ (C) COPYRIGHT ZIYAN Innovations *******END OF FILE******/ |
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file hal_uart.c | ||
| 4 | + * @brief | ||
| 5 | + * | ||
| 6 | + * @copyright (c) 2021 ZIYAN. All rights reserved. | ||
| 7 | + * | ||
| 8 | + * All information contained herein is, and remains, the property of ZIYAN. | ||
| 9 | + * The intellectual and technical concepts contained herein are proprietary | ||
| 10 | + * to ZIYAN and may be covered by U.S. and foreign patents, patents in process, | ||
| 11 | + * and protected by trade secret or copyright law. Dissemination of this | ||
| 12 | + * information, including but not limited to data and other proprietary | ||
| 13 | + * material(s) incorporated within the information, in any form, is strictly | ||
| 14 | + * prohibited without the express written consent of ZIYAN. | ||
| 15 | + * | ||
| 16 | + * If you receive this source code without ZIYAN’s authorization, you may not | ||
| 17 | + * further disseminate the information, and you must immediately remove the | ||
| 18 | + * source code and notify ZIYAN of its removal. ZIYAN reserves the right to pursue | ||
| 19 | + * legal actions against you for any loss(es) or damage(s) caused by your | ||
| 20 | + * failure to do so. | ||
| 21 | + * | ||
| 22 | + ********************************************************************* | ||
| 23 | + */ | ||
| 24 | + | ||
| 25 | +/* Includes ------------------------------------------------------------------*/ | ||
| 26 | +#include <ziyan_logger.h> | ||
| 27 | +#include "hal_uart.h" | ||
| 28 | + | ||
| 29 | +/* Private constants ---------------------------------------------------------*/ | ||
| 30 | +#define UART_DEV_NAME_STR_SIZE (128) | ||
| 31 | +#define ZIYAN_SYSTEM_CMD_STR_MAX_SIZE (128) | ||
| 32 | +#define ZIYAN_SYSTEM_RESULT_STR_MAX_SIZE (128) | ||
| 33 | + | ||
| 34 | +/* Private types -------------------------------------------------------------*/ | ||
| 35 | +typedef struct { | ||
| 36 | + int32_t uartFd; | ||
| 37 | +} T_UartHandleStruct; | ||
| 38 | + | ||
| 39 | +/* Private values -------------------------------------------------------------*/ | ||
| 40 | + | ||
| 41 | +/* Private functions declaration ---------------------------------------------*/ | ||
| 42 | + | ||
| 43 | +/* Exported functions definition ---------------------------------------------*/ | ||
| 44 | +T_ZiyanReturnCode HalUart_Init(E_ZiyanHalUartNum uartNum, uint32_t baudRate, T_ZiyanUartHandle *uartHandle) | ||
| 45 | +{ | ||
| 46 | + T_UartHandleStruct *uartHandleStruct = NULL; | ||
| 47 | + struct termios options; | ||
| 48 | + struct flock lock; | ||
| 49 | + T_ZiyanReturnCode returnCode = ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 50 | + char uartName[UART_DEV_NAME_STR_SIZE]; | ||
| 51 | + char systemCmd[ZIYAN_SYSTEM_CMD_STR_MAX_SIZE + 32]; | ||
| 52 | + char *ret = NULL; | ||
| 53 | + char lineBuf[ZIYAN_SYSTEM_RESULT_STR_MAX_SIZE] = {0}; | ||
| 54 | + FILE *fp; | ||
| 55 | + | ||
| 56 | + uartHandleStruct = malloc(sizeof(T_UartHandleStruct)); | ||
| 57 | + if (uartHandleStruct == NULL) { | ||
| 58 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_MEMORY_ALLOC_FAILED; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + if (uartNum == ZIYAN_HAL_UART_NUM_0) { | ||
| 62 | + strcpy(uartName, LINUX_UART_DEV1); | ||
| 63 | + } else if (uartNum == ZIYAN_HAL_UART_NUM_1) { | ||
| 64 | + strcpy(uartName, LINUX_UART_DEV2); | ||
| 65 | + } else { | ||
| 66 | + goto free_uart_handle; | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | +#ifdef USE_CLION_DEBUG | ||
| 70 | + sprintf(systemCmd, "ls -l %s", uartName); | ||
| 71 | + fp = popen(systemCmd, "r"); | ||
| 72 | + if (fp == NULL) { | ||
| 73 | + goto free_uart_handle; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + ret = fgets(lineBuf, sizeof(lineBuf), fp); | ||
| 77 | + if (ret == NULL) { | ||
| 78 | + goto close_fp; | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + if (strstr(lineBuf, "crwxrwxrwx") == NULL) { | ||
| 82 | + USER_LOG_ERROR("Can't operation the device. " | ||
| 83 | + "Probably the device has not operation permission. " | ||
| 84 | + "Please execute command 'sudo chmod 777 %s' to add permission. ", uartName); | ||
| 85 | + goto close_fp; | ||
| 86 | + } | ||
| 87 | +#else | ||
| 88 | + sprintf(systemCmd, "chmod 777 %s", uartName); | ||
| 89 | + fp = popen(systemCmd, "r"); | ||
| 90 | + if (fp == NULL) { | ||
| 91 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 92 | + } | ||
| 93 | +#endif | ||
| 94 | + | ||
| 95 | + uartHandleStruct->uartFd = open(uartName, (unsigned) O_RDWR | (unsigned) O_NOCTTY | (unsigned) O_NDELAY); | ||
| 96 | + if (uartHandleStruct->uartFd == -1) { | ||
| 97 | + goto close_fp; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + // Forbid multiple psdk programs to access the serial port | ||
| 101 | + lock.l_type = F_WRLCK; | ||
| 102 | + lock.l_pid = getpid(); | ||
| 103 | + lock.l_whence = SEEK_SET; | ||
| 104 | + lock.l_start = 0; | ||
| 105 | + lock.l_len = 0; | ||
| 106 | + | ||
| 107 | + if (fcntl(uartHandleStruct->uartFd, F_GETLK, &lock) < 0) { | ||
| 108 | + goto close_uart_fd; | ||
| 109 | + } | ||
| 110 | + if (lock.l_type != F_UNLCK) { | ||
| 111 | + goto close_uart_fd; | ||
| 112 | + } | ||
| 113 | + lock.l_type = F_WRLCK; | ||
| 114 | + lock.l_pid = getpid(); | ||
| 115 | + lock.l_whence = SEEK_SET; | ||
| 116 | + lock.l_start = 0; | ||
| 117 | + lock.l_len = 0; | ||
| 118 | + if (fcntl(uartHandleStruct->uartFd, F_SETLKW, &lock) < 0) { | ||
| 119 | + goto close_uart_fd; | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + if (tcgetattr(uartHandleStruct->uartFd, &options) != 0) { | ||
| 123 | + goto close_uart_fd; | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + switch (baudRate) { | ||
| 127 | + case 115200: | ||
| 128 | + cfsetispeed(&options, B115200); | ||
| 129 | + cfsetospeed(&options, B115200); | ||
| 130 | + break; | ||
| 131 | + case 230400: | ||
| 132 | + cfsetispeed(&options, B230400); | ||
| 133 | + cfsetospeed(&options, B230400); | ||
| 134 | + break; | ||
| 135 | + case 460800: | ||
| 136 | + cfsetispeed(&options, B460800); | ||
| 137 | + cfsetospeed(&options, B460800); | ||
| 138 | + break; | ||
| 139 | + case 921600: | ||
| 140 | + cfsetispeed(&options, B921600); | ||
| 141 | + cfsetospeed(&options, B921600); | ||
| 142 | + break; | ||
| 143 | + case 1000000: | ||
| 144 | + cfsetispeed(&options, B1000000); | ||
| 145 | + cfsetospeed(&options, B1000000); | ||
| 146 | + break; | ||
| 147 | + default: | ||
| 148 | + goto close_uart_fd; | ||
| 149 | + } | ||
| 150 | + | ||
| 151 | + options.c_cflag |= (unsigned) CLOCAL; | ||
| 152 | + options.c_cflag |= (unsigned) CREAD; | ||
| 153 | + options.c_cflag &= ~(unsigned) CRTSCTS; | ||
| 154 | + options.c_cflag &= ~(unsigned) CSIZE; | ||
| 155 | + options.c_cflag |= (unsigned) CS8; | ||
| 156 | + options.c_cflag &= ~(unsigned) PARENB; | ||
| 157 | + options.c_iflag &= ~(unsigned) INPCK; | ||
| 158 | + options.c_cflag &= ~(unsigned) CSTOPB; | ||
| 159 | + options.c_oflag &= ~(unsigned) OPOST; | ||
| 160 | + options.c_lflag &= ~((unsigned) ICANON | (unsigned) ECHO | (unsigned) ECHOE | (unsigned) ISIG); | ||
| 161 | + options.c_iflag &= ~((unsigned) BRKINT | (unsigned) ICRNL | (unsigned) INPCK | (unsigned) ISTRIP | (unsigned) IXON); | ||
| 162 | + options.c_cc[VTIME] = 0; | ||
| 163 | + options.c_cc[VMIN] = 0; | ||
| 164 | + | ||
| 165 | + tcflush(uartHandleStruct->uartFd, TCIFLUSH); | ||
| 166 | + | ||
| 167 | + if (tcsetattr(uartHandleStruct->uartFd, TCSANOW, &options) != 0) { | ||
| 168 | + goto close_uart_fd; | ||
| 169 | + } | ||
| 170 | + | ||
| 171 | + *uartHandle = uartHandleStruct; | ||
| 172 | + pclose(fp); | ||
| 173 | + | ||
| 174 | + return returnCode; | ||
| 175 | + | ||
| 176 | +close_uart_fd: | ||
| 177 | + close(uartHandleStruct->uartFd); | ||
| 178 | + | ||
| 179 | +close_fp: | ||
| 180 | + pclose(fp); | ||
| 181 | + | ||
| 182 | +free_uart_handle: | ||
| 183 | + free(uartHandleStruct); | ||
| 184 | + | ||
| 185 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 186 | +} | ||
| 187 | + | ||
| 188 | +T_ZiyanReturnCode HalUart_DeInit(T_ZiyanUartHandle uartHandle) | ||
| 189 | +{ | ||
| 190 | + int32_t ret; | ||
| 191 | + T_UartHandleStruct *uartHandleStruct = (T_UartHandleStruct *) uartHandle; | ||
| 192 | + | ||
| 193 | + if (uartHandle == NULL) { | ||
| 194 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_UNKNOWN; | ||
| 195 | + } | ||
| 196 | + | ||
| 197 | + ret = close(uartHandleStruct->uartFd); | ||
| 198 | + if (ret < 0) { | ||
| 199 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 200 | + } | ||
| 201 | + | ||
| 202 | + free(uartHandleStruct); | ||
| 203 | + | ||
| 204 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 205 | +} | ||
| 206 | + | ||
| 207 | +T_ZiyanReturnCode HalUart_WriteData(T_ZiyanUartHandle uartHandle, const uint8_t *buf, uint32_t len, uint32_t *realLen) | ||
| 208 | +{ | ||
| 209 | + int32_t ret; | ||
| 210 | + T_UartHandleStruct *uartHandleStruct = (T_UartHandleStruct *) uartHandle; | ||
| 211 | + | ||
| 212 | + if (uartHandle == NULL || buf == NULL || len == 0 || realLen == NULL) { | ||
| 213 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER; | ||
| 214 | + } | ||
| 215 | + | ||
| 216 | + ret = write(uartHandleStruct->uartFd, buf, len); | ||
| 217 | + if (ret >= 0) { | ||
| 218 | + *realLen = ret; | ||
| 219 | + } else { | ||
| 220 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 221 | + } | ||
| 222 | + | ||
| 223 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 224 | +} | ||
| 225 | + | ||
| 226 | +T_ZiyanReturnCode HalUart_ReadData(T_ZiyanUartHandle uartHandle, uint8_t *buf, uint32_t len, uint32_t *realLen) | ||
| 227 | +{ | ||
| 228 | + int32_t ret; | ||
| 229 | + T_UartHandleStruct *uartHandleStruct = (T_UartHandleStruct *) uartHandle; | ||
| 230 | + | ||
| 231 | + if (uartHandle == NULL || buf == NULL || len == 0 || realLen == NULL) { | ||
| 232 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER; | ||
| 233 | + } | ||
| 234 | + | ||
| 235 | + ret = read(uartHandleStruct->uartFd, buf, len); | ||
| 236 | + if (ret >= 0) { | ||
| 237 | + *realLen = ret; | ||
| 238 | + } else { | ||
| 239 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 240 | + } | ||
| 241 | + | ||
| 242 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 243 | +} | ||
| 244 | + | ||
| 245 | +T_ZiyanReturnCode HalUart_GetStatus(E_ZiyanHalUartNum uartNum, T_ZiyanUartStatus *status) | ||
| 246 | +{ | ||
| 247 | + if (uartNum == ZIYAN_HAL_UART_NUM_0) { | ||
| 248 | + status->isConnect = true; | ||
| 249 | + } else if (uartNum == ZIYAN_HAL_UART_NUM_1) { | ||
| 250 | + status->isConnect = true; | ||
| 251 | + } else { | ||
| 252 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER; | ||
| 253 | + } | ||
| 254 | + | ||
| 255 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 256 | +} | ||
| 257 | + | ||
| 258 | +/* Private functions definition-----------------------------------------------*/ | ||
| 259 | + | ||
| 260 | +/****************** (C) COPYRIGHT ZIYAN Innovations *****END OF FILE****/ |
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file hal_uart.h | ||
| 4 | + * @brief This is the header file for "hal_uart.c", defining the structure and | ||
| 5 | + * (exported) function prototypes. | ||
| 6 | + * | ||
| 7 | + * @copyright (c) 2021 ZIYAN. All rights reserved. | ||
| 8 | + * | ||
| 9 | + * All information contained herein is, and remains, the property of ZIYAN. | ||
| 10 | + * The intellectual and technical concepts contained herein are proprietary | ||
| 11 | + * to ZIYAN and may be covered by U.S. and foreign patents, patents in process, | ||
| 12 | + * and protected by trade secret or copyright law. Dissemination of this | ||
| 13 | + * information, including but not limited to data and other proprietary | ||
| 14 | + * material(s) incorporated within the information, in any form, is strictly | ||
| 15 | + * prohibited without the express written consent of ZIYAN. | ||
| 16 | + * | ||
| 17 | + * If you receive this source code without ZIYAN’s authorization, you may not | ||
| 18 | + * further disseminate the information, and you must immediately remove the | ||
| 19 | + * source code and notify ZIYAN of its removal. ZIYAN reserves the right to pursue | ||
| 20 | + * legal actions against you for any loss(es) or damage(s) caused by your | ||
| 21 | + * failure to do so. | ||
| 22 | + * | ||
| 23 | + ********************************************************************* | ||
| 24 | + */ | ||
| 25 | + | ||
| 26 | +/* Define to prevent recursive inclusion -------------------------------------*/ | ||
| 27 | +#ifndef HAL_UART_H | ||
| 28 | +#define HAL_UART_H | ||
| 29 | + | ||
| 30 | +/* Includes ------------------------------------------------------------------*/ | ||
| 31 | +#include "stdint.h" | ||
| 32 | +#include <stdio.h> | ||
| 33 | +#include <unistd.h> | ||
| 34 | +#include <fcntl.h> | ||
| 35 | +#include <termios.h> | ||
| 36 | +#include <unistd.h> | ||
| 37 | +#include <string.h> | ||
| 38 | +#include "stdlib.h" | ||
| 39 | + | ||
| 40 | +#include "ziyan_platform.h" | ||
| 41 | + | ||
| 42 | +#ifdef __cplusplus | ||
| 43 | +extern "C" { | ||
| 44 | +#endif | ||
| 45 | + | ||
| 46 | +/* Exported constants --------------------------------------------------------*/ | ||
| 47 | +//User can config dev based on there environmental conditions | ||
| 48 | +#define LINUX_UART_DEV1 "/dev/ttyS1" | ||
| 49 | +#define LINUX_UART_DEV2 "/dev/ttyACM0" | ||
| 50 | + | ||
| 51 | +/* Exported types ------------------------------------------------------------*/ | ||
| 52 | + | ||
| 53 | +/* Exported functions --------------------------------------------------------*/ | ||
| 54 | +T_ZiyanReturnCode HalUart_Init(E_ZiyanHalUartNum uartNum, uint32_t baudRate, T_ZiyanUartHandle *uartHandle); | ||
| 55 | +T_ZiyanReturnCode HalUart_DeInit(T_ZiyanUartHandle uartHandle); | ||
| 56 | +T_ZiyanReturnCode HalUart_WriteData(T_ZiyanUartHandle uartHandle, const uint8_t *buf, uint32_t len, uint32_t *realLen); | ||
| 57 | +T_ZiyanReturnCode HalUart_ReadData(T_ZiyanUartHandle uartHandle, uint8_t *buf, uint32_t len, uint32_t *realLen); | ||
| 58 | +T_ZiyanReturnCode HalUart_GetStatus(E_ZiyanHalUartNum uartNum, T_ZiyanUartStatus *status); | ||
| 59 | + | ||
| 60 | +#ifdef __cplusplus | ||
| 61 | +} | ||
| 62 | +#endif | ||
| 63 | + | ||
| 64 | +#endif // HAL_UART_H | ||
| 65 | +/************************ (C) COPYRIGHT ZIYAN Innovations *******END OF FILE******/ |
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file hal_usb_bulk.c | ||
| 4 | + * @brief | ||
| 5 | + * | ||
| 6 | + * @copyright (c) 2021 ZIYAN. All rights reserved. | ||
| 7 | + * | ||
| 8 | + * All information contained herein is, and remains, the property of ZIYAN. | ||
| 9 | + * The intellectual and technical concepts contained herein are proprietary | ||
| 10 | + * to ZIYAN and may be covered by U.S. and foreign patents, patents in process, | ||
| 11 | + * and protected by trade secret or copyright law. Dissemination of this | ||
| 12 | + * information, including but not limited to data and other proprietary | ||
| 13 | + * material(s) incorporated within the information, in any form, is strictly | ||
| 14 | + * prohibited without the express written consent of ZIYAN. | ||
| 15 | + * | ||
| 16 | + * If you receive this source code without ZIYAN’s authorization, you may not | ||
| 17 | + * further disseminate the information, and you must immediately remove the | ||
| 18 | + * source code and notify ZIYAN of its removal. ZIYAN reserves the right to pursue | ||
| 19 | + * legal actions against you for any loss(es) or damage(s) caused by your | ||
| 20 | + * failure to do so. | ||
| 21 | + * | ||
| 22 | + ********************************************************************* | ||
| 23 | + */ | ||
| 24 | + | ||
| 25 | +/* Includes ------------------------------------------------------------------*/ | ||
| 26 | +#include "hal_usb_bulk.h" | ||
| 27 | +#include "ziyan_logger.h" | ||
| 28 | + | ||
| 29 | +/* Private constants ---------------------------------------------------------*/ | ||
| 30 | +#define LINUX_USB_BULK_TRANSFER_TIMEOUT_MS (50) | ||
| 31 | +#define LINUX_USB_BULK_TRANSFER_WAIT_FOREVER (-1) | ||
| 32 | + | ||
| 33 | +/* Private types -------------------------------------------------------------*/ | ||
| 34 | +typedef struct { | ||
| 35 | +#ifdef LIBUSB_INSTALLED | ||
| 36 | + libusb_device_handle *handle; | ||
| 37 | +#else | ||
| 38 | + void *handle; | ||
| 39 | +#endif | ||
| 40 | + int32_t ep1; | ||
| 41 | + int32_t ep2; | ||
| 42 | + uint32_t interfaceNum; | ||
| 43 | + T_ZiyanHalUsbBulkInfo usbBulkInfo; | ||
| 44 | +} T_HalUsbBulkObj; | ||
| 45 | + | ||
| 46 | +/* Private values -------------------------------------------------------------*/ | ||
| 47 | + | ||
| 48 | +/* Private functions declaration ---------------------------------------------*/ | ||
| 49 | + | ||
| 50 | +/* Exported functions definition ---------------------------------------------*/ | ||
| 51 | +T_ZiyanReturnCode HalUsbBulk_Init(T_ZiyanHalUsbBulkInfo usbBulkInfo, T_ZiyanUsbBulkHandle *usbBulkHandle) | ||
| 52 | +{ | ||
| 53 | + int32_t ret; | ||
| 54 | + struct libusb_device_handle *handle = NULL; | ||
| 55 | + | ||
| 56 | + *usbBulkHandle = malloc(sizeof(T_HalUsbBulkObj)); | ||
| 57 | + if (*usbBulkHandle == NULL) { | ||
| 58 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + if (usbBulkInfo.isUsbHost == true) { | ||
| 62 | +#ifdef LIBUSB_INSTALLED | ||
| 63 | + ret = libusb_init(NULL); | ||
| 64 | + if (ret < 0) { | ||
| 65 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + handle = libusb_open_device_with_vid_pid(NULL, usbBulkInfo.vid, usbBulkInfo.pid); | ||
| 69 | + if (handle == NULL) { | ||
| 70 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + ret = libusb_claim_interface(handle, usbBulkInfo.channelInfo.interfaceNum); | ||
| 74 | + if (ret != LIBUSB_SUCCESS) { | ||
| 75 | + printf("libusb claim interface error"); | ||
| 76 | + libusb_close(handle); | ||
| 77 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + ((T_HalUsbBulkObj *) *usbBulkHandle)->handle = handle; | ||
| 81 | + memcpy(&((T_HalUsbBulkObj *) *usbBulkHandle)->usbBulkInfo, &usbBulkInfo, sizeof(usbBulkInfo)); | ||
| 82 | +#endif | ||
| 83 | + } else { | ||
| 84 | + ((T_HalUsbBulkObj *) *usbBulkHandle)->handle = handle; | ||
| 85 | + memcpy(&((T_HalUsbBulkObj *) *usbBulkHandle)->usbBulkInfo, &usbBulkInfo, sizeof(usbBulkInfo)); | ||
| 86 | + ((T_HalUsbBulkObj *) *usbBulkHandle)->interfaceNum = usbBulkInfo.channelInfo.interfaceNum; | ||
| 87 | + | ||
| 88 | + if (usbBulkInfo.channelInfo.interfaceNum == LINUX_USB_BULK1_INTERFACE_NUM) { | ||
| 89 | + ((T_HalUsbBulkObj *) *usbBulkHandle)->ep1 = open(LINUX_USB_BULK1_EP_OUT_FD, O_RDWR); | ||
| 90 | + if (((T_HalUsbBulkObj *) *usbBulkHandle)->ep1 < 0) { | ||
| 91 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + ((T_HalUsbBulkObj *) *usbBulkHandle)->ep2 = open(LINUX_USB_BULK1_EP_IN_FD, O_RDWR); | ||
| 95 | + if (((T_HalUsbBulkObj *) *usbBulkHandle)->ep2 < 0) { | ||
| 96 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 97 | + } | ||
| 98 | + } else if (usbBulkInfo.channelInfo.interfaceNum == LINUX_USB_BULK2_INTERFACE_NUM) { | ||
| 99 | + ((T_HalUsbBulkObj *) *usbBulkHandle)->ep1 = open(LINUX_USB_BULK2_EP_OUT_FD, O_RDWR); | ||
| 100 | + if (((T_HalUsbBulkObj *) *usbBulkHandle)->ep1 < 0) { | ||
| 101 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + ((T_HalUsbBulkObj *) *usbBulkHandle)->ep2 = open(LINUX_USB_BULK2_EP_IN_FD, O_RDWR); | ||
| 105 | + if (((T_HalUsbBulkObj *) *usbBulkHandle)->ep2 < 0) { | ||
| 106 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 107 | + } | ||
| 108 | + } | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 112 | +} | ||
| 113 | + | ||
| 114 | +T_ZiyanReturnCode HalUsbBulk_DeInit(T_ZiyanUsbBulkHandle usbBulkHandle) | ||
| 115 | +{ | ||
| 116 | + struct libusb_device_handle *handle = NULL; | ||
| 117 | + T_ZiyanOsalHandler *osalHandler = ZiyanPlatform_GetOsalHandler(); | ||
| 118 | + | ||
| 119 | + if (usbBulkHandle == NULL) { | ||
| 120 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + handle = ((T_HalUsbBulkObj *) usbBulkHandle)->handle; | ||
| 124 | + | ||
| 125 | + if (((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.isUsbHost == true) { | ||
| 126 | +#ifdef LIBUSB_INSTALLED | ||
| 127 | + libusb_release_interface(handle, ((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.channelInfo.interfaceNum); | ||
| 128 | + osalHandler->TaskSleepMs(100); | ||
| 129 | + libusb_exit(NULL); | ||
| 130 | +#endif | ||
| 131 | + } else { | ||
| 132 | + close(((T_HalUsbBulkObj *) usbBulkHandle)->ep1); | ||
| 133 | + close(((T_HalUsbBulkObj *) usbBulkHandle)->ep2); | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + free(usbBulkHandle); | ||
| 137 | + | ||
| 138 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 139 | +} | ||
| 140 | + | ||
| 141 | +T_ZiyanReturnCode HalUsbBulk_WriteData(T_ZiyanUsbBulkHandle usbBulkHandle, const uint8_t *buf, uint32_t len, | ||
| 142 | + uint32_t *realLen) | ||
| 143 | +{ | ||
| 144 | + int32_t ret; | ||
| 145 | + int32_t actualLen; | ||
| 146 | + struct libusb_device_handle *handle = NULL; | ||
| 147 | + | ||
| 148 | + if (usbBulkHandle == NULL) { | ||
| 149 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + handle = ((T_HalUsbBulkObj *) usbBulkHandle)->handle; | ||
| 153 | + | ||
| 154 | + if (((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.isUsbHost == true) { | ||
| 155 | +#ifdef LIBUSB_INSTALLED | ||
| 156 | + ret = libusb_bulk_transfer(handle, ((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.channelInfo.endPointOut, | ||
| 157 | + (uint8_t *) buf, len, &actualLen, LINUX_USB_BULK_TRANSFER_TIMEOUT_MS); | ||
| 158 | + if (ret < 0) { | ||
| 159 | + USER_LOG_ERROR("Write usb bulk data failed, errno = %d", ret); | ||
| 160 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + *realLen = actualLen; | ||
| 164 | +#endif | ||
| 165 | + } else { | ||
| 166 | + *realLen = write(((T_HalUsbBulkObj *) usbBulkHandle)->ep1, buf, len); | ||
| 167 | + } | ||
| 168 | + | ||
| 169 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 170 | +} | ||
| 171 | + | ||
| 172 | +T_ZiyanReturnCode HalUsbBulk_ReadData(T_ZiyanUsbBulkHandle usbBulkHandle, uint8_t *buf, uint32_t len, | ||
| 173 | + uint32_t *realLen) | ||
| 174 | +{ | ||
| 175 | + int32_t ret; | ||
| 176 | + struct libusb_device_handle *handle = NULL; | ||
| 177 | + int32_t actualLen; | ||
| 178 | + | ||
| 179 | + if (usbBulkHandle == NULL) { | ||
| 180 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 181 | + } | ||
| 182 | + | ||
| 183 | + handle = ((T_HalUsbBulkObj *) usbBulkHandle)->handle; | ||
| 184 | + | ||
| 185 | + if (((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.isUsbHost == true) { | ||
| 186 | +#ifdef LIBUSB_INSTALLED | ||
| 187 | + ret = libusb_bulk_transfer(handle, ((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.channelInfo.endPointIn, | ||
| 188 | + buf, len, &actualLen, LINUX_USB_BULK_TRANSFER_WAIT_FOREVER); | ||
| 189 | + if (ret < 0) { | ||
| 190 | + USER_LOG_ERROR("Read usb bulk data failed, errno = %d", ret); | ||
| 191 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 192 | + } | ||
| 193 | + | ||
| 194 | + *realLen = actualLen; | ||
| 195 | +#endif | ||
| 196 | + } else { | ||
| 197 | + *realLen = read(((T_HalUsbBulkObj *) usbBulkHandle)->ep2, buf, len); | ||
| 198 | + } | ||
| 199 | + | ||
| 200 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 201 | +} | ||
| 202 | + | ||
| 203 | +T_ZiyanReturnCode HalUsbBulk_GetDeviceInfo(T_ZiyanHalUsbBulkDeviceInfo *deviceInfo) | ||
| 204 | +{ | ||
| 205 | + //attention: this interface only be called in usb device mode. | ||
| 206 | + deviceInfo->vid = LINUX_USB_VID; | ||
| 207 | + deviceInfo->pid = LINUX_USB_PID; | ||
| 208 | + | ||
| 209 | + // This bulk channel is used to obtain ZIYAN camera video stream and push 3rd-party camera video stream. | ||
| 210 | + deviceInfo->channelInfo[ZIYAN_HAL_USB_BULK_NUM_0].interfaceNum = LINUX_USB_BULK1_INTERFACE_NUM; | ||
| 211 | + deviceInfo->channelInfo[ZIYAN_HAL_USB_BULK_NUM_0].endPointIn = LINUX_USB_BULK1_END_POINT_IN; | ||
| 212 | + deviceInfo->channelInfo[ZIYAN_HAL_USB_BULK_NUM_0].endPointOut = LINUX_USB_BULK1_END_POINT_OUT; | ||
| 213 | + | ||
| 214 | + // This bulk channel is used to obtain ZIYAN perception image and download camera media file. | ||
| 215 | + deviceInfo->channelInfo[ZIYAN_HAL_USB_BULK_NUM_1].interfaceNum = LINUX_USB_BULK2_INTERFACE_NUM; | ||
| 216 | + deviceInfo->channelInfo[ZIYAN_HAL_USB_BULK_NUM_1].endPointIn = LINUX_USB_BULK2_END_POINT_IN; | ||
| 217 | + deviceInfo->channelInfo[ZIYAN_HAL_USB_BULK_NUM_1].endPointOut = LINUX_USB_BULK2_END_POINT_OUT; | ||
| 218 | + | ||
| 219 | + return ZIYAN_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 220 | +} | ||
| 221 | + | ||
| 222 | +/* Private functions definition-----------------------------------------------*/ | ||
| 223 | + | ||
| 224 | +/****************** (C) COPYRIGHT ZIYAN Innovations *****END OF FILE****/ |
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file hal_usb_bulk.h | ||
| 4 | + * @brief This is the header file for "hal_usb_bulk.c", defining the structure and | ||
| 5 | + * (exported) function prototypes. | ||
| 6 | + * | ||
| 7 | + * @copyright (c) 2021 ZIYAN. All rights reserved. | ||
| 8 | + * | ||
| 9 | + * All information contained herein is, and remains, the property of ZIYAN. | ||
| 10 | + * The intellectual and technical concepts contained herein are proprietary | ||
| 11 | + * to ZIYAN and may be covered by U.S. and foreign patents, patents in process, | ||
| 12 | + * and protected by trade secret or copyright law. Dissemination of this | ||
| 13 | + * information, including but not limited to data and other proprietary | ||
| 14 | + * material(s) incorporated within the information, in any form, is strictly | ||
| 15 | + * prohibited without the express written consent of ZIYAN. | ||
| 16 | + * | ||
| 17 | + * If you receive this source code without ZIYAN’s authorization, you may not | ||
| 18 | + * further disseminate the information, and you must immediately remove the | ||
| 19 | + * source code and notify ZIYAN of its removal. ZIYAN reserves the right to pursue | ||
| 20 | + * legal actions against you for any loss(es) or damage(s) caused by your | ||
| 21 | + * failure to do so. | ||
| 22 | + * | ||
| 23 | + ********************************************************************* | ||
| 24 | + */ | ||
| 25 | + | ||
| 26 | +/* Define to prevent recursive inclusion -------------------------------------*/ | ||
| 27 | +#ifndef HAL_USB_BULK_H | ||
| 28 | +#define HAL_USB_BULK_H | ||
| 29 | + | ||
| 30 | +/* Includes ------------------------------------------------------------------*/ | ||
| 31 | +#include "stdint.h" | ||
| 32 | +#include <stdio.h> | ||
| 33 | +#include <unistd.h> | ||
| 34 | +#include <fcntl.h> | ||
| 35 | +#include <termios.h> | ||
| 36 | +#include <unistd.h> | ||
| 37 | +#include <string.h> | ||
| 38 | +#include <sys/socket.h> | ||
| 39 | +#include <netinet/in.h> | ||
| 40 | +#include <arpa/inet.h> | ||
| 41 | + | ||
| 42 | +#ifdef LIBUSB_INSTALLED | ||
| 43 | + | ||
| 44 | +#include <libusb-1.0/libusb.h> | ||
| 45 | + | ||
| 46 | +#endif | ||
| 47 | + | ||
| 48 | +#include "ziyan_platform.h" | ||
| 49 | + | ||
| 50 | +#ifdef __cplusplus | ||
| 51 | +extern "C" { | ||
| 52 | +#endif | ||
| 53 | + | ||
| 54 | +/* Exported constants --------------------------------------------------------*/ | ||
| 55 | +#define LINUX_USB_BULK1_EP_OUT_FD "/dev/usb-ffs/bulk1/ep1" | ||
| 56 | +#define LINUX_USB_BULK1_EP_IN_FD "/dev/usb-ffs/bulk1/ep2" | ||
| 57 | + | ||
| 58 | +#define LINUX_USB_BULK1_INTERFACE_NUM (7) | ||
| 59 | +#define LINUX_USB_BULK1_END_POINT_IN (0x88) | ||
| 60 | +#define LINUX_USB_BULK1_END_POINT_OUT (5) | ||
| 61 | + | ||
| 62 | +#define LINUX_USB_BULK2_EP_OUT_FD "/dev/usb-ffs/bulk2/ep1" | ||
| 63 | +#define LINUX_USB_BULK2_EP_IN_FD "/dev/usb-ffs/bulk2/ep2" | ||
| 64 | + | ||
| 65 | +#define LINUX_USB_BULK2_INTERFACE_NUM (8) | ||
| 66 | +#define LINUX_USB_BULK2_END_POINT_IN (0x89) | ||
| 67 | +#define LINUX_USB_BULK2_END_POINT_OUT (6) | ||
| 68 | + | ||
| 69 | +#ifdef PLATFORM_ARCH_x86_64 | ||
| 70 | +#define LINUX_USB_VID (0x0B95) | ||
| 71 | +#define LINUX_USB_PID (0x1790) | ||
| 72 | +#else | ||
| 73 | +#define LINUX_USB_VID (0x0955) | ||
| 74 | +#define LINUX_USB_PID (0x7020) | ||
| 75 | +#endif | ||
| 76 | + | ||
| 77 | +/* Exported types ------------------------------------------------------------*/ | ||
| 78 | + | ||
| 79 | +/* Exported functions --------------------------------------------------------*/ | ||
| 80 | +T_ZiyanReturnCode HalUsbBulk_Init(T_ZiyanHalUsbBulkInfo usbBulkInfo, T_ZiyanUsbBulkHandle *usbBulkHandle); | ||
| 81 | +T_ZiyanReturnCode HalUsbBulk_DeInit(T_ZiyanUsbBulkHandle usbBulkHandle); | ||
| 82 | +T_ZiyanReturnCode HalUsbBulk_WriteData(T_ZiyanUsbBulkHandle usbBulkHandle, const uint8_t *buf, uint32_t len, | ||
| 83 | + uint32_t *realLen); | ||
| 84 | +T_ZiyanReturnCode HalUsbBulk_ReadData(T_ZiyanUsbBulkHandle usbBulkHandle, uint8_t *buf, uint32_t len, uint32_t *realLen); | ||
| 85 | +T_ZiyanReturnCode HalUsbBulk_GetDeviceInfo(T_ZiyanHalUsbBulkDeviceInfo *deviceInfo); | ||
| 86 | + | ||
| 87 | +#ifdef __cplusplus | ||
| 88 | +} | ||
| 89 | +#endif | ||
| 90 | + | ||
| 91 | +#endif // HAL_USB_BULK_H | ||
| 92 | +/************************ (C) COPYRIGHT ZIYAN Innovations *******END OF FILE******/ |
-
请 注册 或 登录 后发表评论