diff options
author | 2025-01-04 14:52:55 +0800 | |
---|---|---|
committer | 2025-01-04 14:52:55 +0800 | |
commit | ab091cb4661aed9b9da997e58a8b5ec1f5853951 (patch) | |
tree | 0abdf7f99b5fc069536d975b39e1bcb8cf8e77b9 /udp2lcm/udp.c | |
parent | 6c06f515f18f5913a027ba2c84092c4861e8cf45 (diff) | |
download | WheelCtrl-master.tar.gz WheelCtrl-master.zip |
In the old commit, CMakeLists is set to find liblcm in
${CMAKE_SOURCE_ROOT}/libs, and there are two dirs: aarch64 and x86.
When I compile it for x86-64 computer using the cmake on host machine,
it will automatically find lib under ${CMAKE_SOURCE_ROOT}/lib/x86, and
when compiling for arm using cmake/compiler provided by ohos, it will
also find under ${CMAKE_SOURCE_ROOT}/lib/aarch64. Sounds good.
But, this is just a feature of special version for cmake/make/binutils,
causing error on other linux distributions. The path should be given,
but tools wouldn't find libs there recursively, which means path should
be spercific.
So in this commit, I use runme.sh to compile. It will work depending on
the argument(named arch) given by user, and pass it as a macro named
OHOS_ARCH to cmake, which is used in linking path of CMakeLists.
Besides, libpthread.so is not always default linked. So let's write it
in CMakeLists.
Last but not least, keeping source code clean is our duty. There's a
.clang-format under ${CMAKE_SOURCE_ROOT} to help. Use it.
Moving for the better!
Diffstat (limited to 'udp2lcm/udp.c')
-rw-r--r-- | udp2lcm/udp.c | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/udp2lcm/udp.c b/udp2lcm/udp.c index 6c4bd4a..97fb53e 100644 --- a/udp2lcm/udp.c +++ b/udp2lcm/udp.c | |||
@@ -1,6 +1,6 @@ | |||
1 | #include "udp2lcm.h" | 1 | #include "udp2lcm.h" |
2 | 2 | ||
3 | void udpRecvHandler() { | 3 | void *udpRecvHandler(void *args) { |
4 | int socketfd = -1; | 4 | int socketfd = -1; |
5 | char buffer[MAX_BUFFER_SIZE]; | 5 | char buffer[MAX_BUFFER_SIZE]; |
6 | struct sockaddr_in serverAddr; | 6 | struct sockaddr_in serverAddr; |
@@ -13,7 +13,7 @@ void udpRecvHandler() { | |||
13 | printf("udpRecvHandler\n"); | 13 | printf("udpRecvHandler\n"); |
14 | if ((socketfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { | 14 | if ((socketfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { |
15 | fprintf(stderr, "Error: Failed to create socket\n"); | 15 | fprintf(stderr, "Error: Failed to create socket\n"); |
16 | return; | 16 | return NULL; |
17 | } | 17 | } |
18 | memset((char *)&serverAddr, 0, sizeof(serverAddr)); | 18 | memset((char *)&serverAddr, 0, sizeof(serverAddr)); |
19 | memset(buffer, 0, sizeof(buffer)); | 19 | memset(buffer, 0, sizeof(buffer)); |
@@ -25,7 +25,7 @@ void udpRecvHandler() { | |||
25 | -1) { | 25 | -1) { |
26 | fprintf(stderr, "Error: Bind failed\n"); | 26 | fprintf(stderr, "Error: Bind failed\n"); |
27 | close(socketfd); | 27 | close(socketfd); |
28 | return; | 28 | return NULL; |
29 | } | 29 | } |
30 | 30 | ||
31 | bytesReceived = recvfrom(socketfd, buffer, MAX_BUFFER_SIZE, 0, | 31 | bytesReceived = recvfrom(socketfd, buffer, MAX_BUFFER_SIZE, 0, |
@@ -33,7 +33,7 @@ void udpRecvHandler() { | |||
33 | if (bytesReceived == -1) { | 33 | if (bytesReceived == -1) { |
34 | fprintf(stderr, "Error: Failed to receive data\n"); | 34 | fprintf(stderr, "Error: Failed to receive data\n"); |
35 | close(socketfd); | 35 | close(socketfd); |
36 | return; | 36 | return NULL; |
37 | } | 37 | } |
38 | printf("Start message from %s: %s\n", inet_ntoa(clientAddr.sin_addr), | 38 | printf("Start message from %s: %s\n", inet_ntoa(clientAddr.sin_addr), |
39 | buffer); | 39 | buffer); |
@@ -57,13 +57,13 @@ void udpRecvHandler() { | |||
57 | robotCtrlData.iparams[0] = 1; | 57 | robotCtrlData.iparams[0] = 1; |
58 | robot_control_t_publish(lcm, "ROBOT_CONTROL", &robotCtrlData); | 58 | robot_control_t_publish(lcm, "ROBOT_CONTROL", &robotCtrlData); |
59 | freeRobotCtrl(&robotCtrlData); | 59 | freeRobotCtrl(&robotCtrlData); |
60 | // 随即下达30号命令,开始建图 | 60 | // // 随即下达30号命令,开始建图 |
61 | robotCtrlInit(&robotCtrlData, 0, 30, 0, 1, 1, 0, 0); | 61 | // robotCtrlInit(&robotCtrlData, 0, 30, 0, 1, 1, 0, 0); |
62 | robotCtrlData.dparams[0] = 0.05; | 62 | // robotCtrlData.dparams[0] = 0.05; |
63 | robotCtrlData.niparams = 1; | 63 | // robotCtrlData.niparams = 1; |
64 | robotCtrlData.iparams[0] = 1; | 64 | // robotCtrlData.iparams[0] = 1; |
65 | robot_control_t_publish(lcm, "ROBOT_CONTROL", &robotCtrlData); | 65 | // robot_control_t_publish(lcm, "ROBOT_CONTROL", &robotCtrlData); |
66 | freeRobotCtrl(&robotCtrlData); | 66 | // freeRobotCtrl(&robotCtrlData); |
67 | 67 | ||
68 | /* | 68 | /* |
69 | * 开始接收来自手机端的命令 | 69 | * 开始接收来自手机端的命令 |
@@ -99,13 +99,13 @@ void udpRecvHandler() { | |||
99 | } | 99 | } |
100 | } | 100 | } |
101 | 101 | ||
102 | void udpSendHandler() { | 102 | void *udpSendHandler(void *args) { |
103 | // 创建UDP套接字 | 103 | // 创建UDP套接字 |
104 | int sockfd = -1; | 104 | int sockfd = -1; |
105 | struct sockaddr_in serverAddr; | 105 | struct sockaddr_in serverAddr; |
106 | if ((sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { | 106 | if ((sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { |
107 | fprintf(stderr, "Error: Failed to create socket\n"); | 107 | fprintf(stderr, "Error: Failed to create socket\n"); |
108 | return; | 108 | return NULL; |
109 | } | 109 | } |
110 | 110 | ||
111 | memset((char *)&serverAddr, 0, sizeof(serverAddr)); | 111 | memset((char *)&serverAddr, 0, sizeof(serverAddr)); |
@@ -114,7 +114,7 @@ void udpSendHandler() { | |||
114 | if (inet_aton(clientIP, &serverAddr.sin_addr) == 0) { | 114 | if (inet_aton(clientIP, &serverAddr.sin_addr) == 0) { |
115 | fprintf(stderr, "Error: Failed to convert IP address\n"); | 115 | fprintf(stderr, "Error: Failed to convert IP address\n"); |
116 | close(sockfd); | 116 | close(sockfd); |
117 | return; | 117 | return NULL; |
118 | } | 118 | } |
119 | 119 | ||
120 | while (true) { | 120 | while (true) { |
@@ -124,4 +124,4 @@ void udpSendHandler() { | |||
124 | pthread_mutex_unlock(&heartBeatMutex); | 124 | pthread_mutex_unlock(&heartBeatMutex); |
125 | sleep(1); | 125 | sleep(1); |
126 | } | 126 | } |
127 | } \ No newline at end of file | 127 | } |