恢复上一次提交前更改

This commit is contained in:
zzh 2026-01-09 10:41:53 +08:00
parent d8ed14d14d
commit e9b7bc62a8
2 changed files with 23 additions and 45 deletions

View File

@ -3421,23 +3421,13 @@ int uart_data_receive_version(uart_utils_t *uart){
int uart_data_receive_data_back(uart_utils_t *uart,uint16_t *parmAck,uint16_t *tagCodeHead,uint32_t *tagCode,uint8_t *tagSignal, int uart_data_receive_data_back(uart_utils_t *uart,uint16_t *parmAck,uint16_t *tagCodeHead,uint32_t *tagCode,uint8_t *tagSignal,
uint8_t *totalLen,uint8_t *tagFeature,uint8_t *count,uint8_t *batteryV,uint16_t *version,uint8_t *ledCtrl, uint8_t *totalLen,uint8_t *tagFeature,uint8_t *count,uint8_t *batteryV,uint16_t *version,uint8_t *ledCtrl,
uint16_t *signCode,uint16_t *reserve,uint32_t *lableParm){ uint16_t *signCode,uint16_t *reserve,uint32_t *lableParm){
//LOG_I("ENTER: uart_data_receive_data_back\n");
int ret = 0; int ret = 0;
jt_data_back_package_t jt_data_back_package; jt_data_back_package_t jt_data_back_package;
uint8_t *buf = (uint8_t *)&jt_data_back_package; uint8_t *buf = (uint8_t *)&jt_data_back_package;
int pkg_size = sizeof(jt_data_back_package_t); int pkg_size = sizeof(jt_data_back_package_t);
//LOG_I("DEBUG: uart_data_receive_data_back starting, uart_fd=%d, buffer size: %d bytes\n", uart->uart_fd, pkg_size);
ret = uart_read_until_time(uart->uart_fd,(char *)buf, pkg_size, 1000, 50); ret = uart_read_until_time(uart->uart_fd,(char *)buf, pkg_size, 1000, 50);
//LOG_I("DEBUG: uart_read_until_time returned %d (expected %d)\n", ret, pkg_size);
if(ret != pkg_size){ if(ret != pkg_size){
if(ret == 0) {
// 超时,不打印错误日志
return -1;
}
//LOG_I("uart_data_receive_data_back failed - ret=%d, expected=%d\n", ret, pkg_size);
return -1; return -1;
} }

View File

@ -2,7 +2,6 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <sys/select.h> #include <sys/select.h>
#include <errno.h>
#include "read_utils.h" #include "read_utils.h"
#define PRINT_TIME_TAG #define PRINT_TIME_TAG
#define DBG_TAG "read_utils" #define DBG_TAG "read_utils"
@ -21,20 +20,15 @@ int read_data_until_time(int fd, char *buffer, int len, int timeout_first, int t
int i; int i;
memset(buffer, 0, len); memset(buffer, 0, len);
tv.tv_sec = 0;
tv.tv_usec = timeout_first*1000;
for(i=0; i<len; i++){ for(i=0; i<len; i++){
FD_ZERO(&fds); FD_ZERO(&fds);
FD_SET(fd, &fds); FD_SET(fd, &fds);
// 每次都要重新设置超时时间,因为 select 会修改 tv //ret = select(FD_SETSIZE, &fds, NULL, NULL, &tv);
tv.tv_sec = 0; ret = select(FD_SETSIZE, &fds, NULL, NULL, 0);
tv.tv_usec = (i == 0) ? timeout_first*1000 : timeout_interval*1000;
// 确保超时时间正确设置
if(tv.tv_usec >= 1000000) {
tv.tv_sec = tv.tv_usec / 1000000;
tv.tv_usec = tv.tv_usec % 1000000;
}
ret = select(fd + 1, &fds, NULL, NULL, &tv);
if(ret < 0){ if(ret < 0){
LOG_I("%s:select error, errno=%d (%s), fd=%d\n",__func__, errno, strerror(errno), fd); LOG_I("%s:seclect error\n",__func__);
i = -1; i = -1;
break; break;
}else if(ret > 0){ }else if(ret > 0){
@ -51,6 +45,8 @@ int read_data_until_time(int fd, char *buffer, int len, int timeout_first, int t
buffer[i] = c; buffer[i] = c;
} }
} }
tv.tv_sec = 0;
tv.tv_usec = timeout_interval*1000;
}else{ }else{
//LOG_I("read time out\n"); //LOG_I("read time out\n");
break; break;
@ -72,19 +68,14 @@ int read_data_until_char(int fd, char *buffer, int len, char until, int timeout_
memset(buffer, 0, len); memset(buffer, 0, len);
for(i=0; i<len; i++){ for(i=0; i<len; i++){
tv.tv_sec = 0;
tv.tv_usec = timeout_first*1000;
FD_ZERO(&fds); FD_ZERO(&fds);
FD_SET(fd, &fds); FD_SET(fd, &fds);
// 每次都要重新设置超时时间,因为 select 会修改 tv //ret = select(FD_SETSIZE, &fds, NULL, NULL, &tv);
tv.tv_sec = 0; ret = select(FD_SETSIZE, &fds, NULL, NULL, 0);
tv.tv_usec = (i == 0) ? timeout_first*1000 : timeout_interval*1000;
// 确保超时时间正确设置
if(tv.tv_usec >= 1000000) {
tv.tv_sec = tv.tv_usec / 1000000;
tv.tv_usec = tv.tv_usec % 1000000;
}
ret = select(fd + 1, &fds, NULL, NULL, &tv);
if(ret < 0){ if(ret < 0){
LOG_I("%s:select error, errno=%d (%s), fd=%d\n",__func__, errno, strerror(errno), fd); LOG_I("%s:seclect error\n",__func__);
i = -1; i = -1;
break; break;
}else if(ret > 0){ }else if(ret > 0){
@ -102,13 +93,15 @@ int read_data_until_char(int fd, char *buffer, int len, char until, int timeout_
LOG_D("i= %d\n", i); LOG_D("i= %d\n", i);
LOG_D("\t,[%#x], <%c>\n", c, c); LOG_D("\t,[%#x], <%c>\n", c, c);
#endif #endif
} tv.tv_sec = 0;
} tv.tv_usec = timeout_interval*1000;
}else{
if(c == until){ if(c == until){
i++; i++;
break; break;
} }
}
}
}else{
//LOG_I("read time out\n"); //LOG_I("read time out\n");
} }
} }
@ -128,19 +121,14 @@ int read_data_until_str(int fd, char *buffer, int len, char *until, int until_le
memset(buffer, 0, len); memset(buffer, 0, len);
for(i=0; i<len; i++){ for(i=0; i<len; i++){
tv.tv_sec = 0;
tv.tv_usec = timeout_first*1000;
FD_ZERO(&fds); FD_ZERO(&fds);
FD_SET(fd, &fds); FD_SET(fd, &fds);
// 每次都要重新设置超时时间,因为 select 会修改 tv //ret = select(FD_SETSIZE, &fds, NULL, NULL, &tv);
tv.tv_sec = 0; ret = select(FD_SETSIZE, &fds, NULL, NULL, 0);
tv.tv_usec = (i == 0) ? timeout_first*1000 : timeout_interval*1000;
// 确保超时时间正确设置
if(tv.tv_usec >= 1000000) {
tv.tv_sec = tv.tv_usec / 1000000;
tv.tv_usec = tv.tv_usec % 1000000;
}
ret = select(fd + 1, &fds, NULL, NULL, &tv);
if(ret < 0){ if(ret < 0){
LOG_I("%s:select error, errno=%d (%s), fd=%d\n",__func__, errno, strerror(errno), fd); LOG_I("%s:seclect error\n",__func__);
i = -1; i = -1;
break; break;
}else if(ret > 0){ }else if(ret > 0){