- sock发送
u8 str_send[1024];
strcpy((char *)str_send, "Hello, World!\r\n");
lwip_send(sock, str_send, strlen(str_send), 0);
memset(str_send, '\0', strlen(str_send));
C 库函数 size_t strlen(const char *str) 计算字符串 str 的长度,直到空结束字符,但不包括空格字符!!!!
- 以空格为间隔,分割字符串
char *token;
// 获取第一个子字符串
token = strtok(recv_buf, delimiter);
// 遍历剩余的子字符串
while (token != NULL) {
// printf("Token %d: %s\n", count + 1, token); // 输出每个分割出来的子字符串
for(int i = 0; i < strlen(token); i++){
para[count][i] = *(token + i);
}
count++; // 统计分割后的子字符串个数
token = strtok(NULL, delimiter); // 获取下一个子字符串
}
// printf("Total number of tokens: %d\n", count); // 输出总的子字符串个数
- 参数解析
/*------------传输延时参数 参数1------------*/
idx_ch = extract_number(para[0]);//提取通道的索引值
xil_printf("Channel value = %u\r\n", idx_ch); // 输出: 12345
Xil_Out32(ADDR_OCM_CH - 2, (u16)idx_ch);
/*------------传输权重参数 参数2------------*/
float weight = strtof(para[1], &endptr);
// 检查是否整个字符串都被成功解析
// if (*endptr == '\0') {
// printf("The entire string was successfully converted.\n");
// } else {
// printf("The remaining string after conversion: %s\n", endptr); // 输出"abc.456"
// }
// printf("Converted float: %f\n", weight); // float
tmp = float_to_fixed(weight);
Xil_Out32(ADDR_OCM_CH + (idx_ch-1)*8, tmp);
// xil_printf("Converted fixed: %d\n", tmp); // u32
weight = fixed_to_float(tmp);
// printf("Converted float: %f\n", weight); // float
// printf("para[2] = %s\n", para[2]);
/*------------传输延时参数 参数3------------*/
// 使用 strtoul 将字符串转换为 unsigned int
tmp = (u32) strtoul(para[2], &endptr1, 10); // 以十进制(base 10)解析
// 输出结果
// printf("Converted value: %u\n", tmp); // 输出: 12345
Xil_Out32(ADDR_OCM_CH + (idx_ch-1)*8 + OFFSET_DELAY, tmp);