串口服务器— 设计方案

news2026/5/5 22:54:01
UART转以太网服务器解析完整代码解析与流程图一、项目概述本项目实现了一个嵌入式Linux下的串口转以太网服务器它可以通过JSON配置文件动态指定工作模式TCP Server 或 TCP Client实时监听配置文件变化inotify无需重启进程即可应用新配置作为 TCP Server 时支持多个客户端同时连接将串口数据广播给所有客户端并将任意客户端发来的数据转发到串口作为 TCP Client 时主动连接远程服务器实现串口与远程网络的双向透传提供串口参数配置波特率、数据位、校验位、停止位等程序完全使用 C 语言编写依赖 cJSON 库解析配置使用 epoll 处理高并发网络使用双向循环链表管理客户端连接支持守护进程模式。二、系统流程图三、代码模块详解事件标志速查表事件标志含义触发条件代码中的用途EPOLLIN文件描述符可读有数据到达socket 接收缓冲区非空监听客户端或串口是否有数据可读EPOLLRDHUP对方关闭连接或半关闭TCP 连接收到 FIN 包对端调用close或shutdown快速检测客户端正常关闭避免多一次recv调用EPOLLET边缘触发模式状态发生变化时只通知一次提高性能减少epoll_wait调用次数配合非阻塞 I/OEPOLLHUP挂起事件对端挂起如连接断开、设备被移除检测异常断开清理资源EPOLLERR错误事件文件描述符发生错误如连接被重置ECONNRESET检测连接错误关闭并清理EPOLLOUT文件描述符可写发送缓冲区有空闲空间对于非阻塞 socket代码中未使用但在需要异步发送大数据时很有用主循环新连接到来accept后设置非阻塞注册EPOLLIN | EPOLLRDHUP | EPOLLET边缘触发将客户端信息插入链表计数增加。串口可读调用read_serial读取数据然后遍历链表向所有客户端send。若发送失败对方已关闭则从链表中删除该客户端并关闭 socket。客户端可读recv数据然后写入串口。客户端断开/异常EPOLLRDHUP或EPOLLERR触发关闭 socket 并从链表中删除。#include sys/types.h #include sys/stat.h #include fcntl.h #include stdio.h #include stdlib.h #include unistd.h #include sys/inotify.h// inotify_init, inotify_add_watch, inotify_event #include sys/stat.h // stat, struct stat #include syslog.h #include cJSON.h #include pthread.h #include sys/socket.h #include netinet/in.h #include arpa/inet.h #include signal.h #include sys/wait.h #include errno.h #include pthread.h #include UART.h #include sys/epoll.h #include poll.h #include string.h #include double_link_list.h #include inotify_create_server_clinet.h #define MAX_EVENTS 64 int create_fork(int status); void kill_child_fork(int pid); int parse_config_file(const char *file_path); int reload_server_create(char *ip,int port); int reload_client_create(char *ip,int port); enum { SERVER 1, CLIENT, LINK_CLIENT, UNLINK_CLIENT }; struct server_or_client { pid_t pid; int status; char server_ip[64]; int server_port; char client_ip[64]; int client_port; }; struct uart_status { int fd_uart; char device[20]; int baudrate; int data_bits; char parity[10]; int stop_bits; }; struct info_client_status { int client_socket; int link_status; }; // 全局结构体实例 static struct server_or_client g_inet_status {0}; static struct uart_status g_uart_status {0}; //链表表头 LLIST *list_head; //fd设置为非阻塞 static int set_nonblocking(int fd) { int flags fcntl(fd, F_GETFL, 0); if(flags -1) return -1; return fcntl(fd, F_SETFL, flags | O_NONBLOCK); } //删除链表查找回调函数 static int client_id_cmp(const void *key,const void *record) { const int *socket key; const struct info_client_status *p record; return (*socket - p-client_socket); } /******* 串口重开 ******/ int reopen_serial(void) { // 从配置文件重读串口参数并重开 int new_fd open_port(g_uart_status.device); g_uart_status.fd_uart 0; if(new_fd 0) { set_opt(new_fd, g_uart_status.baudrate,\ g_uart_status.data_bits, g_uart_status.parity,\ g_uart_status.stop_bits); set_nonblocking(new_fd); } else return -1; return new_fd; } /******* 串口重开校验 ***********/ int handle_serial_check(int epfd, int *fd, struct epoll_event *ev_server) { static int reopen_serial_num 0; epoll_ctl(epfd, EPOLL_CTL_DEL, *fd, NULL); close(*fd); *fd -1; while(reopen_serial_num 3) { int new_fd reopen_serial(); if(new_fd 0) { reopen_serial_num 0; ev_server-events EPOLLIN; ev_server-data.fd new_fd; *fd new_fd; epoll_ctl(epfd, EPOLL_CTL_ADD, new_fd, ev_server); return 0; // 重开成功 } reopen_serial_num; sleep(1); } return -1; } static int daemonize() { int fd; pid_t pid; pid fork(); if(pid 0) return -1; if(pid 0) exit(0); fd open(/dev/null,O_RDWR); if(fd 0) return -1; dup2(fd,0); dup2(fd,1); dup2(fd,2); if(fd 2) close(fd); //创建守护进程 setsid(); chdir(/); umask(0); return 0; } /* 1.监视文件 是/否 修改 */ void watch_file_modify(const char *file_path) { struct stat statbuf; int fd,wd; int r_len; char buf[BUF_LEN]; //openlog(inotify_daemonize,LOG_PID,LOG_DAEMON); // if(daemonize()) // { // syslog(LOG_ERR,daemonize failed!); // exit(1); // } // else // syslog(LOG_INFO,daemonize() success!); while(1) { if(parse_config_file(file_path) 0) break; sleep(1); } // 1.等待文件创建 while(stat(file_path,statbuf) -1) { printf(文件未创建 等待文件创建, 行 %d\n,__LINE__); sleep(1); } printf(文件已完成创建开始监听(配置文件), 行 %d\n,__LINE__); // 2.初始化inotify 设置监听事件 fd inotify_init(); if(fd 0) { printf(inotify 初始化失败, 行 %d\n,__LINE__); exit(1); } wd inotify_add_watch(fd,file_path, IN_CLOSE_WRITE); if(wd 0) { printf(inotify 无法监听文件:%s, 行 %d\n,WATCH_PATH,__LINE__); closelog(); close(fd); exit(1); } printf(开始监听文件:%s, 行 %d\n,WATCH_PATH,__LINE__); // 3.循环读取事件 while(1) { r_len read(fd,buf,BUF_LEN); if(r_len 0) { printf(read 读取修改事件失败, 行 %d\n,__LINE__); break; } int i 0; while(i r_len) { struct inotify_event *event (struct inotify_event *)buf[i]; if(event-mask IN_CLOSE_WRITE) { printf(文件以被修改 %s, 行 %d\n,WATCH_PATH,__LINE__); int ret parse_config_file(WATCH_PATH); if(ret 0) { printf(配置文件空, 行 %d\n,__LINE__); continue; } } i EVENT_SIZE event-len; } } inotify_rm_watch(fd,wd); close(fd); //closelog(); exit(0); } /* 2.配置文件 被修改 解析配置文件 */ int parse_config_file(const char *file_path) { FILE *fp_cfg; int len; char *data; pthread_t tid; // 1.读配置文件 fp_cfg fopen(file_path,r); if(fp_cfg NULL) { printf(pares配置文件,打开失败%s\n,file_path); return -1; } fseek(fp_cfg,0,SEEK_END); len ftell(fp_cfg); fseek(fp_cfg,0,SEEK_SET); data (char *)malloc(len 1); if(data NULL) { fclose(fp_cfg); return -1; } fread(data,1,len,fp_cfg); data[len] \0; fclose(fp_cfg); // 2.解析 cJSON *root cJSON_Parse(data); free(data); if (!root) { fprintf(stderr, ERROR: 解析cJSON_Parse 失败\n); return -1; } cJSON *Item; /* 解析串口配置是否被更改 */ char uart_name[50]; int baudrate g_uart_status.baudrate; int data_bits g_uart_status.data_bits; char parity[10]; int stop_bits g_uart_status.stop_bits; strncpy(uart_name, g_uart_status.device, sizeof(uart_name)-1); uart_name[sizeof(uart_name)-1] \0; strncpy(parity, g_uart_status.parity, sizeof(parity)-1); parity[sizeof(parity)-1] \0; cJSON *uart cJSON_GetObjectItem(root,serial); if((Item cJSON_GetObjectItem(uart, device)) cJSON_IsString(Item)) strncpy(uart_name, Item-valuestring, sizeof(uart_name)-1); if((Item cJSON_GetObjectItem(uart, baudrate)) cJSON_IsNumber(Item)) baudrate Item-valueint; if((Item cJSON_GetObjectItem(uart, data_bits)) cJSON_IsNumber(Item)) data_bits Item-valueint; if((Item cJSON_GetObjectItem(uart, parity)) cJSON_IsString(Item)) strncpy(parity, Item-valuestring, sizeof(parity)-1); if((Item cJSON_GetObjectItem(uart, stop_bits)) cJSON_IsNumber(Item)) stop_bits Item-valueint; //判断串口设备配置是否被更改 if( !g_uart_status.fd_uart || (g_uart_status.fd_uart ||\ strcmp(uart_name,g_uart_status.device) ! 0 ||\ strcmp(parity,g_uart_status.parity) ! 0 || baudrate ! g_uart_status.baudrate || data_bits ! g_uart_status.data_bits || stop_bits ! g_uart_status.stop_bits)) { if (g_uart_status.fd_uart 0) { close(g_uart_status.fd_uart); } g_uart_status.fd_uart open_port(uart_name); if(g_uart_status.fd_uart 0) { printf(串口设备打开失败: [%s], 行 %d\n,uart_name,__LINE__); return -1; } else printf(串口设备打开成功: [%s], 行 %d\n,uart_name,__LINE__); int ret set_opt(g_uart_status.fd_uart,baudrate,data_bits,parity,stop_bits); if(ret ! 0) printf(串口配置失败%d\n,__LINE__); //更新全局结构体的串口配置 memcpy(g_uart_status.device,uart_name,sizeof(uart_name)); g_uart_status.baudrate baudrate; g_uart_status.data_bits data_bits; memcpy(g_uart_status.parity,parity,sizeof(parity)); g_uart_status.stop_bits stop_bits; printf(【%s】串口设备打开,波特率: %d、数据位: %d、校验位: %s、停止位: %d, 行 %d\n,uart_name,baudrate,data_bits,parity,stop_bits,__LINE__); } // 2.1解析网络参数是否更改并创建网络 char work_mode[10]; char ip[64]; char addrs[20]; char ports[20]; int port; cJSON *network cJSON_GetObjectItem(root,network); if((Item cJSON_GetObjectItem(network, work_mode)) cJSON_IsString(Item)) strncpy(work_mode, Item-valuestring, sizeof(work_mode)-1); // 2.2判断是否由服务器改为客户端,如更改杀死服务器进程 或 服务器、客户端口改变重新创建进程 if(g_inet_status.status strcmp(work_mode,server) 0 g_inet_status.status CLIENT) kill_child_fork(g_inet_status.pid); if(strcmp(work_mode,server) 0) { strncpy(addrs,local_ip,sizeof(local_ip)); strncpy(ports,local_port,sizeof(local_port)); g_inet_status.status SERVER; } else if(strcmp(work_mode,client) 0) { strncpy(addrs,remote_addr,sizeof(remote_addr)); strncpy(ports,remote_port,sizeof(remote_port)); g_inet_status.status CLIENT; } else { fprintf(stderr, 输入参数错误 %s 无对应网络模式, 行 %d\n, work_mode,__LINE__); return -1; } if((Item cJSON_GetObjectItem(network, addrs)) cJSON_IsString(Item)) strncpy(ip, Item-valuestring, sizeof(ip)-1); else { fprintf(stderr, 网络IP错误 %s ,行 %d\n, addrs,__LINE__); return -1; } if((Item cJSON_GetObjectItem(network, ports)) cJSON_IsNumber(Item)) port Item-valueint; else { fprintf(stderr, 网络端口输入错误 %s ,行 %d\n, ports,__LINE__); return -1; } if(g_inet_status.status SERVER) { strncpy(g_inet_status.server_ip,ip,sizeof(ip)); //判断SERVER端IP是否更改 if(g_inet_status.server_port port) return 0; else { int only_one_create 0; g_inet_status.server_port port; // 首次启动 if (g_inet_status.pid 0) { only_one_create 1; create_fork(g_inet_status.status); } if(g_inet_status.pid) kill_child_fork(g_inet_status.pid); if(!only_one_create) create_fork(g_inet_status.status); } } else if(g_inet_status.status CLIENT) { //判断CLIENT端 IP是否更改 if((strcmp(g_inet_status.client_ip,ip) ! 0) || g_inet_status.client_port ! port) { strncpy(g_inet_status.client_ip,ip,sizeof(ip)); g_inet_status.client_port port; if (g_inet_status.pid 0) create_fork(g_inet_status.status); else { kill_child_fork(g_inet_status.pid); create_fork(g_inet_status.status); } } } return 0; } /* 3.创建一个进程 */ int create_fork(int status) { pid_t pid_s; printf(%s %s %d\n, __FILE__, __FUNCTION__, __LINE__); pid_s fork(); if(pid_s 0) { printf(配置文件改写后服务器进程创建失败, 行 %d\n,__LINE__); return -1; } else if(pid_s 0) { printf(配置文件修改服务器进程创建成功, 行 %d\n,__LINE__); } else { g_inet_status.pid getpid(); if(g_inet_status.status SERVER) { printf(%s %s %d\n, __FILE__, __FUNCTION__, __LINE__); reload_server_create(g_inet_status.server_ip,g_inet_status.server_port); } else if(g_inet_status.status CLIENT) reload_client_create(g_inet_status.client_ip,g_inet_status.client_port); } } // 处理串口读 广播 void handle_serial_event(int epfd, int *uart_fd, struct epoll_event *ev, char *buf, int buf_len) { int total_read 0; int n; printf(串口事件触发串口以读取数据 %d\n,*uart_fd); while (1) { n read(*uart_fd, buf total_read, buf_len - total_read); if (n 0) { total_read n; // 广播给所有客户端 struct llist_node_st *cur, *next; for (cur list_head-head.next; cur ! list_head-head; cur next) { next cur-next; struct info_client_status *data (struct info_client_status*)cur-data; int s send(data-client_socket, buf, n, MSG_NOSIGNAL); printf(服务器将串口数据 发送至 客户端[%d] %s\n,data-client_socket,buf); if (s 0 errno ! EAGAIN) { epoll_ctl(epfd, EPOLL_CTL_DEL,>#ifndef DOUBLE_LINK_LIST_H__ #define DOUBLE_LINK_LIST_H__ #define FORWARD 1 //头插入 #define BACKWARD 2 //尾插入 typedef void (*llist_op)(const void *); typedef int (*llist_cmp)(const void *, const void *); //【性能】传任何类型完成双向链表的机制 //链表节点 struct llist_node_st { struct llist_node_st *prev; struct llist_node_st *next; char data[1]; }; //头节点 typedef struct llist_head { int size; //单链表存储大小可由用户指定 struct llist_node_st head; int (*insert)(struct llist_head * , const void *, int ); void *(*find)(struct llist_head * , const void * , llist_cmp ); int (*delete)(struct llist_head * , const void * , llist_cmp ); int (*fetch)(struct llist_head * , const void * , llist_cmp , void *); void (*travel)(struct llist_head * ,llist_op ); void (*destroy)(struct llist_head * ); }LLIST; /* 1.创建链表()带头节点的双向循环链表 */ LLIST *llist_create(int initsize); /* 2.插入一个链表头/尾 */ int llist_insert(LLIST *ptr, const void *data, int mode); /* 3.查找一个链表数据 */ void *llist_find(LLIST *ptr, const void *key, llist_cmp cmp); /* 4.删除一个链表 */ int llist_delete(LLIST *ptr, const void *key, llist_cmp cmp); /* 5.提取一个链表 */ int llist_fetch(LLIST *ptr, const void *key, llist_cmp cmp, void *data); /* 6.显示所有链表数据 */ void llist_travel(LLIST *ptr, llist_op); /* 7.释放所有链表 */ void llist_destroy(LLIST *ptr); #endif#include stdio.h #include stdlib.h #include errno.h #include string.h #include double_link_list.h //【性能】传任何类型完成双向链表的机制 //公用查找函数 static struct llist_node_st *find_(LLIST *ptr, const void *key, llist_cmp cmp) { struct llist_node_st *cur; for(cur ptr-head.next; cur ! ptr-head; cur cur-next) { if(cmp(key,cur-data) 0) break; } return cur; //没找到cur为头节点 } /* 1.创建链表()带头节点的双向循环链表 */ LLIST *llist_create(int initsize) { LLIST *new; new malloc(sizeof(*new)); if(new NULL) return NULL; new-size initsize; new-head.prev new-head; new-head.next new-head; new-insert llist_insert; new-find llist_find; new-delete llist_delete; new-fetch llist_fetch; new-travel llist_travel; new-destroy llist_destroy; return new; } /* 2.插入一个链表 */ int llist_insert(LLIST *ptr, const void *data, int mode) { struct llist_node_st *newnode; if (ptr NULL || data NULL) { errno EINVAL; return -1; } newnode malloc(sizeof(*newnode) ptr-size); if(newnode NULL) { errno ENOMEM; return -1; } else memcpy(newnode-data,data,ptr-size); if(mode FORWARD) { newnode-prev ptr-head; newnode-next ptr-head.next; } else if(mode BACKWARD) { newnode-next ptr-head; newnode-prev ptr-head.prev; } else { errno EINVAL; return -1; } newnode-prev-next newnode; newnode-next-prev newnode; return 0; } /* 3.删除一个链表 */ int llist_delete(LLIST *ptr, const void *key, llist_cmp cmp) { struct llist_node_st *node; node find_(ptr,key,cmp); if(node ptr-head) return -1; node-next-prev node-prev; node-prev-next node-next; free(node); return 0; } /* 4.查找数据 */ void *llist_find(LLIST *ptr, const void *key, llist_cmp cmp) { struct llist_node_st *node; node find_(ptr,key,cmp); if(node ptr-head) return NULL; return node-data; } /* 5.拿出一个链表 */ int llist_fetch(LLIST *ptr, const void *key, llist_cmp cmp, void *data) { struct llist_node_st *node; node find_(ptr,key,cmp); if(node ptr-head) return -1; node-next-prev node-prev; node-prev-next node-next; if(data ! NULL) memcpy(data,node-data,ptr-size); free(node); return 0; } /* 6.推送一个链表 (推送给有读标志的成员)*/ void llist_travel(LLIST *ptr,llist_op operate) { struct llist_node_st *cur; for(cur ptr-head.next; cur ! ptr-head; cur cur-next) operate(cur-data); } /* 7.销毁*/ void llist_destroy(LLIST *ptr) { struct llist_node_st *cur,*next; for(cur ptr-head.next; cur ! ptr-head; cur next) { next cur-next; free(cur); } free(ptr); }9. 全局数据结构struct server_or_client保存网络模式、子进程 PID、IP 和端口区分 server/client 两套变量struct uart_status保存串口 fd、设备名、波特率、数据位、校验位、停止位struct info_client_status保存客户端 socket 和连接状态仅服务器模式使用LLIST *list_head服务器模式下的客户端链表二、核心要点总结多进程架构主进程监控配置 子进程网络转发。子进程崩溃或被杀死后主进程根据最新配置可重新拉起实现热更新。热配置更新串口参数变化关闭原串口打开新串口子进程中直接生效无需重启进程网络参数变化杀死子进程主进程再创建新子进程完全重启网络服务配置监控基于 inotify响应文件修改事件I/O 多路复用服务器模式采用 epoll边缘触发处理大量客户端连接和串口数据客户端模式采用 poll简单高效仅两个 fd数据流向服务器模式服务器读串口数据 → 广播到所有客户端任一客户端 → 串口客户端模式客户端读串口数据 → 服务器服务器 → 串口容错处理客户端发送失败时自动剔除并关闭连接串口异常时尝试重开最多 3 次失败则退出进程由主进程重建客户端模式连接服务器时循环重试直到成功非阻塞 I/O所有 socket 和串口 fd 都设置为非阻塞配合 epoll/poll 避免阻塞。链式存储服务器模式动态维护客户端列表支持任意数量客户端上限由CLIENT_INSERT宏限制。三、整体流程text[主进程启动] | v watch_file_modify() | -- 等待配置文件创建 | v inotify_add_watch() 监听 IN_CLOSE_WRITE | -------------------------- | 配置文件修改事件 | v v parse_config_file() [继续监听] | -- 解析串口参数 - 变化则重开串口重置 g_uart_status.fd_uart | -- 解析网络参数mode/ip/port | -- 若配置与当前 g_inet_status 不同 | (1) 杀死已有子进程 (kill_child_fork) | (2) 创建新子进程 (create_fork) | -- 子进程运行 | -- [服务器模式] reload_server_create() | | | -- 创建监听socket - epoll循环 | - 新连接 - 加入客户端列表 | - 串口可读 - 广播数据 | - 客户端可读 - 写入串口 | -- [客户端模式] reload_client_create() | -- 连接服务器 - poll循环 - 串口可读 - 发送给服务器 - socket可读 - 写入串口关键路径说明主进程只负责配置监控和子进程生命周期管理不处理实际数据转发。当配置文件修改时子进程可能被销毁并重新创建实现网络服务的动态切换。串口的热更只涉及子进程内部重新打开 fd不重启进程。四、潜在问题与改进建议竞态条件主进程修改全局g_uart_status和g_inet_status时子进程正在读取这些变量未加锁保护。建议通过信号或管道传递配置变更而非共享内存。资源释放服务器模式下退出时未释放链表、关闭 epoll fd 和 socket客户端模式下未关闭串口和 socket。僵尸进程kill_child_fork中waitpid非阻塞实际是阻塞的但若子进程已退出可能出错建议使用SIGCHLD信号处理。硬编码限制CLIENT_INSERT未给出定义缓冲区大小固定 1024 可能溢出。守护进程当前未真正 daemonize日志输出到 stdout生产环境建议启用。断线重连客户端模式在服务器断开后直接退出应由主进程根据配置重新创建子进程依赖配置监控触发但若网络闪断未改配置则无法恢复。建议在客户端内部实现重连逻辑。以上分析基于代码实际行为对设计思想和实现细节进行了系统梳理。依赖说明cJSON 库用于解析 JSON 配置文件请从 cJSON 官方仓库 下载cJSON.h和cJSON.c并一同编译。编译命令中需要包含-lpthreadcJSON 内部可能使用了线程局部存储虽然本程序未直接多线程。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2586399.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

SpringBoot-17-MyBatis动态SQL标签之常用标签

文章目录 1 代码1.1 实体User.java1.2 接口UserMapper.java1.3 映射UserMapper.xml1.3.1 标签if1.3.2 标签if和where1.3.3 标签choose和when和otherwise1.4 UserController.java2 常用动态SQL标签2.1 标签set2.1.1 UserMapper.java2.1.2 UserMapper.xml2.1.3 UserController.ja…

wordpress后台更新后 前端没变化的解决方法

使用siteground主机的wordpress网站,会出现更新了网站内容和修改了php模板文件、js文件、css文件、图片文件后,网站没有变化的情况。 不熟悉siteground主机的新手,遇到这个问题,就很抓狂,明明是哪都没操作错误&#x…

网络编程(Modbus进阶)

思维导图 Modbus RTU(先学一点理论) 概念 Modbus RTU 是工业自动化领域 最广泛应用的串行通信协议,由 Modicon 公司(现施耐德电气)于 1979 年推出。它以 高效率、强健性、易实现的特点成为工业控制系统的通信标准。 包…

UE5 学习系列(二)用户操作界面及介绍

这篇博客是 UE5 学习系列博客的第二篇,在第一篇的基础上展开这篇内容。博客参考的 B 站视频资料和第一篇的链接如下: 【Note】:如果你已经完成安装等操作,可以只执行第一篇博客中 2. 新建一个空白游戏项目 章节操作,重…

IDEA运行Tomcat出现乱码问题解决汇总

最近正值期末周,有很多同学在写期末Java web作业时,运行tomcat出现乱码问题,经过多次解决与研究,我做了如下整理: 原因: IDEA本身编码与tomcat的编码与Windows编码不同导致,Windows 系统控制台…

利用最小二乘法找圆心和半径

#include <iostream> #include <vector> #include <cmath> #include <Eigen/Dense> // 需安装Eigen库用于矩阵运算 // 定义点结构 struct Point { double x, y; Point(double x_, double y_) : x(x_), y(y_) {} }; // 最小二乘法求圆心和半径 …

使用docker在3台服务器上搭建基于redis 6.x的一主两从三台均是哨兵模式

一、环境及版本说明 如果服务器已经安装了docker,则忽略此步骤,如果没有安装,则可以按照一下方式安装: 1. 在线安装(有互联网环境): 请看我这篇文章 传送阵>> 点我查看 2. 离线安装(内网环境):请看我这篇文章 传送阵>> 点我查看 说明&#xff1a;假设每台服务器已…

XML Group端口详解

在XML数据映射过程中&#xff0c;经常需要对数据进行分组聚合操作。例如&#xff0c;当处理包含多个物料明细的XML文件时&#xff0c;可能需要将相同物料号的明细归为一组&#xff0c;或对相同物料号的数量进行求和计算。传统实现方式通常需要编写脚本代码&#xff0c;增加了开…

LBE-LEX系列工业语音播放器|预警播报器|喇叭蜂鸣器的上位机配置操作说明

LBE-LEX系列工业语音播放器|预警播报器|喇叭蜂鸣器专为工业环境精心打造&#xff0c;完美适配AGV和无人叉车。同时&#xff0c;集成以太网与语音合成技术&#xff0c;为各类高级系统&#xff08;如MES、调度系统、库位管理、立库等&#xff09;提供高效便捷的语音交互体验。 L…

(LeetCode 每日一题) 3442. 奇偶频次间的最大差值 I (哈希、字符串)

题目&#xff1a;3442. 奇偶频次间的最大差值 I 思路 &#xff1a;哈希&#xff0c;时间复杂度0(n)。 用哈希表来记录每个字符串中字符的分布情况&#xff0c;哈希表这里用数组即可实现。 C版本&#xff1a; class Solution { public:int maxDifference(string s) {int a[26]…

【大模型RAG】拍照搜题技术架构速览:三层管道、两级检索、兜底大模型

摘要 拍照搜题系统采用“三层管道&#xff08;多模态 OCR → 语义检索 → 答案渲染&#xff09;、两级检索&#xff08;倒排 BM25 向量 HNSW&#xff09;并以大语言模型兜底”的整体框架&#xff1a; 多模态 OCR 层 将题目图片经过超分、去噪、倾斜校正后&#xff0c;分别用…

【Axure高保真原型】引导弹窗

今天和大家中分享引导弹窗的原型模板&#xff0c;载入页面后&#xff0c;会显示引导弹窗&#xff0c;适用于引导用户使用页面&#xff0c;点击完成后&#xff0c;会显示下一个引导弹窗&#xff0c;直至最后一个引导弹窗完成后进入首页。具体效果可以点击下方视频观看或打开下方…

接口测试中缓存处理策略

在接口测试中&#xff0c;缓存处理策略是一个关键环节&#xff0c;直接影响测试结果的准确性和可靠性。合理的缓存处理策略能够确保测试环境的一致性&#xff0c;避免因缓存数据导致的测试偏差。以下是接口测试中常见的缓存处理策略及其详细说明&#xff1a; 一、缓存处理的核…

龙虎榜——20250610

上证指数放量收阴线&#xff0c;个股多数下跌&#xff0c;盘中受消息影响大幅波动。 深证指数放量收阴线形成顶分型&#xff0c;指数短线有调整的需求&#xff0c;大概需要一两天。 2025年6月10日龙虎榜行业方向分析 1. 金融科技 代表标的&#xff1a;御银股份、雄帝科技 驱动…

观成科技:隐蔽隧道工具Ligolo-ng加密流量分析

1.工具介绍 Ligolo-ng是一款由go编写的高效隧道工具&#xff0c;该工具基于TUN接口实现其功能&#xff0c;利用反向TCP/TLS连接建立一条隐蔽的通信信道&#xff0c;支持使用Let’s Encrypt自动生成证书。Ligolo-ng的通信隐蔽性体现在其支持多种连接方式&#xff0c;适应复杂网…

铭豹扩展坞 USB转网口 突然无法识别解决方法

当 USB 转网口扩展坞在一台笔记本上无法识别,但在其他电脑上正常工作时,问题通常出在笔记本自身或其与扩展坞的兼容性上。以下是系统化的定位思路和排查步骤,帮助你快速找到故障原因: 背景: 一个M-pard(铭豹)扩展坞的网卡突然无法识别了,扩展出来的三个USB接口正常。…

未来机器人的大脑:如何用神经网络模拟器实现更智能的决策?

编辑&#xff1a;陈萍萍的公主一点人工一点智能 未来机器人的大脑&#xff1a;如何用神经网络模拟器实现更智能的决策&#xff1f;RWM通过双自回归机制有效解决了复合误差、部分可观测性和随机动力学等关键挑战&#xff0c;在不依赖领域特定归纳偏见的条件下实现了卓越的预测准…

Linux应用开发之网络套接字编程(实例篇)

服务端与客户端单连接 服务端代码 #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <arpa/inet.h> #include <pthread.h> …

华为云AI开发平台ModelArts

华为云ModelArts&#xff1a;重塑AI开发流程的“智能引擎”与“创新加速器”&#xff01; 在人工智能浪潮席卷全球的2025年&#xff0c;企业拥抱AI的意愿空前高涨&#xff0c;但技术门槛高、流程复杂、资源投入巨大的现实&#xff0c;却让许多创新构想止步于实验室。数据科学家…

深度学习在微纳光子学中的应用

深度学习在微纳光子学中的主要应用方向 深度学习与微纳光子学的结合主要集中在以下几个方向&#xff1a; 逆向设计 通过神经网络快速预测微纳结构的光学响应&#xff0c;替代传统耗时的数值模拟方法。例如设计超表面、光子晶体等结构。 特征提取与优化 从复杂的光学数据中自…