目录
GUI-toc" style="margin-left:40px;">1、修改GUI
C%E5%8F%91%E9%80%81%E7%BC%93%E5%86%B2%E5%8C%BA%E7%9A%84%E5%B8%A7-toc" style="margin-left:40px;">2、修改数据处理和发送缓冲区的帧
3、修改server中对SR04的处理
4、添加SR04的dirver_handle
C%E8%AF%81-toc" style="margin-left:40px;">5、验证
6、遇到问题及解决方法
C-toc" style="margin-left:40px;">7、 项目管理操作
GUI">1、修改GUI
C%E5%8F%91%E9%80%81%E7%BC%93%E5%86%B2%E5%8C%BA%E7%9A%84%E5%B8%A7">2、修改数据处理和发送缓冲区的帧
添加对SR04按键事件处理
添加对接收数据的处理
3、修改server中对SR04的处理
printf("SR04!!!\n");if ('g' == cmd[4]){opt = sr04_handle(&get_data);if (NOERROR == opt){sprintf(buf,"@002g%03d", get_data);tx_buffer = buf;}else{tx_buffer = "@002e";}}printf(">>>>>>%s\n",tx_buffer); if (send(acceptfd, tx_buffer, strlen(tx_buffer), 0) < 0){perror("send failed"); }
4、添加SR04的dirver_handle
/*
*author : xintianyu
*function : Handle sr501 Settings
*date : 2024-4-18
-----------------------
author date modify*/
int sr04_handle(int *data)
{char *device = "/dev/CEBSS_sr04";int ret = NOERROR;static int fd;struct pollfd fds[1];int val;/* 打开文件 */fd = open(device, O_RDWR);if (fd == -1){printf("can not open file %s\n", device);return ERROR;}ioctl(fd, CMD_TRIG);printf("I am goning to read distance: \n");fds[0].fd = fd;fds[0].events = POLLIN;if (1 == poll(fds, 1, 5000)){if (read(fd, &val, 4) == 4){printf("get distance: %d cm\n", val*17/1000000);*data = val*17/1000000;}elseprintf("get distance err\n");}else{printf("get distance poll timeout/err\n");ret = ERROR;}if (*data > 450){ret = ERROR;}close(fd);return ret;
}
C%E8%AF%81">5、验证
6、遇到问题及解决方法
/home/book/program/cebss/server/src/driver_handle.c:144:2: error: implicit declaration of function ‘ioctl’ [-Werror=implicit-function-declaration]
ioctl(fd, CMD_TRIG);
^~~~~
cc1: all warnings being treated as errors
添加ioctl的头文件
/home/book/program/cebss/server/src/tcp.c:239:25: error: ‘tx_buffer’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
sprintf(tx_buffer,"@001g%d", get_data);
sprintf函数的buf必须是初始化过的内存比如数组或者malloc的地址
遇到其它问题可直接写导评论区或者加群反馈