From 9e63686a521181041e6b0cc4adb4eb84992b9fbc Mon Sep 17 00:00:00 2001 From: tangchao0503 <735056338@qq.com> Date: Wed, 24 Jan 2024 10:27:51 +0800 Subject: [PATCH] =?UTF-8?q?rlx=EF=BC=9A=E7=82=B9=E5=87=BB=E9=81=A5?= =?UTF-8?q?=E6=8E=A7=E5=99=A8=E6=97=B6=E9=80=9A=E8=BF=87udp=E5=8F=91?= =?UTF-8?q?=E9=80=81=E7=82=B9=E5=87=BB=E5=9D=90=E6=A0=87=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../camera_emu/test_payload_cam_emu_base.c | 19 +++++++++++++++++++ .../camera_emu/test_payload_cam_emu_base.h | 7 +++++++ 2 files changed, 26 insertions(+) diff --git a/samples/sample_c/module_sample/camera_emu/test_payload_cam_emu_base.c b/samples/sample_c/module_sample/camera_emu/test_payload_cam_emu_base.c index 2c9eb2b..39e395b 100644 --- a/samples/sample_c/module_sample/camera_emu/test_payload_cam_emu_base.c +++ b/samples/sample_c/module_sample/camera_emu/test_payload_cam_emu_base.c @@ -119,6 +119,13 @@ static uint32_t s_tapZoomNewestTargetHybridFocalLength = 0; // unit: 0.1mm static T_DjiMutexHandle s_tapZoomMutex = NULL; static E_DjiCameraVideoStreamType s_cameraVideoStreamType; +static int sockfd; +static struct sockaddr_in server; +static struct sockaddr_in client; +static socklen_t addrlen; + +char s_positionMessage[100]=" "; + /* Private functions declaration ---------------------------------------------*/ //用于s_commonHandler中的回调函数:相机类基础功能 static T_DjiReturnCode GetSystemState(T_DjiCameraSystemState *systemState); @@ -587,6 +594,9 @@ static T_DjiReturnCode SetFocusTarget(T_DjiCameraPointInScreen target) USER_LOG_INFO("set focus target x:%.2f y:%.2f", target.focusX, target.focusY); memcpy(&s_cameraFocusTarget, &target, sizeof(T_DjiCameraPointInScreen)); + sprintf(s_positionMessage, "%.2f,%.2f", target.focusX, target.focusY); + sendto(sockfd, s_positionMessage, strlen(s_positionMessage), 0, (struct sockaddr *)&server, sizeof(server)); + return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS; } @@ -1399,6 +1409,15 @@ T_DjiReturnCode DjiTest_CameraEmuBaseStartService(void) s_isCamInited = true; + // 创建UDP套接字 + if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { + perror("Creatingsocket failed."); + } + bzero(&server, sizeof(server)); + server.sin_family = AF_INET; + server.sin_port = htons(POSITION_PORT_RLX); + server.sin_addr.s_addr = htonl(INADDR_ANY); + return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS; } diff --git a/samples/sample_c/module_sample/camera_emu/test_payload_cam_emu_base.h b/samples/sample_c/module_sample/camera_emu/test_payload_cam_emu_base.h index 5601b8d..578b554 100644 --- a/samples/sample_c/module_sample/camera_emu/test_payload_cam_emu_base.h +++ b/samples/sample_c/module_sample/camera_emu/test_payload_cam_emu_base.h @@ -31,6 +31,13 @@ #include "dji_typedef.h" #include "dji_payload_camera.h" +#include +#include +#include +#include + +#define POSITION_PORT_RLX 20005 + #ifdef __cplusplus extern "C" { #endif