test: 🐛 更换更简单的写入方式

This commit is contained in:
yuanQie 2025-05-27 02:37:52 +08:00
parent d38be6aca9
commit 9e7b19652b

View File

@ -92,6 +92,8 @@ void *handleUdpTransmission(void *arg)
server_addr_case52.sin_family = AF_INET; // IPv4
server_addr_case52.sin_port = htons(SERVER_PORT_CASE52); // 端口转换
server_addr_case52.sin_addr.s_addr = inet_addr(SERVER_IP_CASE52); // IP转换
int flags = fcntl(sockfd_case52, F_GETFL, 0);
fcntl(sockfd_case52, F_SETFL, flags | O_NONBLOCK);
printf("[socket]:UDP ready\n");
// mmap
/************************************************************************************** */
@ -175,7 +177,7 @@ void *handleUdpTransmission(void *arg)
// 偏移
size_t tx_data_offset = wr_cunt * 16016 + arr_cunt * 2;
// cpy
memcpy((char*)map_base_tx_case52 + tx_data_offset, &txt_buffer[data_index], 2);
memcpy((char*)map_base_tx_case52 + tx_data_offset, &txt_buffer[data_index], 2);//65536
// 更新数据索引
data_index = (data_index + 1) % 65535;
}
@ -189,26 +191,16 @@ void *handleUdpTransmission(void *arg)
printf("[slot]:%u \n", slot_ind_flag);
if (1 == slot_ind_flag)
{
printf("[test 01]\n");
slot_ind_flag = 0;
/************************************************************************************** */
// wr 16016*64(byte) [8008] 2字节复制一次while循环会写入 1/20 的数据触发条件为slot_ind_flag
printf("[test 02]\n");
size_t buffer_start = data_index;// 当前数据读取的起始索引
size_t elements_remaining = 65535 - buffer_start;// 从buffer_start到数组末尾的剩余元素数
size_t elements_to_copy = (elements_remaining >= 8008) ? 8008 : elements_remaining; // 剩余
printf("[test 03]\n");
// 拷贝前半部分(可能跨数组末尾)
printf("[test 04]\n");
memcpy((char*)map_base_tx_case52 + wr_cunt * 16016, &txt_buffer[buffer_start], elements_to_copy * 2);
printf("[test 05]\n");
// 处理数组环绕
if (elements_to_copy < 8008) {
size_t elements_needed = 8008 - elements_to_copy;
memcpy((char*)map_base_tx_case52 + wr_cunt * 16016 + elements_to_copy * 2, &txt_buffer[0], elements_needed * 2);
// wr 16016*20(byte),一次while循环会写入 1/20 的数据触发条件为slot_ind_flag
const size_t current_pos = wr_cunt * 16016;
for (int i = 0; i < 8008; ++i) {
const uint16_t value = txt_buffer[(data_index + i) % 65535];
memcpy((char*)map_base_tx_case52 + current_pos + i*2, &value, 2);
}
printf("[test 06]\n");
// 更新数组索引和块索引
data_index = (data_index + 8008) % 65535;
wr_cunt = (wr_cunt + 1) % 20;
/************************************************************************************** */
@ -222,7 +214,6 @@ void *handleUdpTransmission(void *arg)
/************************************************************************************** */
// 尝试读取
uint8_t block_n = 0;
printf("[test 08]\n");
if (w_idx == r_idx){
printf("[while(1)]: w_idx = %hhu, r_idx = %hhu\n", w_idx, r_idx);
printf("[while(1)]: 空\n");
@ -245,6 +236,15 @@ void *handleUdpTransmission(void *arg)
(const struct sockaddr*)&server_addr_case52,
sizeof(server_addr_case52)
);
if (send_len == -1) {
if (errno == EAGAIN || errno == EWOULDBLOCK) {
printf("[UDP] UDP发送缓冲区满\n");
continue;
}else{
perror("sendto error");
continue;
}
}
r_idx ++ ;
}
// 更新r_idx,如果到头
@ -267,6 +267,15 @@ void *handleUdpTransmission(void *arg)
(const struct sockaddr*)&server_addr_case52,
sizeof(server_addr_case52)
);
if (send_len == -1) {
if (errno == EAGAIN || errno == EWOULDBLOCK) {
printf("[UDP] UDP发送缓冲区满\n");
continue;
}else{
perror("sendto error");
continue;
}
}
r_idx ++ ;
}
r_idx = r_idx % 8;
@ -285,6 +294,15 @@ void *handleUdpTransmission(void *arg)
(const struct sockaddr*)&server_addr_case52,
sizeof(server_addr_case52)
);
if (send_len == -1) {
if (errno == EAGAIN || errno == EWOULDBLOCK) {
printf("[UDP] UDP发送缓冲区满\n");
continue;
}else{
perror("sendto error");
continue;
}
}
r_idx ++;
}
}