正在显示
70 个修改的文件
包含
10774 行增加
和
0 行删除
CmakeConfig/Compiler.cmake
0 → 100644
| 1 | +# 编译链的配置 | ||
| 2 | + | ||
| 3 | +#1、编译链与设备类型的选择 | ||
| 4 | +set(DEVICE_NAME JZ_H1T) | ||
| 5 | +#上一行为禁止修改行 | ||
| 6 | + | ||
| 7 | +if("${DEVICE_NAME}" STREQUAL "JZ_H1E") | ||
| 8 | + set(MAKE_COMPILER ARM_CORTEXA9_LINUX) | ||
| 9 | + set(DEVICE_TYPE MEGAPHONE) | ||
| 10 | +elseif("${DEVICE_NAME}" STREQUAL "JZ_H1T") | ||
| 11 | + set(MAKE_COMPILER ARM_CORTEXA9_LINUX) | ||
| 12 | + set(DEVICE_TYPE MEGAPHONE) | ||
| 13 | +elseif("${DEVICE_NAME}" STREQUAL "JZ_H150S") | ||
| 14 | + set(MAKE_COMPILER ARM_CORTEXA9_LINUX) | ||
| 15 | + set(DEVICE_TYPE MEGAPHONE) | ||
| 16 | +elseif("${DEVICE_NAME}" STREQUAL "JZ_H150T") | ||
| 17 | + set(MAKE_COMPILER ARM_CORTEXA9_LINUX) | ||
| 18 | + set(DEVICE_TYPE MEGAPHONE) | ||
| 19 | +elseif("${DEVICE_NAME}" STREQUAL "JZ_H10") | ||
| 20 | + set(MAKE_COMPILER ARM_CORTEXA9_LINUX) | ||
| 21 | + set(DEVICE_TYPE MEGAPHONE) | ||
| 22 | +elseif("${DEVICE_NAME}" STREQUAL "JZ_H10T") | ||
| 23 | + set(MAKE_COMPILER ARM_CORTEXA9_LINUX) | ||
| 24 | + set(DEVICE_TYPE MEGAPHONE) | ||
| 25 | +elseif("${DEVICE_NAME}" STREQUAL "JZ_U3") | ||
| 26 | + set(MAKE_COMPILER ARM_CORTEXA9_LINUX) | ||
| 27 | + set(DEVICE_TYPE MEGAPHONE) | ||
| 28 | +elseif("${DEVICE_NAME}" STREQUAL "JZ_U3S") | ||
| 29 | + set(MAKE_COMPILER ARM_CORTEXA9_LINUX) | ||
| 30 | + set(DEVICE_TYPE MEGAPHONE) | ||
| 31 | +elseif("${DEVICE_NAME}" STREQUAL "TF_A1") | ||
| 32 | + set(MAKE_COMPILER ARM_CORTEXA9_LINUX) | ||
| 33 | + set(DEVICE_TYPE MEGAPHONE) | ||
| 34 | +elseif("${DEVICE_NAME}" STREQUAL "JZ_C1") | ||
| 35 | + set(MAKE_COMPILER ARM_X86_64_ARRCH64) | ||
| 36 | +endif() | ||
| 37 | + | ||
| 38 | +if(${MAKE_COMPILER} STREQUAL "ARM_CORTEXA9_LINUX") | ||
| 39 | + set(TOOLCHAIN_NAME arm-linux-gnueabihf-gcc) | ||
| 40 | + set(CMAKE_C_COMPILER "/usr/local/arm/4.9.3/bin/arm-cortexa9-linux-gnueabihf-gcc") | ||
| 41 | + set(CMAKE_CXX_COMPILER "/usr/local/arm/4.9.3/bin/arm-cortexa9-linux-gnueabihf-g++") | ||
| 42 | + message("使用ARM_CORTEXA9_LINUX编译链") | ||
| 43 | + | ||
| 44 | +elseif(${MAKE_COMPILER} STREQUAL "ARM_CORTEX_LINUX") | ||
| 45 | + set(TOOLCHAIN_NAME arm-linux-gnueabihf-gcc) | ||
| 46 | + set(CMAKE_C_COMPILER "/opt/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc") | ||
| 47 | + set(CMAKE_CXX_COMPILER "/opt/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g++") | ||
| 48 | + message("使用ARM_CORTEX_LINUX编译链") | ||
| 49 | + | ||
| 50 | +elseif(${MAKE_COMPILER} STREQUAL "ARM_X86_64_ARRCH64") | ||
| 51 | + # 交叉编译链3 | ||
| 52 | + set(TOOLCHAIN_NAME aarch64-linux-gnu-gcc) | ||
| 53 | + set(CMAKE_C_COMPILER "/opt/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc") | ||
| 54 | + set(CMAKE_CXX_COMPILER "/opt/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-g++") | ||
| 55 | + message("使用ARM_X86_64_ARRCH64编译链") | ||
| 56 | + | ||
| 57 | +elseif(${MAKE_COMPILER} STREQUAL "LOCAL") | ||
| 58 | + # 本地测试编译链 | ||
| 59 | + set(CMAKE_C_COMPILER "/usr/bin/gcc") | ||
| 60 | + set(CMAKE_CXX_COMPILER "/usr/bin/g++") | ||
| 61 | + message("使用LOCAL编译链") | ||
| 62 | + | ||
| 63 | +else() | ||
| 64 | + message(FATAL_ERROR "不支持的编译链") | ||
| 65 | +endif() | ||
| 66 | + | ||
| 67 | +message("编译链配置完毕\n") |
CmakeConfig/ModuleConfig.cmake
0 → 100644
| 1 | +# ModuleConfig.cmake 模组模块的配置文件 | ||
| 2 | + | ||
| 3 | +###################### 自己的库 ############################## | ||
| 4 | +# AudioDeal 音频处理模块 | ||
| 5 | +set(AUDIODEAL_MODULE VERSION_SWITCH_OFF) | ||
| 6 | + | ||
| 7 | +# 信息模块 | ||
| 8 | +set(DEVICE_INFO_MODULE VERSION_SWITCH_OFF) | ||
| 9 | + | ||
| 10 | +# Gimbal 云台处理模块 | ||
| 11 | +set(GIMBAL_MODULE VERSION_SWITCH_OFF) | ||
| 12 | + | ||
| 13 | +# IRCUT 引脚处理模块 | ||
| 14 | +set(IRCUT_MODULE VERSION_SWITCH_OFF) | ||
| 15 | + | ||
| 16 | +# LIGHTING 光源处理模块 | ||
| 17 | +set(LIGHTING_MODULE VERSION_SWITCH_OFF) | ||
| 18 | + | ||
| 19 | +# MediaProc 媒体管理模块 | ||
| 20 | +set(MEDIA_PROC_MODULE VERSION_SWITCH_OFF) | ||
| 21 | + | ||
| 22 | +# 喊话器模块 | ||
| 23 | +set(MEGAPHONE_MODULE VERSION_SWITCH_OFF) | ||
| 24 | + | ||
| 25 | +# 电源管理模块 | ||
| 26 | +set(POWER_MANAGER_MODULE VERSION_SWITCH_OFF) | ||
| 27 | + | ||
| 28 | +# UI管理模块 | ||
| 29 | +set(UI_CONTROL_MODULE VERSION_SWITCH_OFF) | ||
| 30 | + | ||
| 31 | +# 红外相机模块 | ||
| 32 | +set(IRC_MODULE VERSION_SWITCH_OFF) | ||
| 33 | + | ||
| 34 | +# 侧面激光模块 | ||
| 35 | +set(SIDE_LASER_MODULE VERSION_SWITCH_OFF) | ||
| 36 | + | ||
| 37 | +###################### 第三方库 ############################## | ||
| 38 | + | ||
| 39 | +# FFMPEG及其附属模块 | ||
| 40 | +set(FFMPEG_MODULE VERSION_SWITCH_OFF) | ||
| 41 | + | ||
| 42 | +# cedarxLib | ||
| 43 | +set(CedarxLib VERSION_SWITCH_OFF) | ||
| 44 | + | ||
| 45 | +########################## 通用库 ########################################### | ||
| 46 | + | ||
| 47 | +# 添加信息模块 | ||
| 48 | +set(DEVICE_INFO_MODULE VERSION_SWITCH_ON) | ||
| 49 | + | ||
| 50 | +# 添加UI管理模块 | ||
| 51 | +set(UI_CONTROL_MODULE VERSION_SWITCH_ON) | ||
| 52 | + | ||
| 53 | +##################################################################### | ||
| 54 | + | ||
| 55 | +if("${DEVICE_NAME}" STREQUAL "JZ_H1E") | ||
| 56 | + | ||
| 57 | +elseif("${DEVICE_NAME}" STREQUAL "JZ_H1T") | ||
| 58 | + | ||
| 59 | + # 添加AudioDeal 音频处理模块 | ||
| 60 | + set(AUDIODEAL_MODULE VERSION_SWITCH_ON) | ||
| 61 | + | ||
| 62 | + # 添加Gimbal 云台处理模块 | ||
| 63 | + set(GIMBAL_MODULE VERSION_SWITCH_ON) | ||
| 64 | + | ||
| 65 | + # 添加IRCUT 引脚处理模块 | ||
| 66 | + set(IRCUT_MODULE VERSION_SWITCH_ON) | ||
| 67 | + | ||
| 68 | + # 添加LIGHTING 光源处理模块 | ||
| 69 | + set(LIGHTING_MODULE VERSION_SWITCH_ON) | ||
| 70 | + | ||
| 71 | + # 添加喊话器模块 | ||
| 72 | + set(MEGAPHONE_MODULE VERSION_SWITCH_ON) | ||
| 73 | + | ||
| 74 | + # 添加电源管理模块 | ||
| 75 | + set(POWER_MANAGER_MODULE VERSION_SWITCH_ON) | ||
| 76 | + | ||
| 77 | + # 添加FFMPEG及其附属模块 | ||
| 78 | + set(FFMPEG_MODULE VERSION_SWITCH_ON) | ||
| 79 | + | ||
| 80 | +elseif("${DEVICE_NAME}" STREQUAL "JZ_U3S") | ||
| 81 | + | ||
| 82 | + # 添加AudioDeal 音频处理模块 | ||
| 83 | + set(AUDIODEAL_MODULE VERSION_SWITCH_ON) | ||
| 84 | + | ||
| 85 | + # 添加Gimbal 云台处理模块 | ||
| 86 | + set(GIMBAL_MODULE VERSION_SWITCH_ON) | ||
| 87 | + | ||
| 88 | + # 添加IRCUT 引脚处理模块 | ||
| 89 | + set(IRCUT_MODULE VERSION_SWITCH_ON) | ||
| 90 | + | ||
| 91 | + # 添加LIGHTING 光源处理模块 | ||
| 92 | + set(LIGHTING_MODULE VERSION_SWITCH_ON) | ||
| 93 | + | ||
| 94 | + # 添加喊话器模块 | ||
| 95 | + set(MEGAPHONE_MODULE VERSION_SWITCH_ON) | ||
| 96 | + | ||
| 97 | + # 添加电源管理模块 | ||
| 98 | + set(POWER_MANAGER_MODULE VERSION_SWITCH_ON) | ||
| 99 | + | ||
| 100 | + # 添加FFMPEG及其附属模块 | ||
| 101 | + set(FFMPEG_MODULE VERSION_SWITCH_ON) | ||
| 102 | + | ||
| 103 | + # 添加激光模块 | ||
| 104 | + set(SIDE_LASER_MODULE VERSION_SWITCH_ON) | ||
| 105 | + | ||
| 106 | +elseif("${DEVICE_NAME}" STREQUAL "JZ_C1") | ||
| 107 | + | ||
| 108 | + # 添加Gimbal 云台处理模块 | ||
| 109 | + set(GIMBAL_MODULE VERSION_SWITCH_ON) | ||
| 110 | + | ||
| 111 | + # 添加IRCUT 引脚处理模块 | ||
| 112 | + set(IRCUT_MODULE VERSION_SWITCH_ON) | ||
| 113 | + | ||
| 114 | + # 添加LIGHTING 光源处理模块 | ||
| 115 | + set(LIGHTING_MODULE VERSION_SWITCH_ON) | ||
| 116 | + | ||
| 117 | + # 添加MediaProc 媒体管理模块 | ||
| 118 | + set(MEDIA_PROC_MODULE VERSION_SWITCH_ON) | ||
| 119 | + | ||
| 120 | + # 添加电源管理模块 | ||
| 121 | + set(POWER_MANAGER_MODULE VERSION_SWITCH_ON) | ||
| 122 | + | ||
| 123 | + # 添加红外相机模块 | ||
| 124 | + set(IRC_MODULE VERSION_SWITCH_ON) | ||
| 125 | +endif() | ||
| 126 | + | ||
| 127 | +message("模组模块已加载\n") |
CmakeConfig/ModuleLoading.cmake
0 → 100644
| 1 | + | ||
| 2 | +# ModuleLoading.cmake 模块加载文件 | ||
| 3 | + | ||
| 4 | + | ||
| 5 | +if(${IFLAY_TTS_MODULE} STREQUAL "VERSION_SWITCH_ON") | ||
| 6 | + set(iFLYTEK_TTS_DIRS "${ROOT_DIRS}ThirdParty/iFLYTEK_TTS/lib/arm-cortexa9-linux-gnueabihf") | ||
| 7 | + include_directories(${ROOT_DIRS}ThirdParty/iFLYTEK_TTS/include) | ||
| 8 | + target_link_libraries( | ||
| 9 | + ${PROJECT_NAME} | ||
| 10 | + ${iFLYTEK_TTS_DIRS}/libmsc.so | ||
| 11 | + ) | ||
| 12 | + message("讯飞TTS模块已加载\n") | ||
| 13 | +endif() | ||
| 14 | + | ||
| 15 | +if(${ESPEAK_TTS_MODULE} STREQUAL "VERSION_SWITCH_ON") | ||
| 16 | + set(ESPEAK_TTS_DIRS "${ROOT_DIRS}ThirdParty/Espeak/lib/arm-cortexa9-linux-gnueabihf") | ||
| 17 | + include_directories(${ROOT_DIRS}ThirdParty/Espeak/include) | ||
| 18 | + target_link_libraries( | ||
| 19 | + ${PROJECT_NAME} | ||
| 20 | + ${ESPEAK_TTS_DIRS}/libportaudio.so.2 | ||
| 21 | + ${ESPEAK_TTS_DIRS}/libTTS_Player.so | ||
| 22 | + ) | ||
| 23 | + message("Espeak模块已加载\n") | ||
| 24 | +endif() | ||
| 25 | + | ||
| 26 | +if(${ALSALIB_MODULE} STREQUAL "VERSION_SWITCH_ON") | ||
| 27 | + set(ALSALIB_DIRS "${ROOT_DIRS}ThirdParty/AlsaLib/lib/arm-cortexa9-linux-gnueabihf") | ||
| 28 | + include_directories(${ROOT_DIRS}ThirdParty/AlsaLib/include) | ||
| 29 | + target_link_libraries( | ||
| 30 | + ${PROJECT_NAME} | ||
| 31 | + ${ALSALIB_DIRS}/libasound.so.2.0.0 | ||
| 32 | + ) | ||
| 33 | + message("alsalib已加载\n") | ||
| 34 | +endif() | ||
| 35 | + | ||
| 36 | +if(${OPUS_MODULE} STREQUAL "VERSION_SWITCH_ON") | ||
| 37 | + set(OPUS_DIRS "${ROOT_DIRS}ThirdParty/opus/lib/arm-cortexa9-linux-gnueabihf") | ||
| 38 | + include_directories(${ROOT_DIRS}ThirdParty/opus/include) | ||
| 39 | + target_link_libraries( | ||
| 40 | + ${PROJECT_NAME} | ||
| 41 | + ${OPUS_DIRS}/libopus.so | ||
| 42 | + ) | ||
| 43 | + message("OPUS模块已加载\n") | ||
| 44 | +endif() | ||
| 45 | + | ||
| 46 | +if(${CedarxLib} STREQUAL "VERSION_SWITCH_ON") | ||
| 47 | + message("\nCedarX已加载\n") | ||
| 48 | + target_link_libraries(${PROJECT_NAME} | ||
| 49 | + ${ROOT_DIRS}ModuleLib/Camera/CedarX/libawh264.so | ||
| 50 | + ${ROOT_DIRS}ModuleLib/Camera/CedarX/libMemAdapter.so | ||
| 51 | + ${ROOT_DIRS}ModuleLib/Camera/CedarX/libVE.so | ||
| 52 | + ${ROOT_DIRS}ModuleLib/Camera/CedarX/libvencoder.so | ||
| 53 | + ${ROOT_DIRS}ModuleLib/Camera/CedarX/libvideoengine.so | ||
| 54 | + ${ROOT_DIRS}ModuleLib/Camera/CedarX/libvdecoder.so | ||
| 55 | + ) | ||
| 56 | + | ||
| 57 | + message("\n OpenCV已加载\n") | ||
| 58 | + target_link_libraries(${PROJECT_NAME} | ||
| 59 | + ${ROOT_DIRS}ModuleLib/OpenCV/libopencv_calib3d.so | ||
| 60 | + ${ROOT_DIRS}ModuleLib/OpenCV/libopencv_core.so | ||
| 61 | + ${ROOT_DIRS}ModuleLib/OpenCV/libopencv_dnn.so | ||
| 62 | + ${ROOT_DIRS}ModuleLib/OpenCV/libopencv_features2d.so | ||
| 63 | + ${ROOT_DIRS}ModuleLib/OpenCV/libopencv_flann.so | ||
| 64 | + ${ROOT_DIRS}ModuleLib/OpenCV/libopencv_highgui.so | ||
| 65 | + ${ROOT_DIRS}ModuleLib/OpenCV/libopencv_imgcodecs.so | ||
| 66 | + ${ROOT_DIRS}ModuleLib/OpenCV/libopencv_imgproc.so | ||
| 67 | + ${ROOT_DIRS}ModuleLib/OpenCV/libopencv_ml.so | ||
| 68 | + ${ROOT_DIRS}ModuleLib/OpenCV/libopencv_objdetect.so | ||
| 69 | + ${ROOT_DIRS}ModuleLib/OpenCV/libopencv_photo.so | ||
| 70 | + ${ROOT_DIRS}ModuleLib/OpenCV/libopencv_shape.so | ||
| 71 | + ${ROOT_DIRS}ModuleLib/OpenCV/libopencv_stitching.so | ||
| 72 | + ${ROOT_DIRS}ModuleLib/OpenCV/libopencv_superres.so | ||
| 73 | + ${ROOT_DIRS}ModuleLib/OpenCV/libopencv_videoio.so | ||
| 74 | + ${ROOT_DIRS}ModuleLib/OpenCV/libopencv_video.so | ||
| 75 | + ${ROOT_DIRS}ModuleLib/OpenCV/libopencv_videostab.so | ||
| 76 | + ) | ||
| 77 | + | ||
| 78 | + message("\n ffmpeg已加载\n") | ||
| 79 | + target_link_libraries(${PROJECT_NAME} | ||
| 80 | + ${ROOT_DIRS}ModuleLib/ffmpeg/libavcodec.so | ||
| 81 | + ${ROOT_DIRS}ModuleLib/ffmpeg/libavdevice.so | ||
| 82 | + ${ROOT_DIRS}ModuleLib/ffmpeg/libavfilter.so | ||
| 83 | + ${ROOT_DIRS}ModuleLib/ffmpeg/libavformat.so | ||
| 84 | + ${ROOT_DIRS}ModuleLib/ffmpeg/libavutil.so | ||
| 85 | + ${ROOT_DIRS}ModuleLib/ffmpeg/libswresample.so | ||
| 86 | + ${ROOT_DIRS}ModuleLib/ffmpeg/libswscale.so | ||
| 87 | + ) | ||
| 88 | + | ||
| 89 | + message("\n SearchLightCenter已加载\n") | ||
| 90 | + target_link_libraries(${PROJECT_NAME} | ||
| 91 | + ${ROOT_DIRS}ModuleLib/SearchLightCenter/libcenter.so | ||
| 92 | + ) | ||
| 93 | + | ||
| 94 | +endif() | ||
| 95 | + | ||
| 96 | + | ||
| 97 | +if(${FFMPEG_MODULE} STREQUAL "VERSION_SWITCH_ON") | ||
| 98 | + message("\nffmpeg模块加载\n") | ||
| 99 | + set(FFMPEG_6_0_DIRS "${ROOT_DIRS}ThirdParty/ffmpeg_6_0/lib/arm-cortexa9-linux-gnueabihf") | ||
| 100 | + include_directories(${ROOT_DIRS}ThirdParty/ffmpeg_6_0/include) | ||
| 101 | + target_link_libraries( | ||
| 102 | + ${PROJECT_NAME} | ||
| 103 | + ${FFMPEG_6_0_DIRS}/libavcodec.so.60 | ||
| 104 | + ${FFMPEG_6_0_DIRS}/libavdevice.so.60 | ||
| 105 | + ${FFMPEG_6_0_DIRS}/libavfilter.so.9 | ||
| 106 | + ${FFMPEG_6_0_DIRS}/libavformat.so.60 | ||
| 107 | + ${FFMPEG_6_0_DIRS}/libavutil.so.58 | ||
| 108 | + ${FFMPEG_6_0_DIRS}/libpostproc.so.57 | ||
| 109 | + ${FFMPEG_6_0_DIRS}/libswresample.so.4 | ||
| 110 | + ${FFMPEG_6_0_DIRS}/libswscale.so.7 | ||
| 111 | + ) | ||
| 112 | + | ||
| 113 | + message("x264模块已加载\n") | ||
| 114 | + set(X264_DIRS "${ROOT_DIRS}ThirdParty/x264_2245/lib/arm-cortexa9-linux-gnueabihf") | ||
| 115 | + include_directories(${ROOT_DIRS}ThirdParty/x264_2245/include) | ||
| 116 | + target_link_libraries( | ||
| 117 | + ${PROJECT_NAME} | ||
| 118 | + ${X264_DIRS}/libx264.so.157 | ||
| 119 | + ) | ||
| 120 | + | ||
| 121 | + message("FDK_AAC模块已加载\n") | ||
| 122 | + set(FDK_AAC_DIRS "${ROOT_DIRS}ThirdParty/fdk_aac_2_0_3/lib/arm-cortexa9-linux-gnueabihf") | ||
| 123 | + include_directories(${ROOT_DIRS}ThirdParty/fdk_aac_2_0_3/include) | ||
| 124 | + target_link_libraries( | ||
| 125 | + ${PROJECT_NAME} | ||
| 126 | + ${FDK_AAC_DIRS}/libfdk-aac.so.2 | ||
| 127 | + ) | ||
| 128 | + | ||
| 129 | +endif() | ||
| 130 | + | ||
| 131 | + | ||
| 132 | +#rtk_mmp库 | ||
| 133 | +if(${LIB_RTK_MMP} STREQUAL "VERSION_SWITCH_ON") | ||
| 134 | + message("RTK_MMP库已加载\n") | ||
| 135 | + add_definitions(-DMACRO_RTK_MPP_MODULE) #加载usb模块 | ||
| 136 | + | ||
| 137 | + include_directories(${ROOT_DIRS}/ThirdParty/RTK_mmp/aarch64-none-linux-gnu/include) | ||
| 138 | + target_link_libraries( | ||
| 139 | + ${PROJECT_NAME} | ||
| 140 | + ${ROOT_DIRS}/ThirdParty/RTK_mmp/aarch64-none-linux-gnu/lib/librockchip_mpp.so.0 | ||
| 141 | + ${ROOT_DIRS}/ThirdParty/RTK_mmp/aarch64-none-linux-gnu/lib/librockchip_vpu.so.0 | ||
| 142 | + ) | ||
| 143 | +endif() | ||
| 144 | + | ||
| 145 | +#usb库 | ||
| 146 | +if(${LIB_USB} STREQUAL "VERSION_SWITCH_ON") | ||
| 147 | + add_definitions(-DMACRO_USB_MODULE) #加载usb模块 | ||
| 148 | + | ||
| 149 | + message("USB库已加载\n") | ||
| 150 | + include_directories(${ROOT_DIRS}/ThirdParty/libusb/aarch64-none-linux-gnu/include) | ||
| 151 | + target_link_libraries( | ||
| 152 | + ${PROJECT_NAME} | ||
| 153 | + ${ROOT_DIRS}/ThirdParty/libusb/aarch64-none-linux-gnu/lib/libusb-1.0.so.0.4.0 | ||
| 154 | + ) | ||
| 155 | + | ||
| 156 | + message("udev库已加载\n") | ||
| 157 | + | ||
| 158 | + include_directories(${ROOT_DIRS}/ThirdParty/udev/aarch64-none-linux-gnu/include) | ||
| 159 | + target_link_libraries( | ||
| 160 | + ${PROJECT_NAME} | ||
| 161 | + ${ROOT_DIRS}/ThirdParty/udev/aarch64-none-linux-gnu/lib/libudev.so.1.6.3 | ||
| 162 | + ) | ||
| 163 | +endif() |
CmakeConfig/SubsidiaryThirdPartyConfig.cmake
0 → 100644
| 1 | +# SubsidiaryThirdPartyConfig.cmake 附属第三方库配置文件 | ||
| 2 | + | ||
| 3 | +set(IFLAY_TTS_MODULE VERSION_SWITCH_OFF) | ||
| 4 | +set(ESPEAK_TTS_MODULE VERSION_SWITCH_OFF) | ||
| 5 | +set(ALSALIB_MODULE VERSION_SWITCH_OFF) | ||
| 6 | +set(OPUS_MODULE VERSION_SWITCH_OFF) | ||
| 7 | +set(LIB_RTK_MMP VERSION_SWITCH_OFF) | ||
| 8 | +set(LIB_USB VERSION_SWITCH_OFF) | ||
| 9 | + | ||
| 10 | +add_definitions(-D COMPILE_MODE_MODULE) #设置代码为编译模式 | ||
| 11 | + | ||
| 12 | +if(${MEGAPHONE_MODULE} STREQUAL "VERSION_SWITCH_ON") | ||
| 13 | + message("\n喊话器模块已加载") | ||
| 14 | + add_definitions(-DMACRO_MEGAPHONE_MODULE) #加载喊话器模块 | ||
| 15 | + | ||
| 16 | + message("加载讯飞TTS模块") | ||
| 17 | + set(IFLAY_TTS_MODULE VERSION_SWITCH_ON) | ||
| 18 | + | ||
| 19 | + message("加载espeak模块") | ||
| 20 | + set(ESPEAK_TTS_MODULE VERSION_SWITCH_ON) | ||
| 21 | + | ||
| 22 | + message("加载alsalib模块") | ||
| 23 | + set(ALSALIB_MODULE VERSION_SWITCH_ON) | ||
| 24 | + | ||
| 25 | + message("加载OPUS模块") | ||
| 26 | + set(OPUS_MODULE VERSION_SWITCH_ON) | ||
| 27 | +endif() | ||
| 28 | + | ||
| 29 | +if(${IRC_MODULE} STREQUAL "VERSION_SWITCH_ON") | ||
| 30 | + message("\n红外相机模块已加载") | ||
| 31 | + add_definitions(-DMACRO_IRC_MODULE) | ||
| 32 | + | ||
| 33 | + message("加载RTK模块") | ||
| 34 | + set(LIB_RTK_MMP VERSION_SWITCH_ON) | ||
| 35 | + | ||
| 36 | + message("加载USB模块") | ||
| 37 | + set(LIB_USB VERSION_SWITCH_ON) | ||
| 38 | + | ||
| 39 | + message("\n媒体管理模块已加载") | ||
| 40 | + add_definitions(-DMACRO_MEDIA_PROC_MODULE) | ||
| 41 | + | ||
| 42 | +endif() | ||
| 43 | + | ||
| 44 | +if(${SIDE_LASER_MODULE} STREQUAL "VERSION_SWITCH_ON") | ||
| 45 | + message("加载侧面激光模块") | ||
| 46 | + add_definitions(-DMACRO_SIDE_LASER_MODULE) | ||
| 47 | +endif() | ||
| 48 | + | ||
| 49 | + | ||
| 50 | +message("附属库已加载\n") |
JZsdk_Common/JZsdkLib.c
0 → 100644
JZsdk_Common/JZsdkLib.h
0 → 100644
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file JZsdkLib.h | ||
| 4 | + * JZsdk的头文件 | ||
| 5 | + * | ||
| 6 | + ********************************************************************* | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/ | ||
| 10 | +#ifndef JZSDKLIB_H | ||
| 11 | +#define JZSDKLIB_H | ||
| 12 | + | ||
| 13 | +/* Includes ------------------------------------------------------------------*/ | ||
| 14 | + | ||
| 15 | +#ifdef __cplusplus | ||
| 16 | +extern "C" { | ||
| 17 | +#endif | ||
| 18 | + | ||
| 19 | +/* Exported constants --------------------------------------------------------*/ | ||
| 20 | +/* 常亮定义*/ | ||
| 21 | +#include "JZsdk_Base/JZsdkBase.h" | ||
| 22 | +#include "JZsdk_Base/JZsdk_Code/JZsdk_Code.h" | ||
| 23 | + | ||
| 24 | +#include "JZsdk_CommonFuntion/JZsdkCommonFuntion.h" | ||
| 25 | +/* Exported types ------------------------------------------------------------*/ | ||
| 26 | + | ||
| 27 | +/* Exported functions --------------------------------------------------------*/ | ||
| 28 | +T_JZsdkReturnCode JZsdk_LibInit(); | ||
| 29 | + | ||
| 30 | + | ||
| 31 | +#ifdef __cplusplus | ||
| 32 | +} | ||
| 33 | +#endif | ||
| 34 | + | ||
| 35 | +#endif | ||
| 36 | +/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/ |
JZsdk_Common/JZsdk_Base/JZsdkBase.h
0 → 100644
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file JZsdkBase.h | ||
| 4 | + * JZsdk基础部件的头文件 | ||
| 5 | + * | ||
| 6 | + ********************************************************************* | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/ | ||
| 10 | +#ifndef JZSDKBASE_H | ||
| 11 | +#define JZSDKBASE_H | ||
| 12 | + | ||
| 13 | +/* Includes ------------------------------------------------------------------*/ | ||
| 14 | + | ||
| 15 | +#ifdef __cplusplus | ||
| 16 | +extern "C" { | ||
| 17 | +#endif | ||
| 18 | + | ||
| 19 | +/* Exported constants --------------------------------------------------------*/ | ||
| 20 | +/* 常亮定义*/ | ||
| 21 | +#include "JZsdk_Logger/JZsdk_Logger.h" | ||
| 22 | +#include "JZsdk_Osal/JZsdk_FileSystm.h" | ||
| 23 | +#include "JZsdk_Delay/JZsdk_Delay.h" | ||
| 24 | +#include "JZsdk_Code/JZsdk_FLagCode.h" | ||
| 25 | +#include "JZsdk_Osal/JZsdk_MemoryAdapter.h" | ||
| 26 | + | ||
| 27 | +/* Exported types ------------------------------------------------------------*/ | ||
| 28 | + | ||
| 29 | + | ||
| 30 | +/* Exported functions --------------------------------------------------------*/ | ||
| 31 | + | ||
| 32 | + | ||
| 33 | +#ifdef __cplusplus | ||
| 34 | +} | ||
| 35 | +#endif | ||
| 36 | + | ||
| 37 | +#endif |
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file JZsdk_Code.h | ||
| 4 | + * 用于记录各类码的表 | ||
| 5 | + * | ||
| 6 | + ********************************************************************* | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/ | ||
| 10 | +#ifndef JZSDK_CODE_H | ||
| 11 | +#define JZSDK_CODE_H | ||
| 12 | + | ||
| 13 | +/* Includes ------------------------------------------------------------------*/ | ||
| 14 | + | ||
| 15 | +#ifdef __cplusplus | ||
| 16 | +extern "C" { | ||
| 17 | +#endif | ||
| 18 | + | ||
| 19 | +/* Exported constants --------------------------------------------------------*/ | ||
| 20 | +/* 常亮定义*/ | ||
| 21 | + | ||
| 22 | +#include "./JZsdk_InsCode.h" | ||
| 23 | +#include "./JZsdk_FLagCode.h" | ||
| 24 | +#include "./JZsdk_ReturnCode.h" | ||
| 25 | +#include "./JZsdk_FileType.h" | ||
| 26 | + | ||
| 27 | +/* Exported types ------------------------------------------------------------*/ | ||
| 28 | + | ||
| 29 | + | ||
| 30 | +/* Exported functions --------------------------------------------------------*/ | ||
| 31 | + | ||
| 32 | +#ifdef __cplusplus | ||
| 33 | +} | ||
| 34 | +#endif | ||
| 35 | + | ||
| 36 | +#endif |
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file JZsdk_ErrorCode.h | ||
| 4 | + * 用于错误码的表 | ||
| 5 | + * | ||
| 6 | + ********************************************************************* | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/ | ||
| 10 | +#ifndef JZSDK_ERRORCODE_H | ||
| 11 | +#define JZSDK_ERRORCODE_H | ||
| 12 | + | ||
| 13 | +/* Includes ------------------------------------------------------------------*/ | ||
| 14 | + | ||
| 15 | +#ifdef __cplusplus | ||
| 16 | +extern "C" { | ||
| 17 | +#endif | ||
| 18 | + | ||
| 19 | +/* Exported constants --------------------------------------------------------*/ | ||
| 20 | +/* 常亮定义*/ | ||
| 21 | + | ||
| 22 | + | ||
| 23 | +/* Exported types ------------------------------------------------------------*/ | ||
| 24 | +typedef enum { | ||
| 25 | + JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS = 0x0000, | ||
| 26 | + JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE = 0x0001, | ||
| 27 | + JZ_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER = 0x0002, //文件指针错误 | ||
| 28 | +} JZ_SYSTEM_Code; | ||
| 29 | + | ||
| 30 | +typedef enum { | ||
| 31 | + JZ_ERROR_SYSTEM_FRAME_ERROR = 0x0100, | ||
| 32 | + | ||
| 33 | +} JZ_Syetem_frame_ErrorCode; | ||
| 34 | + | ||
| 35 | +typedef enum { | ||
| 36 | + JZ_ERRORCODE_MUSIC_NOT_FOUND_IN_LIST = 0x1000 | ||
| 37 | + | ||
| 38 | +} JZ_Megaphone_music_ErrorCode; | ||
| 39 | + | ||
| 40 | +typedef enum { | ||
| 41 | + JZ_ERRORCODE_REALTIMEVOICE_HAS_BEEN_ON = 0x1201 | ||
| 42 | + | ||
| 43 | +} JZ_Megaphone_opus_ErrorCode; | ||
| 44 | + | ||
| 45 | +typedef enum { | ||
| 46 | + JZ_ERRORCODE_TTS_INVALID_TONE = 0x1300, | ||
| 47 | + JZ_ERRORCODE_TTS_INVALID_SPEED = 0x1301, | ||
| 48 | + JZ_ERRORCODE_TTS_INVALID_ADDTONE = 0x1302, | ||
| 49 | + | ||
| 50 | +} JZ_Megaphone_TTS_ErrorCode; | ||
| 51 | + | ||
| 52 | +typedef enum { | ||
| 53 | + JZ_ERRORCODE_GIMBAL_INVALID_PITCH = 0x4000, | ||
| 54 | + JZ_ERRORCODE_GIMBAL_INVALID_YAW = 0x4001, | ||
| 55 | + JZ_ERRORCODE_GIMBAL_INVALID_ROLL = 0x4002, | ||
| 56 | + | ||
| 57 | +} JZ_Gimbal_ErrorCode; | ||
| 58 | +/* Exported functions --------------------------------------------------------*/ | ||
| 59 | + | ||
| 60 | +#ifdef __cplusplus | ||
| 61 | +} | ||
| 62 | +#endif | ||
| 63 | + | ||
| 64 | +#endif |
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file JZsdk_FLagCode.h | ||
| 4 | + * 用于标识码的表 | ||
| 5 | + * | ||
| 6 | + ********************************************************************* | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/ | ||
| 10 | +#ifndef JZSDK_FLAGCODE_H | ||
| 11 | +#define JZSDK_FLAGCODE_H | ||
| 12 | + | ||
| 13 | +/* Includes ------------------------------------------------------------------*/ | ||
| 14 | + | ||
| 15 | +#ifdef __cplusplus | ||
| 16 | +extern "C" { | ||
| 17 | +#endif | ||
| 18 | + | ||
| 19 | +/* Exported constants --------------------------------------------------------*/ | ||
| 20 | +/* 常亮定义*/ | ||
| 21 | + | ||
| 22 | +typedef enum JZ_Flag_Code{ | ||
| 23 | + JZ_FLAGCODE_OFF = 0x0000, | ||
| 24 | + JZ_FLAGCODE_ON = 0x0001, | ||
| 25 | + JZ_FLAGCODE_GET = 0x0010, //获取指令 | ||
| 26 | + JZ_FLAGCODE_SET = 0x0011, //设置指令 | ||
| 27 | + | ||
| 28 | + JZ_FLAGCODE_NORMAL = 0x00FF, //默认模式 | ||
| 29 | +} JZ_Flag_Code; | ||
| 30 | + | ||
| 31 | +/* Exported types ------------------------------------------------------------*/ | ||
| 32 | + | ||
| 33 | + | ||
| 34 | +/* Exported functions --------------------------------------------------------*/ | ||
| 35 | + | ||
| 36 | +#ifdef __cplusplus | ||
| 37 | +} | ||
| 38 | +#endif | ||
| 39 | + | ||
| 40 | +#endif |
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file JZsdk_FileType.h | ||
| 4 | + * 用于记录文件类型的表 | ||
| 5 | + * | ||
| 6 | + ********************************************************************* | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/ | ||
| 10 | +#ifndef JZSDK_FILE_TYPE_H | ||
| 11 | +#define JZSDK_FILE_TYPE_H | ||
| 12 | + | ||
| 13 | +/* Includes ------------------------------------------------------------------*/ | ||
| 14 | + | ||
| 15 | +#ifdef __cplusplus | ||
| 16 | +extern "C" { | ||
| 17 | +#endif | ||
| 18 | + | ||
| 19 | +/* Exported constants --------------------------------------------------------*/ | ||
| 20 | +/* 常亮定义*/ | ||
| 21 | + | ||
| 22 | + | ||
| 23 | +/* Exported types ------------------------------------------------------------*/ | ||
| 24 | +typedef enum { | ||
| 25 | + AUDIO_TYPE_WAV = 0x00000001, | ||
| 26 | + AUDIO_TYPE_MP3 = 0x00000002, | ||
| 27 | + AUDIO_TYPE_OPUS = 0x00000003, | ||
| 28 | + AUDIO_TYPE_PCM = 0x00000004, | ||
| 29 | +} JZ_AUDIO_FILE_TYPE; | ||
| 30 | + | ||
| 31 | +/* Exported functions --------------------------------------------------------*/ | ||
| 32 | + | ||
| 33 | +#ifdef __cplusplus | ||
| 34 | +} | ||
| 35 | +#endif | ||
| 36 | + | ||
| 37 | +#endif |
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file JZsdk_InsCode.h | ||
| 4 | + * 用于错误码的表 | ||
| 5 | + * | ||
| 6 | + ********************************************************************* | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/ | ||
| 10 | +#ifndef JZSDK_INSCODE_H | ||
| 11 | +#define JZSDK_INSCODE_H | ||
| 12 | + | ||
| 13 | +/* Includes ------------------------------------------------------------------*/ | ||
| 14 | + | ||
| 15 | +#ifdef __cplusplus | ||
| 16 | +extern "C" { | ||
| 17 | +#endif | ||
| 18 | + | ||
| 19 | +/* Exported constants --------------------------------------------------------*/ | ||
| 20 | +/* 常亮定义*/ | ||
| 21 | + | ||
| 22 | +typedef enum { | ||
| 23 | + | ||
| 24 | +//5A类帧 | ||
| 25 | + JZ_INSCODE_5AFRAME_FRAME = 0x10000000, //接收类帧 | ||
| 26 | + | ||
| 27 | + JZ_INSCODE_5AFRAME_ASKFORCONNECT = 0x10000100, //申请连接 | ||
| 28 | + JZ_INSCODE_5AFRAME_HEARTBEAT = 0x10000101, //心跳帧 | ||
| 29 | + JZ_INSCODE_5AFRAME_TIMESTAMP = 0x10000102, //时间戳帧 | ||
| 30 | + JZ_INSCODE_5AFRAME_ALL_VERSION = 0x10000103, //全版本查询 | ||
| 31 | + JZ_INSCODE_5AFRAME_ALL_SERIAL_NUMBER = 0x10000104, //全序列号查询 | ||
| 32 | + JZ_INSCODE_5AFRAME_LOG_MESSAGE_PRINTF = 0x10000105, //log信息打印 | ||
| 33 | + JZ_INSCODE_5AFRAME_DEVICE_MESSAGE = 0x10000106, //设备信息 | ||
| 34 | + | ||
| 35 | + JZ_INSCODE_5AFRAME_FRAME_POWER_STATUS = 0x10000110, //电源状态设置 | ||
| 36 | + | ||
| 37 | + JZ_INSCODE_5AFRAME_REALTIMEMP2_START = 0x10000200, //开启实时MP2 | ||
| 38 | + JZ_INSCODE_5AFRAME_REALTIMEMP2_UNLIMIT_TRANSMISSION = 0x10000201, //无限制传输实时MP2 | ||
| 39 | + JZ_INSCODE_5AFRAME_REALTIMEMP2_STOP = 0x10000202, //结束实时MP2 | ||
| 40 | + JZ_INSCODE_5AFRAME_REALTIMEMP2_LIMIT_TRANSMISSION = 0x10000203, //有限制传输MP2 | ||
| 41 | + | ||
| 42 | + JZ_INSCODE_5AFRAME_AUDIOFILE_TRANS_START = 0x10000300, //打开音频文件上传 | ||
| 43 | + JZ_INSCODE_5AFRAME_AUDIOFILE_TRANS_UNLIMIT_TRANSMISSION = 0x10000301, //无限制传输音频文件 | ||
| 44 | + JZ_INSCODE_5AFRAME_AUDIOFILE_TRANS_STOP = 0x10000302, //关闭音频文件上传 | ||
| 45 | + JZ_INSCODE_5AFRAME_AUDIOFILE_TRANS_LIMIT_TRANSMISSION = 0x10000303, //定长传输音频文件 | ||
| 46 | + | ||
| 47 | + JZ_INSCODE_5AFRAME_AUDIO_PLAYFILE = 0x10000400, //播放指定音频 | ||
| 48 | + JZ_INSCODE_5AFRAME_AUDIO_CONTINUE = 0x10000401, //音频继续播放 | ||
| 49 | + JZ_INSCODE_5AFRAME_AUDIO_PAUSE = 0x10000402, //音频暂停播放 | ||
| 50 | + JZ_INSCODE_5AFRAME_AUDIO_STOP = 0x10000403, //音频停止播放 | ||
| 51 | + | ||
| 52 | + JZ_INSCODE_5AFRAME_AUDIO_LASTSONG = 0x10000410, //音频上一曲 | ||
| 53 | + JZ_INSCODE_5AFRAME_AUDIO_NEXTSONG = 0x10000411, //音频下一曲 | ||
| 54 | + | ||
| 55 | + JZ_INSCODE_5AFRAME_AUDIO_GETMUSICLIST = 0x10000420, //获取音频列表 | ||
| 56 | + | ||
| 57 | + | ||
| 58 | + JZ_INSCODE_5AFRAME_AMPLIFIER_STOP = 0x10000500, //强制关闭功放 | ||
| 59 | + JZ_INSCODE_5AFRAME_AMPLIFIER_OPEN = 0x10000501, //强制开启功放 | ||
| 60 | + JZ_INSCODE_5AFRAME_AMPLIFIER_AUTO = 0x10000502, //恢复自动功放 | ||
| 61 | + | ||
| 62 | + JZ_INSCODE_5AFRAME_VOLUME = 0x10000600, //调节音量 | ||
| 63 | + | ||
| 64 | + JZ_INSCODE_5AFRAME_CHECKSTATUS_VOLUME = 0x10000620, //查询音量 | ||
| 65 | + JZ_INSCODE_5AFRAME_CHECKSTATUS_PLAY = 0x10000621, //查询播放状态 | ||
| 66 | + JZ_INSCODE_5AFRAME_CHECKSTATUS_GIMBAL = 0x10000622, //查询云台角度 | ||
| 67 | + JZ_INSCODE_5AFRAME_CHECKSTATUS_GIMBAL_FINETUNING = 0x10000623, //查询云台微调角度 | ||
| 68 | + | ||
| 69 | + JZ_INSCODE_5AFRAME_CHECKSTATUS_PLAYFILENAME = 0x10000624, //查询播放文件名 | ||
| 70 | + JZ_INSCODE_5AFRAME_CHECKSTATUS_SOFTWAREVERSION = 0x10000625, //查询软件版本号 | ||
| 71 | + JZ_INSCODE_5AFRAME_CHECKSTATUS_LOOPPLAY = 0x10000626, //查询是否打开循环 | ||
| 72 | + JZ_INSCODE_5AFRAME_CHECKSTATUS_TTSTONE = 0x10000627, //查询音色 | ||
| 73 | + JZ_INSCODE_5AFRAME_CHECKSTATUS_TTSSPEED = 0x10000628, //查询语速 | ||
| 74 | + JZ_INSCODE_5AFRAME_CHECKSTATUS_SEARCHLIGHT_LIGHTATTRIBUTE = 0x10000629, //查询探照灯 灯3个属性 | ||
| 75 | + JZ_INSCODE_5AFRAME_CHECKSTATUS_SEARCHLIGHT_LUMEN = 0x10000630, //查询探照灯流明 | ||
| 76 | + JZ_INSCODE_5AFRAME_CHECKSTATUS_SEARCHLIGHT_FREQUENCY = 0x10000631, //查询探照灯频率 | ||
| 77 | + JZ_INSCODE_5AFRAME_CHECKSTATUS_SEARCHLIGHT_MODE = 0x10000632, //查询探照灯模式 | ||
| 78 | + JZ_INSCODE_5AFRAME_CHECKSTATUS_SEARCHLIGHT_TEMPERATURE = 0x10000633, //查询探照灯温度 | ||
| 79 | + | ||
| 80 | + JZ_INSCODE_5AFRAME_CHECKSTATUS_LASER_STATUS = 0x10000634, //查询激光状态 | ||
| 81 | + JZ_INSCODE_5AFRAME_CHECKSTATUS_WARNINGLIGHT_STATUS = 0x10000635, //查询警灯状态 | ||
| 82 | + JZ_INSCODE_5AFRAME_CHECKSTATUS_WARNINGLIGHT_COLOR = 0x10000636, //查询警灯颜色 | ||
| 83 | + JZ_INSCODE_5AFRAME_CHECKSTATUS_SERIALNUMBER = 0x10000637, //查询序列号 | ||
| 84 | + | ||
| 85 | + | ||
| 86 | + JZ_INSCODE_5AFRAME_PLAY_LOOP = 0x10000690, //开启关闭循环 | ||
| 87 | + | ||
| 88 | + JZ_INSCODE_5AFRAME_DELETE_AUDIO = 0x10000700, //删除音频 | ||
| 89 | + JZ_INSCODE_5AFRAME_DELETE_VOICE_RECORD = 0x10000710, //删除录音 | ||
| 90 | + JZ_INSCODE_5AFRAME_DELETE_VIDEO_RECORD = 0x10000720, //删除视频 | ||
| 91 | + | ||
| 92 | + | ||
| 93 | + JZ_INSCODE_5AFRAME_TTS_SET_TONE = 0x10000801, //TTS设置音色 | ||
| 94 | + JZ_INSCODE_5AFRAME_TTS_SET_SPEED = 0x10000802, //TTS设置语速 | ||
| 95 | + JZ_INSCODE_5AFRAME_TTS_TRANS_START = 0x10000803, //TTS开始发送 | ||
| 96 | + JZ_INSCODE_5AFRAME_TTS_TRANS_UNLIMIT_TRANSMISSION = 0x10000804, //TTS正在无限制接收 | ||
| 97 | + JZ_INSCODE_5AFRAME_TTS_TRANS_STOP = 0x10000805, //TTS发送完毕 | ||
| 98 | + JZ_INSCODE_5AFRAME_TTS_TRANS_LIMIT_TRANSMISSION = 0x10000806, //TTS正在定长接收 | ||
| 99 | + | ||
| 100 | + JZ_INSCODE_5AFRAME_OPUS_TRANS_START = 0x10000900, //opus传输开始 | ||
| 101 | + JZ_INSCODE_5AFRAME_OPUS_TRAN_UNLIMIT_TRANSMISSION = 0x10000901, //opus 无限制传输中 | ||
| 102 | + JZ_INSCODE_5AFRAME_OPUS_TRANS_LIMIT_TRANSMISSION = 0x10000903, //opus传输中 | ||
| 103 | + | ||
| 104 | + JZ_INSCODE_5AFRAME_OPUS_TRANS_STOP = 0x10000902, //opus传输结束 | ||
| 105 | + | ||
| 106 | + JZ_INSCODE_5AFRAME_OPUS_PLAY = 0x10000910, //opus播放 | ||
| 107 | + | ||
| 108 | + JZ_INSCODE_5AFRAME_OPUS_REALTIMEVOICE_START = 0x10000A00, //开启opus实时语音 | ||
| 109 | + JZ_INSCODE_5AFRAME_OPUS_REALTIMEVOICE_UNLIMIT_TRANSMISSION = 0x10000A01, //无限制传输opus实时语音 | ||
| 110 | + JZ_INSCODE_5AFRAME_OPUS_REALTIMEVOICE_STOP = 0x10000A02, //结束opus实时语音 | ||
| 111 | + JZ_INSCODE_5AFRAME_OPUS_REALTIMEVOICE_LIMIT_TRANSMISSION = 0x10000A03, //定长传输opus实时语音 | ||
| 112 | + | ||
| 113 | + JZ_INSCODE_5AFRAME_GIMBAL_PITCH_CONTROL = 0x10000B00, //云台俯仰控制 | ||
| 114 | + JZ_INSCODE_5AFRAME_GIMBAL_YAW_CONTROL = 0x10000B01, //云台朝向控制 | ||
| 115 | + JZ_INSCODE_5AFRAME_GIMBAL_ROLL_CONTROL = 0x10000B02, //云台旋转控制 | ||
| 116 | + JZ_INSCODE_5AFRAME_GIMBAL_PITCH_FINETUNING_CONTROL = 0x10000B04, //云台俯仰微调 | ||
| 117 | + JZ_INSCODE_5AFRAME_GIMBAL_YAW_FINETUNING_CONTROL = 0x10000B05, //云台朝向微调 | ||
| 118 | + JZ_INSCODE_5AFRAME_GIMBAL_ROLL_FINETUNING_CONTROL = 0x10000B06, //云台旋转微调 | ||
| 119 | + | ||
| 120 | + | ||
| 121 | + JZ_INSCODE_5AFRAME_LASER_CONTROL = 0x10000C00, //激光控制 | ||
| 122 | + | ||
| 123 | + JZ_INSCODE_5AFRAME_SEARCHLIGHT_CONTROL = 0x10000E00, //探照灯开光 | ||
| 124 | + JZ_INSCODE_5AFRAME_SEARCHLIGHT_SET_LUMEN = 0x10000E10, //设置探照灯亮度 | ||
| 125 | + JZ_INSCODE_5AFRAME_SEARCHLIGHT_SET_FREQUENCY = 0x10000E20, //设置把爆闪频率 | ||
| 126 | + JZ_INSCODE_5AFRAME_SEARCHLIGHT_MESSAGE_SUBSCRIPTION_CONTROL = 0x10000E21,//探照灯消息订阅控制 | ||
| 127 | + | ||
| 128 | + JZ_INSCODE_5AFRAME_WARNINGLIGHT_CONTROL = 0x10000F00, //警示灯模式控制 | ||
| 129 | + JZ_INSCODE_5AFRAME_WARNINGLIGHT_COLOUR = 0x10000F10, //警示灯颜色控制 | ||
| 130 | + | ||
| 131 | + JZ_INSCODE_5AFRAME_OUTPUTPOWER_CONTROL = 0x10001000, //对外供电开关 | ||
| 132 | + JZ_INSCODE_5AFRAME_CHECKSTATUS_OUTPUTPOWER = 0x10001001, //对外供电查询 | ||
| 133 | + | ||
| 134 | +//5B类帧 | ||
| 135 | + JZ_INSCODE_5BFRAME_FRAME = 0x10004000, //发送帧 | ||
| 136 | + | ||
| 137 | + JZ_INSCODE_5BFRAME_INITIATECONNECT = 0x10004101, //主动连接 | ||
| 138 | + JZ_INSCODE_5BFRAME_HEARTBEAT = 0x10004102, //心跳帧回复 | ||
| 139 | + JZ_INSCODE_5BFRAME_TIMESTAMP = 0x10004103, //时间戳帧 | ||
| 140 | + JZ_INSCODE_5BFRAME_ALL_VERSION = 0x10004104, //全版本查询 | ||
| 141 | + JZ_INSCODE_5BFRAME_ALL_SERIAL_NUMBER = 0x10004105, //全序列号查询 | ||
| 142 | + JZ_INSCODE_5BFRAME_DEVICE_MESSAGE = 0x10004107, //设备信息 | ||
| 143 | + | ||
| 144 | + JZ_INSCODE_5BFRAME_SUCESS = 0x10004200, //操作成功 | ||
| 145 | + JZ_INSCODE_5BFRAME_DEFEAT = 0x10004201, //操作失败 | ||
| 146 | + | ||
| 147 | + JZ_INSCODE_5BFRAME_MUSICLIST_START = 0x10004300, //开启发送音乐列表帧 | ||
| 148 | + JZ_INSCODE_5BFRAME_MUSICLIST_TRANS = 0x10004301, //发送音乐列表帧 | ||
| 149 | + JZ_INSCODE_5BFRAME_MUSICLIST_STOP = 0x10004302, //结束发送音乐列表帧 | ||
| 150 | + | ||
| 151 | + JZ_INSCODE_5BFRAME_AUDIO_PLAYSTATUS = 0x10004310, //音频播放状态返回帧 | ||
| 152 | + JZ_INSCODE_5BFRAME_AUDIO_PLAYSTATUS_END = 0x10004311, //音频播放状态结束帧 | ||
| 153 | + | ||
| 154 | + JZ_INSCODE_5BFRAME_VOLUME = 0x10004400, //音量返回帧 | ||
| 155 | + JZ_INSCODE_5BFRAME_AUDIO_PLAYLOOPSTATUS = 0x10004401, //发送音频循环播放状态 | ||
| 156 | + JZ_INSCODE_5BFRAME_TTS_TONE = 0x10004402, //发送tts音色 | ||
| 157 | + JZ_INSCODE_5BFRAME_TTS_SPEED = 0x10004403, //发送tts语速 | ||
| 158 | + JZ_INSCODE_5BFRAME_AUDIO_PLAYFILENAME = 0x10004404, //当前播放的音频名字 | ||
| 159 | + | ||
| 160 | + | ||
| 161 | + JZ_INSCODE_5BFRAME_GIMBAL_PITCH = 0x10004500, //云台俯仰角度 | ||
| 162 | + JZ_INSCODE_5BFRAME_GIMBAL_YAW = 0x10004501, //云台航向角度 | ||
| 163 | + JZ_INSCODE_5BFRAME_GIMBAL_ROLL = 0x10004502, // | ||
| 164 | + | ||
| 165 | + JZ_INSCODE_5BFRAME_GIMBAL_PITCH_FINETUNING = 0x10004510, //云台俯仰微调值 | ||
| 166 | + | ||
| 167 | + | ||
| 168 | + JZ_INSCODE_5BFRAME_CHECKSTATUS_SEARCHLIGHT_TEMPERATURE = 0x10004600, //查询探照灯温度 | ||
| 169 | + JZ_INSCODE_5BFRAME_CHECKSTATUS_LASER_STATUS = 0x10004601, //查询激光状态 | ||
| 170 | + JZ_INSCODE_5BFRAME_CHECKSTATUS_SEARCHLIGHT_FREQUENCY = 0x10004602, //查询探照灯频率 | ||
| 171 | + JZ_INSCODE_5BFRAME_CHECKSTATUS_SEARCHLIGHT_MODE = 0x10004603, //查询探照灯模式 | ||
| 172 | + JZ_INSCODE_5BFRAME_CHECKSTATUS_SEARCHLIGHT_LUMEN = 0x10004604, //查询探照灯流明 | ||
| 173 | + | ||
| 174 | + JZ_INSCODE_5BFRAME_CHECKSTATUS_WARNINGLIGHT_STATUS = 0x10004700, //警示灯模式控制 | ||
| 175 | + JZ_INSCODE_5BFRAME_CHECKSTATUS_WARNINGLIGHT_COLOR = 0x10004701, //警示灯颜色控制 | ||
| 176 | + | ||
| 177 | + | ||
| 178 | + JZ_INSCODE_5BFRAME_SORTWAREVERSION = 0x10004800, //发送软件版本号 | ||
| 179 | + JZ_INSCODE_5BFRAME_HARDWAREVERSION = 0x10004801, //发送硬件版本号 | ||
| 180 | + JZ_INSCODE_5BFRAME_CHECKSTATUS_SERIALNUMBER = 0x10004802, //回复序列号 | ||
| 181 | + | ||
| 182 | + JZ_INSCODE_5BFRAME_CHECKSTATUS_OUTPUTPOWER = 0x10004900, //对外供电查询 | ||
| 183 | + | ||
| 184 | + JZ_INSCODE_5BFRAME_OPUS_DECODE_STATUS = 0x10005000, //opus解码状态 | ||
| 185 | + | ||
| 186 | + | ||
| 187 | +//6A类 | ||
| 188 | + JZ_INSCODE_6AFRAME_FRAME = 0x10008000, //发送帧 | ||
| 189 | + | ||
| 190 | + JZ_INSCODE_6AFRAME_SET_GIMBAL_ORIGIN = 0x10008101, //设置坐标0值 | ||
| 191 | + JZ_INSCODE_6AFRAME_SET_GIMBAL_MAXMIN_RANGE = 0x10008102, //设置云台范围最大最小值 | ||
| 192 | + JZ_INSCODE_6AFRAME_SET_LUMEN_MAXMIN_RANGE = 0x10008103, //设置灯光范围最大最小值 | ||
| 193 | + JZ_INSCODE_6AFRAME_SET_SERIALNUMBER = 0x10008104, //设置序列号 | ||
| 194 | + JZ_INSCODE_6AFRAME_SERVO_SELFCHECK = 0x10008105, //舵机自检 | ||
| 195 | + JZ_INSCODE_6AFRAME_GIMBAL_LINKAGE_CONTROL = 0x10008106, //开关云台联动 | ||
| 196 | + | ||
| 197 | + JZ_INSCODE_6AFRAME_CHECKSTATUS_SECONDARY_DEVICE_NAME = 0x10008400, //查询从设备设备名 | ||
| 198 | + JZ_INSCODE_6AFRAME_CHECKSTATUS_GIMBAL_LINKAGE = 0x10008401, //查询云台联动 | ||
| 199 | + | ||
| 200 | + JZ_INSCODE_6AFRAME_UART_BITRATE_CHANGE = 0x10008500, //串口比特率修改 | ||
| 201 | + | ||
| 202 | + JZ_INSCODE_6AFRAME_SPECIAL_PARAMETERS = 0x10008510, //设置特殊参数 | ||
| 203 | + JZ_INSCODE_6AFRAME_CHECK_SPECIAL_PARAMETERS = 0x10008511, //查询特殊参数 | ||
| 204 | + | ||
| 205 | +//6B类 | ||
| 206 | + JZ_INSCODE_6BFRAME_CHECKSTATUS_SECONDARY_DEVICE_NAME = 0x1000C400, //回复从设备名 | ||
| 207 | + JZ_INSCODE_6BFRAME_CHECKSTATUS_GIMBAL_LINKAGE = 0x1000C401, //回复云台联动 | ||
| 208 | + JZ_INSCODE_6BFRAME_CHECK_SPECIAL_PARAMETERS = 0x1000C511, //回复特殊参数 | ||
| 209 | + | ||
| 210 | +} JZ_InsCode; | ||
| 211 | + | ||
| 212 | + | ||
| 213 | +/* Exported types ------------------------------------------------------------*/ | ||
| 214 | + | ||
| 215 | + | ||
| 216 | +/* Exported functions --------------------------------------------------------*/ | ||
| 217 | + | ||
| 218 | +#ifdef __cplusplus | ||
| 219 | +} | ||
| 220 | +#endif | ||
| 221 | + | ||
| 222 | +#endif |
| 1 | +#include <stdint.h> | ||
| 2 | +#include <stdbool.h> | ||
| 3 | +#include <stddef.h> | ||
| 4 | +#include <string.h> | ||
| 5 | +#include <stdlib.h> | ||
| 6 | +#include <stdio.h> | ||
| 7 | +#include <string.h> | ||
| 8 | + | ||
| 9 | +#include "./JZsdk_Code.h" | ||
| 10 | + | ||
| 11 | + | ||
| 12 | + | ||
| 13 | +//获取返回码的信息 | ||
| 14 | +const char* JZsdk_GetReturnCodeMessage(T_JZsdkReturnCode ReturnCode) | ||
| 15 | +{ | ||
| 16 | + switch (ReturnCode) { | ||
| 17 | + case JZ_ERRORCODE_REALTIMEVOICE_HAS_BEEN_ON: | ||
| 18 | + return "实时语音被开启,该操作失败"; | ||
| 19 | + | ||
| 20 | + default: | ||
| 21 | + return "未知错误:Unknown error."; | ||
| 22 | + } | ||
| 23 | +} |
| 1 | + | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + ******************************************************************** | ||
| 5 | + * @file JZsdk_ReturnCode.h | ||
| 6 | + * 用于记录各类码的表 | ||
| 7 | + * | ||
| 8 | + ********************************************************************* | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/ | ||
| 12 | +#ifndef JZSDK_RETURNCODE_H | ||
| 13 | +#define JZSDK_RETURNCODE_H | ||
| 14 | + | ||
| 15 | +/* Includes ------------------------------------------------------------------*/ | ||
| 16 | +#include <stdint.h> | ||
| 17 | +#include "JZsdk_ErrorCode.h" | ||
| 18 | + | ||
| 19 | +#ifdef __cplusplus | ||
| 20 | +extern "C" { | ||
| 21 | +#endif | ||
| 22 | + | ||
| 23 | +/* Exported constants --------------------------------------------------------*/ | ||
| 24 | +/* 常亮定义*/ | ||
| 25 | + | ||
| 26 | + | ||
| 27 | + | ||
| 28 | + | ||
| 29 | + | ||
| 30 | + | ||
| 31 | + | ||
| 32 | +/* Exported types ------------------------------------------------------------*/ | ||
| 33 | +//重定义一个返回码 | ||
| 34 | +typedef uint64_t T_JZsdkReturnCode; | ||
| 35 | +typedef uint8_t U8_t; | ||
| 36 | +typedef uint16_t U16_t; | ||
| 37 | +typedef uint32_t U32_t; | ||
| 38 | +typedef uint64_t U64_t; | ||
| 39 | + | ||
| 40 | +// typedef unsigned long T_JZsdkReturnCode; | ||
| 41 | +// typedef unsigned char U8_t; | ||
| 42 | +// typedef unsigned short U16_t; | ||
| 43 | +// typedef unsigned int U32_t; | ||
| 44 | +// typedef unsigned long U64_t; | ||
| 45 | + | ||
| 46 | +typedef double F64_t; | ||
| 47 | +typedef float F32_t; | ||
| 48 | + | ||
| 49 | +/* Exported functions --------------------------------------------------------*/ | ||
| 50 | +const char* JZsdk_GetReturnCodeMessage(T_JZsdkReturnCode ReturnCode); | ||
| 51 | + | ||
| 52 | +#ifdef __cplusplus | ||
| 53 | +} | ||
| 54 | +#endif | ||
| 55 | + | ||
| 56 | +#endif |
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file JZsdk_SMT_Code.h | ||
| 4 | + * 用于序列号管理的表 | ||
| 5 | + * | ||
| 6 | + ********************************************************************* | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/ | ||
| 10 | +#ifndef JZSDK_SMT_CODE_H | ||
| 11 | +#define JZSDK_SMT_CODE_H | ||
| 12 | + | ||
| 13 | +/* Includes ------------------------------------------------------------------*/ | ||
| 14 | + | ||
| 15 | +#ifdef __cplusplus | ||
| 16 | +extern "C" { | ||
| 17 | +#endif | ||
| 18 | + | ||
| 19 | +/* Exported constants --------------------------------------------------------*/ | ||
| 20 | +/* 常亮定义*/ | ||
| 21 | + | ||
| 22 | +typedef enum | ||
| 23 | +{ | ||
| 24 | + // 设备序列号类型 | ||
| 25 | + UNDEFINED_SNM = 0x0000, //未定义类型序列号 | ||
| 26 | + STANDARD_DJI_SNM = 0x0001, // 大疆转接环序列号类型 | ||
| 27 | + STANDARD_JZ_1_SNM = 0x0002, // JZ-1型序列号 | ||
| 28 | + STANDARD_JZ_2_SNM = 0x0003, // JZ-2型序列号 2023.12.14 制定 | ||
| 29 | +} JZSDK_SNM_TPYE; | ||
| 30 | + | ||
| 31 | +typedef enum | ||
| 32 | +{ | ||
| 33 | + // 设备激活码状态 0 未存在序列号 1 旧版序列号 2新版序列号未激活 3新版序列号已激活 | ||
| 34 | + SNM_NOT_EXISTS = 0x0000, // (未存在序列号) | ||
| 35 | + SNM_HAVE_ACTIVATED = 0x0001, // 已激活 | ||
| 36 | + SNM_NOT_ACTIVATED = 0x0002, // 未激活 | ||
| 37 | + SNM_ERROR_ACTIVATED = 0x0003, //激活错误状态 | ||
| 38 | +} JZSDK_SNM_STATUS; | ||
| 39 | + | ||
| 40 | +typedef enum | ||
| 41 | +{ | ||
| 42 | + STANDARD_DJI_SNM_LENGTH = 14, //dji序列号默认长度14 | ||
| 43 | + STANDARD_JZ_1_SUM_LENGTH = 14, //极至标准1长度太多种拉 喊话器最长是14 | ||
| 44 | + STANDARD_JZ_2_SUM_LENGTH = 16, //极至标准2 16长度 | ||
| 45 | +}JZSDK_SNM_STANDARD_LENGTH; | ||
| 46 | + | ||
| 47 | +typedef enum | ||
| 48 | +{ | ||
| 49 | + STANDARD_JZ_2_CN = 0x0001, //极至标准2通用码 | ||
| 50 | + STANDARD_JZ_2_EN = 0x0002, //极至标准2海外码 | ||
| 51 | +}JZSDK_FIREWARM_CODE; | ||
| 52 | + | ||
| 53 | +typedef enum | ||
| 54 | +{ | ||
| 55 | + STANDARD_JZ_2_F1 = 0x0001, //通用版本固件 | ||
| 56 | + | ||
| 57 | +}JZSKD_SPECIAL_VERSION; | ||
| 58 | + | ||
| 59 | + | ||
| 60 | +#ifdef __cplusplus | ||
| 61 | +} | ||
| 62 | +#endif | ||
| 63 | + | ||
| 64 | +#endif |
| 1 | +#include <stdio.h> | ||
| 2 | +#include "JZsdk_Delay.h" | ||
| 3 | +#include <unistd.h> | ||
| 4 | + | ||
| 5 | +/* | ||
| 6 | +* 用于延时(粗略) | ||
| 7 | +* 需要优化 | ||
| 8 | +*/ | ||
| 9 | +int delayUs(unsigned long msec) | ||
| 10 | +{ | ||
| 11 | + usleep(msec); | ||
| 12 | +} | ||
| 13 | + | ||
| 14 | +/* | ||
| 15 | +* 用于延时(粗略) | ||
| 16 | +* 需要优化 | ||
| 17 | +*/ | ||
| 18 | +int delayMs(unsigned long msec) | ||
| 19 | +{ | ||
| 20 | + usleep(msec * 1000); | ||
| 21 | +} | ||
| 22 | + | ||
| 23 | +/* | ||
| 24 | +* 用于延时(粗略) | ||
| 25 | +* 需要优化 | ||
| 26 | +*/ | ||
| 27 | +int delayS(unsigned long sec) | ||
| 28 | +{ | ||
| 29 | + delayMs(sec * 1000); | ||
| 30 | +} |
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file JZsdk_FileSystem.h | ||
| 4 | + * 用于文件系统操作 | ||
| 5 | + * | ||
| 6 | + ********************************************************************* | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/ | ||
| 10 | +#ifndef JZSDK_DELAY_H | ||
| 11 | +#define JZSDK_DELAY_H | ||
| 12 | + | ||
| 13 | +/* Includes ------------------------------------------------------------------*/ | ||
| 14 | + | ||
| 15 | +#ifdef __cplusplus | ||
| 16 | +extern "C" { | ||
| 17 | +#endif | ||
| 18 | + | ||
| 19 | +/* Exported constants --------------------------------------------------------*/ | ||
| 20 | +/* 常亮定义*/ | ||
| 21 | + | ||
| 22 | + | ||
| 23 | +/* Exported types ------------------------------------------------------------*/ | ||
| 24 | + | ||
| 25 | + | ||
| 26 | +/* Exported functions --------------------------------------------------------*/ | ||
| 27 | +int delayMs(unsigned long msec); | ||
| 28 | +int delayS(unsigned long sec); | ||
| 29 | +int delayUs(unsigned long msec); | ||
| 30 | + | ||
| 31 | +#ifdef __cplusplus | ||
| 32 | +} | ||
| 33 | +#endif | ||
| 34 | + | ||
| 35 | +#endif | ||
| 36 | +/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/ |
| 1 | +#include <stdio.h> | ||
| 2 | +#include "./JZsdk_FrameComparsion.h" | ||
| 3 | +#include "../JZsdk_Code/JZsdk_Code.h" | ||
| 4 | + | ||
| 5 | +/************************* | ||
| 6 | + * | ||
| 7 | + * 获取帧的序列号 | ||
| 8 | + * | ||
| 9 | + * ***************************/ | ||
| 10 | +int JZsdk_Get_FrameSequence(char *DealBuf) | ||
| 11 | +{ | ||
| 12 | + return DealBuf[6]; | ||
| 13 | +} | ||
| 14 | + | ||
| 15 | +/*************************** | ||
| 16 | + * 、 | ||
| 17 | + * | ||
| 18 | + * 帧校对 获取功能 | ||
| 19 | + * | ||
| 20 | + * | ||
| 21 | + * ***********************/ | ||
| 22 | +int JZsdk_FrameComparsion(char *getdata, int len) | ||
| 23 | +{ | ||
| 24 | + //1、判断是否是5A帧 | ||
| 25 | + if (getdata[0] == 0x5A && getdata[1] == 0x5A && getdata[2] == 0x77) | ||
| 26 | + { | ||
| 27 | + printf("JZsdk_FrameComparsion:5A帧\n"); | ||
| 28 | + return JZsdk_5AFrameComparsion(getdata, len); | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + //2、判断是否是5B帧 | ||
| 32 | + if (getdata[0] == 0x5b && getdata[1] == 0x5b && getdata[2] == 0x77) | ||
| 33 | + { | ||
| 34 | + printf("JZsdk_FrameComparsion:5B帧\n"); | ||
| 35 | + return JZsdk_5BFrameComparsion(getdata, len); | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + //3、判断是否是6A帧 | ||
| 39 | + if (getdata[0] == 0x6A && getdata[1] == 0x6A && getdata[2] == 0x77) | ||
| 40 | + { | ||
| 41 | + printf("JZsdk_FrameComparsion:6A帧\n"); | ||
| 42 | + return JZsdk_6AFrameComparsion(getdata, len); | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + //4、判断是否是6B帧 | ||
| 46 | + if (getdata[0] == 0x6b && getdata[1] == 0x6b && getdata[2] == 0x77) | ||
| 47 | + { | ||
| 48 | + printf("JZsdk_FrameComparsion:6B帧\n"); | ||
| 49 | + return JZsdk_6BFrameComparsion(getdata, len); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + printf("接受到的帧,没有帧头或者帧尾,退出recv帧判断函数\n"); | ||
| 53 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 54 | +} |
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file JZsdk_FrameComparsion.h | ||
| 4 | + * 用于帧对比的头文件 | ||
| 5 | + * | ||
| 6 | + ********************************************************************* | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/ | ||
| 10 | +#ifndef JZSDK_FRAMECOMPARSION_H | ||
| 11 | +#define JZSDK_FRAMECOMPARSION_H | ||
| 12 | + | ||
| 13 | +/* Includes ------------------------------------------------------------------*/ | ||
| 14 | + | ||
| 15 | +#ifdef __cplusplus | ||
| 16 | +extern "C" { | ||
| 17 | +#endif | ||
| 18 | + | ||
| 19 | +/* Exported constants --------------------------------------------------------*/ | ||
| 20 | +/* 常亮定义*/ | ||
| 21 | +#include "JZsdk_FrameComparsion_5Aframe.h" | ||
| 22 | +#include "JZsdk_FrameComparsion_5Bframe.h" | ||
| 23 | +#include "JZsdk_FrameComparsion_6Aframe.h" | ||
| 24 | +#include "JZsdk_FrameComparsion_6Bframe.h" | ||
| 25 | +#include "JZsdk_GetFrameTemplate.h" | ||
| 26 | + | ||
| 27 | +/* Exported types ------------------------------------------------------------*/ | ||
| 28 | + | ||
| 29 | + | ||
| 30 | +/* Exported functions --------------------------------------------------------*/ | ||
| 31 | +int JZsdk_Get_FrameSequence(char *DealBuf); | ||
| 32 | +int JZsdk_FrameComparsion(char *getdata, int len); | ||
| 33 | + | ||
| 34 | +#ifdef __cplusplus | ||
| 35 | +} | ||
| 36 | +#endif | ||
| 37 | + | ||
| 38 | +#endif |
| 1 | +#include <stdio.h> | ||
| 2 | +#include "../JZsdk_Code/JZsdk_Code.h" | ||
| 3 | + | ||
| 4 | +/****************************************************** | ||
| 5 | + | ||
| 6 | + 接收一级功能码区 | ||
| 7 | + | ||
| 8 | +/******************************************************/ | ||
| 9 | +//一级功能码是连接功能 | ||
| 10 | +static int Comparison_5AFRAME_FirstLevelCode_0x50(char *getdata) | ||
| 11 | +{ | ||
| 12 | + //二级功能位 | ||
| 13 | + switch (getdata[8]) | ||
| 14 | + { | ||
| 15 | + //开启连接 | ||
| 16 | + case 0x51: | ||
| 17 | + return JZ_INSCODE_5AFRAME_ASKFORCONNECT; | ||
| 18 | + break; | ||
| 19 | + | ||
| 20 | + //设备电源状态 | ||
| 21 | + case 0x52: | ||
| 22 | + return JZ_INSCODE_5AFRAME_FRAME_POWER_STATUS; | ||
| 23 | + break; | ||
| 24 | + | ||
| 25 | + //心跳帧 | ||
| 26 | + case 0x53: | ||
| 27 | + return JZ_INSCODE_5AFRAME_HEARTBEAT; | ||
| 28 | + break; | ||
| 29 | + | ||
| 30 | + //时间戳帧 | ||
| 31 | + case 0x54: | ||
| 32 | + return JZ_INSCODE_5AFRAME_TIMESTAMP; | ||
| 33 | + break; | ||
| 34 | + | ||
| 35 | + //所有版本号帧 | ||
| 36 | + case 0x55: | ||
| 37 | + return JZ_INSCODE_5AFRAME_ALL_VERSION; | ||
| 38 | + break; | ||
| 39 | + | ||
| 40 | + //所有序列号帧 | ||
| 41 | + case 0x56: | ||
| 42 | + return JZ_INSCODE_5AFRAME_ALL_SERIAL_NUMBER; | ||
| 43 | + break; | ||
| 44 | + | ||
| 45 | + //log信息打印 | ||
| 46 | + case 0x57: | ||
| 47 | + return JZ_INSCODE_5AFRAME_LOG_MESSAGE_PRINTF; | ||
| 48 | + break; | ||
| 49 | + | ||
| 50 | + //获取设备信息帧 | ||
| 51 | + case 0x58: | ||
| 52 | + return JZ_INSCODE_5AFRAME_DEVICE_MESSAGE; | ||
| 53 | + break; | ||
| 54 | + | ||
| 55 | + default: | ||
| 56 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 57 | + break; | ||
| 58 | + } | ||
| 59 | +} | ||
| 60 | +//一级功能码是语音 或是 文件功能 | ||
| 61 | +static int Comparison_5AFRAME_FirstLevelCode_0x51(char *getdata) | ||
| 62 | +{ | ||
| 63 | + //二级功能位 | ||
| 64 | + switch (getdata[8]) | ||
| 65 | + { | ||
| 66 | + //开启语音 | ||
| 67 | + case 0xb1: | ||
| 68 | + return JZ_INSCODE_5AFRAME_REALTIMEMP2_START; | ||
| 69 | + break; | ||
| 70 | + | ||
| 71 | + //结束语音 | ||
| 72 | + case 0xb2: | ||
| 73 | + return JZ_INSCODE_5AFRAME_REALTIMEMP2_STOP; | ||
| 74 | + break; | ||
| 75 | + | ||
| 76 | + //有限制传输mp2语言 | ||
| 77 | + case 0xb3: | ||
| 78 | + return JZ_INSCODE_5AFRAME_REALTIMEMP2_LIMIT_TRANSMISSION; | ||
| 79 | + break; | ||
| 80 | + | ||
| 81 | + //打开音频文件上传 | ||
| 82 | + case 0x01: | ||
| 83 | + return JZ_INSCODE_5AFRAME_AUDIOFILE_TRANS_START; | ||
| 84 | + break; | ||
| 85 | + | ||
| 86 | + //有限制传输音频文件 | ||
| 87 | + case 0x02: | ||
| 88 | + return JZ_INSCODE_5AFRAME_AUDIOFILE_TRANS_LIMIT_TRANSMISSION; | ||
| 89 | + break; | ||
| 90 | + | ||
| 91 | + //关闭音频文件上传 | ||
| 92 | + case 0x03: | ||
| 93 | + return JZ_INSCODE_5AFRAME_AUDIOFILE_TRANS_STOP; | ||
| 94 | + break; | ||
| 95 | + | ||
| 96 | + default: | ||
| 97 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 98 | + break; | ||
| 99 | + } | ||
| 100 | +} | ||
| 101 | +//一级功能码是音频/功放/音量调节 | ||
| 102 | +static int Comparison_5AFRAME_FirstLevelCode_0x52(char *getdata) | ||
| 103 | +{ | ||
| 104 | + //二级功能位 | ||
| 105 | + switch (getdata[8]) | ||
| 106 | + { | ||
| 107 | + //播放指定音频 | ||
| 108 | + case 0x02: | ||
| 109 | + return JZ_INSCODE_5AFRAME_AUDIO_PLAYFILE; | ||
| 110 | + break; | ||
| 111 | + | ||
| 112 | + //音频继续播放 | ||
| 113 | + case 0x04: | ||
| 114 | + return JZ_INSCODE_5AFRAME_AUDIO_CONTINUE; | ||
| 115 | + break; | ||
| 116 | + | ||
| 117 | + //音频暂停播放 | ||
| 118 | + case 0x05: | ||
| 119 | + return JZ_INSCODE_5AFRAME_AUDIO_PAUSE; | ||
| 120 | + break; | ||
| 121 | + | ||
| 122 | + //音频停止播放 | ||
| 123 | + case 0x06: | ||
| 124 | + return JZ_INSCODE_5AFRAME_AUDIO_STOP; | ||
| 125 | + break; | ||
| 126 | + | ||
| 127 | + //音频上一曲 | ||
| 128 | + case 0x07: | ||
| 129 | + return JZ_INSCODE_5AFRAME_AUDIO_LASTSONG; | ||
| 130 | + break; | ||
| 131 | + | ||
| 132 | + //音频下一曲 | ||
| 133 | + case 0x08: | ||
| 134 | + return JZ_INSCODE_5AFRAME_AUDIO_NEXTSONG; | ||
| 135 | + break; | ||
| 136 | + | ||
| 137 | + //强制关闭功放 | ||
| 138 | + case 0x20: | ||
| 139 | + return JZ_INSCODE_5AFRAME_AMPLIFIER_STOP; | ||
| 140 | + break; | ||
| 141 | + | ||
| 142 | + //强制开启功放 | ||
| 143 | + case 0x21: | ||
| 144 | + return JZ_INSCODE_5AFRAME_AMPLIFIER_OPEN; | ||
| 145 | + break; | ||
| 146 | + | ||
| 147 | + //恢复自动功放 | ||
| 148 | + case 0x22: | ||
| 149 | + return JZ_INSCODE_5AFRAME_AMPLIFIER_AUTO; | ||
| 150 | + break; | ||
| 151 | + | ||
| 152 | + //调节音量 | ||
| 153 | + case 0x10: | ||
| 154 | + return JZ_INSCODE_5AFRAME_VOLUME; | ||
| 155 | + break; | ||
| 156 | + | ||
| 157 | + default: | ||
| 158 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 159 | + break; | ||
| 160 | + } | ||
| 161 | +} | ||
| 162 | +//一级功能码是查询状态 | ||
| 163 | +static int Comparison_5AFRAME_FirstLevelCode_0x53(char *getdata) | ||
| 164 | +{ | ||
| 165 | + //二级功能位 | ||
| 166 | + switch (getdata[8]) | ||
| 167 | + { | ||
| 168 | + //查询音量 | ||
| 169 | + case 0x01: | ||
| 170 | + return JZ_INSCODE_5AFRAME_CHECKSTATUS_VOLUME; | ||
| 171 | + break; | ||
| 172 | + | ||
| 173 | + //查询播放状态 | ||
| 174 | + case 0x02: | ||
| 175 | + return JZ_INSCODE_5AFRAME_CHECKSTATUS_PLAY; | ||
| 176 | + break; | ||
| 177 | + | ||
| 178 | + //查询云台角度(已舍弃) | ||
| 179 | + case 0x03: | ||
| 180 | + return JZ_INSCODE_5AFRAME_CHECKSTATUS_GIMBAL; | ||
| 181 | + break; | ||
| 182 | + | ||
| 183 | + //查询播放文件名 | ||
| 184 | + case 0x04: | ||
| 185 | + return JZ_INSCODE_5AFRAME_CHECKSTATUS_PLAYFILENAME; | ||
| 186 | + break; | ||
| 187 | + | ||
| 188 | + //查询是否打开循环 | ||
| 189 | + case 0x05: | ||
| 190 | + return JZ_INSCODE_5AFRAME_CHECKSTATUS_LOOPPLAY; | ||
| 191 | + break; | ||
| 192 | + | ||
| 193 | + //查询音色 | ||
| 194 | + case 0x06: | ||
| 195 | + return JZ_INSCODE_5AFRAME_CHECKSTATUS_TTSTONE; | ||
| 196 | + break; | ||
| 197 | + | ||
| 198 | + //查询语速 | ||
| 199 | + case 0x07: | ||
| 200 | + return JZ_INSCODE_5AFRAME_CHECKSTATUS_TTSSPEED; | ||
| 201 | + break; | ||
| 202 | + | ||
| 203 | + //查询软件版本号 | ||
| 204 | + case 0xf1: | ||
| 205 | + return JZ_INSCODE_5AFRAME_CHECKSTATUS_SOFTWAREVERSION; | ||
| 206 | + break; | ||
| 207 | + | ||
| 208 | + default: | ||
| 209 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 210 | + break; | ||
| 211 | + } | ||
| 212 | + | ||
| 213 | +} | ||
| 214 | +//一级功能码是删除 | ||
| 215 | +static int Comparison_5AFRAME_FirstLevelCode_0x54(char *getdata) | ||
| 216 | +{ | ||
| 217 | + //二级功能位 | ||
| 218 | + switch (getdata[8]) | ||
| 219 | + { | ||
| 220 | + //删除音频 | ||
| 221 | + case 0x02: | ||
| 222 | + return JZ_INSCODE_5AFRAME_DELETE_AUDIO; | ||
| 223 | + break; | ||
| 224 | + | ||
| 225 | + //删除录音 | ||
| 226 | + case 0x03: | ||
| 227 | + return JZ_INSCODE_5AFRAME_DELETE_VOICE_RECORD; | ||
| 228 | + break; | ||
| 229 | + | ||
| 230 | + // //删除视频 | ||
| 231 | + // case 0x02: | ||
| 232 | + // return JZ_INSCODE_DELETE_VIDEO_RECORD; | ||
| 233 | + // break; | ||
| 234 | + | ||
| 235 | + default: | ||
| 236 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 237 | + break; | ||
| 238 | + } | ||
| 239 | +} | ||
| 240 | +//一级功能码开启关闭循环 | ||
| 241 | +static int Comparison_5AFRAME_FirstLevelCode_0x55(char *getdata) | ||
| 242 | +{ | ||
| 243 | + //二级功能位 | ||
| 244 | + switch (getdata[8]) | ||
| 245 | + { | ||
| 246 | + //开启关闭循环 | ||
| 247 | + case 0x00: | ||
| 248 | + return JZ_INSCODE_5AFRAME_PLAY_LOOP; | ||
| 249 | + break; | ||
| 250 | + | ||
| 251 | + default: | ||
| 252 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 253 | + break; | ||
| 254 | + } | ||
| 255 | +} | ||
| 256 | +//一级功能码 | ||
| 257 | +static int Comparison_5AFRAME_FirstLevelCode_0x56(char *getdata) | ||
| 258 | +{ | ||
| 259 | + //二级功能位 | ||
| 260 | + switch (getdata[8]) | ||
| 261 | + { | ||
| 262 | + default: | ||
| 263 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 264 | + break; | ||
| 265 | + } | ||
| 266 | +} | ||
| 267 | +//一级功能码是 文本播放 | ||
| 268 | +static int Comparison_5AFRAME_FirstLevelCode_0x57(char *getdata) | ||
| 269 | +{ | ||
| 270 | + //二级功能位 | ||
| 271 | + switch (getdata[8]) | ||
| 272 | + { | ||
| 273 | + //设置音色 | ||
| 274 | + case 0x01: | ||
| 275 | + return JZ_INSCODE_5AFRAME_TTS_SET_TONE; | ||
| 276 | + break; | ||
| 277 | + | ||
| 278 | + //设置语速 | ||
| 279 | + case 0x02: | ||
| 280 | + return JZ_INSCODE_5AFRAME_TTS_SET_SPEED; | ||
| 281 | + break; | ||
| 282 | + | ||
| 283 | + //开始发送TTS | ||
| 284 | + case 0x03: | ||
| 285 | + return JZ_INSCODE_5AFRAME_TTS_TRANS_START; | ||
| 286 | + break; | ||
| 287 | + | ||
| 288 | + case 0x04: | ||
| 289 | + return JZ_INSCODE_5AFRAME_TTS_TRANS_STOP; | ||
| 290 | + break; | ||
| 291 | + | ||
| 292 | + //定长传输文本 | ||
| 293 | + case 0x05: | ||
| 294 | + return JZ_INSCODE_5AFRAME_TTS_TRANS_LIMIT_TRANSMISSION; | ||
| 295 | + break; | ||
| 296 | + | ||
| 297 | + default: | ||
| 298 | + break; | ||
| 299 | + } | ||
| 300 | +} | ||
| 301 | +//一级功能 查询列表 | ||
| 302 | +static int Comparison_5AFRAME_FirstLevelCode_0x58(char *getdata) | ||
| 303 | +{ | ||
| 304 | + //二级功能位 | ||
| 305 | + switch (getdata[8]) | ||
| 306 | + { | ||
| 307 | + //设置音色 | ||
| 308 | + case 0x01: | ||
| 309 | + return JZ_INSCODE_5AFRAME_AUDIO_GETMUSICLIST; | ||
| 310 | + break; | ||
| 311 | + | ||
| 312 | + default: | ||
| 313 | + break; | ||
| 314 | + } | ||
| 315 | +} | ||
| 316 | +//一级功能码opus功能 | ||
| 317 | +static int Comparison_5AFRAME_FirstLevelCode_0x59(char *getdata) | ||
| 318 | +{ | ||
| 319 | + //二级功能位 | ||
| 320 | + switch (getdata[8]) | ||
| 321 | + { | ||
| 322 | + //opus录音传输 | ||
| 323 | + //opus传输开始 | ||
| 324 | + case 0xF1: | ||
| 325 | + return JZ_INSCODE_5AFRAME_OPUS_TRANS_START; | ||
| 326 | + break; | ||
| 327 | + | ||
| 328 | + //opus传输结束 | ||
| 329 | + case 0xF2: | ||
| 330 | + return JZ_INSCODE_5AFRAME_OPUS_TRANS_STOP; | ||
| 331 | + break; | ||
| 332 | + | ||
| 333 | + //opus定长传输 | ||
| 334 | + case 0xF3: | ||
| 335 | + return JZ_INSCODE_5AFRAME_OPUS_TRANS_LIMIT_TRANSMISSION; | ||
| 336 | + break; | ||
| 337 | + | ||
| 338 | + //opus播放 | ||
| 339 | + case 0x01: | ||
| 340 | + return JZ_INSCODE_5AFRAME_OPUS_PLAY; | ||
| 341 | + break; | ||
| 342 | + | ||
| 343 | + //opus实时语音开始 | ||
| 344 | + case 0xE1: | ||
| 345 | + return JZ_INSCODE_5AFRAME_OPUS_REALTIMEVOICE_START; | ||
| 346 | + break; | ||
| 347 | + | ||
| 348 | + case 0xE2: | ||
| 349 | + return JZ_INSCODE_5AFRAME_OPUS_REALTIMEVOICE_STOP; | ||
| 350 | + break; | ||
| 351 | + | ||
| 352 | + //opus定长传输文件 | ||
| 353 | + case 0xE3: | ||
| 354 | + return JZ_INSCODE_5AFRAME_OPUS_REALTIMEVOICE_LIMIT_TRANSMISSION; | ||
| 355 | + break; | ||
| 356 | + | ||
| 357 | + default: | ||
| 358 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 359 | + break; | ||
| 360 | + } | ||
| 361 | +} | ||
| 362 | + | ||
| 363 | +//一级功能码,硬件引脚控制 | ||
| 364 | +static int Comparison_5AFRAME_FirstLevelCode_0x5A(char *getdata) | ||
| 365 | +{ | ||
| 366 | + //二级功能位 | ||
| 367 | + switch (getdata[8]) | ||
| 368 | + { | ||
| 369 | + //对外供电开关 | ||
| 370 | + case 0x01: | ||
| 371 | + return JZ_INSCODE_5AFRAME_OUTPUTPOWER_CONTROL; | ||
| 372 | + break; | ||
| 373 | + | ||
| 374 | + //对外供电查询 | ||
| 375 | + case 0x02: | ||
| 376 | + return JZ_INSCODE_5AFRAME_CHECKSTATUS_OUTPUTPOWER; | ||
| 377 | + break; | ||
| 378 | + | ||
| 379 | + default: | ||
| 380 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 381 | + break; | ||
| 382 | + } | ||
| 383 | +} | ||
| 384 | + | ||
| 385 | +//一级功能码 激光控制 | ||
| 386 | +static int Comparison_5AFRAME_FirstLevelCode_0x60(char *getdata) | ||
| 387 | +{ | ||
| 388 | + //二级功能位 | ||
| 389 | + switch (getdata[8]) | ||
| 390 | + { | ||
| 391 | + //激光控制 | ||
| 392 | + case 0x51: | ||
| 393 | + return JZ_INSCODE_5AFRAME_LASER_CONTROL; | ||
| 394 | + break; | ||
| 395 | + | ||
| 396 | + default: | ||
| 397 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 398 | + break; | ||
| 399 | + } | ||
| 400 | +} | ||
| 401 | + | ||
| 402 | +//一级功能码 爆闪频率 | ||
| 403 | +static int Comparison_5AFRAME_FirstLevelCode_0x61(char *getdata) | ||
| 404 | +{ | ||
| 405 | + //二级功能位 | ||
| 406 | + switch (getdata[8]) | ||
| 407 | + { | ||
| 408 | + //爆闪频率 | ||
| 409 | + case 0x51: | ||
| 410 | + return JZ_INSCODE_5AFRAME_SEARCHLIGHT_SET_FREQUENCY; | ||
| 411 | + break; | ||
| 412 | + | ||
| 413 | + default: | ||
| 414 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 415 | + break; | ||
| 416 | + } | ||
| 417 | +} | ||
| 418 | + | ||
| 419 | +//一级功能码 灯光控制 | ||
| 420 | +static int Comparison_5AFRAME_FirstLevelCode_0x62(char *getdata) | ||
| 421 | +{ | ||
| 422 | + //二级功能位 | ||
| 423 | + switch (getdata[8]) | ||
| 424 | + { | ||
| 425 | + //灯光模式 | ||
| 426 | + case 0x51: | ||
| 427 | + return JZ_INSCODE_5AFRAME_SEARCHLIGHT_CONTROL; | ||
| 428 | + break; | ||
| 429 | + | ||
| 430 | + default: | ||
| 431 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 432 | + break; | ||
| 433 | + } | ||
| 434 | +} | ||
| 435 | + | ||
| 436 | +//一级功能码 灯光亮度 | ||
| 437 | +static int Comparison_5AFRAME_FirstLevelCode_0x63(char *getdata) | ||
| 438 | +{ | ||
| 439 | + //二级功能位 | ||
| 440 | + switch (getdata[8]) | ||
| 441 | + { | ||
| 442 | + //灯光亮度 | ||
| 443 | + case 0x51: | ||
| 444 | + return JZ_INSCODE_5AFRAME_SEARCHLIGHT_SET_LUMEN; | ||
| 445 | + break; | ||
| 446 | + | ||
| 447 | + default: | ||
| 448 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 449 | + break; | ||
| 450 | + } | ||
| 451 | +} | ||
| 452 | + | ||
| 453 | +//一级功能码云台功能 | ||
| 454 | +static int Comparison_5AFRAME_FirstLevelCode_0x64(char *getdata) | ||
| 455 | +{ | ||
| 456 | + //二级功能位 | ||
| 457 | + switch (getdata[8]) | ||
| 458 | + { | ||
| 459 | + //云台俯仰控制 | ||
| 460 | + case 0x51: | ||
| 461 | + return JZ_INSCODE_5AFRAME_GIMBAL_PITCH_CONTROL; | ||
| 462 | + break; | ||
| 463 | + | ||
| 464 | + //云台俯仰微调控制 | ||
| 465 | + case 0x52: | ||
| 466 | + return JZ_INSCODE_5AFRAME_GIMBAL_PITCH_FINETUNING_CONTROL; | ||
| 467 | + break; | ||
| 468 | + | ||
| 469 | + default: | ||
| 470 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 471 | + break; | ||
| 472 | + } | ||
| 473 | +} | ||
| 474 | + | ||
| 475 | +//一级功能码 云台航向 | ||
| 476 | +static int Comparison_5AFRAME_FirstLevelCode_0x65(char *getdata) | ||
| 477 | +{ | ||
| 478 | + | ||
| 479 | +} | ||
| 480 | + | ||
| 481 | +//一级功能码 警灯模式控制 | ||
| 482 | +static int Comparison_5AFRAME_FirstLevelCode_0x66(char *getdata) | ||
| 483 | +{ | ||
| 484 | + switch (getdata[8]) | ||
| 485 | + { | ||
| 486 | + //警灯模式控制 | ||
| 487 | + case 0x51: | ||
| 488 | + return JZ_INSCODE_5AFRAME_WARNINGLIGHT_CONTROL; | ||
| 489 | + break; | ||
| 490 | + | ||
| 491 | + default: | ||
| 492 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 493 | + break; | ||
| 494 | + } | ||
| 495 | +} | ||
| 496 | + | ||
| 497 | +//一级功能码 警灯眼色选择 | ||
| 498 | +static int Comparison_5AFRAME_FirstLevelCode_0x67(char *getdata) | ||
| 499 | +{ | ||
| 500 | + switch (getdata[8]) | ||
| 501 | + { | ||
| 502 | + //警灯颜色选择 | ||
| 503 | + case 0x51: | ||
| 504 | + return JZ_INSCODE_5AFRAME_WARNINGLIGHT_COLOUR; | ||
| 505 | + break; | ||
| 506 | + | ||
| 507 | + default: | ||
| 508 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 509 | + break; | ||
| 510 | + } | ||
| 511 | +} | ||
| 512 | + | ||
| 513 | +//一级功能码 探照灯消息订阅 | ||
| 514 | +static int Comparison_5AFRAME_FirstLevelCode_0x68(char *getdata) | ||
| 515 | +{ | ||
| 516 | + switch (getdata[8]) | ||
| 517 | + { | ||
| 518 | + //探照灯消息订阅 | ||
| 519 | + case 0x51: | ||
| 520 | + return JZ_INSCODE_5AFRAME_SEARCHLIGHT_MESSAGE_SUBSCRIPTION_CONTROL; | ||
| 521 | + break; | ||
| 522 | + | ||
| 523 | + default: | ||
| 524 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 525 | + break; | ||
| 526 | + } | ||
| 527 | + | ||
| 528 | +} | ||
| 529 | + | ||
| 530 | +//一级功能码 私有协议 | ||
| 531 | +static int Comparison_5AFRAME_FirstLevelCode_0x69(char *getdata) | ||
| 532 | +{ | ||
| 533 | + | ||
| 534 | +} | ||
| 535 | + | ||
| 536 | +//一级功能码 6F查询帧 | ||
| 537 | +static int Comparison_5AFRAME_FirstLevelCode_0x6F(char *getdata) | ||
| 538 | +{ | ||
| 539 | + //二级功能位 | ||
| 540 | + switch (getdata[8]) | ||
| 541 | + { | ||
| 542 | + //灯光查询 | ||
| 543 | + case 0x51: | ||
| 544 | + return JZ_INSCODE_5AFRAME_CHECKSTATUS_SEARCHLIGHT_LIGHTATTRIBUTE; | ||
| 545 | + break; | ||
| 546 | + | ||
| 547 | + //温度查询 | ||
| 548 | + case 0x52: | ||
| 549 | + return JZ_INSCODE_5AFRAME_CHECKSTATUS_SEARCHLIGHT_TEMPERATURE; | ||
| 550 | + break; | ||
| 551 | + | ||
| 552 | + //激光查询 | ||
| 553 | + case 0x53: | ||
| 554 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 555 | + break; | ||
| 556 | + | ||
| 557 | + //云台角度查询 | ||
| 558 | + case 0x54: | ||
| 559 | + return JZ_INSCODE_5AFRAME_CHECKSTATUS_GIMBAL; | ||
| 560 | + break; | ||
| 561 | + | ||
| 562 | + //警灯状态查询 | ||
| 563 | + case 0x55: | ||
| 564 | + return JZ_INSCODE_5AFRAME_CHECKSTATUS_WARNINGLIGHT_STATUS; | ||
| 565 | + break; | ||
| 566 | + | ||
| 567 | + //警灯颜色查询 | ||
| 568 | + case 0x56: | ||
| 569 | + return JZ_INSCODE_5AFRAME_CHECKSTATUS_WARNINGLIGHT_COLOR; | ||
| 570 | + break; | ||
| 571 | + | ||
| 572 | + //产品序列号查询 | ||
| 573 | + case 0x57: | ||
| 574 | + return JZ_INSCODE_5AFRAME_CHECKSTATUS_SERIALNUMBER; | ||
| 575 | + break; | ||
| 576 | + | ||
| 577 | + //云台微调值查询 | ||
| 578 | + case 0x58: | ||
| 579 | + return JZ_INSCODE_5AFRAME_CHECKSTATUS_GIMBAL_FINETUNING; | ||
| 580 | + break; | ||
| 581 | + | ||
| 582 | + default: | ||
| 583 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 584 | + break; | ||
| 585 | + } | ||
| 586 | +} | ||
| 587 | + | ||
| 588 | +/****************************************************************** | ||
| 589 | + | ||
| 590 | + 回复帧对比 | ||
| 591 | + 成功返回帧类型 无对比数据返回 JZ_ERROR_SYSTEM_FRAME_ERROR | ||
| 592 | + | ||
| 593 | +******************************************************************/ | ||
| 594 | +int JZsdk_5AFrameComparsion(char *getdata, int len) | ||
| 595 | +{ | ||
| 596 | + //1、判断帧头帧尾 | ||
| 597 | + if ( | ||
| 598 | + ( (getdata[0]!= 0x5a) && (getdata[1] != 0x5a) && (getdata[2]!=0x77) ) | ||
| 599 | + || ( (getdata[len -2]!= 0x00) && (getdata[ len -1] != 0x23) ) | ||
| 600 | + ) | ||
| 601 | + { | ||
| 602 | + printf("接受到的帧,没有帧头或者帧尾,退出JZsdk_5AFrameComparsion函数\n"); | ||
| 603 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 604 | + } | ||
| 605 | + | ||
| 606 | + //一级功能码 | ||
| 607 | + switch (getdata[7]) | ||
| 608 | + { | ||
| 609 | +/********************************************************************************************************************************************************* | ||
| 610 | + * | ||
| 611 | + * 连接请求码 | ||
| 612 | + * | ||
| 613 | +*********************************************************************************************************************************************************/ | ||
| 614 | + //一级功能码是连接请求 | ||
| 615 | + case 0x50: | ||
| 616 | + return Comparison_5AFRAME_FirstLevelCode_0x50(getdata); | ||
| 617 | + break; | ||
| 618 | + | ||
| 619 | +/********************************************************************************************************************************************************* | ||
| 620 | + * | ||
| 621 | + * 喊话器功能码 | ||
| 622 | + * | ||
| 623 | +*********************************************************************************************************************************************************/ | ||
| 624 | + //一级功能码 语音 / 音频文件功能 | ||
| 625 | + case 0x51: | ||
| 626 | + return Comparison_5AFRAME_FirstLevelCode_0x51(getdata); | ||
| 627 | + break; | ||
| 628 | + | ||
| 629 | + //一级功能码 音频/ 功放/ 音量调节 | ||
| 630 | + case 0x52: | ||
| 631 | + return Comparison_5AFRAME_FirstLevelCode_0x52(getdata); | ||
| 632 | + break; | ||
| 633 | + | ||
| 634 | + //一级功能码 查询状态 | ||
| 635 | + case 0x53: | ||
| 636 | + return Comparison_5AFRAME_FirstLevelCode_0x53(getdata); | ||
| 637 | + break; | ||
| 638 | + | ||
| 639 | + //一级功能码 删除 | ||
| 640 | + case 0x54: | ||
| 641 | + return Comparison_5AFRAME_FirstLevelCode_0x54(getdata); | ||
| 642 | + break; | ||
| 643 | + | ||
| 644 | + //一级功能码 开启关闭循环 | ||
| 645 | + case 0x55: | ||
| 646 | + return Comparison_5AFRAME_FirstLevelCode_0x55(getdata); | ||
| 647 | + break; | ||
| 648 | + | ||
| 649 | + //一级功能码 | ||
| 650 | + case 0x56: | ||
| 651 | + return Comparison_5AFRAME_FirstLevelCode_0x56(getdata); | ||
| 652 | + break; | ||
| 653 | + | ||
| 654 | + //一级功能码 TTS | ||
| 655 | + case 0x57: | ||
| 656 | + return Comparison_5AFRAME_FirstLevelCode_0x57(getdata); | ||
| 657 | + break; | ||
| 658 | + | ||
| 659 | + //一级功能码 查询列表功能 | ||
| 660 | + case 0x58: | ||
| 661 | + return Comparison_5AFRAME_FirstLevelCode_0x58(getdata); | ||
| 662 | + break; | ||
| 663 | + | ||
| 664 | + //一级功能码 opus | ||
| 665 | + case 0x59: | ||
| 666 | + return Comparison_5AFRAME_FirstLevelCode_0x59(getdata); | ||
| 667 | + break; | ||
| 668 | + | ||
| 669 | + //一级功能码,硬件引脚控制 | ||
| 670 | + case 0x5A: | ||
| 671 | + return Comparison_5AFRAME_FirstLevelCode_0x5A(getdata); | ||
| 672 | + break; | ||
| 673 | + | ||
| 674 | + //一级功能码 激光控制 | ||
| 675 | + case 0x60: | ||
| 676 | + return Comparison_5AFRAME_FirstLevelCode_0x60(getdata); | ||
| 677 | + break; | ||
| 678 | + | ||
| 679 | + //一级功能码 爆闪控制 | ||
| 680 | + case 0x61: | ||
| 681 | + return Comparison_5AFRAME_FirstLevelCode_0x61(getdata); | ||
| 682 | + break; | ||
| 683 | + | ||
| 684 | + //一级功能码 灯光控制 | ||
| 685 | + case 0x62: | ||
| 686 | + return Comparison_5AFRAME_FirstLevelCode_0x62(getdata); | ||
| 687 | + break; | ||
| 688 | + | ||
| 689 | + //一级功能码 灯光亮度 | ||
| 690 | + case 0x63: | ||
| 691 | + return Comparison_5AFRAME_FirstLevelCode_0x63(getdata); | ||
| 692 | + break; | ||
| 693 | + | ||
| 694 | + //一级功能码 云台俯仰 | ||
| 695 | + case 0x64: | ||
| 696 | + return Comparison_5AFRAME_FirstLevelCode_0x64(getdata); | ||
| 697 | + break; | ||
| 698 | + | ||
| 699 | + //一级功能码 云台航向 | ||
| 700 | + case 0x65: | ||
| 701 | + return Comparison_5AFRAME_FirstLevelCode_0x65(getdata); | ||
| 702 | + break; | ||
| 703 | + | ||
| 704 | + //一级功能码 警灯模式控制 | ||
| 705 | + case 0x66: | ||
| 706 | + return Comparison_5AFRAME_FirstLevelCode_0x66(getdata); | ||
| 707 | + break; | ||
| 708 | + | ||
| 709 | + //一级功能码 警灯眼色选择 | ||
| 710 | + case 0x67: | ||
| 711 | + return Comparison_5AFRAME_FirstLevelCode_0x67(getdata); | ||
| 712 | + break; | ||
| 713 | + | ||
| 714 | + //一级功能码 探照灯消息订阅 | ||
| 715 | + case 0x68: | ||
| 716 | + return Comparison_5AFRAME_FirstLevelCode_0x68(getdata); | ||
| 717 | + break; | ||
| 718 | + | ||
| 719 | + //一级功能码 私有协议 | ||
| 720 | + case 0x69: | ||
| 721 | + return Comparison_5AFRAME_FirstLevelCode_0x69(getdata); | ||
| 722 | + break; | ||
| 723 | + | ||
| 724 | + //一级功能码 6f查询帧 | ||
| 725 | + case 0x6F: | ||
| 726 | + return Comparison_5AFRAME_FirstLevelCode_0x6F(getdata); | ||
| 727 | + break; | ||
| 728 | + | ||
| 729 | + | ||
| 730 | + break; | ||
| 731 | + | ||
| 732 | + //一级功能码 | ||
| 733 | + | ||
| 734 | +/********************************************************************************************************************************************************* | ||
| 735 | + * | ||
| 736 | + * | ||
| 737 | + * | ||
| 738 | +*********************************************************************************************************************************************************/ | ||
| 739 | + default: | ||
| 740 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 741 | + break; | ||
| 742 | + } | ||
| 743 | +} | ||
| 744 | + |
| 1 | +/********************************************************************** | ||
| 2 | + * @file | ||
| 3 | + * | ||
| 4 | + * | ||
| 5 | + ********************************************************************* | ||
| 6 | + */ | ||
| 7 | + | ||
| 8 | +/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/ | ||
| 9 | +#ifndef JZSDK_FRAMECOMPARSION_5AFRAME_H | ||
| 10 | +#define JZSDK_FRAMECOMPARSION_5AFRAME_H | ||
| 11 | + | ||
| 12 | +/* Includes ------------------------------------------------------------------*/ | ||
| 13 | + | ||
| 14 | +#ifdef __cplusplus | ||
| 15 | +extern "C" { | ||
| 16 | +#endif | ||
| 17 | + | ||
| 18 | +/* Exported constants --------------------------------------------------------*/ | ||
| 19 | +/* 常亮定义*/ | ||
| 20 | + | ||
| 21 | +/* Exported types ------------------------------------------------------------*/ | ||
| 22 | + | ||
| 23 | +/* Exported functions --------------------------------------------------------*/ | ||
| 24 | + | ||
| 25 | +int JZsdk_5AFrameComparsion(char *getdata, int len); | ||
| 26 | + | ||
| 27 | +#ifdef __cplusplus | ||
| 28 | +} | ||
| 29 | +#endif | ||
| 30 | + | ||
| 31 | +#endif |
| 1 | +#include <stdio.h> | ||
| 2 | +#include "../JZsdk_Code/JZsdk_Code.h" | ||
| 3 | + | ||
| 4 | + | ||
| 5 | +/****************************************************** | ||
| 6 | + | ||
| 7 | + 接收一级功能码区 | ||
| 8 | + | ||
| 9 | +/******************************************************/ | ||
| 10 | +//一级功能码是连接功能 | ||
| 11 | +static int Comparison_5BFRAME_FirstLevelCode_0x50(char *getdata) | ||
| 12 | +{ | ||
| 13 | + //二级功能位 | ||
| 14 | + switch (getdata[8]) | ||
| 15 | + { | ||
| 16 | + //回复连接 | ||
| 17 | + case 0x51: | ||
| 18 | + return JZ_INSCODE_5BFRAME_INITIATECONNECT; | ||
| 19 | + break; | ||
| 20 | + | ||
| 21 | + //心跳帧回复 | ||
| 22 | + case 0x53: | ||
| 23 | + return JZ_INSCODE_5BFRAME_HEARTBEAT; | ||
| 24 | + break; | ||
| 25 | + | ||
| 26 | + //时间戳回复 | ||
| 27 | + case 0x54: | ||
| 28 | + return JZ_INSCODE_5BFRAME_TIMESTAMP; | ||
| 29 | + break; | ||
| 30 | + | ||
| 31 | + //版本号回复 | ||
| 32 | + case 0x55: | ||
| 33 | + return JZ_INSCODE_5BFRAME_ALL_VERSION; | ||
| 34 | + break; | ||
| 35 | + | ||
| 36 | + //序列号回复 | ||
| 37 | + case 0x56: | ||
| 38 | + return JZ_INSCODE_5BFRAME_ALL_SERIAL_NUMBER; | ||
| 39 | + break; | ||
| 40 | + | ||
| 41 | + //log信息打印 | ||
| 42 | + case 0x58: | ||
| 43 | + return JZ_INSCODE_5BFRAME_DEVICE_MESSAGE; | ||
| 44 | + break; | ||
| 45 | + | ||
| 46 | + default: | ||
| 47 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 48 | + break; | ||
| 49 | + } | ||
| 50 | +} | ||
| 51 | + | ||
| 52 | +//一级功能码是操作功能 | ||
| 53 | +static int Comparison_5BFRAME_FirstLevelCode_0x51(char *getdata) | ||
| 54 | +{ | ||
| 55 | + //二级功能位 | ||
| 56 | + switch (getdata[8]) | ||
| 57 | + { | ||
| 58 | + //回复操作成功 | ||
| 59 | + case 0x01: | ||
| 60 | + return JZ_INSCODE_5BFRAME_SUCESS; | ||
| 61 | + break; | ||
| 62 | + | ||
| 63 | + //回复操作失败 | ||
| 64 | + case 0xff: | ||
| 65 | + return JZ_INSCODE_5BFRAME_DEFEAT; | ||
| 66 | + break; | ||
| 67 | + | ||
| 68 | + default: | ||
| 69 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 70 | + break; | ||
| 71 | + } | ||
| 72 | +} | ||
| 73 | +//一级功能码是音频列表功能 | ||
| 74 | +static int Comparison_5BFRAME_FirstLevelCode_0x53(char *getdata) | ||
| 75 | +{ | ||
| 76 | + //二级功能位 | ||
| 77 | + switch (getdata[8]) | ||
| 78 | + { | ||
| 79 | + //音量返回 | ||
| 80 | + case 0x01: | ||
| 81 | + return JZ_INSCODE_5BFRAME_VOLUME; | ||
| 82 | + break; | ||
| 83 | + | ||
| 84 | + //播放状态返回 | ||
| 85 | + case 0x02: | ||
| 86 | + return JZ_INSCODE_5BFRAME_AUDIO_PLAYSTATUS; | ||
| 87 | + break; | ||
| 88 | + | ||
| 89 | + //当前播放文件名返回 | ||
| 90 | + case 0x04: | ||
| 91 | + return JZ_INSCODE_5BFRAME_AUDIO_PLAYFILENAME; | ||
| 92 | + break; | ||
| 93 | + | ||
| 94 | + //查询是否开启循环 | ||
| 95 | + case 0x05: | ||
| 96 | + return JZ_INSCODE_5BFRAME_AUDIO_PLAYLOOPSTATUS; | ||
| 97 | + break; | ||
| 98 | + | ||
| 99 | + //查询音色 | ||
| 100 | + case 0x06: | ||
| 101 | + return JZ_INSCODE_5BFRAME_TTS_TONE; | ||
| 102 | + break; | ||
| 103 | + | ||
| 104 | + //查询语速 | ||
| 105 | + case 0x07: | ||
| 106 | + return JZ_INSCODE_5BFRAME_TTS_SPEED; | ||
| 107 | + break; | ||
| 108 | + | ||
| 109 | + //版本返回 | ||
| 110 | + case 0xf1: | ||
| 111 | + return JZ_INSCODE_5BFRAME_SORTWAREVERSION; | ||
| 112 | + break; | ||
| 113 | + | ||
| 114 | + //播放结束(主动返回) | ||
| 115 | + case 0xff: | ||
| 116 | + return JZ_INSCODE_5BFRAME_AUDIO_PLAYSTATUS_END; | ||
| 117 | + break; | ||
| 118 | + | ||
| 119 | + default: | ||
| 120 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 121 | + break; | ||
| 122 | + } | ||
| 123 | +} | ||
| 124 | + | ||
| 125 | +//一级功能码是音频列表功能 | ||
| 126 | +static int Comparison_5BFRAME_FirstLevelCode_0x58(char *getdata) | ||
| 127 | +{ | ||
| 128 | + //二级功能位 | ||
| 129 | + switch (getdata[8]) | ||
| 130 | + { | ||
| 131 | + //查询列表开始 | ||
| 132 | + case 0x00: | ||
| 133 | + return JZ_INSCODE_5BFRAME_MUSICLIST_START; | ||
| 134 | + break; | ||
| 135 | + | ||
| 136 | + //文件列表帧 | ||
| 137 | + case 0x02: | ||
| 138 | + return JZ_INSCODE_5BFRAME_MUSICLIST_TRANS; | ||
| 139 | + break; | ||
| 140 | + | ||
| 141 | + //结束列表返回 | ||
| 142 | + case 0xff: | ||
| 143 | + return JZ_INSCODE_5BFRAME_MUSICLIST_STOP; | ||
| 144 | + break; | ||
| 145 | + | ||
| 146 | + default: | ||
| 147 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 148 | + break; | ||
| 149 | + } | ||
| 150 | +} | ||
| 151 | + | ||
| 152 | +//一级功能码是opus功能 | ||
| 153 | +static int Comparison_5BFRAME_FirstLevelCode_0x59(char *getdata) | ||
| 154 | +{ | ||
| 155 | + //二级功能位 | ||
| 156 | + switch (getdata[8]) | ||
| 157 | + { | ||
| 158 | + //opus解码状态 | ||
| 159 | + case 0xF2: | ||
| 160 | + return JZ_INSCODE_5BFRAME_OPUS_DECODE_STATUS; | ||
| 161 | + break; | ||
| 162 | + | ||
| 163 | + default: | ||
| 164 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 165 | + break; | ||
| 166 | + } | ||
| 167 | +} | ||
| 168 | + | ||
| 169 | +//一级功能码是硬件引脚控制 | ||
| 170 | +static int Comparison_5BFRAME_FirstLevelCode_0x5A(char *getdata) | ||
| 171 | +{ | ||
| 172 | + //二级功能位 | ||
| 173 | + switch (getdata[8]) | ||
| 174 | + { | ||
| 175 | + //回复对供电开关状态返回 | ||
| 176 | + case 0x02: | ||
| 177 | + return JZ_INSCODE_5BFRAME_CHECKSTATUS_OUTPUTPOWER; | ||
| 178 | + break; | ||
| 179 | + | ||
| 180 | + default: | ||
| 181 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 182 | + break; | ||
| 183 | + } | ||
| 184 | +} | ||
| 185 | + | ||
| 186 | +//一级功能码是激光 | ||
| 187 | +static int Comparison_5BFRAME_FirstLevelCode_0x60(char *getdata) | ||
| 188 | +{ | ||
| 189 | + //二级功能位 | ||
| 190 | + switch (getdata[8]) | ||
| 191 | + { | ||
| 192 | + //回复激光查询 | ||
| 193 | + case 0x51: | ||
| 194 | + return JZ_INSCODE_5BFRAME_CHECKSTATUS_LASER_STATUS; | ||
| 195 | + break; | ||
| 196 | + | ||
| 197 | + default: | ||
| 198 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 199 | + break; | ||
| 200 | + } | ||
| 201 | +} | ||
| 202 | + | ||
| 203 | +//一级功能码是回复灯光频率 | ||
| 204 | +static int Comparison_5BFRAME_FirstLevelCode_0x61(char *getdata) | ||
| 205 | +{ | ||
| 206 | + //二级功能位 | ||
| 207 | + switch (getdata[8]) | ||
| 208 | + { | ||
| 209 | + //回复灯光频率 | ||
| 210 | + case 0x51: | ||
| 211 | + return JZ_INSCODE_5BFRAME_CHECKSTATUS_SEARCHLIGHT_FREQUENCY; | ||
| 212 | + break; | ||
| 213 | + | ||
| 214 | + default: | ||
| 215 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 216 | + break; | ||
| 217 | + } | ||
| 218 | +} | ||
| 219 | + | ||
| 220 | +//一级功能码是回复灯光模式 | ||
| 221 | +static int Comparison_5BFRAME_FirstLevelCode_0x62(char *getdata) | ||
| 222 | +{ | ||
| 223 | + //二级功能位 | ||
| 224 | + switch (getdata[8]) | ||
| 225 | + { | ||
| 226 | + //回复灯光模式 | ||
| 227 | + case 0x51: | ||
| 228 | + return JZ_INSCODE_5BFRAME_CHECKSTATUS_SEARCHLIGHT_MODE; | ||
| 229 | + break; | ||
| 230 | + | ||
| 231 | + default: | ||
| 232 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 233 | + break; | ||
| 234 | + } | ||
| 235 | +} | ||
| 236 | + | ||
| 237 | +//一级功能码是回复灯光亮度 | ||
| 238 | +static int Comparison_5BFRAME_FirstLevelCode_0x63(char *getdata) | ||
| 239 | +{ | ||
| 240 | + //二级功能位 | ||
| 241 | + switch (getdata[8]) | ||
| 242 | + { | ||
| 243 | + //回复灯光亮度 | ||
| 244 | + case 0x51: | ||
| 245 | + return JZ_INSCODE_5BFRAME_CHECKSTATUS_SEARCHLIGHT_LUMEN; | ||
| 246 | + break; | ||
| 247 | + | ||
| 248 | + default: | ||
| 249 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 250 | + break; | ||
| 251 | + } | ||
| 252 | +} | ||
| 253 | + | ||
| 254 | +//一级功能码是云台俯仰 | ||
| 255 | +static int Comparison_5BFRAME_FirstLevelCode_0x64(char *getdata) | ||
| 256 | +{ | ||
| 257 | + //二级功能位 | ||
| 258 | + switch (getdata[8]) | ||
| 259 | + { | ||
| 260 | + //回复云台俯仰 | ||
| 261 | + case 0x51: | ||
| 262 | + return JZ_INSCODE_5BFRAME_GIMBAL_PITCH; | ||
| 263 | + break; | ||
| 264 | + | ||
| 265 | + //回复云台俯仰微调值 | ||
| 266 | + case 0x52: | ||
| 267 | + return JZ_INSCODE_5BFRAME_GIMBAL_PITCH_FINETUNING; | ||
| 268 | + break; | ||
| 269 | + | ||
| 270 | + default: | ||
| 271 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 272 | + break; | ||
| 273 | + } | ||
| 274 | +} | ||
| 275 | +//一级功能码是云台航向 | ||
| 276 | +static int Comparison_5BFRAME_FirstLevelCode_0x65(char *getdata) | ||
| 277 | +{ | ||
| 278 | + //二级功能位 | ||
| 279 | + switch (getdata[8]) | ||
| 280 | + { | ||
| 281 | + //回复云台航向 | ||
| 282 | + case 0x51: | ||
| 283 | + return JZ_INSCODE_5BFRAME_GIMBAL_YAW; | ||
| 284 | + break; | ||
| 285 | + | ||
| 286 | + | ||
| 287 | + default: | ||
| 288 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 289 | + break; | ||
| 290 | + } | ||
| 291 | +} | ||
| 292 | +//一级功能码是回复警灯状态 | ||
| 293 | +static int Comparison_5BFRAME_FirstLevelCode_0x66(char *getdata) | ||
| 294 | +{ | ||
| 295 | + //二级功能位 | ||
| 296 | + switch (getdata[8]) | ||
| 297 | + { | ||
| 298 | + //回复警灯状态 | ||
| 299 | + case 0x51: | ||
| 300 | + return JZ_INSCODE_5BFRAME_CHECKSTATUS_WARNINGLIGHT_STATUS; | ||
| 301 | + break; | ||
| 302 | + | ||
| 303 | + | ||
| 304 | + default: | ||
| 305 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 306 | + break; | ||
| 307 | + } | ||
| 308 | +}//一级功能码是回复警灯颜色 | ||
| 309 | +static int Comparison_5BFRAME_FirstLevelCode_0x67(char *getdata) | ||
| 310 | +{ | ||
| 311 | + //二级功能位 | ||
| 312 | + switch (getdata[8]) | ||
| 313 | + { | ||
| 314 | + //回复回复警灯颜色 | ||
| 315 | + case 0x51: | ||
| 316 | + return JZ_INSCODE_5BFRAME_CHECKSTATUS_WARNINGLIGHT_COLOR; | ||
| 317 | + break; | ||
| 318 | + | ||
| 319 | + | ||
| 320 | + default: | ||
| 321 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 322 | + break; | ||
| 323 | + } | ||
| 324 | +}//一级功能码是回复温度/序列号查询 | ||
| 325 | +static int Comparison_5BFRAME_FirstLevelCode_0x69(char *getdata) | ||
| 326 | +{ | ||
| 327 | + //二级功能位 | ||
| 328 | + switch (getdata[8]) | ||
| 329 | + { | ||
| 330 | + //回复温度查询 | ||
| 331 | + case 0x51: | ||
| 332 | + return JZ_INSCODE_5BFRAME_CHECKSTATUS_SEARCHLIGHT_TEMPERATURE; | ||
| 333 | + break; | ||
| 334 | + | ||
| 335 | + //回复产品序列号 | ||
| 336 | + case 0x54: | ||
| 337 | + return JZ_INSCODE_5BFRAME_CHECKSTATUS_SERIALNUMBER; | ||
| 338 | + break; | ||
| 339 | + | ||
| 340 | + default: | ||
| 341 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 342 | + break; | ||
| 343 | + } | ||
| 344 | +} | ||
| 345 | +/****************************************************************** | ||
| 346 | + | ||
| 347 | + 回复帧对比 | ||
| 348 | + 成功返回帧类型 无对比数据返回 JZ_ERROR_SYSTEM_FRAME_ERROR | ||
| 349 | + | ||
| 350 | +******************************************************************/ | ||
| 351 | +int JZsdk_5BFrameComparsion(char *getdata, int len) | ||
| 352 | +{ | ||
| 353 | + //1、判断帧头帧尾 | ||
| 354 | + if ( | ||
| 355 | + ( (getdata[0]!= 0x5B) && (getdata[1] != 0x5B) && (getdata[2]!=0x77) ) | ||
| 356 | + || ( (getdata[len -2]!= 0x00) && (getdata[ len -1] != 0x23) ) | ||
| 357 | + ) | ||
| 358 | + { | ||
| 359 | + printf("接受到的帧,没有帧头或者帧尾,退出JZsdk_5BFrameComparsion函数\n"); | ||
| 360 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 361 | + } | ||
| 362 | + | ||
| 363 | + //一级功能码 | ||
| 364 | + switch (getdata[7]) | ||
| 365 | + { | ||
| 366 | + case 0x50: | ||
| 367 | + return Comparison_5BFRAME_FirstLevelCode_0x50(getdata); | ||
| 368 | + break; | ||
| 369 | + | ||
| 370 | + case 0x51: | ||
| 371 | + return Comparison_5BFRAME_FirstLevelCode_0x51(getdata); | ||
| 372 | + break; | ||
| 373 | + | ||
| 374 | + case 0x53: | ||
| 375 | + return Comparison_5BFRAME_FirstLevelCode_0x53(getdata); | ||
| 376 | + break; | ||
| 377 | + | ||
| 378 | + case 0x58: | ||
| 379 | + return Comparison_5BFRAME_FirstLevelCode_0x58(getdata); | ||
| 380 | + break; | ||
| 381 | + | ||
| 382 | + case 0x59: | ||
| 383 | + return Comparison_5BFRAME_FirstLevelCode_0x58(getdata); | ||
| 384 | + break; | ||
| 385 | + | ||
| 386 | + case 0x5A: | ||
| 387 | + return Comparison_5BFRAME_FirstLevelCode_0x5A(getdata); | ||
| 388 | + break; | ||
| 389 | + | ||
| 390 | + case 0x60: | ||
| 391 | + return Comparison_5BFRAME_FirstLevelCode_0x60(getdata); | ||
| 392 | + break; | ||
| 393 | + | ||
| 394 | + case 0x61: | ||
| 395 | + return Comparison_5BFRAME_FirstLevelCode_0x61(getdata); | ||
| 396 | + break; | ||
| 397 | + | ||
| 398 | + case 0x62: | ||
| 399 | + return Comparison_5BFRAME_FirstLevelCode_0x62(getdata); | ||
| 400 | + break; | ||
| 401 | + | ||
| 402 | + case 0x63: | ||
| 403 | + return Comparison_5BFRAME_FirstLevelCode_0x63(getdata); | ||
| 404 | + break; | ||
| 405 | + | ||
| 406 | + case 0x64: | ||
| 407 | + return Comparison_5BFRAME_FirstLevelCode_0x64(getdata); | ||
| 408 | + break; | ||
| 409 | + | ||
| 410 | + case 0x65: | ||
| 411 | + return Comparison_5BFRAME_FirstLevelCode_0x65(getdata); | ||
| 412 | + break; | ||
| 413 | + | ||
| 414 | + case 0x66: | ||
| 415 | + return Comparison_5BFRAME_FirstLevelCode_0x66(getdata); | ||
| 416 | + break; | ||
| 417 | + | ||
| 418 | + case 0x67: | ||
| 419 | + return Comparison_5BFRAME_FirstLevelCode_0x67(getdata); | ||
| 420 | + break; | ||
| 421 | + | ||
| 422 | + case 0x69: | ||
| 423 | + return Comparison_5BFRAME_FirstLevelCode_0x69(getdata); | ||
| 424 | + break; | ||
| 425 | + | ||
| 426 | + | ||
| 427 | + default: | ||
| 428 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 429 | + break; | ||
| 430 | + } | ||
| 431 | +} |
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file | ||
| 4 | + * | ||
| 5 | + * | ||
| 6 | + ********************************************************************* | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/ | ||
| 10 | +#ifndef JZSDK_FRAMECOMPARSION_5BFRAME_H | ||
| 11 | +#define JZSDK_FRAMECOMPARSION_5BFRAME_H | ||
| 12 | + | ||
| 13 | +/* Includes ------------------------------------------------------------------*/ | ||
| 14 | + | ||
| 15 | +#ifdef __cplusplus | ||
| 16 | +extern "C" { | ||
| 17 | +#endif | ||
| 18 | + | ||
| 19 | +/* Exported constants --------------------------------------------------------*/ | ||
| 20 | +/* 常亮定义*/ | ||
| 21 | + | ||
| 22 | +/* Exported types ------------------------------------------------------------*/ | ||
| 23 | + | ||
| 24 | +/* Exported functions --------------------------------------------------------*/ | ||
| 25 | +int JZsdk_5BFrameComparsion(char *getdata, int len); | ||
| 26 | + | ||
| 27 | + | ||
| 28 | +#ifdef __cplusplus | ||
| 29 | +} | ||
| 30 | +#endif | ||
| 31 | + | ||
| 32 | +#endif |
| 1 | +#include <stdio.h> | ||
| 2 | +#include "../JZsdk_Code/JZsdk_Code.h" | ||
| 3 | + | ||
| 4 | + | ||
| 5 | +//一级功能码是私有协议 | ||
| 6 | +static int Comparison_6AFRAME_FirstLevelCode_0x69(char *getdata) | ||
| 7 | +{ | ||
| 8 | + //二级功能位 | ||
| 9 | + switch (getdata[8]) | ||
| 10 | + { | ||
| 11 | + //设置当前为云台零值 | ||
| 12 | + case 0x51: | ||
| 13 | + return JZ_INSCODE_6AFRAME_SET_GIMBAL_ORIGIN; | ||
| 14 | + break; | ||
| 15 | + | ||
| 16 | + //设置云台当前为最大最小值 | ||
| 17 | + case 0x52: | ||
| 18 | + return JZ_INSCODE_6AFRAME_SET_GIMBAL_MAXMIN_RANGE; | ||
| 19 | + break; | ||
| 20 | + | ||
| 21 | + //设置灯光当前亮度为最大最小值 | ||
| 22 | + case 0x53: | ||
| 23 | + return JZ_INSCODE_6AFRAME_SET_LUMEN_MAXMIN_RANGE; | ||
| 24 | + break; | ||
| 25 | + | ||
| 26 | + //设置产品序列号 | ||
| 27 | + case 0x54: | ||
| 28 | + return JZ_INSCODE_6AFRAME_SET_SERIALNUMBER; | ||
| 29 | + break; | ||
| 30 | + | ||
| 31 | + //舵机自检 | ||
| 32 | + case 0x55: | ||
| 33 | + return JZ_INSCODE_6AFRAME_SERVO_SELFCHECK; | ||
| 34 | + break; | ||
| 35 | + | ||
| 36 | + //开启关闭云台联动 | ||
| 37 | + case 0x56: | ||
| 38 | + return JZ_INSCODE_6AFRAME_GIMBAL_LINKAGE_CONTROL; | ||
| 39 | + break; | ||
| 40 | + | ||
| 41 | + default: | ||
| 42 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 43 | + break; | ||
| 44 | + } | ||
| 45 | +} | ||
| 46 | + | ||
| 47 | + | ||
| 48 | + | ||
| 49 | +//一级功能码是私有协议 | ||
| 50 | +static int Comparison_6AFRAME_FirstLevelCode_0x6F(char *getdata) | ||
| 51 | +{ | ||
| 52 | + //二级功能位 | ||
| 53 | + switch (getdata[8]) | ||
| 54 | + { | ||
| 55 | + //设置当前为云台零值 | ||
| 56 | + case 0x50: | ||
| 57 | + return JZ_INSCODE_6AFRAME_CHECKSTATUS_SECONDARY_DEVICE_NAME; | ||
| 58 | + break; | ||
| 59 | + | ||
| 60 | + //设置当前为云台零值 | ||
| 61 | + case 0x51: | ||
| 62 | + return JZ_INSCODE_6AFRAME_CHECKSTATUS_GIMBAL_LINKAGE; | ||
| 63 | + break; | ||
| 64 | + | ||
| 65 | + //串口比特率修改 | ||
| 66 | + case 0x52: | ||
| 67 | + return JZ_INSCODE_6AFRAME_UART_BITRATE_CHANGE; | ||
| 68 | + break; | ||
| 69 | + | ||
| 70 | + //设置特殊变量 | ||
| 71 | + case 0x53: | ||
| 72 | + return JZ_INSCODE_6AFRAME_SPECIAL_PARAMETERS; | ||
| 73 | + break; | ||
| 74 | + | ||
| 75 | + //查询特殊变量 | ||
| 76 | + case 0x54: | ||
| 77 | + return JZ_INSCODE_6AFRAME_CHECK_SPECIAL_PARAMETERS; | ||
| 78 | + break; | ||
| 79 | + | ||
| 80 | + default: | ||
| 81 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 82 | + break; | ||
| 83 | + } | ||
| 84 | +} | ||
| 85 | + | ||
| 86 | +/****************************************************************** | ||
| 87 | + | ||
| 88 | + 回复帧对比 | ||
| 89 | + 成功返回帧类型 无对比数据返回 JZ_ERROR_SYSTEM_FRAME_ERROR | ||
| 90 | + | ||
| 91 | +******************************************************************/ | ||
| 92 | +int JZsdk_6AFrameComparsion(char *getdata, int len) | ||
| 93 | +{ | ||
| 94 | + //1、判断帧头帧尾 | ||
| 95 | + if ( | ||
| 96 | + ( (getdata[0]!= 0x6A) && (getdata[1] != 0x6A) && (getdata[2]!=0x77) ) | ||
| 97 | + || ( (getdata[len -2]!= 0x00) && (getdata[ len -1] != 0x23) ) | ||
| 98 | + ) | ||
| 99 | + { | ||
| 100 | + printf("接受到的帧,没有帧头或者帧尾,退出JZsdk_6AFrameComparsion函数\n"); | ||
| 101 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + //一级功能码 | ||
| 105 | + switch (getdata[7]) | ||
| 106 | + { | ||
| 107 | + case 0x69: | ||
| 108 | + return Comparison_6AFRAME_FirstLevelCode_0x69(getdata); | ||
| 109 | + break; | ||
| 110 | + | ||
| 111 | + case 0x6F: | ||
| 112 | + return Comparison_6AFRAME_FirstLevelCode_0x6F(getdata); | ||
| 113 | + break; | ||
| 114 | + | ||
| 115 | + | ||
| 116 | + default: | ||
| 117 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 118 | + break; | ||
| 119 | + } | ||
| 120 | +} |
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file | ||
| 4 | + * | ||
| 5 | + * | ||
| 6 | + ********************************************************************* | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/ | ||
| 10 | +#ifndef JZSDK_FRAMECOMPARSION_6AFRAME_H | ||
| 11 | +#define JZSDK_FRAMECOMPARSION_6AFRAME_H | ||
| 12 | + | ||
| 13 | +/* Includes ------------------------------------------------------------------*/ | ||
| 14 | + | ||
| 15 | +#ifdef __cplusplus | ||
| 16 | +extern "C" { | ||
| 17 | +#endif | ||
| 18 | + | ||
| 19 | +/* Exported constants --------------------------------------------------------*/ | ||
| 20 | +/* 常亮定义*/ | ||
| 21 | + | ||
| 22 | +/* Exported types ------------------------------------------------------------*/ | ||
| 23 | + | ||
| 24 | +/* Exported functions --------------------------------------------------------*/ | ||
| 25 | +int JZsdk_6AFrameComparsion(char *getdata, int len); | ||
| 26 | + | ||
| 27 | + | ||
| 28 | +#ifdef __cplusplus | ||
| 29 | +} | ||
| 30 | +#endif | ||
| 31 | + | ||
| 32 | +#endif | ||
| 33 | + |
| 1 | +#include <stdio.h> | ||
| 2 | +#include "../JZsdk_Code/JZsdk_Code.h" | ||
| 3 | + | ||
| 4 | + | ||
| 5 | +//一级功能码是私有协议 | ||
| 6 | +static int Comparison_6BFRAME_FirstLevelCode_0x6F(char *getdata) | ||
| 7 | +{ | ||
| 8 | + //二级功能位 | ||
| 9 | + switch (getdata[8]) | ||
| 10 | + { | ||
| 11 | + //从设备名返回 | ||
| 12 | + case 0x50: | ||
| 13 | + return JZ_INSCODE_6BFRAME_CHECKSTATUS_SECONDARY_DEVICE_NAME; | ||
| 14 | + break; | ||
| 15 | + | ||
| 16 | + //查询云台联动返回 | ||
| 17 | + case 0x51: | ||
| 18 | + return JZ_INSCODE_6BFRAME_CHECKSTATUS_GIMBAL_LINKAGE; | ||
| 19 | + break; | ||
| 20 | + | ||
| 21 | + //查询特殊变量 | ||
| 22 | + case 0x54: | ||
| 23 | + return JZ_INSCODE_6BFRAME_CHECKSTATUS_SECONDARY_DEVICE_NAME; | ||
| 24 | + break; | ||
| 25 | + | ||
| 26 | + default: | ||
| 27 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 28 | + break; | ||
| 29 | + } | ||
| 30 | +} | ||
| 31 | + | ||
| 32 | +/****************************************************************** | ||
| 33 | + | ||
| 34 | + 回复帧对比 | ||
| 35 | + 成功返回帧类型 无对比数据返回 JZ_ERROR_SYSTEM_FRAME_ERROR | ||
| 36 | + | ||
| 37 | +******************************************************************/ | ||
| 38 | +int JZsdk_6BFrameComparsion(char *getdata, int len) | ||
| 39 | +{ | ||
| 40 | + //1、判断帧头帧尾 | ||
| 41 | + if ( | ||
| 42 | + ( (getdata[0]!= 0x6B) && (getdata[1] != 0x6B) && (getdata[2]!=0x77) ) | ||
| 43 | + || ( (getdata[len -2]!= 0x00) && (getdata[ len -1] != 0x23) ) | ||
| 44 | + ) | ||
| 45 | + { | ||
| 46 | + printf("接受到的帧,没有帧头或者帧尾,退出JZsdk_6BFrameComparsion函数\n"); | ||
| 47 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + //一级功能码 | ||
| 51 | + switch (getdata[7]) | ||
| 52 | + { | ||
| 53 | + case 0x6F: | ||
| 54 | + return Comparison_6BFRAME_FirstLevelCode_0x6F(getdata); | ||
| 55 | + break; | ||
| 56 | + | ||
| 57 | + | ||
| 58 | + default: | ||
| 59 | + return JZ_ERROR_SYSTEM_FRAME_ERROR; | ||
| 60 | + break; | ||
| 61 | + } | ||
| 62 | +} |
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file | ||
| 4 | + * | ||
| 5 | + * | ||
| 6 | + ********************************************************************* | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/ | ||
| 10 | + | ||
| 11 | + | ||
| 12 | +#ifndef JZSDK_FRAMECOMPARSION_6BFRAME_H | ||
| 13 | +#define JZSDK_FRAMECOMPARSION_6BFRAME_H | ||
| 14 | + | ||
| 15 | +/* Includes ------------------------------------------------------------------*/ | ||
| 16 | + | ||
| 17 | +#ifdef __cplusplus | ||
| 18 | +extern "C" { | ||
| 19 | +#endif | ||
| 20 | + | ||
| 21 | +/* Exported constants --------------------------------------------------------*/ | ||
| 22 | +/* 常亮定义*/ | ||
| 23 | + | ||
| 24 | +/* Exported types ------------------------------------------------------------*/ | ||
| 25 | + | ||
| 26 | +/* Exported functions --------------------------------------------------------*/ | ||
| 27 | +int JZsdk_6BFrameComparsion(char *getdata, int len); | ||
| 28 | + | ||
| 29 | + | ||
| 30 | +#ifdef __cplusplus | ||
| 31 | +} | ||
| 32 | +#endif | ||
| 33 | + | ||
| 34 | +#endif | ||
| 35 | + |
| 1 | +#include <stdio.h> | ||
| 2 | +#include <string.h> | ||
| 3 | +#include "../JZsdk_Code/JZsdk_Code.h" | ||
| 4 | + | ||
| 5 | +/****************************************************** | ||
| 6 | + | ||
| 7 | + 用于获取帧模板 | ||
| 8 | + | ||
| 9 | +/******************************************************/ | ||
| 10 | +int JZsdk_GetFrameTemplate(int InsCode ,char *str, int *str_len) | ||
| 11 | +{ | ||
| 12 | + //printf("JZsdk_GetFrameTemplate:获取0x%x帧模板\n",InsCode); //该打印可能会对 要求快速控制的地方变慢,请不要随意开启 | ||
| 13 | + switch (InsCode) | ||
| 14 | + { | ||
| 15 | +/******************************************************************************************************************************************************** | ||
| 16 | + * | ||
| 17 | + * 5A帧 | ||
| 18 | + * | ||
| 19 | +********************************************************************************************************************************************************/ | ||
| 20 | + case JZ_INSCODE_5AFRAME_ASKFORCONNECT: | ||
| 21 | + { | ||
| 22 | + char sendbuf[12] = {0x5A ,0x5A ,0x77 ,0x00 ,0x0C ,0x00 ,0x00 ,0x50 ,0x51 ,0x00 ,0x00 ,0x23}; | ||
| 23 | + memcpy(str, sendbuf, 12); | ||
| 24 | + *str_len = 12; | ||
| 25 | + } | ||
| 26 | + break; | ||
| 27 | + | ||
| 28 | + case JZ_INSCODE_5AFRAME_FRAME_POWER_STATUS: | ||
| 29 | + { | ||
| 30 | + unsigned char sendbuf[12] = {0x5A ,0x5A ,0x77 ,0x00 ,0x0C ,0x00 ,0x00 ,0x50 ,0x52 ,0x00 ,0x00 ,0x23}; | ||
| 31 | + memcpy(str, sendbuf, 12); | ||
| 32 | + *str_len = 12; | ||
| 33 | + } | ||
| 34 | + break; | ||
| 35 | + | ||
| 36 | + case JZ_INSCODE_5AFRAME_HEARTBEAT: | ||
| 37 | + { | ||
| 38 | + unsigned char sendbuf[12] = {0x5A ,0x5A ,0x77 ,0x00 ,0x0C ,0x00 ,0x00 ,0x50 ,0x53 ,0x00 ,0x00 ,0x23}; | ||
| 39 | + memcpy(str, sendbuf, 12); | ||
| 40 | + *str_len = 12; | ||
| 41 | + } | ||
| 42 | + break; | ||
| 43 | + | ||
| 44 | + case JZ_INSCODE_5AFRAME_TIMESTAMP: | ||
| 45 | + { | ||
| 46 | + unsigned char sendbuf[12] = {0x5A ,0x5A ,0x77 ,0x00 ,0x0C ,0x00 ,0x00 ,0x50 ,0x54 ,0x00 ,0x00 ,0x23}; | ||
| 47 | + memcpy(str, sendbuf, 12); | ||
| 48 | + *str_len = 12; | ||
| 49 | + } | ||
| 50 | + break; | ||
| 51 | + case JZ_INSCODE_5AFRAME_AUDIO_STOP: | ||
| 52 | + { | ||
| 53 | + char sendbuf[12] = {0x5A ,0x5A ,0x77 ,0x00 ,0x0C ,0x00 ,0x00 ,0x52 ,0x06 ,0x00 ,0x00 ,0x23}; | ||
| 54 | + memcpy(str, sendbuf, 12); | ||
| 55 | + *str_len = 12; | ||
| 56 | + } | ||
| 57 | + break; | ||
| 58 | + | ||
| 59 | + case JZ_INSCODE_5AFRAME_AUDIO_LASTSONG: | ||
| 60 | + { | ||
| 61 | + char sendbuf[12] = {0x5A ,0x5A ,0x77 ,0x00 ,0x0C ,0x00 ,0x00 ,0x52 ,0x07 ,0x00 ,0x00 ,0x23}; | ||
| 62 | + memcpy(str, sendbuf, 12); | ||
| 63 | + *str_len = 12; | ||
| 64 | + } | ||
| 65 | + break; | ||
| 66 | + | ||
| 67 | + case JZ_INSCODE_5AFRAME_AUDIO_NEXTSONG: | ||
| 68 | + { | ||
| 69 | + char sendbuf[12] = {0x5A ,0x5A ,0x77 ,0x00 ,0x0C ,0x00 ,0x00 ,0x52 ,0x08 ,0x00 ,0x00 ,0x23}; | ||
| 70 | + memcpy(str, sendbuf, 12); | ||
| 71 | + *str_len = 12; | ||
| 72 | + } | ||
| 73 | + break; | ||
| 74 | + | ||
| 75 | + case JZ_INSCODE_5AFRAME_VOLUME: | ||
| 76 | + { | ||
| 77 | + char sendbuf[12] = {0x5A ,0x5A ,0x77 ,0x00 ,0x0C ,0x00 ,0x00 ,0x52 ,0x10 ,0x00 ,0x00 ,0x23}; | ||
| 78 | + memcpy(str, sendbuf, 12); | ||
| 79 | + *str_len = 12; | ||
| 80 | + } | ||
| 81 | + break; | ||
| 82 | + | ||
| 83 | + case JZ_INSCODE_5AFRAME_PLAY_LOOP: | ||
| 84 | + { | ||
| 85 | + char sendbuf[12] = {0x5A ,0x5A ,0x77 ,0x00 ,0x0C ,0x00 ,0x00 ,0x55 ,0x00 ,0x00 ,0x00 ,0x23}; | ||
| 86 | + memcpy(str, sendbuf, 12); | ||
| 87 | + *str_len = 12; | ||
| 88 | + } | ||
| 89 | + break; | ||
| 90 | + | ||
| 91 | + case JZ_INSCODE_5AFRAME_TTS_SET_TONE: | ||
| 92 | + { | ||
| 93 | + char sendbuf[12] = {0x5A ,0x5A ,0x77 ,0x00 ,0x0C ,0x00 ,0x00 ,0x57 ,0x01 ,0x00 ,0x00 ,0x23}; | ||
| 94 | + memcpy(str, sendbuf, 12); | ||
| 95 | + *str_len = 12; | ||
| 96 | + } | ||
| 97 | + break; | ||
| 98 | + | ||
| 99 | + case JZ_INSCODE_5AFRAME_TTS_TRANS_START: | ||
| 100 | + { | ||
| 101 | + char sendbuf[12] = {0x5A ,0x5A ,0x77 ,0x00 ,0x0C ,0x00 ,0x00 ,0x57 ,0x03 ,0x00 ,0x00 ,0x23}; | ||
| 102 | + memcpy(str, sendbuf, 12); | ||
| 103 | + *str_len = 12; | ||
| 104 | + } | ||
| 105 | + break; | ||
| 106 | + | ||
| 107 | + case JZ_INSCODE_5AFRAME_TTS_TRANS_STOP: | ||
| 108 | + { | ||
| 109 | + char sendbuf[12] = {0x5A ,0x5A ,0x77 ,0x00 ,0x0C ,0x00 ,0x00 ,0x57 ,0x04 ,0x00 ,0x00 ,0x23}; | ||
| 110 | + memcpy(str, sendbuf, 12); | ||
| 111 | + *str_len = 12; | ||
| 112 | + } | ||
| 113 | + break; | ||
| 114 | + | ||
| 115 | + case JZ_INSCODE_5AFRAME_SEARCHLIGHT_SET_FREQUENCY: | ||
| 116 | + { | ||
| 117 | + char sendbuf[13] = {0x5A ,0x5A ,0x77 ,0x00 ,0x0D ,0x00 ,0x00 ,0x61 ,0x51 ,0x00 ,0x00 ,0x00 ,0x23}; | ||
| 118 | + memcpy(str, sendbuf, 13); | ||
| 119 | + *str_len = 13; | ||
| 120 | + } | ||
| 121 | + break; | ||
| 122 | + | ||
| 123 | + case JZ_INSCODE_5AFRAME_SEARCHLIGHT_CONTROL: | ||
| 124 | + { | ||
| 125 | + char sendbuf[13] = {0x5A ,0x5A ,0x77 ,0x00 ,0x0D ,0x00 ,0x00 ,0x62 ,0x51 ,0x00 ,0x00 ,0x00 ,0x23}; | ||
| 126 | + memcpy(str, sendbuf, 13); | ||
| 127 | + *str_len = 13; | ||
| 128 | + } | ||
| 129 | + break; | ||
| 130 | + | ||
| 131 | + case JZ_INSCODE_5AFRAME_SEARCHLIGHT_SET_LUMEN: | ||
| 132 | + { | ||
| 133 | + char sendbuf[13] = {0x5A ,0x5A ,0x77 ,0x00 ,0x0D ,0x00 ,0x00 ,0x63 ,0x51 ,0x00 ,0x00 ,0x00 ,0x23}; | ||
| 134 | + memcpy(str, sendbuf, 13); | ||
| 135 | + *str_len = 13; | ||
| 136 | + } | ||
| 137 | + break; | ||
| 138 | + | ||
| 139 | + case JZ_INSCODE_5AFRAME_GIMBAL_PITCH_CONTROL: | ||
| 140 | + { | ||
| 141 | + char sendbuf[14] = {0x5A ,0x5A ,0x77 ,0x00 ,0x0E ,0x00 ,0x00 ,0x64 ,0x51 ,0x00 ,0x00 ,0x00 ,0x00 ,0x23}; | ||
| 142 | + memcpy(str, sendbuf, 14); | ||
| 143 | + *str_len = 14; | ||
| 144 | + } | ||
| 145 | + break; | ||
| 146 | + | ||
| 147 | + case JZ_INSCODE_5AFRAME_GIMBAL_PITCH_FINETUNING_CONTROL: | ||
| 148 | + { | ||
| 149 | + char sendbuf[14] = {0x5A ,0x5A ,0x77 ,0x00 ,0x0E ,0x00 ,0x00 ,0x64 ,0x52 ,0x00 ,0x00 ,0x00 ,0x00 ,0x23}; | ||
| 150 | + memcpy(str, sendbuf, 14); | ||
| 151 | + *str_len = 14; | ||
| 152 | + } | ||
| 153 | + break; | ||
| 154 | + | ||
| 155 | + case JZ_INSCODE_5AFRAME_WARNINGLIGHT_CONTROL: | ||
| 156 | + { | ||
| 157 | + char sendbuf[13] = {0x5A ,0x5A ,0x77 ,0x00 ,0x0D ,0x00 ,0x00 ,0x66 ,0x51 ,0x00 ,0x00 ,0x00 ,0x23}; | ||
| 158 | + memcpy(str, sendbuf, 13); | ||
| 159 | + *str_len = 13; | ||
| 160 | + } | ||
| 161 | + break; | ||
| 162 | + | ||
| 163 | + case JZ_INSCODE_5AFRAME_WARNINGLIGHT_COLOUR: | ||
| 164 | + { | ||
| 165 | + char sendbuf[13] = {0x5A ,0x5A ,0x77 ,0x00 ,0x0D ,0x00 ,0x00 ,0x67 ,0x51 ,0x00 ,0x00 ,0x00 ,0x23}; | ||
| 166 | + memcpy(str, sendbuf, 13); | ||
| 167 | + *str_len = 13; | ||
| 168 | + } | ||
| 169 | + break; | ||
| 170 | + | ||
| 171 | + case JZ_INSCODE_5AFRAME_SEARCHLIGHT_MESSAGE_SUBSCRIPTION_CONTROL: | ||
| 172 | + { | ||
| 173 | + char sendbuf[13] = {0x5A ,0x5A ,0x77 ,0x00 ,0x0D ,0x00 ,0x00 ,0x68 ,0x51 ,0x00 ,0x00 ,0x00 ,0x23}; | ||
| 174 | + memcpy(str, sendbuf, 13); | ||
| 175 | + *str_len = 13; | ||
| 176 | + } | ||
| 177 | + break; | ||
| 178 | + | ||
| 179 | + case JZ_INSCODE_5AFRAME_CHECKSTATUS_SEARCHLIGHT_LIGHTATTRIBUTE: | ||
| 180 | + { | ||
| 181 | + char sendbuf[13] = {0x5A ,0x5A ,0x77 ,0x00 ,0x0D ,0x00 ,0x00 ,0x6F ,0x51 ,0x00 ,0x00 ,0x00 ,0x23}; | ||
| 182 | + memcpy(str, sendbuf, 13); | ||
| 183 | + *str_len = 13; | ||
| 184 | + } | ||
| 185 | + break; | ||
| 186 | + | ||
| 187 | + case JZ_INSCODE_5AFRAME_CHECKSTATUS_SEARCHLIGHT_TEMPERATURE: | ||
| 188 | + { | ||
| 189 | + char sendbuf[13] = {0x5A ,0x5A ,0x77 ,0x00 ,0x0D ,0x00 ,0x00 ,0x6F ,0x52 ,0x00 ,0x00 ,0x00 ,0x23}; | ||
| 190 | + memcpy(str, sendbuf, 13); | ||
| 191 | + *str_len = 13; | ||
| 192 | + } | ||
| 193 | + break; | ||
| 194 | + | ||
| 195 | + case JZ_INSCODE_5AFRAME_CHECKSTATUS_GIMBAL: | ||
| 196 | + { | ||
| 197 | + char sendbuf[13] = {0x5A ,0x5A ,0x77 ,0x00 ,0x0D ,0x00 ,0x00 ,0x6F ,0x54 ,0x00 ,0x00 ,0x00 ,0x23}; | ||
| 198 | + memcpy(str, sendbuf, 13); | ||
| 199 | + *str_len = 13; | ||
| 200 | + } | ||
| 201 | + break; | ||
| 202 | + | ||
| 203 | + case JZ_INSCODE_5AFRAME_CHECKSTATUS_WARNINGLIGHT_STATUS: | ||
| 204 | + { | ||
| 205 | + char sendbuf[13] = {0x5A ,0x5A ,0x77 ,0x00 ,0x0D ,0x00 ,0x00 ,0x6F ,0x55 ,0x00 ,0x00 ,0x00 ,0x23}; | ||
| 206 | + memcpy(str, sendbuf, 13); | ||
| 207 | + *str_len = 13; | ||
| 208 | + } | ||
| 209 | + break; | ||
| 210 | + | ||
| 211 | + case JZ_INSCODE_5AFRAME_CHECKSTATUS_WARNINGLIGHT_COLOR: | ||
| 212 | + { | ||
| 213 | + char sendbuf[13] = {0x5A ,0x5A ,0x77 ,0x00 ,0x0D ,0x00 ,0x00 ,0x6F ,0x56 ,0x00 ,0x00 ,0x00 ,0x23}; | ||
| 214 | + memcpy(str, sendbuf, 13); | ||
| 215 | + *str_len = 13; | ||
| 216 | + } | ||
| 217 | + break; | ||
| 218 | + | ||
| 219 | + case JZ_INSCODE_5AFRAME_CHECKSTATUS_SERIALNUMBER: | ||
| 220 | + { | ||
| 221 | + char sendbuf[13] = {0x5A ,0x5A ,0x77 ,0x00 ,0x0D ,0x00 ,0x00 ,0x6F ,0x57 ,0x00 ,0x00 ,0x00 ,0x23}; | ||
| 222 | + memcpy(str, sendbuf, 13); | ||
| 223 | + *str_len = 13; | ||
| 224 | + } | ||
| 225 | + break; | ||
| 226 | + | ||
| 227 | + case JZ_INSCODE_5AFRAME_CHECKSTATUS_GIMBAL_FINETUNING: | ||
| 228 | + { | ||
| 229 | + char sendbuf[13] = {0x5A ,0x5A ,0x77 ,0x00 ,0x0D ,0x00 ,0x00 ,0x6F ,0x58 ,0x00 ,0x00 ,0x00 ,0x23}; | ||
| 230 | + memcpy(str, sendbuf, 13); | ||
| 231 | + *str_len = 13; | ||
| 232 | + } | ||
| 233 | + break; | ||
| 234 | +/******************************************************************************************************************************************************** | ||
| 235 | + * | ||
| 236 | + * 5B帧 | ||
| 237 | + * | ||
| 238 | +********************************************************************************************************************************************************/ | ||
| 239 | + case JZ_INSCODE_5BFRAME_INITIATECONNECT: | ||
| 240 | + { | ||
| 241 | + char sendbuf[12] = {0x5B ,0x5B ,0x77 ,0x00 ,0x0c ,0x00 ,0x00 ,0x50 ,0x51 ,0x00 ,0x00 ,0x23}; | ||
| 242 | + memcpy(str, sendbuf, 12); | ||
| 243 | + *str_len = 12; | ||
| 244 | + } | ||
| 245 | + break; | ||
| 246 | + | ||
| 247 | + case JZ_INSCODE_5BFRAME_HEARTBEAT: | ||
| 248 | + { | ||
| 249 | + char sendbuf[12] = {0x5B ,0x5B ,0x77 ,0x00 ,0x0c ,0x00 ,0x00 ,0x50 ,0x53 ,0x00 ,0x00 ,0x23}; | ||
| 250 | + memcpy(str, sendbuf, 12); | ||
| 251 | + *str_len = 12; | ||
| 252 | + } | ||
| 253 | + break; | ||
| 254 | + | ||
| 255 | + case JZ_INSCODE_5BFRAME_ALL_VERSION: | ||
| 256 | + { | ||
| 257 | + unsigned char sendbuf[16] = {0x5B ,0x5B ,0x77 ,0x00 ,0x10 ,0x00 ,0x00 ,0x50 ,0x55, 0x00, 0x00, 0x00, 0x00 ,0x00 ,0x00 ,0x23}; | ||
| 258 | + memcpy(str, sendbuf, 16); | ||
| 259 | + *str_len = 16; | ||
| 260 | + } | ||
| 261 | + break; | ||
| 262 | + | ||
| 263 | + case JZ_INSCODE_5BFRAME_ALL_SERIAL_NUMBER: | ||
| 264 | + { | ||
| 265 | + unsigned char sendbuf[13] = {0x5B ,0x5B ,0x77 ,0x00 ,0x10 ,0x00 ,0x00 ,0x50 ,0x56, 0x00, 0x00 , 0x00 ,0x23}; | ||
| 266 | + memcpy(str, sendbuf, 13); | ||
| 267 | + *str_len = 13; | ||
| 268 | + } | ||
| 269 | + break; | ||
| 270 | + | ||
| 271 | + case JZ_INSCODE_5BFRAME_DEVICE_MESSAGE: | ||
| 272 | + { | ||
| 273 | + unsigned char sendbuf[12] = {0x5B ,0x5B ,0x77 ,0x00 ,0x0c ,0x00 ,0x00 ,0x50 ,0x58, 0x00 , 0x00 ,0x23}; | ||
| 274 | + memcpy(str, sendbuf, 12); | ||
| 275 | + *str_len = 12; | ||
| 276 | + } | ||
| 277 | + break; | ||
| 278 | + | ||
| 279 | + case JZ_INSCODE_5BFRAME_SUCESS: | ||
| 280 | + { | ||
| 281 | + char sendbuf[12] = {0x5B, 0x5B, 0x77, 0x00, 0x0c, 0x00, 0x00, 0x51, 0x01, 0x00, 0x00, 0x23}; | ||
| 282 | + memcpy(str, sendbuf, 12); | ||
| 283 | + *str_len = 12; | ||
| 284 | + } | ||
| 285 | + break; | ||
| 286 | + | ||
| 287 | + case JZ_INSCODE_5BFRAME_DEFEAT: | ||
| 288 | + { | ||
| 289 | + char sendbuf[12] = {0x5B, 0x5B, 0x77, 0x00, 0x0c, 0x00, 0x00, 0x51, 0xff, 0x00, 0x00, 0x23}; | ||
| 290 | + memcpy(str, sendbuf, 12); | ||
| 291 | + *str_len = 12; | ||
| 292 | + } | ||
| 293 | + break; | ||
| 294 | + | ||
| 295 | + | ||
| 296 | + case JZ_INSCODE_5BFRAME_AUDIO_PLAYSTATUS_END: | ||
| 297 | + { | ||
| 298 | + char sendbuf[12] = { 0x5b, 0x5b, 0x77, 0x00, 0x0c, 0x00, 0x00, 0x53, 0xff, 0x00, 0x00, 0x23}; | ||
| 299 | + memcpy(str, sendbuf, 12); | ||
| 300 | + *str_len = 12; | ||
| 301 | + } | ||
| 302 | + break; | ||
| 303 | + | ||
| 304 | + case JZ_INSCODE_5BFRAME_AUDIO_PLAYSTATUS: | ||
| 305 | + { | ||
| 306 | + char sendbuf[12] = { 0x5b, 0x5b, 0x77, 0x00, 0x0c, 0x00, 0x00, 0x53, 0x02, 0x00, 0x00, 0x23}; | ||
| 307 | + memcpy(str, sendbuf, 12); | ||
| 308 | + *str_len = 12; | ||
| 309 | + } | ||
| 310 | + break; | ||
| 311 | + | ||
| 312 | + case JZ_INSCODE_5BFRAME_AUDIO_PLAYFILENAME: | ||
| 313 | + { | ||
| 314 | + char sendbuf[12] = {0x5B, 0x5B, 0x77, 0x00, 0x0c, 0x00, 0x00, 0x53, 0x04, 0x00, 0x00, 0x23}; | ||
| 315 | + memcpy(str, sendbuf, 12); | ||
| 316 | + *str_len = 12; | ||
| 317 | + } | ||
| 318 | + break; | ||
| 319 | + | ||
| 320 | + case JZ_INSCODE_5BFRAME_VOLUME: | ||
| 321 | + { | ||
| 322 | + char sendbuf[12] = { 0x5b, 0x5b, 0x77, 0x00, 0x0c, 0x00, 0x00, 0x53, 0x01, 0x00, 0x00, 0x23}; | ||
| 323 | + memcpy(str, sendbuf, 12); | ||
| 324 | + *str_len = 12; | ||
| 325 | + } | ||
| 326 | + break; | ||
| 327 | + | ||
| 328 | + | ||
| 329 | + | ||
| 330 | + case JZ_INSCODE_5BFRAME_SORTWAREVERSION: | ||
| 331 | + { | ||
| 332 | + char sendbuf[15] = { 0x5b, 0x5b, 0x77, 0x00, 0x0f, 0x00, 0x00, 0x53, 0xf1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23}; | ||
| 333 | + memcpy(str, sendbuf, 15); | ||
| 334 | + *str_len = 15; | ||
| 335 | + } | ||
| 336 | + break; | ||
| 337 | + | ||
| 338 | + case JZ_INSCODE_5BFRAME_AUDIO_PLAYLOOPSTATUS: | ||
| 339 | + { | ||
| 340 | + char sendbuf[12] = { 0x5b, 0x5b, 0x77, 0x00, 0x0c, 0x00, 0x00, 0x53, 0x05, 0x00, 0x00, 0x23}; | ||
| 341 | + memcpy(str, sendbuf, 12); | ||
| 342 | + *str_len = 12; | ||
| 343 | + } | ||
| 344 | + break; | ||
| 345 | + | ||
| 346 | + case JZ_INSCODE_5BFRAME_TTS_TONE: | ||
| 347 | + { | ||
| 348 | + char sendbuf[12] = { 0x5b, 0x5b, 0x77, 0x00, 0x0c, 0x00, 0x00, 0x53, 0x06, 0x00, 0x00, 0x23}; | ||
| 349 | + memcpy(str, sendbuf, 12); | ||
| 350 | + *str_len = 12; | ||
| 351 | + } | ||
| 352 | + break; | ||
| 353 | + | ||
| 354 | + case JZ_INSCODE_5BFRAME_TTS_SPEED: | ||
| 355 | + { | ||
| 356 | + char sendbuf[12] = { 0x5b, 0x5b, 0x77, 0x00, 0x0c, 0x00, 0x00, 0x53, 0x07, 0x00, 0x00, 0x23}; | ||
| 357 | + memcpy(str, sendbuf, 12); | ||
| 358 | + *str_len = 12; | ||
| 359 | + } | ||
| 360 | + break; | ||
| 361 | + | ||
| 362 | + case JZ_INSCODE_5BFRAME_MUSICLIST_START: | ||
| 363 | + { | ||
| 364 | + char sendbuf[12] = { 0x5b, 0x5b, 0x77, 0x00, 0x0c, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, 0x23}; | ||
| 365 | + memcpy(str, sendbuf, 12); | ||
| 366 | + *str_len = 12; | ||
| 367 | + } | ||
| 368 | + break; | ||
| 369 | + | ||
| 370 | + case JZ_INSCODE_5BFRAME_MUSICLIST_TRANS: | ||
| 371 | + { | ||
| 372 | + char sendbuf[12] = {0x5B, 0x5B, 0x77, 0x00, 0x0c, 0x00, 0x00, 0x58, 0x02, 0x00, 0x00, 0x23}; | ||
| 373 | + memcpy(str, sendbuf, 12); | ||
| 374 | + *str_len = 12; | ||
| 375 | + } | ||
| 376 | + break; | ||
| 377 | + | ||
| 378 | + case JZ_INSCODE_5BFRAME_MUSICLIST_STOP: | ||
| 379 | + { | ||
| 380 | + char sendbuf[12] = { 0x5b, 0x5b, 0x77, 0x00, 0x0c, 0x00, 0x00, 0x58, 0xff, 0x00, 0x00, 0x23}; | ||
| 381 | + memcpy(str, sendbuf, 12); | ||
| 382 | + *str_len = 12; | ||
| 383 | + } | ||
| 384 | + break; | ||
| 385 | + | ||
| 386 | + case JZ_INSCODE_5BFRAME_OPUS_DECODE_STATUS: | ||
| 387 | + { | ||
| 388 | + char sendbuf[12] = { 0x5b, 0x5b, 0x77, 0x00, 0x0c, 0x00, 0x00, 0x59, 0xf2, 0x00, 0x00, 0x23}; | ||
| 389 | + memcpy(str, sendbuf, 12); | ||
| 390 | + *str_len = 12; | ||
| 391 | + } | ||
| 392 | + break; | ||
| 393 | + | ||
| 394 | + case JZ_INSCODE_5BFRAME_CHECKSTATUS_OUTPUTPOWER: | ||
| 395 | + { | ||
| 396 | + char sendbuf[12] = { 0x5b, 0x5b, 0x77, 0x00, 0x0C, 0x00, 0x00, 0x5A, 0x02, 0x00, 0x00, 0x23}; | ||
| 397 | + memcpy(str, sendbuf, 12); | ||
| 398 | + *str_len = 12; | ||
| 399 | + } | ||
| 400 | + break; | ||
| 401 | + | ||
| 402 | + case JZ_INSCODE_5BFRAME_CHECKSTATUS_SEARCHLIGHT_FREQUENCY: | ||
| 403 | + { | ||
| 404 | + char sendbuf[13] = { 0x5b, 0x5b, 0x77, 0x00, 0x0D, 0x00, 0x00, 0x61, 0x51, 0x00, 0x00, 0x00, 0x23}; | ||
| 405 | + memcpy(str, sendbuf, 13); | ||
| 406 | + *str_len = 13; | ||
| 407 | + } | ||
| 408 | + break; | ||
| 409 | + | ||
| 410 | + case JZ_INSCODE_5BFRAME_CHECKSTATUS_SEARCHLIGHT_MODE: | ||
| 411 | + { | ||
| 412 | + char sendbuf[13] = { 0x5b, 0x5b, 0x77, 0x00, 0x0D, 0x00, 0x00, 0x62, 0x51, 0x00, 0x00, 0x00, 0x23}; | ||
| 413 | + memcpy(str, sendbuf, 13); | ||
| 414 | + *str_len = 13; | ||
| 415 | + } | ||
| 416 | + break; | ||
| 417 | + | ||
| 418 | + case JZ_INSCODE_5BFRAME_CHECKSTATUS_SEARCHLIGHT_LUMEN: | ||
| 419 | + { | ||
| 420 | + char sendbuf[13] = { 0x5b, 0x5b, 0x77, 0x00, 0x0D, 0x00, 0x00, 0x63, 0x51, 0x00, 0x00, 0x00, 0x23}; | ||
| 421 | + memcpy(str, sendbuf, 13); | ||
| 422 | + *str_len = 13; | ||
| 423 | + } | ||
| 424 | + break; | ||
| 425 | + | ||
| 426 | + case JZ_INSCODE_5BFRAME_GIMBAL_PITCH: | ||
| 427 | + { | ||
| 428 | + char sendbuf[14] = { 0x5b, 0x5b, 0x77, 0x00, 0x0e, 0x00, 0x00, 0x64, 0x51, 0x00, 0x00, 0x00, 0x00, 0x23}; | ||
| 429 | + memcpy(str, sendbuf, 14); | ||
| 430 | + *str_len = 14; | ||
| 431 | + } | ||
| 432 | + break; | ||
| 433 | + | ||
| 434 | + case JZ_INSCODE_5BFRAME_GIMBAL_PITCH_FINETUNING: | ||
| 435 | + { | ||
| 436 | + char sendbuf[14] = { 0x5b, 0x5b, 0x77, 0x00, 0x0e, 0x00, 0x00, 0x64, 0x52, 0x00, 0x00, 0x00, 0x00, 0x23}; | ||
| 437 | + memcpy(str, sendbuf, 14); | ||
| 438 | + *str_len = 14; | ||
| 439 | + } | ||
| 440 | + break; | ||
| 441 | + | ||
| 442 | + case JZ_INSCODE_5BFRAME_GIMBAL_YAW: | ||
| 443 | + { | ||
| 444 | + char sendbuf[14] = { 0x5b, 0x5b, 0x77, 0x00, 0x0e, 0x00, 0x00, 0x65, 0x51, 0x00, 0x00, 0x00, 0x00, 0x23}; | ||
| 445 | + memcpy(str, sendbuf, 14); | ||
| 446 | + *str_len = 14; | ||
| 447 | + } | ||
| 448 | + break; | ||
| 449 | + | ||
| 450 | + case JZ_INSCODE_5BFRAME_CHECKSTATUS_WARNINGLIGHT_STATUS: | ||
| 451 | + { | ||
| 452 | + char sendbuf[13] = { 0x5b, 0x5b, 0x77, 0x00, 0x0D, 0x00, 0x00, 0x66, 0x51, 0x00, 0x00, 0x00, 0x23}; | ||
| 453 | + memcpy(str, sendbuf, 13); | ||
| 454 | + *str_len = 13; | ||
| 455 | + } | ||
| 456 | + break; | ||
| 457 | + | ||
| 458 | + case JZ_INSCODE_5BFRAME_CHECKSTATUS_WARNINGLIGHT_COLOR: | ||
| 459 | + { | ||
| 460 | + char sendbuf[13] = { 0x5b, 0x5b, 0x77, 0x00, 0x0D, 0x00, 0x00, 0x67, 0x51, 0x00, 0x00, 0x00, 0x23}; | ||
| 461 | + memcpy(str, sendbuf, 13); | ||
| 462 | + *str_len = 13; | ||
| 463 | + } | ||
| 464 | + break; | ||
| 465 | + | ||
| 466 | + case JZ_INSCODE_5BFRAME_CHECKSTATUS_SEARCHLIGHT_TEMPERATURE: | ||
| 467 | + { | ||
| 468 | + char sendbuf[13] = { 0x5b, 0x5b, 0x77, 0x00, 0x0D, 0x00, 0x00, 0x69, 0x51, 0x00, 0x00, 0x00, 0x23}; | ||
| 469 | + memcpy(str, sendbuf, 13); | ||
| 470 | + *str_len = 13; | ||
| 471 | + } | ||
| 472 | + break; | ||
| 473 | + | ||
| 474 | + case JZ_INSCODE_5BFRAME_CHECKSTATUS_SERIALNUMBER: | ||
| 475 | + { | ||
| 476 | + char sendbuf[13] = { 0x5b, 0x5b, 0x77, 0x00, 0x0D, 0x00, 0x00, 0x6F, 0x57, 0x00, 0x00, 0x00, 0x23}; | ||
| 477 | + memcpy(str, sendbuf, 13); | ||
| 478 | + *str_len = 13; | ||
| 479 | + } | ||
| 480 | + break; | ||
| 481 | + | ||
| 482 | + | ||
| 483 | + | ||
| 484 | +/******************************************************************************************************************************************************** | ||
| 485 | + * | ||
| 486 | + * 6A帧 | ||
| 487 | + * | ||
| 488 | +********************************************************************************************************************************************************/ | ||
| 489 | + | ||
| 490 | + case JZ_INSCODE_6AFRAME_SET_GIMBAL_MAXMIN_RANGE: | ||
| 491 | + { | ||
| 492 | + char sendbuf[13] = {0x6A ,0x6A ,0x77 ,0x00 ,0x0D ,0x00 ,0x00 ,0x69 ,0x52 ,0x00 ,0x00 ,0x00 ,0x23}; | ||
| 493 | + memcpy(str, sendbuf, 13); | ||
| 494 | + *str_len = 13; | ||
| 495 | + } | ||
| 496 | + break; | ||
| 497 | + | ||
| 498 | + case JZ_INSCODE_6AFRAME_GIMBAL_LINKAGE_CONTROL: | ||
| 499 | + { | ||
| 500 | + char sendbuf[13] = {0x6A ,0x6A ,0x77 ,0x00 ,0x0D ,0x00 ,0x00 ,0x69 ,0x56 ,0x00 ,0x00 ,0x00 ,0x23}; | ||
| 501 | + memcpy(str, sendbuf, 13); | ||
| 502 | + *str_len = 13; | ||
| 503 | + } | ||
| 504 | + break; | ||
| 505 | + | ||
| 506 | + case JZ_INSCODE_6AFRAME_CHECKSTATUS_SECONDARY_DEVICE_NAME: | ||
| 507 | + { | ||
| 508 | + char sendbuf[13] = {0x6A ,0x6A ,0x77 ,0x00 ,0x0D ,0x00 ,0x00 ,0x6F ,0x50 ,0x00 ,0x00 ,0x00 ,0x23}; | ||
| 509 | + memcpy(str, sendbuf, 13); | ||
| 510 | + *str_len = 13; | ||
| 511 | + } | ||
| 512 | + break; | ||
| 513 | + | ||
| 514 | + case JZ_INSCODE_6AFRAME_CHECKSTATUS_GIMBAL_LINKAGE: | ||
| 515 | + { | ||
| 516 | + char sendbuf[13] = {0x6A ,0x6A ,0x77 ,0x00 ,0x0D ,0x00 ,0x00 ,0x6F ,0x51 ,0x00 ,0x00 ,0x00 ,0x23}; | ||
| 517 | + memcpy(str, sendbuf, 13); | ||
| 518 | + *str_len = 13; | ||
| 519 | + } | ||
| 520 | + break; | ||
| 521 | + | ||
| 522 | + | ||
| 523 | +/******************************************************************************************************************************************************** | ||
| 524 | + * | ||
| 525 | + * 6B帧 | ||
| 526 | + * | ||
| 527 | +********************************************************************************************************************************************************/ | ||
| 528 | + case JZ_INSCODE_6BFRAME_CHECKSTATUS_SECONDARY_DEVICE_NAME: | ||
| 529 | + { | ||
| 530 | + char sendbuf[13] = {0x6B ,0x6B ,0x77 ,0x00 ,0x0D ,0x00 ,0x00 ,0x6F ,0x50 ,0x00 ,0x00 ,0x00 ,0x23}; | ||
| 531 | + memcpy(str, sendbuf, 13); | ||
| 532 | + *str_len = 13; | ||
| 533 | + } | ||
| 534 | + break; | ||
| 535 | + | ||
| 536 | + case JZ_INSCODE_6BFRAME_CHECKSTATUS_GIMBAL_LINKAGE: | ||
| 537 | + { | ||
| 538 | + char sendbuf[13] = {0x6B ,0x6B ,0x77 ,0x00 ,0x0D ,0x00 ,0x00 ,0x6F ,0x51 ,0x00 ,0x00 ,0x00 ,0x23}; | ||
| 539 | + memcpy(str, sendbuf, 13); | ||
| 540 | + *str_len = 13; | ||
| 541 | + } | ||
| 542 | + break; | ||
| 543 | + | ||
| 544 | + case JZ_INSCODE_6BFRAME_CHECK_SPECIAL_PARAMETERS: | ||
| 545 | + { | ||
| 546 | + char sendbuf[13] = {0x6B ,0x6B ,0x77 ,0x00 ,0x0D ,0x00 ,0x00 ,0x6F ,0x54 ,0x00 ,0x00 ,0x00 ,0x23}; | ||
| 547 | + memcpy(str, sendbuf, 13); | ||
| 548 | + *str_len = 13; | ||
| 549 | + } | ||
| 550 | + break; | ||
| 551 | + | ||
| 552 | + default: | ||
| 553 | + printf("JZsdk_GetFrameTemplate:没有对应的帧模板\n"); | ||
| 554 | + break; | ||
| 555 | + } | ||
| 556 | +} |
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file | ||
| 4 | + * | ||
| 5 | + * | ||
| 6 | + ********************************************************************* | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/ | ||
| 10 | +#ifndef JZSDK_GET_FRAME_TEMPLATE_H | ||
| 11 | +#define JZSDK_GET_FRAME_TEMPLATE_H | ||
| 12 | + | ||
| 13 | +/* Includes ------------------------------------------------------------------*/ | ||
| 14 | + | ||
| 15 | +#ifdef __cplusplus | ||
| 16 | +extern "C" { | ||
| 17 | +#endif | ||
| 18 | + | ||
| 19 | +/* Exported constants --------------------------------------------------------*/ | ||
| 20 | +/* 常亮定义*/ | ||
| 21 | + | ||
| 22 | +/* Exported types ------------------------------------------------------------*/ | ||
| 23 | + | ||
| 24 | +/* Exported functions --------------------------------------------------------*/ | ||
| 25 | +int JZsdk_GetFrameTemplate(int InsCode ,char *str, int *str_len); | ||
| 26 | + | ||
| 27 | + | ||
| 28 | +#ifdef __cplusplus | ||
| 29 | +} | ||
| 30 | +#endif | ||
| 31 | + | ||
| 32 | +#endif |
| 1 | +/* 头文件 ------------------------------------------------------------------*/ | ||
| 2 | +#include <stdio.h> | ||
| 3 | +#include <stdlib.h> | ||
| 4 | +#include <string.h> | ||
| 5 | +#include <stdarg.h> | ||
| 6 | +#include <stdio.h> | ||
| 7 | + | ||
| 8 | +#include "JZsdk_Logger.h" | ||
| 9 | +#include <time.h> | ||
| 10 | +#include "JZsdkLib.h" | ||
| 11 | +#include <pthread.h> | ||
| 12 | +#include <sys/time.h> | ||
| 13 | +#include <sys/resource.h> | ||
| 14 | +#include <unistd.h> | ||
| 15 | +#include <sys/types.h> | ||
| 16 | + | ||
| 17 | + | ||
| 18 | +#define LOG_GRADE JZSDK_LOGGER_CONSOLE_LOG_LEVEL_INFO | ||
| 19 | + | ||
| 20 | +// 定义全局互斥锁 | ||
| 21 | +static pthread_mutex_t LogWriteMutex = PTHREAD_MUTEX_INITIALIZER; | ||
| 22 | + | ||
| 23 | +/* 全局变量 ------------------------------------------------------------------*/ | ||
| 24 | +static struct timeval g_start_time; | ||
| 25 | +static FILE *logFile = NULL; | ||
| 26 | +static char LogFileName[JZSDK_FILENAME_SIZE]; | ||
| 27 | +static int Logger_init_flag = JZ_FLAGCODE_OFF; | ||
| 28 | + | ||
| 29 | +/* 函数声明 ------------------------------------------------------------------*/ | ||
| 30 | + | ||
| 31 | +long long get_total_ram() { | ||
| 32 | + FILE *file; | ||
| 33 | + char line[128]; | ||
| 34 | + long long total_ram = 0; | ||
| 35 | + | ||
| 36 | + file = fopen("/proc/meminfo", "r"); | ||
| 37 | + if (!file) { | ||
| 38 | + perror("Error opening /proc/meminfo"); | ||
| 39 | + return 0; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + while (fgets(line, sizeof(line), file)) { | ||
| 43 | + if (strncmp(line, "MemTotal:", 9) == 0) { | ||
| 44 | + sscanf(line, "MemTotal: %lld kB", &total_ram); | ||
| 45 | + break; | ||
| 46 | + } | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + fclose(file); | ||
| 50 | + return total_ram; | ||
| 51 | +} | ||
| 52 | + | ||
| 53 | +long long get_current_rss(pid_t pid) { | ||
| 54 | + FILE *file; | ||
| 55 | + char line[128]; | ||
| 56 | + long long vmrss = 0; | ||
| 57 | + | ||
| 58 | + char path[64]; | ||
| 59 | + snprintf(path, sizeof(path), "/proc/%d/status", pid); | ||
| 60 | + | ||
| 61 | + file = fopen(path, "r"); | ||
| 62 | + if (!file) { | ||
| 63 | + perror("Error opening /proc/[pid]/status"); | ||
| 64 | + return 0; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + while (fgets(line, sizeof(line), file)) { | ||
| 68 | + if (strncmp(line, "VmRSS:", 6) == 0) { | ||
| 69 | + sscanf(line, "VmRSS: %lld kB", &vmrss); | ||
| 70 | + break; | ||
| 71 | + } | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + fclose(file); | ||
| 75 | + return vmrss; | ||
| 76 | +} | ||
| 77 | + | ||
| 78 | +static void *MonitorTask(void *arg) | ||
| 79 | +{ | ||
| 80 | + //获取程序的pid号 | ||
| 81 | + pid_t pid = getpid(); // 获取当前进程的 PID | ||
| 82 | + long long total_ram; //最大ram内存 | ||
| 83 | + long long current_rss; //RSS内存 | ||
| 84 | + double memory_percentage; //内存百分比 | ||
| 85 | + | ||
| 86 | + // 获取系统总 RAM | ||
| 87 | + total_ram = get_total_ram(); | ||
| 88 | + | ||
| 89 | + while (1) | ||
| 90 | + { | ||
| 91 | + printf("当前进程pid号%d\n",pid); | ||
| 92 | + | ||
| 93 | + // 获取当前进程的内存使用量 | ||
| 94 | + current_rss = get_current_rss(pid); | ||
| 95 | + | ||
| 96 | + // 计算内存百分比 | ||
| 97 | + if (total_ram > 0) | ||
| 98 | + { | ||
| 99 | + memory_percentage = (double)current_rss / total_ram * 100; | ||
| 100 | + } else { | ||
| 101 | + memory_percentage = 0; | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + // 打印结果 | ||
| 105 | + printf("Program current memory usage: %lld KB\n", current_rss); | ||
| 106 | + JZSDK_LOG_INFO("Monitor:(%.2f%% of total RAM)", memory_percentage); | ||
| 107 | + | ||
| 108 | + delayS(10); | ||
| 109 | + } | ||
| 110 | +} | ||
| 111 | + | ||
| 112 | + | ||
| 113 | + | ||
| 114 | +static int Log_Monitor() | ||
| 115 | +{ | ||
| 116 | + pthread_t work_mode_task; | ||
| 117 | + pthread_attr_t task_attribute; //线程属性 | ||
| 118 | + pthread_attr_init(&task_attribute); //初始化线程属性 | ||
| 119 | + pthread_attr_setdetachstate(&task_attribute, PTHREAD_CREATE_DETACHED); //设置线程属性 | ||
| 120 | + int timer = pthread_create(&work_mode_task,&task_attribute,MonitorTask,NULL); //线程 | ||
| 121 | + if(timer != 0) | ||
| 122 | + { | ||
| 123 | + printf("创建计时线程失败!\n"); | ||
| 124 | + } | ||
| 125 | +} | ||
| 126 | + | ||
| 127 | +T_JZsdkReturnCode createJZLOGFolder() | ||
| 128 | +{ | ||
| 129 | + const char *path = "/root/sdcard/JZLOG"; | ||
| 130 | + | ||
| 131 | + // 使用系统命令检测路径是否存在 | ||
| 132 | + if(JZsdk_check_directory_exists_posix(path) == JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS) | ||
| 133 | + { | ||
| 134 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 135 | + } | ||
| 136 | + else | ||
| 137 | + { | ||
| 138 | + JZsdk_Osal_Mkdir(path); | ||
| 139 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 140 | + } | ||
| 141 | +} | ||
| 142 | + | ||
| 143 | +int ReadLogNumFromFile() | ||
| 144 | +{ | ||
| 145 | + const char *path = "/root/sdcard/JZLOG/thelast"; | ||
| 146 | + int logNum = 0; | ||
| 147 | + | ||
| 148 | + FILE *file = fopen(path, "r"); | ||
| 149 | + if (file == NULL) | ||
| 150 | + { | ||
| 151 | + // 如果文件不存在,则创建并设置LogNum为0 | ||
| 152 | + file = fopen(path, "w"); | ||
| 153 | + fprintf(file, "%d", logNum); | ||
| 154 | + } | ||
| 155 | + else | ||
| 156 | + { | ||
| 157 | + // 从文件中读取LogNum,并自增1 | ||
| 158 | + fscanf(file, "%d", &logNum); | ||
| 159 | + logNum++; | ||
| 160 | + fclose(file); | ||
| 161 | + | ||
| 162 | + // 将新的LogNum写回文件中 | ||
| 163 | + file = fopen(path, "w"); | ||
| 164 | + fprintf(file, "%d", logNum); | ||
| 165 | + } | ||
| 166 | + fclose(file); | ||
| 167 | + | ||
| 168 | + return logNum; | ||
| 169 | +} | ||
| 170 | + | ||
| 171 | +T_JZsdkReturnCode JZsdk_LoggerInit() | ||
| 172 | +{ | ||
| 173 | + //1、记录启动时间 | ||
| 174 | + gettimeofday(&g_start_time, 0); | ||
| 175 | + | ||
| 176 | + //2、检查是否存在log文件,不在则创建 | ||
| 177 | + createJZLOGFolder(); | ||
| 178 | + | ||
| 179 | + //3、获取本地log个数 | ||
| 180 | + int LogNum = ReadLogNumFromFile(); | ||
| 181 | + | ||
| 182 | + //4、获取本地时间,拼接出log文件名 | ||
| 183 | + time_t current_time; | ||
| 184 | + struct tm *info; | ||
| 185 | + char timeString[80]; | ||
| 186 | + time(¤t_time); | ||
| 187 | + info = localtime(¤t_time); | ||
| 188 | + strftime(timeString, sizeof(timeString), "%Y%m%d_%H-%M-%S", info); | ||
| 189 | + snprintf(LogFileName, sizeof(LogFileName), "/root/sdcard/JZLOG/%d_%s", LogNum, timeString); | ||
| 190 | + | ||
| 191 | + printf("LogFileName:%s\n",LogFileName); | ||
| 192 | + | ||
| 193 | + // 在主函数或初始化阶段初始化互斥锁 | ||
| 194 | + pthread_mutex_init(&LogWriteMutex, NULL); | ||
| 195 | + | ||
| 196 | + //5、打开记录文件 | ||
| 197 | + logFile = fopen(LogFileName, "w"); | ||
| 198 | + if (logFile == NULL) { | ||
| 199 | + // 文件打开失败,输出错误消息 | ||
| 200 | + printf("Failed to open file: %s", LogFileName); | ||
| 201 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 202 | + } | ||
| 203 | + | ||
| 204 | + //6、写入开始时间 | ||
| 205 | + char logMessage[256]; | ||
| 206 | + snprintf(logMessage,256,"LOG_FILE:%s\n",LogFileName); | ||
| 207 | + fprintf(logFile, "%s", logMessage); | ||
| 208 | + | ||
| 209 | + //dfclose(logFile); | ||
| 210 | + | ||
| 211 | + //打开初始化完成的flag | ||
| 212 | + Logger_init_flag = JZ_FLAGCODE_ON; | ||
| 213 | + | ||
| 214 | + //设立监控 | ||
| 215 | + Log_Monitor(); | ||
| 216 | + | ||
| 217 | + JZSDK_LOG_INFO("log初始化完成"); | ||
| 218 | +} | ||
| 219 | + | ||
| 220 | +T_JZsdkReturnCode JZsdk_LoggerDeInit() | ||
| 221 | +{ | ||
| 222 | + if (logFile != NULL) | ||
| 223 | + { | ||
| 224 | + fclose(logFile); | ||
| 225 | + } | ||
| 226 | +} | ||
| 227 | + | ||
| 228 | +T_JZsdkReturnCode writeToLogFile(const char *data) | ||
| 229 | +{ | ||
| 230 | + // 加锁 | ||
| 231 | + pthread_mutex_lock(&LogWriteMutex); | ||
| 232 | + | ||
| 233 | + //logFile = fopen(LogFileName, "a"); // 使用"a"模式打开文件,以在末尾追加数据 | ||
| 234 | + | ||
| 235 | + // if (logFile == NULL) { | ||
| 236 | + // // 文件打开失败,输出错误消息 | ||
| 237 | + // printf("Failed to open file: %s", LogFileName); | ||
| 238 | + // pthread_mutex_unlock(&LogWriteMutex); | ||
| 239 | + | ||
| 240 | + // return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 241 | + // } | ||
| 242 | + | ||
| 243 | + if (logFile == NULL) | ||
| 244 | + { | ||
| 245 | + printf("Failed to open file: %s", LogFileName); | ||
| 246 | + pthread_mutex_unlock(&LogWriteMutex); | ||
| 247 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 248 | + } | ||
| 249 | + | ||
| 250 | + fprintf(logFile, "%s", data); // 写入新的数据 | ||
| 251 | + | ||
| 252 | + //fclose(logFile); | ||
| 253 | + | ||
| 254 | + // 解锁 | ||
| 255 | + pthread_mutex_unlock(&LogWriteMutex); | ||
| 256 | + | ||
| 257 | +} | ||
| 258 | + | ||
| 259 | +T_JZsdkReturnCode HexToLogFile(const char *data) | ||
| 260 | +{ | ||
| 261 | + // 加锁 | ||
| 262 | + pthread_mutex_lock(&LogWriteMutex); | ||
| 263 | + | ||
| 264 | + // logFile = fopen(LogFileName, "a"); // 使用"a"模式打开文件,以在末尾追加数据 | ||
| 265 | + | ||
| 266 | + // if (logFile == NULL) { | ||
| 267 | + // // 文件打开失败,输出错误消息 | ||
| 268 | + // printf("Failed to open file: %s", LogFileName); | ||
| 269 | + // pthread_mutex_unlock(&LogWriteMutex); | ||
| 270 | + | ||
| 271 | + // return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 272 | + // } | ||
| 273 | + | ||
| 274 | + if (logFile == NULL) | ||
| 275 | + { | ||
| 276 | + printf("Failed to open file: %s", LogFileName); | ||
| 277 | + pthread_mutex_unlock(&LogWriteMutex); | ||
| 278 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 279 | + } | ||
| 280 | + | ||
| 281 | + fprintf(logFile, "%x ", data[0]); // 写入新的数据 | ||
| 282 | + | ||
| 283 | + //fclose(logFile); | ||
| 284 | + | ||
| 285 | + // 解锁 | ||
| 286 | + pthread_mutex_unlock(&LogWriteMutex); | ||
| 287 | +} | ||
| 288 | + | ||
| 289 | + | ||
| 290 | +void JZsdk_UserLogOutput(E_JZsdkConsoleLogLevel level, const char *fmt, ...) | ||
| 291 | +{ | ||
| 292 | + // 将日志级别转换为相应的字符串 | ||
| 293 | + const char *JZSDK_LOGGER_CONSOLE_LOG_LEVEL = ""; | ||
| 294 | + switch (level) { | ||
| 295 | + case JZSDK_LOGGER_CONSOLE_LOG_LEVEL_DEBUG: | ||
| 296 | + JZSDK_LOGGER_CONSOLE_LOG_LEVEL = "DEBUG"; | ||
| 297 | + break; | ||
| 298 | + case JZSDK_LOGGER_CONSOLE_LOG_LEVEL_INFO: | ||
| 299 | + JZSDK_LOGGER_CONSOLE_LOG_LEVEL = "INFO"; | ||
| 300 | + break; | ||
| 301 | + case JZSDK_LOGGER_CONSOLE_LOG_LEVEL_WARN: | ||
| 302 | + JZSDK_LOGGER_CONSOLE_LOG_LEVEL = "WARNING"; | ||
| 303 | + break; | ||
| 304 | + case JZSDK_LOGGER_CONSOLE_LOG_LEVEL_ERROR: | ||
| 305 | + JZSDK_LOGGER_CONSOLE_LOG_LEVEL = "ERROR"; | ||
| 306 | + break; | ||
| 307 | + default: | ||
| 308 | + break; | ||
| 309 | + } | ||
| 310 | + // 使用可变参数处理传入的格式化字符串和可变参数 | ||
| 311 | + va_list args; | ||
| 312 | + va_start(args, fmt); | ||
| 313 | + | ||
| 314 | + //格式化日志消息 | ||
| 315 | + char logMessage[512]; | ||
| 316 | + memset(logMessage, 0, sizeof(logMessage)); | ||
| 317 | + vsnprintf(logMessage, sizeof(logMessage), fmt, args); | ||
| 318 | + | ||
| 319 | + va_end(args); | ||
| 320 | + | ||
| 321 | + struct timeval current_time; | ||
| 322 | + gettimeofday(¤t_time, 0); | ||
| 323 | + | ||
| 324 | + long seconds = current_time.tv_sec - g_start_time.tv_sec; | ||
| 325 | + long microseconds = current_time.tv_usec - g_start_time.tv_usec; | ||
| 326 | + double elapsed = seconds + microseconds*1e-6; | ||
| 327 | + | ||
| 328 | + // 执行具体的日志输出操作 | ||
| 329 | + char finalLogMessage[612]; | ||
| 330 | + memset(finalLogMessage, 0, sizeof(finalLogMessage)); | ||
| 331 | + snprintf(finalLogMessage, 612, "[%s][%.4f]%s\n", JZSDK_LOGGER_CONSOLE_LOG_LEVEL, elapsed, logMessage); | ||
| 332 | + | ||
| 333 | + printf("%s",finalLogMessage); | ||
| 334 | + | ||
| 335 | + //写入日志 | ||
| 336 | + if (Logger_init_flag == JZ_FLAGCODE_ON && level <= LOG_GRADE) | ||
| 337 | + { | ||
| 338 | + writeToLogFile(finalLogMessage); | ||
| 339 | + } | ||
| 340 | +} | ||
| 341 | + | ||
| 342 | + | ||
| 343 | + | ||
| 344 | +void JZsdk_User_OutputHex(E_JZsdkConsoleLogLevel level, const char *fmt, ...) | ||
| 345 | +{ | ||
| 346 | + // 将日志级别转换为相应的字符串 | ||
| 347 | + const char *JZSDK_LOGGER_CONSOLE_LOG_LEVEL = ""; | ||
| 348 | + switch (level) { | ||
| 349 | + case JZSDK_LOGGER_CONSOLE_LOG_LEVEL_DEBUG: | ||
| 350 | + JZSDK_LOGGER_CONSOLE_LOG_LEVEL = "DEBUG"; | ||
| 351 | + break; | ||
| 352 | + case JZSDK_LOGGER_CONSOLE_LOG_LEVEL_INFO: | ||
| 353 | + JZSDK_LOGGER_CONSOLE_LOG_LEVEL = "INFO"; | ||
| 354 | + break; | ||
| 355 | + case JZSDK_LOGGER_CONSOLE_LOG_LEVEL_WARN: | ||
| 356 | + JZSDK_LOGGER_CONSOLE_LOG_LEVEL = "WARNING"; | ||
| 357 | + break; | ||
| 358 | + case JZSDK_LOGGER_CONSOLE_LOG_LEVEL_ERROR: | ||
| 359 | + JZSDK_LOGGER_CONSOLE_LOG_LEVEL = "ERROR"; | ||
| 360 | + break; | ||
| 361 | + default: | ||
| 362 | + break; | ||
| 363 | + } | ||
| 364 | + // 使用可变参数处理传入的格式化字符串和可变参数 | ||
| 365 | + va_list args; | ||
| 366 | + va_start(args, fmt); | ||
| 367 | + | ||
| 368 | + //格式化日志消息 | ||
| 369 | + char logMessage[10]; | ||
| 370 | + memset(logMessage, 0, sizeof(logMessage)); | ||
| 371 | + vsnprintf(logMessage, sizeof(logMessage), fmt, args); | ||
| 372 | + | ||
| 373 | + va_end(args); | ||
| 374 | + | ||
| 375 | + // 执行具体的日志输出操作 | ||
| 376 | + char finalLogMessage[512]; | ||
| 377 | + memset(finalLogMessage, 0, sizeof(finalLogMessage)); | ||
| 378 | + snprintf(finalLogMessage, 612, "%s", logMessage); | ||
| 379 | + | ||
| 380 | + | ||
| 381 | + printf("%x ",finalLogMessage[0]); | ||
| 382 | + | ||
| 383 | + //写入日志 | ||
| 384 | + HexToLogFile(finalLogMessage); | ||
| 385 | +} |
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file JZsdk_Logger.h | ||
| 4 | + * 用于给h150s logger显示文件 | ||
| 5 | + * | ||
| 6 | + ********************************************************************* | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/ | ||
| 10 | +#ifndef JZSDK_LOGGER_H | ||
| 11 | +#define JZSDK_LOGGER_H | ||
| 12 | + | ||
| 13 | +/* Includes ------------------------------------------------------------------*/ | ||
| 14 | +#include "JZsdk_Base/JZsdk_Code/JZsdk_Code.h" | ||
| 15 | + | ||
| 16 | +#ifdef __cplusplus | ||
| 17 | +extern "C" { | ||
| 18 | +#endif | ||
| 19 | + | ||
| 20 | +/* Exported constants --------------------------------------------------------*/ | ||
| 21 | +/* 常亮定义*/ | ||
| 22 | + | ||
| 23 | + | ||
| 24 | +typedef enum { | ||
| 25 | + JZSDK_LOGGER_CONSOLE_LOG_LEVEL_ERROR = 0, /*!< Logger console error level. The method and level of the console are | ||
| 26 | + associated with each other. If the level of the registered console | ||
| 27 | + method is lower than this level, the level interface will not be | ||
| 28 | + printed successfully. */ | ||
| 29 | + JZSDK_LOGGER_CONSOLE_LOG_LEVEL_WARN = 1, /*!< Logger console warning level.The method and level of the console are | ||
| 30 | + associated with each other. If the level of the registered console | ||
| 31 | + method is lower than this level, the level interface will not be | ||
| 32 | + printed successfully. */ | ||
| 33 | + JZSDK_LOGGER_CONSOLE_LOG_LEVEL_INFO = 2, /*!< Logger console info level. The method and level of the console are | ||
| 34 | + associated with each other. If the level of the registered console | ||
| 35 | + method is lower than this level, the level interface will not be | ||
| 36 | + printed successfully. */ | ||
| 37 | + JZSDK_LOGGER_CONSOLE_LOG_LEVEL_DEBUG = 3, /*!< Logger console debug level. The method and level of the console are | ||
| 38 | + associated with each other. If the level of the registered console | ||
| 39 | + method is lower than this level, the level interface will not be | ||
| 40 | + printed successfully. */ | ||
| 41 | +} E_JZsdkConsoleLogLevel; | ||
| 42 | +/* Exported types ------------------------------------------------------------*/ | ||
| 43 | + | ||
| 44 | + | ||
| 45 | +/* Exported functions --------------------------------------------------------*/ | ||
| 46 | +void JZsdk_UserLogOutput(E_JZsdkConsoleLogLevel level, const char *fmt, ...); | ||
| 47 | +T_JZsdkReturnCode JZsdk_LoggerInit(); | ||
| 48 | +void JZsdk_User_OutputHex(E_JZsdkConsoleLogLevel level, const char *fmt, ...); | ||
| 49 | + | ||
| 50 | +/* Exported constants --------------------------------------------------------*/ | ||
| 51 | +#define JZSDK_LOG_DEBUG(fmt, ...) \ | ||
| 52 | + JZsdk_UserLogOutput(JZSDK_LOGGER_CONSOLE_LOG_LEVEL_DEBUG, "[%s:%d) " fmt, __FUNCTION__, __LINE__ , ##__VA_ARGS__) | ||
| 53 | +#define JZSDK_LOG_INFO(fmt, ...) \ | ||
| 54 | + JZsdk_UserLogOutput(JZSDK_LOGGER_CONSOLE_LOG_LEVEL_INFO, "[%s:%d) " fmt, __FUNCTION__, __LINE__ , ##__VA_ARGS__) | ||
| 55 | +#define JZSDK_LOG_WARN(fmt, ...) \ | ||
| 56 | + JZsdk_UserLogOutput(JZSDK_LOGGER_CONSOLE_LOG_LEVEL_WARN, "[%s:%d) " fmt, __FUNCTION__, __LINE__ , ##__VA_ARGS__) | ||
| 57 | +#define JZSDK_LOG_ERROR(fmt, ...) \ | ||
| 58 | + JZsdk_UserLogOutput(JZSDK_LOGGER_CONSOLE_LOG_LEVEL_ERROR, "[%s:%d) " fmt, __FUNCTION__, __LINE__ , ##__VA_ARGS__) | ||
| 59 | +#define JZSDK_LOG_OUTPUTHEX(fmt, ...) \ | ||
| 60 | + JZsdk_User_OutputHex(JZSDK_LOGGER_CONSOLE_LOG_LEVEL_INFO, "" fmt , ##__VA_ARGS__) | ||
| 61 | + | ||
| 62 | + | ||
| 63 | +#ifdef __cplusplus | ||
| 64 | +} | ||
| 65 | +#endif | ||
| 66 | + | ||
| 67 | +#endif | ||
| 68 | +/************************ (C) COPYRIGHT JZSDK Innovations *******END OF FILE******/ |
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file JZsdk_FS_Standards.h | ||
| 4 | + * 用于规范文件名及长度 | ||
| 5 | + * | ||
| 6 | + ********************************************************************* | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/ | ||
| 10 | +#ifndef JZSDK_FS_STANDARDS_H | ||
| 11 | +#define JZSDK_FS_STANDARDS_H | ||
| 12 | + | ||
| 13 | +#define JZSDK_FILENAME_SIZE (128) //文件名最大长度128 | ||
| 14 | +#define JZSDK_CMD_SIZE (256) //cmd指令最大长度 | ||
| 15 | + | ||
| 16 | + | ||
| 17 | +#endif |
| 1 | +#include <stdio.h> | ||
| 2 | +#include "JZsdk_FileSystm.h" | ||
| 3 | +#include <stdlib.h> | ||
| 4 | +#include <stdbool.h> | ||
| 5 | +#include <string.h> | ||
| 6 | +#include <unistd.h> | ||
| 7 | +#include <sys/types.h> | ||
| 8 | +#include <sys/stat.h> | ||
| 9 | +#include "JZsdkLib.h" | ||
| 10 | +#include <dirent.h> | ||
| 11 | +#include <errno.h> | ||
| 12 | + | ||
| 13 | +/* | ||
| 14 | +* 用于运行指令 | ||
| 15 | +* | ||
| 16 | +*/ | ||
| 17 | +T_JZsdkReturnCode JZsdk_RunSystemCmd(char *systemCmd) | ||
| 18 | +{ | ||
| 19 | + //FILE *fp; | ||
| 20 | + | ||
| 21 | + //printf("JZsdk_RunSystemCmd:%s\n",systemCmd); | ||
| 22 | + | ||
| 23 | + // fp = popen(systemCmd, "r"); | ||
| 24 | + // if (fp == NULL) { | ||
| 25 | + // return -1; | ||
| 26 | + // } | ||
| 27 | + | ||
| 28 | + int status = system(systemCmd); | ||
| 29 | + if (status == -1 || WIFEXITED(status) == false) { | ||
| 30 | + printf("Call %s error, status = %d\n", systemCmd, status); | ||
| 31 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + if (WEXITSTATUS(status) == 0) { | ||
| 35 | + JZSDK_LOG_DEBUG("指令执行成功%s\n",systemCmd); | ||
| 36 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 37 | + } | ||
| 38 | + else { | ||
| 39 | + JZSDK_LOG_ERROR("指令执行失败Exit status is = %d", WEXITSTATUS(status)); | ||
| 40 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 41 | + } | ||
| 42 | + //pclose(fp); | ||
| 43 | + | ||
| 44 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 45 | +} | ||
| 46 | + | ||
| 47 | +/* | ||
| 48 | + | ||
| 49 | + 运行命令 并读取返回值 | ||
| 50 | + | ||
| 51 | +*/ | ||
| 52 | +// FILE* JZsdk_RunSystemCmd_ReturnFilePointer(char *systemCmd) | ||
| 53 | +// { | ||
| 54 | +// FILE *fp; | ||
| 55 | + | ||
| 56 | +// fp = popen(systemCmd, "r"); | ||
| 57 | + | ||
| 58 | +// pclose(fp); | ||
| 59 | + | ||
| 60 | +// return fp; | ||
| 61 | +// } | ||
| 62 | + | ||
| 63 | + | ||
| 64 | +/********************************** | ||
| 65 | + * | ||
| 66 | + * 创建一个文件夹 | ||
| 67 | + 函数名:JZsdk_check_file_exists | ||
| 68 | + 参数:文件路径 | ||
| 69 | + 返回值:JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS表示文件存在, | ||
| 70 | + JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE表示文件不存在 | ||
| 71 | + * *******************************/ | ||
| 72 | +T_JZsdkReturnCode JZsdk_Osal_Mkdir(const char *filePath) | ||
| 73 | +{ | ||
| 74 | + int32_t ret; | ||
| 75 | + | ||
| 76 | + if (filePath == NULL) { | ||
| 77 | + return JZ_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + ret = mkdir(filePath, S_IRWXU); | ||
| 81 | + if (ret < 0) { | ||
| 82 | + switch (errno) { | ||
| 83 | + case EACCES: | ||
| 84 | + JZSDK_LOG_ERROR("Permission denied\n"); | ||
| 85 | + break; | ||
| 86 | + case EEXIST: | ||
| 87 | + JZSDK_LOG_ERROR("Directory already exists\n"); | ||
| 88 | + break; | ||
| 89 | + case ENOENT: | ||
| 90 | + JZSDK_LOG_ERROR("A component of the path does not exist or is a dangling symbolic link\n"); | ||
| 91 | + break; | ||
| 92 | + case ENOMEM: | ||
| 93 | + JZSDK_LOG_ERROR("Not enough memory\n"); | ||
| 94 | + break; | ||
| 95 | + case ENOTDIR: | ||
| 96 | + JZSDK_LOG_ERROR("A component of the path prefix is not a directory\n"); | ||
| 97 | + break; | ||
| 98 | + case EROFS: | ||
| 99 | + JZSDK_LOG_ERROR("The named file resides on a read-only file system\n"); | ||
| 100 | + break; | ||
| 101 | + default: | ||
| 102 | + JZSDK_LOG_ERROR("Unknown error %d\n", errno); | ||
| 103 | + } | ||
| 104 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 108 | +} | ||
| 109 | + | ||
| 110 | + | ||
| 111 | +/********************************** | ||
| 112 | + * | ||
| 113 | + * 文件是否存在判断函数 | ||
| 114 | +* 判断文件是否存在 | ||
| 115 | + 函数名:JZsdk_check_file_exists | ||
| 116 | + 参数:文件路径 | ||
| 117 | + 返回值:JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS表示文件存在, | ||
| 118 | + JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE表示文件不存在 | ||
| 119 | + * *******************************/ | ||
| 120 | +T_JZsdkReturnCode JZsdk_check_file_exists(const char* file_path) | ||
| 121 | +{ | ||
| 122 | + if (access(file_path, F_OK) == 0) | ||
| 123 | + { | ||
| 124 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 125 | + } | ||
| 126 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 127 | +} | ||
| 128 | + | ||
| 129 | +/********************************** | ||
| 130 | + * | ||
| 131 | + * 文件夹是否存在判断函数 | ||
| 132 | +* 判断文件是否存在 | ||
| 133 | + 函数名:JZsdk_check_file_exists | ||
| 134 | + 参数:文件路径 | ||
| 135 | + 返回值:JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS表示文件存在, | ||
| 136 | + JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE表示文件不存在 | ||
| 137 | + * *******************************/ | ||
| 138 | +T_JZsdkReturnCode JZsdk_check_directory_exists_posix(const char* directory_path) | ||
| 139 | +{ | ||
| 140 | + struct stat st; | ||
| 141 | + if (stat(directory_path, &st) == 0 && S_ISDIR(st.st_mode)) | ||
| 142 | + { | ||
| 143 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 144 | + } | ||
| 145 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 146 | +} | ||
| 147 | + | ||
| 148 | +/********************************** | ||
| 149 | + * | ||
| 150 | + * 创建新的文件 | ||
| 151 | + 函数名:JZsdk_check_file_exists | ||
| 152 | + 参数:文件路径 | ||
| 153 | + 返回值:JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS表示文件存在, | ||
| 154 | + JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE表示文件不存在 | ||
| 155 | + * *******************************/ | ||
| 156 | +T_JZsdkReturnCode JZsdk_create_file(const char* file_path) | ||
| 157 | +{ | ||
| 158 | + FILE* file = fopen(file_path, "w"); | ||
| 159 | + if (file != NULL) | ||
| 160 | + { | ||
| 161 | + fclose(file); | ||
| 162 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 163 | + } | ||
| 164 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 165 | +} | ||
| 166 | + | ||
| 167 | +/********************************** | ||
| 168 | + * | ||
| 169 | + * 删除文件 | ||
| 170 | + 函数名:JZsdk_delete_file | ||
| 171 | + 参数:文件路径 | ||
| 172 | + 返回值:JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS表示文件已经不存在 | ||
| 173 | + JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE表示文件仍然存在 | ||
| 174 | + * *******************************/ | ||
| 175 | +T_JZsdkReturnCode JZsdk_delete_file(const char* file_path) | ||
| 176 | +{ | ||
| 177 | + int remove_result = remove(file_path); | ||
| 178 | + if (remove_result != 0) { | ||
| 179 | + // 删除失败,返回错误 | ||
| 180 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 181 | + } | ||
| 182 | + | ||
| 183 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; // 删除成功 | ||
| 184 | +} | ||
| 185 | + | ||
| 186 | +/********************************** | ||
| 187 | + * | ||
| 188 | + * 复制文件 | ||
| 189 | + 函数名:JZsdk_copy_file | ||
| 190 | + 参数:文件路径 | ||
| 191 | + 返回值:JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS表示文件已经不存在 | ||
| 192 | + JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE表示文件仍然存在 | ||
| 193 | + * *******************************/ | ||
| 194 | +T_JZsdkReturnCode JZsdk_copy_file_byC(const char* source_path, const char* dest_path) | ||
| 195 | +{ | ||
| 196 | + FILE *source_file = fopen(source_path, "rb"); // 以二进制读模式打开源文件 | ||
| 197 | + if (source_file == NULL) { | ||
| 198 | + // 无法打开源文件 | ||
| 199 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 200 | + } | ||
| 201 | + | ||
| 202 | + FILE *dest_file = fopen(dest_path, "wb"); // 以二进制写模式打开目标文件 | ||
| 203 | + if (dest_file == NULL) { | ||
| 204 | + // 无法创建或打开目标文件 | ||
| 205 | + fclose(source_file); // 关闭已打开的源文件 | ||
| 206 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 207 | + } | ||
| 208 | + | ||
| 209 | + // 分配缓冲区用于读取和写入文件 | ||
| 210 | + char buffer[4096]; // 缓冲区大小可以根据需要调整 | ||
| 211 | + size_t bytes_read; | ||
| 212 | + | ||
| 213 | + // 复制文件内容 | ||
| 214 | + while ((bytes_read = fread(buffer, 1, sizeof(buffer), source_file)) > 0) { | ||
| 215 | + if (fwrite(buffer, 1, bytes_read, dest_file) != bytes_read) { | ||
| 216 | + // 写入目标文件失败 | ||
| 217 | + fclose(source_file); // 关闭已打开的源文件 | ||
| 218 | + fclose(dest_file); // 关闭已打开的目标文件 | ||
| 219 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 220 | + } | ||
| 221 | + } | ||
| 222 | + | ||
| 223 | + // 关闭文件 | ||
| 224 | + fclose(source_file); | ||
| 225 | + fclose(dest_file); | ||
| 226 | + | ||
| 227 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; // 复制成功 | ||
| 228 | +} | ||
| 229 | + | ||
| 230 | + | ||
| 231 | +// 删除指定路径下的所有文件(不包括子文件夹) | ||
| 232 | +// 注意:这个函数不会删除子文件夹,如果您需要删除子文件夹,请添加递归逻辑。 | ||
| 233 | +T_JZsdkReturnCode JZsdk_delete_files_in_directory(const char* directory_path) | ||
| 234 | +{ | ||
| 235 | + DIR* dir; | ||
| 236 | + struct dirent* ent; | ||
| 237 | + char file_path[1024]; // 假设文件路径不会超过这个长度 | ||
| 238 | + T_JZsdkReturnCode ret = JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 239 | + | ||
| 240 | + if ((dir = opendir(directory_path)) != NULL) { | ||
| 241 | + while ((ent = readdir(dir)) != NULL) { | ||
| 242 | + // 跳过目录条目 '.' 和 '..' | ||
| 243 | + if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) { | ||
| 244 | + continue; | ||
| 245 | + } | ||
| 246 | + | ||
| 247 | + // 构建文件的完整路径 | ||
| 248 | + snprintf(file_path, sizeof(file_path), "%s/%s", directory_path, ent->d_name); | ||
| 249 | + | ||
| 250 | + // 如果是文件,则删除它 | ||
| 251 | + if (remove(file_path) != 0) { | ||
| 252 | + perror("remove"); // 打印错误信息 | ||
| 253 | + ret = JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 254 | + break; // 或者您可以继续并尝试删除其他文件 | ||
| 255 | + } | ||
| 256 | + } | ||
| 257 | + closedir(dir); | ||
| 258 | + } else { | ||
| 259 | + perror("opendir"); // 打印错误信息 | ||
| 260 | + ret = JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 261 | + } | ||
| 262 | + | ||
| 263 | + return ret; | ||
| 264 | +} | ||
| 265 | + | ||
| 266 | +/********************************** | ||
| 267 | + * | ||
| 268 | + * 创建硬链接的函数 | ||
| 269 | + 函数名:JZsdk_create_hardlink | ||
| 270 | + 参数:文件路径 链接路径 | ||
| 271 | + 返回值:JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS表示成功 | ||
| 272 | + JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE表示失败 | ||
| 273 | + * *******************************/ | ||
| 274 | +T_JZsdkReturnCode JZsdk_create_hardlink(const char* target_path, const char* link_path) | ||
| 275 | +{ | ||
| 276 | + int result = link(target_path, link_path); | ||
| 277 | + if (result == -1) { | ||
| 278 | + JZSDK_LOG_ERROR("hardlink"); // 打印错误信息 | ||
| 279 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; // 返回错误代码 | ||
| 280 | + } | ||
| 281 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; // 返回成功代码 | ||
| 282 | +} | ||
| 283 | + | ||
| 284 | + | ||
| 285 | +/********************************** | ||
| 286 | + * | ||
| 287 | + * 字符串后缀对比 | ||
| 288 | + 函数名:JZsdk_strings_suffix_comparison | ||
| 289 | + 参数:字符串,后缀名 | ||
| 290 | + 返回值: | ||
| 291 | + JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS表示后缀正确 | ||
| 292 | + JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE表示后缀错误,或是长度不对 | ||
| 293 | + * *******************************/ | ||
| 294 | +T_JZsdkReturnCode JZsdk_strings_suffix_comparison_onlyStr(const unsigned char* Strings, const unsigned char *suffix) | ||
| 295 | +{ | ||
| 296 | + if (Strings == NULL || suffix == NULL) | ||
| 297 | + { | ||
| 298 | + JZSDK_LOG_ERROR("字符串后缀对比输入错误"); | ||
| 299 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; // 如果指针为NULL,返回失败 | ||
| 300 | + } | ||
| 301 | + | ||
| 302 | + int suffix_len = (int)strlen((const char*)suffix); // 强制转换为const char*以确保兼容性 | ||
| 303 | + int Strings_len = (int)strlen((const char*)Strings); // 强制转换为const char*以确保兼容性 | ||
| 304 | + | ||
| 305 | + if (Strings_len <= suffix_len) | ||
| 306 | + { | ||
| 307 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; // 如果字符串长度小于后缀长度,返回失败 | ||
| 308 | + } | ||
| 309 | + | ||
| 310 | + // 确保不会越界,并且字符串是以空字符结尾的 | ||
| 311 | + if (memcmp(Strings + Strings_len - suffix_len, suffix, suffix_len) == 0) | ||
| 312 | + { | ||
| 313 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 314 | + } | ||
| 315 | + else | ||
| 316 | + { | ||
| 317 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 318 | + } | ||
| 319 | +} | ||
| 320 | + | ||
| 321 | + | ||
| 322 | +/********************************** | ||
| 323 | + * | ||
| 324 | + * 字符串后缀对比 | ||
| 325 | + 函数名:JZsdk_strings_suffix_comparison | ||
| 326 | + 参数:字符串, 字符串长度,后缀名 | ||
| 327 | + 返回值: | ||
| 328 | + JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS表示后缀正确 | ||
| 329 | + JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE表示后缀错误,或是长度不对 | ||
| 330 | + * *******************************/ | ||
| 331 | +T_JZsdkReturnCode JZsdk_strings_suffix_comparison_withLen(const unsigned char* Strings, int Strings_len, const unsigned char *suffix) | ||
| 332 | +{ | ||
| 333 | + if (Strings == NULL || suffix == NULL) | ||
| 334 | + { | ||
| 335 | + JZSDK_LOG_ERROR("字符串后缀对比输入错误"); | ||
| 336 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; // 如果指针为NULL,返回失败 | ||
| 337 | + } | ||
| 338 | + | ||
| 339 | + int suffix_len = (int)strlen((const char*)suffix); // 强制转换为const char*以确保兼容性 | ||
| 340 | + | ||
| 341 | + if (Strings_len <= suffix_len) | ||
| 342 | + { | ||
| 343 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; // 如果字符串长度小于后缀长度,返回失败 | ||
| 344 | + } | ||
| 345 | + | ||
| 346 | + // 确保不会越界,并且字符串是以空字符结尾的 | ||
| 347 | + if (memcmp(Strings + Strings_len - suffix_len, suffix, suffix_len) == 0) | ||
| 348 | + { | ||
| 349 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 350 | + } | ||
| 351 | + else | ||
| 352 | + { | ||
| 353 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 354 | + } | ||
| 355 | +} | ||
| 356 | + | ||
| 357 | + | ||
| 358 | + | ||
| 359 | +/********************************** | ||
| 360 | + * | ||
| 361 | + * 读取文件大小 | ||
| 362 | + 函数名:JZsdk_Fs_ReadFileSize | ||
| 363 | + 参数:字符串, 字符串长度,后缀名 | ||
| 364 | + 返回值: | ||
| 365 | + JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS读取正确 | ||
| 366 | + JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE读取错误 | ||
| 367 | + * *******************************/ | ||
| 368 | +T_JZsdkReturnCode JZsdk_Fs_ReadFileSize(const unsigned char* FilePath, int *FileSize) | ||
| 369 | +{ | ||
| 370 | + struct stat statbuf; | ||
| 371 | + int result = stat(FilePath, &statbuf); | ||
| 372 | + | ||
| 373 | + if (result == -1) { | ||
| 374 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 375 | + } | ||
| 376 | + | ||
| 377 | + *FileSize = statbuf.st_size; | ||
| 378 | + | ||
| 379 | + if (*FileSize == 0) | ||
| 380 | + { | ||
| 381 | + // 文件大小为0,可能是空文件 | ||
| 382 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 383 | + } | ||
| 384 | + | ||
| 385 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 386 | +} |
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file JZsdk_FileSystem.h | ||
| 4 | + * 用于文件系统操作 | ||
| 5 | + * | ||
| 6 | + ********************************************************************* | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/ | ||
| 10 | +#ifndef JZSDK_FILESYSTEM_H | ||
| 11 | +#define JZSDK_FILESYSTEM_H | ||
| 12 | + | ||
| 13 | +/* Includes ------------------------------------------------------------------*/ | ||
| 14 | +#include "../JZsdk_Code/JZsdk_Code.h" | ||
| 15 | +#include "./JZsdk_FS_Standards.h" | ||
| 16 | + | ||
| 17 | +#ifdef __cplusplus | ||
| 18 | +extern "C" { | ||
| 19 | +#endif | ||
| 20 | + | ||
| 21 | +/* Exported constants --------------------------------------------------------*/ | ||
| 22 | +/* 常亮定义*/ | ||
| 23 | + | ||
| 24 | +/* Exported types ------------------------------------------------------------*/ | ||
| 25 | + | ||
| 26 | + | ||
| 27 | +/* Exported functions --------------------------------------------------------*/ | ||
| 28 | +T_JZsdkReturnCode JZsdk_RunSystemCmd(char *systemCmd); | ||
| 29 | +T_JZsdkReturnCode JZsdk_check_file_exists(const char* file_path) ; | ||
| 30 | +T_JZsdkReturnCode JZsdk_create_file(const char* file_path) ; | ||
| 31 | +T_JZsdkReturnCode JZsdk_delete_file(const char* file_path) ; | ||
| 32 | +T_JZsdkReturnCode JZsdk_strings_suffix_comparison_onlyStr(const unsigned char* Strings, const unsigned char *suffix) ; | ||
| 33 | +T_JZsdkReturnCode JZsdk_strings_suffix_comparison_withLen(const unsigned char* Strings, int Strings_len, const unsigned char *suffix) ; | ||
| 34 | +T_JZsdkReturnCode JZsdk_Osal_Mkdir(const char *filePath); | ||
| 35 | +T_JZsdkReturnCode JZsdk_delete_files_in_directory(const char* directory_path); | ||
| 36 | +T_JZsdkReturnCode JZsdk_create_hardlink(const char* target_path, const char* link_path); | ||
| 37 | +T_JZsdkReturnCode JZsdk_check_directory_exists_posix(const char* directory_path); | ||
| 38 | +T_JZsdkReturnCode JZsdk_Fs_ReadFileSize(const unsigned char* FilePath, int *FileSize); | ||
| 39 | +T_JZsdkReturnCode JZsdk_copy_file_byC(const char* source_path, const char* dest_path); | ||
| 40 | + | ||
| 41 | +#ifdef __cplusplus | ||
| 42 | +} | ||
| 43 | +#endif | ||
| 44 | + | ||
| 45 | +#endif | ||
| 46 | +/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/ |
| 1 | +#include <stdio.h> | ||
| 2 | +#include <stdlib.h> | ||
| 3 | +#include <stdbool.h> | ||
| 4 | +#include <string.h> | ||
| 5 | + | ||
| 6 | +#include "JZsdkLib.h" | ||
| 7 | + | ||
| 8 | + | ||
| 9 | + | ||
| 10 | +/********************************** | ||
| 11 | + * | ||
| 12 | + * 注册内存 | ||
| 13 | + 函数名:JZsdk_Malloc | ||
| 14 | + 参数:指针,注册大小 | ||
| 15 | + 返回值: | ||
| 16 | + JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS正确 | ||
| 17 | + JZ_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER 错误 | ||
| 18 | + * *******************************/ | ||
| 19 | +T_JZsdkReturnCode JZsdk_Malloc(void **ptr, unsigned int size) | ||
| 20 | +{ | ||
| 21 | + if (size == 0) | ||
| 22 | + { | ||
| 23 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + *ptr = malloc(size); | ||
| 27 | + | ||
| 28 | + if (*ptr == NULL) | ||
| 29 | + { | ||
| 30 | + return JZ_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER; | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 34 | +} | ||
| 35 | + | ||
| 36 | + | ||
| 37 | +/********************************** | ||
| 38 | + * | ||
| 39 | + * 释放内存 | ||
| 40 | + 函数名:JZsdk_Free | ||
| 41 | + 参数:指针,注册大小 | ||
| 42 | + 返回值: | ||
| 43 | + JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS正确 | ||
| 44 | + JZ_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER 错误 | ||
| 45 | + * *******************************/ | ||
| 46 | +T_JZsdkReturnCode JZsdk_Free(void *ptr) | ||
| 47 | +{ | ||
| 48 | + if (ptr == NULL) | ||
| 49 | + { | ||
| 50 | + return JZ_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + free(ptr); | ||
| 54 | + ptr = NULL; | ||
| 55 | + | ||
| 56 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 57 | +} |
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file JZsdk_MemoryAdapter.h | ||
| 4 | + * 用于内存管理 | ||
| 5 | + * | ||
| 6 | + ********************************************************************* | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/ | ||
| 10 | +#ifndef JZSDK_MEMORY_ADAPTER_H | ||
| 11 | +#define JZSDK_MEMORY_ADAPTER_H | ||
| 12 | + | ||
| 13 | +/* Includes ------------------------------------------------------------------*/ | ||
| 14 | +#include "../JZsdk_Code/JZsdk_Code.h" | ||
| 15 | + | ||
| 16 | +#ifdef __cplusplus | ||
| 17 | +extern "C" { | ||
| 18 | +#endif | ||
| 19 | + | ||
| 20 | +/* Exported constants --------------------------------------------------------*/ | ||
| 21 | +/* 常亮定义*/ | ||
| 22 | + | ||
| 23 | +/* Exported types ------------------------------------------------------------*/ | ||
| 24 | + | ||
| 25 | + | ||
| 26 | +/* Exported functions --------------------------------------------------------*/ | ||
| 27 | +T_JZsdkReturnCode JZsdk_Malloc(void **ptr, unsigned int size); | ||
| 28 | +T_JZsdkReturnCode JZsdk_Free(void *ptr); | ||
| 29 | + | ||
| 30 | +#ifdef __cplusplus | ||
| 31 | +} | ||
| 32 | +#endif | ||
| 33 | + | ||
| 34 | +#endif | ||
| 35 | +/************************ (C) COPYRIGHT DJI Innovations *******END OF FILE******/ |
JZsdk_Common/JZsdk_Base/Lwrb/lwrb.c
0 → 100644
| 1 | +/** | ||
| 2 | + * \file lwrb.c | ||
| 3 | + * \brief Lightweight ring buffer | ||
| 4 | + */ | ||
| 5 | + | ||
| 6 | +/* | ||
| 7 | + * Copyright (c) 2024 Tilen MAJERLE | ||
| 8 | + * | ||
| 9 | + * Permission is hereby granted, free of charge, to any person | ||
| 10 | + * obtaining a copy of this software and associated documentation | ||
| 11 | + * files (the "Software"), to deal in the Software without restriction, | ||
| 12 | + * including without limitation the rights to use, copy, modify, merge, | ||
| 13 | + * publish, distribute, sublicense, and/or sell copies of the Software, | ||
| 14 | + * and to permit persons to whom the Software is furnished to do so, | ||
| 15 | + * subject to the following conditions: | ||
| 16 | + * | ||
| 17 | + * The above copyright notice and this permission notice shall be | ||
| 18 | + * included in all copies or substantial portions of the Software. | ||
| 19 | + * | ||
| 20 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
| 21 | + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
| 22 | + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE | ||
| 23 | + * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
| 24 | + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
| 25 | + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
| 26 | + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
| 27 | + * OTHER DEALINGS IN THE SOFTWARE. | ||
| 28 | + * | ||
| 29 | + * This file is part of LwRB - Lightweight ring buffer library. | ||
| 30 | + * | ||
| 31 | + * Author: Tilen MAJERLE <tilen@majerle.eu> | ||
| 32 | + * Version: v3.1.0 | ||
| 33 | + */ | ||
| 34 | +#include "./lwrb.h" | ||
| 35 | + | ||
| 36 | +/* Memory set and copy functions */ | ||
| 37 | +#define BUF_MEMSET memset | ||
| 38 | +#define BUF_MEMCPY memcpy | ||
| 39 | + | ||
| 40 | +#define BUF_IS_VALID(b) ((b) != NULL && (b)->buff != NULL && (b)->size > 0) | ||
| 41 | +#define BUF_MIN(x, y) ((x) < (y) ? (x) : (y)) | ||
| 42 | +#define BUF_MAX(x, y) ((x) > (y) ? (x) : (y)) | ||
| 43 | +#define BUF_SEND_EVT(b, type, bp) \ | ||
| 44 | + do { \ | ||
| 45 | + if ((b)->evt_fn != NULL) { \ | ||
| 46 | + (b)->evt_fn((void*)(b), (type), (bp)); \ | ||
| 47 | + } \ | ||
| 48 | + } while (0) | ||
| 49 | + | ||
| 50 | +/* Optional atomic opeartions */ | ||
| 51 | +#ifdef LWRB_DISABLE_ATOMIC | ||
| 52 | +#define LWRB_INIT(var, val) (var) = (val) | ||
| 53 | +#define LWRB_LOAD(var, type) (var) | ||
| 54 | +#define LWRB_STORE(var, val, type) (var) = (val) | ||
| 55 | +#else | ||
| 56 | +#define LWRB_INIT(var, val) atomic_init(&(var), (val)) | ||
| 57 | +#define LWRB_LOAD(var, type) atomic_load_explicit(&(var), (type)) | ||
| 58 | +#define LWRB_STORE(var, val, type) atomic_store_explicit(&(var), (val), (type)) | ||
| 59 | +#endif | ||
| 60 | + | ||
| 61 | +/** | ||
| 62 | + * \brief Initialize buffer handle to default values with size and buffer data array | ||
| 63 | + * \param[in] buff: Ring buffer instance | ||
| 64 | + * \param[in] buffdata: Pointer to memory to use as buffer data | ||
| 65 | + * \param[in] size: Size of `buffdata` in units of bytes | ||
| 66 | + * Maximum number of bytes buffer can hold is `size - 1` | ||
| 67 | + * \return `1` on success, `0` otherwise | ||
| 68 | + * * \brief 初始化环形缓冲区 | ||
| 69 | + * | ||
| 70 | + * @param buff 环形缓冲区指针 | ||
| 71 | + * @param buffdata 缓冲区数据内存 | ||
| 72 | + * @param size 缓冲区大小 | ||
| 73 | + * @return 初始化成功返回非零值,失败返回0 | ||
| 74 | + */ | ||
| 75 | +uint8_t | ||
| 76 | +lwrb_init(lwrb_t* buff, void* buffdata, lwrb_sz_t size) { | ||
| 77 | + if (buff == NULL || buffdata == NULL || size == 0) { | ||
| 78 | + return 0; | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + buff->evt_fn = NULL; | ||
| 82 | + buff->size = size; | ||
| 83 | + buff->buff = buffdata; | ||
| 84 | + LWRB_INIT(buff->w, 0); | ||
| 85 | + LWRB_INIT(buff->r, 0); | ||
| 86 | + return 1; | ||
| 87 | +} | ||
| 88 | + | ||
| 89 | +/** | ||
| 90 | + * \brief Check if buff is initialized and ready to use | ||
| 91 | + * \param[in] buff: Ring buffer instance | ||
| 92 | + * \return `1` if ready, `0` otherwise | ||
| 93 | + */ | ||
| 94 | +uint8_t | ||
| 95 | +lwrb_is_ready(lwrb_t* buff) { | ||
| 96 | + return BUF_IS_VALID(buff); | ||
| 97 | +} | ||
| 98 | + | ||
| 99 | +/** | ||
| 100 | + * \brief Free buffer memory | ||
| 101 | + * \note Since implementation does not use dynamic allocation, | ||
| 102 | + * it just sets buffer handle to `NULL` | ||
| 103 | + * \param[in] buff: Ring buffer instance | ||
| 104 | + */ | ||
| 105 | +void | ||
| 106 | +lwrb_free(lwrb_t* buff) { | ||
| 107 | + if (BUF_IS_VALID(buff)) { | ||
| 108 | + buff->buff = NULL; | ||
| 109 | + } | ||
| 110 | +} | ||
| 111 | + | ||
| 112 | +/** | ||
| 113 | + * \brief Set event function callback for different buffer operations | ||
| 114 | + * \param[in] buff: Ring buffer instance | ||
| 115 | + * \param[in] evt_fn: Callback function | ||
| 116 | + */ | ||
| 117 | +void | ||
| 118 | +lwrb_set_evt_fn(lwrb_t* buff, lwrb_evt_fn evt_fn) { | ||
| 119 | + if (BUF_IS_VALID(buff)) { | ||
| 120 | + buff->evt_fn = evt_fn; | ||
| 121 | + } | ||
| 122 | +} | ||
| 123 | + | ||
| 124 | +/** | ||
| 125 | + * \brief Set custom buffer argument, that can be retrieved in the event function | ||
| 126 | + * \param[in] buff: Ring buffer instance | ||
| 127 | + * \param[in] arg: Custom user argument | ||
| 128 | + */ | ||
| 129 | +void | ||
| 130 | +lwrb_set_arg(lwrb_t* buff, void* arg) { | ||
| 131 | + if (BUF_IS_VALID(buff)) { | ||
| 132 | + buff->arg = arg; | ||
| 133 | + } | ||
| 134 | +} | ||
| 135 | + | ||
| 136 | +/** | ||
| 137 | + * \brief Get custom buffer argument, previously set with \ref lwrb_set_arg | ||
| 138 | + * \param[in] buff: Ring buffer instance | ||
| 139 | + * \return User argument, previously set with \ref lwrb_set_arg | ||
| 140 | + */ | ||
| 141 | +void* | ||
| 142 | +lwrb_get_arg(lwrb_t* buff) { | ||
| 143 | + return buff != NULL ? buff->arg : NULL; | ||
| 144 | +} | ||
| 145 | + | ||
| 146 | +/** | ||
| 147 | + * \brief Write data to buffer. | ||
| 148 | + * Copies data from `data` array to buffer and marks buffer as full for maximum `btw` number of bytes | ||
| 149 | + * | ||
| 150 | + * \param[in] buff: Ring buffer instance | ||
| 151 | + * \param[in] data: Pointer to data to write into buffer | ||
| 152 | + * \param[in] btw: Number of bytes to write | ||
| 153 | + * \return Number of bytes written to buffer. | ||
| 154 | + * When returned value is less than `btw`, there was no enough memory available | ||
| 155 | + * to copy full data array. | ||
| 156 | + */ | ||
| 157 | +lwrb_sz_t | ||
| 158 | +lwrb_write(lwrb_t* buff, const void* data, lwrb_sz_t btw) { | ||
| 159 | + lwrb_sz_t written = 0; | ||
| 160 | + | ||
| 161 | + if (lwrb_write_ex(buff, data, btw, &written, 0)) { | ||
| 162 | + return written; | ||
| 163 | + } | ||
| 164 | + return 0; | ||
| 165 | +} | ||
| 166 | + | ||
| 167 | +/** | ||
| 168 | + * \brief Write extended functionality | ||
| 169 | + * | ||
| 170 | + * \param buff: Ring buffer instance | ||
| 171 | + * \param data: Pointer to data to write into buffer | ||
| 172 | + * \param btw: Number of bytes to write | ||
| 173 | + * \param bw: Output pointer to write number of bytes written | ||
| 174 | + * \param flags: Optional flags. | ||
| 175 | + * \ref LWRB_FLAG_WRITE_ALL: Request to write all data (up to btw). | ||
| 176 | + * Will early return if no memory available | ||
| 177 | + * \return `1` if write operation OK, `0` otherwise | ||
| 178 | + */ | ||
| 179 | +uint8_t | ||
| 180 | +lwrb_write_ex(lwrb_t* buff, const void* data, lwrb_sz_t btw, lwrb_sz_t* bw, uint16_t flags) { | ||
| 181 | + lwrb_sz_t tocopy, free, buff_w_ptr; | ||
| 182 | + const uint8_t* d = data; | ||
| 183 | + | ||
| 184 | + if (!BUF_IS_VALID(buff) || data == NULL || btw == 0) { | ||
| 185 | + return 0; | ||
| 186 | + } | ||
| 187 | + | ||
| 188 | + /* Calculate maximum number of bytes available to write */ | ||
| 189 | + free = lwrb_get_free(buff); | ||
| 190 | + /* If no memory, or if user wants to write ALL data but no enough space, exit early */ | ||
| 191 | + if (free == 0 || (free < btw && flags & LWRB_FLAG_WRITE_ALL)) { | ||
| 192 | + return 0; | ||
| 193 | + } | ||
| 194 | + btw = BUF_MIN(free, btw); | ||
| 195 | + buff_w_ptr = LWRB_LOAD(buff->w, memory_order_acquire); | ||
| 196 | + | ||
| 197 | + /* Step 1: Write data to linear part of buffer */ | ||
| 198 | + tocopy = BUF_MIN(buff->size - buff_w_ptr, btw); | ||
| 199 | + BUF_MEMCPY(&buff->buff[buff_w_ptr], d, tocopy); | ||
| 200 | + buff_w_ptr += tocopy; | ||
| 201 | + btw -= tocopy; | ||
| 202 | + | ||
| 203 | + /* Step 2: Write data to beginning of buffer (overflow part) */ | ||
| 204 | + if (btw > 0) { | ||
| 205 | + BUF_MEMCPY(buff->buff, &d[tocopy], btw); | ||
| 206 | + buff_w_ptr = btw; | ||
| 207 | + } | ||
| 208 | + | ||
| 209 | + /* Step 3: Check end of buffer */ | ||
| 210 | + if (buff_w_ptr >= buff->size) { | ||
| 211 | + buff_w_ptr = 0; | ||
| 212 | + } | ||
| 213 | + | ||
| 214 | + /* | ||
| 215 | + * Write final value to the actual running variable. | ||
| 216 | + * This is to ensure no read operation can access intermediate data | ||
| 217 | + */ | ||
| 218 | + LWRB_STORE(buff->w, buff_w_ptr, memory_order_release); | ||
| 219 | + | ||
| 220 | + BUF_SEND_EVT(buff, LWRB_EVT_WRITE, tocopy + btw); | ||
| 221 | + if (bw != NULL) { | ||
| 222 | + *bw = tocopy + btw; | ||
| 223 | + } | ||
| 224 | + return 1; | ||
| 225 | +} | ||
| 226 | + | ||
| 227 | +/** | ||
| 228 | + * \brief Read data from buffer. | ||
| 229 | + * Copies data from buffer to `data` array and marks buffer as free for maximum `btr` number of bytes | ||
| 230 | + * | ||
| 231 | + * \param[in] buff: Ring buffer instance | ||
| 232 | + * \param[out] data: Pointer to output memory to copy buffer data to | ||
| 233 | + * \param[in] btr: Number of bytes to read | ||
| 234 | + * \return Number of bytes read and copied to data array | ||
| 235 | + */ | ||
| 236 | +lwrb_sz_t | ||
| 237 | +lwrb_read(lwrb_t* buff, void* data, lwrb_sz_t btr) { | ||
| 238 | + lwrb_sz_t read = 0; | ||
| 239 | + | ||
| 240 | + if (lwrb_read_ex(buff, data, btr, &read, 0)) { | ||
| 241 | + return read; | ||
| 242 | + } | ||
| 243 | + return 0; | ||
| 244 | +} | ||
| 245 | + | ||
| 246 | +/** | ||
| 247 | + * \brief Write extended functionality | ||
| 248 | + * | ||
| 249 | + * \param buff: Ring buffer instance | ||
| 250 | + * \param data: Pointer to memory to write read data from buffer | ||
| 251 | + * \param btr: Number of bytes to read | ||
| 252 | + * \param br: Output pointer to write number of bytes read | ||
| 253 | + * \param flags: Optional flags | ||
| 254 | + * \ref LWRB_FLAG_READ_ALL: Request to read all data (up to btr). | ||
| 255 | + * Will early return if no enough bytes in the buffer | ||
| 256 | + * \return `1` if read operation OK, `0` otherwise | ||
| 257 | + */ | ||
| 258 | +uint8_t | ||
| 259 | +lwrb_read_ex(lwrb_t* buff, void* data, lwrb_sz_t btr, lwrb_sz_t* br, uint16_t flags) { | ||
| 260 | + lwrb_sz_t tocopy, full, buff_r_ptr; | ||
| 261 | + uint8_t* d = data; | ||
| 262 | + | ||
| 263 | + if (!BUF_IS_VALID(buff) || data == NULL || btr == 0) { | ||
| 264 | + return 0; | ||
| 265 | + } | ||
| 266 | + | ||
| 267 | + /* Calculate maximum number of bytes available to read */ | ||
| 268 | + full = lwrb_get_full(buff); | ||
| 269 | + if (full == 0 || (full < btr && (flags & LWRB_FLAG_READ_ALL))) { | ||
| 270 | + return 0; | ||
| 271 | + } | ||
| 272 | + btr = BUF_MIN(full, btr); | ||
| 273 | + buff_r_ptr = LWRB_LOAD(buff->r, memory_order_acquire); | ||
| 274 | + | ||
| 275 | + /* Step 1: Read data from linear part of buffer */ | ||
| 276 | + tocopy = BUF_MIN(buff->size - buff_r_ptr, btr); | ||
| 277 | + BUF_MEMCPY(d, &buff->buff[buff_r_ptr], tocopy); | ||
| 278 | + buff_r_ptr += tocopy; | ||
| 279 | + btr -= tocopy; | ||
| 280 | + | ||
| 281 | + /* Step 2: Read data from beginning of buffer (overflow part) */ | ||
| 282 | + if (btr > 0) { | ||
| 283 | + BUF_MEMCPY(&d[tocopy], buff->buff, btr); | ||
| 284 | + buff_r_ptr = btr; | ||
| 285 | + } | ||
| 286 | + | ||
| 287 | + /* Step 3: Check end of buffer */ | ||
| 288 | + if (buff_r_ptr >= buff->size) { | ||
| 289 | + buff_r_ptr = 0; | ||
| 290 | + } | ||
| 291 | + | ||
| 292 | + /* | ||
| 293 | + * Write final value to the actual running variable. | ||
| 294 | + * This is to ensure no write operation can access intermediate data | ||
| 295 | + */ | ||
| 296 | + LWRB_STORE(buff->r, buff_r_ptr, memory_order_release); | ||
| 297 | + | ||
| 298 | + BUF_SEND_EVT(buff, LWRB_EVT_READ, tocopy + btr); | ||
| 299 | + if (br != NULL) { | ||
| 300 | + *br = tocopy + btr; | ||
| 301 | + } | ||
| 302 | + return 1; | ||
| 303 | +} | ||
| 304 | + | ||
| 305 | +/** | ||
| 306 | + * \brief Read from buffer without changing read pointer (peek only) | ||
| 307 | + * \param[in] buff: Ring buffer instance | ||
| 308 | + * \param[in] skip_count: Number of bytes to skip before reading data | ||
| 309 | + * \param[out] data: Pointer to output memory to copy buffer data to | ||
| 310 | + * \param[in] btp: Number of bytes to peek | ||
| 311 | + * \return Number of bytes peeked and written to output array | ||
| 312 | + */ | ||
| 313 | +lwrb_sz_t | ||
| 314 | +lwrb_peek(const lwrb_t* buff, lwrb_sz_t skip_count, void* data, lwrb_sz_t btp) { | ||
| 315 | + lwrb_sz_t full, tocopy, r; | ||
| 316 | + uint8_t* d = data; | ||
| 317 | + | ||
| 318 | + if (!BUF_IS_VALID(buff) || data == NULL || btp == 0) { | ||
| 319 | + return 0; | ||
| 320 | + } | ||
| 321 | + | ||
| 322 | + /* | ||
| 323 | + * Calculate maximum number of bytes available to read | ||
| 324 | + * and check if we can even fit to it | ||
| 325 | + */ | ||
| 326 | + full = lwrb_get_full(buff); | ||
| 327 | + if (skip_count >= full) { | ||
| 328 | + return 0; | ||
| 329 | + } | ||
| 330 | + r = LWRB_LOAD(buff->r, memory_order_relaxed); | ||
| 331 | + r += skip_count; | ||
| 332 | + full -= skip_count; | ||
| 333 | + if (r >= buff->size) { | ||
| 334 | + r -= buff->size; | ||
| 335 | + } | ||
| 336 | + | ||
| 337 | + /* Check maximum number of bytes available to read after skip */ | ||
| 338 | + btp = BUF_MIN(full, btp); | ||
| 339 | + if (btp == 0) { | ||
| 340 | + return 0; | ||
| 341 | + } | ||
| 342 | + | ||
| 343 | + /* Step 1: Read data from linear part of buffer */ | ||
| 344 | + tocopy = BUF_MIN(buff->size - r, btp); | ||
| 345 | + BUF_MEMCPY(d, &buff->buff[r], tocopy); | ||
| 346 | + btp -= tocopy; | ||
| 347 | + | ||
| 348 | + /* Step 2: Read data from beginning of buffer (overflow part) */ | ||
| 349 | + if (btp > 0) { | ||
| 350 | + BUF_MEMCPY(&d[tocopy], buff->buff, btp); | ||
| 351 | + } | ||
| 352 | + return tocopy + btp; | ||
| 353 | +} | ||
| 354 | + | ||
| 355 | +/** | ||
| 356 | + * \brief Get available size in buffer for write operation | ||
| 357 | + * \param[in] buff: Ring buffer instance | ||
| 358 | + * \return Number of free bytes in memory | ||
| 359 | + */ | ||
| 360 | +lwrb_sz_t | ||
| 361 | +lwrb_get_free(const lwrb_t* buff) { | ||
| 362 | + lwrb_sz_t size, w, r; | ||
| 363 | + | ||
| 364 | + if (!BUF_IS_VALID(buff)) { | ||
| 365 | + return 0; | ||
| 366 | + } | ||
| 367 | + | ||
| 368 | + /* | ||
| 369 | + * Copy buffer pointers to local variables with atomic access. | ||
| 370 | + * | ||
| 371 | + * To ensure thread safety (only when in single-entry, single-exit FIFO mode use case), | ||
| 372 | + * it is important to write buffer r and w values to local w and r variables. | ||
| 373 | + * | ||
| 374 | + * Local variables will ensure below if statements will always use the same value, | ||
| 375 | + * even if buff->w or buff->r get changed during interrupt processing. | ||
| 376 | + * | ||
| 377 | + * They may change during load operation, important is that | ||
| 378 | + * they do not change during if-else operations following these assignments. | ||
| 379 | + * | ||
| 380 | + * lwrb_get_free is only called for write purpose, and when in FIFO mode, then: | ||
| 381 | + * - buff->w pointer will not change by another process/interrupt because we are in write mode just now | ||
| 382 | + * - buff->r pointer may change by another process. If it gets changed after buff->r has been loaded to local variable, | ||
| 383 | + * buffer will see "free size" less than it actually is. This is not a problem, application can | ||
| 384 | + * always try again to write more data to remaining free memory that was read just during copy operation | ||
| 385 | + */ | ||
| 386 | + w = LWRB_LOAD(buff->w, memory_order_relaxed); | ||
| 387 | + r = LWRB_LOAD(buff->r, memory_order_relaxed); | ||
| 388 | + | ||
| 389 | + if (w >= r) { | ||
| 390 | + size = buff->size - (w - r); | ||
| 391 | + } else { | ||
| 392 | + size = r - w; | ||
| 393 | + } | ||
| 394 | + | ||
| 395 | + /* Buffer free size is always 1 less than actual size */ | ||
| 396 | + return size - 1; | ||
| 397 | +} | ||
| 398 | + | ||
| 399 | +/** | ||
| 400 | + * \brief Get number of bytes currently available in buffer | ||
| 401 | + * \param[in] buff: Ring buffer instance | ||
| 402 | + * \return Number of bytes ready to be read | ||
| 403 | + */ | ||
| 404 | +lwrb_sz_t | ||
| 405 | +lwrb_get_full(const lwrb_t* buff) { | ||
| 406 | + lwrb_sz_t size, w, r; | ||
| 407 | + | ||
| 408 | + if (!BUF_IS_VALID(buff)) { | ||
| 409 | + return 0; | ||
| 410 | + } | ||
| 411 | + | ||
| 412 | + /* | ||
| 413 | + * Copy buffer pointers to local variables. | ||
| 414 | + * | ||
| 415 | + * To ensure thread safety (only when in single-entry, single-exit FIFO mode use case), | ||
| 416 | + * it is important to write buffer r and w values to local w and r variables. | ||
| 417 | + * | ||
| 418 | + * Local variables will ensure below if statements will always use the same value, | ||
| 419 | + * even if buff->w or buff->r get changed during interrupt processing. | ||
| 420 | + * | ||
| 421 | + * They may change during load operation, important is that | ||
| 422 | + * they do not change during if-else operations following these assignments. | ||
| 423 | + * | ||
| 424 | + * lwrb_get_full is only called for read purpose, and when in FIFO mode, then: | ||
| 425 | + * - buff->r pointer will not change by another process/interrupt because we are in read mode just now | ||
| 426 | + * - buff->w pointer may change by another process. If it gets changed after buff->w has been loaded to local variable, | ||
| 427 | + * buffer will see "full size" less than it really is. This is not a problem, application can | ||
| 428 | + * always try again to read more data from remaining full memory that was written just during copy operation | ||
| 429 | + */ | ||
| 430 | + w = LWRB_LOAD(buff->w, memory_order_relaxed); | ||
| 431 | + r = LWRB_LOAD(buff->r, memory_order_relaxed); | ||
| 432 | + | ||
| 433 | + if (w >= r) { | ||
| 434 | + size = w - r; | ||
| 435 | + } else { | ||
| 436 | + size = buff->size - (r - w); | ||
| 437 | + } | ||
| 438 | + return size; | ||
| 439 | +} | ||
| 440 | + | ||
| 441 | +/** | ||
| 442 | + * \brief Resets buffer to default values. Buffer size is not modified | ||
| 443 | + * \note This function is not thread safe. | ||
| 444 | + * When used, application must ensure there is no active read/write operation | ||
| 445 | + * \param[in] buff: Ring buffer instance | ||
| 446 | + */ | ||
| 447 | +void | ||
| 448 | +lwrb_reset(lwrb_t* buff) { | ||
| 449 | + if (BUF_IS_VALID(buff)) { | ||
| 450 | + LWRB_STORE(buff->w, 0, memory_order_release); | ||
| 451 | + LWRB_STORE(buff->r, 0, memory_order_release); | ||
| 452 | + BUF_SEND_EVT(buff, LWRB_EVT_RESET, 0); | ||
| 453 | + } | ||
| 454 | +} | ||
| 455 | + | ||
| 456 | +/** | ||
| 457 | + * \brief Get linear address for buffer for fast read | ||
| 458 | + * \param[in] buff: Ring buffer instance | ||
| 459 | + * \return Linear buffer start address | ||
| 460 | + */ | ||
| 461 | +void* | ||
| 462 | +lwrb_get_linear_block_read_address(const lwrb_t* buff) { | ||
| 463 | + if (!BUF_IS_VALID(buff)) { | ||
| 464 | + return NULL; | ||
| 465 | + } | ||
| 466 | + return &buff->buff[buff->r]; | ||
| 467 | +} | ||
| 468 | + | ||
| 469 | +/** | ||
| 470 | + * \brief Get length of linear block address before it overflows for read operation | ||
| 471 | + * \param[in] buff: Ring buffer instance | ||
| 472 | + * \return Linear buffer size in units of bytes for read operation | ||
| 473 | + */ | ||
| 474 | +lwrb_sz_t | ||
| 475 | +lwrb_get_linear_block_read_length(const lwrb_t* buff) { | ||
| 476 | + lwrb_sz_t len, w, r; | ||
| 477 | + | ||
| 478 | + if (!BUF_IS_VALID(buff)) { | ||
| 479 | + return 0; | ||
| 480 | + } | ||
| 481 | + | ||
| 482 | + /* | ||
| 483 | + * Use temporary values in case they are changed during operations. | ||
| 484 | + * See lwrb_buff_free or lwrb_buff_full functions for more information why this is OK. | ||
| 485 | + */ | ||
| 486 | + w = LWRB_LOAD(buff->w, memory_order_relaxed); | ||
| 487 | + r = LWRB_LOAD(buff->r, memory_order_relaxed); | ||
| 488 | + | ||
| 489 | + if (w > r) { | ||
| 490 | + len = w - r; | ||
| 491 | + } else if (r > w) { | ||
| 492 | + len = buff->size - r; | ||
| 493 | + } else { | ||
| 494 | + len = 0; | ||
| 495 | + } | ||
| 496 | + return len; | ||
| 497 | +} | ||
| 498 | + | ||
| 499 | +/** | ||
| 500 | + * \brief Skip (ignore; advance read pointer) buffer data | ||
| 501 | + * Marks data as read in the buffer and increases free memory for up to `len` bytes | ||
| 502 | + * | ||
| 503 | + * \note Useful at the end of streaming transfer such as DMA | ||
| 504 | + * \param[in] buff: Ring buffer instance | ||
| 505 | + * \param[in] len: Number of bytes to skip and mark as read | ||
| 506 | + * \return Number of bytes skipped | ||
| 507 | + */ | ||
| 508 | +lwrb_sz_t | ||
| 509 | +lwrb_skip(lwrb_t* buff, lwrb_sz_t len) { | ||
| 510 | + lwrb_sz_t full, r; | ||
| 511 | + | ||
| 512 | + if (!BUF_IS_VALID(buff) || len == 0) { | ||
| 513 | + return 0; | ||
| 514 | + } | ||
| 515 | + | ||
| 516 | + full = lwrb_get_full(buff); | ||
| 517 | + len = BUF_MIN(len, full); | ||
| 518 | + r = LWRB_LOAD(buff->r, memory_order_acquire); | ||
| 519 | + r += len; | ||
| 520 | + if (r >= buff->size) { | ||
| 521 | + r -= buff->size; | ||
| 522 | + } | ||
| 523 | + LWRB_STORE(buff->r, r, memory_order_release); | ||
| 524 | + BUF_SEND_EVT(buff, LWRB_EVT_READ, len); | ||
| 525 | + return len; | ||
| 526 | +} | ||
| 527 | + | ||
| 528 | +/** | ||
| 529 | + * \brief Get linear address for buffer for fast read | ||
| 530 | + * \param[in] buff: Ring buffer instance | ||
| 531 | + * \return Linear buffer start address | ||
| 532 | + */ | ||
| 533 | +void* | ||
| 534 | +lwrb_get_linear_block_write_address(const lwrb_t* buff) { | ||
| 535 | + if (!BUF_IS_VALID(buff)) { | ||
| 536 | + return NULL; | ||
| 537 | + } | ||
| 538 | + return &buff->buff[buff->w]; | ||
| 539 | +} | ||
| 540 | + | ||
| 541 | +/** | ||
| 542 | + * \brief Get length of linear block address before it overflows for write operation | ||
| 543 | + * \param[in] buff: Ring buffer instance | ||
| 544 | + * \return Linear buffer size in units of bytes for write operation | ||
| 545 | + */ | ||
| 546 | +lwrb_sz_t | ||
| 547 | +lwrb_get_linear_block_write_length(const lwrb_t* buff) { | ||
| 548 | + lwrb_sz_t len, w, r; | ||
| 549 | + | ||
| 550 | + if (!BUF_IS_VALID(buff)) { | ||
| 551 | + return 0; | ||
| 552 | + } | ||
| 553 | + | ||
| 554 | + /* | ||
| 555 | + * Use temporary values in case they are changed during operations. | ||
| 556 | + * See lwrb_buff_free or lwrb_buff_full functions for more information why this is OK. | ||
| 557 | + */ | ||
| 558 | + w = LWRB_LOAD(buff->w, memory_order_relaxed); | ||
| 559 | + r = LWRB_LOAD(buff->r, memory_order_relaxed); | ||
| 560 | + | ||
| 561 | + if (w >= r) { | ||
| 562 | + len = buff->size - w; | ||
| 563 | + /* | ||
| 564 | + * When read pointer is 0, | ||
| 565 | + * maximal length is one less as if too many bytes | ||
| 566 | + * are written, buffer would be considered empty again (r == w) | ||
| 567 | + */ | ||
| 568 | + if (r == 0) { | ||
| 569 | + /* | ||
| 570 | + * Cannot overflow: | ||
| 571 | + * - If r is not 0, statement does not get called | ||
| 572 | + * - buff->size cannot be 0 and if r is 0, len is greater 0 | ||
| 573 | + */ | ||
| 574 | + --len; | ||
| 575 | + } | ||
| 576 | + } else { | ||
| 577 | + len = r - w - 1; | ||
| 578 | + } | ||
| 579 | + return len; | ||
| 580 | +} | ||
| 581 | + | ||
| 582 | +/** | ||
| 583 | + * \brief Advance write pointer in the buffer. | ||
| 584 | + * Similar to skip function but modifies write pointer instead of read | ||
| 585 | + * | ||
| 586 | + * \note Useful when hardware is writing to buffer and application needs to increase number | ||
| 587 | + * of bytes written to buffer by hardware | ||
| 588 | + * \param[in] buff: Ring buffer instance | ||
| 589 | + * \param[in] len: Number of bytes to advance | ||
| 590 | + * \return Number of bytes advanced for write operation | ||
| 591 | + */ | ||
| 592 | +lwrb_sz_t | ||
| 593 | +lwrb_advance(lwrb_t* buff, lwrb_sz_t len) { | ||
| 594 | + lwrb_sz_t free, w; | ||
| 595 | + | ||
| 596 | + if (!BUF_IS_VALID(buff) || len == 0) { | ||
| 597 | + return 0; | ||
| 598 | + } | ||
| 599 | + | ||
| 600 | + /* Use local variables before writing back to main structure */ | ||
| 601 | + free = lwrb_get_free(buff); | ||
| 602 | + len = BUF_MIN(len, free); | ||
| 603 | + w = LWRB_LOAD(buff->w, memory_order_acquire); | ||
| 604 | + w += len; | ||
| 605 | + if (w >= buff->size) { | ||
| 606 | + w -= buff->size; | ||
| 607 | + } | ||
| 608 | + LWRB_STORE(buff->w, w, memory_order_release); | ||
| 609 | + BUF_SEND_EVT(buff, LWRB_EVT_WRITE, len); | ||
| 610 | + return len; | ||
| 611 | +} | ||
| 612 | + | ||
| 613 | +/** | ||
| 614 | + * \brief Searches for a *needle* in an array, starting from given offset. | ||
| 615 | + * | ||
| 616 | + * \note This function is not thread-safe. | ||
| 617 | + * | ||
| 618 | + * \param buff: Ring buffer to search for needle in | ||
| 619 | + * \param bts: Constant byte array sequence to search for in a buffer | ||
| 620 | + * \param len: Length of the \arg bts array | ||
| 621 | + * \param start_offset: Start offset in the buffer | ||
| 622 | + * \param found_idx: Pointer to variable to write index in array where bts has been found | ||
| 623 | + * Must not be set to `NULL` | ||
| 624 | + * \return `1` if \arg bts found, `0` otherwise | ||
| 625 | + */ | ||
| 626 | +uint8_t | ||
| 627 | +lwrb_find(const lwrb_t* buff, const void* bts, lwrb_sz_t len, lwrb_sz_t start_offset, lwrb_sz_t* found_idx) { | ||
| 628 | + lwrb_sz_t full, r, max_x; | ||
| 629 | + uint8_t found = 0; | ||
| 630 | + const uint8_t* needle = bts; | ||
| 631 | + | ||
| 632 | + if (!BUF_IS_VALID(buff) || needle == NULL || len == 0 || found_idx == NULL) { | ||
| 633 | + return 0; | ||
| 634 | + } | ||
| 635 | + *found_idx = 0; | ||
| 636 | + | ||
| 637 | + full = lwrb_get_full(buff); | ||
| 638 | + /* Verify initial conditions */ | ||
| 639 | + if (full < (len + start_offset)) { | ||
| 640 | + return 0; | ||
| 641 | + } | ||
| 642 | + | ||
| 643 | + /* Max number of for loops is buff_full - input_len - start_offset of buffer length */ | ||
| 644 | + max_x = full - len; | ||
| 645 | + for (lwrb_sz_t skip_x = start_offset; !found && skip_x <= max_x; ++skip_x) { | ||
| 646 | + found = 1; /* Found by default */ | ||
| 647 | + | ||
| 648 | + /* Prepare the starting point for reading */ | ||
| 649 | + r = buff->r + skip_x; | ||
| 650 | + if (r >= buff->size) { | ||
| 651 | + r -= buff->size; | ||
| 652 | + } | ||
| 653 | + | ||
| 654 | + /* Search in the buffer */ | ||
| 655 | + for (lwrb_sz_t i = 0; i < len; ++i) { | ||
| 656 | + if (buff->buff[r] != needle[i]) { | ||
| 657 | + found = 0; | ||
| 658 | + break; | ||
| 659 | + } | ||
| 660 | + if (++r >= buff->size) { | ||
| 661 | + r = 0; | ||
| 662 | + } | ||
| 663 | + } | ||
| 664 | + if (found) { | ||
| 665 | + *found_idx = skip_x; | ||
| 666 | + } | ||
| 667 | + } | ||
| 668 | + return found; | ||
| 669 | +} |
JZsdk_Common/JZsdk_Base/Lwrb/lwrb.h
0 → 100644
| 1 | +/** | ||
| 2 | + * \file lwrb.h | ||
| 3 | + * \brief LwRB - Lightweight ring buffer | ||
| 4 | + */ | ||
| 5 | + | ||
| 6 | +/* | ||
| 7 | + * Copyright (c) 2024 Tilen MAJERLE | ||
| 8 | + * | ||
| 9 | + * Permission is hereby granted, free of charge, to any person | ||
| 10 | + * obtaining a copy of this software and associated documentation | ||
| 11 | + * files (the "Software"), to deal in the Software without restriction, | ||
| 12 | + * including without limitation the rights to use, copy, modify, merge, | ||
| 13 | + * publish, distribute, sublicense, and/or sell copies of the Software, | ||
| 14 | + * and to permit persons to whom the Software is furnished to do so, | ||
| 15 | + * subject to the following conditions: | ||
| 16 | + * | ||
| 17 | + * The above copyright notice and this permission notice shall be | ||
| 18 | + * included in all copies or substantial portions of the Software. | ||
| 19 | + * | ||
| 20 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
| 21 | + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
| 22 | + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE | ||
| 23 | + * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
| 24 | + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
| 25 | + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
| 26 | + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
| 27 | + * OTHER DEALINGS IN THE SOFTWARE. | ||
| 28 | + * | ||
| 29 | + * This file is part of LwRB - Lightweight ring buffer library. | ||
| 30 | + * | ||
| 31 | + * Author: Tilen MAJERLE <tilen@majerle.eu> | ||
| 32 | + * Version: v3.1.0 | ||
| 33 | + */ | ||
| 34 | +#ifndef LWRB_HDR_H | ||
| 35 | +#define LWRB_HDR_H | ||
| 36 | + | ||
| 37 | +#include <stddef.h> | ||
| 38 | +#include <stdint.h> | ||
| 39 | +#include <string.h> | ||
| 40 | + | ||
| 41 | +#ifdef __cplusplus | ||
| 42 | +extern "C" { | ||
| 43 | +#endif /* __cplusplus */ | ||
| 44 | + | ||
| 45 | +/** | ||
| 46 | + * \defgroup LWRB Lightweight ring buffer manager | ||
| 47 | + * \brief Lightweight ring buffer manager | ||
| 48 | + * \{ | ||
| 49 | + */ | ||
| 50 | + | ||
| 51 | +#if !defined(LWRB_DISABLE_ATOMIC) || __DOXYGEN__ | ||
| 52 | +#include <stdatomic.h> | ||
| 53 | + | ||
| 54 | +/** | ||
| 55 | + * \brief Atomic type for size variable. | ||
| 56 | + * Default value is set to be `unsigned 32-bits` type | ||
| 57 | + * * \brief 原子类型,用于大小变量。 | ||
| 58 | + * 默认值被设置为`无符号32位`类型 | ||
| 59 | + */ | ||
| 60 | +typedef atomic_ulong lwrb_sz_atomic_t; | ||
| 61 | + | ||
| 62 | +/** | ||
| 63 | + * \brief Size variable for all library operations. | ||
| 64 | + * Default value is set to be `unsigned 32-bits` type | ||
| 65 | + * * \brief 所有库操作的大小变量。 | ||
| 66 | + * 默认值被设置为`无符号32位`类型 | ||
| 67 | + */ | ||
| 68 | +typedef unsigned long lwrb_sz_t; | ||
| 69 | +#else | ||
| 70 | +typedef unsigned long lwrb_sz_atomic_t; | ||
| 71 | +typedef unsigned long lwrb_sz_t; | ||
| 72 | +#endif | ||
| 73 | + | ||
| 74 | +/** | ||
| 75 | + * \brief Event type for buffer operations | ||
| 76 | + * 用于缓冲区操作的事件类型 | ||
| 77 | + */ | ||
| 78 | +typedef enum { | ||
| 79 | + LWRB_EVT_READ, /*!< Read event */ | ||
| 80 | + LWRB_EVT_WRITE, /*!< Write event */ | ||
| 81 | + LWRB_EVT_RESET, /*!< Reset event */ | ||
| 82 | +} lwrb_evt_type_t; | ||
| 83 | + | ||
| 84 | +/** | ||
| 85 | + * \brief Buffer structure forward declaration环形缓冲区结构的前置声明 | ||
| 86 | + */ | ||
| 87 | +struct lwrb; | ||
| 88 | + | ||
| 89 | +/** | ||
| 90 | + * \brief Event callback function type 事件回调函数类型 | ||
| 91 | + * \param[in] buff: Buffer handle for event 事件的缓冲区句柄 | ||
| 92 | + * \param[in] evt: Event type 事件类型 | ||
| 93 | + * \param[in] bp: Number of bytes written or read (when used), depends on event type 写入或读取的字节数(当使用时),取决于事件类型 | ||
| 94 | + */ | ||
| 95 | +typedef void (*lwrb_evt_fn)(struct lwrb* buff, lwrb_evt_type_t evt, lwrb_sz_t bp); | ||
| 96 | + | ||
| 97 | +/* List of flags */ | ||
| 98 | +#define LWRB_FLAG_READ_ALL ((uint16_t)0x0001) | ||
| 99 | +#define LWRB_FLAG_WRITE_ALL ((uint16_t)0x0001) | ||
| 100 | + | ||
| 101 | +/** | ||
| 102 | + * \brief Buffer structure | ||
| 103 | + */ | ||
| 104 | +typedef struct lwrb { | ||
| 105 | + uint8_t* buff; // 指向缓冲区数据的指针。当buff != NULL且size > 0时,认为缓冲区已初始化 / | ||
| 106 | + lwrb_sz_t size; /*!<缓冲区数据的大小。实际缓冲区的大小比此值小1字节 */ | ||
| 107 | + lwrb_sz_atomic_t r; /*!< 下一个读指针。当r == w时,认为缓冲区为空;当w == (r - 1 + size) % size时,认为缓冲区已满 */ | ||
| 108 | + lwrb_sz_atomic_t w; /*!< 下一个写指针。当r == w时,认为缓冲区为空;当w == (r - 1 + size) % size时,认为缓冲区已满 */ | ||
| 109 | + lwrb_evt_fn evt_fn; /*!< 事件回调函数指针 */ | ||
| 110 | + void* arg; /*!< 事件自定义用户参数t */ | ||
| 111 | +} lwrb_t; | ||
| 112 | + | ||
| 113 | +uint8_t lwrb_init(lwrb_t* buff, void* buffdata, lwrb_sz_t size); | ||
| 114 | +uint8_t lwrb_is_ready(lwrb_t* buff); | ||
| 115 | +void lwrb_free(lwrb_t* buff); | ||
| 116 | +void lwrb_reset(lwrb_t* buff); | ||
| 117 | +void lwrb_set_evt_fn(lwrb_t* buff, lwrb_evt_fn fn); | ||
| 118 | +void lwrb_set_arg(lwrb_t* buff, void* arg); | ||
| 119 | +void* lwrb_get_arg(lwrb_t* buff); | ||
| 120 | + | ||
| 121 | +/* Read/Write functions */ | ||
| 122 | +lwrb_sz_t lwrb_write(lwrb_t* buff, const void* data, lwrb_sz_t btw); | ||
| 123 | +lwrb_sz_t lwrb_read(lwrb_t* buff, void* data, lwrb_sz_t btr); | ||
| 124 | +lwrb_sz_t lwrb_peek(const lwrb_t* buff, lwrb_sz_t skip_count, void* data, lwrb_sz_t btp); | ||
| 125 | + | ||
| 126 | +/* Extended read/write functions */ | ||
| 127 | +uint8_t lwrb_write_ex(lwrb_t* buff, const void* data, lwrb_sz_t btw, lwrb_sz_t* bw, uint16_t flags); | ||
| 128 | +uint8_t lwrb_read_ex(lwrb_t* buff, void* data, lwrb_sz_t btr, lwrb_sz_t* br, uint16_t flags); | ||
| 129 | + | ||
| 130 | +/* Buffer size information */ | ||
| 131 | +lwrb_sz_t lwrb_get_free(const lwrb_t* buff); | ||
| 132 | +lwrb_sz_t lwrb_get_full(const lwrb_t* buff); | ||
| 133 | + | ||
| 134 | +/* Read data block management */ | ||
| 135 | +void* lwrb_get_linear_block_read_address(const lwrb_t* buff); | ||
| 136 | +lwrb_sz_t lwrb_get_linear_block_read_length(const lwrb_t* buff); | ||
| 137 | +lwrb_sz_t lwrb_skip(lwrb_t* buff, lwrb_sz_t len); | ||
| 138 | + | ||
| 139 | +/* Write data block management */ | ||
| 140 | +void* lwrb_get_linear_block_write_address(const lwrb_t* buff); | ||
| 141 | +lwrb_sz_t lwrb_get_linear_block_write_length(const lwrb_t* buff); | ||
| 142 | +lwrb_sz_t lwrb_advance(lwrb_t* buff, lwrb_sz_t len); | ||
| 143 | + | ||
| 144 | +/* Search in buffer */ | ||
| 145 | +uint8_t lwrb_find(const lwrb_t* buff, const void* bts, lwrb_sz_t len, lwrb_sz_t start_offset, lwrb_sz_t* found_idx); | ||
| 146 | +lwrb_sz_t lwrb_overwrite(lwrb_t* buff, const void* data, lwrb_sz_t btw); | ||
| 147 | +lwrb_sz_t lwrb_move(lwrb_t* dest, lwrb_t* src); | ||
| 148 | + | ||
| 149 | +/** | ||
| 150 | + * \} | ||
| 151 | + */ | ||
| 152 | + | ||
| 153 | +#ifdef __cplusplus | ||
| 154 | +} | ||
| 155 | +#endif /* __cplusplus */ | ||
| 156 | + | ||
| 157 | +#endif /* LWRB_HDR_H */ |
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file JZsdkCommonFuntion.h | ||
| 4 | + * JZsdk常用函数库的头文件 | ||
| 5 | + * | ||
| 6 | + ********************************************************************* | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/ | ||
| 10 | +#ifndef JZSDKCOMMONFUNTION_H | ||
| 11 | +#define JZSDKCOMMONFUNTION_H | ||
| 12 | + | ||
| 13 | +/* Includes ------------------------------------------------------------------*/ | ||
| 14 | + | ||
| 15 | +#ifdef __cplusplus | ||
| 16 | +extern "C" { | ||
| 17 | +#endif | ||
| 18 | + | ||
| 19 | +/* Exported constants --------------------------------------------------------*/ | ||
| 20 | +/* 常亮定义*/ | ||
| 21 | +#include "JZsdk_string/JZsdk_string.h" | ||
| 22 | +#include "JZsdk_math/JZsdk_math.h" | ||
| 23 | + | ||
| 24 | +/* Exported types ------------------------------------------------------------*/ | ||
| 25 | + | ||
| 26 | + | ||
| 27 | +/* Exported functions --------------------------------------------------------*/ | ||
| 28 | + | ||
| 29 | + | ||
| 30 | +#ifdef __cplusplus | ||
| 31 | +} | ||
| 32 | +#endif | ||
| 33 | + | ||
| 34 | +#endif |
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file JZsdk_math.h | ||
| 4 | + * 用于文件系统操作 | ||
| 5 | + * | ||
| 6 | + ********************************************************************* | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/ | ||
| 10 | +#ifndef JZSDK_MATH_H | ||
| 11 | +#define JZSDK_MATH_H | ||
| 12 | + | ||
| 13 | +/* Includes ------------------------------------------------------------------*/ | ||
| 14 | +#include <stddef.h> | ||
| 15 | +#include "JZsdk_Base/JZsdk_Code/JZsdk_Code.h" | ||
| 16 | + | ||
| 17 | +#ifdef __cplusplus | ||
| 18 | +extern "C" { | ||
| 19 | +#endif | ||
| 20 | + | ||
| 21 | +/* Exported constants --------------------------------------------------------*/ | ||
| 22 | +/* 常亮定义*/ | ||
| 23 | + | ||
| 24 | + | ||
| 25 | +/* Exported types ------------------------------------------------------------*/ | ||
| 26 | + | ||
| 27 | + | ||
| 28 | +/* Exported functions --------------------------------------------------------*/ | ||
| 29 | +#define JZ_MATH_MAX(a, b) ((a) > (b) ? (a) : (b)) //比较大小 | ||
| 30 | +#define JZ_MATH_MIN(a, b) ((a) < (b) ? (a) : (b)) //比较大小 | ||
| 31 | +#define JZ_MATH_ADD(a, b) ((a) + (b)) //相加 | ||
| 32 | +#define JZ_MATH_SUB(a, b) ((a) - (b)) //相减 | ||
| 33 | +#define JZ_MATH_MUL(a, b) ((a) * (b)) //相乘 | ||
| 34 | +#define JZ_MATH_DIVIDE(a, b) ((b) != 0 ? (a) / (b) : (-1)) //相除 | ||
| 35 | +#define JZ_MATH_MODULUS(a, b) ((b) != 0 ? (a) % (b) : (-1)) //求余 | ||
| 36 | +#define JZ_MATH_ABS(a) ((a) < 0 ? -(a) : (a)) //求绝对值 | ||
| 37 | +#define JZ_MATH_SQUARE(a) ((a) * (a)) //求平方 | ||
| 38 | +#define JZ_MATH_CUBE(a) ((a) * (a) * (a)) //求立方 | ||
| 39 | + | ||
| 40 | +// 注意:这个宏只适用于正整数幂且幂次较小的情况 | ||
| 41 | +#define JZ_MATH_POW(base, exponent) ((exponent) == 0 ? 1 : ((base) * JZ_MATH_POW(base, (exponent) - 1))) | ||
| 42 | +// 使用递归,对于大幂次或浮点数幂次,建议使用math.h中的pow函数 | ||
| 43 | + | ||
| 44 | +// #include <math.h> | ||
| 45 | +// #define JZ_MATH_SQRT(a) sqrt(a) | ||
| 46 | + | ||
| 47 | +#define JZ_MATH_CLAMP(value, min, max) ((value) < (min) ? (min) : ((value) > (max) ? (max) : (value))) //限制值在范围内(确保一个值在指定的最小值和最大值之间): | ||
| 48 | +#define JZ_MATH_SWAP(a, b) do { typeof(a) temp = (a); (a) = (b); (b) = temp; } while (0) //交换两个变量的值(这个宏使用了一个临时变量,但它仍然是通过宏来完成的): | ||
| 49 | + | ||
| 50 | + | ||
| 51 | +#ifdef __cplusplus | ||
| 52 | +} | ||
| 53 | +#endif | ||
| 54 | + | ||
| 55 | +#endif |
| 1 | +#include <stdio.h> | ||
| 2 | +#include <string.h> | ||
| 3 | +#include "JZsdk_string.h" | ||
| 4 | +#include "../../JZsdkLib.h" | ||
| 5 | + | ||
| 6 | +/* | ||
| 7 | +* 用于字符串转int型 | ||
| 8 | +*/ | ||
| 9 | +int JZsdk_String_str_to_int(const char *str) | ||
| 10 | +{ | ||
| 11 | + int temp = 0; | ||
| 12 | + const char *ptr = str; //ptr保存str字符串开头 | ||
| 13 | + | ||
| 14 | + if (*str == '-' || *str == '+') //如果第一个字符是正负号, | ||
| 15 | + { //则移到下一个字符 | ||
| 16 | + str++; | ||
| 17 | + } | ||
| 18 | + while(*str != 0) | ||
| 19 | + { | ||
| 20 | + if ((*str < '0') || (*str > '9')) //如果当前字符不是数字 | ||
| 21 | + { //则退出循环 | ||
| 22 | + break; | ||
| 23 | + } | ||
| 24 | + temp = temp * 10 + (*str - '0'); //如果当前字符是数字则计算数值 | ||
| 25 | + str++; //移到下一个字符 | ||
| 26 | + } | ||
| 27 | + if (*ptr == '-') //如果字符串是以“-”开头,则转换成其相反数 | ||
| 28 | + { | ||
| 29 | + temp = -temp; | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + return temp; | ||
| 33 | +} | ||
| 34 | + | ||
| 35 | + | ||
| 36 | +/* | ||
| 37 | +* int型转字符串 | ||
| 38 | +*/ | ||
| 39 | +void JZsdk_String_int_to_str(int n, char *str) | ||
| 40 | +{ | ||
| 41 | + char buf[10] = ""; | ||
| 42 | + int i = 0; | ||
| 43 | + int len = 0; | ||
| 44 | + int temp = n < 0 ? -n: n; // temp为n的绝对值 | ||
| 45 | + | ||
| 46 | + if (str == NULL) | ||
| 47 | + { | ||
| 48 | + return; | ||
| 49 | + } | ||
| 50 | + while(temp) | ||
| 51 | + { | ||
| 52 | + buf[i++] = (temp % 10) + '0'; //把temp的每一位上的数存入buf | ||
| 53 | + temp = temp / 10; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + len = n < 0 ? ++i: i; //如果n是负数,则多需要一位来存储负号 | ||
| 57 | + str[i] = 0; //末尾是结束符0 | ||
| 58 | + while(1) | ||
| 59 | + { | ||
| 60 | + i--; | ||
| 61 | + if (buf[len-i-1] ==0) | ||
| 62 | + { | ||
| 63 | + break; | ||
| 64 | + } | ||
| 65 | + str[i] = buf[len-i-1]; //把buf数组里的字符拷到字符串 | ||
| 66 | + } | ||
| 67 | + if (i == 0 ) | ||
| 68 | + { | ||
| 69 | + str[i] = '-'; //如果是负数,添加一个负号 | ||
| 70 | + } | ||
| 71 | +} | ||
| 72 | + | ||
| 73 | +/* | ||
| 74 | +* longlong型转字符串型 | ||
| 75 | +*/ | ||
| 76 | +size_t JZsdk_String_longlong_to_str(char *s, long long value,int radix) | ||
| 77 | +{ | ||
| 78 | + char *p, aux; | ||
| 79 | + unsigned long long v; | ||
| 80 | + size_t l; | ||
| 81 | + | ||
| 82 | + /* Generate the string representation, this method produces | ||
| 83 | + * an reversed string. */ | ||
| 84 | + v = (value < 0) ? -value : value; | ||
| 85 | + p = s; | ||
| 86 | + do { | ||
| 87 | + *p++ = '0' + (v % radix); // 2 | ||
| 88 | + v /= radix; // 2 | ||
| 89 | + } while (v); | ||
| 90 | + if (value < 0) *p++ = '-'; | ||
| 91 | + | ||
| 92 | + /* Compute length and add null term. */ | ||
| 93 | + l = p - s; | ||
| 94 | + *p = '\0'; | ||
| 95 | + | ||
| 96 | + /* Reverse the string. */ | ||
| 97 | + p--; | ||
| 98 | + while (s < p) { | ||
| 99 | + aux = *s; | ||
| 100 | + *s = *p; | ||
| 101 | + *p = aux; | ||
| 102 | + s++; | ||
| 103 | + p--; | ||
| 104 | + } | ||
| 105 | + return l; | ||
| 106 | +} | ||
| 107 | + | ||
| 108 | +/**************** | ||
| 109 | + * | ||
| 110 | + * 用于判断数组是否为空 | ||
| 111 | + * 不为空 JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE | ||
| 112 | + * 空 JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS | ||
| 113 | + * ***********/ | ||
| 114 | +T_JZsdkReturnCode JZsdk_Array_isEmpty(unsigned char array[], int size) | ||
| 115 | +{ | ||
| 116 | + for (int i = 0; i < size; i++) { | ||
| 117 | + if (array[i] != 0) { | ||
| 118 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; // 数组不为空 | ||
| 119 | + } | ||
| 120 | + } | ||
| 121 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; // 数组为空 | ||
| 122 | +} | ||
| 123 | + | ||
| 124 | +/**************** | ||
| 125 | + * | ||
| 126 | + * 用于替换数组中的换行符'\n'为结束符'\0' | ||
| 127 | + * | ||
| 128 | + * 替换成功返回 JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS | ||
| 129 | + * 没有替换 返回JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE | ||
| 130 | + | ||
| 131 | + * ***********/ | ||
| 132 | +T_JZsdkReturnCode JZsdk_replace_newlines_with_null_terminator(char* string) | ||
| 133 | +{ | ||
| 134 | + int replace_flag = JZ_FLAGCODE_OFF; | ||
| 135 | + | ||
| 136 | + // 获取字符串的长度 | ||
| 137 | + int length = strlen(string); | ||
| 138 | + | ||
| 139 | + // 遍历字符串,将换行符替换为结束符 | ||
| 140 | + for (int i = 0; i < length; i++) { | ||
| 141 | + if (string[i] == '\n') { | ||
| 142 | + string[i] = '\0'; | ||
| 143 | + replace_flag = JZ_FLAGCODE_ON; | ||
| 144 | + } | ||
| 145 | + } | ||
| 146 | + | ||
| 147 | + if (replace_flag == JZ_FLAGCODE_ON) | ||
| 148 | + { | ||
| 149 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 150 | + } | ||
| 151 | + else | ||
| 152 | + { | ||
| 153 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 154 | + } | ||
| 155 | + | ||
| 156 | +} | ||
| 157 | + | ||
| 158 | +/**************** | ||
| 159 | + * | ||
| 160 | + * 用于将两位u8的数据逆向合并为u16的数据 | ||
| 161 | + * | ||
| 162 | + * 成功返回 JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS | ||
| 163 | + * 失败 返回JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE | ||
| 164 | + | ||
| 165 | + * ***********/ | ||
| 166 | +T_JZsdkReturnCode JZsdk_Merge_U8_to_U16_byReverse(U8_t *in_str, int in_str_len, U16_t *out_str, int *out_str_len) | ||
| 167 | +{ | ||
| 168 | + // 检查输入长度是否是2的倍数 | ||
| 169 | + if (in_str_len % 2 != 0) | ||
| 170 | + { | ||
| 171 | + // 输入长度不是偶数,处理错误 | ||
| 172 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 173 | + } | ||
| 174 | + | ||
| 175 | + // 检查函数地址 | ||
| 176 | + if(in_str == NULL || out_str == NULL) | ||
| 177 | + { | ||
| 178 | + return JZ_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER; | ||
| 179 | + } | ||
| 180 | + | ||
| 181 | + int Step = 0; | ||
| 182 | + for (int i = 0; i < in_str_len; i += 2) | ||
| 183 | + { | ||
| 184 | + // 两字节合并为一个16位的整数,注意高低位的顺序 | ||
| 185 | + out_str[Step++] = ((U16_t)in_str[i+1] << 8) | in_str[i]; | ||
| 186 | + } | ||
| 187 | + | ||
| 188 | + // 设置输出字符串的长度为输入长度的一半 | ||
| 189 | + *out_str_len = in_str_len / 2; | ||
| 190 | + | ||
| 191 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 192 | +} | ||
| 193 | + | ||
| 194 | +/**************** | ||
| 195 | + * | ||
| 196 | + * 用于将两位u8的数据正向合并为u16的数据 | ||
| 197 | + * | ||
| 198 | + * 成x功返回 JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS | ||
| 199 | + * 失败 返回JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE | ||
| 200 | + | ||
| 201 | + * ***********/ | ||
| 202 | +T_JZsdkReturnCode JZsdk_Merge_U8_to_U16_byForward(U8_t *in_str, int in_str_len, U16_t *out_str, int *out_str_len) | ||
| 203 | +{ | ||
| 204 | + // 检查输入长度是否是2的倍数 | ||
| 205 | + if (in_str_len % 2 != 0) | ||
| 206 | + { | ||
| 207 | + // 输入长度不是偶数,处理错误 | ||
| 208 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 209 | + } | ||
| 210 | + | ||
| 211 | + // 检查函数地址 | ||
| 212 | + if (in_str == NULL || out_str == NULL) | ||
| 213 | + { | ||
| 214 | + return JZ_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER; | ||
| 215 | + } | ||
| 216 | + | ||
| 217 | + int Step = 0; | ||
| 218 | + for (int i = 0; i < in_str_len; i += 2) | ||
| 219 | + { | ||
| 220 | + // 两字节合并为一个16位的整数,注意高低位的顺序 | ||
| 221 | + out_str[Step++] = ((U16_t)in_str[i+1] << 8) | in_str[i]; | ||
| 222 | + } | ||
| 223 | + | ||
| 224 | + // 设置输出字符串的长度为输入长度的一半 | ||
| 225 | + *out_str_len = in_str_len / 2; | ||
| 226 | + | ||
| 227 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 228 | +} |
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file JZsdk_string.h | ||
| 4 | + * 用于文件系统操作 | ||
| 5 | + * | ||
| 6 | + ********************************************************************* | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/ | ||
| 10 | +#ifndef JZSDK_STRING_H | ||
| 11 | +#define JZSDK_STRING_H | ||
| 12 | + | ||
| 13 | +/* Includes ------------------------------------------------------------------*/ | ||
| 14 | +#include <stddef.h> | ||
| 15 | +#include "JZsdk_Base/JZsdk_Code/JZsdk_Code.h" | ||
| 16 | + | ||
| 17 | +#ifdef __cplusplus | ||
| 18 | +extern "C" { | ||
| 19 | +#endif | ||
| 20 | + | ||
| 21 | +/* Exported constants --------------------------------------------------------*/ | ||
| 22 | +/* 常亮定义*/ | ||
| 23 | + | ||
| 24 | + | ||
| 25 | +/* Exported types ------------------------------------------------------------*/ | ||
| 26 | + | ||
| 27 | + | ||
| 28 | +/* Exported functions --------------------------------------------------------*/ | ||
| 29 | +int JZsdk_String_str_to_int(const char *str); | ||
| 30 | +void JZsdk_String_int_to_str(int n, char *str); | ||
| 31 | +size_t JZsdk_String_longlong_to_str(char *s, long long value,int radix); | ||
| 32 | +T_JZsdkReturnCode JZsdk_Array_isEmpty(unsigned char array[], int size); | ||
| 33 | +T_JZsdkReturnCode JZsdk_replace_newlines_with_null_terminator(char* string) ; | ||
| 34 | + | ||
| 35 | +T_JZsdkReturnCode JZsdk_Merge_U8_to_U16_byReverse(U8_t *in_str, int in_str_len, U16_t *out_str, int *out_str_len); | ||
| 36 | +T_JZsdkReturnCode JZsdk_Merge_U8_to_U16_byForward(U8_t *in_str, int in_str_len, U16_t *out_str, int *out_str_len); | ||
| 37 | + | ||
| 38 | +#ifdef __cplusplus | ||
| 39 | +} | ||
| 40 | +#endif | ||
| 41 | + | ||
| 42 | +#endif |
| 1 | +/****************************** | ||
| 2 | + * | ||
| 3 | + * JZsdk的任务管理模块 | ||
| 4 | + * | ||
| 5 | + * | ||
| 6 | + * ***************************/ | ||
| 7 | +#include <stdio.h> | ||
| 8 | +#include <stdlib.h> | ||
| 9 | +#include <pthread.h> | ||
| 10 | +#include <unistd.h> | ||
| 11 | + | ||
| 12 | +#include "./TaskManagement.h" | ||
| 13 | +#include <JZsdkLib.h> | ||
| 14 | + | ||
| 15 | +#define THREAD_POOL_SIZE 5 // 线程池大小 | ||
| 16 | + | ||
| 17 | +typedef struct { | ||
| 18 | + void (*task_function)(void*); //任务函数指针,用于指定 执行的任务 | ||
| 19 | + void* data; // 任务参数 //任务参数的地址 用于输入任务内容 | ||
| 20 | +} t_JZsdk_TaskMgmt_TaskInput; | ||
| 21 | + | ||
| 22 | +typedef struct { | ||
| 23 | + pthread_t thread; // 线程 //调用的线程 | ||
| 24 | + int is_busy; // 标识线程是否忙碌 | ||
| 25 | + t_JZsdk_TaskMgmt_TaskInput* task; // 线程执行的任务 | ||
| 26 | + pthread_mutex_t lock; // 互斥锁 | ||
| 27 | + pthread_cond_t condition; // 条件变量 | ||
| 28 | +} t_ThreadPool; | ||
| 29 | + | ||
| 30 | +t_ThreadPool TaskPool[THREAD_POOL_SIZE]; //任务池子 | ||
| 31 | + | ||
| 32 | +static void* TaskManagement_ThreadFunction(void* arg); | ||
| 33 | + | ||
| 34 | + | ||
| 35 | +/************** | ||
| 36 | + * | ||
| 37 | + * 任务管理模块的初始化 | ||
| 38 | + * | ||
| 39 | + * ***************/ | ||
| 40 | +T_JZsdkReturnCode TaskManagement_Init() | ||
| 41 | +{ | ||
| 42 | + //1、创建任务池子 | ||
| 43 | + for (int i = 0; i < THREAD_POOL_SIZE; i++) | ||
| 44 | + { | ||
| 45 | + TaskPool[i].is_busy = 0; | ||
| 46 | + pthread_mutex_init(&TaskPool[i].lock, NULL); | ||
| 47 | + pthread_cond_init(&TaskPool[i].condition, NULL); | ||
| 48 | + pthread_create(&TaskPool[i].thread, NULL, TaskManagement_ThreadFunction, &TaskPool[i]); | ||
| 49 | + } | ||
| 50 | +} | ||
| 51 | + | ||
| 52 | +/************** | ||
| 53 | + * | ||
| 54 | + * 任务的输入 | ||
| 55 | + * | ||
| 56 | + * ***************/ | ||
| 57 | +T_JZsdkReturnCode TaskManagement_SubmitTask(void (*task_function)(void*), void* data) | ||
| 58 | +{ | ||
| 59 | + //检阅是否有空余的任务线程 | ||
| 60 | + int i = 0; | ||
| 61 | + for ( ; i < THREAD_POOL_SIZE; i++) | ||
| 62 | + { | ||
| 63 | + if (!TaskPool[i].is_busy) | ||
| 64 | + { | ||
| 65 | + //检测到有空余的线程 | ||
| 66 | + break; | ||
| 67 | + } | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + //没有多余的任务线程,退出该发送任务 | ||
| 71 | + if (i >= THREAD_POOL_SIZE) | ||
| 72 | + { | ||
| 73 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + t_JZsdk_TaskMgmt_TaskInput *task = (t_JZsdk_TaskMgmt_TaskInput*)malloc(sizeof(t_JZsdk_TaskMgmt_TaskInput)); | ||
| 77 | + if (task == NULL) | ||
| 78 | + { | ||
| 79 | + // 处理内存分配失败的情况 | ||
| 80 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + task->task_function = task_function; | ||
| 84 | + task->data = data; | ||
| 85 | + | ||
| 86 | + //将发送内容放入任务 | ||
| 87 | + TaskPool[i].task = task; | ||
| 88 | + TaskPool[i].is_busy = 1; | ||
| 89 | + pthread_cond_signal(&TaskPool[i].condition); | ||
| 90 | + | ||
| 91 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 92 | +} | ||
| 93 | + | ||
| 94 | + | ||
| 95 | +//执行函数 | ||
| 96 | +static void* TaskManagement_ThreadFunction(void* arg) | ||
| 97 | +{ | ||
| 98 | + t_ThreadPool* pool = (t_ThreadPool*)arg; | ||
| 99 | + while (1) | ||
| 100 | + { | ||
| 101 | + pthread_mutex_lock(&pool->lock); | ||
| 102 | + while (!pool->is_busy) | ||
| 103 | + { | ||
| 104 | + pthread_cond_wait(&pool->condition, &pool->lock); | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + // 执行任务 | ||
| 108 | + pthread_mutex_unlock(&pool->lock); | ||
| 109 | + | ||
| 110 | + if (pool->task->task_function != NULL) | ||
| 111 | + { | ||
| 112 | + pool->task->task_function(pool->task->data); | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + // 执行完成,将状态置为未忙碌 | ||
| 116 | + pthread_mutex_lock(&pool->lock); | ||
| 117 | + if (pool->task != NULL) | ||
| 118 | + { | ||
| 119 | + free(pool->task); | ||
| 120 | + pool->task = NULL; | ||
| 121 | + } | ||
| 122 | + pool->is_busy = 0; | ||
| 123 | + pthread_mutex_unlock(&pool->lock); | ||
| 124 | + } | ||
| 125 | + return NULL; | ||
| 126 | +} |
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file TaskManagement.h | ||
| 4 | + * | ||
| 5 | + * | ||
| 6 | + ********************************************************************* | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/ | ||
| 10 | +#ifndef JZSDK_TASK_MANAGEMENT_H | ||
| 11 | +#define JZSDK_TASK_MANAGEMENT_H | ||
| 12 | + | ||
| 13 | +/* Includes ------------------------------------------------------------------*/ | ||
| 14 | + | ||
| 15 | +#ifdef __cplusplus | ||
| 16 | +extern "C" { | ||
| 17 | +#endif | ||
| 18 | + | ||
| 19 | +/* Exported constants --------------------------------------------------------*/ | ||
| 20 | +/* 常亮定义*/ | ||
| 21 | +#include "JZsdk_Base/JZsdk_Code/JZsdk_Code.h" | ||
| 22 | + | ||
| 23 | + | ||
| 24 | +/* Exported types ------------------------------------------------------------*/ | ||
| 25 | + | ||
| 26 | +/* Exported functions --------------------------------------------------------*/ | ||
| 27 | +T_JZsdkReturnCode TaskManagement_Init(); | ||
| 28 | +T_JZsdkReturnCode TaskManagement_SubmitTask(void (*task_function)(void*), void* data); | ||
| 29 | + | ||
| 30 | +#ifdef __cplusplus | ||
| 31 | +} | ||
| 32 | +#endif | ||
| 33 | + | ||
| 34 | +#endif |
| 1 | +#include <stdio.h> | ||
| 2 | +#include <stdlib.h> | ||
| 3 | +#include <pthread.h> | ||
| 4 | +#include <unistd.h> | ||
| 5 | + | ||
| 6 | +#include "./TaskManagement.h" | ||
| 7 | +#include <JZsdkLib.h> | ||
| 8 | + | ||
| 9 | +typedef struct { | ||
| 10 | + char* str; | ||
| 11 | + int num; | ||
| 12 | +} TaskData; | ||
| 13 | + | ||
| 14 | + | ||
| 15 | +static void TaskMgmt_sample_funtion(void *data) | ||
| 16 | +{ | ||
| 17 | + TaskData* taskData = (TaskData*)data; | ||
| 18 | + printf("Sending data to serial: %s, %d\n", taskData->str, taskData->num); | ||
| 19 | + | ||
| 20 | + free(taskData); | ||
| 21 | + taskData = NULL; | ||
| 22 | +} | ||
| 23 | + | ||
| 24 | + | ||
| 25 | + | ||
| 26 | +//记得先初始化 | ||
| 27 | +static T_JZsdkReturnCode TaskMgmt_sample() | ||
| 28 | +{ | ||
| 29 | + TaskData* data = (TaskData*)malloc(sizeof(TaskData)); | ||
| 30 | + if (data == NULL) | ||
| 31 | + { | ||
| 32 | + //内存注册失败 | ||
| 33 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + data->num = 1; | ||
| 37 | + data->str = "A"; | ||
| 38 | + | ||
| 39 | + T_JZsdkReturnCode ret = TaskManagement_SubmitTask(TaskMgmt_sample_funtion, data); | ||
| 40 | + if (ret != JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS) | ||
| 41 | + { | ||
| 42 | + free(data); | ||
| 43 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 47 | +} |
JZsdk_Common/README.txt
0 → 100644
| 1 | +为方便在多个板子之间移植 | ||
| 2 | +sdk包被我分成了多个部分 | ||
| 3 | +1、Base文件 | ||
| 4 | +不需要依赖任何第三方环境,只需要在linux上跑,同时为其他地方,如module提供延时函数等 | ||
| 5 | +2、JZsdk_Normal_Module | ||
| 6 | +功能模组合集,为了移植时不依赖第三方文件或板子环境,使用JZsdk_module_inport.c进行参数提供 | ||
| 7 | +当你需要使用第三方参数给module时,你应该把接口写在Module_InPort,后Module内的模块调用Module_Inport | ||
| 8 | + | ||
| 9 | +当你需要给第三方参数时 | ||
| 10 | +同样应该使用 JZsdk_Module_OutPort.c进行提供 |
JZsdk_Config/BaseConfig.c
0 → 100644
| 1 | +#include <stdio.h> | ||
| 2 | +#include <stdlib.h> | ||
| 3 | +#include <pthread.h> | ||
| 4 | +#include <string.h> | ||
| 5 | + | ||
| 6 | +#include "JZsdkLib.h" | ||
| 7 | + | ||
| 8 | +#include "version_choose.h" | ||
| 9 | +#include "ircut.h" | ||
| 10 | +#include "Megaphone/Megaphone.h" | ||
| 11 | +#include "Gimbal_InAndOut.h" | ||
| 12 | + | ||
| 13 | +#include "JZsdk_uart/JZsdk_Uart_Input.h" | ||
| 14 | +#include "BaseConfig.h" | ||
| 15 | +#include "Psdk_UI_io.h" | ||
| 16 | + | ||
| 17 | +#include "Lighting_InAndOut.h" | ||
| 18 | +#include "JZsdk_network/JZsdk_network.h" | ||
| 19 | + | ||
| 20 | +#include "JZsdk_TaskManagement/TaskManagement.h" | ||
| 21 | +#include "JZsdk_haldata_deal/JZsdk_data_transmisson.h" | ||
| 22 | +#include "MediaProc/MediaProc.h" | ||
| 23 | +#include "UI_control/WidegMgmt/JZsdk_Widget.h" | ||
| 24 | + | ||
| 25 | +#if APP_VERSION == APP_PSDK | ||
| 26 | +#include "fc_subscription/test_fc_subscription.h" | ||
| 27 | +#endif | ||
| 28 | +#include "DeviceInfo/DeviceInfo.h" | ||
| 29 | + | ||
| 30 | +#if MEGAPHONE_CONFIG_STATUS == VERSION_SWITCH_ON | ||
| 31 | + #include "AudioDeal/AudioDeal.h" | ||
| 32 | + #include "Megaphone/Megaphone.h" | ||
| 33 | +#endif | ||
| 34 | + | ||
| 35 | +#if SIDE_LASER_STATUS_ON | ||
| 36 | + #include "SideLaser/SideLaser.h" | ||
| 37 | +#endif | ||
| 38 | + | ||
| 39 | +static int Main_WorkMode(); | ||
| 40 | +static void *Main_WorkModeTask(void *arg); | ||
| 41 | +static int WorkMode = JZ_FLAGCODE_OFF; | ||
| 42 | + | ||
| 43 | +extern int MegaphoneStatusFlag; | ||
| 44 | +static int g_All_filter_Mode = JZ_FLAGCODE_OFF; //用于m30的滤波开关 | ||
| 45 | +static int StartupPriorityNum = JZ_FLAGCODE_OFF; //优先启动项值 | ||
| 46 | + | ||
| 47 | + | ||
| 48 | + | ||
| 49 | +/******************* | ||
| 50 | + * | ||
| 51 | + * mode get 是未获取 m30滤波开关 | ||
| 52 | + * 其他值为set+get | ||
| 53 | + * | ||
| 54 | + * ********************/ | ||
| 55 | +T_JZsdkReturnCode Main_M30_all_filter_mode(int *mode) | ||
| 56 | +{ | ||
| 57 | + | ||
| 58 | +//喊话器功能被打开时 | ||
| 59 | +#if MEGAPHONE_CONFIG_STATUS == VERSION_SWITCH_ON | ||
| 60 | + if (*mode == JZ_FLAGCODE_GET) | ||
| 61 | + { | ||
| 62 | + *mode = g_All_filter_Mode; | ||
| 63 | + printf("滤波模式获取%d\n",*mode); | ||
| 64 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 65 | + } | ||
| 66 | + else if ( (*mode != JZ_FLAGCODE_ON) && (*mode != JZ_FLAGCODE_OFF) ) | ||
| 67 | + { | ||
| 68 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 69 | + } | ||
| 70 | + else | ||
| 71 | + { | ||
| 72 | + printf("滤波模式设置%d\n",*mode); | ||
| 73 | + g_All_filter_Mode = *mode; | ||
| 74 | + if (*mode == JZ_FLAGCODE_ON) | ||
| 75 | + { | ||
| 76 | + //先关闭播放 | ||
| 77 | + Megaphone_StopPlay(JZ_FLAGCODE_OFF); | ||
| 78 | + | ||
| 79 | + | ||
| 80 | + //修改滤波 | ||
| 81 | + AudioDeal_FilterReset(0x01); | ||
| 82 | + } | ||
| 83 | + else | ||
| 84 | + { | ||
| 85 | + //先关闭播放 | ||
| 86 | + Megaphone_StopPlay(JZ_FLAGCODE_OFF); | ||
| 87 | + | ||
| 88 | + | ||
| 89 | + //修改滤波 | ||
| 90 | + AudioDeal_FilterReset(0x00); | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + } | ||
| 94 | +#endif | ||
| 95 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 96 | +} | ||
| 97 | + | ||
| 98 | +/*** ************************* ************************* | ||
| 99 | + * | ||
| 100 | + * 判断设备是否可用 | ||
| 101 | + * return 0 可用 | ||
| 102 | + * return 1 未激活 | ||
| 103 | + * return 2 海外版检测到在国外不可用 | ||
| 104 | + * | ||
| 105 | + * ******************** ******************************/ | ||
| 106 | +int Main_Device_Wheather_Use() | ||
| 107 | +{ | ||
| 108 | + //先判断是否有激活 | ||
| 109 | + T_JZsdkReturnCode ret = SerialMAT_Get_SerialNumberStatus(); | ||
| 110 | + if(ret == 0x02 || ret == 0x03) | ||
| 111 | + { | ||
| 112 | + //未激活 返回1 | ||
| 113 | + return 1; | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + // //如果是国外版,判断是否在国内 //以后再单独领出一个模块 | ||
| 117 | + if (FIRMWARE_ORIGIN == OVERSEAS_VERSION) | ||
| 118 | + { | ||
| 119 | +#if APP_VERSION == APP_PSDK | ||
| 120 | + //如果处于中国境内 | ||
| 121 | + if (Subscription_WhetherInChina() == 1) | ||
| 122 | + { | ||
| 123 | + return 2; | ||
| 124 | + } | ||
| 125 | +#endif | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + return 0; | ||
| 129 | +} | ||
| 130 | + | ||
| 131 | + | ||
| 132 | +T_JZsdkReturnCode Main_APP_Psdk() | ||
| 133 | +{ | ||
| 134 | + //sdklib加载 | ||
| 135 | + JZsdk_LibInit(); | ||
| 136 | + | ||
| 137 | + JZSDK_LOG_INFO("%x,PsdkVersion%x.%x.%x.%x\n",DEVICE_VERSION,MAJOR_VERSION, MINOR_VERSION, MODIFY_VERSION, DEBUG_VERSION); | ||
| 138 | + | ||
| 139 | + //引脚初始化 | ||
| 140 | + Ircut_Init(); | ||
| 141 | + | ||
| 142 | + //设备信息初始化 | ||
| 143 | + DeviceInfo_Init(); | ||
| 144 | + | ||
| 145 | + //工作模式设置函数,用于超时,及播放启动语音等 | ||
| 146 | + Main_WorkMode(); | ||
| 147 | + | ||
| 148 | + //外接传输模块 | ||
| 149 | + JZsdk_data_transmisson_Receive_Init(); | ||
| 150 | + | ||
| 151 | + //喊话器功能被打开时 | ||
| 152 | + if (MEGAPHONE_CONFIG_STATUS == VERSION_SWITCH_ON) | ||
| 153 | + { | ||
| 154 | + //音频库初始化 | ||
| 155 | + AudioDeal_Init(); | ||
| 156 | + | ||
| 157 | + // | ||
| 158 | + } | ||
| 159 | + | ||
| 160 | + | ||
| 161 | + if (DEVICE_VERSION == TF_A1) | ||
| 162 | + { | ||
| 163 | + //串口设备1初始化 | ||
| 164 | + //JZsdk_Uart_Init(UART_DEV_1); | ||
| 165 | + | ||
| 166 | + //串口设备2初始化 | ||
| 167 | + JZsdk_Uart_Init(UART_DEV_2); | ||
| 168 | + | ||
| 169 | + //喊话器初始化 | ||
| 170 | + Megaphone_Init(); | ||
| 171 | + | ||
| 172 | + //云台初始化 | ||
| 173 | + Gimbal_Init(); | ||
| 174 | + | ||
| 175 | + //灯类初始化 | ||
| 176 | + Lighting_Init(); | ||
| 177 | + | ||
| 178 | + delayMs(1000); | ||
| 179 | + | ||
| 180 | + //消息订阅初始化 | ||
| 181 | + JZsdk_Uart_Send_MessageSubcription_Control(UART_DEV_2, JZ_FLAGCODE_ON); | ||
| 182 | + } | ||
| 183 | + | ||
| 184 | + else if (DEVICE_VERSION == JZ_H1E) | ||
| 185 | + { | ||
| 186 | + //串口设备1初始化 | ||
| 187 | + //JZsdk_Uart_Init(UART_DEV_1); | ||
| 188 | + | ||
| 189 | + //喊话器初始化 | ||
| 190 | + Megaphone_Init(); | ||
| 191 | + } | ||
| 192 | + | ||
| 193 | + else if (DEVICE_VERSION == JZ_H1T) | ||
| 194 | + { | ||
| 195 | + //串口设备1初始化 | ||
| 196 | + //JZsdk_Uart_Init(UART_DEV_1); | ||
| 197 | + | ||
| 198 | + //4g设备初始化 | ||
| 199 | + JZsdk_Uart_Init(UART_4G); | ||
| 200 | + | ||
| 201 | + //喊话器初始化 | ||
| 202 | + Megaphone_Init(); | ||
| 203 | + | ||
| 204 | + //云台初始化 | ||
| 205 | + Gimbal_Init(); | ||
| 206 | + } | ||
| 207 | + | ||
| 208 | + else if (DEVICE_VERSION == JZ_H150S || DEVICE_VERSION == JZ_H150T) | ||
| 209 | + { | ||
| 210 | + //串口设备1初始化 | ||
| 211 | + // JZsdk_Uart_Init(UART_DEV_1); | ||
| 212 | + | ||
| 213 | + if (DEVICE_VERSION == JZ_H150T) | ||
| 214 | + { | ||
| 215 | + //4g设备初始化 | ||
| 216 | + JZsdk_Uart_Init(UART_4G); | ||
| 217 | + } | ||
| 218 | + | ||
| 219 | + //喊话器初始化 | ||
| 220 | + Megaphone_Init(); | ||
| 221 | + | ||
| 222 | + //云台初始化 | ||
| 223 | + Gimbal_Init(); | ||
| 224 | + | ||
| 225 | + //相机初始化 | ||
| 226 | + MediaProc_Init(); | ||
| 227 | + } | ||
| 228 | + | ||
| 229 | + else if (DEVICE_VERSION == JZ_H10) | ||
| 230 | + { | ||
| 231 | + //串口设备1初始化 | ||
| 232 | + // JZsdk_Uart_Init(UART_DEV_1); | ||
| 233 | + | ||
| 234 | + //喊话器初始化 | ||
| 235 | + Megaphone_Init(); | ||
| 236 | + | ||
| 237 | + //云台初始化 | ||
| 238 | + Gimbal_Init(); | ||
| 239 | + } | ||
| 240 | + | ||
| 241 | + else if (DEVICE_VERSION == JZ_H10T) | ||
| 242 | + { | ||
| 243 | + //串口设备1初始化 | ||
| 244 | + //JZsdk_Uart_Init(UART_DEV_1); | ||
| 245 | + | ||
| 246 | + //4g设备初始化 | ||
| 247 | + JZsdk_Uart_Init(UART_4G); | ||
| 248 | + | ||
| 249 | + //喊话器初始化 | ||
| 250 | + Megaphone_Init(); | ||
| 251 | + | ||
| 252 | + //云台初始化 | ||
| 253 | + Gimbal_Init(); | ||
| 254 | + } | ||
| 255 | + | ||
| 256 | + else if (DEVICE_VERSION == JZ_U3) | ||
| 257 | + { | ||
| 258 | + //串口设备1初始化 | ||
| 259 | + //JZsdk_Uart_Init(UART_DEV_1); | ||
| 260 | + | ||
| 261 | + //串口设备2初始化 | ||
| 262 | + JZsdk_Uart_Init(UART_DEV_2); | ||
| 263 | + | ||
| 264 | + //喊话器初始化 | ||
| 265 | + Megaphone_Init(); | ||
| 266 | + | ||
| 267 | + //云台初始化 | ||
| 268 | + Gimbal_Init(); | ||
| 269 | + | ||
| 270 | + //灯类初始化 | ||
| 271 | + Lighting_Init(); | ||
| 272 | + | ||
| 273 | + delayMs(1000); | ||
| 274 | + | ||
| 275 | + //消息订阅初始化 | ||
| 276 | + JZsdk_Uart_Send_MessageSubcription_Control(UART_DEV_2, JZ_FLAGCODE_ON); | ||
| 277 | + } | ||
| 278 | + | ||
| 279 | + else if (DEVICE_VERSION == JZ_U3S) | ||
| 280 | + { | ||
| 281 | + //串口设备1初始化 | ||
| 282 | + //JZsdk_Uart_Init(UART_DEV_1); | ||
| 283 | + | ||
| 284 | + //串口设备2初始化 | ||
| 285 | + JZsdk_Uart_Init(UART_DEV_2); | ||
| 286 | + | ||
| 287 | + //喊话器初始化 | ||
| 288 | + Megaphone_Init(); | ||
| 289 | + | ||
| 290 | + //云台初始化 | ||
| 291 | + Gimbal_Init(); | ||
| 292 | + | ||
| 293 | + //灯类初始化 | ||
| 294 | + Lighting_Init(); | ||
| 295 | + | ||
| 296 | + //侧边激光初始化 | ||
| 297 | + SideLaser_Init(); | ||
| 298 | + | ||
| 299 | + delayMs(1000); | ||
| 300 | + | ||
| 301 | + //消息订阅初始化 | ||
| 302 | + JZsdk_Uart_Send_MessageSubcription_Control(UART_DEV_2, JZ_FLAGCODE_ON); | ||
| 303 | + } | ||
| 304 | + | ||
| 305 | + else if (DEVICE_VERSION == JZ_C1) | ||
| 306 | + { | ||
| 307 | + //引脚初始化 | ||
| 308 | + Ircut_Init(); | ||
| 309 | + | ||
| 310 | + //视频流模块初始化 | ||
| 311 | + MediaProc_Init(); | ||
| 312 | + } | ||
| 313 | + | ||
| 314 | + | ||
| 315 | + //初始化控件 | ||
| 316 | + JZSDK_WidgetMgMT_Init(); | ||
| 317 | + | ||
| 318 | + //初始化app模式 | ||
| 319 | + JZsdk_Set_Psdk_UIcontrol_UseFlag(1); | ||
| 320 | + | ||
| 321 | + Main_WorkModeSet(JZ_FLAGCODE_ON); | ||
| 322 | + | ||
| 323 | +} | ||
| 324 | + | ||
| 325 | + | ||
| 326 | + | ||
| 327 | +int Main_APP_Uart() | ||
| 328 | +{ | ||
| 329 | + //lib库初始化 | ||
| 330 | + JZsdk_LibInit(); | ||
| 331 | + | ||
| 332 | + JZSDK_LOG_INFO("%x,UartVersion%x.%x.%x.%x\n",DEVICE_VERSION,MAJOR_VERSION, MINOR_VERSION, MODIFY_VERSION, DEBUG_VERSION); | ||
| 333 | + | ||
| 334 | + //引脚初始化 | ||
| 335 | + Ircut_Init(); | ||
| 336 | + | ||
| 337 | + //设备信息初始化 | ||
| 338 | + DeviceInfo_Init(); | ||
| 339 | + | ||
| 340 | + //工作模式设置函数,用于超时,及播放启动语音等 | ||
| 341 | + Main_WorkMode(); | ||
| 342 | + | ||
| 343 | + //喊话器功能被打开时 | ||
| 344 | + if (MEGAPHONE_CONFIG_STATUS == VERSION_SWITCH_ON) | ||
| 345 | + { | ||
| 346 | + //音频库初始化 | ||
| 347 | + AudioDeal_Init(); | ||
| 348 | + | ||
| 349 | + // | ||
| 350 | + } | ||
| 351 | + | ||
| 352 | + if (DEVICE_VERSION == JZ_H1E) | ||
| 353 | + { | ||
| 354 | + //串口设备1初始化 | ||
| 355 | + JZsdk_Uart_Init(UART_DEV_1); | ||
| 356 | + | ||
| 357 | + //喊话器初始化 | ||
| 358 | + Megaphone_Init(); | ||
| 359 | + } | ||
| 360 | + | ||
| 361 | + if (DEVICE_VERSION == JZ_H1T) | ||
| 362 | + { | ||
| 363 | + //串口设备1初始化 | ||
| 364 | + JZsdk_Uart_Init(UART_DEV_1); | ||
| 365 | + | ||
| 366 | + //4g设备初始化 | ||
| 367 | + JZsdk_Uart_Init(UART_4G); | ||
| 368 | + | ||
| 369 | + //喊话器初始化 | ||
| 370 | + Megaphone_Init(); | ||
| 371 | + | ||
| 372 | + //云台初始化 | ||
| 373 | + Gimbal_Init(); | ||
| 374 | + | ||
| 375 | + // //测试增加选项 | ||
| 376 | + // //开启循环 | ||
| 377 | + // JZsdk_Uart_audio_PlayLoop(UART_DEV_1, 1); | ||
| 378 | + | ||
| 379 | + // //设置音量 | ||
| 380 | + // JZsdk_Uart_Set_Volume(UART_DEV_1, 50); | ||
| 381 | + } | ||
| 382 | + | ||
| 383 | + if (DEVICE_VERSION == JZ_H150S || DEVICE_VERSION == JZ_H150T) | ||
| 384 | + { | ||
| 385 | + //串口设备1初始化 | ||
| 386 | + JZsdk_Uart_Init(UART_DEV_1); | ||
| 387 | + | ||
| 388 | + //网口初始化 | ||
| 389 | + JZsdk_NetWork_Init(); | ||
| 390 | + | ||
| 391 | + if (DEVICE_VERSION == JZ_H150T) | ||
| 392 | + { | ||
| 393 | + //4g设备初始化 | ||
| 394 | + JZsdk_Uart_Init(UART_4G); | ||
| 395 | + } | ||
| 396 | + | ||
| 397 | + //云台初始化 | ||
| 398 | + Gimbal_Init(); | ||
| 399 | + | ||
| 400 | + //相机初始化 | ||
| 401 | + MediaProc_Init(); | ||
| 402 | + | ||
| 403 | + //喊话器初始化 | ||
| 404 | + Megaphone_Init(); | ||
| 405 | + } | ||
| 406 | + | ||
| 407 | + if (DEVICE_VERSION == JZ_H10) | ||
| 408 | + { | ||
| 409 | + //串口设备1初始化 | ||
| 410 | + JZsdk_Uart_Init(UART_DEV_1); | ||
| 411 | + | ||
| 412 | + //H10和10t固定打开滤波 | ||
| 413 | + int filter_mode = JZ_FLAGCODE_ON; | ||
| 414 | + Main_M30_all_filter_mode(&filter_mode); | ||
| 415 | + | ||
| 416 | + //喊话器初始化 | ||
| 417 | + Megaphone_Init(); | ||
| 418 | + | ||
| 419 | + //云台初始化 | ||
| 420 | + Gimbal_Init(); | ||
| 421 | + } | ||
| 422 | + | ||
| 423 | + if (DEVICE_VERSION == JZ_H10T) | ||
| 424 | + { | ||
| 425 | + //串口设备1初始化 | ||
| 426 | + JZsdk_Uart_Init(UART_DEV_1); | ||
| 427 | + | ||
| 428 | + //4g设备初始化 | ||
| 429 | + JZsdk_Uart_Init(UART_4G); | ||
| 430 | + | ||
| 431 | + //H10和10t固定打开滤波 | ||
| 432 | + int filter_mode = JZ_FLAGCODE_ON; | ||
| 433 | + Main_M30_all_filter_mode(&filter_mode); | ||
| 434 | + | ||
| 435 | + //喊话器初始化 | ||
| 436 | + Megaphone_Init(); | ||
| 437 | + | ||
| 438 | + //云台初始化 | ||
| 439 | + Gimbal_Init(); | ||
| 440 | + } | ||
| 441 | + | ||
| 442 | + if (DEVICE_VERSION == JZ_U3) | ||
| 443 | + { | ||
| 444 | + //串口设备1初始化 | ||
| 445 | + JZsdk_Uart_Init(UART_DEV_1); | ||
| 446 | + | ||
| 447 | + //串口设备2初始化 | ||
| 448 | + JZsdk_Uart_Init(UART_DEV_2); | ||
| 449 | + | ||
| 450 | + //喊话器初始化 | ||
| 451 | + Megaphone_Init(); | ||
| 452 | + | ||
| 453 | + //云台初始化 | ||
| 454 | + Gimbal_Init(); | ||
| 455 | + | ||
| 456 | + //灯类初始化 | ||
| 457 | + Lighting_Init(); | ||
| 458 | + | ||
| 459 | + delayMs(1000); | ||
| 460 | + | ||
| 461 | + //消息订阅初始化 | ||
| 462 | + JZsdk_Uart_Send_MessageSubcription_Control(UART_DEV_2, JZ_FLAGCODE_ON); | ||
| 463 | + | ||
| 464 | + // //测试需要开启亮度 | ||
| 465 | + // JZsdk_Uart_SearchLight_Control(UART_DEV_1, 1); | ||
| 466 | + // JZsdk_Uart_SearchLight_Lumen(UART_DEV_1, 20, 20); | ||
| 467 | + | ||
| 468 | + } | ||
| 469 | + | ||
| 470 | + | ||
| 471 | + | ||
| 472 | + if (DEVICE_VERSION == TF_A1) | ||
| 473 | + { | ||
| 474 | + //串口设备1初始化 | ||
| 475 | + JZsdk_Uart_Init(UART_DEV_1); | ||
| 476 | + | ||
| 477 | + //串口设备2初始化 | ||
| 478 | + JZsdk_Uart_Init(UART_DEV_2); | ||
| 479 | + | ||
| 480 | + //喊话器初始化 | ||
| 481 | + Megaphone_Init(); | ||
| 482 | + | ||
| 483 | + //云台初始化 | ||
| 484 | + Gimbal_Init(); | ||
| 485 | + | ||
| 486 | + //消息订阅初始化 | ||
| 487 | + JZsdk_Uart_Send_MessageSubcription_Control(UART_DEV_2, JZ_FLAGCODE_ON); | ||
| 488 | + } | ||
| 489 | + | ||
| 490 | +} | ||
| 491 | + | ||
| 492 | +int Main_TestAPP() | ||
| 493 | +{ | ||
| 494 | + //串口设备1初始化 | ||
| 495 | + JZsdk_Uart_Init(UART_DEV_1); | ||
| 496 | +} | ||
| 497 | + | ||
| 498 | +//JZ_FLAGCODE_GET为返回工作值,其他值为设置 | ||
| 499 | +int Main_WorkModeSet(int mode) | ||
| 500 | +{ | ||
| 501 | + if (mode == JZ_FLAGCODE_GET) | ||
| 502 | + { | ||
| 503 | + return WorkMode; | ||
| 504 | + } | ||
| 505 | + | ||
| 506 | + WorkMode = mode; | ||
| 507 | + | ||
| 508 | + //如果工作模式被打开 | ||
| 509 | + if ( (WorkMode == JZ_FLAGCODE_ON) && (APP_VERSION == APP_UART) ) | ||
| 510 | + { | ||
| 511 | + int flag = 0x00; | ||
| 512 | + Main_StartupPriority(&flag); | ||
| 513 | + } | ||
| 514 | + | ||
| 515 | + return WorkMode; | ||
| 516 | +} | ||
| 517 | + | ||
| 518 | +static int Main_GetStartupPriorityStatus() | ||
| 519 | +{ | ||
| 520 | + if( JZsdk_check_file_exists("/root/Uart_connected") == JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS) | ||
| 521 | + { | ||
| 522 | + StartupPriorityNum = 0x00; | ||
| 523 | + } | ||
| 524 | + else //目前只有psdk和串口的优先区分 | ||
| 525 | + { | ||
| 526 | + StartupPriorityNum = 0x01; | ||
| 527 | + } | ||
| 528 | + | ||
| 529 | + return StartupPriorityNum; | ||
| 530 | +} | ||
| 531 | + | ||
| 532 | +//设置优先启动项 | ||
| 533 | +//0x00 优先启动串口程序 | ||
| 534 | +//0x01 优先大疆PSDK | ||
| 535 | +// | ||
| 536 | +T_JZsdkReturnCode Main_StartupPriority(int *choose) | ||
| 537 | +{ | ||
| 538 | + if (*choose == JZ_FLAGCODE_GET) | ||
| 539 | + { | ||
| 540 | + printf("获取优先启动项\n"); | ||
| 541 | + | ||
| 542 | + //1、查询本地的是否存在优先启动值 | ||
| 543 | + Main_GetStartupPriorityStatus(); | ||
| 544 | + | ||
| 545 | + //2、返回优先启动值 | ||
| 546 | + *choose = StartupPriorityNum; | ||
| 547 | + | ||
| 548 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 549 | + } | ||
| 550 | + else | ||
| 551 | + { | ||
| 552 | + //1、设置本地的版本号 | ||
| 553 | + if (*choose == 0x00) | ||
| 554 | + { | ||
| 555 | + //增加uart连接标志 | ||
| 556 | + if(JZsdk_create_file("/root/Uart_connected") != JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS) | ||
| 557 | + { | ||
| 558 | + JZSDK_LOG_ERROR("优先启动Uart模式失败"); | ||
| 559 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 560 | + } | ||
| 561 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 562 | + } | ||
| 563 | + else if (*choose == 0x01) | ||
| 564 | + { | ||
| 565 | + //连接后清除串口标志 | ||
| 566 | + if(JZsdk_delete_file("/root/Uart_connected") != JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS) | ||
| 567 | + { | ||
| 568 | + JZSDK_LOG_ERROR("优先启动psdk模式失败"); | ||
| 569 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 570 | + } | ||
| 571 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 572 | + } | ||
| 573 | + else | ||
| 574 | + { | ||
| 575 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 576 | + } | ||
| 577 | + } | ||
| 578 | +} | ||
| 579 | + | ||
| 580 | + | ||
| 581 | +static int Main_WorkMode() | ||
| 582 | +{ | ||
| 583 | + pthread_t work_mode_task; | ||
| 584 | + pthread_attr_t task_attribute; //线程属性 | ||
| 585 | + pthread_attr_init(&task_attribute); //初始化线程属性 | ||
| 586 | + pthread_attr_setdetachstate(&task_attribute, PTHREAD_CREATE_DETACHED); //设置线程属性 | ||
| 587 | + int timer = pthread_create(&work_mode_task,&task_attribute,Main_WorkModeTask,NULL); //线程 | ||
| 588 | + if(timer != 0) | ||
| 589 | + { | ||
| 590 | + printf("创建计时线程失败!\n"); | ||
| 591 | + } | ||
| 592 | +} | ||
| 593 | + | ||
| 594 | + | ||
| 595 | +static void *Main_WorkModeTask(void *arg) | ||
| 596 | +{ | ||
| 597 | + //计时flag | ||
| 598 | + int i=0; | ||
| 599 | + printf("进入串口等待函数\n"); | ||
| 600 | + int start_voice_flag = JZ_FLAGCODE_OFF; | ||
| 601 | + | ||
| 602 | +#if APP_VERSION == APP_UART | ||
| 603 | + for (i = 0; i < 60; i++) | ||
| 604 | + { | ||
| 605 | +#if CONNECTION_TIMED_OUT == VERSION_SWITCH_OFF | ||
| 606 | + break; | ||
| 607 | +#endif | ||
| 608 | + | ||
| 609 | + delayMs(1000);//延迟一秒钟 | ||
| 610 | + printf("计数%d\n",i); | ||
| 611 | + | ||
| 612 | + if (start_voice_flag == JZ_FLAGCODE_OFF && MegaphoneStatusFlag == JZ_FLAGCODE_ON) | ||
| 613 | + { | ||
| 614 | + start_voice_flag = JZ_FLAGCODE_ON; | ||
| 615 | + Start_voice(); | ||
| 616 | + } | ||
| 617 | + | ||
| 618 | + if (WorkMode == JZ_FLAGCODE_ON) | ||
| 619 | + { | ||
| 620 | + printf("串口连接成功,进入串口模式\n"); | ||
| 621 | + printf("连接花费时间%i秒\n",i); | ||
| 622 | + i = 0; | ||
| 623 | + break; | ||
| 624 | + } | ||
| 625 | + } | ||
| 626 | + | ||
| 627 | + if(i==60 && WorkMode == JZ_FLAGCODE_OFF && CONNECTION_TIMED_OUT == VERSION_SWITCH_ON) | ||
| 628 | + { | ||
| 629 | + printf("串口连接超时,回到连接psdk"); | ||
| 630 | + exit(0); | ||
| 631 | + } | ||
| 632 | +#elif APP_VERSION == APP_PSDK | ||
| 633 | + | ||
| 634 | +#endif | ||
| 635 | + | ||
| 636 | +#if MEGAPHONE_CONFIG_STATUS == VERSION_SWITCH_ON | ||
| 637 | + while (1) | ||
| 638 | + { | ||
| 639 | + if (start_voice_flag == JZ_FLAGCODE_OFF && MegaphoneStatusFlag == JZ_FLAGCODE_ON) | ||
| 640 | + { | ||
| 641 | + start_voice_flag = JZ_FLAGCODE_ON; | ||
| 642 | + Start_voice(); | ||
| 643 | + } | ||
| 644 | + | ||
| 645 | + //如果开启工作模式已经打开,且喊话模块已经初始化完毕,播报启动完成 | ||
| 646 | + if (WorkMode == JZ_FLAGCODE_ON && MegaphoneStatusFlag == JZ_FLAGCODE_ON && start_voice_flag == JZ_FLAGCODE_ON) | ||
| 647 | + { | ||
| 648 | + | ||
| 649 | + Start_up_and_broadcast_voice(); | ||
| 650 | + break; | ||
| 651 | + } | ||
| 652 | + | ||
| 653 | + delayMs(100); | ||
| 654 | + } | ||
| 655 | +#endif | ||
| 656 | +} | ||
| 657 | + |
JZsdk_Config/BaseConfig.h
0 → 100644
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file | ||
| 4 | + * | ||
| 5 | + * | ||
| 6 | + ********************************************************************* | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/ | ||
| 10 | +#ifndef BASECONFIG_H | ||
| 11 | +#define BASECONFIG_H | ||
| 12 | + | ||
| 13 | +/* Includes ------------------------------------------------------------------*/ | ||
| 14 | +#include "version_choose.h" | ||
| 15 | +#include "JZsdkLib.h" | ||
| 16 | +#ifdef __cplusplus | ||
| 17 | +extern "C" { | ||
| 18 | +#endif | ||
| 19 | + | ||
| 20 | +/* Exported constants --------------------------------------------------------*/ | ||
| 21 | +/* 常亮定义*/ | ||
| 22 | +#define DEVICE_PSDK 0x1000 //psdk功能 | ||
| 23 | +#define UART_4G 0x1001 //4G功能 | ||
| 24 | +#define UART_DEV_1 0x1002 //1号设备功能 | ||
| 25 | +#define UART_DEV_2 0x1003 //2号设备功能 | ||
| 26 | +#define UART_DEV_3 0x1004 //3号设备功能 | ||
| 27 | +#define UART_DEV_4 0x1005 //4号设备功能 | ||
| 28 | +#define UART_DEV_5 0x1006 //5号设备功能 | ||
| 29 | + | ||
| 30 | +#define UART_USB_1 0x1100 //usb设备 | ||
| 31 | +#define UART_USB_2 0x1101 //usb设备 | ||
| 32 | +#define UART_USB_3 0x1102 //usb设备 | ||
| 33 | +#define UART_USB_4 0x1103 //usb设备 | ||
| 34 | +#define UART_USB_5 0x1104 //usb设备 | ||
| 35 | + | ||
| 36 | +#define HAL_DATA_TRANSMISSION 0x1200 //hal定制的特殊数据传播 | ||
| 37 | + | ||
| 38 | + | ||
| 39 | +#define COMBINE_DEVICE 0x1998 //组合设备 | ||
| 40 | +#define NO_SPECIFIED 0x1999 //无制定设备 | ||
| 41 | + | ||
| 42 | +//展架通讯串口 | ||
| 43 | +#if DEVICE_VERSION == JZ_H150S || DEVICE_VERSION == JZ_H150T | ||
| 44 | + #define UART_DEV1_NUM "/dev/ttyUSB0" | ||
| 45 | + #define UART_DEV1_BITRATE (115200) | ||
| 46 | + | ||
| 47 | + #define UART_DEV2_NUM NULL | ||
| 48 | + #define UART_DEV2_BITRATE (0) | ||
| 49 | + | ||
| 50 | + #define COMM_4G_UART_NUM "/dev/ttyS1" | ||
| 51 | + #define COMM_4G_UART_BITRATE (115200) | ||
| 52 | + | ||
| 53 | + #define GIMBAL_UART_NUM "/dev/ttyS2" | ||
| 54 | + #define GIMBAL_UART_BITRATE (115200) | ||
| 55 | + | ||
| 56 | + #define NET_WORK_IPADDR "192.168.5.3" | ||
| 57 | + #define NET_WORK_TARGET_IPADDR "192.168.5.10" | ||
| 58 | + #define NET_WORK_NETMASK "255.255.255.0" | ||
| 59 | + | ||
| 60 | +#elif DEVICE_VERSION == JZ_H1E | ||
| 61 | + #define UART_DEV1_NUM "/dev/ttyS1" | ||
| 62 | + #define UART_DEV1_BITRATE (115200) | ||
| 63 | + | ||
| 64 | + #define UART_DEV2_NUM NULL | ||
| 65 | + #define UART_DEV2_BITRATE (0) | ||
| 66 | + | ||
| 67 | + #define COMM_4G_UART_NUM NULL | ||
| 68 | + #define COMM_4G_UART_BITRATE (0) | ||
| 69 | + | ||
| 70 | + #define GIMBAL_UART_NUM NULL | ||
| 71 | + #define GIMBAL_UART_BITRATE (0) | ||
| 72 | + | ||
| 73 | + #define NET_WORK_IPADDR NULL | ||
| 74 | + #define NET_WORK_TARGET_IPADDR NULL | ||
| 75 | + #define NET_WORK_NETMASK NULL | ||
| 76 | + | ||
| 77 | +#elif DEVICE_VERSION == JZ_H1T | ||
| 78 | + #define UART_DEV1_NUM "/dev/ttyS2" | ||
| 79 | + #define UART_DEV1_BITRATE (115200) | ||
| 80 | + | ||
| 81 | + #define UART_DEV2_NUM NULL | ||
| 82 | + #define UART_DEV2_BITRATE (0) | ||
| 83 | + | ||
| 84 | + #define COMM_4G_UART_NUM "/dev/ttyS1" | ||
| 85 | + #define COMM_4G_UART_BITRATE (115200) | ||
| 86 | + | ||
| 87 | + #define GIMBAL_UART_NUM NULL | ||
| 88 | + #define GIMBAL_UART_BITRATE (0) | ||
| 89 | + | ||
| 90 | + #define NET_WORK_IPADDR NULL | ||
| 91 | + #define NET_WORK_TARGET_IPADDR NULL | ||
| 92 | + #define NET_WORK_NETMASK NULL | ||
| 93 | + | ||
| 94 | +#elif DEVICE_VERSION == JZ_H10 | ||
| 95 | + #define UART_DEV1_NUM "/dev/ttyUSB0" | ||
| 96 | + #define UART_DEV1_BITRATE (115200) | ||
| 97 | + | ||
| 98 | + #define UART_DEV2_NUM NULL | ||
| 99 | + #define UART_DEV2_BITRATE (0) | ||
| 100 | + | ||
| 101 | + #define COMM_4G_UART_NUM NULL | ||
| 102 | + #define COMM_4G_UART_BITRATE (0) | ||
| 103 | + | ||
| 104 | + #define GIMBAL_UART_NUM NULL | ||
| 105 | + #define GIMBAL_UART_BITRATE (0) | ||
| 106 | + | ||
| 107 | + #define NET_WORK_IPADDR NULL | ||
| 108 | + #define NET_WORK_TARGET_IPADDR NULL | ||
| 109 | + #define NET_WORK_NETMASK NULL | ||
| 110 | + | ||
| 111 | +#elif DEVICE_VERSION == JZ_H10T | ||
| 112 | + #define UART_DEV1_NUM "/dev/ttyS2" | ||
| 113 | + #define UART_DEV1_BITRATE (115200) | ||
| 114 | + | ||
| 115 | + #define UART_DEV2_NUM NULL | ||
| 116 | + #define UART_DEV2_BITRATE (0) | ||
| 117 | + | ||
| 118 | + #define COMM_4G_UART_NUM "/dev/ttyS1" | ||
| 119 | + #define COMM_4G_UART_BITRATE (115200) | ||
| 120 | + | ||
| 121 | + #define GIMBAL_UART_NUM NULL | ||
| 122 | + #define GIMBAL_UART_BITRATE (0) | ||
| 123 | + | ||
| 124 | + #define NET_WORK_IPADDR NULL | ||
| 125 | + #define NET_WORK_TARGET_IPADDR NULL | ||
| 126 | + #define NET_WORK_NETMASK NULL | ||
| 127 | + | ||
| 128 | +#elif DEVICE_VERSION == JZ_U3 | ||
| 129 | + #define UART_DEV1_NUM "/dev/ttyS1" | ||
| 130 | + #define UART_DEV1_BITRATE (115200) | ||
| 131 | + | ||
| 132 | + #define UART_DEV2_NUM "/dev/ttyS2" | ||
| 133 | + #define UART_DEV2_BITRATE (115200) | ||
| 134 | + | ||
| 135 | + #define COMM_4G_UART_NUM NULL | ||
| 136 | + #define COMM_4G_UART_BITRATE (0) | ||
| 137 | + | ||
| 138 | + #define GIMBAL_UART_NUM NULL | ||
| 139 | + #define GIMBAL_UART_BITRATE (0) | ||
| 140 | + | ||
| 141 | + #define NET_WORK_IPADDR NULL | ||
| 142 | + #define NET_WORK_TARGET_IPADDR NULL | ||
| 143 | + #define NET_WORK_NETMASK NULL | ||
| 144 | + | ||
| 145 | +#elif DEVICE_VERSION == JZ_U3S | ||
| 146 | + #define UART_DEV1_NUM "/dev/ttyS1" | ||
| 147 | + #define UART_DEV1_BITRATE (115200) | ||
| 148 | + | ||
| 149 | + #define UART_DEV2_NUM "/dev/ttyS2" | ||
| 150 | + #define UART_DEV2_BITRATE (115200) | ||
| 151 | + | ||
| 152 | + #define COMM_4G_UART_NUM NULL | ||
| 153 | + #define COMM_4G_UART_BITRATE (0) | ||
| 154 | + | ||
| 155 | + #define GIMBAL_UART_NUM NULL | ||
| 156 | + #define GIMBAL_UART_BITRATE (0) | ||
| 157 | + | ||
| 158 | + #define NET_WORK_IPADDR NULL | ||
| 159 | + #define NET_WORK_TARGET_IPADDR NULL | ||
| 160 | + #define NET_WORK_NETMASK NULL | ||
| 161 | + | ||
| 162 | +#elif DEVICE_VERSION == JZ_U3D | ||
| 163 | + #define UART_DEV1_NUM "/dev/ttyS1" | ||
| 164 | + #define UART_DEV1_BITRATE (115200) | ||
| 165 | + | ||
| 166 | + #define UART_DEV2_NUM "/dev/ttyS2" | ||
| 167 | + #define UART_DEV2_BITRATE (115200) | ||
| 168 | + | ||
| 169 | + #define COMM_4G_UART_NUM NULL | ||
| 170 | + #define COMM_4G_UART_BITRATE (0) | ||
| 171 | + | ||
| 172 | + #define GIMBAL_UART_NUM NULL | ||
| 173 | + #define GIMBAL_UART_BITRATE (0) | ||
| 174 | + | ||
| 175 | + #define NET_WORK_IPADDR NULL | ||
| 176 | + #define NET_WORK_TARGET_IPADDR NULL | ||
| 177 | + #define NET_WORK_NETMASK NULL | ||
| 178 | + | ||
| 179 | +#elif DEVICE_VERSION == TF_A1 | ||
| 180 | + #define UART_DEV1_NUM "/dev/ttyS2" | ||
| 181 | + #define UART_DEV1_BITRATE (115200) | ||
| 182 | + | ||
| 183 | + #define UART_DEV2_NUM "/dev/ttyS1" | ||
| 184 | + #define UART_DEV2_BITRATE (115200) | ||
| 185 | + | ||
| 186 | + #define COMM_4G_UART_NUM NULL | ||
| 187 | + #define COMM_4G_UART_BITRATE (0) | ||
| 188 | + | ||
| 189 | + #define GIMBAL_UART_NUM NULL | ||
| 190 | + #define GIMBAL_UART_BITRATE (0) | ||
| 191 | + | ||
| 192 | + #define NET_WORK_IPADDR NULL | ||
| 193 | + #define NET_WORK_TARGET_IPADDR NULL | ||
| 194 | + #define NET_WORK_NETMASK NULL | ||
| 195 | + | ||
| 196 | +#elif DEVICE_VERSION == JZ_C1 | ||
| 197 | + #define UART_DEV1_NUM "/dev/ttyUSB0" | ||
| 198 | + #define UART_DEV1_BITRATE (115200) | ||
| 199 | + | ||
| 200 | + #define UART_DEV2_NUM NULL | ||
| 201 | + #define UART_DEV2_BITRATE (115200) | ||
| 202 | + | ||
| 203 | + #define COMM_4G_UART_NUM NULL | ||
| 204 | + #define COMM_4G_UART_BITRATE (0) | ||
| 205 | + | ||
| 206 | + #define GIMBAL_UART_NUM NULL | ||
| 207 | + #define GIMBAL_UART_BITRATE (0) | ||
| 208 | + | ||
| 209 | + #define NET_WORK_IPADDR NULL | ||
| 210 | + #define NET_WORK_TARGET_IPADDR NULL | ||
| 211 | + #define NET_WORK_NETMASK NULL | ||
| 212 | + | ||
| 213 | +#else | ||
| 214 | + #define UART_DEV1_NUM NULL | ||
| 215 | + #define UART_DEV1_BITRATE (0) | ||
| 216 | + | ||
| 217 | + #define UART_DEV2_NUM NULL | ||
| 218 | + #define UART_DEV2_BITRATE (0) | ||
| 219 | + | ||
| 220 | + #define COMM_4G_UART_NUM NULL | ||
| 221 | + #define COMM_4G_UART_BITRATE (0) | ||
| 222 | + | ||
| 223 | + #define GIMBAL_UART_NUM NULL | ||
| 224 | + #define GIMBAL_UART_BITRATE (0) | ||
| 225 | + | ||
| 226 | + #define NET_WORK_IPADDR NULL | ||
| 227 | + #define NET_WORK_TARGET_IPADDR NULL | ||
| 228 | + #define NET_WORK_NETMASK NULL | ||
| 229 | + | ||
| 230 | +#endif | ||
| 231 | + | ||
| 232 | + | ||
| 233 | +/* Exported types ------------------------------------------------------------*/ | ||
| 234 | + | ||
| 235 | +/* Exported functions --------------------------------------------------------*/ | ||
| 236 | +int Main_WorkModeSet(int mode); | ||
| 237 | +int Main_APP_Uart(); | ||
| 238 | +T_JZsdkReturnCode Main_APP_Psdk(); | ||
| 239 | +int Main_TestAPP(); | ||
| 240 | +int Main_Device_Wheather_Use(); | ||
| 241 | +T_JZsdkReturnCode Main_M30_all_filter_mode(int *mode); | ||
| 242 | +T_JZsdkReturnCode Main_StartupPriority(int *choose); | ||
| 243 | +T_JZsdkReturnCode Main_SetDeviceName(unsigned int Port, int g_DeviceID); | ||
| 244 | + | ||
| 245 | +#ifdef __cplusplus | ||
| 246 | +} | ||
| 247 | +#endif | ||
| 248 | + | ||
| 249 | +#endif |
JZsdk_Config/ConfigParams.h
0 → 100644
| 1 | +/* ******************************************************************** | ||
| 2 | +* | ||
| 3 | +* 用来规范version_choose的参数 | ||
| 4 | +* | ||
| 5 | +***********************************************/ | ||
| 6 | +#ifndef CONFIG_PARAMS_H | ||
| 7 | +#define CONFIG_PARAMS_H | ||
| 8 | + | ||
| 9 | +//特殊版本号 | ||
| 10 | +#define SPECIAL_NORMAL 0x01 | ||
| 11 | +#define SPECIAL_DAOTONG 0x02 | ||
| 12 | + | ||
| 13 | +//软件模式 | ||
| 14 | +#define APP_PSDK 0x01 //psdk设备 | ||
| 15 | +#define APP_UART 0x02 //串口设备 | ||
| 16 | +#define APP_TEST 0x03 //测试设备 | ||
| 17 | + | ||
| 18 | +//平台选择 | ||
| 19 | +#define PLATFORM_H3 0x01 | ||
| 20 | +#define PLATFORM_V3S 0x02 | ||
| 21 | + | ||
| 22 | +//固件属地 | ||
| 23 | +#define OVERSEAS_VERSION 0x01 //海外版 | ||
| 24 | +#define DOMESTIC_VERSION 0x02 //国内版 | ||
| 25 | + | ||
| 26 | +//音频滤波的方式 | ||
| 27 | +//目前只有和h10使用带阻滤波 | ||
| 28 | +#define DIRECTED_STOPBAND_FILTERING 0x10001 //带阻滤波 | ||
| 29 | +#define HIGH_PASS_FILTERING 0x10002 //高通滤波 | ||
| 30 | +#define INTERGRATED_FILTERING_1 0x10003 //综合滤波1代 | ||
| 31 | + | ||
| 32 | +//加载开关 | ||
| 33 | +#define VERSION_SWITCH_ON 0x0001 | ||
| 34 | +#define VERSION_SWITCH_OFF 0x0000 | ||
| 35 | + | ||
| 36 | +//设备选择 | ||
| 37 | +#define JZ_H1E 0x0011 | ||
| 38 | + | ||
| 39 | +#define JZ_H1T 0x0016 | ||
| 40 | + | ||
| 41 | +#define JZ_U3 0x0017 | ||
| 42 | +#define JZ_U3S 0x0018 | ||
| 43 | +#define JZ_U3D 0x0019 | ||
| 44 | + | ||
| 45 | +#define JZ_H150S 0x0013 | ||
| 46 | +#define JZ_H150T 0x0015 | ||
| 47 | + | ||
| 48 | +#define JZ_H10 0x0012 | ||
| 49 | +#define JZ_H10T 0x0014 | ||
| 50 | + | ||
| 51 | +#define TF_A1 0x1010 | ||
| 52 | +#define JZ_C1 0x1011 | ||
| 53 | + | ||
| 54 | +#endif |
JZsdk_Config/version_choose.h
0 → 100644
| 1 | +/* ******************************************************************** | ||
| 2 | +* | ||
| 3 | +* 用于确认对应设备的选择 | ||
| 4 | +* | ||
| 5 | +***********************************************/ | ||
| 6 | +#ifndef VERSION_CHOOSE_H | ||
| 7 | +#define VERSION_CHOOSE_H | ||
| 8 | +#include "./ConfigParams.h" | ||
| 9 | +//1~10行 除了D可以修改版本选择 禁止动任何东西 | ||
| 10 | +#define DEVICE_VERSION JZ_H1T | ||
| 11 | + | ||
| 12 | +//禁止修改行 选择是串口程序 还是 psdk程序 | ||
| 13 | +#define APP_VERSION APP_UART | ||
| 14 | + | ||
| 15 | +//禁止修改行 板子型号 | ||
| 16 | +#define PLATFORM_VERSION PLATFORM_V3S | ||
| 17 | + | ||
| 18 | +//禁止修改行 串口连接程序的软件版本号 | ||
| 19 | +#define MAJOR_VERSION 0x00 | ||
| 20 | +#define MINOR_VERSION 0x00 | ||
| 21 | +#define MODIFY_VERSION 0x02 | ||
| 22 | +#define DEBUG_VERSION 0x04 | ||
| 23 | + | ||
| 24 | +//禁止修改行 滤波方式 | ||
| 25 | +#define FILTERING_TYPE HIGH_PASS_FILTERING | ||
| 26 | + | ||
| 27 | +//禁止修改行固件属地 目前 国内版/海外版 | ||
| 28 | +#define FIRMWARE_ORIGIN DOMESTIC_VERSION | ||
| 29 | + | ||
| 30 | +//禁止修改行指定特殊固件 | ||
| 31 | +#define SPECIAL_VERSION SPECIAL_NORMAL | ||
| 32 | + | ||
| 33 | +//禁止修改行 全志编解码库 | ||
| 34 | +#define ALLWINNER_CEDAR VERSION_SWITCH_OFF | ||
| 35 | + | ||
| 36 | +//禁止修改行 是否开启连接超时 | ||
| 37 | +#define CONNECTION_TIMED_OUT VERSION_SWITCH_OFF | ||
| 38 | + | ||
| 39 | +//这个开关可以方便日常代码编写的跳转功能 | ||
| 40 | +#ifdef COMPILE_MODE_MODULE | ||
| 41 | + //是否开启喊话器功能 | ||
| 42 | + #ifdef MACRO_MEGAPHONE_MODULE | ||
| 43 | + #define MEGAPHONE_CONFIG_STATUS VERSION_SWITCH_ON | ||
| 44 | + #else | ||
| 45 | + #define MEGAPHONE_CONFIG_STATUS VERSION_SWITCH_OFF | ||
| 46 | + #endif | ||
| 47 | + | ||
| 48 | + //是否开启媒体功能 | ||
| 49 | + #ifdef MACRO_MEDIA_PROC_MODULE | ||
| 50 | + #define MEDIA_PROC_CONFIG_STATUS VERSION_SWITCH_ON | ||
| 51 | + #else | ||
| 52 | + #define MEDIA_PROC_CONFIG_STATUS VERSION_SWITCH_OFF | ||
| 53 | + #endif | ||
| 54 | + | ||
| 55 | + //是否开启红外相机功能 | ||
| 56 | + #ifdef MACRO_IRC_MODULE | ||
| 57 | + #define IRC_CONFIG_STATUS VERSION_SWITCH_ON | ||
| 58 | + #else | ||
| 59 | + #define IRC_CONFIG_STATUS VERSION_SWITCH_OFF | ||
| 60 | + #endif | ||
| 61 | + | ||
| 62 | + //是否加载usb模块 | ||
| 63 | + #ifdef MACRO_USB_MODULE | ||
| 64 | + #define USB_CONFIG_STATUS VERSION_SWITCH_ON | ||
| 65 | + #else | ||
| 66 | + #define USB_CONFIG_STATUS VERSION_SWITCH_OFF | ||
| 67 | + #endif | ||
| 68 | + | ||
| 69 | + //是否加载RTK_MPP模块 | ||
| 70 | + #ifdef MACRO_RTK_MPP_MODULE | ||
| 71 | + #define RTK_MPP_STATUS VERSION_SWITCH_ON | ||
| 72 | + #else | ||
| 73 | + #define RTK_MPP_STATUS VERSION_SWITCH_OFF | ||
| 74 | + #endif | ||
| 75 | + | ||
| 76 | + //是否加载WIRINGPI模块 | ||
| 77 | + #ifdef MACRO_WIRINGPI_MODULE | ||
| 78 | + #define WIRINGPI_STATUS VERSION_SWITCH_ON | ||
| 79 | + #else | ||
| 80 | + #define WIRINGPI_STATUS VERSION_SWITCH_OFF | ||
| 81 | + #endif | ||
| 82 | + | ||
| 83 | + //是否加载侧边激光模块 | ||
| 84 | + #ifdef MACRO_SIDE_LASER_MODULE | ||
| 85 | + #define SIDE_LASER_STATUS_ON | ||
| 86 | + #endif | ||
| 87 | + | ||
| 88 | +#else | ||
| 89 | + //是否开启喊话器功能 | ||
| 90 | + #define MEGAPHONE_CONFIG_STATUS VERSION_SWITCH_ON | ||
| 91 | + | ||
| 92 | + //是否开启媒体管理功能 | ||
| 93 | + #define MEDIA_PROC_CONFIG_STATUS VERSION_SWITCH_ON | ||
| 94 | + | ||
| 95 | + //是否开启红外相机功能 | ||
| 96 | + #define IRC_CONFIG_STATUS VERSION_SWITCH_ON | ||
| 97 | + | ||
| 98 | + //是否加载usb模块 | ||
| 99 | + #define USB_CONFIG_STATUS VERSION_SWITCH_ON | ||
| 100 | + | ||
| 101 | + //是否加载RTK_MPP模块 | ||
| 102 | + #define RTK_MPP_STATUS VERSION_SWITCH_ON | ||
| 103 | + | ||
| 104 | + //是否加载WIRINGPI模块 | ||
| 105 | + #define WIRINGPI_STATUS VERSION_SWITCH_ON | ||
| 106 | + | ||
| 107 | + //是否加载侧边激光模块 | ||
| 108 | + #define SIDE_LASER_STATUS_ON | ||
| 109 | +#endif | ||
| 110 | + | ||
| 111 | +#endif |
| 1 | +#include <stdio.h> | ||
| 2 | +#include <string.h> | ||
| 3 | +#include <stdlib.h> | ||
| 4 | +#include <pthread.h> | ||
| 5 | + | ||
| 6 | +#include "JZsdk_TaskManagement/TaskManagement.h" | ||
| 7 | +#include "JZsdk_Base/JZsdk_Code/JZsdk_Code.h" | ||
| 8 | +#include "JZsdk_Base/JZsdk_FrameComparsion/JZsdk_FrameComparsion.h" | ||
| 9 | +#include "JZsdk_uart/JZsdk_Uart_UartDeal.h" | ||
| 10 | +#include "BaseConfig.h" | ||
| 11 | + | ||
| 12 | +typedef struct | ||
| 13 | +{ | ||
| 14 | + char Message[1024]; // 传递的字符串 | ||
| 15 | + int MessageLength; // 字符串的长度 | ||
| 16 | + int ResLen; //剩余长度 | ||
| 17 | + pthread_mutex_t WriteMutex; // 互斥锁 | ||
| 18 | + pthread_mutex_t ReadMutex; // 互斥锁 | ||
| 19 | +} JZsdk_data_transmisson; | ||
| 20 | + | ||
| 21 | +#define BUFFER_SIZE 128*1024 // 128k的缓冲区 | ||
| 22 | +static unsigned char DataTransmissonBuffer[BUFFER_SIZE]; //data_transmisson的被动接收缓冲区 | ||
| 23 | +static int buffer_head = 0; //缓冲区的写入标志位 | ||
| 24 | +static int buffer_end = 0; //缓冲区的写出标志位 | ||
| 25 | +static void *JZsdk_hal_data_rece(void *arg); | ||
| 26 | +static void *JZsdk_hal_data_deal(void *arg); | ||
| 27 | +static pthread_mutex_t DataTransmissonLock; | ||
| 28 | +static int DataTransFlag = JZ_FLAGCODE_OFF; //用于判断初始化完成 | ||
| 29 | + | ||
| 30 | +/**************** | ||
| 31 | + * | ||
| 32 | + * 计算缓冲区剩余容量 | ||
| 33 | + * | ||
| 34 | + * **************/ | ||
| 35 | +static int JZsdk_data_transmisson_buffer_GetEmpty() | ||
| 36 | +{ | ||
| 37 | + int empty; | ||
| 38 | + | ||
| 39 | + //后续要找办法处理数据段长度的问题,目前先用大空间存储 | ||
| 40 | + | ||
| 41 | + //头在尾后面 说明目前数组缓冲区组成为 空数据 尾巴 实数据 头部 空数据 | ||
| 42 | + if (buffer_head >= buffer_end) | ||
| 43 | + { | ||
| 44 | + empty = BUFFER_SIZE - (buffer_head - buffer_end); | ||
| 45 | + } | ||
| 46 | + //尾在头后面 说明目前数组缓冲区组成为 实数据 头部 空数据 尾巴 实数据 | ||
| 47 | + else if (buffer_head < buffer_end) | ||
| 48 | + { | ||
| 49 | + empty = (buffer_end - buffer_head); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + return empty; | ||
| 53 | +} | ||
| 54 | + | ||
| 55 | +/**************** | ||
| 56 | + * | ||
| 57 | + * 池满判断 | ||
| 58 | + * | ||
| 59 | + * **************/ | ||
| 60 | +static int JZsdk_data_transmisson_buffer_WriteDataEndReset() //池满判断 | ||
| 61 | +{ | ||
| 62 | + if (buffer_end >= BUFFER_SIZE) | ||
| 63 | + { | ||
| 64 | + buffer_end = 0; | ||
| 65 | + } | ||
| 66 | +} | ||
| 67 | +static int JZsdk_data_transmisson_buffer_WriteDataHeadReset() //池满判断 | ||
| 68 | +{ | ||
| 69 | + if (buffer_head >= BUFFER_SIZE) | ||
| 70 | + { | ||
| 71 | + buffer_head = 0; | ||
| 72 | + } | ||
| 73 | +} | ||
| 74 | + | ||
| 75 | +/****************************************************************** | ||
| 76 | + | ||
| 77 | + 初始化hal口数据接收 | ||
| 78 | + | ||
| 79 | +******************************************************************/ | ||
| 80 | +int JZsdk_data_transmisson_Receive(unsigned char *data, int data_len) | ||
| 81 | +{ | ||
| 82 | + //初始化完成前不能使用 | ||
| 83 | + if (DataTransFlag == JZ_FLAGCODE_OFF) | ||
| 84 | + { | ||
| 85 | + return 0 ; | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + int temp_lenth = 0; //临时长度; | ||
| 89 | + | ||
| 90 | + //后续要增加缓冲区大小判断,避免出现问题 | ||
| 91 | + //计算当前缓冲区的剩余容量 | ||
| 92 | + int buffer_empty = JZsdk_data_transmisson_buffer_GetEmpty(); | ||
| 93 | + if (buffer_empty < data_len) | ||
| 94 | + { | ||
| 95 | + data_len = buffer_empty; | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + // 在写入解码前加锁 | ||
| 99 | + pthread_mutex_lock(&DataTransmissonLock); | ||
| 100 | + | ||
| 101 | + while( (data_len - temp_lenth) > 0) | ||
| 102 | + { | ||
| 103 | + DataTransmissonBuffer[buffer_head] = data [temp_lenth]; | ||
| 104 | + temp_lenth+=1; | ||
| 105 | + buffer_head+=1; //池尾后移一组 | ||
| 106 | + JZsdk_data_transmisson_buffer_WriteDataHeadReset() ; //池满判断 | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + // 在解码数据后解锁 | ||
| 110 | + pthread_mutex_unlock(&DataTransmissonLock); | ||
| 111 | +} | ||
| 112 | + | ||
| 113 | +/****************************************************************** | ||
| 114 | + | ||
| 115 | + 初始化hal口数据接收初始化 | ||
| 116 | + | ||
| 117 | +******************************************************************/ | ||
| 118 | +int JZsdk_data_transmisson_Receive_Init() | ||
| 119 | +{ | ||
| 120 | + int ret = 0; | ||
| 121 | + pthread_t Uart_rece_task; | ||
| 122 | + | ||
| 123 | + pthread_attr_t task_attribute; // 线程属性 | ||
| 124 | + pthread_attr_init(&task_attribute); // 初始化线程属性 | ||
| 125 | + pthread_attr_setdetachstate(&task_attribute, PTHREAD_CREATE_DETACHED); // 设置线程属性 | ||
| 126 | + | ||
| 127 | + | ||
| 128 | + | ||
| 129 | + JZsdk_data_transmisson *parameter = (JZsdk_data_transmisson *)malloc(sizeof(JZsdk_data_transmisson)); | ||
| 130 | + parameter->MessageLength = 0; | ||
| 131 | + memset(parameter->Message, 0, sizeof(parameter->Message)); | ||
| 132 | + | ||
| 133 | + pthread_mutex_init(&DataTransmissonLock, NULL); //初始化锁 | ||
| 134 | + pthread_mutex_init(¶meter->WriteMutex, NULL); | ||
| 135 | + pthread_mutex_init(¶meter->ReadMutex, NULL); | ||
| 136 | + | ||
| 137 | + // 创建串口数据接收线程 | ||
| 138 | + pthread_t receiveThread; | ||
| 139 | + pthread_t SerialDealThread; | ||
| 140 | + pthread_attr_t task_attribute1; // 线程属性 | ||
| 141 | + pthread_attr_t task_attribute2; // 线程属性 | ||
| 142 | + pthread_attr_setdetachstate(&task_attribute1, PTHREAD_CREATE_DETACHED); // 设置线程分离属性 | ||
| 143 | + pthread_attr_setdetachstate(&task_attribute2, PTHREAD_CREATE_DETACHED); // 设置线程分离属性 | ||
| 144 | + | ||
| 145 | + pthread_attr_init(&task_attribute1); | ||
| 146 | + pthread_attr_init(&task_attribute2); | ||
| 147 | + | ||
| 148 | + if (pthread_create(&receiveThread, &task_attribute1, JZsdk_hal_data_rece, parameter) != 0) | ||
| 149 | + { | ||
| 150 | + JZSDK_LOG_ERROR("Failed to create receive thread"); | ||
| 151 | + return 1; | ||
| 152 | + } | ||
| 153 | + | ||
| 154 | + // 创建串口数据处理线程 | ||
| 155 | + if (pthread_create(&SerialDealThread, &task_attribute2, JZsdk_hal_data_deal, parameter) != 0) | ||
| 156 | + { | ||
| 157 | + JZSDK_LOG_ERROR("Failed to create receive thread"); | ||
| 158 | + return 1; | ||
| 159 | + } | ||
| 160 | + | ||
| 161 | + DataTransFlag = JZ_FLAGCODE_ON; | ||
| 162 | + | ||
| 163 | + JZSDK_LOG_INFO("hal数据传输模块初始化完成"); | ||
| 164 | +} | ||
| 165 | + | ||
| 166 | + | ||
| 167 | +/*** | ||
| 168 | + * | ||
| 169 | + * 数据读取函数 | ||
| 170 | + * 获取数据的数组str | ||
| 171 | + * 最多可以获取max_get_len的长度 | ||
| 172 | + * ***/ | ||
| 173 | +static int Buffer_get_data(unsigned char *str, int max_get_len) | ||
| 174 | +{ | ||
| 175 | + int return_len; //返回的长度 | ||
| 176 | + | ||
| 177 | + //头在尾后面 说明目前数组缓冲区组成为 空数据 尾巴 实数据 头部 空数据 | ||
| 178 | + if (buffer_head >= buffer_end) | ||
| 179 | + { | ||
| 180 | + if (max_get_len >= (buffer_head-buffer_end)) | ||
| 181 | + { | ||
| 182 | + return_len = (buffer_head-buffer_end); | ||
| 183 | + memcpy(str, &DataTransmissonBuffer[buffer_end], return_len); | ||
| 184 | + buffer_end +=return_len; | ||
| 185 | + JZsdk_data_transmisson_buffer_WriteDataEndReset(); | ||
| 186 | + return return_len; | ||
| 187 | + } | ||
| 188 | + else | ||
| 189 | + { | ||
| 190 | + return_len = max_get_len; | ||
| 191 | + memcpy(str, &DataTransmissonBuffer[buffer_end], return_len); | ||
| 192 | + buffer_end +=return_len; | ||
| 193 | + JZsdk_data_transmisson_buffer_WriteDataEndReset(); | ||
| 194 | + return return_len; | ||
| 195 | + } | ||
| 196 | + } | ||
| 197 | + | ||
| 198 | + //尾在头后面 说明目前数组缓冲区组成为 实数据 头部 空数据 尾巴 实数据 | ||
| 199 | + else if (buffer_head < buffer_end) | ||
| 200 | + { | ||
| 201 | + if (max_get_len >= ( (BUFFER_SIZE-buffer_end) + buffer_head) ) | ||
| 202 | + { | ||
| 203 | + return_len = ( (BUFFER_SIZE-buffer_end) + buffer_head); | ||
| 204 | + memcpy(str, &DataTransmissonBuffer[buffer_end], (BUFFER_SIZE-buffer_end)); | ||
| 205 | + | ||
| 206 | + memcpy(str + (BUFFER_SIZE-buffer_end), &DataTransmissonBuffer[0], buffer_head); | ||
| 207 | + buffer_end = buffer_head; | ||
| 208 | + JZsdk_data_transmisson_buffer_WriteDataEndReset(); | ||
| 209 | + return return_len; | ||
| 210 | + } | ||
| 211 | + else if(max_get_len < ( (BUFFER_SIZE-buffer_end) + buffer_head) ) | ||
| 212 | + { | ||
| 213 | + // 实数据 头部 空数据 尾巴 大于接收区的实数据 | ||
| 214 | + if (max_get_len <= (BUFFER_SIZE-buffer_end) ) | ||
| 215 | + { | ||
| 216 | + return_len = max_get_len; | ||
| 217 | + memcpy(str, &DataTransmissonBuffer[buffer_end], return_len); | ||
| 218 | + buffer_end+=max_get_len; | ||
| 219 | + JZsdk_data_transmisson_buffer_WriteDataEndReset(); | ||
| 220 | + return return_len; | ||
| 221 | + } | ||
| 222 | + // 实数据 头部 空数据 尾巴 小于接收区的实数据 | ||
| 223 | + else | ||
| 224 | + { | ||
| 225 | + return_len = max_get_len; | ||
| 226 | + memcpy(str, &DataTransmissonBuffer[buffer_end], (BUFFER_SIZE-buffer_end)); | ||
| 227 | + | ||
| 228 | + memcpy(str, &DataTransmissonBuffer[0], (max_get_len - (BUFFER_SIZE-buffer_end) ) ); | ||
| 229 | + buffer_end = (max_get_len - (BUFFER_SIZE-buffer_end) ); | ||
| 230 | + JZsdk_data_transmisson_buffer_WriteDataEndReset(); | ||
| 231 | + return return_len; | ||
| 232 | + } | ||
| 233 | + | ||
| 234 | + } | ||
| 235 | + } | ||
| 236 | + | ||
| 237 | + | ||
| 238 | + return return_len; | ||
| 239 | +} | ||
| 240 | + | ||
| 241 | +/*** | ||
| 242 | + * | ||
| 243 | + * 数据接收线程 | ||
| 244 | + * | ||
| 245 | + * ***/ | ||
| 246 | +static void *JZsdk_hal_data_rece(void *arg) | ||
| 247 | +{ | ||
| 248 | + | ||
| 249 | + JZsdk_data_transmisson *args = (JZsdk_data_transmisson *)arg; | ||
| 250 | + | ||
| 251 | + memset(args->Message, 0, sizeof(args->Message)); // 清空接收数组 | ||
| 252 | + args->ResLen = 0; | ||
| 253 | + args->MessageLength = 0; | ||
| 254 | + | ||
| 255 | + int data_len; | ||
| 256 | + int data_len2; | ||
| 257 | + | ||
| 258 | + while (1) | ||
| 259 | + { | ||
| 260 | + // 检查fs_read套接字是否有数据 | ||
| 261 | + if (buffer_head == buffer_end) | ||
| 262 | + { | ||
| 263 | + delayMs(1); | ||
| 264 | + | ||
| 265 | + // 超时 | ||
| 266 | + continue; | ||
| 267 | + } | ||
| 268 | + | ||
| 269 | + // 如果有数据就加锁 | ||
| 270 | + pthread_mutex_lock(&args->WriteMutex); | ||
| 271 | + | ||
| 272 | + // 读取串口内容 | ||
| 273 | + int bytesRead = Buffer_get_data(&(args->Message[args->ResLen]), (sizeof(args->Message) - args->ResLen)); | ||
| 274 | + printf("bytesRead %d\n",bytesRead); | ||
| 275 | + | ||
| 276 | + if (bytesRead > 0) | ||
| 277 | + { | ||
| 278 | + args->MessageLength = args->ResLen + bytesRead; | ||
| 279 | + | ||
| 280 | + // data_len+=bytesRead; | ||
| 281 | + // data_len2+=args->MessageLength; | ||
| 282 | + // printf("当前接收长度%d bytesRead%d bmessage%d reslen%d\n",data_len,bytesRead,data_len2,args->ResLen); | ||
| 283 | + | ||
| 284 | + // JZSDK_LOG_INFO("从串口读取到,长度%d",(args->MessageLength-args->ResLen)); | ||
| 285 | + | ||
| 286 | + // for (int i = 0; i < (args->MessageLength-args->ResLen); i++) | ||
| 287 | + // { | ||
| 288 | + // JZSDK_LOG_OUTPUTHEX("%s",&args->Message[i+args->ResLen]); | ||
| 289 | + // } | ||
| 290 | + | ||
| 291 | + args->ResLen = 0; | ||
| 292 | + } | ||
| 293 | + else if (bytesRead == 0) | ||
| 294 | + { | ||
| 295 | + // 串口关闭或者无数据可读 | ||
| 296 | + JZSDK_LOG_ERROR("hal数据传输,读取数据为空"); | ||
| 297 | + args->MessageLength = 0; | ||
| 298 | + args->ResLen = 0; | ||
| 299 | + memset(&(args->Message[0]), 0, sizeof(args->Message)); | ||
| 300 | + } | ||
| 301 | + else | ||
| 302 | + { | ||
| 303 | + // 读取错误发生 | ||
| 304 | + JZSDK_LOG_ERROR("hal数据传输读取错误"); | ||
| 305 | + args->MessageLength = 0; | ||
| 306 | + args->ResLen = 0; | ||
| 307 | + memset(&(args->Message[0]), 0, sizeof(args->Message)); | ||
| 308 | + } | ||
| 309 | + | ||
| 310 | + // 通知线程 | ||
| 311 | + pthread_mutex_unlock(&args->ReadMutex); // 解锁 | ||
| 312 | + | ||
| 313 | + delayMs(3); // 加多了可能导致实时播放难恢复,以及声音间隔 3ms32字节 会向上约1个3ms opus一帧80字节 | ||
| 314 | + } | ||
| 315 | + | ||
| 316 | +} | ||
| 317 | + | ||
| 318 | +/*** | ||
| 319 | + * | ||
| 320 | + * 串口处理线程 | ||
| 321 | + * | ||
| 322 | + * ***/ | ||
| 323 | +// 串口数据处理线程函数 | ||
| 324 | +static void *JZsdk_hal_data_deal(void *arg) | ||
| 325 | +{ | ||
| 326 | + JZsdk_data_transmisson *args = (JZsdk_data_transmisson *)arg; | ||
| 327 | + | ||
| 328 | + static int ResidualLength = 0; // 未处理数据长度 | ||
| 329 | + | ||
| 330 | + while (1) | ||
| 331 | + { | ||
| 332 | + | ||
| 333 | + // 加锁 | ||
| 334 | + pthread_mutex_lock(&args->ReadMutex); | ||
| 335 | + | ||
| 336 | + // data_len+=args->MessageLength; | ||
| 337 | + // printf("当前处理长度%d\n",data_len); | ||
| 338 | + | ||
| 339 | + if (args->MessageLength > 0) | ||
| 340 | + { | ||
| 341 | + | ||
| 342 | + //清除错误的多余半帧 | ||
| 343 | + //前面有帧的长度 | ||
| 344 | + if(args->ResLen != 0) | ||
| 345 | + { | ||
| 346 | + //存在第一帧,同时第二轮的数据开头是帧头,则清空前半段第一帧 | ||
| 347 | + if ( (args->Message[args->ResLen ] == 0x5A) | ||
| 348 | + && (args->Message[args->ResLen + 1] == 0x5A) | ||
| 349 | + && (args->Message[args->ResLen + 2] == 0x77) ) | ||
| 350 | + { | ||
| 351 | + int temp_num; | ||
| 352 | + temp_num = args->MessageLength - args->ResLen; | ||
| 353 | + if (temp_num < 0) | ||
| 354 | + { | ||
| 355 | + temp_num = 0; | ||
| 356 | + } | ||
| 357 | + | ||
| 358 | + memcpy(args->Message, &(args->Message[args->ResLen]), temp_num); | ||
| 359 | + memset(&args->Message[temp_num], 0, (args->MessageLength - temp_num)); | ||
| 360 | + args->MessageLength = temp_num; | ||
| 361 | + args->ResLen = 0; | ||
| 362 | + | ||
| 363 | + JZSDK_LOG_ERROR("串口上一帧为不完全帧,舍弃该帧操作"); | ||
| 364 | + } | ||
| 365 | + } | ||
| 366 | + | ||
| 367 | + // 处理数据 | ||
| 368 | + ResidualLength = UartDeal_Recv_interface(1,HAL_DATA_TRANSMISSION, args->Message, args->MessageLength); | ||
| 369 | + //如果还有剩余的长度 | ||
| 370 | + if (ResidualLength != 0) | ||
| 371 | + { | ||
| 372 | + memcpy(args->Message, &(args->Message[args->MessageLength - ResidualLength]), ResidualLength); | ||
| 373 | + memset(&(args->Message[ResidualLength]), 0, (sizeof(args->Message) - ResidualLength)); | ||
| 374 | + args->MessageLength = 0; | ||
| 375 | + args->ResLen = ResidualLength; | ||
| 376 | + } | ||
| 377 | + else | ||
| 378 | + { | ||
| 379 | + memset(args->Message, 0, sizeof(args->Message)); | ||
| 380 | + args->MessageLength = 0; | ||
| 381 | + args->ResLen = 0; | ||
| 382 | + } | ||
| 383 | + | ||
| 384 | + } | ||
| 385 | + else | ||
| 386 | + { | ||
| 387 | + memset(args->Message, 0, sizeof(args->Message)); | ||
| 388 | + args->MessageLength = 0; | ||
| 389 | + args->ResLen = 0; | ||
| 390 | + } | ||
| 391 | + | ||
| 392 | + pthread_mutex_unlock(&args->WriteMutex); // 解锁 | ||
| 393 | + } | ||
| 394 | +} | ||
| 395 | + |
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file JZsdk_data_transmisson.h | ||
| 4 | + * JZsdk_data_transmisson的头文件 | ||
| 5 | + * | ||
| 6 | + ********************************************************************* | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/ | ||
| 10 | +#ifndef JZSDK_DATA_TRANS_MISSION_H | ||
| 11 | +#define JZSDK_DATA_TRANS_MISSION_H | ||
| 12 | + | ||
| 13 | +/* Includes ------------------------------------------------------------------*/ | ||
| 14 | + | ||
| 15 | +#ifdef __cplusplus | ||
| 16 | +extern "C" { | ||
| 17 | +#endif | ||
| 18 | + | ||
| 19 | +/* Exported constants --------------------------------------------------------*/ | ||
| 20 | +/* 常亮定义*/ | ||
| 21 | +#include "JZsdk_Base/JZsdk_Code/JZsdk_Code.h" | ||
| 22 | + | ||
| 23 | +/* Exported types ------------------------------------------------------------*/ | ||
| 24 | + | ||
| 25 | +/* Exported functions --------------------------------------------------------*/ | ||
| 26 | +int JZsdk_data_transmisson_Receive_Init(); | ||
| 27 | +int JZsdk_data_transmisson_Receive(unsigned char *data, int data_len); | ||
| 28 | + | ||
| 29 | +#ifdef __cplusplus | ||
| 30 | +} | ||
| 31 | +#endif | ||
| 32 | + | ||
| 33 | +#endif |
JZsdk_hal/JZsdk_network/JZsdk_network.c
0 → 100644
| 1 | +#include <stdio.h> | ||
| 2 | +#include <string.h> | ||
| 3 | +#include <stdlib.h> | ||
| 4 | +#include <termios.h> | ||
| 5 | +#include <sys/socket.h> | ||
| 6 | +#include <netinet/in.h> | ||
| 7 | +#include <arpa/inet.h> | ||
| 8 | + | ||
| 9 | +#include "BaseConfig.h" | ||
| 10 | +#include "version_choose.h" | ||
| 11 | + | ||
| 12 | +#include "JZsdkLib.h" | ||
| 13 | +#include "./JZsdk_network.h" | ||
| 14 | + | ||
| 15 | +#define LINUX_CMD_STR_MAX_SIZE (128) | ||
| 16 | +#define LINUX_NETWORK_DEV "eth0" | ||
| 17 | +#define UDP_SERVER_PORT (23003) | ||
| 18 | + | ||
| 19 | +#define MAX_SEND_FRAME_LENTH (60000) | ||
| 20 | + | ||
| 21 | +#define JZSDK_UTIL_MIN(a, b) (((a) < (b)) ? (a) : (b)) | ||
| 22 | + | ||
| 23 | +static int udp_socket = 0; | ||
| 24 | +static struct sockaddr_in udp_server_addr; | ||
| 25 | +static int NetworkMode = JZ_FLAGCODE_OFF; //网络模式 | ||
| 26 | + | ||
| 27 | +T_JZsdkReturnCode JZsdk_NetWork_Init() | ||
| 28 | +{ | ||
| 29 | + T_JZsdkReturnCode ret; | ||
| 30 | + char cmdStr[LINUX_CMD_STR_MAX_SIZE]; | ||
| 31 | + | ||
| 32 | + if (NET_WORK_IPADDR == NULL || NET_WORK_NETMASK == NULL) | ||
| 33 | + { | ||
| 34 | + JZSDK_LOG_ERROR("无网络参数配置"); | ||
| 35 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + //1、打开网卡设备 | ||
| 39 | + memset(cmdStr, 0, sizeof(cmdStr)); | ||
| 40 | + snprintf(cmdStr, sizeof(cmdStr), "ifconfig %s up", LINUX_NETWORK_DEV); | ||
| 41 | + ret = system(cmdStr); | ||
| 42 | + if (ret != JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 43 | + JZSDK_LOG_ERROR("Can't open the network." | ||
| 44 | + "Probably the program not execute with root permission." | ||
| 45 | + "Please use the root permission to execute the program."); | ||
| 46 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + //2、打开网络 | ||
| 50 | + memset(cmdStr, 0, sizeof(cmdStr)); | ||
| 51 | + snprintf(cmdStr, sizeof(cmdStr), "ifconfig %s %s netmask %s", LINUX_NETWORK_DEV, NET_WORK_IPADDR, NET_WORK_NETMASK); | ||
| 52 | + ret = system(cmdStr); | ||
| 53 | + if (ret != JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS) { | ||
| 54 | + JZSDK_LOG_ERROR("Can't config the ip address of network." | ||
| 55 | + "Probably the program not execute with root permission." | ||
| 56 | + "Please use the root permission to execute the program."); | ||
| 57 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + //3、创建UDP socket 套接字 | ||
| 61 | + udp_socket = socket(AF_INET, SOCK_DGRAM, 0); | ||
| 62 | + if (udp_socket == -1) { | ||
| 63 | + JZSDK_LOG_ERROR("网口套接字注册失败"); | ||
| 64 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + //4、配置udp服务器地址 | ||
| 68 | + memset(&udp_server_addr, 0, sizeof(udp_server_addr)); | ||
| 69 | + udp_server_addr.sin_family = AF_INET; | ||
| 70 | + udp_server_addr.sin_port = htons(UDP_SERVER_PORT); | ||
| 71 | + if(inet_aton(NET_WORK_TARGET_IPADDR, &udp_server_addr.sin_addr) == 0) | ||
| 72 | + { | ||
| 73 | + JZSDK_LOG_ERROR("udp服务器配置失败"); | ||
| 74 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + NetworkMode = JZ_FLAGCODE_ON; | ||
| 78 | + | ||
| 79 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 80 | +} | ||
| 81 | + | ||
| 82 | +T_JZsdkReturnCode JZsdk_NetWork_DeInit() | ||
| 83 | +{ | ||
| 84 | + NetworkMode = JZ_FLAGCODE_OFF; | ||
| 85 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 86 | +} | ||
| 87 | + | ||
| 88 | +static T_JZsdkReturnCode JZsdk_NetWork_Sent(const unsigned char *data, const int data_len) | ||
| 89 | +{ | ||
| 90 | + int bytes_sent = sendto(udp_socket, data, data_len, 0, | ||
| 91 | + (struct sockaddr *) &udp_server_addr, sizeof(udp_server_addr)); | ||
| 92 | + | ||
| 93 | + if (bytes_sent == -1) | ||
| 94 | + { | ||
| 95 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 96 | + } | ||
| 97 | + else | ||
| 98 | + { | ||
| 99 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 100 | + } | ||
| 101 | +} | ||
| 102 | + | ||
| 103 | +T_JZsdkReturnCode JZsdk_NetWork_SentData(const unsigned char *data, const int data_len) | ||
| 104 | +{ | ||
| 105 | + if (NetworkMode != JZ_FLAGCODE_ON) | ||
| 106 | + { | ||
| 107 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + T_JZsdkReturnCode returnCode; | ||
| 111 | + | ||
| 112 | + int lengthOfDataHaveBeenSent = 0; | ||
| 113 | + int lengthOfDataToBeSent = 0; | ||
| 114 | + | ||
| 115 | + while (data_len - lengthOfDataHaveBeenSent) | ||
| 116 | + { | ||
| 117 | + lengthOfDataToBeSent = JZSDK_UTIL_MIN(MAX_SEND_FRAME_LENTH, | ||
| 118 | + data_len - lengthOfDataHaveBeenSent); | ||
| 119 | + | ||
| 120 | + returnCode = JZsdk_NetWork_Sent((const uint8_t *) data + lengthOfDataHaveBeenSent, | ||
| 121 | + lengthOfDataToBeSent); | ||
| 122 | + if (JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS != JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS) | ||
| 123 | + { | ||
| 124 | + JZSDK_LOG_ERROR("网口发送错误"); | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + lengthOfDataHaveBeenSent += lengthOfDataToBeSent; | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 131 | +} |
JZsdk_hal/JZsdk_network/JZsdk_network.h
0 → 100644
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file JZsdk_Uart_UartDeal.h | ||
| 4 | + * JZsdk_Uart_UartDeal的头文件 | ||
| 5 | + * | ||
| 6 | + ********************************************************************* | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/ | ||
| 10 | +#ifndef JZSDK_NETWORK_H | ||
| 11 | +#define JZSDK_NETWORK_H | ||
| 12 | + | ||
| 13 | +/* Includes ------------------------------------------------------------------*/ | ||
| 14 | + | ||
| 15 | +#ifdef __cplusplus | ||
| 16 | +extern "C" { | ||
| 17 | +#endif | ||
| 18 | + | ||
| 19 | +/* Exported constants --------------------------------------------------------*/ | ||
| 20 | +/* 常亮定义*/ | ||
| 21 | +#include "JZsdk_Base/JZsdk_Code/JZsdk_Code.h" | ||
| 22 | + | ||
| 23 | +/* Exported types ------------------------------------------------------------*/ | ||
| 24 | + | ||
| 25 | +/* Exported functions --------------------------------------------------------*/ | ||
| 26 | +T_JZsdkReturnCode JZsdk_NetWork_Init(); | ||
| 27 | +T_JZsdkReturnCode JZsdk_NetWork_DeInit(); | ||
| 28 | +T_JZsdkReturnCode JZsdk_NetWork_SentData(const unsigned char *data, const int data_len); | ||
| 29 | + | ||
| 30 | +#ifdef __cplusplus | ||
| 31 | +} | ||
| 32 | +#endif | ||
| 33 | + | ||
| 34 | +#endif |
JZsdk_hal/JZsdk_uart/JZsdk_Uart_Input.c
0 → 100644
| 1 | +#include <stdio.h> | ||
| 2 | +#include <string.h> | ||
| 3 | +#include <stdlib.h> | ||
| 4 | + | ||
| 5 | +#include "JZsdk_uart/UartConnection/UartConnection.h" | ||
| 6 | +#include "Megaphone/Megaphone.h" | ||
| 7 | +#include "BaseConfig.h" | ||
| 8 | +#include "version_choose.h" | ||
| 9 | + | ||
| 10 | +#include "JZsdk_uart/JZsdk_Uart_Input.h" | ||
| 11 | +#include "JZsdk_uart/JZsdk_Uart_UartDeal.h" | ||
| 12 | +#include "JZsdk_uart/Uart_Config.h" | ||
| 13 | +#include "JZsdk_uart/JZsdk_Uart_Send/JZsdk_Uart_Send.h" | ||
| 14 | +#include "Gimbal_InAndOut.h" | ||
| 15 | + | ||
| 16 | +// 记录串口是否有被使用,方便ui_contrl进行信息反馈 | ||
| 17 | +struct UartDev_UseFlag | ||
| 18 | +{ | ||
| 19 | + int UartDev_DEV1 ; | ||
| 20 | + int UartDev_DEV2 ; | ||
| 21 | + int UartDev_4G ; | ||
| 22 | +}; | ||
| 23 | +static struct UartDev_UseFlag UartDevUseFlag = {JZ_FLAGCODE_OFF, JZ_FLAGCODE_OFF, JZ_FLAGCODE_OFF}; | ||
| 24 | + | ||
| 25 | + | ||
| 26 | +/**************** | ||
| 27 | + * | ||
| 28 | + * 回复串口是否有被调用 | ||
| 29 | + * | ||
| 30 | + * *************/ | ||
| 31 | +int JZsdk_Get_UartDev_UseFlag(int UART_DEV_NAME) | ||
| 32 | +{ | ||
| 33 | + if (UART_DEV_NAME == UART_DEV_1) | ||
| 34 | + { | ||
| 35 | + return UartDevUseFlag.UartDev_DEV1; | ||
| 36 | + } | ||
| 37 | + else if (UART_DEV_NAME == UART_DEV_2) | ||
| 38 | + { | ||
| 39 | + return UartDevUseFlag.UartDev_DEV2; | ||
| 40 | + } | ||
| 41 | + else if (UART_DEV_NAME == UART_4G) | ||
| 42 | + { | ||
| 43 | + return UartDevUseFlag.UartDev_4G; | ||
| 44 | + } | ||
| 45 | +} | ||
| 46 | + | ||
| 47 | +/************** | ||
| 48 | + * | ||
| 49 | + * 串口部分初始化 | ||
| 50 | + * | ||
| 51 | + * *********/ | ||
| 52 | +int JZsdk_Uart_Init(int UART_DEV_NAME) | ||
| 53 | +{ | ||
| 54 | + | ||
| 55 | + //初始化的是一号设备 | ||
| 56 | + if (UART_DEV_NAME == UART_DEV_1) | ||
| 57 | + { | ||
| 58 | + JZsdk_Uart_SecondInit(UART_DEV_1,UART_DEV1_BITRATE); | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + //初始化的是二号设备 | ||
| 62 | + else if (UART_DEV_NAME == UART_DEV_2) | ||
| 63 | + { | ||
| 64 | + JZsdk_Uart_SecondInit(UART_DEV_2, UART_DEV2_BITRATE); | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + else if (UART_DEV_NAME == UART_4G) | ||
| 68 | + { | ||
| 69 | + JZsdk_Uart_SecondInit(UART_4G, COMM_4G_UART_BITRATE); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + printf("%x串口初始化完成\n", UART_DEV_NAME); | ||
| 73 | +} | ||
| 74 | + | ||
| 75 | +/************** | ||
| 76 | + * | ||
| 77 | + * 串口部分修改波特率 | ||
| 78 | + * | ||
| 79 | + * *********/ | ||
| 80 | +int JZsdk_Uart_BitRateChange(int UART_DEV_NAME, int BitRate) | ||
| 81 | +{ | ||
| 82 | + //1、释放掉原串口 | ||
| 83 | + if (UART_DEV_NAME == UART_DEV_1) | ||
| 84 | + { | ||
| 85 | + //将使用标识关闭 | ||
| 86 | + UartDevUseFlag.UartDev_DEV1 = JZ_FLAGCODE_OFF; | ||
| 87 | + | ||
| 88 | + //等候关闭接收线程 | ||
| 89 | + JZsdk_Uart_CloseUartThead(UART_DEV_NAME, BitRate); | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + //1、释放掉原串口 | ||
| 93 | + else if (UART_DEV_NAME == UART_DEV_2) | ||
| 94 | + { | ||
| 95 | + //将使用标识关闭 | ||
| 96 | + UartDevUseFlag.UartDev_DEV2 = JZ_FLAGCODE_OFF; | ||
| 97 | + | ||
| 98 | + //等候关闭接收线程 | ||
| 99 | + JZsdk_Uart_CloseUartThead(UART_DEV_NAME, BitRate); | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + //1、释放掉原串口 | ||
| 103 | + else if (UART_DEV_NAME == UART_4G) | ||
| 104 | + { | ||
| 105 | + //将使用标识关闭 | ||
| 106 | + UartDevUseFlag.UartDev_4G = JZ_FLAGCODE_OFF; | ||
| 107 | + | ||
| 108 | + //等候关闭接收线程 | ||
| 109 | + JZsdk_Uart_CloseUartThead(UART_DEV_NAME, BitRate); | ||
| 110 | + } | ||
| 111 | +} | ||
| 112 | + | ||
| 113 | +/************** | ||
| 114 | + * | ||
| 115 | + * 串口部分串口再注册 | ||
| 116 | + * | ||
| 117 | + * *********/ | ||
| 118 | +int JZsdk_Uart_SecondInit(int UART_DEV_NAME, int BitRate) | ||
| 119 | +{ | ||
| 120 | + int Uart_fd = 0; | ||
| 121 | + | ||
| 122 | + printf("初始化串口%x\n",UART_DEV_NAME); | ||
| 123 | + | ||
| 124 | + //初始化的是一号设备 | ||
| 125 | + if (UART_DEV_NAME == UART_DEV_1) | ||
| 126 | + { | ||
| 127 | + //1、串口初始化 | ||
| 128 | + Uart_fd = UartConnection_UartEnabled(UART_DEV1_NUM, BitRate); | ||
| 129 | + | ||
| 130 | + //2、串口接收初始化 | ||
| 131 | + JZsdk_Uart_UartDeal_Receive(Uart_fd, UART_DEV_1); | ||
| 132 | + | ||
| 133 | + //3、将使用标识打开 | ||
| 134 | + UartDevUseFlag.UartDev_DEV1 = JZ_FLAGCODE_ON; | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + else if (UART_DEV_NAME == UART_DEV_2) | ||
| 138 | + { | ||
| 139 | + //1、串口初始化 | ||
| 140 | + Uart_fd = UartConnection_UartEnabled(UART_DEV2_NUM, BitRate); | ||
| 141 | + | ||
| 142 | + //2、串口接收初始化 | ||
| 143 | + JZsdk_Uart_UartDeal_Receive(Uart_fd, UART_DEV_2); | ||
| 144 | + | ||
| 145 | + //3、将使用标识打开 | ||
| 146 | + UartDevUseFlag.UartDev_DEV2 = JZ_FLAGCODE_ON; | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + else if (UART_DEV_NAME == UART_4G) | ||
| 150 | + { | ||
| 151 | + //1、串口初始化 | ||
| 152 | + Uart_fd = UartConnection_UartEnabled(COMM_4G_UART_NUM, BitRate); | ||
| 153 | + | ||
| 154 | + //2、串口接收初始化 | ||
| 155 | + JZsdk_Uart_UartDeal_Receive(Uart_fd, UART_4G); | ||
| 156 | + | ||
| 157 | + //3、将使用标识打开 | ||
| 158 | + UartDevUseFlag.UartDev_4G = JZ_FLAGCODE_ON; | ||
| 159 | + } | ||
| 160 | +} | ||
| 161 | + | ||
| 162 | +/******************************* | ||
| 163 | + * | ||
| 164 | + * 自由帧发送 | ||
| 165 | + * | ||
| 166 | + * ******************/ | ||
| 167 | +int JZsdk_Uart_Send_CustomOrder(int UartPort, char *frame, int frame_len) | ||
| 168 | +{ | ||
| 169 | + JZsdk_Uart_UartSend(UartPort, frame, frame_len); | ||
| 170 | +} | ||
| 171 | + | ||
| 172 | +/***************** | ||
| 173 | + * | ||
| 174 | + * 发送主动连接帧 | ||
| 175 | + * | ||
| 176 | + * ******************/ | ||
| 177 | +int JZsdk_Uart_Send_ConnectFrame(int PortNum) | ||
| 178 | +{ | ||
| 179 | + JZsdk_Uart_SendDeal_ConnectFrame(PortNum); | ||
| 180 | +} | ||
| 181 | + | ||
| 182 | +/* | ||
| 183 | +* | ||
| 184 | +* 发送播放结束状态帧 | ||
| 185 | +* | ||
| 186 | +*/ | ||
| 187 | +int JZsdk_Uart_Reply_PlayStatus_end(int PortNum) | ||
| 188 | +{ | ||
| 189 | + //发送播放状态结束帧 | ||
| 190 | + JZsdk_Uart_SendDeal_Send_PlayStatus_end(PortNum); | ||
| 191 | +} | ||
| 192 | + | ||
| 193 | +/************** | ||
| 194 | + * | ||
| 195 | + * 发送发送播放状态帧 | ||
| 196 | + * | ||
| 197 | + * ***********/ | ||
| 198 | +int JZsdk_Uart_Send_PlayStatus(int Uartport ,int num) | ||
| 199 | +{ | ||
| 200 | + JZsdk_Uart_SendDeal_Send_PlayStatus(Uartport, num); | ||
| 201 | +} | ||
| 202 | + | ||
| 203 | +/************** | ||
| 204 | + * | ||
| 205 | + * 发送音量 | ||
| 206 | + * | ||
| 207 | + * ***********/ | ||
| 208 | +int JZsdk_Uart_Reply_Volume(int Uartport,int volume) | ||
| 209 | +{ | ||
| 210 | + JZsdk_Uart_SendDeal_Reply_Volume(Uartport, volume); | ||
| 211 | +} | ||
| 212 | + | ||
| 213 | +/************** | ||
| 214 | + * | ||
| 215 | + * 发送音色 | ||
| 216 | + * | ||
| 217 | + * ***********/ | ||
| 218 | +int JZsdk_Uart_Reply_TTS_tone(int Uartport,int tone) | ||
| 219 | +{ | ||
| 220 | + JZsdk_Uart_SendDeal_Reply_TTS_tone(Uartport, tone); | ||
| 221 | +} | ||
| 222 | + | ||
| 223 | +/************** | ||
| 224 | + * | ||
| 225 | + * 发送语速 | ||
| 226 | + * | ||
| 227 | + * ***********/ | ||
| 228 | +int JZsdk_Uart_Reply_TTS_speed(int Uartport,int speed) | ||
| 229 | +{ | ||
| 230 | + JZsdk_Uart_SendDeal_Reply_TTS_speed(Uartport, speed); | ||
| 231 | +} | ||
| 232 | + | ||
| 233 | +/************** | ||
| 234 | + * | ||
| 235 | + * 发送循环状态 | ||
| 236 | + * | ||
| 237 | + * ***********/ | ||
| 238 | +int JZsdk_Uart_Reply_AudioPlayLoopStatus(int Uartport,int speed) | ||
| 239 | +{ | ||
| 240 | + JZsdk_Uart_SendDeal_Reply_LoopPlayStatus(Uartport, speed); | ||
| 241 | +} | ||
| 242 | + | ||
| 243 | + | ||
| 244 | +/************** | ||
| 245 | + * | ||
| 246 | + * 发送云台俯仰角度查询值 | ||
| 247 | + * | ||
| 248 | + * ***********/ | ||
| 249 | +int JZsdk_Uart_Reply_GimbalPitchAngle(int Uartport,int angle) | ||
| 250 | +{ | ||
| 251 | + JZsdk_Uart_SendDeal_Reply_GimbalPitchAngle(Uartport, angle); | ||
| 252 | +} | ||
| 253 | + | ||
| 254 | +/************* | ||
| 255 | + * | ||
| 256 | + * 设置云台俯仰角度 | ||
| 257 | + * | ||
| 258 | + * **************/ | ||
| 259 | +int JZsdk_Uart_Send_SetGimbalPitch(int Uartport,int angle) | ||
| 260 | +{ | ||
| 261 | + JZsdk_Uart_SendDeal_Set_GimbalPitchAngle(Uartport, angle); | ||
| 262 | +} | ||
| 263 | + | ||
| 264 | +/************* | ||
| 265 | + * | ||
| 266 | + * 查询云台角度 | ||
| 267 | + * | ||
| 268 | + * **************/ | ||
| 269 | +int JZsdk_Uart_Send_CheckStatus_GimbalAngle(int Uartport ,int FrameSequence) | ||
| 270 | +{ | ||
| 271 | + JZsdk_Uart_SendDeal_CheckStatus_GimbalAngle(Uartport, FrameSequence); | ||
| 272 | +} | ||
| 273 | + | ||
| 274 | +/************* | ||
| 275 | + * | ||
| 276 | + * 设置云台俯仰角度微调 | ||
| 277 | + * | ||
| 278 | + * **************/ | ||
| 279 | +int JZsdk_Uart_Send_SetGimbalFineTuningPitch(int Uartport,int angle) | ||
| 280 | +{ | ||
| 281 | + JZsdk_Uart_SendDeal_Set_GimbalFineTuningPitch(Uartport, angle); | ||
| 282 | +} | ||
| 283 | + | ||
| 284 | +/************* | ||
| 285 | + * | ||
| 286 | + * 查询云台微调角度 | ||
| 287 | + * | ||
| 288 | + * **************/ | ||
| 289 | +int JZsdk_Uart_Send_CheckStatus_GimbalFineTuningPitch(int Uartport,int FrameSequence) | ||
| 290 | +{ | ||
| 291 | + JZsdk_Uart_SendDeal_CheckStatus_GimbalFineTuningPitch(Uartport,FrameSequence); | ||
| 292 | +} | ||
| 293 | + | ||
| 294 | +/************* | ||
| 295 | + * | ||
| 296 | + * 发送云台俯仰微调值 | ||
| 297 | + * | ||
| 298 | + * **************/ | ||
| 299 | +int JZsdk_Uart_Send_GimbalFineTuningPitch(int Uartport,int FrameSequence, int Pitch) | ||
| 300 | +{ | ||
| 301 | + JZsdk_Uart_SendDeal_Reply_GimbalFineTuningPitch(Uartport,FrameSequence, Pitch); | ||
| 302 | +} | ||
| 303 | + | ||
| 304 | +/************* | ||
| 305 | + * | ||
| 306 | + * 设置云台联动 | ||
| 307 | + * | ||
| 308 | + * **************/ | ||
| 309 | +int JZsdk_Uart_Send_Set_GimbalLinkageControl(int Uartport,int FrameSequence, int value) | ||
| 310 | +{ | ||
| 311 | + JZsdk_Uart_SendDeal_Set_GimbalLinkageControl(Uartport,FrameSequence, value); | ||
| 312 | +} | ||
| 313 | + | ||
| 314 | +/************* | ||
| 315 | + * | ||
| 316 | + * 查询云台联动值 | ||
| 317 | + * | ||
| 318 | + * **************/ | ||
| 319 | +int JZsdk_Uart_Send_CheckStatus_GimbalLinkage(int Uartport,int FrameSequence) | ||
| 320 | +{ | ||
| 321 | + JZsdk_Uart_SendDeal_CheckStatus_GimbalLinkage(Uartport,FrameSequence); | ||
| 322 | +} | ||
| 323 | + | ||
| 324 | +/************* | ||
| 325 | + * | ||
| 326 | + * 发送云台联动值 | ||
| 327 | + * | ||
| 328 | + * **************/ | ||
| 329 | +int JZsdk_Uart_Send_GimbalLinkageControl(int Uartport,int FrameSequence, int value) | ||
| 330 | +{ | ||
| 331 | + JZsdk_Uart_SendDeal_GimbalLinkageControl(Uartport,FrameSequence,value); | ||
| 332 | +} | ||
| 333 | + | ||
| 334 | +/************* | ||
| 335 | + * | ||
| 336 | + * 设置云台最大最小值 | ||
| 337 | + * | ||
| 338 | + * **************/ | ||
| 339 | +int JZsdk_Uart_Send_SetGimbalRange(int Uartport,int FrameSequence, int value) | ||
| 340 | +{ | ||
| 341 | + JZsdk_Uart_SendDeal_SetGimbalRange(Uartport,FrameSequence,value); | ||
| 342 | +} | ||
| 343 | + | ||
| 344 | +/******************************************************************************************************************************* | ||
| 345 | + * | ||
| 346 | + * 探照灯部分 | ||
| 347 | + * | ||
| 348 | + * *******************************************************************************************************************************/ | ||
| 349 | + | ||
| 350 | +/************* | ||
| 351 | + * | ||
| 352 | + * 设置探照灯爆闪频率 | ||
| 353 | + * | ||
| 354 | + * **************/ | ||
| 355 | +int JZsdk_Uart_Send_SearchLight_SetFrequency(int Uartport,int Frequency) | ||
| 356 | +{ | ||
| 357 | + JZsdk_Uart_SendDeal_Set_SearchLightFrequency(Uartport ,Frequency); | ||
| 358 | +} | ||
| 359 | + | ||
| 360 | +/************* | ||
| 361 | + * | ||
| 362 | + * 探照灯控制 | ||
| 363 | + * | ||
| 364 | + * **************/ | ||
| 365 | +int JZsdk_Uart_Send_SearchLight_Control(int Uartport,int mode) | ||
| 366 | +{ | ||
| 367 | + JZsdk_Uart_SendDeal_SearchLight_Control(Uartport, mode); | ||
| 368 | +} | ||
| 369 | + | ||
| 370 | +/************* | ||
| 371 | + * | ||
| 372 | + * 探照灯亮度 | ||
| 373 | + * | ||
| 374 | + * **************/ | ||
| 375 | +int JZsdk_Uart_Send_SearchLight_SetLumen(int Uartport, int LeftLumen, int RightLumen) | ||
| 376 | +{ | ||
| 377 | + JZsdk_Uart_SendDeal_SearchLight_SetLumen(Uartport, LeftLumen, RightLumen); | ||
| 378 | +} | ||
| 379 | + | ||
| 380 | +/************* | ||
| 381 | + * | ||
| 382 | + * 查询爆闪频率 | ||
| 383 | + * | ||
| 384 | + * **************/ | ||
| 385 | +int JZsdk_Uart_Send_SearchLight_CheckStatus_Frequency(int Uartport) | ||
| 386 | +{ | ||
| 387 | + JZsdk_Uart_SendDeal_Set_SearchLight_CheckStatus_Frequency(Uartport); | ||
| 388 | +} | ||
| 389 | + | ||
| 390 | +/************* | ||
| 391 | + * | ||
| 392 | + * 查询探照灯亮度 | ||
| 393 | + * | ||
| 394 | + * **************/ | ||
| 395 | +int JZsdk_Uart_Send_SearchLight_CheckStatus_Lumen(int Uartport) | ||
| 396 | +{ | ||
| 397 | + JZsdk_Uart_SendDeal_Set_SearchLight_CheckStatus_Lumen(Uartport); | ||
| 398 | +} | ||
| 399 | + | ||
| 400 | +/************* | ||
| 401 | + * | ||
| 402 | + * 查询探照灯模式 | ||
| 403 | + * | ||
| 404 | + * **************/ | ||
| 405 | +int JZsdk_Uart_Send_SearchLight_CheckStatus_Mode(int Uartport) | ||
| 406 | +{ | ||
| 407 | + JZsdk_Uart_SendDeal_Set_SearchLight_CheckStatus_Mode(Uartport); | ||
| 408 | +} | ||
| 409 | + | ||
| 410 | +/************* | ||
| 411 | + * | ||
| 412 | + * 查询探照灯属性 | ||
| 413 | + * | ||
| 414 | + * **************/ | ||
| 415 | +int JZsdk_Uart_Send_SearchLight_CheckStatus_LightAttribute(int Uartport) | ||
| 416 | +{ | ||
| 417 | + JZsdk_Uart_SendDeal_CheckStatus_LightAttribute(Uartport); | ||
| 418 | +} | ||
| 419 | + | ||
| 420 | +/************* | ||
| 421 | + * | ||
| 422 | + * 查询探照灯温度 | ||
| 423 | + * | ||
| 424 | + * **************/ | ||
| 425 | +int JZsdk_Uart_Send_SearchLight_CheckStatus_SearchLightTemperture(int Uartport) | ||
| 426 | +{ | ||
| 427 | + JZsdk_Uart_SendDeal_CheckStatus_SearchLightTemperture(Uartport); | ||
| 428 | +} | ||
| 429 | + | ||
| 430 | + | ||
| 431 | +/************* | ||
| 432 | + * | ||
| 433 | + * 探照灯消息订阅 | ||
| 434 | + * | ||
| 435 | + * **************/ | ||
| 436 | +int JZsdk_Uart_Send_MessageSubcription_Control(int Uartport,int value) | ||
| 437 | +{ | ||
| 438 | + JZsdk_Uart_SendDeal_MessageSubcription_Control(Uartport, value); | ||
| 439 | +} | ||
| 440 | +/******************************************************************************************************************************* | ||
| 441 | + * | ||
| 442 | + * 警灯部分 | ||
| 443 | + * | ||
| 444 | + * *******************************************************************************************************************************/ | ||
| 445 | + | ||
| 446 | +/************* | ||
| 447 | + * | ||
| 448 | + * 设置警灯状态 | ||
| 449 | + * | ||
| 450 | + * **************/ | ||
| 451 | +int JZsdk_Uart_Send_Set_WarningLight_Status(int Uartport,int status, int mode) | ||
| 452 | +{ | ||
| 453 | + JZsdk_Uart_SendDeal_Set_WarningLight_Status(Uartport, status, mode); | ||
| 454 | +} | ||
| 455 | +/************* | ||
| 456 | + * | ||
| 457 | + * 设置警灯颜色 | ||
| 458 | + * | ||
| 459 | + * **************/ | ||
| 460 | +int JZsdk_Uart_Send_Set_WarningLight_Color(int Uartport,int color1, int color2) | ||
| 461 | +{ | ||
| 462 | + JZsdk_Uart_SendDeal_Set_WarningLight_Color(Uartport, color1, color2); | ||
| 463 | +} | ||
| 464 | + | ||
| 465 | +/******************************************************************************************************************************* | ||
| 466 | + * | ||
| 467 | + * 5B类部分 | ||
| 468 | + * | ||
| 469 | + * *******************************************************************************************************************************/ | ||
| 470 | +/************* | ||
| 471 | + * | ||
| 472 | + * 发送opus解码状态 | ||
| 473 | + * | ||
| 474 | + * **************/ | ||
| 475 | +int JZsdk_Uart_Send_OpusDecodeStatus(int Uartport,int value) | ||
| 476 | +{ | ||
| 477 | + JZsdk_Uart_SendDeal_OpusDecodeStatus(Uartport, value); | ||
| 478 | +} | ||
| 479 | + | ||
| 480 | + | ||
| 481 | +/************* | ||
| 482 | + * | ||
| 483 | + * 发送探照灯爆闪频率 | ||
| 484 | + * | ||
| 485 | + * **************/ | ||
| 486 | +int JZsdk_Uart_Send_SearchLight_Frequency(int Uartport,int value) | ||
| 487 | +{ | ||
| 488 | + JZsdk_Uart_SendDeal_SearchLight_Frequency(Uartport, value); | ||
| 489 | +} | ||
| 490 | + | ||
| 491 | +/************* | ||
| 492 | + * | ||
| 493 | + * 发送探照灯模式 | ||
| 494 | + * | ||
| 495 | + * **************/ | ||
| 496 | +int JZsdk_Uart_Send_SearchLight_Mode(int Uartport,int value) | ||
| 497 | +{ | ||
| 498 | + JZsdk_Uart_SendDeal_SearchLight_Mode(Uartport, value); | ||
| 499 | +} | ||
| 500 | + | ||
| 501 | +/************* | ||
| 502 | + * | ||
| 503 | + * 发送探照灯亮度 | ||
| 504 | + * | ||
| 505 | + * **************/ | ||
| 506 | +int JZsdk_Uart_Send_SearchLight_Lumen(int Uartport,int LeftLumen, int RightLumen) | ||
| 507 | +{ | ||
| 508 | + JZsdk_Uart_SendDeal_SearchLight_Lumen(Uartport, LeftLumen, RightLumen); | ||
| 509 | +} | ||
| 510 | + | ||
| 511 | +/************* | ||
| 512 | + * | ||
| 513 | + * 发送探照灯温度 | ||
| 514 | + * | ||
| 515 | + * **************/ | ||
| 516 | +int JZsdk_Uart_Send_SearchLight_Temperature(int Uartport,int LeftTemperature, int RightTemperature) | ||
| 517 | +{ | ||
| 518 | + JZsdk_Uart_SendDeal_SearchLight_Temperature(Uartport, LeftTemperature, RightTemperature); | ||
| 519 | +} | ||
| 520 | + | ||
| 521 | + | ||
| 522 | +/************* | ||
| 523 | + * | ||
| 524 | + * 发送对外供电电源的状态 | ||
| 525 | + * | ||
| 526 | + * **************/ | ||
| 527 | +int JZsdk_Uart_Send_OutputPowerStatus(int Uartport, int FrameSequence, int status) | ||
| 528 | +{ | ||
| 529 | + JZsdk_Uart_SendDeal_OutputPowerStatus(Uartport, FrameSequence, status); | ||
| 530 | +} | ||
| 531 | + | ||
| 532 | +/******************************************************************************************************************************* | ||
| 533 | + * | ||
| 534 | + * 警灯部分 | ||
| 535 | + * | ||
| 536 | + * *******************************************************************************************************************************/ | ||
| 537 | +/************* | ||
| 538 | + * | ||
| 539 | + * 发送警灯状态 | ||
| 540 | + * | ||
| 541 | + * **************/ | ||
| 542 | +int JZsdk_Uart_Send_WarningLight_Status(int Uartport, int status, int mode) | ||
| 543 | +{ | ||
| 544 | + JZsdk_Uart_SendDeal_WarningLight_Status(Uartport, status, mode); | ||
| 545 | +} | ||
| 546 | + | ||
| 547 | +/************* | ||
| 548 | + * | ||
| 549 | + * 发送警灯颜色 | ||
| 550 | + * | ||
| 551 | + * **************/ | ||
| 552 | +int JZsdk_Uart_Send_WarningLight_Color(int Uartport, int color1, int color2) | ||
| 553 | +{ | ||
| 554 | + JZsdk_Uart_SendDeal_WarningLight_Color(Uartport, color1, color2); | ||
| 555 | +} | ||
| 556 | + | ||
| 557 | + | ||
| 558 | +/************* | ||
| 559 | + * | ||
| 560 | + * 查询警灯状态 | ||
| 561 | + * | ||
| 562 | + * **************/ | ||
| 563 | +int JZsdk_Uart_Send_CheckStatus_WarningLightStatus(int Uartport) | ||
| 564 | +{ | ||
| 565 | + JZsdk_Uart_SendDeal_CheckStatus_WarningLightStatus(Uartport); | ||
| 566 | +} | ||
| 567 | + | ||
| 568 | + | ||
| 569 | +/************* | ||
| 570 | + * | ||
| 571 | + * 查询警灯颜色 | ||
| 572 | + * | ||
| 573 | + * **************/ | ||
| 574 | +int JZsdk_Uart_Send_CheckStatus_WarningLightColor(int Uartport) | ||
| 575 | +{ | ||
| 576 | + JZsdk_Uart_SendDeal_CheckStatus_WarningLightColor(Uartport); | ||
| 577 | +} |
JZsdk_hal/JZsdk_uart/JZsdk_Uart_Input.h
0 → 100644
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file JZsdk_Uart_Input.h | ||
| 4 | + * JZsdk_Uart_Input | ||
| 5 | + * | ||
| 6 | + ********************************************************************* | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/ | ||
| 10 | +#ifndef JZSDK_UART_INPUT_H | ||
| 11 | +#define JZSDK_UART_INPUT_H | ||
| 12 | + | ||
| 13 | +/* Includes ------------------------------------------------------------------*/ | ||
| 14 | + | ||
| 15 | +#ifdef __cplusplus | ||
| 16 | +extern "C" { | ||
| 17 | +#endif | ||
| 18 | + | ||
| 19 | + | ||
| 20 | +/* Exported constants --------------------------------------------------------*/ | ||
| 21 | +/* 常亮定义*/ | ||
| 22 | + | ||
| 23 | +/* Exported types ------------------------------------------------------------*/ | ||
| 24 | + | ||
| 25 | +/* Exported functions --------------------------------------------------------*/ | ||
| 26 | +int JZsdk_Uart_Init(int UART_DEV_NAME); | ||
| 27 | +int JZsdk_Get_UartDev_UseFlag(int UART_DEV_NAME); | ||
| 28 | + | ||
| 29 | +int JZsdk_Uart_Reply_PlayStatus_end(int PortNum); | ||
| 30 | +int JZsdk_Uart_Send_PlayStatus(int Uartport ,int num); | ||
| 31 | +int JZsdk_Uart_Reply_Volume(int Uartport,int volume); | ||
| 32 | +int JZsdk_Uart_Reply_TTS_tone(int Uartport,int tone); | ||
| 33 | +int JZsdk_Uart_Reply_TTS_speed(int Uartport,int speed); | ||
| 34 | +int JZsdk_Uart_Reply_AudioPlayLoopStatus(int Uartport,int speed); | ||
| 35 | +int JZsdk_Uart_Send_OpusDecodeStatus(int Uartport,int value); | ||
| 36 | + | ||
| 37 | +int JZsdk_Uart_Send_CustomOrder(int UartPort, char *frame, int frame_len); | ||
| 38 | +int JZsdk_Uart_Send_ConnectFrame(int PortNum); | ||
| 39 | + | ||
| 40 | +int JZsdk_Uart_Reply_GimbalPitchAngle(int Uartport,int angle); | ||
| 41 | +int JZsdk_Uart_Send_SetGimbalPitch(int Uartport,int angle); | ||
| 42 | +int JZsdk_Uart_Send_SetGimbalFineTuningPitch(int Uartport,int angle); | ||
| 43 | +int JZsdk_Uart_Send_Gimbal_Pitch(int Uartport, int pitch); | ||
| 44 | +int JZsdk_Uart_Send_CheckStatus_GimbalFineTuningPitch(int Uartport,int FrameSequence); | ||
| 45 | +int JZsdk_Uart_Send_GimbalFineTuningPitch(int Uartport,int FrameSequence, int Pitch); | ||
| 46 | +int JZsdk_Uart_Send_Set_GimbalLinkageControl(int Uartport,int FrameSequence, int value); | ||
| 47 | +int JZsdk_Uart_Send_CheckStatus_GimbalLinkage(int Uartport,int FrameSequence); | ||
| 48 | +int JZsdk_Uart_Send_GimbalLinkageControl(int Uartport,int FrameSequence, int value); | ||
| 49 | +int JZsdk_Uart_Send_CheckStatus_GimbalAngle(int Uartport ,int FrameSequence); | ||
| 50 | +int JZsdk_Uart_Send_SetGimbalRange(int Uartport,int FrameSequence, int value); | ||
| 51 | + | ||
| 52 | +int JZsdk_Uart_Send_SearchLight_SetFrequency(int Uartport,int Frequency); | ||
| 53 | +int JZsdk_Uart_Send_SearchLight_Control(int Uartport,int mode); | ||
| 54 | +int JZsdk_Uart_Send_SearchLight_SetLumen(int Uartport, int LeftLumen, int RightLumen); | ||
| 55 | + | ||
| 56 | +int JZsdk_Uart_Send_MessageSubcription_Control(int Uartport,int value); | ||
| 57 | + | ||
| 58 | +int JZsdk_Uart_Send_Set_WarningLight_Status(int Uartport,int status, int mode); | ||
| 59 | +int JZsdk_Uart_Send_Set_WarningLight_Color(int Uartport,int color1, int color2); | ||
| 60 | + | ||
| 61 | +int JZsdk_Uart_Send_SearchLight_CheckStatus_Frequency(int Uartport); | ||
| 62 | +int JZsdk_Uart_Send_SearchLight_CheckStatus_Lumen(int Uartport); | ||
| 63 | +int JZsdk_Uart_Send_SearchLight_CheckStatus_Mode(int Uartport); | ||
| 64 | +int JZsdk_Uart_Send_SearchLight_CheckStatus_LightAttribute(int Uartport); | ||
| 65 | +int JZsdk_Uart_Send_SearchLight_CheckStatus_SearchLightTemperture(int Uartport); | ||
| 66 | + | ||
| 67 | +int JZsdk_Uart_Send_SearchLight_Frequency(int Uartport,int value); | ||
| 68 | +int JZsdk_Uart_Send_SearchLight_Mode(int Uartport,int value); | ||
| 69 | +int JZsdk_Uart_Send_SearchLight_Lumen(int Uartport,int LeftLumen, int RightLumen); | ||
| 70 | +int JZsdk_Uart_Send_SearchLight_Temperature(int Uartport,int LeftTemperature, int RightTemperature); | ||
| 71 | + | ||
| 72 | + | ||
| 73 | +int JZsdk_Uart_Send_WarningLight_Status(int Uartport, int status, int mode); | ||
| 74 | +int JZsdk_Uart_Send_WarningLight_Color(int Uartport, int color1, int color2); | ||
| 75 | +int JZsdk_Uart_Send_CheckStatus_WarningLightStatus(int Uartport); | ||
| 76 | +int JZsdk_Uart_Send_CheckStatus_WarningLightColor(int Uartport); | ||
| 77 | + | ||
| 78 | + | ||
| 79 | +int JZsdk_Uart_Send_OutputPowerStatus(int Uartport, int FrameSequence, int status); | ||
| 80 | + | ||
| 81 | +int JZsdk_Uart_BitRateChange(int UART_DEV_NAME, int BitRate); | ||
| 82 | +int JZsdk_Uart_SecondInit(int UART_DEV_NAME, int BitRate); | ||
| 83 | + | ||
| 84 | +#ifdef __cplusplus | ||
| 85 | +} | ||
| 86 | +#endif | ||
| 87 | + | ||
| 88 | +#endif |
此 diff 太大无法显示。
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file JZsdk_Uart_RecvDeal.h | ||
| 4 | + * JZsdk_Uart_RecvDeal的头文件 | ||
| 5 | + * | ||
| 6 | + ********************************************************************* | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/ | ||
| 10 | +#ifndef JZSDK_UART_RECVDEAL_H | ||
| 11 | +#define JZSDK_UART_RECVDEAL_H | ||
| 12 | + | ||
| 13 | +/* Includes ------------------------------------------------------------------*/ | ||
| 14 | + | ||
| 15 | +#ifdef __cplusplus | ||
| 16 | +extern "C" { | ||
| 17 | +#endif | ||
| 18 | + | ||
| 19 | +/* Exported constants --------------------------------------------------------*/ | ||
| 20 | +/* 常亮定义*/ | ||
| 21 | + | ||
| 22 | +/* Exported types ------------------------------------------------------------*/ | ||
| 23 | + | ||
| 24 | +/* Exported functions --------------------------------------------------------*/ | ||
| 25 | +int JZsdk_Uart_RecvDeal_CharmDeal(int Port, unsigned char *getbuf, int len); | ||
| 26 | + | ||
| 27 | +#ifdef __cplusplus | ||
| 28 | +} | ||
| 29 | +#endif | ||
| 30 | + | ||
| 31 | +#endif |
| 1 | +#include <stdio.h> | ||
| 2 | +#include <string.h> | ||
| 3 | +#include <stdlib.h> | ||
| 4 | + | ||
| 5 | +#include "../JZsdk_Uart_UartDeal.h" | ||
| 6 | +#include "../Uart_Config.h" | ||
| 7 | +#include "./JZsdk_Uart_Send.h" | ||
| 8 | +#include "JZsdk_TaskManagement/TaskManagement.h" | ||
| 9 | +#include "JZsdk_Base/JZsdk_Code/JZsdk_Code.h" | ||
| 10 | +#include "JZsdk_Base/JZsdk_FrameComparsion/JZsdk_FrameComparsion.h" | ||
| 11 | + | ||
| 12 | + | ||
| 13 | +//发送主动连接帧 | ||
| 14 | +int JZsdk_Uart_SendDeal_ConnectFrame(int PortNum) | ||
| 15 | +{ | ||
| 16 | + unsigned char sendbuf[256]; | ||
| 17 | + int send_buf_len; | ||
| 18 | + | ||
| 19 | + //1、获取帧样板 | ||
| 20 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5AFRAME_ASKFORCONNECT , sendbuf, &send_buf_len); | ||
| 21 | + | ||
| 22 | + //2、发送帧 | ||
| 23 | + JZsdk_Uart_UartSend(PortNum ,sendbuf, send_buf_len); | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +//回复连接帧 | ||
| 27 | +int JZsdk_Uart_SendDeal_Send_Connect(int Uartport , int FrameSequence,int Version_flag) | ||
| 28 | +{ | ||
| 29 | + unsigned char sendbuf[256]; | ||
| 30 | + int send_buf_len; | ||
| 31 | + | ||
| 32 | + //1、获取帧样板 | ||
| 33 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5BFRAME_INITIATECONNECT , sendbuf, &send_buf_len); | ||
| 34 | + | ||
| 35 | + //2、写入硬件码 | ||
| 36 | + sendbuf[9] = Version_flag; | ||
| 37 | + | ||
| 38 | + //写入帧序列 | ||
| 39 | + sendbuf[6] = FrameSequence; //帧序列 | ||
| 40 | + | ||
| 41 | + //3、发送帧 | ||
| 42 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 43 | +} | ||
| 44 | + | ||
| 45 | +//回复心跳帧 | ||
| 46 | +int JZsdk_Uart_SendDeal_Send_HeartBeatStatus(int Uartport , int FrameSequence,int HeartBeatStatus) | ||
| 47 | +{ | ||
| 48 | + unsigned char sendbuf[256]; | ||
| 49 | + int send_buf_len; | ||
| 50 | + | ||
| 51 | + //1、获取帧样板 | ||
| 52 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5BFRAME_HEARTBEAT , sendbuf, &send_buf_len); | ||
| 53 | + | ||
| 54 | + //2、写入硬件码 | ||
| 55 | + sendbuf[9] = HeartBeatStatus; | ||
| 56 | + | ||
| 57 | + //写入帧序列 | ||
| 58 | + sendbuf[6] = FrameSequence; //帧序列 | ||
| 59 | + | ||
| 60 | + //3、发送帧 | ||
| 61 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 62 | +} | ||
| 63 | + | ||
| 64 | +//设置电源状态 | ||
| 65 | +T_JZsdkReturnCode JZsdk_Uart_SendDeal_PowerStatus(int Uartport, int FrameSequence, int status) | ||
| 66 | +{ | ||
| 67 | + printf("发送电源状态\n"); | ||
| 68 | + | ||
| 69 | + unsigned char sendbuf[256]; | ||
| 70 | + int send_buf_len; | ||
| 71 | + | ||
| 72 | + //1、获取帧样板 | ||
| 73 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5AFRAME_FRAME_POWER_STATUS, sendbuf, &send_buf_len); | ||
| 74 | + | ||
| 75 | + sendbuf[9] = status; | ||
| 76 | + sendbuf[6] = FrameSequence; //帧序列 | ||
| 77 | + | ||
| 78 | + //2、发送帧 | ||
| 79 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 80 | +} | ||
| 81 | + | ||
| 82 | +//发送心跳帧 | ||
| 83 | +T_JZsdkReturnCode JZsdk_Uart_SendDeal_Ask_HeartBeatStatus(int Uartport , int FrameSequence,int HeartBeatStatus) | ||
| 84 | +{ | ||
| 85 | + printf("发送请求心跳帧\n"); | ||
| 86 | + | ||
| 87 | + unsigned char sendbuf[256]; | ||
| 88 | + int send_buf_len; | ||
| 89 | + | ||
| 90 | + //1、获取帧样板 | ||
| 91 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5AFRAME_HEARTBEAT, sendbuf, &send_buf_len); | ||
| 92 | + | ||
| 93 | + sendbuf[9] = HeartBeatStatus; | ||
| 94 | + sendbuf[6] = FrameSequence; //帧序列 | ||
| 95 | + | ||
| 96 | + //2、发送帧 | ||
| 97 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 98 | +} | ||
| 99 | + | ||
| 100 | +//发送请求时间戳帧 | ||
| 101 | +T_JZsdkReturnCode JZsdk_Uart_SendDeal_Ask_TimeStamp(int Uartport , int FrameSequence) | ||
| 102 | +{ | ||
| 103 | + printf("发送请求时间戳帧\n"); | ||
| 104 | + | ||
| 105 | + unsigned char sendbuf[256]; | ||
| 106 | + int send_buf_len; | ||
| 107 | + | ||
| 108 | + //1、获取帧样板 | ||
| 109 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5AFRAME_TIMESTAMP, sendbuf, &send_buf_len); | ||
| 110 | + | ||
| 111 | + sendbuf[6] = FrameSequence; //帧序列 | ||
| 112 | + | ||
| 113 | + //2、发送帧 | ||
| 114 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 115 | +} | ||
| 116 | + | ||
| 117 | +//发送版本号 | ||
| 118 | +T_JZsdkReturnCode JZsdk_Uart_SendDeal_SendAllVersion(int Uartport, int FrameSequence, int DeviceID, int MajorVersion, int MinorVersion, int ModifyVersion, int DebugVersion) | ||
| 119 | +{ | ||
| 120 | + printf("发送所有版本号\n"); | ||
| 121 | + | ||
| 122 | + unsigned char sendbuf[256]; | ||
| 123 | + int send_buf_len; | ||
| 124 | + | ||
| 125 | + //1、获取帧样板 | ||
| 126 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5BFRAME_ALL_VERSION, sendbuf, &send_buf_len); | ||
| 127 | + | ||
| 128 | + sendbuf[6] = FrameSequence; //帧序列 | ||
| 129 | + sendbuf[9] = DeviceID; | ||
| 130 | + sendbuf[10] = MajorVersion; | ||
| 131 | + sendbuf[11] = MinorVersion; | ||
| 132 | + sendbuf[12] = ModifyVersion; | ||
| 133 | + sendbuf[13] = DebugVersion; | ||
| 134 | + | ||
| 135 | + //2、发送帧 | ||
| 136 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 137 | +} | ||
| 138 | + | ||
| 139 | +//发送序列号 | ||
| 140 | +T_JZsdkReturnCode JZsdk_Uart_SendDeal_SendAllSerialNumber(int Uartport, int FrameSequence, int DeviceID, unsigned char *SerialNumber, int SerialNumberLen) | ||
| 141 | +{ | ||
| 142 | + printf("发送所有序列号\n"); | ||
| 143 | + | ||
| 144 | + unsigned char sendbuf[256]; | ||
| 145 | + int send_buf_len; | ||
| 146 | + | ||
| 147 | + //1、获取帧样板 | ||
| 148 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5BFRAME_ALL_SERIAL_NUMBER, sendbuf, &send_buf_len); | ||
| 149 | + | ||
| 150 | + sendbuf[6] = FrameSequence; //帧序列 | ||
| 151 | + sendbuf[9] = DeviceID; | ||
| 152 | + memcpy(&sendbuf[10], SerialNumber, SerialNumberLen); | ||
| 153 | + send_buf_len = send_buf_len - 1 + SerialNumberLen; | ||
| 154 | + sendbuf[send_buf_len-2] = 0x00; | ||
| 155 | + sendbuf[send_buf_len-1] = 0x23; | ||
| 156 | + | ||
| 157 | + sendbuf[3] = (send_buf_len >> 8); | ||
| 158 | + sendbuf[4] = (send_buf_len & 0xff); | ||
| 159 | + | ||
| 160 | + //2、发送帧 | ||
| 161 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 162 | +} | ||
| 163 | + | ||
| 164 | +//发送成功帧 | ||
| 165 | +int JZsdk_Uart_SendDeal_Reply_Sucesss(int Uartport ,int FrameSequence) | ||
| 166 | +{ | ||
| 167 | + unsigned char sendbuf[256]; | ||
| 168 | + int send_buf_len; | ||
| 169 | + | ||
| 170 | + //1、获取帧样板 | ||
| 171 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5BFRAME_SUCESS , sendbuf, &send_buf_len); | ||
| 172 | + | ||
| 173 | + //2、写入数据 | ||
| 174 | + sendbuf[6] = FrameSequence; //帧序列 | ||
| 175 | + | ||
| 176 | + //3、发送帧 | ||
| 177 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 178 | +} | ||
| 179 | + | ||
| 180 | +//发送失败帧 | ||
| 181 | +int JZsdk_Uart_SendDeal_Reply_Failure(int Uartport ,int FrameSequence) | ||
| 182 | +{ | ||
| 183 | + unsigned char sendbuf[256]; | ||
| 184 | + int send_buf_len; | ||
| 185 | + | ||
| 186 | + //1、获取帧样板 | ||
| 187 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5BFRAME_DEFEAT , sendbuf, &send_buf_len); | ||
| 188 | + | ||
| 189 | + //2、写入数据 | ||
| 190 | + sendbuf[6] = FrameSequence; //帧序列 | ||
| 191 | + | ||
| 192 | + //3、发送帧 | ||
| 193 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 194 | +} | ||
| 195 | + | ||
| 196 | +//发送当前从设备名 | ||
| 197 | +int JZsdk_Uart_SendDeal_Reply_SecondaryDeviceName(int Uartport , int device_name, int FrameSequence) | ||
| 198 | +{ | ||
| 199 | + unsigned char sendbuf[256]; | ||
| 200 | + int send_buf_len; | ||
| 201 | + | ||
| 202 | + //1、获取帧样板 | ||
| 203 | + JZsdk_GetFrameTemplate(JZ_INSCODE_6BFRAME_CHECKSTATUS_SECONDARY_DEVICE_NAME , sendbuf, &send_buf_len); | ||
| 204 | + | ||
| 205 | + //2、写入数据 | ||
| 206 | + sendbuf[6] = FrameSequence; //帧序列 | ||
| 207 | + sendbuf[10] = device_name; | ||
| 208 | + | ||
| 209 | + //3、发送帧 | ||
| 210 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 211 | +} | ||
| 212 | + | ||
| 213 | + | ||
| 214 | +//查询当前从设备名 | ||
| 215 | +int JZsdk_Uart_SendDeal_QuerySecondaryDeviceName(int Uartport ,int FrameSequence) | ||
| 216 | +{ | ||
| 217 | + unsigned char sendbuf[256]; | ||
| 218 | + int send_buf_len; | ||
| 219 | + | ||
| 220 | + //1、获取帧样板 | ||
| 221 | + JZsdk_GetFrameTemplate(JZ_INSCODE_6AFRAME_CHECKSTATUS_SECONDARY_DEVICE_NAME , sendbuf, &send_buf_len); | ||
| 222 | + | ||
| 223 | + //2、写入数据 | ||
| 224 | + sendbuf[6] = FrameSequence; //帧序列 | ||
| 225 | + | ||
| 226 | + //3、发送帧 | ||
| 227 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 228 | +} | ||
| 229 | + | ||
| 230 | +//发送当前设备序列号 | ||
| 231 | +int JZsdk_Uart_SendDeal_SerialNumber(int UartPort, int FrameSequence, char *SerialNumber, int SerialNumberLenth) | ||
| 232 | +{ | ||
| 233 | + unsigned char sendbuf[256]; | ||
| 234 | + int send_buf_len; | ||
| 235 | + | ||
| 236 | + //1、获取帧样板 | ||
| 237 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5BFRAME_CHECKSTATUS_SERIALNUMBER , sendbuf, &send_buf_len); | ||
| 238 | + | ||
| 239 | + //2、写入数据 | ||
| 240 | + sendbuf[6] = FrameSequence; //帧序列 | ||
| 241 | + | ||
| 242 | + for (int i = 0; i < SerialNumberLenth; i++) | ||
| 243 | + { | ||
| 244 | + sendbuf[9+i] = SerialNumber[i]; | ||
| 245 | + } | ||
| 246 | + | ||
| 247 | + sendbuf[9+SerialNumberLenth] = 0x00; | ||
| 248 | + sendbuf[9+SerialNumberLenth + 1] = 0x23; | ||
| 249 | + | ||
| 250 | + send_buf_len = (9+SerialNumberLenth + 2); | ||
| 251 | + sendbuf[4] = send_buf_len; | ||
| 252 | + | ||
| 253 | + //3、发送帧 | ||
| 254 | + JZsdk_Uart_UartSend(UartPort ,sendbuf, send_buf_len); | ||
| 255 | +} | ||
| 256 | + | ||
| 257 | +/********* | ||
| 258 | + * | ||
| 259 | + * 发送设备信息 | ||
| 260 | + * | ||
| 261 | + * | ||
| 262 | + * *******/ | ||
| 263 | +T_JZsdkReturnCode JZsdk_Uart_SendDeal_DeviceMessage(int UartPort, int FrameSequence, unsigned char *message, unsigned int messageLen) | ||
| 264 | +{ | ||
| 265 | + unsigned char sendbuf[300]; | ||
| 266 | + memset(sendbuf,0,sizeof(sendbuf)); | ||
| 267 | + unsigned int send_buf_len = 0; | ||
| 268 | + | ||
| 269 | + //获取帧样板 | ||
| 270 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5BFRAME_DEVICE_MESSAGE , sendbuf, &send_buf_len); | ||
| 271 | + | ||
| 272 | + memcpy(&sendbuf[9], message, messageLen); | ||
| 273 | + send_buf_len = 9+messageLen+2; | ||
| 274 | + | ||
| 275 | + sendbuf[9+messageLen] = 0x00; | ||
| 276 | + sendbuf[9+messageLen + 1] = 0x23; | ||
| 277 | + | ||
| 278 | + //3、发送帧 | ||
| 279 | + JZsdk_Uart_UartSend(UartPort ,sendbuf, send_buf_len); | ||
| 280 | +} | ||
| 281 | + | ||
| 282 | + | ||
| 283 | +struct JZsdk_MusicListSentStruct | ||
| 284 | +{ | ||
| 285 | + int UartPort; | ||
| 286 | + int FrameSequence; | ||
| 287 | + int music_sum; | ||
| 288 | + char **MusicName; | ||
| 289 | + int *MusicNameLength; | ||
| 290 | +}; | ||
| 291 | + | ||
| 292 | +/********** | ||
| 293 | + * | ||
| 294 | + * 歌曲列表发送任务函数 | ||
| 295 | + * | ||
| 296 | + * ***********/ | ||
| 297 | +static void JZsdk_Uart_SentDeal_Reply_Musiclist_Task(void *data) | ||
| 298 | +{ | ||
| 299 | + struct JZsdk_MusicListSentStruct *taskData = (struct JZsdk_MusicListSentStruct *)data; | ||
| 300 | + unsigned char sendbuf[256]; | ||
| 301 | + int send_buf_len; | ||
| 302 | + | ||
| 303 | + //1、发送操作成功 | ||
| 304 | + //获取帧样板 | ||
| 305 | + memset(sendbuf,0,sizeof(sendbuf)); | ||
| 306 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5BFRAME_SUCESS , sendbuf, &send_buf_len); | ||
| 307 | + //写入数据 | ||
| 308 | + sendbuf[6] = taskData->FrameSequence; //帧序列 | ||
| 309 | + //发送帧 | ||
| 310 | + printf("发送操作成功帧\n"); | ||
| 311 | + JZsdk_Uart_UartSend_NotTask(taskData->UartPort ,sendbuf, send_buf_len); | ||
| 312 | + | ||
| 313 | + //2、发送开始帧 | ||
| 314 | + //获取帧样板 | ||
| 315 | + memset(sendbuf,0,sizeof(sendbuf)); | ||
| 316 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5BFRAME_MUSICLIST_START , sendbuf, &send_buf_len); | ||
| 317 | + //写入数据 | ||
| 318 | + sendbuf[6] = taskData->FrameSequence; //帧序列 | ||
| 319 | + sendbuf[9] = taskData->music_sum; | ||
| 320 | + //发送帧 | ||
| 321 | + printf("发送歌曲开始列表帧\n"); | ||
| 322 | + JZsdk_Uart_UartSend_NotTask(taskData->UartPort ,sendbuf, send_buf_len); | ||
| 323 | + | ||
| 324 | + //3、逐一调用发送函数将歌曲名发出 | ||
| 325 | + for (int i = 0; i < (taskData->music_sum) ; i++) | ||
| 326 | + { | ||
| 327 | + memset(sendbuf,0,sizeof(sendbuf)); | ||
| 328 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5BFRAME_MUSICLIST_TRANS , sendbuf, &send_buf_len); | ||
| 329 | + | ||
| 330 | + memcpy(&sendbuf[9],taskData->MusicName[i],taskData->MusicNameLength[i]); | ||
| 331 | + sendbuf[9+taskData->MusicNameLength[i]]=0x00; | ||
| 332 | + sendbuf[10+taskData->MusicNameLength[i]]=0x23; | ||
| 333 | + | ||
| 334 | + send_buf_len = send_buf_len -1 + taskData->MusicNameLength[i] ; | ||
| 335 | + | ||
| 336 | + sendbuf[3] = (send_buf_len >> 8); | ||
| 337 | + sendbuf[4] = (send_buf_len & 0xff); | ||
| 338 | + sendbuf[6] = taskData->FrameSequence; //帧序列 | ||
| 339 | + JZsdk_Uart_UartSend_NotTask(taskData->UartPort ,sendbuf, send_buf_len); | ||
| 340 | + } | ||
| 341 | + | ||
| 342 | + //4、发送结束帧 | ||
| 343 | + //获取帧样板 | ||
| 344 | + memset(sendbuf,0,sizeof(sendbuf)); | ||
| 345 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5BFRAME_MUSICLIST_STOP , sendbuf, &send_buf_len); | ||
| 346 | + //写入数据 | ||
| 347 | + sendbuf[6] = taskData->FrameSequence; //帧序列 | ||
| 348 | + sendbuf[9] = taskData->music_sum; | ||
| 349 | + //发送帧 | ||
| 350 | + printf("发送歌曲结束列表"); | ||
| 351 | + JZsdk_Uart_UartSend_NotTask(taskData->UartPort ,sendbuf, send_buf_len); | ||
| 352 | + | ||
| 353 | + //5、释放内存 | ||
| 354 | + for (int i = 0; i < taskData->music_sum; i++) | ||
| 355 | + { | ||
| 356 | + free(taskData->MusicName[i]); | ||
| 357 | + taskData->MusicName[i] = NULL; | ||
| 358 | + } | ||
| 359 | + | ||
| 360 | + free(taskData->MusicName); | ||
| 361 | + taskData->MusicName = NULL; | ||
| 362 | + | ||
| 363 | + free(taskData->MusicNameLength); | ||
| 364 | + free(taskData); | ||
| 365 | + taskData = NULL; | ||
| 366 | +} | ||
| 367 | + | ||
| 368 | +T_JZsdkReturnCode JZsdk_Uart_SentDeal_Reply_Musiclist(int UartPort ,int FrameSequence, int music_sum ,char **MusicName ,int *MusicNameLength) | ||
| 369 | +{ | ||
| 370 | + struct JZsdk_MusicListSentStruct *musicList = (struct JZsdk_MusicListSentStruct *)malloc(sizeof(struct JZsdk_MusicListSentStruct)); | ||
| 371 | + if (musicList == NULL) | ||
| 372 | + { | ||
| 373 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 374 | + } | ||
| 375 | + | ||
| 376 | + musicList->UartPort = UartPort; | ||
| 377 | + musicList->FrameSequence = FrameSequence; | ||
| 378 | + musicList->music_sum = music_sum; | ||
| 379 | + musicList->MusicName = MusicName; | ||
| 380 | + musicList->MusicNameLength = MusicNameLength; | ||
| 381 | + | ||
| 382 | + T_JZsdkReturnCode ret = TaskManagement_SubmitTask(JZsdk_Uart_SentDeal_Reply_Musiclist_Task, (void *)musicList); | ||
| 383 | + if (ret == JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE) | ||
| 384 | + { | ||
| 385 | + free(musicList); | ||
| 386 | + musicList = NULL; | ||
| 387 | + return ret; | ||
| 388 | + } | ||
| 389 | + | ||
| 390 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 391 | +} | ||
| 392 | + | ||
| 393 | +//发送播放状态结束帧 | ||
| 394 | +int JZsdk_Uart_SendDeal_Send_PlayStatus_end(int Uartport) | ||
| 395 | +{ | ||
| 396 | + printf("发送播放状态结束帧\n"); | ||
| 397 | + unsigned char sendbuf[256]; | ||
| 398 | + int send_buf_len; | ||
| 399 | + | ||
| 400 | + //1、获取帧样板 | ||
| 401 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5BFRAME_AUDIO_PLAYSTATUS_END , sendbuf, &send_buf_len); | ||
| 402 | + | ||
| 403 | + //2、写入数据 | ||
| 404 | + | ||
| 405 | + //3、发送帧 | ||
| 406 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 407 | +} | ||
| 408 | + | ||
| 409 | +//发送播放状态帧 | ||
| 410 | +int JZsdk_Uart_SendDeal_Send_PlayStatus(int Uartport ,int num) | ||
| 411 | +{ | ||
| 412 | + printf("向"); | ||
| 413 | + switch (Uartport) | ||
| 414 | + { | ||
| 415 | + case UART_4G: | ||
| 416 | + printf("4G模块"); | ||
| 417 | + break; | ||
| 418 | + case UART_DEV_1: | ||
| 419 | + printf("串口1设备"); | ||
| 420 | + break; | ||
| 421 | + case UART_DEV_2: | ||
| 422 | + printf("串口2设备"); | ||
| 423 | + break; | ||
| 424 | + | ||
| 425 | + default: | ||
| 426 | + break; | ||
| 427 | + } | ||
| 428 | + printf("发送播放状态帧%x\n",num); | ||
| 429 | + unsigned char sendbuf[256]; | ||
| 430 | + int send_buf_len; | ||
| 431 | + | ||
| 432 | + //1、获取帧样板 | ||
| 433 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5BFRAME_AUDIO_PLAYSTATUS , sendbuf, &send_buf_len); | ||
| 434 | + | ||
| 435 | + //2、写入数据 | ||
| 436 | + sendbuf[9] = (char)num; | ||
| 437 | + | ||
| 438 | + //3、发送帧 | ||
| 439 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 440 | +} | ||
| 441 | + | ||
| 442 | +//回复当前播放的歌曲名字 | ||
| 443 | +int JZsdk_Uart_SendDeal_Reply_MusicName(int Uartport ,char *music_name, int music_name_len) | ||
| 444 | +{ | ||
| 445 | + printf("发送当前歌曲名字帧"); | ||
| 446 | + unsigned char sendbuf[256]; | ||
| 447 | + int send_buf_len; | ||
| 448 | + | ||
| 449 | + //1、获取帧样板 | ||
| 450 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5BFRAME_AUDIO_PLAYFILENAME , sendbuf, &send_buf_len); | ||
| 451 | + | ||
| 452 | + //2、写入数据 | ||
| 453 | + memcpy(&sendbuf[9],music_name,music_name_len); | ||
| 454 | + sendbuf[9+music_name_len]=0x00; | ||
| 455 | + sendbuf[10+music_name_len]=0x23; | ||
| 456 | + | ||
| 457 | + int len = send_buf_len -1 + music_name_len; | ||
| 458 | + | ||
| 459 | + sendbuf[3] = len >> 8; | ||
| 460 | + sendbuf[4] = len & 0xff; | ||
| 461 | + | ||
| 462 | + //3、发送帧 | ||
| 463 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, len); | ||
| 464 | +} | ||
| 465 | + | ||
| 466 | +//回复当前音量 | ||
| 467 | +int JZsdk_Uart_SendDeal_Reply_Volume(int Uartport ,int num) | ||
| 468 | +{ | ||
| 469 | + printf("发送播放状态帧\n"); | ||
| 470 | + unsigned char sendbuf[256]; | ||
| 471 | + int send_buf_len; | ||
| 472 | + | ||
| 473 | + //1、获取帧样板 | ||
| 474 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5BFRAME_VOLUME, sendbuf, &send_buf_len); | ||
| 475 | + | ||
| 476 | + //2、写入数据 | ||
| 477 | + sendbuf[9] = (char)num; | ||
| 478 | + | ||
| 479 | + //3、发送帧 | ||
| 480 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 481 | + | ||
| 482 | +} | ||
| 483 | + | ||
| 484 | + | ||
| 485 | + | ||
| 486 | +//回复软件版本号 | ||
| 487 | +int JZsdk_Uart_SendDeal_Reply_SoftVersion(int Uartport ,char majorVersion, char minorVersion, char modifyVersion, char debugVersion) | ||
| 488 | +{ | ||
| 489 | + printf("发送软件版本号帧\n"); | ||
| 490 | + unsigned char sendbuf[256]; | ||
| 491 | + int send_buf_len; | ||
| 492 | + | ||
| 493 | + //1、获取帧样板 | ||
| 494 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5BFRAME_SORTWAREVERSION, sendbuf, &send_buf_len); | ||
| 495 | + | ||
| 496 | + //2、写入数据 | ||
| 497 | + sendbuf[9] = majorVersion; | ||
| 498 | + sendbuf[10] = minorVersion; | ||
| 499 | + sendbuf[11] = modifyVersion; | ||
| 500 | + sendbuf[12] = debugVersion; | ||
| 501 | + | ||
| 502 | + //3、发送帧 | ||
| 503 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 504 | +} | ||
| 505 | + | ||
| 506 | +//发送循环状态 | ||
| 507 | +int JZsdk_Uart_SendDeal_Reply_LoopPlayStatus(int Uartport ,int status) | ||
| 508 | +{ | ||
| 509 | + printf("发送循环状态帧\n"); | ||
| 510 | + | ||
| 511 | + unsigned char sendbuf[256]; | ||
| 512 | + int send_buf_len; | ||
| 513 | + | ||
| 514 | + //1、获取帧样板 | ||
| 515 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5BFRAME_AUDIO_PLAYLOOPSTATUS, sendbuf, &send_buf_len); | ||
| 516 | + | ||
| 517 | + //2、写入数据 | ||
| 518 | + sendbuf[9] = status; | ||
| 519 | + | ||
| 520 | + //3、发送帧 | ||
| 521 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 522 | + | ||
| 523 | +} | ||
| 524 | + | ||
| 525 | +//发送音色 | ||
| 526 | +int JZsdk_Uart_SendDeal_Reply_TTS_tone(int Uartport ,int tone) | ||
| 527 | +{ | ||
| 528 | + printf("发送音色帧\n"); | ||
| 529 | + | ||
| 530 | + unsigned char sendbuf[256]; | ||
| 531 | + int send_buf_len; | ||
| 532 | + | ||
| 533 | + //1、获取帧样板 | ||
| 534 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5BFRAME_TTS_TONE, sendbuf, &send_buf_len); | ||
| 535 | + | ||
| 536 | + //2、写入数据 | ||
| 537 | + sendbuf[9] = tone; | ||
| 538 | + | ||
| 539 | + //3、发送帧 | ||
| 540 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 541 | +} | ||
| 542 | + | ||
| 543 | +//发送语速 | ||
| 544 | +int JZsdk_Uart_SendDeal_Reply_TTS_speed(int Uartport ,int speed) | ||
| 545 | +{ | ||
| 546 | + printf("发送音色帧\n"); | ||
| 547 | + | ||
| 548 | + unsigned char sendbuf[256]; | ||
| 549 | + int send_buf_len; | ||
| 550 | + | ||
| 551 | + //1、获取帧样板 | ||
| 552 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5BFRAME_TTS_SPEED, sendbuf, &send_buf_len); | ||
| 553 | + | ||
| 554 | + //2、写入数据 | ||
| 555 | + sendbuf[9] = speed; | ||
| 556 | + | ||
| 557 | + //3、发送帧 | ||
| 558 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 559 | +} | ||
| 560 | + | ||
| 561 | +/************* | ||
| 562 | + * | ||
| 563 | + * 发送opus解码状态 | ||
| 564 | + * | ||
| 565 | + * **************/ | ||
| 566 | +int JZsdk_Uart_SendDeal_OpusDecodeStatus(int Uartport,int value) | ||
| 567 | +{ | ||
| 568 | + printf("发送opus解码状态帧\n"); | ||
| 569 | + | ||
| 570 | + unsigned char sendbuf[256]; | ||
| 571 | + int send_buf_len; | ||
| 572 | + | ||
| 573 | + //1、获取帧样板 | ||
| 574 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5BFRAME_OPUS_DECODE_STATUS, sendbuf, &send_buf_len); | ||
| 575 | + | ||
| 576 | + //2、写入数据 | ||
| 577 | + sendbuf[9] = value; | ||
| 578 | + | ||
| 579 | + //3、发送帧 | ||
| 580 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 581 | +} | ||
| 582 | + | ||
| 583 | +/**************************************************************************************************************************************************** | ||
| 584 | +* | ||
| 585 | +* 云台部分 | ||
| 586 | +* | ||
| 587 | +****************************************************************************************************************************************************/ | ||
| 588 | + | ||
| 589 | +//回复当前云台角度 | ||
| 590 | +int JZsdk_Uart_SendDeal_Reply_GimbalPitchAngle(int Uartport ,int angle) | ||
| 591 | +{ | ||
| 592 | + printf("发送当前云台角度帧\n"); | ||
| 593 | + unsigned char sendbuf[256]; | ||
| 594 | + int send_buf_len; | ||
| 595 | + | ||
| 596 | + //1、获取帧样板 | ||
| 597 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5BFRAME_GIMBAL_PITCH, sendbuf, &send_buf_len); | ||
| 598 | + | ||
| 599 | + //2、写入数据 | ||
| 600 | + char signal = 0x00; | ||
| 601 | + if (angle < 0) | ||
| 602 | + { | ||
| 603 | + signal = 0xff; | ||
| 604 | + angle = -angle; | ||
| 605 | + } | ||
| 606 | + | ||
| 607 | + sendbuf[9] = (char)signal; | ||
| 608 | + sendbuf[10] = (char)(angle >> 8); | ||
| 609 | + sendbuf[11] = (char)(angle & 255); | ||
| 610 | + | ||
| 611 | + //3、发送帧 | ||
| 612 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 613 | +} | ||
| 614 | + | ||
| 615 | +//设置当前云台角度 | ||
| 616 | +int JZsdk_Uart_SendDeal_Set_GimbalPitchAngle(int Uartport ,int angle) | ||
| 617 | +{ | ||
| 618 | + //printf("发送设置云台角度帧 %d\n",angle); //该打印可能会造成卡顿 | ||
| 619 | + unsigned char sendbuf[256]; | ||
| 620 | + int send_buf_len; | ||
| 621 | + | ||
| 622 | + //1、获取帧样板 | ||
| 623 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5AFRAME_GIMBAL_PITCH_CONTROL, sendbuf, &send_buf_len); | ||
| 624 | + | ||
| 625 | + //char sendbuf[14] = {0x5A ,0x5A ,0x77 ,0x00 ,0x0E ,0x00 ,0x00 ,0x64 ,0x51 ,0x00 ,0x00 ,0x00 ,0x00 ,0x23}; | ||
| 626 | + //send_buf_len = 14; | ||
| 627 | + | ||
| 628 | + //2、写入数据 | ||
| 629 | + if (angle < 0) | ||
| 630 | + { | ||
| 631 | + angle = -angle; | ||
| 632 | + sendbuf[9] = 0xff; | ||
| 633 | + } | ||
| 634 | + else | ||
| 635 | + { | ||
| 636 | + sendbuf[9] = 0x00; | ||
| 637 | + } | ||
| 638 | + | ||
| 639 | + sendbuf[10] = ((angle>>8) & 0xff); | ||
| 640 | + sendbuf[11] = (angle & 0xff); | ||
| 641 | + | ||
| 642 | + //3、发送帧 | ||
| 643 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 644 | +} | ||
| 645 | + | ||
| 646 | +//查询云台角度 | ||
| 647 | +int JZsdk_Uart_SendDeal_CheckStatus_GimbalAngle(int Uartport ,int FrameSequence) | ||
| 648 | +{ | ||
| 649 | + printf("发送查询云台角度帧\n"); | ||
| 650 | + unsigned char sendbuf[256]; | ||
| 651 | + int send_buf_len; | ||
| 652 | + | ||
| 653 | + //1、获取帧样板 | ||
| 654 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5AFRAME_CHECKSTATUS_GIMBAL, sendbuf, &send_buf_len); | ||
| 655 | + | ||
| 656 | + //2、写入帧序列 | ||
| 657 | + sendbuf[6] = FrameSequence; | ||
| 658 | + | ||
| 659 | + //3、发送帧 | ||
| 660 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 661 | +} | ||
| 662 | + | ||
| 663 | +//微调云台pitch | ||
| 664 | +int JZsdk_Uart_SendDeal_Set_GimbalFineTuningPitch(int Uartport, int PitchFineTuning) | ||
| 665 | +{ | ||
| 666 | + printf("发送微调云台pitch帧\n"); | ||
| 667 | + unsigned char sendbuf[256]; | ||
| 668 | + int send_buf_len; | ||
| 669 | + | ||
| 670 | + //1、获取帧样板 | ||
| 671 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5AFRAME_GIMBAL_PITCH_FINETUNING_CONTROL, sendbuf, &send_buf_len); | ||
| 672 | + | ||
| 673 | + //2、写入数据 | ||
| 674 | + if (PitchFineTuning < 0) | ||
| 675 | + { | ||
| 676 | + PitchFineTuning = -PitchFineTuning; | ||
| 677 | + sendbuf[9] = 0xff; | ||
| 678 | + } | ||
| 679 | + else | ||
| 680 | + { | ||
| 681 | + sendbuf[9] = 0x00; | ||
| 682 | + } | ||
| 683 | + | ||
| 684 | + sendbuf[10] = ((PitchFineTuning>>8) & 0xff); | ||
| 685 | + sendbuf[11] = (PitchFineTuning & 0xff); | ||
| 686 | + | ||
| 687 | + //3、发送帧 | ||
| 688 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 689 | +} | ||
| 690 | + | ||
| 691 | +//查询云台角度微调值 | ||
| 692 | +int JZsdk_Uart_SendDeal_CheckStatus_GimbalFineTuningPitch(int Uartport, int FrameSequence) | ||
| 693 | +{ | ||
| 694 | + printf("发送查询云台角度微调值帧\n"); | ||
| 695 | + unsigned char sendbuf[256]; | ||
| 696 | + int send_buf_len; | ||
| 697 | + | ||
| 698 | + //1、获取帧样板 | ||
| 699 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5AFRAME_CHECKSTATUS_GIMBAL_FINETUNING, sendbuf, &send_buf_len); | ||
| 700 | + | ||
| 701 | + //2、写入数据 | ||
| 702 | + sendbuf[6] = FrameSequence; //帧序列 | ||
| 703 | + | ||
| 704 | + //3、发送帧 | ||
| 705 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 706 | +} | ||
| 707 | + | ||
| 708 | +//回复云台pitch微调值 | ||
| 709 | +int JZsdk_Uart_SendDeal_Reply_GimbalFineTuningPitch(int Uartport, int FrameSequence, int FineTunigPitch) | ||
| 710 | +{ | ||
| 711 | + printf("发送云台pitch微调值\n"); | ||
| 712 | + unsigned char sendbuf[256]; | ||
| 713 | + int send_buf_len; | ||
| 714 | + | ||
| 715 | + //1、获取帧样板 | ||
| 716 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5BFRAME_GIMBAL_PITCH_FINETUNING, sendbuf, &send_buf_len); | ||
| 717 | + | ||
| 718 | + //2、写入数据 | ||
| 719 | + if (FineTunigPitch < 0) | ||
| 720 | + { | ||
| 721 | + FineTunigPitch = -FineTunigPitch; | ||
| 722 | + sendbuf[9] = 0xff; | ||
| 723 | + } | ||
| 724 | + else | ||
| 725 | + { | ||
| 726 | + sendbuf[9] = 0x00; | ||
| 727 | + } | ||
| 728 | + | ||
| 729 | + sendbuf[10] = ((FineTunigPitch>>8) & 0xff); | ||
| 730 | + sendbuf[11] = (FineTunigPitch & 0xff); | ||
| 731 | + | ||
| 732 | + //3、发送帧 | ||
| 733 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 734 | +} | ||
| 735 | + | ||
| 736 | +//设置云台联动 | ||
| 737 | +int JZsdk_Uart_SendDeal_Set_GimbalLinkageControl(int Uartport,int FrameSequence, int value) | ||
| 738 | +{ | ||
| 739 | + printf("发送设置云台联动帧\n"); | ||
| 740 | + unsigned char sendbuf[256]; | ||
| 741 | + int send_buf_len; | ||
| 742 | + | ||
| 743 | + //1、获取帧样板 | ||
| 744 | + JZsdk_GetFrameTemplate(JZ_INSCODE_6AFRAME_GIMBAL_LINKAGE_CONTROL, sendbuf, &send_buf_len); | ||
| 745 | + | ||
| 746 | + //2、写入数据 | ||
| 747 | + sendbuf[6] = FrameSequence; //帧序列 | ||
| 748 | + sendbuf[10] = value; | ||
| 749 | + | ||
| 750 | + //3、发送帧 | ||
| 751 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 752 | +} | ||
| 753 | + | ||
| 754 | +//查询云台联动值 | ||
| 755 | +int JZsdk_Uart_SendDeal_CheckStatus_GimbalLinkage(int Uartport,int FrameSequence) | ||
| 756 | +{ | ||
| 757 | + printf("发送查询云台联动值帧\n"); | ||
| 758 | + unsigned char sendbuf[256]; | ||
| 759 | + int send_buf_len; | ||
| 760 | + | ||
| 761 | + //1、获取帧样板 | ||
| 762 | + JZsdk_GetFrameTemplate(JZ_INSCODE_6AFRAME_CHECKSTATUS_GIMBAL_LINKAGE, sendbuf, &send_buf_len); | ||
| 763 | + | ||
| 764 | + //2、写入数据 | ||
| 765 | + sendbuf[6] = FrameSequence; //帧序列 | ||
| 766 | + | ||
| 767 | + //3、发送帧 | ||
| 768 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 769 | +} | ||
| 770 | + | ||
| 771 | +//发送云台联动值 | ||
| 772 | +int JZsdk_Uart_SendDeal_GimbalLinkageControl(int Uartport,int FrameSequence,int value) | ||
| 773 | +{ | ||
| 774 | + printf("发送云台联动值帧\n"); | ||
| 775 | + unsigned char sendbuf[256]; | ||
| 776 | + int send_buf_len; | ||
| 777 | + | ||
| 778 | + //1、获取帧样板 | ||
| 779 | + JZsdk_GetFrameTemplate(JZ_INSCODE_6BFRAME_CHECKSTATUS_GIMBAL_LINKAGE, sendbuf, &send_buf_len); | ||
| 780 | + | ||
| 781 | + //2、写入数据 | ||
| 782 | + sendbuf[6] = FrameSequence; //帧序列 | ||
| 783 | + sendbuf[10] = value; | ||
| 784 | + | ||
| 785 | + //3、发送帧 | ||
| 786 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 787 | +} | ||
| 788 | + | ||
| 789 | +//发送云台最大最小值帧 | ||
| 790 | +int JZsdk_Uart_SendDeal_SetGimbalRange(int Uartport,int FrameSequence,int value) | ||
| 791 | +{ | ||
| 792 | + printf("发送云台最大最小值帧\n"); | ||
| 793 | + unsigned char sendbuf[256]; | ||
| 794 | + int send_buf_len; | ||
| 795 | + | ||
| 796 | + //1、获取帧样板 | ||
| 797 | + JZsdk_GetFrameTemplate(JZ_INSCODE_6AFRAME_SET_GIMBAL_MAXMIN_RANGE, sendbuf, &send_buf_len); | ||
| 798 | + | ||
| 799 | + //2、写入数据 | ||
| 800 | + sendbuf[6] = FrameSequence; //帧序列 | ||
| 801 | + sendbuf[10] = value; | ||
| 802 | + | ||
| 803 | + //3、发送帧 | ||
| 804 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 805 | +} | ||
| 806 | + | ||
| 807 | +/**************************************************************************************************************************************************** | ||
| 808 | +* | ||
| 809 | +* 探照灯部分 | ||
| 810 | +* | ||
| 811 | +****************************************************************************************************************************************************/ | ||
| 812 | + | ||
| 813 | +//发送设置探照灯爆闪频率 | ||
| 814 | +int JZsdk_Uart_SendDeal_Set_SearchLightFrequency(int Uartport ,int Frequency) | ||
| 815 | +{ | ||
| 816 | + printf("发送设置爆闪频率帧\n"); | ||
| 817 | + | ||
| 818 | + unsigned char sendbuf[256]; | ||
| 819 | + int send_buf_len; | ||
| 820 | + | ||
| 821 | + //1、获取帧样板 | ||
| 822 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5AFRAME_SEARCHLIGHT_SET_FREQUENCY, sendbuf, &send_buf_len); | ||
| 823 | + | ||
| 824 | + //2、写入数据 | ||
| 825 | + sendbuf[10] = Frequency; | ||
| 826 | + | ||
| 827 | + //3、发送帧 | ||
| 828 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 829 | +} | ||
| 830 | + | ||
| 831 | +//设置探照灯控制 | ||
| 832 | +int JZsdk_Uart_SendDeal_SearchLight_Control(int Uartport,int mode) | ||
| 833 | +{ | ||
| 834 | + printf("发送探照灯控制\n"); | ||
| 835 | + | ||
| 836 | + unsigned char sendbuf[256]; | ||
| 837 | + int send_buf_len; | ||
| 838 | + | ||
| 839 | + //1、获取帧样板 | ||
| 840 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5AFRAME_SEARCHLIGHT_CONTROL, sendbuf, &send_buf_len); | ||
| 841 | + | ||
| 842 | + //2、写入数据 | ||
| 843 | + sendbuf[10] = mode; | ||
| 844 | + | ||
| 845 | + //3、发送帧 | ||
| 846 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 847 | +} | ||
| 848 | + | ||
| 849 | +//设置探照灯亮度 | ||
| 850 | +int JZsdk_Uart_SendDeal_SearchLight_SetLumen(int Uartport, int LeftLumen, int RightLumen) | ||
| 851 | +{ | ||
| 852 | + printf("发送设置探照灯亮度\n"); | ||
| 853 | + | ||
| 854 | + unsigned char sendbuf[256]; | ||
| 855 | + int send_buf_len; | ||
| 856 | + | ||
| 857 | + //1、获取帧样板 | ||
| 858 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5AFRAME_SEARCHLIGHT_SET_LUMEN, sendbuf, &send_buf_len); | ||
| 859 | + | ||
| 860 | + //2、写入数据 | ||
| 861 | + sendbuf[9] = LeftLumen; | ||
| 862 | + sendbuf[10] = RightLumen; | ||
| 863 | + | ||
| 864 | + //3、发送帧 | ||
| 865 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 866 | +} | ||
| 867 | + | ||
| 868 | +//发送 | ||
| 869 | + | ||
| 870 | +//查询探照灯频率 | ||
| 871 | +int JZsdk_Uart_SendDeal_Set_SearchLight_CheckStatus_Frequency(int Uartport) | ||
| 872 | +{ | ||
| 873 | + printf("发送查询探照灯频率帧\n"); | ||
| 874 | + | ||
| 875 | + unsigned char sendbuf[256]; | ||
| 876 | + int send_buf_len; | ||
| 877 | + | ||
| 878 | + //1、获取帧样板 | ||
| 879 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5AFRAME_CHECKSTATUS_SEARCHLIGHT_FREQUENCY, sendbuf, &send_buf_len); | ||
| 880 | + | ||
| 881 | + //2、发送帧 | ||
| 882 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 883 | +} | ||
| 884 | + | ||
| 885 | +//查询探照灯亮度 | ||
| 886 | +int JZsdk_Uart_SendDeal_Set_SearchLight_CheckStatus_Lumen(int Uartport) | ||
| 887 | +{ | ||
| 888 | + printf("发送查询探照灯亮度帧\n"); | ||
| 889 | + | ||
| 890 | + unsigned char sendbuf[256]; | ||
| 891 | + int send_buf_len; | ||
| 892 | + | ||
| 893 | + //1、获取帧样板 | ||
| 894 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5AFRAME_CHECKSTATUS_SEARCHLIGHT_LUMEN, sendbuf, &send_buf_len); | ||
| 895 | + | ||
| 896 | + //2、发送帧 | ||
| 897 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 898 | +} | ||
| 899 | + | ||
| 900 | +//查询探照灯模式 | ||
| 901 | +int JZsdk_Uart_SendDeal_Set_SearchLight_CheckStatus_Mode(int Uartport) | ||
| 902 | +{ | ||
| 903 | + printf("发送查询探照灯模式帧\n"); | ||
| 904 | + | ||
| 905 | + unsigned char sendbuf[256]; | ||
| 906 | + int send_buf_len; | ||
| 907 | + | ||
| 908 | + //1、获取帧样板 | ||
| 909 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5AFRAME_CHECKSTATUS_SEARCHLIGHT_MODE, sendbuf, &send_buf_len); | ||
| 910 | + | ||
| 911 | + //2、发送帧 | ||
| 912 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 913 | +} | ||
| 914 | + | ||
| 915 | +//查询探照灯属性 | ||
| 916 | +int JZsdk_Uart_SendDeal_CheckStatus_LightAttribute(int Uartport) | ||
| 917 | +{ | ||
| 918 | + printf("发送查询探照灯属性帧\n"); | ||
| 919 | + | ||
| 920 | + unsigned char sendbuf[256]; | ||
| 921 | + int send_buf_len; | ||
| 922 | + | ||
| 923 | + //1、获取帧样板 | ||
| 924 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5AFRAME_CHECKSTATUS_SEARCHLIGHT_LIGHTATTRIBUTE, sendbuf, &send_buf_len); | ||
| 925 | + | ||
| 926 | + //2、发送帧 | ||
| 927 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 928 | +} | ||
| 929 | + | ||
| 930 | +//查询探照灯温度 | ||
| 931 | +int JZsdk_Uart_SendDeal_CheckStatus_SearchLightTemperture(int Uartport) | ||
| 932 | +{ | ||
| 933 | + printf("发送查询探照灯温度\n"); | ||
| 934 | + | ||
| 935 | + unsigned char sendbuf[256]; | ||
| 936 | + int send_buf_len; | ||
| 937 | + | ||
| 938 | + //1、获取帧样板 | ||
| 939 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5AFRAME_CHECKSTATUS_SEARCHLIGHT_TEMPERATURE, sendbuf, &send_buf_len); | ||
| 940 | + | ||
| 941 | + //2、发送帧 | ||
| 942 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 943 | +} | ||
| 944 | + | ||
| 945 | +//开启消息订阅 | ||
| 946 | +int JZsdk_Uart_SendDeal_MessageSubcription_Control(int Uartport, int value) | ||
| 947 | +{ | ||
| 948 | + printf("发送开启消息订阅%d\n",value); | ||
| 949 | + | ||
| 950 | + unsigned char sendbuf[256]; | ||
| 951 | + int send_buf_len; | ||
| 952 | + | ||
| 953 | + //1、获取帧样板 | ||
| 954 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5AFRAME_SEARCHLIGHT_MESSAGE_SUBSCRIPTION_CONTROL, sendbuf, &send_buf_len); | ||
| 955 | + | ||
| 956 | + //2、写入数据 | ||
| 957 | + sendbuf[10] = value; | ||
| 958 | + | ||
| 959 | + //3、发送帧 | ||
| 960 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 961 | +} | ||
| 962 | + | ||
| 963 | +/**************************************************************************************************************************************************** | ||
| 964 | +* | ||
| 965 | +* 警灯部分 | ||
| 966 | +* | ||
| 967 | +****************************************************************************************************************************************************/ | ||
| 968 | +/************* | ||
| 969 | + * | ||
| 970 | + * 设置警灯状态 | ||
| 971 | + * | ||
| 972 | + * **************/ | ||
| 973 | +int JZsdk_Uart_SendDeal_Set_WarningLight_Status(int Uartport,int status, int mode) | ||
| 974 | +{ | ||
| 975 | + printf("发送设置警灯状态\n"); | ||
| 976 | + | ||
| 977 | + unsigned char sendbuf[256]; | ||
| 978 | + int send_buf_len; | ||
| 979 | + | ||
| 980 | + //1、获取帧样板 | ||
| 981 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5AFRAME_WARNINGLIGHT_CONTROL, sendbuf, &send_buf_len); | ||
| 982 | + | ||
| 983 | + //2、写入数据 | ||
| 984 | + sendbuf[9] = status; | ||
| 985 | + sendbuf[10] = mode; | ||
| 986 | + | ||
| 987 | + //3、发送帧 | ||
| 988 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 989 | +} | ||
| 990 | + | ||
| 991 | +/************* | ||
| 992 | + * | ||
| 993 | + * 设置警灯颜色 | ||
| 994 | + * | ||
| 995 | + * **************/ | ||
| 996 | +int JZsdk_Uart_SendDeal_Set_WarningLight_Color(int Uartport,int color1, int color2) | ||
| 997 | +{ | ||
| 998 | + printf("发送设置警灯颜色\n"); | ||
| 999 | + | ||
| 1000 | + unsigned char sendbuf[256]; | ||
| 1001 | + int send_buf_len; | ||
| 1002 | + | ||
| 1003 | + //1、获取帧样板 | ||
| 1004 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5AFRAME_WARNINGLIGHT_COLOUR, sendbuf, &send_buf_len); | ||
| 1005 | + | ||
| 1006 | + //2、写入数据 | ||
| 1007 | + sendbuf[9] = color1; | ||
| 1008 | + sendbuf[10] = color2; | ||
| 1009 | + | ||
| 1010 | + //3、发送帧 | ||
| 1011 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 1012 | +} | ||
| 1013 | + | ||
| 1014 | +//查询警灯状态 | ||
| 1015 | +int JZsdk_Uart_SendDeal_CheckStatus_WarningLightStatus(int Uartport) | ||
| 1016 | +{ | ||
| 1017 | + printf("发送查询警灯状态\n"); | ||
| 1018 | + | ||
| 1019 | + unsigned char sendbuf[256]; | ||
| 1020 | + int send_buf_len; | ||
| 1021 | + | ||
| 1022 | + //1、获取帧样板 | ||
| 1023 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5AFRAME_CHECKSTATUS_WARNINGLIGHT_STATUS, sendbuf, &send_buf_len); | ||
| 1024 | + | ||
| 1025 | + //2、发送帧 | ||
| 1026 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 1027 | +} | ||
| 1028 | + | ||
| 1029 | +//查询警灯颜色 | ||
| 1030 | +int JZsdk_Uart_SendDeal_CheckStatus_WarningLightColor(int Uartport) | ||
| 1031 | +{ | ||
| 1032 | + printf("发送查询警灯颜色\n"); | ||
| 1033 | + | ||
| 1034 | + unsigned char sendbuf[256]; | ||
| 1035 | + int send_buf_len; | ||
| 1036 | + | ||
| 1037 | + //1、获取帧样板 | ||
| 1038 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5AFRAME_CHECKSTATUS_WARNINGLIGHT_COLOR, sendbuf, &send_buf_len); | ||
| 1039 | + | ||
| 1040 | + //2、发送帧 | ||
| 1041 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 1042 | +} | ||
| 1043 | + | ||
| 1044 | +/**************************************************************************************************************************************************** | ||
| 1045 | +* | ||
| 1046 | +* 5B类帧 | ||
| 1047 | +* | ||
| 1048 | +****************************************************************************************************************************************************/ | ||
| 1049 | + | ||
| 1050 | +/************* | ||
| 1051 | + * | ||
| 1052 | + * 发送探照灯爆闪频率 | ||
| 1053 | + * | ||
| 1054 | + * **************/ | ||
| 1055 | +int JZsdk_Uart_SendDeal_SearchLight_Frequency(int Uartport, int Frequency) | ||
| 1056 | +{ | ||
| 1057 | + printf("发送灯光频率帧\n"); | ||
| 1058 | + | ||
| 1059 | + unsigned char sendbuf[256]; | ||
| 1060 | + int send_buf_len; | ||
| 1061 | + | ||
| 1062 | + //1、获取帧样板 | ||
| 1063 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5BFRAME_CHECKSTATUS_SEARCHLIGHT_FREQUENCY, sendbuf, &send_buf_len); | ||
| 1064 | + | ||
| 1065 | + //2、写入数据 | ||
| 1066 | + sendbuf[10] = Frequency; | ||
| 1067 | + | ||
| 1068 | + //3、发送帧 | ||
| 1069 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 1070 | +} | ||
| 1071 | + | ||
| 1072 | +/************* | ||
| 1073 | + * | ||
| 1074 | + * 发送探照灯模式 | ||
| 1075 | + * | ||
| 1076 | + * **************/ | ||
| 1077 | +int JZsdk_Uart_SendDeal_SearchLight_Mode(int Uartport, int mode) | ||
| 1078 | +{ | ||
| 1079 | + printf("发送探照灯模式帧\n"); | ||
| 1080 | + | ||
| 1081 | + unsigned char sendbuf[256]; | ||
| 1082 | + int send_buf_len; | ||
| 1083 | + | ||
| 1084 | + //1、获取帧样板 | ||
| 1085 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5BFRAME_CHECKSTATUS_SEARCHLIGHT_MODE, sendbuf, &send_buf_len); | ||
| 1086 | + | ||
| 1087 | + //2、写入数据 | ||
| 1088 | + sendbuf[10] = mode; | ||
| 1089 | + | ||
| 1090 | + //3、发送帧 | ||
| 1091 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 1092 | +} | ||
| 1093 | + | ||
| 1094 | +/************* | ||
| 1095 | + * | ||
| 1096 | + * 发送探照灯亮度 | ||
| 1097 | + * | ||
| 1098 | + * **************/ | ||
| 1099 | +int JZsdk_Uart_SendDeal_SearchLight_Lumen(int Uartport,int LeftLumen, int RightLumen) | ||
| 1100 | +{ | ||
| 1101 | + printf("发送探照灯亮度帧\n"); | ||
| 1102 | + | ||
| 1103 | + unsigned char sendbuf[256]; | ||
| 1104 | + int send_buf_len; | ||
| 1105 | + | ||
| 1106 | + //1、获取帧样板 | ||
| 1107 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5BFRAME_CHECKSTATUS_SEARCHLIGHT_LUMEN, sendbuf, &send_buf_len); | ||
| 1108 | + | ||
| 1109 | + //2、写入数据 | ||
| 1110 | + sendbuf[9] = LeftLumen; | ||
| 1111 | + sendbuf[10] = RightLumen; | ||
| 1112 | + | ||
| 1113 | + //3、发送帧 | ||
| 1114 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 1115 | +} | ||
| 1116 | + | ||
| 1117 | +/************* | ||
| 1118 | + * | ||
| 1119 | + * 发送探照灯温度 | ||
| 1120 | + * | ||
| 1121 | + * **************/ | ||
| 1122 | +int JZsdk_Uart_SendDeal_SearchLight_Temperature(int Uartport, int LeftTemperature, int RightTemperature) | ||
| 1123 | +{ | ||
| 1124 | + printf("发送探照灯温度帧\n"); | ||
| 1125 | + | ||
| 1126 | + unsigned char sendbuf[256]; | ||
| 1127 | + int send_buf_len; | ||
| 1128 | + | ||
| 1129 | + //1、获取帧样板 | ||
| 1130 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5BFRAME_CHECKSTATUS_SEARCHLIGHT_TEMPERATURE, sendbuf, &send_buf_len); | ||
| 1131 | + | ||
| 1132 | + //2、写入数据 | ||
| 1133 | + sendbuf[9] = LeftTemperature; | ||
| 1134 | + sendbuf[10] = RightTemperature; | ||
| 1135 | + | ||
| 1136 | + //3、发送帧 | ||
| 1137 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 1138 | +} | ||
| 1139 | + | ||
| 1140 | + | ||
| 1141 | +/************* | ||
| 1142 | + * | ||
| 1143 | + * 发送警灯状态 | ||
| 1144 | + * | ||
| 1145 | + * **************/ | ||
| 1146 | +int JZsdk_Uart_SendDeal_WarningLight_Status(int Uartport, int status, int mode) | ||
| 1147 | +{ | ||
| 1148 | + printf("发送警灯状态帧\n"); | ||
| 1149 | + | ||
| 1150 | + unsigned char sendbuf[256]; | ||
| 1151 | + int send_buf_len; | ||
| 1152 | + | ||
| 1153 | + //1、获取帧样板 | ||
| 1154 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5BFRAME_CHECKSTATUS_WARNINGLIGHT_STATUS, sendbuf, &send_buf_len); | ||
| 1155 | + | ||
| 1156 | + //2、写入数据 | ||
| 1157 | + sendbuf[9] = status; | ||
| 1158 | + sendbuf[10] = mode; | ||
| 1159 | + | ||
| 1160 | + //3、发送帧 | ||
| 1161 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); } | ||
| 1162 | + | ||
| 1163 | +/************* | ||
| 1164 | + * | ||
| 1165 | + * 发送警灯颜色 | ||
| 1166 | + * | ||
| 1167 | + * **************/ | ||
| 1168 | +int JZsdk_Uart_SendDeal_WarningLight_Color(int Uartport, int color1, int color2) | ||
| 1169 | +{ | ||
| 1170 | + printf("发送警灯颜色帧\n"); | ||
| 1171 | + | ||
| 1172 | + unsigned char sendbuf[256]; | ||
| 1173 | + int send_buf_len; | ||
| 1174 | + | ||
| 1175 | + //1、获取帧样板 | ||
| 1176 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5BFRAME_CHECKSTATUS_WARNINGLIGHT_COLOR, sendbuf, &send_buf_len); | ||
| 1177 | + | ||
| 1178 | + //2、写入数据 | ||
| 1179 | + sendbuf[9] = color1; | ||
| 1180 | + sendbuf[10] = color2; | ||
| 1181 | + | ||
| 1182 | + //3、发送帧 | ||
| 1183 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 1184 | +} | ||
| 1185 | + | ||
| 1186 | +/************* | ||
| 1187 | + * | ||
| 1188 | + * 发送对外电源状态 | ||
| 1189 | + * | ||
| 1190 | + * **************/ | ||
| 1191 | +int JZsdk_Uart_SendDeal_OutputPowerStatus(int Uartport, int FrameSequence, int status) | ||
| 1192 | +{ | ||
| 1193 | + printf("发送对外电源状态帧\n"); | ||
| 1194 | + | ||
| 1195 | + unsigned char sendbuf[256]; | ||
| 1196 | + int send_buf_len; | ||
| 1197 | + | ||
| 1198 | + //1、获取帧样板 | ||
| 1199 | + JZsdk_GetFrameTemplate(JZ_INSCODE_5BFRAME_CHECKSTATUS_OUTPUTPOWER, sendbuf, &send_buf_len); | ||
| 1200 | + | ||
| 1201 | + //2、写入数据 | ||
| 1202 | + sendbuf[9] = status; | ||
| 1203 | + | ||
| 1204 | + //3、发送帧 | ||
| 1205 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 1206 | +} | ||
| 1207 | + | ||
| 1208 | +/**************************************************************************************************************************************************** | ||
| 1209 | +* | ||
| 1210 | +* 6B类帧 | ||
| 1211 | +* | ||
| 1212 | +****************************************************************************************************************************************************/ | ||
| 1213 | +//发送特殊参数 | ||
| 1214 | +int JZsdk_Uart_Reply_CheckSpecialParameters(int Uartport,int FrameSequence,int type, int value) | ||
| 1215 | +{ | ||
| 1216 | + printf("发送特殊参数帧\n"); | ||
| 1217 | + unsigned char sendbuf[256]; | ||
| 1218 | + int send_buf_len; | ||
| 1219 | + | ||
| 1220 | + //1、获取帧样板 | ||
| 1221 | + JZsdk_GetFrameTemplate(JZ_INSCODE_6BFRAME_CHECK_SPECIAL_PARAMETERS, sendbuf, &send_buf_len); | ||
| 1222 | + | ||
| 1223 | + //2、写入数据 | ||
| 1224 | + sendbuf[6] = FrameSequence; //帧序列 | ||
| 1225 | + sendbuf[9] = type; | ||
| 1226 | + sendbuf[10] = value; | ||
| 1227 | + | ||
| 1228 | + //3、发送帧 | ||
| 1229 | + JZsdk_Uart_UartSend(Uartport ,sendbuf, send_buf_len); | ||
| 1230 | +} |
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file JZsdk_Uart_SendDeal.h | ||
| 4 | + * | ||
| 5 | + * | ||
| 6 | + ********************************************************************* | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/ | ||
| 10 | +#ifndef JZSDK_IART_SENDDEAL_H | ||
| 11 | +#define JZSDK_IART_SENDDEAL_H | ||
| 12 | + | ||
| 13 | +/* Includes ------------------------------------------------------------------*/ | ||
| 14 | +#include "JZsdk_Base/JZsdk_Code/JZsdk_Code.h" | ||
| 15 | + | ||
| 16 | +#ifdef __cplusplus | ||
| 17 | +extern "C" { | ||
| 18 | +#endif | ||
| 19 | + | ||
| 20 | +/* Exported constants --------------------------------------------------------*/ | ||
| 21 | +/* 常亮定义*/ | ||
| 22 | + | ||
| 23 | + | ||
| 24 | +/* Exported types ------------------------------------------------------------*/ | ||
| 25 | +int JZsdk_Uart_SendDeal_Send_Connect(int Uartport , int FrameSequence,int Version_flag); | ||
| 26 | +int JZsdk_Uart_SendDeal_ConnectFrame(int PortNum); | ||
| 27 | +int JZsdk_Uart_SendDeal_Send_HeartBeatStatus(int Uartport , int FrameSequence,int HeartBeatStatus); | ||
| 28 | + | ||
| 29 | +T_JZsdkReturnCode JZsdk_Uart_SendDeal_PowerStatus(int Uartport, int FrameSequence, int status); | ||
| 30 | +T_JZsdkReturnCode JZsdk_Uart_SendDeal_Ask_HeartBeatStatus(int Uartport , int FrameSequence,int HeartBeatStatus); | ||
| 31 | +T_JZsdkReturnCode JZsdk_Uart_SendDeal_Ask_TimeStamp(int Uartport , int FrameSequence); | ||
| 32 | +T_JZsdkReturnCode JZsdk_Uart_SendDeal_SendAllVersion(int Uartport, int FrameSequence, int DeviceID, int MajorVersion, int MinorVersion, int ModifyVersion, int DebugVersion); | ||
| 33 | +T_JZsdkReturnCode JZsdk_Uart_SendDeal_SendAllSerialNumber(int Uartport, int FrameSequence, int DeviceID, unsigned char *SerialNumber, int SerialNumberLen); | ||
| 34 | +T_JZsdkReturnCode JZsdk_Uart_SendDeal_DeviceMessage(int UartPort, int FrameSequence, unsigned char *message, unsigned int messageLen); | ||
| 35 | + | ||
| 36 | +int JZsdk_Uart_SendDeal_Reply_SecondaryDeviceName(int Uartport , int device_name, int FrameSequence); | ||
| 37 | +int JZsdk_Uart_SendDeal_QuerySecondaryDeviceName(int Uartport ,int FrameSequence); | ||
| 38 | + | ||
| 39 | + | ||
| 40 | + | ||
| 41 | +int JZsdk_Uart_SendDeal_Reply_Sucesss(int Uartport ,int FrameSequence); | ||
| 42 | +int JZsdk_Uart_SendDeal_Reply_Failure(int Uartport ,int FrameSequence); | ||
| 43 | +T_JZsdkReturnCode JZsdk_Uart_SentDeal_Reply_Musiclist(int UartPort ,int FrameSequence, int music_sum ,char **MusicName ,int *MusicNameLength); | ||
| 44 | +int JZsdk_Uart_SendDeal_Send_PlayStatus_end(int Uartport); | ||
| 45 | +int JZsdk_Uart_SendDeal_Send_PlayStatus(int Uartport ,int num); | ||
| 46 | +int JZsdk_Uart_SendDeal_Reply_MusicName(int Uartport ,char *music_name, int music_name_len); | ||
| 47 | +int JZsdk_Uart_SendDeal_Reply_Volume(int Uartport ,int num); | ||
| 48 | +int JZsdk_Uart_SendDeal_OpusDecodeStatus(int Uartport,int value); | ||
| 49 | + | ||
| 50 | +int JZsdk_Uart_SendDeal_Reply_GimbalPitchAngle(int Uartport ,int angle); | ||
| 51 | +int JZsdk_Uart_SendDeal_Set_GimbalPitchAngle(int Uartport ,int angle); | ||
| 52 | +int JZsdk_Uart_SendDeal_Reply_GimbalFineTuningPitch(int Uartport, int FrameSequence, int FineTunigPitch); | ||
| 53 | +int JZsdk_Uart_SendDeal_Set_GimbalFineTuningPitch(int Uartport, int PitchFineTuning); | ||
| 54 | +int JZsdk_Uart_SendDeal_CheckStatus_GimbalFineTuningPitch(int Uartport, int FrameSequence); | ||
| 55 | +int JZsdk_Uart_SendDeal_Set_GimbalLinkageControl(int Uartport,int FrameSequence, int value); | ||
| 56 | +int JZsdk_Uart_SendDeal_CheckStatus_GimbalLinkage(int Uartport,int FrameSequence); | ||
| 57 | +int JZsdk_Uart_SendDeal_GimbalLinkageControl(int Uartport,int FrameSequence,int value); | ||
| 58 | +int JZsdk_Uart_SendDeal_CheckStatus_GimbalAngle(int Uartport ,int FrameSequence); | ||
| 59 | +int JZsdk_Uart_SendDeal_SetGimbalRange(int Uartport,int FrameSequence,int value); | ||
| 60 | + | ||
| 61 | + | ||
| 62 | +int JZsdk_Uart_SendDeal_Reply_SoftVersion(int Uartport ,char majorVersion, char minorVersion, char modifyVersion, char debugVersion); | ||
| 63 | +int JZsdk_Uart_SendDeal_Reply_LoopPlayStatus(int Uartport ,int status); | ||
| 64 | +int JZsdk_Uart_SendDeal_Reply_TTS_tone(int Uartport ,int tone); | ||
| 65 | +int JZsdk_Uart_SendDeal_Reply_TTS_speed(int Uartport ,int speed); | ||
| 66 | + | ||
| 67 | +int JZsdk_Uart_SendDeal_Set_SearchLightFrequency(int Uartport ,int Frequency); | ||
| 68 | +int JZsdk_Uart_SendDeal_SearchLight_Control(int Uartport,int mode); | ||
| 69 | +int JZsdk_Uart_SendDeal_SearchLight_SetLumen(int Uartport, int LeftLumen, int RightLumen); | ||
| 70 | +int JZsdk_Uart_SendDeal_MessageSubcription_Control(int Uartport, int value); | ||
| 71 | + | ||
| 72 | +int JZsdk_Uart_SendDeal_Set_WarningLight_Status(int Uartport,int status, int mode); | ||
| 73 | +int JZsdk_Uart_SendDeal_Set_WarningLight_Color(int Uartport,int color1, int color2); | ||
| 74 | + | ||
| 75 | +int JZsdk_Uart_SendDeal_SerialNumber(int UartPort, int FrameSequence, char *SerialNumber, int SerialNumberLenth); | ||
| 76 | +int JZsdk_Uart_Reply_CheckSpecialParameters(int Uartport,int FrameSequence,int type, int value); | ||
| 77 | + | ||
| 78 | + | ||
| 79 | + | ||
| 80 | + | ||
| 81 | + | ||
| 82 | + | ||
| 83 | +int JZsdk_Uart_SendDeal_SearchLight_Frequency(int Uartport, int Frequency); | ||
| 84 | +int JZsdk_Uart_SendDeal_SearchLight_Mode(int Uartport, int mode); | ||
| 85 | +int JZsdk_Uart_SendDeal_SearchLight_Lumen(int Uartport,int LeftLumen, int RightLumen); | ||
| 86 | +int JZsdk_Uart_SendDeal_SearchLight_Temperature(int Uartport, int LeftTemperature, int RightTemperature); | ||
| 87 | + | ||
| 88 | + | ||
| 89 | +//查询探照灯频率 | ||
| 90 | +int JZsdk_Uart_SendDeal_Set_SearchLight_CheckStatus_Frequency(int Uartport); | ||
| 91 | +int JZsdk_Uart_SendDeal_Set_SearchLight_CheckStatus_Lumen(int Uartport); | ||
| 92 | +int JZsdk_Uart_SendDeal_Set_SearchLight_CheckStatus_Mode(int Uartport); | ||
| 93 | +int JZsdk_Uart_SendDeal_CheckStatus_LightAttribute(int Uartport); | ||
| 94 | +int JZsdk_Uart_SendDeal_CheckStatus_SearchLightTemperture(int Uartport); | ||
| 95 | + | ||
| 96 | + | ||
| 97 | +int JZsdk_Uart_SendDeal_WarningLight_Status(int Uartport, int status, int mode); | ||
| 98 | +int JZsdk_Uart_SendDeal_WarningLight_Color(int Uartport, int color1, int color2); | ||
| 99 | +int JZsdk_Uart_SendDeal_CheckStatus_WarningLightStatus(int Uartport); | ||
| 100 | +int JZsdk_Uart_SendDeal_CheckStatus_WarningLightColor(int Uartport); | ||
| 101 | + | ||
| 102 | +int JZsdk_Uart_SendDeal_OutputPowerStatus(int Uartport, int FrameSequence, int status); | ||
| 103 | + | ||
| 104 | + | ||
| 105 | +/* Exported functions --------------------------------------------------------*/ | ||
| 106 | + | ||
| 107 | +#ifdef __cplusplus | ||
| 108 | +} | ||
| 109 | +#endif | ||
| 110 | + | ||
| 111 | +#endif |
JZsdk_hal/JZsdk_uart/JZsdk_Uart_UartDeal.c
0 → 100644
| 1 | +#include <stdio.h> | ||
| 2 | +#include <string.h> | ||
| 3 | +#include <pthread.h> | ||
| 4 | +#include <stdlib.h> | ||
| 5 | + | ||
| 6 | +#include <fcntl.h> | ||
| 7 | +#include <unistd.h> | ||
| 8 | +#include <termios.h> | ||
| 9 | +#include <sys/time.h> | ||
| 10 | +#include "JZsdk_uart/Uart_Config.h" | ||
| 11 | +#include "JZsdk_Uart_Recv/JZsdk_Uart_RecvDeal.h" | ||
| 12 | +#include "JZsdkLib.h" | ||
| 13 | +#include "JZsdk_uart/JZsdk_Uart_Input.h" | ||
| 14 | +#include "JZsdk_TaskManagement/TaskManagement.h" | ||
| 15 | +#include "JZsdk_Uart_UartDeal.h" | ||
| 16 | + | ||
| 17 | + | ||
| 18 | +#if APP_VERSION == APP_PSDK | ||
| 19 | + #include "data_transmission/test_data_transmission.h" | ||
| 20 | +#endif | ||
| 21 | + | ||
| 22 | +// 串口参数结构体 | ||
| 23 | +typedef struct | ||
| 24 | +{ | ||
| 25 | + int UartFd; // 串口识别符 | ||
| 26 | + int UartDevName; //串口名 | ||
| 27 | + char Message[1024]; // 传递的字符串 | ||
| 28 | + int MessageLength; // 字符串的长度 | ||
| 29 | + int ResLen; //剩余长度 | ||
| 30 | + pthread_mutex_t WriteMutex; // 互斥锁 | ||
| 31 | + pthread_mutex_t ReadMutex; // 互斥锁 | ||
| 32 | + pthread_cond_t cond; // 条件变量 | ||
| 33 | +} s_SerialArgs; | ||
| 34 | + | ||
| 35 | +// 再注册串口 | ||
| 36 | +typedef struct | ||
| 37 | +{ | ||
| 38 | + int UartFd; // 串口识别符 | ||
| 39 | + int UartDevName; //串口名 | ||
| 40 | + int BitRate; //波特率 | ||
| 41 | +} s_SerialInitArg; | ||
| 42 | + | ||
| 43 | +//不同串口的描述符 | ||
| 44 | +static int Uart_4G_fd; | ||
| 45 | +static int Uart_DEV1_fd; | ||
| 46 | +static int Uart_DEV2_fd; | ||
| 47 | + | ||
| 48 | +//用于判断关闭的是哪个串口 | ||
| 49 | +static int Uart_4G_Switch = JZ_FLAGCODE_OFF; | ||
| 50 | +static int Uart_DEV1_Switch = JZ_FLAGCODE_OFF; | ||
| 51 | +static int Uart_DEV2_Switch = JZ_FLAGCODE_OFF; | ||
| 52 | + | ||
| 53 | +static int Recv_Thread = JZ_FLAGCODE_OFF; //用于判断接收线程是否成功退出 | ||
| 54 | +static int Deal_Thread = JZ_FLAGCODE_OFF; //用于判断处理线程是否成功退出 | ||
| 55 | + | ||
| 56 | +static void *UartDeal_rece(void *arg); | ||
| 57 | +static void *UartDeal_deal(void *arg); | ||
| 58 | + | ||
| 59 | +/********************* | ||
| 60 | + * | ||
| 61 | + * 串口接收线程 | ||
| 62 | + * | ||
| 63 | + * *****************/ | ||
| 64 | +/****************************************************************** | ||
| 65 | + | ||
| 66 | + 初始化串口接收和处理 | ||
| 67 | + | ||
| 68 | +******************************************************************/ | ||
| 69 | +int JZsdk_Uart_UartDeal_Receive(int Uart_fd, int Uart_Dev_name) | ||
| 70 | +{ | ||
| 71 | + int ret = 0; | ||
| 72 | + pthread_t Uart_rece_task; | ||
| 73 | + | ||
| 74 | + pthread_attr_t task_attribute; // 线程属性 | ||
| 75 | + pthread_attr_init(&task_attribute); // 初始化线程属性 | ||
| 76 | + pthread_attr_setdetachstate(&task_attribute, PTHREAD_CREATE_DETACHED); // 设置线程属性 | ||
| 77 | + | ||
| 78 | + if (Uart_Dev_name == UART_DEV_1) | ||
| 79 | + { | ||
| 80 | + Uart_DEV1_fd = Uart_fd; | ||
| 81 | + } | ||
| 82 | + else if (Uart_Dev_name == UART_DEV_2) | ||
| 83 | + { | ||
| 84 | + Uart_DEV2_fd = Uart_fd; | ||
| 85 | + } | ||
| 86 | + else if (Uart_Dev_name == UART_4G) | ||
| 87 | + { | ||
| 88 | + Uart_4G_fd = Uart_fd; | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + s_SerialArgs *parameter = (s_SerialArgs *)malloc(sizeof(s_SerialArgs)); | ||
| 92 | + parameter->UartFd = Uart_fd; | ||
| 93 | + parameter->UartDevName = Uart_Dev_name; | ||
| 94 | + parameter->MessageLength = 0; | ||
| 95 | + memset(parameter->Message, 0, sizeof(parameter->Message)); | ||
| 96 | + pthread_mutex_init(¶meter->WriteMutex, NULL); | ||
| 97 | + pthread_mutex_init(¶meter->ReadMutex, NULL); | ||
| 98 | + | ||
| 99 | + pthread_cond_init(¶meter->cond, NULL); | ||
| 100 | + | ||
| 101 | + // 创建串口数据接收线程 | ||
| 102 | + pthread_t receiveThread; | ||
| 103 | + pthread_t SerialDealThread; | ||
| 104 | + pthread_attr_t task_attribute1; // 线程属性 | ||
| 105 | + pthread_attr_t task_attribute2; // 线程属性 | ||
| 106 | + pthread_attr_setdetachstate(&task_attribute1, PTHREAD_CREATE_DETACHED); // 设置线程分离属性 | ||
| 107 | + pthread_attr_setdetachstate(&task_attribute2, PTHREAD_CREATE_DETACHED); // 设置线程分离属性 | ||
| 108 | + | ||
| 109 | + pthread_attr_init(&task_attribute1); | ||
| 110 | + pthread_attr_init(&task_attribute2); | ||
| 111 | + | ||
| 112 | + if (pthread_create(&receiveThread, &task_attribute1, UartDeal_rece, parameter) != 0) | ||
| 113 | + { | ||
| 114 | + JZSDK_LOG_ERROR("Failed to create receive thread"); | ||
| 115 | + return 1; | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + // 创建串口数据处理线程 | ||
| 119 | + if (pthread_create(&SerialDealThread, &task_attribute2, UartDeal_deal, parameter) != 0) | ||
| 120 | + { | ||
| 121 | + JZSDK_LOG_ERROR("Failed to create receive thread"); | ||
| 122 | + return 1; | ||
| 123 | + } | ||
| 124 | +} | ||
| 125 | +/*** | ||
| 126 | + * | ||
| 127 | + * 串口接收线程 | ||
| 128 | + * | ||
| 129 | + * ***/ | ||
| 130 | +static void *UartDeal_rece(void *arg) | ||
| 131 | +{ | ||
| 132 | + | ||
| 133 | + s_SerialArgs *args = (s_SerialArgs *)arg; | ||
| 134 | + struct timeval timeout; // 超时时间 | ||
| 135 | + fd_set fs_read; | ||
| 136 | + | ||
| 137 | + int Uart_fd = args->UartFd; | ||
| 138 | + | ||
| 139 | + FD_ZERO(&fs_read); | ||
| 140 | + FD_SET(Uart_fd, &fs_read); | ||
| 141 | + | ||
| 142 | + memset(args->Message, 0, sizeof(args->Message)); // 清空接收数组 | ||
| 143 | + args->ResLen = 0; | ||
| 144 | + args->MessageLength = 0; | ||
| 145 | + | ||
| 146 | + int *TheadSwtch = NULL; | ||
| 147 | + if (args->UartDevName == UART_4G) | ||
| 148 | + { | ||
| 149 | + TheadSwtch = &Uart_4G_Switch; | ||
| 150 | + Uart_4G_Switch = JZ_FLAGCODE_ON; | ||
| 151 | + } | ||
| 152 | + else if (args->UartDevName == UART_DEV_1) | ||
| 153 | + { | ||
| 154 | + TheadSwtch = &Uart_DEV1_Switch; | ||
| 155 | + Uart_DEV1_Switch = JZ_FLAGCODE_ON; | ||
| 156 | + } | ||
| 157 | + else if (args->UartDevName == UART_DEV_2) | ||
| 158 | + { | ||
| 159 | + TheadSwtch = &Uart_DEV2_Switch; | ||
| 160 | + Uart_DEV2_Switch = JZ_FLAGCODE_ON; | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + while (*TheadSwtch) | ||
| 164 | + { | ||
| 165 | + FD_ZERO(&fs_read); | ||
| 166 | + FD_SET(Uart_fd, &fs_read); | ||
| 167 | + | ||
| 168 | + timeout.tv_sec = 0; | ||
| 169 | + timeout.tv_usec = 100000; // 设置为可变的超时时间(100毫秒) | ||
| 170 | + | ||
| 171 | + // 检查fs_read套接字是否有数据 | ||
| 172 | + int ret = select(Uart_fd + 1, &fs_read, NULL, NULL, &timeout); | ||
| 173 | + if (ret < 0) { | ||
| 174 | + // 发生错误 | ||
| 175 | + JZSDK_LOG_ERROR("串口select出错"); | ||
| 176 | + args->MessageLength = 0; | ||
| 177 | + args->ResLen = 0; | ||
| 178 | + memset(&(args->Message[0]), 0, sizeof(args->Message)); | ||
| 179 | + delayMs(3); | ||
| 180 | + continue; | ||
| 181 | + } else if (ret == 0) | ||
| 182 | + { | ||
| 183 | + // 超时 | ||
| 184 | + continue; | ||
| 185 | + } | ||
| 186 | + | ||
| 187 | + // 如果有数据就加锁 | ||
| 188 | + pthread_mutex_lock(&args->WriteMutex); | ||
| 189 | + | ||
| 190 | + // 读取串口内容 | ||
| 191 | + int bytesRead = read(Uart_fd, &(args->Message[args->ResLen]), (sizeof(args->Message) - args->ResLen)); | ||
| 192 | + if (bytesRead > 0) | ||
| 193 | + { | ||
| 194 | + args->MessageLength = args->ResLen + bytesRead; | ||
| 195 | + | ||
| 196 | + // data_len+=bytesRead; | ||
| 197 | + // data_len2+=args->MessageLength; | ||
| 198 | + // printf("当前接收长度%d bytesRead%d bmessage%d reslen%d\n",data_len,bytesRead,data_len2,args->ResLen); | ||
| 199 | + | ||
| 200 | + // JZSDK_LOG_INFO("从串口读取到,长度%d",(args->MessageLength-args->ResLen)); | ||
| 201 | + | ||
| 202 | + // for (int i = 0; i < (args->MessageLength-args->ResLen); i++) | ||
| 203 | + // { | ||
| 204 | + // JZSDK_LOG_OUTPUTHEX("%s",&args->Message[i+args->ResLen]); | ||
| 205 | + // } | ||
| 206 | + | ||
| 207 | + args->ResLen = 0; | ||
| 208 | + } | ||
| 209 | + else if (bytesRead == 0) | ||
| 210 | + { | ||
| 211 | + // 串口关闭或者无数据可读 | ||
| 212 | + JZSDK_LOG_ERROR("串口读取数据为空"); | ||
| 213 | + args->MessageLength = 0; | ||
| 214 | + args->ResLen = 0; | ||
| 215 | + memset(&(args->Message[0]), 0, sizeof(args->Message)); | ||
| 216 | + } | ||
| 217 | + else | ||
| 218 | + { | ||
| 219 | + // 读取错误发生 | ||
| 220 | + JZSDK_LOG_ERROR("Error reading from serial port"); | ||
| 221 | + args->MessageLength = 0; | ||
| 222 | + args->ResLen = 0; | ||
| 223 | + memset(&(args->Message[0]), 0, sizeof(args->Message)); | ||
| 224 | + } | ||
| 225 | + | ||
| 226 | + // 通知线程 | ||
| 227 | + //pthread_cond_signal(&args->cond); | ||
| 228 | + pthread_mutex_unlock(&args->ReadMutex); // 解锁 | ||
| 229 | + | ||
| 230 | + // 添加适当延时,确保接收缓冲区完全填满 | ||
| 231 | + delayMs(3); // 加多了可能导致实时播放难恢复,以及声音间隔 3ms32字节 会向上约1个3ms opus一帧80字节 | ||
| 232 | + } | ||
| 233 | + | ||
| 234 | + //注销相关 | ||
| 235 | + Recv_Thread = JZ_FLAGCODE_OFF; | ||
| 236 | + // 通知线程 | ||
| 237 | + //pthread_cond_signal(&args->cond); | ||
| 238 | + pthread_mutex_unlock(&args->WriteMutex); // 解锁 | ||
| 239 | + | ||
| 240 | + JZSDK_LOG_WARN("串口接收线程被关闭"); | ||
| 241 | +} | ||
| 242 | + | ||
| 243 | +/*** | ||
| 244 | + * | ||
| 245 | + * 串口处理线程 | ||
| 246 | + * | ||
| 247 | + * ***/ | ||
| 248 | +// 串口数据处理线程函数 | ||
| 249 | +static void *UartDeal_deal(void *arg) | ||
| 250 | +{ | ||
| 251 | + s_SerialArgs *args = (s_SerialArgs *)arg; | ||
| 252 | + | ||
| 253 | + static int ResidualLength = 0; // 未处理数据长度 | ||
| 254 | + | ||
| 255 | + int *TheadSwtch = NULL; | ||
| 256 | + if (args->UartDevName == UART_4G) | ||
| 257 | + { | ||
| 258 | + TheadSwtch = &Uart_4G_Switch; | ||
| 259 | + Uart_4G_Switch = JZ_FLAGCODE_ON; | ||
| 260 | + } | ||
| 261 | + else if (args->UartDevName == UART_DEV_1) | ||
| 262 | + { | ||
| 263 | + TheadSwtch = &Uart_DEV1_Switch; | ||
| 264 | + Uart_DEV1_Switch = JZ_FLAGCODE_ON; | ||
| 265 | + } | ||
| 266 | + else if (args->UartDevName == UART_DEV_2) | ||
| 267 | + { | ||
| 268 | + TheadSwtch = &Uart_DEV2_Switch; | ||
| 269 | + Uart_DEV2_Switch = JZ_FLAGCODE_ON; | ||
| 270 | + } | ||
| 271 | + | ||
| 272 | + //int data_len = 0; | ||
| 273 | + | ||
| 274 | + while (*TheadSwtch) | ||
| 275 | + { | ||
| 276 | + | ||
| 277 | + // 加锁 | ||
| 278 | + pthread_mutex_lock(&args->ReadMutex); | ||
| 279 | + | ||
| 280 | + // 等候接收线程的通知 | ||
| 281 | + //pthread_cond_wait(&args->cond, &args->mutex); | ||
| 282 | + | ||
| 283 | + // data_len+=args->MessageLength; | ||
| 284 | + // printf("当前处理长度%d\n",data_len); | ||
| 285 | + | ||
| 286 | + if (args->MessageLength > 0) | ||
| 287 | + { | ||
| 288 | + | ||
| 289 | + //清除错误的多余半帧 | ||
| 290 | + //前面有帧的长度 | ||
| 291 | + if(args->ResLen != 0) | ||
| 292 | + { | ||
| 293 | + //存在第一帧,同时第二轮的数据开头是帧头,则清空前半段第一帧 | ||
| 294 | + if ( (args->Message[args->ResLen ] == 0x5A) | ||
| 295 | + && (args->Message[args->ResLen + 1] == 0x5A) | ||
| 296 | + && (args->Message[args->ResLen + 2] == 0x77) ) | ||
| 297 | + { | ||
| 298 | + int temp_num; | ||
| 299 | + temp_num = args->MessageLength - args->ResLen; | ||
| 300 | + if (temp_num < 0) | ||
| 301 | + { | ||
| 302 | + temp_num = 0; | ||
| 303 | + } | ||
| 304 | + | ||
| 305 | + memcpy(args->Message, &(args->Message[args->ResLen]), temp_num); | ||
| 306 | + memset(&args->Message[temp_num], 0, (args->MessageLength - temp_num)); | ||
| 307 | + args->MessageLength = temp_num; | ||
| 308 | + args->ResLen = 0; | ||
| 309 | + | ||
| 310 | + JZSDK_LOG_ERROR("串口上一帧为不完全帧,舍弃该帧操作"); | ||
| 311 | + } | ||
| 312 | + } | ||
| 313 | + | ||
| 314 | + // 处理数据 | ||
| 315 | + ResidualLength = UartDeal_Recv_interface(0, args->UartFd, args->Message, args->MessageLength); | ||
| 316 | + //如果还有剩余的长度 | ||
| 317 | + if (ResidualLength != 0) | ||
| 318 | + { | ||
| 319 | + memcpy(args->Message, &(args->Message[args->MessageLength - ResidualLength]), ResidualLength); | ||
| 320 | + memset(&(args->Message[ResidualLength]), 0, (sizeof(args->Message) - ResidualLength)); | ||
| 321 | + args->MessageLength = 0; | ||
| 322 | + args->ResLen = ResidualLength; | ||
| 323 | + } | ||
| 324 | + else | ||
| 325 | + { | ||
| 326 | + memset(args->Message, 0, sizeof(args->Message)); | ||
| 327 | + args->MessageLength = 0; | ||
| 328 | + args->ResLen = 0; | ||
| 329 | + } | ||
| 330 | + | ||
| 331 | + } | ||
| 332 | + else | ||
| 333 | + { | ||
| 334 | + memset(args->Message, 0, sizeof(args->Message)); | ||
| 335 | + args->MessageLength = 0; | ||
| 336 | + args->ResLen = 0; | ||
| 337 | + } | ||
| 338 | + | ||
| 339 | + pthread_mutex_unlock(&args->WriteMutex); // 解锁 | ||
| 340 | + } | ||
| 341 | + | ||
| 342 | + Deal_Thread = JZ_FLAGCODE_OFF; | ||
| 343 | + free(args); //释放掉处理结构体 | ||
| 344 | + JZSDK_LOG_WARN("串口处理线程被关闭"); | ||
| 345 | +} | ||
| 346 | + | ||
| 347 | +/* | ||
| 348 | + | ||
| 349 | + 数据排出函数 | ||
| 350 | + | ||
| 351 | +*/ | ||
| 352 | +static int UartDeal_Recv_Ouput(int tpye, int fd, unsigned char *getbuf, int ReadLen) | ||
| 353 | +{ | ||
| 354 | + //JZSDK_LOG_INFO("UartDeal_Recv_Ouput排出函数%d",ReadLen); | ||
| 355 | + if (tpye == 0) | ||
| 356 | + { | ||
| 357 | + if (fd == Uart_DEV1_fd) | ||
| 358 | + { | ||
| 359 | + JZsdk_Uart_RecvDeal_CharmDeal(UART_DEV_1, getbuf, ReadLen); | ||
| 360 | + | ||
| 361 | + } | ||
| 362 | + else if (fd == Uart_DEV2_fd) | ||
| 363 | + { | ||
| 364 | + JZsdk_Uart_RecvDeal_CharmDeal(UART_DEV_2, getbuf, ReadLen); | ||
| 365 | + } | ||
| 366 | + else if (fd == Uart_4G_fd) | ||
| 367 | + { | ||
| 368 | + JZsdk_Uart_RecvDeal_CharmDeal(UART_4G, getbuf, ReadLen); | ||
| 369 | + } | ||
| 370 | + else | ||
| 371 | + { | ||
| 372 | + JZSDK_LOG_ERROR("接收到的数据不是从正常串口来的"); | ||
| 373 | + return 0; | ||
| 374 | + } | ||
| 375 | + } | ||
| 376 | + else if (tpye == 1) | ||
| 377 | + { | ||
| 378 | + if (fd == HAL_DATA_TRANSMISSION) | ||
| 379 | + { | ||
| 380 | + JZsdk_Uart_RecvDeal_CharmDeal(HAL_DATA_TRANSMISSION, getbuf, ReadLen); | ||
| 381 | + } | ||
| 382 | + else | ||
| 383 | + { | ||
| 384 | + JZSDK_LOG_ERROR("接收到的数据不是从hal_transmisson来的"); | ||
| 385 | + return 0; | ||
| 386 | + } | ||
| 387 | + } | ||
| 388 | +} | ||
| 389 | + | ||
| 390 | +/* | ||
| 391 | + | ||
| 392 | + 处理数据接口,返回没有处理的数据长度 | ||
| 393 | + | ||
| 394 | +*/ | ||
| 395 | +int UartDeal_Recv_interface(int type, int Uart_fd , unsigned char *getbuf, int getbufLen) | ||
| 396 | +{ | ||
| 397 | + //0即是串口内容 | ||
| 398 | + if (type == 0) | ||
| 399 | + { | ||
| 400 | + if (Uart_fd == Uart_DEV1_fd) | ||
| 401 | + { | ||
| 402 | + JZSDK_LOG_INFO("串口-设备1号,接受到数据+未处理数据的长度len: %d", getbufLen); | ||
| 403 | + } | ||
| 404 | + else if (Uart_fd == Uart_DEV2_fd) | ||
| 405 | + { | ||
| 406 | + JZSDK_LOG_INFO("串口-设备2号,接受到数据+未处理数据的长度len: %d", getbufLen); | ||
| 407 | + } | ||
| 408 | + else if (Uart_fd == Uart_4G_fd) | ||
| 409 | + { | ||
| 410 | + JZSDK_LOG_INFO("串口-设备4G,接受到数据+未处理数据的长度len: %d", getbufLen); | ||
| 411 | + } | ||
| 412 | + else | ||
| 413 | + { | ||
| 414 | + JZSDK_LOG_ERROR("接收到的数据不是从正常串口来的"); | ||
| 415 | + return 0; | ||
| 416 | + } | ||
| 417 | + } | ||
| 418 | + else if (type == 1) | ||
| 419 | + { | ||
| 420 | + if (Uart_fd == HAL_DATA_TRANSMISSION) | ||
| 421 | + { | ||
| 422 | + JZSDK_LOG_INFO("hal_data,接受到数据+未处理数据的长度len: %d", getbufLen); | ||
| 423 | + } | ||
| 424 | + else | ||
| 425 | + { | ||
| 426 | + JZSDK_LOG_ERROR("接收到的数据不是从hal_transmisson来的"); | ||
| 427 | + return 0; | ||
| 428 | + } | ||
| 429 | + } | ||
| 430 | + | ||
| 431 | + // 是否要打印内容 | ||
| 432 | + // printf("getbuf: %s\n", getbuf); | ||
| 433 | + // for (int i = 0; i < getbufLen; i++) | ||
| 434 | + // { | ||
| 435 | + // printf("%x ", getbuf[i]); | ||
| 436 | + // } | ||
| 437 | + // printf("\n"); | ||
| 438 | + | ||
| 439 | + int HaveReadLen = 0; // 已读长度 | ||
| 440 | + int HaveDealLen = 0; // 已处理长度 | ||
| 441 | + int FrameFlag = 0; // 帧标志 | ||
| 442 | + int FrameLen = 0; | ||
| 443 | + | ||
| 444 | + // 检索出帧数据 | ||
| 445 | + | ||
| 446 | + // 遍历数据找帧头,直到数据的倒数第4位,如果这里有帧,帧存在帧头3位+数据长度两位 | ||
| 447 | + | ||
| 448 | + //printf("遍历开始\n"); | ||
| 449 | + for (HaveReadLen = 0; HaveReadLen < (getbufLen - 4); ) | ||
| 450 | + { | ||
| 451 | + // 1、如果找到 5A 5B 6A 6B 判断是否是帧 | ||
| 452 | + switch (getbuf[HaveReadLen]) | ||
| 453 | + { | ||
| 454 | + case 0x5A: | ||
| 455 | + if ( (getbuf[HaveReadLen + 1] == 0x5A) && (getbuf[HaveReadLen + 2] == 0x77)) | ||
| 456 | + { | ||
| 457 | + //JZSDK_LOG_INFO("输入5A"); | ||
| 458 | + FrameFlag = 0x5A; | ||
| 459 | + break; | ||
| 460 | + } | ||
| 461 | + else | ||
| 462 | + { | ||
| 463 | + FrameFlag = 0x00; | ||
| 464 | + break; | ||
| 465 | + } | ||
| 466 | + | ||
| 467 | + case 0x5B: | ||
| 468 | + if ((getbuf[HaveReadLen + 1] == 0x5B) && (getbuf[HaveReadLen + 2] == 0x77)) | ||
| 469 | + { | ||
| 470 | + //JZSDK_LOG_INFO("输入5B"); | ||
| 471 | + FrameFlag = 0x5B; | ||
| 472 | + break; | ||
| 473 | + } | ||
| 474 | + else | ||
| 475 | + { | ||
| 476 | + FrameFlag = 0x00; | ||
| 477 | + break; | ||
| 478 | + } | ||
| 479 | + | ||
| 480 | + case 0x6A: | ||
| 481 | + if ((getbuf[HaveReadLen + 1] == 0x6A) && (getbuf[HaveReadLen + 2] == 0x77)) | ||
| 482 | + { | ||
| 483 | + //JZSDK_LOG_INFO("输入6A"); | ||
| 484 | + FrameFlag = 0x6A; | ||
| 485 | + break; | ||
| 486 | + } | ||
| 487 | + else | ||
| 488 | + { | ||
| 489 | + FrameFlag = 0x00; | ||
| 490 | + break; | ||
| 491 | + } | ||
| 492 | + | ||
| 493 | + case 0x6B: | ||
| 494 | + if ((getbuf[HaveReadLen + 1] == 0x6B) && (getbuf[HaveReadLen + 2] == 0x77)) | ||
| 495 | + { | ||
| 496 | + //JZSDK_LOG_INFO("输入6B"); | ||
| 497 | + FrameFlag = 0x6B; | ||
| 498 | + break; | ||
| 499 | + } | ||
| 500 | + else | ||
| 501 | + { | ||
| 502 | + FrameFlag = 0x00; | ||
| 503 | + break; | ||
| 504 | + } | ||
| 505 | + | ||
| 506 | + default: | ||
| 507 | + FrameFlag = 0x00; | ||
| 508 | + break; | ||
| 509 | + } | ||
| 510 | + | ||
| 511 | + if (FrameFlag == 0) | ||
| 512 | + { | ||
| 513 | + if (HaveReadLen >= (getbufLen - 5)) | ||
| 514 | + { | ||
| 515 | + //JZSDK_LOG_INFO("没有找到帧头"); | ||
| 516 | + } | ||
| 517 | + HaveReadLen++; | ||
| 518 | + continue; | ||
| 519 | + } | ||
| 520 | + | ||
| 521 | + // 3、如果有帧头,则先判断前面有没有多余的数据残留,并将其排出到处理线程 | ||
| 522 | + if ((HaveReadLen - HaveDealLen) > 0) | ||
| 523 | + { | ||
| 524 | + //JZSDK_LOG_INFO("残余处理%d",(HaveReadLen - HaveDealLen)); | ||
| 525 | + UartDeal_Recv_Ouput(type, Uart_fd, &getbuf[HaveDealLen], (HaveReadLen - HaveDealLen)); | ||
| 526 | + HaveDealLen = HaveReadLen; | ||
| 527 | + } | ||
| 528 | + | ||
| 529 | + // 4、检查帧长度是否超过数组剩余内容 | ||
| 530 | + FrameLen = (((int)getbuf[HaveReadLen+3]) << 8) + (int)getbuf[HaveReadLen+4]; | ||
| 531 | + if (FrameLen > (getbufLen - HaveReadLen)) | ||
| 532 | + { | ||
| 533 | + JZSDK_LOG_DEBUG("当前帧长度位长度%d 超出剩余帧长度%d ",FrameLen,(getbufLen - HaveReadLen)); | ||
| 534 | + // 直接跳出for循环 | ||
| 535 | + break; | ||
| 536 | + } | ||
| 537 | + | ||
| 538 | + //5、检查帧长度是否为0,避免卡死接收串口 | ||
| 539 | + if (FrameLen == 0) | ||
| 540 | + { | ||
| 541 | + JZSDK_LOG_ERROR("严重错误,接收到的帧出现长度为空"); | ||
| 542 | + //直接清空接收的数组 | ||
| 543 | + return 0; | ||
| 544 | + } | ||
| 545 | + | ||
| 546 | + // 6、以上检查都没问题,则正常输出帧 | ||
| 547 | + //JZSDK_LOG_INFO("正常输出帧%d",FrameLen); | ||
| 548 | + UartDeal_Recv_Ouput(type, Uart_fd, &getbuf[HaveReadLen], FrameLen); | ||
| 549 | + HaveReadLen = HaveReadLen + FrameLen; | ||
| 550 | + HaveDealLen = HaveReadLen; | ||
| 551 | + | ||
| 552 | + JZSDK_LOG_INFO("framelen%d read%d [read]:%x get%d",FrameLen ,HaveReadLen, getbuf[HaveReadLen], getbufLen); | ||
| 553 | + | ||
| 554 | + FrameLen = 0; | ||
| 555 | + FrameFlag = 0; | ||
| 556 | + } | ||
| 557 | + | ||
| 558 | + //JZSDK_LOG_INFO("UartDeal_Recv_Ouput%d %d %d",HaveDealLen,HaveReadLen , getbufLen); | ||
| 559 | + | ||
| 560 | + // 如果没有数据残留了 | ||
| 561 | + if (HaveDealLen >= getbufLen) | ||
| 562 | + { | ||
| 563 | + //printf("HaveReadLen:%d HaveDealLen%d getbufLen:%d\n",HaveReadLen,HaveDealLen,getbufLen); | ||
| 564 | + return 0; | ||
| 565 | + } | ||
| 566 | + | ||
| 567 | + // 如果是有帧头的情况跳出的,说明是帧被切了,需要返回帧长度给接收线程 | ||
| 568 | + if (FrameFlag != 0) //bu | ||
| 569 | + { | ||
| 570 | + // 1、判断帧的长度会不会不合理,帧的长度最大为文件名帧,其长度为9+2+400 | ||
| 571 | + if (FrameLen > (9 + 2 + 400)) | ||
| 572 | + { | ||
| 573 | + // 将其排出不返回 | ||
| 574 | + UartDeal_Recv_Ouput(type, Uart_fd, &getbuf[HaveReadLen], (getbufLen - HaveReadLen)); | ||
| 575 | + HaveDealLen = HaveReadLen; | ||
| 576 | + return 0; | ||
| 577 | + } | ||
| 578 | + | ||
| 579 | + printf("切帧返回%d\n",(getbufLen - HaveDealLen)); | ||
| 580 | + | ||
| 581 | + // 2、如果合理,则返回剩余长度 | ||
| 582 | + return (getbufLen - HaveDealLen); | ||
| 583 | + } | ||
| 584 | + | ||
| 585 | + // 如果是没有帧头的情况下跳出的 | ||
| 586 | + // 1、先检查 未经检查最后 最后4 3位 | ||
| 587 | + //如果还有4 或者 3 位未处理 | ||
| 588 | + for (; HaveReadLen < getbufLen - 2; HaveReadLen++) | ||
| 589 | + { | ||
| 590 | + if ((getbuf[HaveReadLen] == 0x5A && getbuf[HaveReadLen + 1] == 0x5A && getbuf[HaveReadLen + 2] == 0x77) || | ||
| 591 | + (getbuf[HaveReadLen] == 0x5B && getbuf[HaveReadLen + 1] == 0x5B && getbuf[HaveReadLen + 2] == 0x77) || | ||
| 592 | + (getbuf[HaveReadLen] == 0x6A && getbuf[HaveReadLen + 1] == 0x6A && getbuf[HaveReadLen + 2] == 0x77) || | ||
| 593 | + (getbuf[HaveReadLen] == 0x6B && getbuf[HaveReadLen + 1] == 0x6B && getbuf[HaveReadLen + 2] == 0x77)) | ||
| 594 | + { | ||
| 595 | + if ((HaveReadLen - HaveDealLen) > 0) | ||
| 596 | + { | ||
| 597 | + UartDeal_Recv_Ouput(type, Uart_fd, &getbuf[HaveDealLen], (HaveReadLen - HaveDealLen)); | ||
| 598 | + HaveDealLen = HaveReadLen; | ||
| 599 | + } | ||
| 600 | + | ||
| 601 | + printf("检查最后3 4位%d\n",(getbufLen - HaveDealLen)); | ||
| 602 | + | ||
| 603 | + return (getbufLen - HaveDealLen); | ||
| 604 | + } | ||
| 605 | + } | ||
| 606 | + | ||
| 607 | + // 2、检查最后两位 | ||
| 608 | + // 如果还有两位未处理 | ||
| 609 | + for (; HaveReadLen < getbufLen - 1; HaveReadLen++) | ||
| 610 | + { | ||
| 611 | + if ((getbuf[HaveReadLen] == 0x5A && getbuf[HaveReadLen + 1] == 0x5A) || | ||
| 612 | + (getbuf[HaveReadLen] == 0x5B && getbuf[HaveReadLen + 1] == 0x5B) || | ||
| 613 | + (getbuf[HaveReadLen] == 0x6A && getbuf[HaveReadLen + 1] == 0x6A) || | ||
| 614 | + (getbuf[HaveReadLen] == 0x6B && getbuf[HaveReadLen + 1] == 0x6B)) | ||
| 615 | + { | ||
| 616 | + if ((HaveReadLen - HaveDealLen) > 0) | ||
| 617 | + { | ||
| 618 | + UartDeal_Recv_Ouput(type, Uart_fd, &getbuf[HaveDealLen], (HaveReadLen - HaveDealLen)); | ||
| 619 | + HaveDealLen = HaveReadLen; | ||
| 620 | + } | ||
| 621 | + | ||
| 622 | + printf("检查最后两位%d\n",(getbufLen - HaveDealLen)); | ||
| 623 | + | ||
| 624 | + return (getbufLen - HaveDealLen); | ||
| 625 | + } | ||
| 626 | + } | ||
| 627 | + | ||
| 628 | + // 2、检查最后一位 | ||
| 629 | + // 如果还有一位未处理 | ||
| 630 | + for (; HaveReadLen < getbufLen - 0; HaveReadLen++) | ||
| 631 | + { | ||
| 632 | + // 1、检查最后一位 | ||
| 633 | + if (getbuf[HaveReadLen] == 0x5A || | ||
| 634 | + getbuf[HaveReadLen] == 0x5B || | ||
| 635 | + getbuf[HaveReadLen] == 0x6A || | ||
| 636 | + getbuf[HaveReadLen] == 0x6B) | ||
| 637 | + { | ||
| 638 | + if ((HaveReadLen - HaveDealLen) > 0) | ||
| 639 | + { | ||
| 640 | + UartDeal_Recv_Ouput(type, Uart_fd, &getbuf[HaveDealLen], (HaveReadLen - HaveDealLen)); | ||
| 641 | + HaveDealLen = HaveReadLen; | ||
| 642 | + } | ||
| 643 | + | ||
| 644 | + printf("检查最后一位%d\n",(getbufLen - HaveDealLen)); | ||
| 645 | + | ||
| 646 | + return (getbufLen - HaveDealLen); | ||
| 647 | + } | ||
| 648 | + } | ||
| 649 | + | ||
| 650 | + // 都检查完了,还是没有帧头在里面, 将剩余的所有数据排出 | ||
| 651 | + UartDeal_Recv_Ouput(type, Uart_fd, &getbuf[HaveDealLen], (HaveReadLen - HaveDealLen)); | ||
| 652 | + printf("检查完毕,排出剩余数据HaveReadLen:%d HaveDealLen%d getbufLen:%d\n",HaveReadLen,HaveDealLen,getbufLen); | ||
| 653 | + | ||
| 654 | + return 0; | ||
| 655 | +} | ||
| 656 | + | ||
| 657 | +/********** | ||
| 658 | + * | ||
| 659 | + * 无任务发送函数 | ||
| 660 | + * | ||
| 661 | + * ***********/ | ||
| 662 | +T_JZsdkReturnCode JZsdk_Uart_UartSend_NotTask(int Uart_Name, unsigned char *str, int str_lenth) | ||
| 663 | +{ | ||
| 664 | + if (Uart_Name == UART_4G) | ||
| 665 | + { | ||
| 666 | + printf("向4G设备发送\n"); | ||
| 667 | + write(Uart_4G_fd, str, str_lenth); | ||
| 668 | + } | ||
| 669 | + else if (Uart_Name == UART_DEV_1) | ||
| 670 | + { | ||
| 671 | + printf("向串口1号设备发送\n"); | ||
| 672 | + write(Uart_DEV1_fd, str, str_lenth); | ||
| 673 | + } | ||
| 674 | + else if (Uart_Name = UART_DEV_2) | ||
| 675 | + { | ||
| 676 | + printf("向串口2号设备发送\n"); | ||
| 677 | + write(Uart_DEV2_fd, str, str_lenth); | ||
| 678 | + } | ||
| 679 | + | ||
| 680 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 681 | +} | ||
| 682 | + | ||
| 683 | +typedef struct { | ||
| 684 | + char* str; | ||
| 685 | + int str_lenth; | ||
| 686 | + int Uart_name; | ||
| 687 | +} UartSendData; | ||
| 688 | + | ||
| 689 | +/********** | ||
| 690 | + * | ||
| 691 | + * 发送任务函数 | ||
| 692 | + * | ||
| 693 | + * ***********/ | ||
| 694 | +static void JZsdk_Uart_UartSend_Task(void *data) | ||
| 695 | +{ | ||
| 696 | + UartSendData* taskData = (UartSendData*)data; | ||
| 697 | + | ||
| 698 | + if (taskData->Uart_name == UART_4G) | ||
| 699 | + { | ||
| 700 | + printf("向4G设备发送\n"); | ||
| 701 | + write(Uart_4G_fd, taskData->str, taskData->str_lenth); | ||
| 702 | + } | ||
| 703 | + else if (taskData->Uart_name == UART_DEV_1) | ||
| 704 | + { | ||
| 705 | + printf("向串口1号设备发送\n"); | ||
| 706 | + write(Uart_DEV1_fd, taskData->str, taskData->str_lenth); | ||
| 707 | + } | ||
| 708 | + else if (taskData->Uart_name == UART_DEV_2) | ||
| 709 | + { | ||
| 710 | + printf("向串口2号设备发送\n"); | ||
| 711 | + write(Uart_DEV2_fd, taskData->str, taskData->str_lenth); | ||
| 712 | + } | ||
| 713 | + else if (taskData->Uart_name == HAL_DATA_TRANSMISSION) | ||
| 714 | + { | ||
| 715 | +#if APP_VERSION == APP_PSDK | ||
| 716 | + DJI_Low_Data_Trans(taskData->str, taskData->str_lenth); | ||
| 717 | +#endif | ||
| 718 | + } | ||
| 719 | + | ||
| 720 | + free(taskData->str); | ||
| 721 | + taskData->str = NULL; | ||
| 722 | + | ||
| 723 | + free(taskData); | ||
| 724 | + taskData = NULL; | ||
| 725 | +} | ||
| 726 | + | ||
| 727 | +/**************** | ||
| 728 | + * | ||
| 729 | + * | ||
| 730 | + * 发送函数 | ||
| 731 | + * | ||
| 732 | + * ****************/ | ||
| 733 | +T_JZsdkReturnCode JZsdk_Uart_UartSend(int UartPort, unsigned char *send, int num) | ||
| 734 | +{ | ||
| 735 | + UartSendData *senddata = (UartSendData*)malloc(sizeof(UartSendData)); | ||
| 736 | + if (senddata == NULL) { | ||
| 737 | + // 处理内存分配失败的情况 | ||
| 738 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 739 | + } | ||
| 740 | + | ||
| 741 | + | ||
| 742 | + senddata->str = (unsigned char*)malloc(num + 1); // 分配足够的内存用于保存字符串 | ||
| 743 | + if (senddata->str == NULL) { | ||
| 744 | + // 处理内存分配失败的情况 | ||
| 745 | + free(senddata); // 释放之前分配的内存 | ||
| 746 | + senddata = NULL; | ||
| 747 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 748 | + } | ||
| 749 | + | ||
| 750 | + senddata->str_lenth = num; | ||
| 751 | + senddata->Uart_name = UartPort; | ||
| 752 | + memcpy(senddata->str, send, num); | ||
| 753 | + | ||
| 754 | + T_JZsdkReturnCode ret = TaskManagement_SubmitTask(JZsdk_Uart_UartSend_Task, (void *)senddata); | ||
| 755 | + if (ret == JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE) | ||
| 756 | + { | ||
| 757 | + free(senddata->str); | ||
| 758 | + senddata->str = NULL; | ||
| 759 | + free(senddata); | ||
| 760 | + senddata = NULL; | ||
| 761 | + return ret; | ||
| 762 | + } | ||
| 763 | + | ||
| 764 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 765 | +} | ||
| 766 | + | ||
| 767 | + | ||
| 768 | +/**************** | ||
| 769 | + * | ||
| 770 | + * 串口识别符关闭 | ||
| 771 | + * | ||
| 772 | + * ****************/ | ||
| 773 | +int JZsdk_Uart_CloseUartFd(int UartPort) | ||
| 774 | +{ | ||
| 775 | + if (UartPort == UART_4G) | ||
| 776 | + { | ||
| 777 | + JZSDK_LOG_INFO("关闭4g串口识别符\n"); | ||
| 778 | + close(Uart_4G_fd); | ||
| 779 | + return 0; | ||
| 780 | + } | ||
| 781 | + else if (UartPort == UART_DEV_1) | ||
| 782 | + { | ||
| 783 | + JZSDK_LOG_INFO("关闭串口1识别符\n"); | ||
| 784 | + close(Uart_DEV1_fd); | ||
| 785 | + return 0; | ||
| 786 | + } | ||
| 787 | + else if (UartPort == UART_DEV_2) | ||
| 788 | + { | ||
| 789 | + JZSDK_LOG_INFO("关闭串口2识别符\n"); | ||
| 790 | + close(Uart_DEV1_fd); | ||
| 791 | + return 0; | ||
| 792 | + } | ||
| 793 | +} | ||
| 794 | + | ||
| 795 | + | ||
| 796 | + | ||
| 797 | + | ||
| 798 | +static void *CloseUart(void *arg) | ||
| 799 | +{ | ||
| 800 | + s_SerialInitArg *args = (s_SerialInitArg *)arg; | ||
| 801 | + int UartPort = args->UartDevName; | ||
| 802 | + int BitRate = args->BitRate; | ||
| 803 | + | ||
| 804 | + Recv_Thread = JZ_FLAGCODE_ON; | ||
| 805 | + Deal_Thread = JZ_FLAGCODE_ON; | ||
| 806 | + | ||
| 807 | + if (UartPort == UART_4G) | ||
| 808 | + { | ||
| 809 | + JZSDK_LOG_INFO("关闭4g线程\n"); | ||
| 810 | + Uart_4G_Switch = JZ_FLAGCODE_OFF; | ||
| 811 | + } | ||
| 812 | + else if (UartPort == UART_DEV_1) | ||
| 813 | + { | ||
| 814 | + JZSDK_LOG_INFO("关闭串口1线程\n"); | ||
| 815 | + Uart_DEV1_Switch = JZ_FLAGCODE_OFF; | ||
| 816 | + } | ||
| 817 | + else if (UartPort == UART_DEV_2) | ||
| 818 | + { | ||
| 819 | + JZSDK_LOG_INFO("关闭串口2线程\n"); | ||
| 820 | + Uart_DEV2_Switch = JZ_FLAGCODE_OFF; | ||
| 821 | + } | ||
| 822 | + else | ||
| 823 | + { | ||
| 824 | + return 0; | ||
| 825 | + } | ||
| 826 | + | ||
| 827 | + while ( (Recv_Thread != JZ_FLAGCODE_OFF) && (Deal_Thread != JZ_FLAGCODE_OFF)) | ||
| 828 | + { | ||
| 829 | + delayMs(1); | ||
| 830 | + } | ||
| 831 | + | ||
| 832 | + delayMs(100); | ||
| 833 | + | ||
| 834 | + //保证全部注销后 | ||
| 835 | + JZSDK_LOG_INFO("串口注销完毕"); | ||
| 836 | + | ||
| 837 | + //创建新的 | ||
| 838 | + JZsdk_Uart_SecondInit(UartPort, BitRate); | ||
| 839 | + | ||
| 840 | + free(args); | ||
| 841 | +} | ||
| 842 | + | ||
| 843 | +/**************** | ||
| 844 | + * | ||
| 845 | + * 线程关闭, 并创建一个新的串口 | ||
| 846 | + * | ||
| 847 | + * ****************/ | ||
| 848 | +int JZsdk_Uart_CloseUartThead(int UartPort, int BitRate) | ||
| 849 | +{ | ||
| 850 | + | ||
| 851 | + //将串口描述符关闭 | ||
| 852 | + JZsdk_Uart_CloseUartFd(UartPort); | ||
| 853 | + | ||
| 854 | + s_SerialInitArg *parameter = (s_SerialInitArg *)malloc(sizeof(s_SerialInitArg)); | ||
| 855 | + parameter->UartDevName = UartPort; | ||
| 856 | + parameter->BitRate = BitRate; | ||
| 857 | + | ||
| 858 | + | ||
| 859 | + // 创建关闭串口的线程 | ||
| 860 | + pthread_t CloseThread; | ||
| 861 | + pthread_attr_t task_attribute; // 线程属性 | ||
| 862 | + pthread_attr_setdetachstate(&task_attribute, PTHREAD_CREATE_DETACHED); // 设置线程分离属性 | ||
| 863 | + | ||
| 864 | + pthread_attr_init(&task_attribute); | ||
| 865 | + | ||
| 866 | + | ||
| 867 | + // 创建串口数据处理线程 | ||
| 868 | + if (pthread_create(&CloseThread, &task_attribute, CloseUart, parameter) != 0) | ||
| 869 | + { | ||
| 870 | + JZSDK_LOG_ERROR("Failed to create receive thread"); | ||
| 871 | + return 1; | ||
| 872 | + } | ||
| 873 | +} |
JZsdk_hal/JZsdk_uart/JZsdk_Uart_UartDeal.h
0 → 100644
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file JZsdk_Uart_UartDeal.h | ||
| 4 | + * JZsdk_Uart_UartDeal的头文件 | ||
| 5 | + * | ||
| 6 | + ********************************************************************* | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/ | ||
| 10 | +#ifndef JZSDK_UART_UARTDEAL_H | ||
| 11 | +#define JZSDK_UART_UARTDEAL_H | ||
| 12 | + | ||
| 13 | +/* Includes ------------------------------------------------------------------*/ | ||
| 14 | + | ||
| 15 | +#ifdef __cplusplus | ||
| 16 | +extern "C" { | ||
| 17 | +#endif | ||
| 18 | + | ||
| 19 | +/* Exported constants --------------------------------------------------------*/ | ||
| 20 | +/* 常亮定义*/ | ||
| 21 | +#include "JZsdk_Base/JZsdk_Code/JZsdk_Code.h" | ||
| 22 | + | ||
| 23 | +/* Exported types ------------------------------------------------------------*/ | ||
| 24 | + | ||
| 25 | +/* Exported functions --------------------------------------------------------*/ | ||
| 26 | +T_JZsdkReturnCode JZsdk_Uart_UartSend(int UartPort ,unsigned char *send, int num); | ||
| 27 | +int JZsdk_Uart_UartDeal_Receive(int Uart_fd, int Uart_Dev_name); | ||
| 28 | +int JZsdk_Uart_CloseUartFd(int UartPort); | ||
| 29 | +int JZsdk_Uart_CloseUartThead(int UartPort, int BitRate); | ||
| 30 | +T_JZsdkReturnCode JZsdk_Uart_UartSend_NotTask(int Uart_Name, unsigned char *str, int str_lenth); | ||
| 31 | +int UartDeal_Recv_interface(int type, int Uart_fd , unsigned char *getbuf, int getbufLen); | ||
| 32 | + | ||
| 33 | + | ||
| 34 | + | ||
| 35 | +#ifdef __cplusplus | ||
| 36 | +} | ||
| 37 | +#endif | ||
| 38 | + | ||
| 39 | +#endif |
| 1 | +#include <stdio.h> | ||
| 2 | +#include <string.h> | ||
| 3 | +#include <stdlib.h> | ||
| 4 | + | ||
| 5 | +#include <fcntl.h> | ||
| 6 | +#include <unistd.h> | ||
| 7 | +#include <termios.h> | ||
| 8 | +#include <sys/time.h> | ||
| 9 | + | ||
| 10 | +#include "JZsdkLib.h" | ||
| 11 | + | ||
| 12 | +/******************************************* | ||
| 13 | +* | ||
| 14 | +* 使能一个串口 返回设备号 | ||
| 15 | +* 变量1 串口设备名 | ||
| 16 | + 变量2 比特率 | ||
| 17 | + 返回 int 设备号 | ||
| 18 | + 例子: UartDeal_Base_CreateReceive("/dev/ttyS2", 115200) | ||
| 19 | + | ||
| 20 | +*******************************************/ | ||
| 21 | +int UartConnection_UartEnabled(char *UartDev, int BitRate) | ||
| 22 | +{ | ||
| 23 | + int ret = 0; | ||
| 24 | + int UartReceive_fd = 0; | ||
| 25 | + pthread_t UartReceive_task; | ||
| 26 | + char PrintStr[256]; | ||
| 27 | + | ||
| 28 | + //1、读取串口 | ||
| 29 | + UartReceive_fd = open(UartDev,O_RDWR); | ||
| 30 | + if(UartReceive_fd < 0) | ||
| 31 | + { | ||
| 32 | + snprintf(PrintStr, 256, "打开%s失败", UartDev); | ||
| 33 | + printf("%s\n", PrintStr); | ||
| 34 | + return -1; | ||
| 35 | + } | ||
| 36 | + else | ||
| 37 | + { | ||
| 38 | + snprintf(PrintStr, 256, "打开%s成功", UartDev); | ||
| 39 | + printf("%s\n", PrintStr); | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + //2、获取终端信息 | ||
| 43 | + struct termios options; | ||
| 44 | + if(tcgetattr(UartReceive_fd,&options)!= 0) //获取终端信息 | ||
| 45 | + { | ||
| 46 | + printf("获取终端信息失败!\n"); | ||
| 47 | + return -1; | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + //3、设置比特率 | ||
| 51 | + switch (BitRate) | ||
| 52 | + { | ||
| 53 | + case 115200: | ||
| 54 | + cfsetispeed(&options, B115200); | ||
| 55 | + cfsetospeed(&options, B115200); | ||
| 56 | + break; | ||
| 57 | + case 230400: | ||
| 58 | + cfsetispeed(&options, B230400); | ||
| 59 | + cfsetospeed(&options, B230400); | ||
| 60 | + break; | ||
| 61 | + case 460800: | ||
| 62 | + cfsetispeed(&options, B460800); | ||
| 63 | + cfsetospeed(&options, B460800); | ||
| 64 | + break; | ||
| 65 | + case 921600: | ||
| 66 | + cfsetispeed(&options, B921600); | ||
| 67 | + cfsetospeed(&options, B921600); | ||
| 68 | + break; | ||
| 69 | + case 1000000: | ||
| 70 | + cfsetispeed(&options, B1000000); | ||
| 71 | + cfsetospeed(&options, B1000000); | ||
| 72 | + break; | ||
| 73 | + default: | ||
| 74 | + return -1; | ||
| 75 | + break; | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + options.c_cflag |= (unsigned) CLOCAL; | ||
| 79 | + options.c_cflag |= (unsigned) CREAD; | ||
| 80 | + options.c_cflag &= ~(unsigned) CRTSCTS; | ||
| 81 | + options.c_cflag &= ~(unsigned) CSIZE; | ||
| 82 | + options.c_cflag |= (unsigned) CS8; | ||
| 83 | + options.c_cflag &= ~(unsigned) PARENB; | ||
| 84 | + options.c_iflag &= ~(unsigned) INPCK; | ||
| 85 | + options.c_cflag &= ~(unsigned) CSTOPB; | ||
| 86 | + options.c_oflag &= ~(unsigned) OPOST; | ||
| 87 | + options.c_lflag &= ~((unsigned) ICANON | (unsigned) ECHO | (unsigned) ECHOE | (unsigned) ISIG); | ||
| 88 | + options.c_iflag &= ~((unsigned) BRKINT | (unsigned) ICRNL | (unsigned) INPCK | (unsigned) ISTRIP | (unsigned) IXON); | ||
| 89 | + options.c_cc[VTIME] = 0; | ||
| 90 | + options.c_cc[VMIN] = 0; | ||
| 91 | + | ||
| 92 | + | ||
| 93 | + tcflush(UartReceive_fd,TCIOFLUSH); //刷清输入、输出队列 | ||
| 94 | + tcsetattr(UartReceive_fd,TCSAFLUSH,&options); //串口设置使能 | ||
| 95 | + | ||
| 96 | + JZSDK_LOG_INFO("使能串口 波特率%d成功",BitRate); | ||
| 97 | + | ||
| 98 | + return UartReceive_fd; | ||
| 99 | +} |
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file UartDeal_Base.h | ||
| 4 | + * UartDeal_Base的头文件 | ||
| 5 | + * | ||
| 6 | + ********************************************************************* | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/ | ||
| 10 | +#ifndef UARTDEAL_BASE_H | ||
| 11 | +#define UARTDEAL_BASE_H | ||
| 12 | + | ||
| 13 | +/* Includes ------------------------------------------------------------------*/ | ||
| 14 | + | ||
| 15 | +#ifdef __cplusplus | ||
| 16 | +extern "C" { | ||
| 17 | +#endif | ||
| 18 | + | ||
| 19 | +/* Exported constants --------------------------------------------------------*/ | ||
| 20 | +/* 常亮定义*/ | ||
| 21 | + | ||
| 22 | +/* Exported types ------------------------------------------------------------*/ | ||
| 23 | + | ||
| 24 | +/* Exported functions --------------------------------------------------------*/ | ||
| 25 | +int UartConnection_UartEnabled(char *UartDev, int BitRate); | ||
| 26 | + | ||
| 27 | + | ||
| 28 | +#ifdef __cplusplus | ||
| 29 | +} | ||
| 30 | +#endif | ||
| 31 | + | ||
| 32 | +#endif |
JZsdk_hal/JZsdk_uart/Uart_Config.h
0 → 100644
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file Uart_Config.h | ||
| 4 | + * Uart_Config的头文件 | ||
| 5 | + * 用于管理串口的基本信息 | ||
| 6 | + ********************************************************************* | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/ | ||
| 10 | +#ifndef UART_CONFIG_H | ||
| 11 | +#define UART_CONFIG_H | ||
| 12 | + | ||
| 13 | +/* Includes ------------------------------------------------------------------*/ | ||
| 14 | +#include "BaseConfig.h" | ||
| 15 | + | ||
| 16 | +#ifdef __cplusplus | ||
| 17 | +extern "C" { | ||
| 18 | +#endif | ||
| 19 | + | ||
| 20 | +/* Exported constants --------------------------------------------------------*/ | ||
| 21 | +/* 常亮定义*/ | ||
| 22 | + | ||
| 23 | +/* Exported types ------------------------------------------------------------*/ | ||
| 24 | + | ||
| 25 | +/* Exported functions --------------------------------------------------------*/ | ||
| 26 | + | ||
| 27 | +#ifdef __cplusplus | ||
| 28 | +} | ||
| 29 | +#endif | ||
| 30 | + | ||
| 31 | +#endif |
JZsdk_hal/JZsdk_usb_bulk/JZsdk_usb_bulk.c
0 → 100644
| 1 | +#include <stdio.h> | ||
| 2 | +#include <stdlib.h> | ||
| 3 | + | ||
| 4 | + | ||
| 5 | +#include "version_choose.h" | ||
| 6 | +#include "JZsdkLib.h" | ||
| 7 | +#include "./JZsdk_usb_bulk.h" | ||
| 8 | + | ||
| 9 | + | ||
| 10 | +#if USB_CONFIG_STATUS == VERSION_SWITCH_ON | ||
| 11 | + #include <libusb-1.0/libusb.h> | ||
| 12 | +#endif | ||
| 13 | + | ||
| 14 | +#define LINUX_USB_BULK_TRANSFER_TIMEOUT_MS (50) | ||
| 15 | +#define LINUX_USB_BULK_TRANSFER_WAIT_FOREVER (-1) | ||
| 16 | + | ||
| 17 | +typedef struct JZsdk_T_HalUsbBulkObj{ | ||
| 18 | + | ||
| 19 | + | ||
| 20 | +#if USB_CONFIG_STATUS == VERSION_SWITCH_ON | ||
| 21 | + libusb_device_handle *handle; //usb的权柄 | ||
| 22 | +#endif | ||
| 23 | + | ||
| 24 | + unsigned int interfaceNum; //接口编号 | ||
| 25 | + int isUsbHost; | ||
| 26 | + | ||
| 27 | + unsigned int pid; //pid号码 用于标识产商 | ||
| 28 | + unsigned int vid; //vid号码 用于标识设备名 | ||
| 29 | + | ||
| 30 | + unsigned int PointIn; //读取输入引脚 | ||
| 31 | + unsigned int PointOut; //写入输出引脚 | ||
| 32 | + | ||
| 33 | +}JZsdk_T_HalUsbBulkObj; | ||
| 34 | + | ||
| 35 | +T_JZsdkReturnCode JZsdk_HalUsbBulk_Init(void **index, int interfaceNum, int isUsbHost, | ||
| 36 | + unsigned int pid, unsigned int vid, unsigned int PointIn, unsigned int PointOut) | ||
| 37 | +{ | ||
| 38 | +#if USB_CONFIG_STATUS == VERSION_SWITCH_ON | ||
| 39 | + //创建一个usb信息结构体 | ||
| 40 | + struct JZsdk_T_HalUsbBulkObj *UsbBulkObj = NULL; | ||
| 41 | + | ||
| 42 | + //为usb信息结构体注册内存 | ||
| 43 | + UsbBulkObj = (struct JZsdk_T_HalUsbBulkObj *)malloc(sizeof(struct JZsdk_T_HalUsbBulkObj)); | ||
| 44 | + if (UsbBulkObj == NULL) { | ||
| 45 | + JZSDK_LOG_ERROR("HalUsbBulk注册失败"); | ||
| 46 | + return JZ_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + UsbBulkObj->handle = NULL; | ||
| 50 | + UsbBulkObj->interfaceNum = interfaceNum; | ||
| 51 | + UsbBulkObj->isUsbHost = isUsbHost; | ||
| 52 | + UsbBulkObj->pid = pid; | ||
| 53 | + UsbBulkObj->vid = vid; | ||
| 54 | + UsbBulkObj->PointIn = PointIn; | ||
| 55 | + UsbBulkObj->PointOut = PointOut; | ||
| 56 | + | ||
| 57 | + int ret; | ||
| 58 | + | ||
| 59 | + ret = libusb_init(NULL); | ||
| 60 | + if (ret < 0) { | ||
| 61 | + JZSDK_LOG_ERROR("init usb bulk failed, errno = %d", ret); | ||
| 62 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + UsbBulkObj->handle = libusb_open_device_with_vid_pid(NULL, UsbBulkObj->vid, UsbBulkObj->pid); | ||
| 66 | + if(UsbBulkObj->handle == NULL) { | ||
| 67 | + JZSDK_LOG_ERROR("Open Device Error\n"); | ||
| 68 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + // ret = libusb_detach_kernel_driver(UsbBulkObj->handle, UsbBulkObj->interfaceNum); | ||
| 72 | + // if (ret < 0) | ||
| 73 | + // { | ||
| 74 | + // printf("销毁usb任务失败\n"); | ||
| 75 | + // } | ||
| 76 | + | ||
| 77 | + ret = libusb_claim_interface(UsbBulkObj->handle, UsbBulkObj->interfaceNum); | ||
| 78 | + if(ret < 0) { | ||
| 79 | + JZSDK_LOG_ERROR("Cannot Claim Interface\n"); | ||
| 80 | + libusb_close(UsbBulkObj->handle); | ||
| 81 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + JZSDK_LOG_INFO("USB 初始化完成\n"); | ||
| 85 | + | ||
| 86 | + *index = (void *)UsbBulkObj; | ||
| 87 | +#endif | ||
| 88 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 89 | +} | ||
| 90 | + | ||
| 91 | +T_JZsdkReturnCode JZsdk_HalUsbBulk_DeInit(void **index) | ||
| 92 | +{ | ||
| 93 | + // struct libusb_device_handle *handle = NULL; | ||
| 94 | + // int32_t ret; | ||
| 95 | + // T_DjiOsalHandler *osalHandler = DjiPlatform_GetOsalHandler(); | ||
| 96 | + | ||
| 97 | + // if (usbBulkHandle == NULL) { | ||
| 98 | + // return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 99 | + // } | ||
| 100 | + | ||
| 101 | + // handle = ((T_HalUsbBulkObj *) usbBulkHandle)->handle; | ||
| 102 | + | ||
| 103 | + | ||
| 104 | + // ret = libusb_release_interface(handle, ((T_HalUsbBulkObj *) usbBulkHandle)->usbBulkInfo.channelInfo.interfaceNum); | ||
| 105 | + // if(ret != 0) { | ||
| 106 | + // USER_LOG_ERROR("release usb bulk interface failed, errno = %d", ret); | ||
| 107 | + // return DJI_ERROR_SYSTEM_MODULE_CODE_SYSTEM_ERROR; | ||
| 108 | + // } | ||
| 109 | + // osalHandler->TaskSleepMs(100); | ||
| 110 | + // libusb_exit(NULL); | ||
| 111 | + | ||
| 112 | + | ||
| 113 | + // free(usbBulkHandle); | ||
| 114 | + | ||
| 115 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 116 | +} | ||
| 117 | + | ||
| 118 | +T_JZsdkReturnCode JZsdk_HalUsbBulk_WriteData(void **index ,const unsigned char *buf, unsigned int len, unsigned int *realLen) | ||
| 119 | +{ | ||
| 120 | + struct JZsdk_T_HalUsbBulkObj *UsbBulkObj = (struct JZsdk_T_HalUsbBulkObj *) *index; | ||
| 121 | + | ||
| 122 | + int ret; | ||
| 123 | + int actualLen = 0; | ||
| 124 | +#if USB_CONFIG_STATUS == VERSION_SWITCH_ON | ||
| 125 | + ret = libusb_bulk_transfer(UsbBulkObj->handle, UsbBulkObj->PointOut, | ||
| 126 | + (unsigned char *) buf, len, &actualLen, LINUX_USB_BULK_TRANSFER_TIMEOUT_MS); | ||
| 127 | + if (ret < 0) { | ||
| 128 | + JZSDK_LOG_ERROR("Write usb bulk data failed, errno = %d", ret); | ||
| 129 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 130 | + } | ||
| 131 | +#endif | ||
| 132 | + | ||
| 133 | + *realLen = actualLen; | ||
| 134 | + | ||
| 135 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 136 | +} | ||
| 137 | + | ||
| 138 | +T_JZsdkReturnCode JZsdk_HalUsbBulk_ReadData(void **index ,unsigned char *buf, unsigned int len,unsigned int *realLen) | ||
| 139 | +{ | ||
| 140 | + struct JZsdk_T_HalUsbBulkObj *UsbBulkObj = (struct JZsdk_T_HalUsbBulkObj *) *index; | ||
| 141 | + | ||
| 142 | + int ret; | ||
| 143 | + int actualLen = 0; | ||
| 144 | + | ||
| 145 | +#if USB_CONFIG_STATUS == VERSION_SWITCH_ON | ||
| 146 | + ret = libusb_bulk_transfer(UsbBulkObj->handle, UsbBulkObj->PointIn, | ||
| 147 | + buf, len, &actualLen, LINUX_USB_BULK_TRANSFER_WAIT_FOREVER); | ||
| 148 | + if (ret < 0) { | ||
| 149 | + JZSDK_LOG_ERROR("Read usb bulk data failed, errno = %d", ret); | ||
| 150 | + return JZ_ERROR_SYSTEM_MODULE_CODE_FAILURE; | ||
| 151 | + } | ||
| 152 | +#endif | ||
| 153 | + *realLen = actualLen; | ||
| 154 | + | ||
| 155 | + return JZ_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 156 | +} | ||
| 157 | + | ||
| 158 | +// T_DjiReturnCode HalUsbBulk_GetDeviceInfo(T_DjiHalUsbBulkDeviceInfo *deviceInfo) | ||
| 159 | +// { | ||
| 160 | +// //attention: this interface only be called in usb device mode. | ||
| 161 | +// deviceInfo->vid = LINUX_USB_VID; | ||
| 162 | +// deviceInfo->pid = LINUX_USB_PID; | ||
| 163 | + | ||
| 164 | +// // This bulk channel is used to obtain DJI camera video stream and push 3rd-party camera video stream. | ||
| 165 | +// deviceInfo->channelInfo[DJI_HAL_USB_BULK_NUM_0].interfaceNum = LINUX_USB_BULK1_INTERFACE_NUM; | ||
| 166 | +// deviceInfo->channelInfo[DJI_HAL_USB_BULK_NUM_0].endPointIn = LINUX_USB_BULK1_END_POINT_IN; | ||
| 167 | +// deviceInfo->channelInfo[DJI_HAL_USB_BULK_NUM_0].endPointOut = LINUX_USB_BULK1_END_POINT_OUT; | ||
| 168 | + | ||
| 169 | +// // This bulk channel is used to obtain DJI perception image and download camera media file. | ||
| 170 | +// deviceInfo->channelInfo[DJI_HAL_USB_BULK_NUM_1].interfaceNum = LINUX_USB_BULK2_INTERFACE_NUM; | ||
| 171 | +// deviceInfo->channelInfo[DJI_HAL_USB_BULK_NUM_1].endPointIn = LINUX_USB_BULK2_END_POINT_IN; | ||
| 172 | +// deviceInfo->channelInfo[DJI_HAL_USB_BULK_NUM_1].endPointOut = LINUX_USB_BULK2_END_POINT_OUT; | ||
| 173 | + | ||
| 174 | +// return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS; | ||
| 175 | +// } | ||
| 176 | + | ||
| 177 | +// int JZ_HalUsbBulk_GetDeviceInfo() { | ||
| 178 | +// libusb_device **devs; // 指针的指针,用于存储设备列表 | ||
| 179 | +// libusb_context *ctx = NULL; // libusb上下文 | ||
| 180 | +// libusb_device_handle *dev_handle; // 设备句柄 | ||
| 181 | +// int r; // 用于存储返回值 | ||
| 182 | +// ssize_t cnt; // 设备数量 | ||
| 183 | +// libusb_device_descriptor desc; // 设备描述符 | ||
| 184 | +// libusb_config_descriptor *config_desc; // 配置描述符 | ||
| 185 | +// const libusb_interface *intf; // 接口 | ||
| 186 | +// const libusb_interface_descriptor *intf_desc; // 接口描述符 | ||
| 187 | +// int i, j; | ||
| 188 | + | ||
| 189 | +// // 初始化libusb库 | ||
| 190 | +// r = libusb_init(&ctx); | ||
| 191 | +// if(r < 0) { | ||
| 192 | +// printf("初始化libusb失败\n"); | ||
| 193 | +// return 1; | ||
| 194 | +// } | ||
| 195 | + | ||
| 196 | +// libusb_set_debug(ctx, 3); // 设置调试级别 | ||
| 197 | + | ||
| 198 | +// // 获取USB设备列表 | ||
| 199 | +// cnt = libusb_get_device_list(ctx, &devs); | ||
| 200 | +// if(cnt < 0) { | ||
| 201 | +// printf("获取设备列表失败\n"); | ||
| 202 | +// libusb_exit(ctx); | ||
| 203 | +// return 1; | ||
| 204 | +// } | ||
| 205 | + | ||
| 206 | +// // 遍历设备列表 | ||
| 207 | +// printf("找到了 %zd 个设备\n", cnt); | ||
| 208 | +// for (i = 0; i < cnt; i++) { | ||
| 209 | +// dev_handle = libusb_open_device_with_vid_pid(ctx, VENDOR_ID, PRODUCT_ID); // 使用厂商ID和产品ID打开设备 | ||
| 210 | +// if (dev_handle == NULL) { | ||
| 211 | +// printf("无法打开设备\n"); | ||
| 212 | +// continue; | ||
| 213 | +// } | ||
| 214 | + | ||
| 215 | +// // 获取设备描述符 | ||
| 216 | +// r = libusb_get_device_descriptor(devs[i], &desc); | ||
| 217 | +// if (r < 0) { | ||
| 218 | +// printf("获取设备描述符失败\n"); | ||
| 219 | +// libusb_close(dev_handle); | ||
| 220 | +// continue; | ||
| 221 | +// } | ||
| 222 | + | ||
| 223 | +// printf("设备描述符:\n"); | ||
| 224 | +// printf(" 厂商ID: 0x%04x\n", desc.idVendor); | ||
| 225 | +// printf(" 产品ID: 0x%04x\n", desc.idProduct); | ||
| 226 | + | ||
| 227 | +// // 获取活动配置的描述符 | ||
| 228 | +// r = libusb_get_active_config_descriptor(devs[i], &config_desc); | ||
| 229 | +// if (r < 0) { | ||
| 230 | +// printf("获取配置描述符失败\n"); | ||
| 231 | +// libusb_close(dev_handle); | ||
| 232 | +// continue; | ||
| 233 | +// } | ||
| 234 | + | ||
| 235 | +// // 遍历配置中的接口 | ||
| 236 | +// for (j = 0; j < config_desc->bNumInterfaces; j++) { | ||
| 237 | +// intf = &config_desc->interface[j]; | ||
| 238 | +// printf("接口编号: %d\n", intf->bInterfaceNumber); | ||
| 239 | + | ||
| 240 | +// // 遍历接口中的设置 | ||
| 241 | +// for (int k = 0; k < intf->num_altsetting; k++) { | ||
| 242 | +// intf_desc = &intf->altsetting[k]; | ||
| 243 | +// // 这里可以进一步处理接口描述符的信息,比如端点等 | ||
| 244 | +// printf(" 设置编号: %d\n", intf_desc->bAlternateSetting); | ||
| 245 | +// // ... | ||
| 246 | +// } | ||
| 247 | +// } | ||
| 248 | + | ||
| 249 | +// libusb_free_config_descriptor(config_desc); // 释放配置描述符 | ||
| 250 | +// libusb_close(dev_handle); // 关闭设备句柄 | ||
| 251 | +// } | ||
| 252 | + | ||
| 253 | +// libusb_free_device_list(devs, 1); // 释放设备列表 | ||
| 254 | +// libusb_exit(ctx); // 退出libusb库 | ||
| 255 | + | ||
| 256 | +// return 0; | ||
| 257 | +// } |
JZsdk_hal/JZsdk_usb_bulk/JZsdk_usb_bulk.h
0 → 100644
| 1 | +/** | ||
| 2 | + ******************************************************************** | ||
| 3 | + * @file JZsdk_usb_bulk.h | ||
| 4 | + * JZsdk_usb_bulk的头文件 | ||
| 5 | + * | ||
| 6 | + ********************************************************************* | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/ | ||
| 10 | +#ifndef JZSDK_USB_BULK_H | ||
| 11 | +#define JZSDK_USB_BULK_H | ||
| 12 | + | ||
| 13 | +/* Includes ------------------------------------------------------------------*/ | ||
| 14 | +#include "JZsdk_Base/JZsdk_Code/JZsdk_Code.h" | ||
| 15 | + | ||
| 16 | +#ifdef __cplusplus | ||
| 17 | +extern "C" { | ||
| 18 | +#endif | ||
| 19 | + | ||
| 20 | +#define LINUX_USB_VID (0x04b4) | ||
| 21 | +#define LINUX_USB_PID (0x00f1) | ||
| 22 | +#define USB_OUT_POINT (0x02) | ||
| 23 | +#define USB_IN_POINT (0x86) | ||
| 24 | + | ||
| 25 | +T_JZsdkReturnCode JZsdk_HalUsbBulk_WriteData(void **index ,const unsigned char *buf, unsigned int len, unsigned int *realLen); | ||
| 26 | +T_JZsdkReturnCode JZsdk_HalUsbBulk_ReadData(void **index ,unsigned char *buf, unsigned int len,unsigned int *realLen); | ||
| 27 | +T_JZsdkReturnCode JZsdk_HalUsbBulk_Init(void **index, int interfaceNum, int isUsbHost, | ||
| 28 | + unsigned int pid, unsigned int vid, unsigned int PointIn, unsigned int PointOut); | ||
| 29 | + | ||
| 30 | +#ifdef __cplusplus | ||
| 31 | +} | ||
| 32 | +#endif | ||
| 33 | + | ||
| 34 | +#endif |
git_updata.sh
0 → 100644
| 1 | +#!/bin/bash | ||
| 2 | +#1、输入分支名,账号,密码,描述信息 | ||
| 3 | +branch_name="dev_00.00.02.00" | ||
| 4 | +Account="PanHaoBin" | ||
| 5 | +PassWord="ookk3866" | ||
| 6 | +Message="更新" | ||
| 7 | +ProjectName="114.132.166.25:8099/PanHaoBin/JZSDK_Linux.git" | ||
| 8 | + | ||
| 9 | + | ||
| 10 | +# 检查分支是否存在 | ||
| 11 | +if git rev-parse --verify "$branch_name" >/dev/null 2>&1; then | ||
| 12 | + echo "分支 $branch_name 存在" | ||
| 13 | +else | ||
| 14 | + echo "分支 $branch_name 不存在" | ||
| 15 | + # 创建新分支 | ||
| 16 | + git branch "$branch_name" | ||
| 17 | +fi | ||
| 18 | + | ||
| 19 | +# 切换到新创建的分支 | ||
| 20 | +git checkout "$branch_name" | ||
| 21 | + | ||
| 22 | +#选择上传内容 | ||
| 23 | +#git add -n . | grep -v "project_build" | xargs git add | ||
| 24 | +git add . | ||
| 25 | + | ||
| 26 | +# 写入描述/注释 | ||
| 27 | +git commit -m "$Message" | ||
| 28 | + | ||
| 29 | +# 设置远程仓库的URL | ||
| 30 | +remote_url="http://$Account:$PassWord@$ProjectName" | ||
| 31 | + | ||
| 32 | +# 上传到远程仓库 | ||
| 33 | +git push "$remote_url" "$branch_name" | ||
| 34 | + | ||
| 35 | +echo "推送完成" |
-
请 注册 或 登录 后发表评论