// 关闭CAN接口
char command[256];
snprintf(command, sizeof(command), "ip link set down %s", ifname);
+printf( "can bus down cmd : %s\n", command );
if (execute_system_command(command) < 0) {
return -1;
}
-
+ usleep(200);
// 重新启用CAN接口
snprintf(command, sizeof(command), "ip link set up %s", ifname);
+printf( "can bus up cmd : %s\n", command );
if (execute_system_command(command) < 0) {
return -1;
}
+ usleep(200);
printf("CAN总线 %d (%s) 重置成功\n", bus_id, ifname);
return 0;
// 发送数据
ssize_t nbytes = write(device->socket_fd, &canfd_frame, sizeof(canfd_frame));
if (nbytes < 0) {
+ static int err_n = 0;
fprintf(stderr, "发送CAN数据失败: %s\n", strerror(errno));
+ err_n++;
+ printf( "can write err cnt:%d\n", err_n );
+ if( err_n > 4 ){
+ err_n = 0;
+ printf( "TODO reset can \n" );
+ can_bus_reset( device->bus_id);
+ }
// 可以考虑重新入队
//queue_push(device, &frame);
+ }else{
+ err_n = 0;
}
}
}