Thread_local_global_variable

本文提供了一个使用pthread线程库实现线程局部存储(TLS)的C语言示例程序。该程序创建了两个线程,并为每个线程分配了独立的数据结构。通过设置和获取特定于线程的数据,演示了TLS的基本用法。

1 Thread-specific data

2 Thread local storage

准备中...

    #include <stdio.h>
    #include <stdlib.h>
    #include <pthread.h>
    #include <string.h>
     
    pthread_key_t key;
    pthread_key_t key2;
     
    struct test_struct {
    int i;
    float k;
    }struct_data;
     
    int temp;
    void destroykey(void *td) {
     
    pthread_setspecific (key, NULL);
    free(td);
     
    }
    void destroykey2(void *temp) {
    pthread_setspecific (key2, NULL);
    free(temp);
    }
    int setspecificvar () {
    int *temp = malloc(sizeof(int));
    struct test_struct *td = malloc(sizeof(struct test_struct));
    memset(td, 0, sizeof(struct test_struct));
    memset(temp, 0, sizeof(int));
    pthread_setspecific (key, td);
    pthread_setspecific (key2, temp);
     
    return 0;
    }
    int changedata (int i, float k, int tempvar) {
     
    int *temp = pthread_getspecific(key2);
    *temp = tempvar;
    struct test_struct *td1 = pthread_getspecific(key);
    td1->i = i;
    td1->k = k;
    return 0;
    }
     
    int printdata (int t) {
     
    int *temp = pthread_getspecific(key2);
    struct test_struct *td1 = pthread_getspecific(key);
     
    printf ("The addres in child%d returned from pthread_getspecific(key):0x%p\n", t, (struct test_struct *)pthread_getspecific(key));
     
    printf ("The value of members in structure bound to \"key\" in child%d:\nstruct_data.i:%d\nstruct_data.k: %f\n", t, td1->i, td1->k);
     
    printf ("------------------------------------------------------\n");
     
    printf ("The addres in child%d returned from pthread_getspecific(key2):0x%p\n", t, (int *)pthread_getspecific(key2));
    printf ("The value of \"temp\" bound to \"key2\" in child%d:%d\n", t, *temp);
     
    return 0;
    }
     
    void *child1 (void *arg) {
    setspecificvar ();
    changedata(10, 3.141500, 110);
    printdata(1);
    }
     
    void *child2 (void *arg) {
     
    setspecificvar ();
     
    changedata(211, 2.141500, 211);
    printdata(2);
     
    changedata (222, 22.141500, 2222);
    printdata (2);
    }
     
    int create_key () {
    pthread_key_create (&key, destroykey);
    pthread_key_create (&key2, destroykey2);
    return 0;
    }
     
    int delete_key () {
     
    pthread_key_delete (key);
    pthread_key_delete (key2);
    return 0;
    }
     
    int main (int argc, char *argv[]) {
    pthread_t tid1, tid2;
     
    create_key ();
    pthread_create (&tid1, NULL, (void *)child1, NULL);
    pthread_create (&tid2, NULL, (void *)child2, NULL);
    pthread_join (tid1, NULL);
    pthread_join (tid2, NULL);
     
    delete_key ();
     
    return 0;
    }


参考:

http://stackoverflow.com/questions/14260668/how-to-use-thread-specific-data-correctly

http://publib.boulder.ibm.com/infocenter/iseries/v5r3/index.jsp?topic=%2Frzahw%2Frzahwe21rx.htm

http://cboard.cprogramming.com/c-programming/153492-thread-specific-data-not-work-fine-me-pthread.html

elcome to Atlas 200I DK A2 This system is based on Ubuntu 22.04.5 LTS (GNU/Linux 5.10.0+ aarch64) This system is only applicable to individual developers and cannot be used for c By using this system, you have agreed to the Huawei Software License Agreement. Please refer to the agreement for details on https://www.hiascend.com/software/p Reference resources * Home page: https://www.hiascend.com/hardware/developer-kit-a2 * Documentation: https://www.hiascend.com/hardware/developer-kit-a2/resource * Online courses: https://www.hiascend.com/edu/courses * Online experiments: https://www.hiascend.com/zh/edu/experiment * Forum: https://www.hiascend.com/forum/ * Code: https://gitee.com/HUAWEI-ASCEND/ascend-devkit * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/pro (base) root@davinci-mini:~# davinci-mini0 root@davinci-mini:/# cd racecar/ root@davinci-mini:/racecar# ls RedAndGreen Run_car.sh build_isolated docker-compose.yml nav.sh Run_car.log amcl_nav.launch.log devel_isolated gmapping.sh nav2.log root@davinci-mini:/racecar# bash nav_one.sh ... logging to /root/.ros/log/1ba06f92-cbc5-11f0-be3e-2c52afb5f6d1/roslaunch-davinci-mini-59.log Checking log directory for disk usage. This may take a while. Press Ctrl-C to interrupt Done checking log file disk usage. Usage is <1GB. started roslaunch server http://192.168.5.100:34989/ SUMMARY ======== CLEAR PARAMETERS * /ekf_se/ PARAMETERS * /amcl/base_frame_id: base_footprint * /amcl/first_map_only: True * /amcl/global_frame_id: map * /amcl/gui_publish_rate: 30.0 * /amcl/initial_cov_aa: 0.2 * /amcl/initial_cov_xx: 0.25 * /amcl/initial_cov_yy: 0.25 * /amcl/initial_pose_a: 0.0 * /amcl/initial_pose_x: 0.0 * /amcl/initial_pose_y: 0.0 * /amcl/kld_err: 0.01 * /amcl/kld_z: 0.99 * /amcl/laser_lambda_short: 0.1 * /amcl/laser_likelihood_max_dist: 2.0 * /amcl/laser_max_beams: 30 * /amcl/laser_model_type: likelihood_field * /amcl/laser_sigma_hit: 0.2 * /amcl/laser_z_hit: 0.5 * /amcl/laser_z_max: 0.05 * /amcl/laser_z_rand: 0.5 * /amcl/laser_z_short: 0.05 * /amcl/max_particles: 5000 * /amcl/min_particles: 100 * /amcl/odom_alpha1: 0.2 * /amcl/odom_alpha2: 0.2 * /amcl/odom_alpha3: 0.8 * /amcl/odom_alpha4: 0.2 * /amcl/odom_frame_id: odom * /amcl/odom_model_type: diff * /amcl/recovery_alpha_fast: 0.1 * /amcl/recovery_alpha_slow: 0.0 * /amcl/resample_interval: 2 * /amcl/tf_broadcast: True * /amcl/transform_tolerance: 0.1 * /amcl/update_min_a: 0.1 * /amcl/update_min_d: 0.1 * /amcl/use_map_topic: True * /car_controller/Angle_gain_d: -4.0 * /car_controller/Angle_gain_p: -4.0 * /car_controller/Lfw: 1.5 * /car_controller/Person1: 666 * /car_controller/Person2: 580 * /car_controller/Stopcar: 52 * /car_controller/Stoplight: 43 * /car_controller/Vcmd: 1.5 * /car_controller/baseAngle: 65.0 * /car_controller/baseSpeed: 1670 * /car_controller/first_lap: 100 * /car_controller/goalRadius: 0.7 * /car_controller/second_lap: 510 * /car_controller/vp_max_base: 75 * /car_controller/vp_min: 60 * /ekf_se/base_link_frame: /base_footprint * /ekf_se/debug: False * /ekf_se/debug_out_file: /path/to/debug/fi... * /ekf_se/frequency: 20 * /ekf_se/imu0: /imu_data * /ekf_se/imu0_config: [False, False, Fa... * /ekf_se/imu0_differential: False * /ekf_se/imu0_linear_acceleration_rejection_threshold: 2 * /ekf_se/imu0_nodelay: False * /ekf_se/imu0_pose_rejection_threshold: 2.0 * /ekf_se/imu0_queue_size: 8 * /ekf_se/imu0_relative: True * /ekf_se/imu0_remove_gravitational_acceleration: True * /ekf_se/imu0_twist_rejection_threshold: 2.0 * /ekf_se/initial_estimate_covariance: ['1e-9', 0, 0, 0,... * /ekf_se/map_frame: /map * /ekf_se/odom0: /rf2o_laser_odome... * /ekf_se/odom0_config: [False, False, Fa... * /ekf_se/odom0_differential: True * /ekf_se/odom0_nodelay: True * /ekf_se/odom0_pose_rejection_threshold: 8 * /ekf_se/odom0_queue_size: 5 * /ekf_se/odom0_twist_rejection_threshold: 4 * /ekf_se/odom1: /encoder_imu_odom * /ekf_se/odom1_config: [True, True, Fals... * /ekf_se/odom1_differential: True * /ekf_se/odom1_nodelay: True * /ekf_se/odom1_queue_size: 5 * /ekf_se/odom1_relative: False * /ekf_se/odom_frame: /odom * /ekf_se/print_diagnostics: False * /ekf_se/process_noise_covariance: [0.25, 0, 0, 0, 0... * /ekf_se/publish_acceleration: True * /ekf_se/publish_tf: True * /ekf_se/sensor_timeout: 0.025 * /ekf_se/transform_time_offset: 0.0001 * /ekf_se/transform_timeout: 0.025 * /ekf_se/two_d_mode: True * /ekf_se/world_frame: /odom * /move_base/GlobalPlanner/allow_unknown: True * /move_base/GlobalPlanner/cost_factor: 0.54 * /move_base/GlobalPlanner/default_tolerance: 0.2 * /move_base/GlobalPlanner/lethal_cost: 253 * /move_base/GlobalPlanner/neutral_cost: 21 * /move_base/GlobalPlanner/old_navfn_behavior: False * /move_base/GlobalPlanner/orientation_mode: 0 * /move_base/GlobalPlanner/orientation_window_size: 1 * /move_base/GlobalPlanner/publish_potential: True * /move_base/GlobalPlanner/use_dijkstra: False * /move_base/GlobalPlanner/use_grid_path: True * /move_base/GlobalPlanner/use_quadratic: True * /move_base/GlobalPlanner/visualize_potential: False * /move_base/NavfnROS/allow_unknown: False * /move_base/TebLocalPlannerROS/acc_lim_theta: 60 * /move_base/TebLocalPlannerROS/acc_lim_x: 0.188 * /move_base/TebLocalPlannerROS/allow_init_with_backwards_motion: False * /move_base/TebLocalPlannerROS/cmd_angle_instead_rotvel: False * /move_base/TebLocalPlannerROS/complete_global_plan: True * /move_base/TebLocalPlannerROS/costmap_converter_plugin: * /move_base/TebLocalPlannerROS/costmap_converter_rate: 8 * /move_base/TebLocalPlannerROS/costmap_converter_spin_thread: True * /move_base/TebLocalPlannerROS/costmap_obstacles_behind_robot_dist: 0.1 * /move_base/TebLocalPlannerROS/delete_detours_backwards: True * /move_base/TebLocalPlannerROS/dt_hysteresis: 0.05 * /move_base/TebLocalPlannerROS/dt_ref: 0.21 * /move_base/TebLocalPlannerROS/dynamic_obstacle_inflation_dist: 0.1 * /move_base/TebLocalPlannerROS/enable_homotopy_class_planning: True * /move_base/TebLocalPlannerROS/enable_multithreading: False * /move_base/TebLocalPlannerROS/exact_arc_length: True * /move_base/TebLocalPlannerROS/feasibility_check_no_poses: 10 * /move_base/TebLocalPlannerROS/footprint_model: polygon * /move_base/TebLocalPlannerROS/free_goal_vel: True * /move_base/TebLocalPlannerROS/global_plan_overwrite_orientation: True * /move_base/TebLocalPlannerROS/global_plan_prune_distance: 1 * /move_base/TebLocalPlannerROS/global_plan_viapoint_sep: -1 * /move_base/TebLocalPlannerROS/h_signature_prescaler: 0.5 * /move_base/TebLocalPlannerROS/h_signature_threshold: 0.1 * /move_base/TebLocalPlannerROS/include_costmap_obstacles: True * /move_base/TebLocalPlannerROS/include_dynamic_obstacles: True * /move_base/TebLocalPlannerROS/inflation_dist: 0.62 * /move_base/TebLocalPlannerROS/max_global_plan_lookahead_dist: 4.0 * /move_base/TebLocalPlannerROS/max_number_classes: 5 * /move_base/TebLocalPlannerROS/max_ratio_detours_duration_best_duration: 3.0 * /move_base/TebLocalPlannerROS/max_samples: 500 * /move_base/TebLocalPlannerROS/max_vel_theta: 85 * /move_base/TebLocalPlannerROS/max_vel_x: 3 * /move_base/TebLocalPlannerROS/max_vel_x_backwards: 1.2 * /move_base/TebLocalPlannerROS/max_vel_y: 0.288 * /move_base/TebLocalPlannerROS/min_turning_radius: 0.01 * /move_base/TebLocalPlannerROS/no_inner_iterations: -1 * /move_base/TebLocalPlannerROS/no_outer_iterations: -1 * /move_base/TebLocalPlannerROS/obstacle_cost_exponent: -1 * /move_base/TebLocalPlannerROS/obstacle_heading_threshold: 0.45 * /move_base/TebLocalPlannerROS/obstacle_poses_affected: 20 * /move_base/TebLocalPlannerROS/odom_topic: odom * /move_base/TebLocalPlannerROS/optimization_activate: True * /move_base/TebLocalPlannerROS/optimization_verbose: False * /move_base/TebLocalPlannerROS/oscillation_filter_duration: 10 * /move_base/TebLocalPlannerROS/oscillation_omega_eps: 10 * /move_base/TebLocalPlannerROS/oscillation_recovery: False * /move_base/TebLocalPlannerROS/oscillation_recovery_min_duration: 20 * /move_base/TebLocalPlannerROS/oscillation_v_eps: 10 * /move_base/TebLocalPlannerROS/penalty_epsilon: 0.01 * /move_base/TebLocalPlannerROS/publish_feedback: False * /move_base/TebLocalPlannerROS/roadmap_graph_area_length_scale: 1.0 * /move_base/TebLocalPlannerROS/roadmap_graph_area_width: 5 * /move_base/TebLocalPlannerROS/roadmap_graph_no_samples: 15 * /move_base/TebLocalPlannerROS/selection_alternative_time_cost: False * /move_base/TebLocalPlannerROS/selection_cost_hysteresis: 1.0 * /move_base/TebLocalPlannerROS/selection_obst_cost_scale: 1.0 * /move_base/TebLocalPlannerROS/selection_prefer_initial_plan: 0.95 * /move_base/TebLocalPlannerROS/shrink_horizon_backup: True * /move_base/TebLocalPlannerROS/shrink_horizon_min_duration: 3 * /move_base/TebLocalPlannerROS/switching_blocking_period: 0.0 * /move_base/TebLocalPlannerROS/teb_autosize: True * /move_base/TebLocalPlannerROS/type: polygon * /move_base/TebLocalPlannerROS/vertices: [[-0.175, -0.25],... * /move_base/TebLocalPlannerROS/viapoints_all_candidates: True * /move_base/TebLocalPlannerROS/visualize_hc_graph: True * /move_base/TebLocalPlannerROS/visualize_with_time_as_z_axis_scale: False * /move_base/TebLocalPlannerROS/weight_acc_lim_theta: 10 * /move_base/TebLocalPlannerROS/weight_acc_lim_x: 1 * /move_base/TebLocalPlannerROS/weight_adapt_factor: 20 * /move_base/TebLocalPlannerROS/weight_dynamic_obstacle: 10 * /move_base/TebLocalPlannerROS/weight_dynamic_obstacle_inflation: 5 * /move_base/TebLocalPlannerROS/weight_inflation: 50 * /move_base/TebLocalPlannerROS/weight_kinematics_forward_drive: 1000 * /move_base/TebLocalPlannerROS/weight_kinematics_nh: 1000 * /move_base/TebLocalPlannerROS/weight_kinematics_turning_radius: 1000 * /move_base/TebLocalPlannerROS/weight_max_vel_theta: 10 * /move_base/TebLocalPlannerROS/weight_max_vel_x: 1 * /move_base/TebLocalPlannerROS/weight_obstacle: 50 * /move_base/TebLocalPlannerROS/weight_optimaltime: 1000 * /move_base/TebLocalPlannerROS/weight_shortest_path: 1 * /move_base/TebLocalPlannerROS/weight_viapoint: 1 * /move_base/TebLocalPlannerROS/wheelbase: 0.335 * /move_base/TebLocalPlannerROS/xy_goal_tolerance: 0.01 * /move_base/TebLocalPlannerROS/yaw_goal_tolerance: 0.03 * /move_base/base_global_planner: navfn/NavfnROS * /move_base/base_local_planner: teb_local_planner... * /move_base/clearing_rotation_allowed: False * /move_base/controller_frequency: 10.0 * /move_base/controller_patience: 6.0 * /move_base/global_costmap/footprint: [[-0.175, -0.25],... * /move_base/global_costmap/footprint_padding: 0.01 * /move_base/global_costmap/global_frame: map * /move_base/global_costmap/height: 25.0 * /move_base/global_costmap/inflation/cost_scaling_factor: 2.0 * /move_base/global_costmap/inflation/inflation_radius: 0. 1 * /move_base/global_costmap/plugins: [{'name': 'static... * /move_base/global_costmap/publish_frequency: 1.0 * /move_base/global_costmap/resolution: 0.05 * /move_base/global_costmap/robot_base_frame: base_footprint * /move_base/global_costmap/rolling_window: True * /move_base/global_costmap/sensor/laser_scan_sensor/clearing: True * /move_base/global_costmap/sensor/laser_scan_sensor/data_type: LaserScan * /move_base/global_costmap/sensor/laser_scan_sensor/marking: True * /move_base/global_costmap/sensor/laser_scan_sensor/observation_persistence: 0.5 * /move_base/global_costmap/sensor/laser_scan_sensor/sensor_frame: laser_link * /move_base/global_costmap/sensor/laser_scan_sensor/topic: scan * /move_base/global_costmap/sensor/observation_sources: laser_scan_sensor * /move_base/global_costmap/static/map_topic: /map * /move_base/global_costmap/static/subscribe_to_updates: True * /move_base/global_costmap/track_unknown_space: False * /move_base/global_costmap/transform_tolerance: 0.5 * /move_base/global_costmap/update_frequency: 1.0 * /move_base/global_costmap/width: 25.0 * /move_base/local_costmap/footprint: [[-0.175, -0.25],... * /move_base/local_costmap/footprint_padding: 0.01 * /move_base/local_costmap/global_frame: map * /move_base/local_costmap/height: 3.0 * /move_base/local_costmap/inflation/cost_scaling_factor: 6.0 * /move_base/local_costmap/inflation/inflation_radius: 0.1 * /move_base/local_costmap/plugins: [{'name': 'sensor... * /move_base/local_costmap/publish_frequency: 1.0 * /move_base/local_costmap/resolution: 0.05 * /move_base/local_costmap/robot_base_frame: base_footprint * /move_base/local_costmap/rolling_window: True * /move_base/local_costmap/sensor/laser_scan_sensor/clearing: True * /move_base/local_costmap/sensor/laser_scan_sensor/data_type: LaserScan * /move_base/local_costmap/sensor/laser_scan_sensor/marking: True * /move_base/local_costmap/sensor/laser_scan_sensor/sensor_frame: laser_link * /move_base/local_costmap/sensor/laser_scan_sensor/topic: scan * /move_base/local_costmap/sensor/observation_sources: laser_scan_sensor * /move_base/local_costmap/track_unknown_space: False * /move_base/local_costmap/transform_tolerance: 0.5 * /move_base/local_costmap/update_frequency: 1.0 * /move_base/local_costmap/width: 3.0 * /move_base/oscillation_distance: 0.2 * /move_base/oscillation_timeout: 10.0 * /move_base/planner_frequency: 10.0 * /move_base/planner_patience: 5.0 * /move_base/shutdown_costmaps: False * /rf2o_laser_odometry/base_frame_id: base_footprint * /rf2o_laser_odometry/freq: 20.0 * /rf2o_laser_odometry/laser_scan_topic: scan * /rf2o_laser_odometry/odom_frame_id: odom * /rf2o_laser_odometry/odom_topic: odom_rf2o * /rf2o_laser_odometry/publish_tf: False * /rf2o_laser_odometry/verbose: True * /rosdistro: noetic * /rosversion: 1.15.13 NODES / amcl (amcl/amcl) car_controller (racecar/car_controller_new) ekf_se (robot_localization/ekf_localization_node) map_server (map_server/map_server) move_base (move_base/move_base) rf2o_laser_odometry (rf2o_laser_odometry/rf2o_laser_odometry_node) wheel_odom (encoder_driver/encoder_driver_node1) RLException: run_id on parameter server does not match declared run_id: 1a54deac-cbc5-11f0-9652-2c52afb5f6d1 vs 1ba06f92-cbc5-11f0-be3e-2c52afb5f6d1 The traceback for the exception was written to the log file ROS_MASTER_URI=http://192.168.5.100:11311 2025-11-27 19:13:12+0000 [-] Log opened. 2025-11-27 19:13:12+0000 [-] registered capabilities (classes): 2025-11-27 19:13:12+0000 [-] - <class 'rosbridge_library.capabilities.call_service.CallService'> 2025-11-27 19:13:12+0000 [-] - <class 'rosbridge_library.capabilities.advertise.Advertise'> 2025-11-27 19:13:12+0000 [-] - <class 'rosbridge_library.capabilities.publish.Publish'> 2025-11-27 19:13:12+0000 [-] - <class 'rosbridge_library.capabilities.subscribe.Subscribe'> 2025-11-27 19:13:12+0000 [-] - <class 'rosbridge_library.capabilities.defragmentation.Defragment'> 2025-11-27 19:13:12+0000 [-] - <class 'rosbridge_library.capabilities.advertise_service.AdvertiseService'> 2025-11-27 19:13:12+0000 [-] - <class 'rosbridge_library.capabilities.service_response.ServiceResponse'> 2025-11-27 19:13:12+0000 [-] - <class 'rosbridge_library.capabilities.unadvertise_service.UnadvertiseService'> 2025-11-27 19:13:13+0000 [-] WebSocketServerFactory starting on 9090 2025-11-27 19:13:13+0000 [-] Starting factory <autobahn.twisted.websocket.WebSocketServerFactory object at 0xe7ffca3420a0> 2025-11-27 19:13:13+0000 [-] [INFO] [1764270793.062939]: Rosbridge WebSocket server started at ws://0.0.0.0:9090 ^C终止 ROS 启动进程... lslidar_x10_driver_node: /usr/include/boost/thread/pthread/condition_variable_fwd.hpp:81: boost::condition_variable::~condition_variable(): Assertion `!posix::pthread_mutex_destroy(&internal_mutex)' failed. 2025-11-27 19:14:41+0000 [autobahn.twisted.websocket.WebSocketServerFactory] (TCP Port 9090 Closed) [DEBUG] [1764270791.133628]: init_node, name[/encoder_vel], pid[87] [DEBUG] [1764270791.140349]: binding to 0.0.0.0 0 [DEBUG] [1764270791.143836]: bound to 0.0.0.0 43043 [DEBUG] [1764270791.147385]: ... service URL is rosrpc://192.168.5.100:43043 [DEBUG] [1764270791.150428]: [/encoder_vel/get_loggers]: new Service instance [DEBUG] [1764270791.155703]: ... service URL is rosrpc://192.168.5.100:43043 [DEBUG] [1764270791.158360]: [/encoder_vel/set_logger_level]: new Service instance True 2025-11-27 19:14:41+0000 [-] Stopping factory <autobahn.twisted.websocket.WebSocketServerFactory object at 0xe7ffca3420a0> 2025-11-27 19:14:41+0000 [-] Main loop terminated. WARNING: ignoring defunct <master /> tag ... logging to /root/.ros/log/1a54deac-cbc5-11f0-9652-2c52afb5f6d1/roslaunch-davinci-mini-53.log Checking log directory for disk usage. This may take a while. Press Ctrl-C to interrupt Done checking log file disk usage. Usage is <1GB. started roslaunch server http://192.168.5.100:39739/ SUMMARY ======== PARAMETERS * /encoder_vel/baud_rate: 57600 * /encoder_vel/k: 0.88 * /encoder_vel/serial_port: /dev/encoder * /lslidar_x10_driver_node/angle_disable_max: 0.0 * /lslidar_x10_driver_node/angle_disable_min: 0.0 * /lslidar_x10_driver_node/child_frame_id: laser_link * /lslidar_x10_driver_node/interface_selection: serial * /lslidar_x10_driver_node/lidar_name: M10 * /lslidar_x10_driver_node/max_range: 100.0 * /lslidar_x10_driver_node/min_range: 0 * /lslidar_x10_driver_node/scan_topic: scan * /lslidar_x10_driver_node/serial_port: /dev/laser * /lslidar_x10_driver_node/use_gps_ts: False * /rosbridge_server/websocket_port: 9090 * /rosdistro: noetic * /rosversion: 1.15.13 NODES / base_footprint2base_link (tf/static_transform_publisher) base_link2imu (tf/static_transform_publisher) base_link2laser_link (tf/static_transform_publisher) encoder_vel (encoder_driver/Encoder_vel.py) imu_sonser_spec (serial_imu/serial_imu) lslidar_x10_driver_node (lslidar_x10_driver/lslidar_x10_driver_node) racecar_driver (racecar_driver/racecar_driver_node) rosbridge_server (rosbridge_server/rosbridge_websocket) auto-starting new master process[master]: started with pid [66] ROS_MASTER_URI=http://192.168.5.100:11311 setting /run_id to 1a54deac-cbc5-11f0-9652-2c52afb5f6d1 process[rosout-1]: started with pid [79] started core service [/rosout] process[base_footprint2base_link-2]: started with pid [82] process[base_link2laser_link-3]: started with pid [83] process[base_link2imu-4]: started with pid [84] process[lslidar_x10_driver_node-5]: started with pid [85] process[imu_sonser_spec-6]: started with pid [86] process[encoder_vel-7]: started with pid [87] process[racecar_driver-8]: started with pid [88] process[rosbridge_server-9]: started with pid [89] [rosbridge_server-9] killing on exit [racecar_driver-8] killing on exit [encoder_vel-7] killing on exit [imu_sonser_spec-6] killing on exit [lslidar_x10_driver_node-5] killing on exit [base_link2imu-4] killing on exit [base_link2laser_link-3] killing on exit [base_footprint2base_link-2] killing on exit [rosout-1] killing on exit [master] killing on exit shutting down processing monitor... ... shutting down processing monitor complete done Run_car.launch 进程已终止。 amcl_nav.launch 进程已终止。 root@davinci-mini:/racecar# ^C root@davinci-mini:/racecar# bash nav_one.sh 2025-11-27 19:14:55+0000 [-] Log opened. 2025-11-27 19:14:55+0000 [-] registered capabilities (classes): 2025-11-27 19:14:55+0000 [-] - <class 'rosbridge_library.capabilities.call_service.CallService'> 2025-11-27 19:14:55+0000 [-] - <class 'rosbridge_library.capabilities.advertise.Advertise'> 2025-11-27 19:14:55+0000 [-] - <class 'rosbridge_library.capabilities.publish.Publish'> 2025-11-27 19:14:55+0000 [-] - <class 'rosbridge_library.capabilities.subscribe.Subscribe'> 2025-11-27 19:14:55+0000 [-] - <class 'rosbridge_library.capabilities.defragmentation.Defragment'> 2025-11-27 19:14:55+0000 [-] - <class 'rosbridge_library.capabilities.advertise_service.AdvertiseService'> 2025-11-27 19:14:55+0000 [-] - <class 'rosbridge_library.capabilities.service_response.ServiceResponse'> 2025-11-27 19:14:55+0000 [-] - <class 'rosbridge_library.capabilities.unadvertise_service.UnadvertiseService'> 2025-11-27 19:14:55+0000 [-] WebSocketServerFactory starting on 9090 2025-11-27 19:14:55+0000 [-] Starting factory <autobahn.twisted.websocket.WebSocketServerFactory object at 0xe7ffef3acfd0> 2025-11-27 19:14:55+0000 [-] [INFO] [1764270895.708127]: Rosbridge WebSocket server started at ws://0.0.0.0:9090 ... logging to /root/.ros/log/593a31d0-cbc5-11f0-acbf-2c52afb5f6d1/roslaunch-davinci-mini-235.log Checking log directory for disk usage. This may take a while. Press Ctrl-C to interrupt Done checking log file disk usage. Usage is <1GB. started roslaunch server http://192.168.5.100:35929/ SUMMARY ======== CLEAR PARAMETERS * /ekf_se/ PARAMETERS * /amcl/base_frame_id: base_footprint * /amcl/first_map_only: True * /amcl/global_frame_id: map * /amcl/gui_publish_rate: 30.0 * /amcl/initial_cov_aa: 0.2 * /amcl/initial_cov_xx: 0.25 * /amcl/initial_cov_yy: 0.25 * /amcl/initial_pose_a: 0.0 * /amcl/initial_pose_x: 0.0 * /amcl/initial_pose_y: 0.0 * /amcl/kld_err: 0.01 * /amcl/kld_z: 0.99 * /amcl/laser_lambda_short: 0.1 * /amcl/laser_likelihood_max_dist: 2.0 * /amcl/laser_max_beams: 30 * /amcl/laser_model_type: likelihood_field * /amcl/laser_sigma_hit: 0.2 * /amcl/laser_z_hit: 0.5 * /amcl/laser_z_max: 0.05 * /amcl/laser_z_rand: 0.5 * /amcl/laser_z_short: 0.05 * /amcl/max_particles: 5000 * /amcl/min_particles: 100 * /amcl/odom_alpha1: 0.2 * /amcl/odom_alpha2: 0.2 * /amcl/odom_alpha3: 0.8 * /amcl/odom_alpha4: 0.2 * /amcl/odom_frame_id: odom * /amcl/odom_model_type: diff * /amcl/recovery_alpha_fast: 0.1 * /amcl/recovery_alpha_slow: 0.0 * /amcl/resample_interval: 2 * /amcl/tf_broadcast: True * /amcl/transform_tolerance: 0.1 * /amcl/update_min_a: 0.1 * /amcl/update_min_d: 0.1 * /amcl/use_map_topic: True * /car_controller/Angle_gain_d: -4.0 * /car_controller/Angle_gain_p: -4.0 * /car_controller/Lfw: 1.5 * /car_controller/Person1: 666 * /car_controller/Person2: 580 * /car_controller/Stopcar: 52 * /car_controller/Stoplight: 43 * /car_controller/Vcmd: 1.5 * /car_controller/baseAngle: 65.0 * /car_controller/baseSpeed: 1670 * /car_controller/first_lap: 100 * /car_controller/goalRadius: 0.7 * /car_controller/second_lap: 510 * /car_controller/vp_max_base: 75 * /car_controller/vp_min: 60 * /ekf_se/base_link_frame: /base_footprint * /ekf_se/debug: False * /ekf_se/debug_out_file: /path/to/debug/fi... * /ekf_se/frequency: 20 * /ekf_se/imu0: /imu_data * /ekf_se/imu0_config: [False, False, Fa... * /ekf_se/imu0_differential: False * /ekf_se/imu0_linear_acceleration_rejection_threshold: 2 * /ekf_se/imu0_nodelay: False * /ekf_se/imu0_pose_rejection_threshold: 2.0 * /ekf_se/imu0_queue_size: 8 * /ekf_se/imu0_relative: True * /ekf_se/imu0_remove_gravitational_acceleration: True * /ekf_se/imu0_twist_rejection_threshold: 2.0 * /ekf_se/initial_estimate_covariance: ['1e-9', 0, 0, 0,... * /ekf_se/map_frame: /map * /ekf_se/odom0: /rf2o_laser_odome... * /ekf_se/odom0_config: [False, False, Fa... * /ekf_se/odom0_differential: True * /ekf_se/odom0_nodelay: True * /ekf_se/odom0_pose_rejection_threshold: 8 * /ekf_se/odom0_queue_size: 5 * /ekf_se/odom0_twist_rejection_threshold: 4 * /ekf_se/odom1: /encoder_imu_odom * /ekf_se/odom1_config: [True, True, Fals... * /ekf_se/odom1_differential: True * /ekf_se/odom1_nodelay: True * /ekf_se/odom1_queue_size: 5 * /ekf_se/odom1_relative: False * /ekf_se/odom_frame: /odom * /ekf_se/print_diagnostics: False * /ekf_se/process_noise_covariance: [0.25, 0, 0, 0, 0... * /ekf_se/publish_acceleration: True * /ekf_se/publish_tf: True * /ekf_se/sensor_timeout: 0.025 * /ekf_se/transform_time_offset: 0.0001 * /ekf_se/transform_timeout: 0.025 * /ekf_se/two_d_mode: True * /ekf_se/world_frame: /odom * /move_base/GlobalPlanner/allow_unknown: True * /move_base/GlobalPlanner/cost_factor: 0.54 * /move_base/GlobalPlanner/default_tolerance: 0.2 * /move_base/GlobalPlanner/lethal_cost: 253 * /move_base/GlobalPlanner/neutral_cost: 21 * /move_base/GlobalPlanner/old_navfn_behavior: False * /move_base/GlobalPlanner/orientation_mode: 0 * /move_base/GlobalPlanner/orientation_window_size: 1 * /move_base/GlobalPlanner/publish_potential: True * /move_base/GlobalPlanner/use_dijkstra: False * /move_base/GlobalPlanner/use_grid_path: True * /move_base/GlobalPlanner/use_quadratic: True * /move_base/GlobalPlanner/visualize_potential: False * /move_base/NavfnROS/allow_unknown: False * /move_base/TebLocalPlannerROS/acc_lim_theta: 60 * /move_base/TebLocalPlannerROS/acc_lim_x: 0.188 * /move_base/TebLocalPlannerROS/allow_init_with_backwards_motion: False * /move_base/TebLocalPlannerROS/cmd_angle_instead_rotvel: False * /move_base/TebLocalPlannerROS/complete_global_plan: True * /move_base/TebLocalPlannerROS/costmap_converter_plugin: * /move_base/TebLocalPlannerROS/costmap_converter_rate: 8 * /move_base/TebLocalPlannerROS/costmap_converter_spin_thread: True * /move_base/TebLocalPlannerROS/costmap_obstacles_behind_robot_dist: 0.1 * /move_base/TebLocalPlannerROS/delete_detours_backwards: True * /move_base/TebLocalPlannerROS/dt_hysteresis: 0.05 * /move_base/TebLocalPlannerROS/dt_ref: 0.21 * /move_base/TebLocalPlannerROS/dynamic_obstacle_inflation_dist: 0.1 * /move_base/TebLocalPlannerROS/enable_homotopy_class_planning: True * /move_base/TebLocalPlannerROS/enable_multithreading: False * /move_base/TebLocalPlannerROS/exact_arc_length: True * /move_base/TebLocalPlannerROS/feasibility_check_no_poses: 10 * /move_base/TebLocalPlannerROS/footprint_model: polygon * /move_base/TebLocalPlannerROS/free_goal_vel: True * /move_base/TebLocalPlannerROS/global_plan_overwrite_orientation: True * /move_base/TebLocalPlannerROS/global_plan_prune_distance: 1 * /move_base/TebLocalPlannerROS/global_plan_viapoint_sep: -1 * /move_base/TebLocalPlannerROS/h_signature_prescaler: 0.5 * /move_base/TebLocalPlannerROS/h_signature_threshold: 0.1 * /move_base/TebLocalPlannerROS/include_costmap_obstacles: True * /move_base/TebLocalPlannerROS/include_dynamic_obstacles: True * /move_base/TebLocalPlannerROS/inflation_dist: 0.62 * /move_base/TebLocalPlannerROS/max_global_plan_lookahead_dist: 4.0 * /move_base/TebLocalPlannerROS/max_number_classes: 5 * /move_base/TebLocalPlannerROS/max_ratio_detours_duration_best_duration: 3.0 * /move_base/TebLocalPlannerROS/max_samples: 500 * /move_base/TebLocalPlannerROS/max_vel_theta: 85 * /move_base/TebLocalPlannerROS/max_vel_x: 3 * /move_base/TebLocalPlannerROS/max_vel_x_backwards: 1.2 * /move_base/TebLocalPlannerROS/max_vel_y: 0.288 * /move_base/TebLocalPlannerROS/min_turning_radius: 0.01 * /move_base/TebLocalPlannerROS/no_inner_iterations: -1 * /move_base/TebLocalPlannerROS/no_outer_iterations: -1 * /move_base/TebLocalPlannerROS/obstacle_cost_exponent: -1 * /move_base/TebLocalPlannerROS/obstacle_heading_threshold: 0.45 * /move_base/TebLocalPlannerROS/obstacle_poses_affected: 20 * /move_base/TebLocalPlannerROS/odom_topic: odom * /move_base/TebLocalPlannerROS/optimization_activate: True * /move_base/TebLocalPlannerROS/optimization_verbose: False * /move_base/TebLocalPlannerROS/oscillation_filter_duration: 10 * /move_base/TebLocalPlannerROS/oscillation_omega_eps: 10 * /move_base/TebLocalPlannerROS/oscillation_recovery: False * /move_base/TebLocalPlannerROS/oscillation_recovery_min_duration: 20 * /move_base/TebLocalPlannerROS/oscillation_v_eps: 10 * /move_base/TebLocalPlannerROS/penalty_epsilon: 0.01 * /move_base/TebLocalPlannerROS/publish_feedback: False * /move_base/TebLocalPlannerROS/roadmap_graph_area_length_scale: 1.0 * /move_base/TebLocalPlannerROS/roadmap_graph_area_width: 5 * /move_base/TebLocalPlannerROS/roadmap_graph_no_samples: 15 * /move_base/TebLocalPlannerROS/selection_alternative_time_cost: False * /move_base/TebLocalPlannerROS/selection_cost_hysteresis: 1.0 * /move_base/TebLocalPlannerROS/selection_obst_cost_scale: 1.0 * /move_base/TebLocalPlannerROS/selection_prefer_initial_plan: 0.95 * /move_base/TebLocalPlannerROS/shrink_horizon_backup: True * /move_base/TebLocalPlannerROS/shrink_horizon_min_duration: 3 * /move_base/TebLocalPlannerROS/switching_blocking_period: 0.0 * /move_base/TebLocalPlannerROS/teb_autosize: True * /move_base/TebLocalPlannerROS/type: polygon * /move_base/TebLocalPlannerROS/vertices: [[-0.175, -0.25],... * /move_base/TebLocalPlannerROS/viapoints_all_candidates: True * /move_base/TebLocalPlannerROS/visualize_hc_graph: True * /move_base/TebLocalPlannerROS/visualize_with_time_as_z_axis_scale: False * /move_base/TebLocalPlannerROS/weight_acc_lim_theta: 10 * /move_base/TebLocalPlannerROS/weight_acc_lim_x: 1 * /move_base/TebLocalPlannerROS/weight_adapt_factor: 20 * /move_base/TebLocalPlannerROS/weight_dynamic_obstacle: 10 * /move_base/TebLocalPlannerROS/weight_dynamic_obstacle_inflation: 5 * /move_base/TebLocalPlannerROS/weight_inflation: 50 * /move_base/TebLocalPlannerROS/weight_kinematics_forward_drive: 1000 * /move_base/TebLocalPlannerROS/weight_kinematics_nh: 1000 * /move_base/TebLocalPlannerROS/weight_kinematics_turning_radius: 1000 * /move_base/TebLocalPlannerROS/weight_max_vel_theta: 10 * /move_base/TebLocalPlannerROS/weight_max_vel_x: 1 * /move_base/TebLocalPlannerROS/weight_obstacle: 50 * /move_base/TebLocalPlannerROS/weight_optimaltime: 1000 * /move_base/TebLocalPlannerROS/weight_shortest_path: 1 * /move_base/TebLocalPlannerROS/weight_viapoint: 1 * /move_base/TebLocalPlannerROS/wheelbase: 0.335 * /move_base/TebLocalPlannerROS/xy_goal_tolerance: 0.01 * /move_base/TebLocalPlannerROS/yaw_goal_tolerance: 0.03 * /move_base/base_global_planner: navfn/NavfnROS * /move_base/base_local_planner: teb_local_planner... * /move_base/clearing_rotation_allowed: False * /move_base/controller_frequency: 10.0 * /move_base/controller_patience: 6.0 * /move_base/global_costmap/footprint: [[-0.175, -0.25],... * /move_base/global_costmap/footprint_padding: 0.01 * /move_base/global_costmap/global_frame: map * /move_base/global_costmap/height: 25.0 * /move_base/global_costmap/inflation/cost_scaling_factor: 2.0 * /move_base/global_costmap/inflation/inflation_radius: 0. 1 * /move_base/global_costmap/plugins: [{'name': 'static... * /move_base/global_costmap/publish_frequency: 1.0 * /move_base/global_costmap/resolution: 0.05 * /move_base/global_costmap/robot_base_frame: base_footprint * /move_base/global_costmap/rolling_window: True * /move_base/global_costmap/sensor/laser_scan_sensor/clearing: True * /move_base/global_costmap/sensor/laser_scan_sensor/data_type: LaserScan * /move_base/global_costmap/sensor/laser_scan_sensor/marking: True * /move_base/global_costmap/sensor/laser_scan_sensor/observation_persistence: 0.5 * /move_base/global_costmap/sensor/laser_scan_sensor/sensor_frame: laser_link * /move_base/global_costmap/sensor/laser_scan_sensor/topic: scan * /move_base/global_costmap/sensor/observation_sources: laser_scan_sensor * /move_base/global_costmap/static/map_topic: /map * /move_base/global_costmap/static/subscribe_to_updates: True * /move_base/global_costmap/track_unknown_space: False * /move_base/global_costmap/transform_tolerance: 0.5 * /move_base/global_costmap/update_frequency: 1.0 * /move_base/global_costmap/width: 25.0 * /move_base/local_costmap/footprint: [[-0.175, -0.25],... * /move_base/local_costmap/footprint_padding: 0.01 * /move_base/local_costmap/global_frame: map * /move_base/local_costmap/height: 3.0 * /move_base/local_costmap/inflation/cost_scaling_factor: 6.0 * /move_base/local_costmap/inflation/inflation_radius: 0.1 * /move_base/local_costmap/plugins: [{'name': 'sensor... * /move_base/local_costmap/publish_frequency: 1.0 * /move_base/local_costmap/resolution: 0.05 * /move_base/local_costmap/robot_base_frame: base_footprint * /move_base/local_costmap/rolling_window: True * /move_base/local_costmap/sensor/laser_scan_sensor/clearing: True * /move_base/local_costmap/sensor/laser_scan_sensor/data_type: LaserScan * /move_base/local_costmap/sensor/laser_scan_sensor/marking: True * /move_base/local_costmap/sensor/laser_scan_sensor/sensor_frame: laser_link * /move_base/local_costmap/sensor/laser_scan_sensor/topic: scan * /move_base/local_costmap/sensor/observation_sources: laser_scan_sensor * /move_base/local_costmap/track_unknown_space: False * /move_base/local_costmap/transform_tolerance: 0.5 * /move_base/local_costmap/update_frequency: 1.0 * /move_base/local_costmap/width: 3.0 * /move_base/oscillation_distance: 0.2 * /move_base/oscillation_timeout: 10.0 * /move_base/planner_frequency: 10.0 * /move_base/planner_patience: 5.0 * /move_base/shutdown_costmaps: False * /rf2o_laser_odometry/base_frame_id: base_footprint * /rf2o_laser_odometry/freq: 20.0 * /rf2o_laser_odometry/laser_scan_topic: scan * /rf2o_laser_odometry/odom_frame_id: odom * /rf2o_laser_odometry/odom_topic: odom_rf2o * /rf2o_laser_odometry/publish_tf: False * /rf2o_laser_odometry/verbose: True * /rosdistro: noetic * /rosversion: 1.15.13 NODES / amcl (amcl/amcl) car_controller (racecar/car_controller_new) ekf_se (robot_localization/ekf_localization_node) map_server (map_server/map_server) move_base (move_base/move_base) rf2o_laser_odometry (rf2o_laser_odometry/rf2o_laser_odometry_node) wheel_odom (encoder_driver/encoder_driver_node1) [ WARN] [1764270901.074929580]: Failed to meet update rate! Took 0.1020085420000000076 ^C终止 ROS 启动进程... lslidar_x10_driver_node: /usr/include/boost/thread/pthread/condition_variable_fwd.hpp:81: boost::condition_variable::~condition_variable(): Assertion `!posix::pthread_mutex_destroy(&internal_mutex)' failed. [ INFO] [1764270899.968804781]: ?????????????????????????????? [ INFO] [1764270901.013836659]: Subscribed to map topic. [ INFO] [1764270901.452807176]: Received a 608 X 384 map @ 0.050 m/pix [ INFO] [1764270901.485205220]: Initializing likelihood field model; this can take some time on large maps... [ INFO] [1764270901.599203612]: Done initializing likelihood field model. [DEBUG] [1764270895.085141]: init_node, name[/encoder_vel], pid[205] [DEBUG] [1764270895.091976]: binding to 0.0.0.0 0 [DEBUG] [1764270895.095563]: bound to 0.0.0.0 34779 [DEBUG] [1764270895.099010]: ... service URL is rosrpc://192.168.5.100:34779 [DEBUG] [1764270895.102058]: [/encoder_vel/get_loggers]: new Service instance [DEBUG] [1764270895.107122]: ... service URL is rosrpc://192.168.5.100:34779 [DEBUG] [1764270895.109904]: [/encoder_vel/set_logger_level]: new Service instance True 2025-11-27 19:16:49+0000 [autobahn.twisted.websocket.WebSocketServerFactory] (TCP Port 9090 Closed) 2025-11-27 19:16:49+0000 [-] Stopping factory <autobahn.twisted.websocket.WebSocketServerFactory object at 0xe7ffef3acfd0> 2025-11-27 19:16:49+0000 [-] Main loop terminated. ROS_MASTER_URI=http://192.168.5.100:11311 process[map_server-1]: started with pid [256] process[rf2o_laser_odometry-2]: started with pid [257] process[wheel_odom-3]: started with pid [258] process[ekf_se-4]: started with pid [259] process[amcl-5]: started with pid [266] process[move_base-6]: started with pid [268] process[car_controller-7]: started with pid [269] [car_controller-7] killing on exit [move_base-6] killing on exit [amcl-5] killing on exit [ekf_se-4] killing on exit [map_server-1] killing on exit [wheel_odom-3] killing on exit [rf2o_laser_odometry-2] killing on exit shutting down processing monitor... ... shutting down processing monitor complete done WARNING: ignoring defunct <master /> tag ... logging to /root/.ros/log/593a31d0-cbc5-11f0-acbf-2c52afb5f6d1/roslaunch-davinci-mini-159.log Checking log directory for disk usage. This may take a while. Press Ctrl-C to interrupt Done checking log file disk usage. Usage is <1GB. started roslaunch server http://192.168.5.100:35239/ SUMMARY ======== PARAMETERS * /encoder_vel/baud_rate: 57600 * /encoder_vel/k: 0.88 * /encoder_vel/serial_port: /dev/encoder * /lslidar_x10_driver_node/angle_disable_max: 0.0 * /lslidar_x10_driver_node/angle_disable_min: 0.0 * /lslidar_x10_driver_node/child_frame_id: laser_link * /lslidar_x10_driver_node/interface_selection: serial * /lslidar_x10_driver_node/lidar_name: M10 * /lslidar_x10_driver_node/max_range: 100.0 * /lslidar_x10_driver_node/min_range: 0 * /lslidar_x10_driver_node/scan_topic: scan * /lslidar_x10_driver_node/serial_port: /dev/laser * /lslidar_x10_driver_node/use_gps_ts: False * /rosbridge_server/websocket_port: 9090 * /rosdistro: noetic * /rosversion: 1.15.13 NODES / base_footprint2base_link (tf/static_transform_publisher) base_link2imu (tf/static_transform_publisher) base_link2laser_link (tf/static_transform_publisher) encoder_vel (encoder_driver/Encoder_vel.py) imu_sonser_spec (serial_imu/serial_imu) lslidar_x10_driver_node (lslidar_x10_driver/lslidar_x10_driver_node) racecar_driver (racecar_driver/racecar_driver_node) rosbridge_server (rosbridge_server/rosbridge_websocket) auto-starting new master process[master]: started with pid [169] ROS_MASTER_URI=http://192.168.5.100:11311 setting /run_id to 593a31d0-cbc5-11f0-acbf-2c52afb5f6d1 process[rosout-1]: started with pid [179] started core service [/rosout] process[base_footprint2base_link-2]: started with pid [186] process[base_link2laser_link-3]: started with pid [187] process[base_link2imu-4]: started with pid [188] process[lslidar_x10_driver_node-5]: started with pid [193] process[imu_sonser_spec-6]: started with pid [199] process[encoder_vel-7]: started with pid [205] process[racecar_driver-8]: started with pid [211] process[rosbridge_server-9]: started with pid [217] [rosbridge_server-9] killing on exit [racecar_driver-8] killing on exit [encoder_vel-7] killing on exit [imu_sonser_spec-6] killing on exit [lslidar_x10_driver_node-5] killing on exit [base_footprint2base_link-2] killing on exit [base_link2imu-4] killing on exit [base_link2laser_link-3] killing on exit [rosout-1] killing on exit [master] killing on exit shutting down processing monitor... ... shutting down processing monitor complete done Run_car.launch 进程已终止。 amcl_nav.launch 进程已终止。 root@davinci-mini:/racecar# bash nav_one.sh 2025-11-27 19:16:56+0000 [-] Log opened. 2025-11-27 19:16:56+0000 [-] registered capabilities (classes): 2025-11-27 19:16:56+0000 [-] - <class 'rosbridge_library.capabilities.call_service.CallService'> 2025-11-27 19:16:56+0000 [-] - <class 'rosbridge_library.capabilities.advertise.Advertise'> 2025-11-27 19:16:56+0000 [-] - <class 'rosbridge_library.capabilities.publish.Publish'> 2025-11-27 19:16:56+0000 [-] - <class 'rosbridge_library.capabilities.subscribe.Subscribe'> 2025-11-27 19:16:56+0000 [-] - <class 'rosbridge_library.capabilities.defragmentation.Defragment'> 2025-11-27 19:16:56+0000 [-] - <class 'rosbridge_library.capabilities.advertise_service.AdvertiseService'> 2025-11-27 19:16:56+0000 [-] - <class 'rosbridge_library.capabilities.service_response.ServiceResponse'> 2025-11-27 19:16:56+0000 [-] - <class 'rosbridge_library.capabilities.unadvertise_service.UnadvertiseService'> 2025-11-27 19:16:57+0000 [-] WebSocketServerFactory starting on 9090 2025-11-27 19:16:57+0000 [-] Starting factory <autobahn.twisted.websocket.WebSocketServerFactory object at 0xe7ffc75d7c70> 2025-11-27 19:16:57+0000 [-] [INFO] [1764271017.157078]: Rosbridge WebSocket server started at ws://0.0.0.0:9090 ... logging to /root/.ros/log/a199425e-cbc5-11f0-86b4-2c52afb5f6d1/roslaunch-davinci-mini-476.log Checking log directory for disk usage. This may take a while. Press Ctrl-C to interrupt Done checking log file disk usage. Usage is <1GB. started roslaunch server http://192.168.5.100:43287/ SUMMARY ======== CLEAR PARAMETERS * /ekf_se/ PARAMETERS * /amcl/base_frame_id: base_footprint * /amcl/first_map_only: True * /amcl/global_frame_id: map * /amcl/gui_publish_rate: 30.0 * /amcl/initial_cov_aa: 0.2 * /amcl/initial_cov_xx: 0.25 * /amcl/initial_cov_yy: 0.25 * /amcl/initial_pose_a: 0.0 * /amcl/initial_pose_x: 0.0 * /amcl/initial_pose_y: 0.0 * /amcl/kld_err: 0.01 * /amcl/kld_z: 0.99 * /amcl/laser_lambda_short: 0.1 * /amcl/laser_likelihood_max_dist: 2.0 * /amcl/laser_max_beams: 30 * /amcl/laser_model_type: likelihood_field * /amcl/laser_sigma_hit: 0.2 * /amcl/laser_z_hit: 0.5 * /amcl/laser_z_max: 0.05 * /amcl/laser_z_rand: 0.5 * /amcl/laser_z_short: 0.05 * /amcl/max_particles: 5000 * /amcl/min_particles: 100 * /amcl/odom_alpha1: 0.2 * /amcl/odom_alpha2: 0.2 * /amcl/odom_alpha3: 0.8 * /amcl/odom_alpha4: 0.2 * /amcl/odom_frame_id: odom * /amcl/odom_model_type: diff * /amcl/recovery_alpha_fast: 0.1 * /amcl/recovery_alpha_slow: 0.0 * /amcl/resample_interval: 2 * /amcl/tf_broadcast: True * /amcl/transform_tolerance: 0.1 * /amcl/update_min_a: 0.1 * /amcl/update_min_d: 0.1 * /amcl/use_map_topic: True * /car_controller/Angle_gain_d: -4.0 * /car_controller/Angle_gain_p: -4.0 * /car_controller/Lfw: 1.5 * /car_controller/Person1: 666 * /car_controller/Person2: 580 * /car_controller/Stopcar: 52 * /car_controller/Stoplight: 43 * /car_controller/Vcmd: 1.5 * /car_controller/baseAngle: 65.0 * /car_controller/baseSpeed: 1670 * /car_controller/first_lap: 100 * /car_controller/goalRadius: 0.7 * /car_controller/second_lap: 510 * /car_controller/vp_max_base: 75 * /car_controller/vp_min: 60 * /ekf_se/base_link_frame: /base_footprint * /ekf_se/debug: False * /ekf_se/debug_out_file: /path/to/debug/fi... * /ekf_se/frequency: 20 * /ekf_se/imu0: /imu_data * /ekf_se/imu0_config: [False, False, Fa... * /ekf_se/imu0_differential: False * /ekf_se/imu0_linear_acceleration_rejection_threshold: 2 * /ekf_se/imu0_nodelay: False * /ekf_se/imu0_pose_rejection_threshold: 2.0 * /ekf_se/imu0_queue_size: 8 * /ekf_se/imu0_relative: True * /ekf_se/imu0_remove_gravitational_acceleration: True * /ekf_se/imu0_twist_rejection_threshold: 2.0 * /ekf_se/initial_estimate_covariance: ['1e-9', 0, 0, 0,... * /ekf_se/map_frame: /map * /ekf_se/odom0: /rf2o_laser_odome... * /ekf_se/odom0_config: [False, False, Fa... * /ekf_se/odom0_differential: True * /ekf_se/odom0_nodelay: True * /ekf_se/odom0_pose_rejection_threshold: 8 * /ekf_se/odom0_queue_size: 5 * /ekf_se/odom0_twist_rejection_threshold: 4 * /ekf_se/odom1: /encoder_imu_odom * /ekf_se/odom1_config: [True, True, Fals... * /ekf_se/odom1_differential: True * /ekf_se/odom1_nodelay: True * /ekf_se/odom1_queue_size: 5 * /ekf_se/odom1_relative: False * /ekf_se/odom_frame: /odom * /ekf_se/print_diagnostics: False * /ekf_se/process_noise_covariance: [0.25, 0, 0, 0, 0... * /ekf_se/publish_acceleration: True * /ekf_se/publish_tf: True * /ekf_se/sensor_timeout: 0.025 * /ekf_se/transform_time_offset: 0.0001 * /ekf_se/transform_timeout: 0.025 * /ekf_se/two_d_mode: True * /ekf_se/world_frame: /odom * /move_base/GlobalPlanner/allow_unknown: True * /move_base/GlobalPlanner/cost_factor: 0.54 * /move_base/GlobalPlanner/default_tolerance: 0.2 * /move_base/GlobalPlanner/lethal_cost: 253 * /move_base/GlobalPlanner/neutral_cost: 21 * /move_base/GlobalPlanner/old_navfn_behavior: False * /move_base/GlobalPlanner/orientation_mode: 0 * /move_base/GlobalPlanner/orientation_window_size: 1 * /move_base/GlobalPlanner/publish_potential: True * /move_base/GlobalPlanner/use_dijkstra: False * /move_base/GlobalPlanner/use_grid_path: True * /move_base/GlobalPlanner/use_quadratic: True * /move_base/GlobalPlanner/visualize_potential: False * /move_base/NavfnROS/allow_unknown: False * /move_base/TebLocalPlannerROS/acc_lim_theta: 60 * /move_base/TebLocalPlannerROS/acc_lim_x: 0.188 * /move_base/TebLocalPlannerROS/allow_init_with_backwards_motion: False * /move_base/TebLocalPlannerROS/cmd_angle_instead_rotvel: False * /move_base/TebLocalPlannerROS/complete_global_plan: True * /move_base/TebLocalPlannerROS/costmap_converter_plugin: * /move_base/TebLocalPlannerROS/costmap_converter_rate: 8 * /move_base/TebLocalPlannerROS/costmap_converter_spin_thread: True * /move_base/TebLocalPlannerROS/costmap_obstacles_behind_robot_dist: 0.1 * /move_base/TebLocalPlannerROS/delete_detours_backwards: True * /move_base/TebLocalPlannerROS/dt_hysteresis: 0.05 * /move_base/TebLocalPlannerROS/dt_ref: 0.21 * /move_base/TebLocalPlannerROS/dynamic_obstacle_inflation_dist: 0.1 * /move_base/TebLocalPlannerROS/enable_homotopy_class_planning: True * /move_base/TebLocalPlannerROS/enable_multithreading: False * /move_base/TebLocalPlannerROS/exact_arc_length: True * /move_base/TebLocalPlannerROS/feasibility_check_no_poses: 10 * /move_base/TebLocalPlannerROS/footprint_model: polygon * /move_base/TebLocalPlannerROS/free_goal_vel: True * /move_base/TebLocalPlannerROS/global_plan_overwrite_orientation: True * /move_base/TebLocalPlannerROS/global_plan_prune_distance: 1 * /move_base/TebLocalPlannerROS/global_plan_viapoint_sep: -1 * /move_base/TebLocalPlannerROS/h_signature_prescaler: 0.5 * /move_base/TebLocalPlannerROS/h_signature_threshold: 0.1 * /move_base/TebLocalPlannerROS/include_costmap_obstacles: True * /move_base/TebLocalPlannerROS/include_dynamic_obstacles: True * /move_base/TebLocalPlannerROS/inflation_dist: 0.62 * /move_base/TebLocalPlannerROS/max_global_plan_lookahead_dist: 4.0 * /move_base/TebLocalPlannerROS/max_number_classes: 5 * /move_base/TebLocalPlannerROS/max_ratio_detours_duration_best_duration: 3.0 * /move_base/TebLocalPlannerROS/max_samples: 500 * /move_base/TebLocalPlannerROS/max_vel_theta: 85 * /move_base/TebLocalPlannerROS/max_vel_x: 3 * /move_base/TebLocalPlannerROS/max_vel_x_backwards: 1.2 * /move_base/TebLocalPlannerROS/max_vel_y: 0.288 * /move_base/TebLocalPlannerROS/min_turning_radius: 0.01 * /move_base/TebLocalPlannerROS/no_inner_iterations: -1 * /move_base/TebLocalPlannerROS/no_outer_iterations: -1 * /move_base/TebLocalPlannerROS/obstacle_cost_exponent: -1 * /move_base/TebLocalPlannerROS/obstacle_heading_threshold: 0.45 * /move_base/TebLocalPlannerROS/obstacle_poses_affected: 20 * /move_base/TebLocalPlannerROS/odom_topic: odom * /move_base/TebLocalPlannerROS/optimization_activate: True * /move_base/TebLocalPlannerROS/optimization_verbose: False * /move_base/TebLocalPlannerROS/oscillation_filter_duration: 10 * /move_base/TebLocalPlannerROS/oscillation_omega_eps: 10 * /move_base/TebLocalPlannerROS/oscillation_recovery: False * /move_base/TebLocalPlannerROS/oscillation_recovery_min_duration: 20 * /move_base/TebLocalPlannerROS/oscillation_v_eps: 10 * /move_base/TebLocalPlannerROS/penalty_epsilon: 0.01 * /move_base/TebLocalPlannerROS/publish_feedback: False * /move_base/TebLocalPlannerROS/roadmap_graph_area_length_scale: 1.0 * /move_base/TebLocalPlannerROS/roadmap_graph_area_width: 5 * /move_base/TebLocalPlannerROS/roadmap_graph_no_samples: 15 * /move_base/TebLocalPlannerROS/selection_alternative_time_cost: False * /move_base/TebLocalPlannerROS/selection_cost_hysteresis: 1.0 * /move_base/TebLocalPlannerROS/selection_obst_cost_scale: 1.0 * /move_base/TebLocalPlannerROS/selection_prefer_initial_plan: 0.95 * /move_base/TebLocalPlannerROS/shrink_horizon_backup: True * /move_base/TebLocalPlannerROS/shrink_horizon_min_duration: 3 * /move_base/TebLocalPlannerROS/switching_blocking_period: 0.0 * /move_base/TebLocalPlannerROS/teb_autosize: True * /move_base/TebLocalPlannerROS/type: polygon * /move_base/TebLocalPlannerROS/vertices: [[-0.175, -0.25],... * /move_base/TebLocalPlannerROS/viapoints_all_candidates: True * /move_base/TebLocalPlannerROS/visualize_hc_graph: True * /move_base/TebLocalPlannerROS/visualize_with_time_as_z_axis_scale: False * /move_base/TebLocalPlannerROS/weight_acc_lim_theta: 10 * /move_base/TebLocalPlannerROS/weight_acc_lim_x: 1 * /move_base/TebLocalPlannerROS/weight_adapt_factor: 20 * /move_base/TebLocalPlannerROS/weight_dynamic_obstacle: 10 * /move_base/TebLocalPlannerROS/weight_dynamic_obstacle_inflation: 5 * /move_base/TebLocalPlannerROS/weight_inflation: 50 * /move_base/TebLocalPlannerROS/weight_kinematics_forward_drive: 1000 * /move_base/TebLocalPlannerROS/weight_kinematics_nh: 1000 * /move_base/TebLocalPlannerROS/weight_kinematics_turning_radius: 1000 * /move_base/TebLocalPlannerROS/weight_max_vel_theta: 10 * /move_base/TebLocalPlannerROS/weight_max_vel_x: 1 * /move_base/TebLocalPlannerROS/weight_obstacle: 50 * /move_base/TebLocalPlannerROS/weight_optimaltime: 1000 * /move_base/TebLocalPlannerROS/weight_shortest_path: 1 * /move_base/TebLocalPlannerROS/weight_viapoint: 1 * /move_base/TebLocalPlannerROS/wheelbase: 0.335 * /move_base/TebLocalPlannerROS/xy_goal_tolerance: 0.01 * /move_base/TebLocalPlannerROS/yaw_goal_tolerance: 0.03 * /move_base/base_global_planner: navfn/NavfnROS * /move_base/base_local_planner: teb_local_planner... * /move_base/clearing_rotation_allowed: False * /move_base/controller_frequency: 10.0 * /move_base/controller_patience: 6.0 * /move_base/global_costmap/footprint: [[-0.175, -0.25],... * /move_base/global_costmap/footprint_padding: 0.01 * /move_base/global_costmap/global_frame: map * /move_base/global_costmap/height: 25.0 * /move_base/global_costmap/inflation/cost_scaling_factor: 2.0 * /move_base/global_costmap/inflation/inflation_radius: 0. 1 * /move_base/global_costmap/plugins: [{'name': 'static... * /move_base/global_costmap/publish_frequency: 1.0 * /move_base/global_costmap/resolution: 0.05 * /move_base/global_costmap/robot_base_frame: base_footprint * /move_base/global_costmap/rolling_window: True * /move_base/global_costmap/sensor/laser_scan_sensor/clearing: True * /move_base/global_costmap/sensor/laser_scan_sensor/data_type: LaserScan * /move_base/global_costmap/sensor/laser_scan_sensor/marking: True * /move_base/global_costmap/sensor/laser_scan_sensor/observation_persistence: 0.5 * /move_base/global_costmap/sensor/laser_scan_sensor/sensor_frame: laser_link * /move_base/global_costmap/sensor/laser_scan_sensor/topic: scan * /move_base/global_costmap/sensor/observation_sources: laser_scan_sensor * /move_base/global_costmap/static/map_topic: /map * /move_base/global_costmap/static/subscribe_to_updates: True * /move_base/global_costmap/track_unknown_space: False * /move_base/global_costmap/transform_tolerance: 0.5 * /move_base/global_costmap/update_frequency: 1.0 * /move_base/global_costmap/width: 25.0 * /move_base/local_costmap/footprint: [[-0.175, -0.25],... * /move_base/local_costmap/footprint_padding: 0.01 * /move_base/local_costmap/global_frame: map * /move_base/local_costmap/height: 3.0 * /move_base/local_costmap/inflation/cost_scaling_factor: 6.0 * /move_base/local_costmap/inflation/inflation_radius: 0.1 * /move_base/local_costmap/plugins: [{'name': 'sensor... * /move_base/local_costmap/publish_frequency: 1.0 * /move_base/local_costmap/resolution: 0.05 * /move_base/local_costmap/robot_base_frame: base_footprint * /move_base/local_costmap/rolling_window: True * /move_base/local_costmap/sensor/laser_scan_sensor/clearing: True * /move_base/local_costmap/sensor/laser_scan_sensor/data_type: LaserScan * /move_base/local_costmap/sensor/laser_scan_sensor/marking: True * /move_base/local_costmap/sensor/laser_scan_sensor/sensor_frame: laser_link * /move_base/local_costmap/sensor/laser_scan_sensor/topic: scan * /move_base/local_costmap/sensor/observation_sources: laser_scan_sensor * /move_base/local_costmap/track_unknown_space: False * /move_base/local_costmap/transform_tolerance: 0.5 * /move_base/local_costmap/update_frequency: 1.0 * /move_base/local_costmap/width: 3.0 * /move_base/oscillation_distance: 0.2 * /move_base/oscillation_timeout: 10.0 * /move_base/planner_frequency: 10.0 * /move_base/planner_patience: 5.0 * /move_base/shutdown_costmaps: False * /rf2o_laser_odometry/base_frame_id: base_footprint * /rf2o_laser_odometry/freq: 20.0 * /rf2o_laser_odometry/laser_scan_topic: scan * /rf2o_laser_odometry/odom_frame_id: odom * /rf2o_laser_odometry/odom_topic: odom_rf2o * /rf2o_laser_odometry/publish_tf: False * /rf2o_laser_odometry/verbose: True * /rosdistro: noetic * /rosversion: 1.15.13 NODES / amcl (amcl/amcl) car_controller (racecar/car_controller_new) ekf_se (robot_localization/ekf_localization_node) map_server (map_server/map_server) move_base (move_base/move_base) rf2o_laser_odometry (rf2o_laser_odometry/rf2o_laser_odometry_node) wheel_odom (encoder_driver/encoder_driver_node1) ^C终止 ROS 启动进程... [ INFO] [1764271020.971795831]: ?????????????????????????????? [ INFO] [1764271020.886512045]: Subscribed to map topic. [ INFO] [1764271021.127392896]: Received a 608 X 384 map @ 0.050 m/pix [ INFO] [1764271021.158670011]: Initializing likelihood field model; this can take some time on large maps... [ INFO] [1764271021.265183670]: Done initializing likelihood field model. lslidar_x10_driver_node: /usr/include/boost/thread/pthread/condition_variable_fwd.hpp:81: boost::condition_variable::~condition_variable(): Assertion `!posix::pthread_mutex_destroy(&internal_mutex)' failed. 2025-11-27 19:18:26+0000 [autobahn.twisted.websocket.WebSocketServerFactory] (TCP Port 9090 Closed) 2025-11-27 19:18:26+0000 [-] Stopping factory <autobahn.twisted.websocket.WebSocketServerFactory object at 0xe7ffc75d7c70> 2025-11-27 19:18:26+0000 [-] Main loop terminated. [DEBUG] [1764271016.495434]: init_node, name[/encoder_vel], pid[443] [DEBUG] [1764271016.503376]: binding to 0.0.0.0 0 [DEBUG] [1764271016.507268]: bound to 0.0.0.0 38955 [DEBUG] [1764271016.511287]: ... service URL is rosrpc://192.168.5.100:38955 [DEBUG] [1764271016.514807]: [/encoder_vel/get_loggers]: new Service instance [DEBUG] [1764271016.520463]: ... service URL is rosrpc://192.168.5.100:38955 [DEBUG] [1764271016.523488]: [/encoder_vel/set_logger_level]: new Service instance True ROS_MASTER_URI=http://192.168.5.100:11311 process[map_server-1]: started with pid [496] process[rf2o_laser_odometry-2]: started with pid [497] process[wheel_odom-3]: started with pid [498] process[ekf_se-4]: started with pid [499] process[amcl-5]: started with pid [513] process[move_base-6]: started with pid [522] process[car_controller-7]: started with pid [526] [car_controller-7] killing on exit [move_base-6] killing on exit [amcl-5] killing on exit [ekf_se-4] killing on exit [wheel_odom-3] killing on exit [rf2o_laser_odometry-2] killing on exit [map_server-1] killing on exit shutting down processing monitor... ... shutting down processing monitor complete done WARNING: ignoring defunct <master /> tag ... logging to /root/.ros/log/a199425e-cbc5-11f0-86b4-2c52afb5f6d1/roslaunch-davinci-mini-400.log Checking log directory for disk usage. This may take a while. Press Ctrl-C to interrupt Done checking log file disk usage. Usage is <1GB. started roslaunch server http://192.168.5.100:37043/ SUMMARY ======== PARAMETERS * /encoder_vel/baud_rate: 57600 * /encoder_vel/k: 0.88 * /encoder_vel/serial_port: /dev/encoder * /lslidar_x10_driver_node/angle_disable_max: 0.0 * /lslidar_x10_driver_node/angle_disable_min: 0.0 * /lslidar_x10_driver_node/child_frame_id: laser_link * /lslidar_x10_driver_node/interface_selection: serial * /lslidar_x10_driver_node/lidar_name: M10 * /lslidar_x10_driver_node/max_range: 100.0 * /lslidar_x10_driver_node/min_range: 0 * /lslidar_x10_driver_node/scan_topic: scan * /lslidar_x10_driver_node/serial_port: /dev/laser * /lslidar_x10_driver_node/use_gps_ts: False * /rosbridge_server/websocket_port: 9090 * /rosdistro: noetic * /rosversion: 1.15.13 NODES / base_footprint2base_link (tf/static_transform_publisher) base_link2imu (tf/static_transform_publisher) base_link2laser_link (tf/static_transform_publisher) encoder_vel (encoder_driver/Encoder_vel.py) imu_sonser_spec (serial_imu/serial_imu) lslidar_x10_driver_node (lslidar_x10_driver/lslidar_x10_driver_node) racecar_driver (racecar_driver/racecar_driver_node) rosbridge_server (rosbridge_server/rosbridge_websocket) auto-starting new master process[master]: started with pid [410] ROS_MASTER_URI=http://192.168.5.100:11311 setting /run_id to a199425e-cbc5-11f0-86b4-2c52afb5f6d1 process[rosout-1]: started with pid [420] started core service [/rosout] process[base_footprint2base_link-2]: started with pid [427] process[base_link2laser_link-3]: started with pid [428] process[base_link2imu-4]: started with pid [429] process[lslidar_x10_driver_node-5]: started with pid [434] process[imu_sonser_spec-6]: started with pid [440] process[encoder_vel-7]: started with pid [443] process[racecar_driver-8]: started with pid [449] process[rosbridge_server-9]: started with pid [459] [rosbridge_server-9] killing on exit [racecar_driver-8] killing on exit [encoder_vel-7] killing on exit [imu_sonser_spec-6] killing on exit [lslidar_x10_driver_node-5] killing on exit [base_link2imu-4] killing on exit [base_link2laser_link-3] killing on exit [base_footprint2base_link-2] killing on exit [rosout-1] killing on exit [master] killing on exit shutting down processing monitor... ... shutting down processing monitor complete done Run_car.launch 进程已终止。 amcl_nav.launch 进程已终止。 分析一下有啥问题吗
最新发布
11-28
/* Copyright(c) 2009-2025 Shenzhen TP-LINK Technologies Co.Ltd. * * file poe.c * brief * details * * author Liao Jinlei * version 1.0.0 * date 04Mar25 * * warning * * history \arg 1.0.0, 04Mar25, Liao Jinlei, Create the file. */ #include <stdio.h> #include <stdlib.h> #include <pthread.h> #include <unistd.h> #include <arpa/inet.h> #include <sys/socket.h> #include <netinet/ip.h> #include <netinet/ip_icmp.h> #include <string.h> #include <time.h> #include <errno.h> #include "type_pub.h" #include "utility_debug.h" #include "opLanPort_info.h" #include "unix_sock_msgDef.h" #include "apiPoeMP3924.h" #include "poe_recovery.h" /**************************************************************************************************/ /* DEFINES */ /**************************************************************************************************/ // #define DBG(args...) printf(args...) // #define ERR(args...) printf(args...) #define MAX_THREADS get_poe_last_uport() // 最大线程数限制: 2 #define ICMP_DATA_SIZE 56 #define MAX_ICMP_SIZE 1024 #define TIMEOUT 1000 // 超时时间(毫秒) // @wxh dbg // #define poe_recovery_init_setByWxh_l_array_poe_recovery_cfgs /**************************************************************************************************/ /* TYPES */ /**************************************************************************************************/ /**************************************************************************************************/ /* EXTERN_PROTOTYPES */ /**************************************************************************************************/ /**************************************************************************************************/ /* LOCAL_PROTOTYPES */ /**************************************************************************************************/ // void poe_recovery_task(int *arg); // static int _poe_auto_recovery_config_set(int user_port, const POE_PORTRECOVERYCFG_STRUCT* recovery_cfg); //@wxh 已重构优化,调用此函数处直接调用 ppoe_recovery_set_port_config 函数 // static int _poe_auto_recovery_config_del(int user_port); //@wxh 已重构优化,调用处直接赋值默认参数,并调用 ppoe_recovery_set_port_config /**************************************************************************************************/ /* VARIABLES */ /**************************************************************************************************/ // 静态变量:指定IP地址 // static char* TARGET_IP_1 = "192.168.0.253"; //650-dt // static char* TARGET_IP_2 = "192.168.0.26"; // 线程数组 pthread_t* l_array_poe_recovery_threads = NULL; int* l_array_poe_recovery_ids = NULL; // 存储线程ID POE_PORTRECOVERYCFG_STRUCT* l_array_poe_recovery_cfgs = NULL; static int l_thread_count = 0; // 当前线程数量 static int l_poe_recovery_global_status = POE_RECOVERY_DISABLE_UC; /* 默认Disable */ /**************************************************************************************************/ /* LOCAL_FUNCTIONS */ /**************************************************************************************************/ // 创建原始套接字 static int _create_raw_socket() { int raw_socket = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP); if (raw_socket < 0) { perror("Socket creation failed"); return -1; } return raw_socket; } // 计算校验和 static unsigned short _calculate_checksum(void* b, int len) { unsigned short* buf = b; unsigned int sum = 0; unsigned short result; for (sum = 0; len > 1; len -= 2) sum += *buf++; if (len == 1) sum += *(unsigned char*)buf; sum = (sum >> 16) + (sum & 0xFFFF); sum += (sum >> 16); result = ~sum; return result; } // 发送 ICMP 回显请求 static int _ping_ip(int raw_socket, const char* ip_address, int seq,int user_port) { struct sockaddr_in dest_addr; struct icmp icmp_hdr; char buffer[MAX_ICMP_SIZE]; int sent_bytes; // 设置目标地址 memset(&dest_addr, 0, sizeof(dest_addr)); dest_addr.sin_family = AF_INET; if (inet_pton(AF_INET, ip_address, &dest_addr.sin_addr) <= 0) { perror("Invalid IP address"); return -1; } // 构造 ICMP 数据包 memset(&icmp_hdr, 0, sizeof(icmp_hdr)); icmp_hdr.icmp_type = ICMP_ECHO; icmp_hdr.icmp_code = 0; icmp_hdr.icmp_id = getpid()+user_port*1000; icmp_hdr.icmp_seq = seq; icmp_hdr.icmp_cksum = 0; // 填充数据部分 memset(buffer, 0, MAX_ICMP_SIZE); memcpy(buffer, &icmp_hdr, sizeof(icmp_hdr)); memset(buffer + sizeof(icmp_hdr), 'E', ICMP_DATA_SIZE); icmp_hdr.icmp_cksum = _calculate_checksum(buffer, sizeof(icmp_hdr) + ICMP_DATA_SIZE); memcpy(buffer, &icmp_hdr, sizeof(icmp_hdr)); // 发送 ICMP 数据包 sent_bytes = sendto(raw_socket, buffer, sizeof(icmp_hdr) + ICMP_DATA_SIZE, 0, (struct sockaddr*)&dest_addr, sizeof(dest_addr)); if (sent_bytes < 0) { perror("Sendto failed"); return -1; } return ERR_NO_ERROR; } // 获取 ICMP 回显应答 static int _get_ping_result(int raw_socket, const char* ip_address, int seq, int user_port) { struct sockaddr_in from_addr; struct icmp icmp_hdr; char buffer[MAX_ICMP_SIZE]; int recv_bytes; socklen_t from_len; fd_set readfds; struct timeval timeout; // 设置超时时间 timeout.tv_sec = TIMEOUT / 1000; timeout.tv_usec = (TIMEOUT % 1000) * 1000; int retry = 5; while(retry--) { // 等待 ICMP 回显应答 FD_ZERO(&readfds); FD_SET(raw_socket, &readfds); int activity = select(raw_socket + 1, &readfds, NULL, NULL, &timeout); if ((activity < 0) && (errno != EINTR)) { printf("Select error"); return -1; } if (activity == 0) { printf("Ping request timed out\n"); return -1; } if (FD_ISSET(raw_socket, &readfds)) { from_len = sizeof(from_addr); recv_bytes = recvfrom(raw_socket, buffer, MAX_ICMP_SIZE, 0, (struct sockaddr*)&from_addr, &from_len); if (recv_bytes < 0) { perror("Recvfrom failed"); return -1; } // 解析 ICMP 数据包 memcpy(&icmp_hdr, buffer + sizeof(struct iphdr), sizeof(icmp_hdr)); if (icmp_hdr.icmp_type == ICMP_ECHOREPLY && icmp_hdr.icmp_id == (getpid()+user_port*1000) && icmp_hdr.icmp_seq == seq) // if (icmp_hdr.icmp_type == ICMP_ECHOREPLY && icmp_hdr.icmp_id == (getpid()+user_port*1000)) { printf("[success][PORT %d] Ping reply from %s: icmp_seq=%d\n", user_port,inet_ntoa(from_addr.sin_addr), icmp_hdr.icmp_seq); printf("[success][PORT %d] [actual] icmp_type: %d, icmp_id: %d, icmp_seq: %d\n", user_port,icmp_hdr.icmp_type,icmp_hdr.icmp_id ,icmp_hdr.icmp_seq ); printf("[success][PORT %d] [supose] icmp_type: %d, icmp_id: %d, icmp_seq: %d\n",user_port,ICMP_ECHOREPLY,(getpid()+user_port*1000),seq ); return ERR_NO_ERROR; } else { printf("[failed][PORT %d] Received unexpected ICMP packet\n",user_port); printf("[failed][PORT %d] [actual] icmp_type: %d, icmp_id: %d, icmp_seq: %d\n", user_port,icmp_hdr.icmp_type,icmp_hdr.icmp_id ,icmp_hdr.icmp_seq ); printf("[failed][PORT %d] [supose] icmp_type: %d, icmp_id: %d, icmp_seq: %d\n",user_port,ICMP_ECHOREPLY,(getpid()+user_port*1000),seq ); // return -1; } } } return -1; } static int _poe_recovery_counter_command(int user_port, POE_RECOVERY_COUNTER_CMD cmd) { int rv = ERR_NO_ERROR; if (user_port > get_poe_last_uport() || user_port < get_poe_first_uport() || l_array_poe_recovery_cfgs == NULL) { return ERR_BAD_PARAM; } // RECOVERY_TASK_LOCK(); switch (cmd) { case CLR_FAILURE: l_array_poe_recovery_cfgs[user_port-1].failure = 0; break; case INC_FAILURE: l_array_poe_recovery_cfgs[user_port-1].failure = (l_array_poe_recovery_cfgs[user_port-1].failure++ == POE_RECOVERY_FAILURE_MAX) ? 1 : l_array_poe_recovery_cfgs[user_port-1].failure; break; case INC_RESTART: l_array_poe_recovery_cfgs[user_port-1].restart = (l_array_poe_recovery_cfgs[user_port-1].restart++ == POE_RECOVERY_RESTART_MAX) ? 1 : l_array_poe_recovery_cfgs[user_port-1].restart; break; case INC_TOTAL: l_array_poe_recovery_cfgs[user_port-1].total = (l_array_poe_recovery_cfgs[user_port-1].total++ == POE_RECOVERY_TOTAL_MAX) ? 1 : l_array_poe_recovery_cfgs[user_port-1].total; break; case CLR_FAILURE_RESTART_TOTAL: l_array_poe_recovery_cfgs[user_port-1].failure = 0; l_array_poe_recovery_cfgs[user_port-1].restart = 0; l_array_poe_recovery_cfgs[user_port-1].total = 0; default: rv = ERR_BAD_PARAM; break; } // RECOVERY_TASK_UNLOCK(); return rv; } static int _poe_recovery_validate_port_config(const POE_PORTRECOVERYCFG_STRUCT *poe_port_recovery_cfg, int check_ip) { printf("_poe_recovery_validate_port_config will goto ping recovery %d\n", 5); // @wxh dbg #if 0 if (check_ip && !sw_poe_recovery_ip_validate(poe_port_recovery_cfg->ip)) { return FALSE; } #endif if (poe_port_recovery_cfg->status != POE_RECOVERY_DISABLE_UC && poe_port_recovery_cfg->status != POE_RECOVERY_ENABLE_UC) { printf("[%s] ERR_BAD_PARAM: status.\r\n", __FUNCTION__); return FALSE; } if (poe_port_recovery_cfg->startup < POE_RECOVERY_STARTUP_MIN || poe_port_recovery_cfg->startup > POE_RECOVERY_STARTUP_MAX) { printf("[%s] ERR_BAD_PARAM: startup.\r\n", __FUNCTION__); return FALSE; } if (poe_port_recovery_cfg->interval < POE_RECOVERY_INTERVAL_MIN || poe_port_recovery_cfg->interval > POE_RECOVERY_INTERVAL_MAX) { printf("[%s] ERR_BAD_PARAM: interval.\r\n", __FUNCTION__); return FALSE; } if (poe_port_recovery_cfg->retry < POE_RECOVERY_RETRY_MIN || poe_port_recovery_cfg->retry > POE_RECOVERY_RETRY_MAX) { printf("[%s] ERR_BAD_PARAM: retry.\r\n", __FUNCTION__); return FALSE; } if (poe_port_recovery_cfg->reboot < POE_RECOVERY_BREAK_MIN || poe_port_recovery_cfg->reboot > POE_RECOVERY_BREAK_MAX) { printf("[%s] ERR_BAD_PARAM: reboot.\r\n", __FUNCTION__); return FALSE; } return TRUE; } static int _poe_recovery_get_port_config(int user_port, POE_PORTRECOVERYCFG_STRUCT *poe_port_recovery_cfg) { if (user_port < get_poe_first_uport() || user_port > get_poe_last_uport() || NULL == poe_port_recovery_cfg) { return ERR_BAD_PARAM; } // RECOVERY_TASK_LOCK(); memcpy(poe_port_recovery_cfg, &l_array_poe_recovery_cfgs[user_port-1], sizeof(POE_PORTRECOVERYCFG_STRUCT)); // RECOVERY_TASK_UNLOCK(); return ERR_NO_ERROR; } /* set to local variable */ static int _poe_recovery_set_port_config(int user_port, const POE_PORTRECOVERYCFG_STRUCT *poe_port_recovery_cfg) { printf("_poe_recovery_set_port_config will goto ping recovery %d\n", 6); // @wxh dbg if (NULL == poe_port_recovery_cfg || l_array_poe_recovery_cfgs == NULL) { return ERR_BAD_PARAM; } // RECOVERY_TASK_LOCK(); memset(l_array_poe_recovery_cfgs[user_port-1].ip, 0, 16); snprintf(l_array_poe_recovery_cfgs[user_port-1].ip, 16, "%s", poe_port_recovery_cfg->ip); l_array_poe_recovery_cfgs[user_port-1].status = poe_port_recovery_cfg->status; l_array_poe_recovery_cfgs[user_port-1].startup = poe_port_recovery_cfg->startup; l_array_poe_recovery_cfgs[user_port-1].interval = poe_port_recovery_cfg->interval; l_array_poe_recovery_cfgs[user_port-1].retry = poe_port_recovery_cfg->retry; l_array_poe_recovery_cfgs[user_port-1].reboot = poe_port_recovery_cfg->reboot; // RECOVERY_TASK_UNLOCK(); return ERR_NO_ERROR; } static int _poe_recovery_get_global_status(int *status) { // RECOVERY_TASK_LOCK(); *status = l_poe_recovery_global_status; // RECOVERY_TASK_UNLOCK(); return ERR_NO_ERROR; } /* set to local variable */ static int _poe_recovery_set_global_status(int status) { // RECOVERY_TASK_LOCK(); l_poe_recovery_global_status = status; // RECOVERY_TASK_UNLOCK(); return ERR_NO_ERROR; } /*! *\Function: * _poe_port_status_set *\Description: * Port PoE status set api for PoE Auto Recovery *\Input: user_port - user port, start from 1 enable - status <POE_ENABLE_UC | POE_DISABLE_UC> *\Output: * n/a *\Return: Port PoE status set result *\Note: */ static int _poe_port_status_set(unsigned int user_port, int enable) { // POE_PORTCFG_STRUCT poe_port_config = {0}; int rv = ERR_NO_ERROR; int power_dis_flag = 0; int time_seg_dis_flag = 0; /* Check params */ if (user_port > get_poe_last_uport() || user_port < get_poe_first_uport()) { printf("[%s] PoE function is unavailable on user_port %d.\r\n", __FUNCTION__, user_port); return ERR_BAD_PARAM; } if (POE_DISABLE != enable && POE_ENABLE != enable) { return ERR_BAD_PARAM; } ad_poe_port_flag_get(user_port, POE_MANAGE_POWER_DIS, &power_dis_flag); ad_poe_port_flag_get(user_port, POE_MANAGE_TIMESEG_DIS, &time_seg_dis_flag); if (POE_RELEASE == power_dis_flag && POE_RELEASE == time_seg_dis_flag) { /* Update adapter config */ rv = ad_poe_set_port_state(user_port, enable); if (ERR_NO_ERROR != rv) { return rv; } } /* Update poe port flag */ return ad_poe_port_flag_set(user_port, POE_MANAGE_RECOVERY_DIS, (POE_DISABLE == enable) ? POE_OCCUPY : POE_RELEASE); } // 线程task static void* poe_recovery_task(void* arg) { POE_PORTRECOVERYCFG_STRUCT poe_port_recovery_cfg; int fail_cnt = 0; int global_status; int user_port = *(int*)arg; int seq = 0; if (user_port > get_poe_last_uport() || user_port < get_poe_first_uport()) { return NULL; } /* PoE Auto Recovery Task主循环 */ while (1) { global_status = POE_RECOVERY_DISABLE_UC; (void)_poe_recovery_get_global_status(&global_status); _poe_recovery_get_port_config(user_port, &poe_port_recovery_cfg); if (POE_RECOVERY_ENABLE_UC != poe_port_recovery_cfg.status || POE_RECOVERY_ENABLE_UC != global_status) { printf("[Port %d] PoE Auto Recovery disabled!\r\n", user_port); sleep(1); continue; } int raw_socket = _create_raw_socket(); if (raw_socket < 0) { printf("Thread %d: Failed to create socket\n", user_port); return NULL; } printf("Thread %d: raw_socket is %d \n", user_port,raw_socket); printf("[Port %d] Startup: %d secnonds...\r\n", user_port, poe_port_recovery_cfg.startup); sleep(poe_port_recovery_cfg.startup); /* PoE Auto Recovery工作循环,检测到Enable才进入 */ while (1) { global_status = POE_RECOVERY_DISABLE_UC; (void)_poe_recovery_get_global_status(&global_status); _poe_recovery_get_port_config(user_port, &poe_port_recovery_cfg); if (POE_RECOVERY_ENABLE_UC != poe_port_recovery_cfg.status || POE_RECOVERY_ENABLE_UC != global_status) { printf("[Port %d] PoE Auto Recovery disabled!\r\n", user_port); break; } //ping target ip if (_ping_ip(raw_socket, poe_port_recovery_cfg.ip, seq, user_port) < 0) { printf("[Port %d] Failed to send ping to %s, try again.\r\n", user_port, poe_port_recovery_cfg.ip); sleep(3); continue; } _poe_recovery_counter_command(user_port, INC_TOTAL); if (_get_ping_result(raw_socket, poe_port_recovery_cfg.ip, seq, user_port) < 0) { printf("Thread %d: Ping failed for %s\r\n", user_port, poe_port_recovery_cfg.ip); fail_cnt++; _poe_recovery_counter_command(user_port, INC_FAILURE); printf("[Port %d] Ping FAIL: total=%d, failure=%d, fail_cnt=%d\r\n", user_port, poe_port_recovery_cfg.total+1, poe_port_recovery_cfg.failure+1, fail_cnt); } else { printf("Thread %d: Ping success for %s\n", user_port, poe_port_recovery_cfg.ip); fail_cnt=0; _poe_recovery_counter_command(user_port, CLR_FAILURE); printf("[Port %d] Ping SUCCESS: total=%d, failure=%d, fail_cnt=%d.\r\n", user_port, poe_port_recovery_cfg.total+1, poe_port_recovery_cfg.failure, fail_cnt); } seq++; if (fail_cnt >= poe_port_recovery_cfg.retry) { printf("[Port %d] Ping: fail_cnt reaches the limit(%d), now reboot pd.(Reboot Time: %d seconds)\r\n", user_port, poe_port_recovery_cfg.retry, poe_port_recovery_cfg.reboot); fail_cnt = 0; _poe_recovery_counter_command(user_port, CLR_FAILURE); _poe_recovery_counter_command(user_port, INC_RESTART); _poe_port_status_set(user_port, POE_DISABLE); // ad_poe_set_port_state(user_port, POE_DISABLE); sleep(poe_port_recovery_cfg.reboot); _poe_port_status_set(user_port, POE_ENABLE); // ad_poe_set_port_state(user_port, POE_ENABLE); break; } printf("[Port %d] Ping: wait %d seconds for next ping...\r\n\n", user_port, poe_port_recovery_cfg.interval); sleep(poe_port_recovery_cfg.interval - POE_RECOVERY_PING_TIMEOUT); } close(raw_socket); } } // 创建线程 static int poe_recovery_task_create_thread(int user_port) { // printf("poe_recovery_task_create_thread will goto ping recovery %d \n", 7); // @wxh dbg //@wxh 勘误修改 l_thread_count代表创建的线程数 应该小于等于2,这里 >= 应改为 > 符号 // if (l_thread_count >= MAX_THREADS) { if (l_thread_count > MAX_THREADS) { printf("Error: Maximum number of l_array_poe_recovery_threads reached (%d)\n", MAX_THREADS); return -1; } printf("poe_recovery_task_create_thread thread ID:%d \n",user_port); if (user_port < get_poe_first_uport() || user_port > get_poe_last_uport()) { printf("Error: Invalid thread ID \n"); return -1; } if (l_array_poe_recovery_ids[user_port-1] != POE_RECOVERY_THREAD_NOT_USE) { printf("Error: Thread ID %d is already in use\n", user_port); return -1; } int* arg = malloc(sizeof(int)); if (!arg) { perror("Memory allocation failed"); return -1; } *arg = user_port; if (pthread_create(&l_array_poe_recovery_threads[user_port-1], NULL, poe_recovery_task, arg) != 0) { perror("Failed to create thread"); free(arg); return -1; } l_array_poe_recovery_ids[user_port-1] = POE_RECOVERY_THREAD_IN_USE; // 标记线程ID为已使用 _poe_recovery_counter_command(user_port, CLR_FAILURE_RESTART_TOTAL); l_thread_count++; //todo // stats[user_port] = (PingStats){0, 0, 0}; // 初始化统计信息 printf("Thread for user_port %d created successfully\n", user_port); return ERR_NO_ERROR; } // 关闭线程 static int poe_recovery_task_destroy_thread(int user_port) { // @wxh 勘误修改 这里的 >= 会导致取消线程2时报错,导致线程2无法被取消,应该改为 > // if (user_port < 0 || user_port >= MAX_THREADS) { if (user_port <0 || user_port > MAX_THREADS) { printf("Error: Invalid thread ID\n"); return -1; } if (l_array_poe_recovery_ids[user_port-1] == POE_RECOVERY_THREAD_NOT_USE) { printf("Error: Thread ID %d does not exist\n", user_port); return -1; } if (pthread_cancel(l_array_poe_recovery_threads[user_port-1]) != 0) { perror("Failed to cancel thread"); return -1; } pthread_join(l_array_poe_recovery_threads[user_port-1], NULL); l_array_poe_recovery_ids[user_port-1] = POE_RECOVERY_THREAD_NOT_USE; // 标记线程ID为未使用 _poe_recovery_counter_command(user_port, CLR_FAILURE_RESTART_TOTAL); l_thread_count--; printf("Thread %d canceled successfully\n", user_port); return ERR_NO_ERROR; } /* // 清理所有线程 static void poe_recovery_task_cleanup_threads() { int i; for (i = get_poe_first_uport(); i <= get_poe_last_uport(); i++) { if (l_array_poe_recovery_ids[i-1] != POE_RECOVERY_THREAD_NOT_USE) { pthread_cancel(l_array_poe_recovery_threads[i-1]); pthread_join(l_array_poe_recovery_threads[i-1], NULL); } } } */ /**************************************************************************************************/ /* PUBLIC_FUNCTIONS */ /**************************************************************************************************/ //set port config to local variable int poe_recovery_set_port_config( int user_port, const POE_PORTRECOVERYCFG_STRUCT *poe_port_recovery_cfg, int check_ip) { int rv = 0; int global_status; // POE_PORTCFG_STRUCT poe_port_cfg; POE_PORTRECOVERYCFG_STRUCT poe_port_recovery_cfg_old; printf("[%s] enter on port %d.\r\n", __FUNCTION__, user_port); /* check param legality */ if (user_port < get_poe_first_uport() || user_port > get_poe_last_uport() || NULL == poe_port_recovery_cfg) { printf("[%s][port %d] ERR_BAD_PARAM: user_port.\r\n", __FUNCTION__, user_port); return ERR_BAD_PARAM; } /* check poe config */ // sw_poe_get_port_config(user_port, &poe_port_cfg); _poe_recovery_get_port_config(user_port, &poe_port_recovery_cfg_old); printf("[%s] done _poe_recovery_get_port_config on port %d.\r\n", __FUNCTION__, user_port); /* todo:when port not enable poe,shoule return. if (poe_port_recovery_cfg_old.status == POE_RECOVERY_DISABLE_UC && poe_port_recovery_cfg->status == POE_RECOVERY_ENABLE_UC && poe_port_cfg.status == POE_DISABLE) { // sprintf(buff, "port %d", user_port); // swPoeAddLogSinglePara(LOG_POE_RECOVERY_CONFIG_SET_FAIL, (ULONG)buff); return ERR_POE_RECOVERY_POE_DISABLED; } */ /* validate configuration */ if (!_poe_recovery_validate_port_config(poe_port_recovery_cfg, check_ip)) { printf("[%s][port %d] ERR_BAD_PARAM: user_port.\r\n", __FUNCTION__, user_port); return ERR_BAD_PARAM; } rv = _poe_recovery_set_port_config(user_port, poe_port_recovery_cfg); //更新参数到了 l_array_poe_recovery_cfgs if (ERR_NO_ERROR != rv) { printf("[%s][port %d] _poe_recovery_set_port_config ERROR.\r\n", __FUNCTION__, user_port); return rv; } /* create/destroy poe recovery task */ /* 全局enable的情况下,端口enable/disable触发task创建/销毁 */ /* 全局disable的情况下,端口enable/disable只改变参数,后续全局enable/disable时再创建/销毁线程 */ rv = _poe_recovery_get_global_status(&global_status); if (rv != ERR_NO_ERROR) { return rv; } /* 未更改之前的逻辑,对端口的 status 变化有响应,对端口的其他5个参数变化没有相应 */ // if (poe_port_recovery_cfg_old.status != poe_port_recovery_cfg->status && POE_RECOVERY_ENABLE_UC == global_status) // { // printf("poe_port_recovery_cfg_old.status = %u\n", poe_port_recovery_cfg_old.status); //@wxh dbg // printf("poe_port_recovery_cfg->status = %u\n", poe_port_recovery_cfg->status); //@wxh dbg // printf("POE_RECOVERY_ENABLE_UC = %d\n", POE_RECOVERY_ENABLE_UC); //@wxh dbg // printf("global_status = %d\n", global_status); //@wxh dbg // /* enable -> disable */ // if (poe_port_recovery_cfg_old.status == POE_RECOVERY_ENABLE_UC) // { // rv = poe_recovery_task_destroy_thread(user_port); // if (ERR_NO_ERROR != rv) // { // return rv; // } // } // /* disable -> enable */ // else // { // rv = poe_recovery_task_create_thread(user_port); // if (ERR_NO_ERROR != rv) // { // printf("@@@@@ poe_recovery_task_create_thread failure\n"); // return rv; // } // printf("@@@@@ poe_recovery_task_create_thread sucess\n"); // } // } if (POE_RECOVERY_ENABLE_UC == global_status) { printf("[%s][port %d] POE_RECOVERY_ENABLE_UC == global_status\r\n", __FUNCTION__, user_port); printf("[%s][port %d] poe_port_recovery_cfg_old.status = %d \r\n", __FUNCTION__, user_port,poe_port_recovery_cfg_old.status); printf("[%s][port %d] poe_port_recovery_cfg->status = %d \r\n", __FUNCTION__, user_port,poe_port_recovery_cfg->status); if (poe_port_recovery_cfg_old.status != poe_port_recovery_cfg->status) { // printf("poe_port_recovery_cfg_old.status = %u\n", poe_port_recovery_cfg_old.status); //@wxh dbg // printf("poe_port_recovery_cfg->status = %u\n", poe_port_recovery_cfg->status); //@wxh dbg // printf("POE_RECOVERY_ENABLE_UC = %d\n", POE_RECOVERY_ENABLE_UC); //@wxh dbg // printf("global_status = %d\n", global_status); //@wxh dbg /* enable -> disable */ if (poe_port_recovery_cfg_old.status == POE_RECOVERY_ENABLE_UC) { printf("----->---- [%s] /* disable -> enable */\n", __FUNCTION__); //@wxh dbg rv = poe_recovery_task_destroy_thread(user_port); if (ERR_NO_ERROR != rv) { return rv; } } /* disable -> enable */ else { printf("----->---- [%s] /* disable -> enable */\n", __FUNCTION__); //@wxh dbg rv = poe_recovery_task_create_thread(user_port); if (ERR_NO_ERROR != rv) { printf("----->---- poe_recovery_task_create_thread failure\n"); return rv; } printf("----->---- poe_recovery_task_create_thread sucess\n"); } } /* @wxh 新旧的端口 status 都为 POE_RECOVERY_ENABLE_UC 时,改变ip、startup、interval、retry、reboot 5个参数时 需要销毁线程,并且重新创建线程来使这些更新的参数生效。 */ else { /* @wxh 当5个参数中的任意一个参数发生变化时,销毁线程,重新创建线程来使这些更新的参数生效 */ printf("[%s][port %d] goto else\r\n", __FUNCTION__, user_port); if (POE_RECOVERY_ENABLE_UC == poe_port_recovery_cfg_old.status) { if (0 != strcmp(poe_port_recovery_cfg_old.ip, poe_port_recovery_cfg->ip) || poe_port_recovery_cfg_old.startup != poe_port_recovery_cfg->startup || poe_port_recovery_cfg_old.interval != poe_port_recovery_cfg->interval || poe_port_recovery_cfg_old.retry != poe_port_recovery_cfg->retry || poe_port_recovery_cfg_old.reboot != poe_port_recovery_cfg->reboot) { printf("---->---- 除status的5个参数(ip startup interval retry reboot )发生变化,销毁线程,重新创建线程\n"); printf("---->---->---- old param poe_port_recovery_cfg_old: status:%d ip:%s interval:%d startup:%d retry:%d reboot:%d\n", poe_port_recovery_cfg_old.status, poe_port_recovery_cfg_old.ip, poe_port_recovery_cfg_old.interval, poe_port_recovery_cfg_old.startup, poe_port_recovery_cfg_old.retry, poe_port_recovery_cfg_old.reboot); printf("---->---->---- new param poe_port_recovery_cfg: status:%d ip:%s interval:%d startup:%d retry:%d reboot:%d\n", poe_port_recovery_cfg->status, poe_port_recovery_cfg->ip, poe_port_recovery_cfg->interval, poe_port_recovery_cfg->startup, poe_port_recovery_cfg->retry, poe_port_recovery_cfg->reboot); rv |= poe_recovery_task_destroy_thread(user_port); if (ERR_NO_ERROR != rv) { printf("---->---->---- poe_recovery_task_destroy_thread failure\n"); } printf("---->---->---- poe_recovery_task_create_thread sucess\n"); rv |= poe_recovery_task_create_thread(user_port); if (ERR_NO_ERROR != rv) { printf("---->---->---- poe_recovery_task_create_thread failure\n"); } printf("---->---->---- poe_recovery_task_create_thread sucess\n"); } } } } else { printf("---->---- [%s] poe recovery set port but l_poe_recovery_global_status is POE_RECOVERY_DISABLE_UC\n", __FUNCTION__); printf("---->---- in poe_port_recovery_cfg: status:%d ip:%s interval:%d startup:%d retry:%d reboot:%d\n", poe_port_recovery_cfg->status, poe_port_recovery_cfg->ip, poe_port_recovery_cfg->interval, poe_port_recovery_cfg->startup, poe_port_recovery_cfg->retry, poe_port_recovery_cfg->reboot); } //@wxh 如果 port recovery status 是enable状态,此时上层api 将其中的ip 、interval、startup 等值改变了如何处理? printf("[%s][port %d] end.\r\n", __FUNCTION__, user_port); return ERR_NO_ERROR; } int poe_auto_recovery_global_set(int status) { int user_port, rv, global_status; POE_PORTRECOVERYCFG_STRUCT poe_port_recovery_cfg; if (POE_RECOVERY_DISABLE_UC != status && POE_RECOVERY_ENABLE_UC != status) { return ERR_BAD_PARAM; } if (0 == get_include_poe_auto_recovery()) { printf("[%s] not support auto recovery\n", __FUNCTION__); return ERR_NO_ERROR; } rv = _poe_recovery_get_global_status(&global_status); if (rv != ERR_NO_ERROR) { return rv; } if (status != global_status) { /* update 全局变量 l_poe_recovery_global_status */ _poe_recovery_set_global_status(status); /* enable -> disable */ if (POE_RECOVERY_DISABLE_UC == status) { printf("####**&&** in [%s] /* enable -> disable */\n", __FUNCTION__); for (user_port = get_poe_first_uport(); user_port <= get_poe_last_uport(); user_port++) { rv = poe_recovery_task_destroy_thread(user_port); if (ERR_NO_ERROR != rv) { return rv; } } } /* disable -> enable */ else { printf("####**&&** in [%s] /* disable -> enable */\n", __FUNCTION__); for (user_port = get_poe_first_uport(); user_port <= get_poe_last_uport(); user_port++) { /* Check poe recovery config */ _poe_recovery_get_port_config(user_port, &poe_port_recovery_cfg); printf("####**&&** in [%s] _poe_recovery_get_port_config, result:\n", __FUNCTION__); printf("[port %d] status:%d ip:%s interval:%d startup:%d retry:%d reboot:%d\n", poe_port_recovery_cfg.port_no, poe_port_recovery_cfg.status, poe_port_recovery_cfg.ip, poe_port_recovery_cfg.interval, poe_port_recovery_cfg.startup, poe_port_recovery_cfg.retry, poe_port_recovery_cfg.reboot); if (POE_RECOVERY_ENABLE_UC == poe_port_recovery_cfg.status) { rv = poe_recovery_task_create_thread(user_port); if (ERR_NO_ERROR != rv) { printf("####**&&** poe_recovery_task_create_thread failure\n"); return rv; } printf("####**&&** poe_recovery_task_create_thread sucess\n"); } else { printf("####**&&** poe_port_recovery_cfg.status != POE_RECOVERY_ENABLE_UC\n"); printf("####**&&** poe_port_recovery_cfg.status = %d\n", poe_port_recovery_cfg.status); } } } } printf("[%s] Recovery status changed to %d \n", __FUNCTION__, status); return ERR_NO_ERROR; } int poe_auto_recovery_global_get(int* status) { if( NULL == status ) { return ERR_BAD_PARAM; } if (0 == get_include_poe_auto_recovery()) { printf("[%s] not support auto recovery\n", __FUNCTION__); return ERR_NO_ERROR; } _poe_recovery_get_global_status(status); // printf("[%s] get Recovery status: %d \n", __FUNCTION__, *status); return ERR_NO_ERROR; } //once set one port int poe_auto_recovery_config_set(const POE_OUT_MSG *in_info) { POE_PORTRECOVERYCFG_STRUCT* port_cfg = (POE_PORTRECOVERYCFG_STRUCT*)in_info->data.poe_recovery_port_cfg; POE_PORTRECOVERYCFG_STRUCT recovery_cfg = {0}; int user_port = port_cfg->port_no; int rv = 0; if (0 == get_include_poe_auto_recovery()) { printf("[%s] not support auto recovery\n", __FUNCTION__); return ERR_NO_ERROR; } if (user_port < get_poe_first_uport() || user_port > get_poe_last_uport()) { printf("Input port_id:%d is invalid\n", user_port); return -1; } printf("####ppoe_auto_recovery_config_set in [%s] port:%d\n status:%d ip:%s\n interval:%d\n startup:%d\n retry:%d\n reboot:%d\n failure:%d\n restart:%d\n total:%d\n",__FUNCTION__, port_cfg->port_no, port_cfg->status,port_cfg->ip,port_cfg->interval,port_cfg->startup,port_cfg->retry,port_cfg->reboot,port_cfg->failure,port_cfg->restart,port_cfg->total); recovery_cfg.status = port_cfg->status; // POE_RECOVERY_STATUS_UC status; /* PoE Recovery使能 */ snprintf(recovery_cfg.ip, 16, "%s", port_cfg->ip); //char ip[IP_STR_LEN]; /* Ping IP Address */ recovery_cfg.startup = port_cfg->startup; // int startup; /* Startip Delay (seconds) */ recovery_cfg.interval = port_cfg->interval; // int interval; /* Interval (seconds) */ recovery_cfg.retry = port_cfg->retry; // int retry; /* Failure Threshold */ recovery_cfg.reboot = port_cfg->reboot; // int reboot; /* Break Time (seconds)*/ recovery_cfg.failure = port_cfg->failure; // int failure; /* Failures */ recovery_cfg.restart = port_cfg->restart; // int restart; /* Restarts */ recovery_cfg.total = port_cfg->total; // int total; /* Total */ rv = poe_recovery_set_port_config(user_port, &recovery_cfg, TRUE); if (rv != ERR_NO_ERROR) printf("[%s]Set auto recovery port%d failed\n", __FUNCTION__, user_port); return ERR_NO_ERROR; } //@wxh 已重构优化 //once set one port int poe_auto_recovery_config_del(const POE_OUT_MSG *in_info) { POE_PORTRECOVERYCFG_STRUCT* port_cfg = (POE_PORTRECOVERYCFG_STRUCT*)in_info->data.poe_recovery_port_cfg; int user_port = port_cfg->port_no; int rv = 0; POE_PORTRECOVERYCFG_STRUCT recovery_cfg = {0}; if (0 == get_include_poe_auto_recovery()) { printf("[%s] not support auto recovery\n", __FUNCTION__); return ERR_NO_ERROR; } if (user_port < get_poe_first_uport() || user_port > get_poe_last_uport()) { printf("Input port_id:%d is invalid\n", user_port); return -1; } /* 设置为默认参数 */ recovery_cfg.startup = POE_RECOVERY_STARTUP; recovery_cfg.interval = POE_RECOVERY_INTERVAL; recovery_cfg.retry = POE_RECOVERY_RETRY; recovery_cfg.reboot = POE_RECOVERY_REBOOT; recovery_cfg.status = POE_RECOVERY_DISABLE_UC; rv = poe_recovery_set_port_config(user_port, &recovery_cfg, FALSE); if (rv != ERR_NO_ERROR) printf("[%s]Del auto recovery port%d failed\n", __FUNCTION__, user_port); return rv; } //@wxh 已重构优化 int poe_auto_recovery_status_get(POE_OUT_MSG *out_info) { POE_PORTRECOVERYCFG_STRUCT recovery_cfg = {0}; // POE_PORTRECOVERYCFG_STRUCT* cur_out_port_cfg = out_info->data.poe_recovery_port_cfg; int user_port = 0; if (0 == get_include_poe_auto_recovery()) { printf("[%s] not support auto recovery\n", __FUNCTION__); return ERR_NO_ERROR; } for (user_port = get_poe_first_uport(); user_port <= get_poe_last_uport(); user_port++) { _poe_recovery_get_port_config(user_port, &recovery_cfg); out_info->data.poe_recovery_port_cfg[user_port - 1].port_no = user_port; /* 端口号 */ out_info->data.poe_recovery_port_cfg[user_port - 1].status = recovery_cfg.status; /* PoE Recovery使能 */ // strcpy(out_info->data.poe_recovery_port_cfg[user_port - 1].ip, recovery_cfg.ip); // char ip[IP_STR_LEN]; /* Ping IP Address */ // strcpy(out_info->data.poe_recovery_port_cfg[user_port - 1].ip, "192.168.0.253"); // char ip[IP_STR_LEN]; /* Ping IP Address */ 使用strcpy不安全,应该用snprintf snprintf(out_info->data.poe_recovery_port_cfg[user_port - 1].ip, 16, "%s", recovery_cfg.ip); //char ip[IP_STR_LEN]; /* Ping IP Address */ out_info->data.poe_recovery_port_cfg[user_port - 1].startup = recovery_cfg.startup; /* Startip Delay (seconds) */ out_info->data.poe_recovery_port_cfg[user_port - 1].interval = recovery_cfg.interval; /* Interval (seconds) */ out_info->data.poe_recovery_port_cfg[user_port - 1].retry = recovery_cfg.retry; /* Failure Threshold */ out_info->data.poe_recovery_port_cfg[user_port - 1].reboot = recovery_cfg.reboot; /* Break Time (seconds)*/ out_info->data.poe_recovery_port_cfg[user_port - 1].failure = recovery_cfg.failure; /* Failures */ out_info->data.poe_recovery_port_cfg[user_port - 1].restart = recovery_cfg.restart; /* Restarts */ out_info->data.poe_recovery_port_cfg[user_port - 1].total = recovery_cfg.total; /* Total */ } return ERR_NO_ERROR; } int poe_recovery_init(void) { printf("goto poe_recovery_init\n"); //@wxh dbg // int user_port = 0; int user_port = 1; //@wxh 根据apiPoeMP3924.c user_port - user_port, start from 1 // POE_PORTRECOVERYCFG_STRUCT recovery_cfg = {0}; // int status = -1; // int rv = 0; for (user_port = get_poe_first_uport(); user_port <= get_poe_last_uport(); user_port++) { /* init recovery flag */ ad_poe_port_flag_set(user_port, POE_MANAGE_RECOVERY_DIS, POE_RELEASE); } if (0 == get_include_poe_auto_recovery()) { return ERR_NO_ERROR; } //todo ? /* poe auto recoevry need to load ping module first */ // sw_ping_init(); l_array_poe_recovery_threads = (pthread_t *)malloc(sizeof(pthread_t)*get_poe_last_uport()); l_array_poe_recovery_ids = (int *)malloc(sizeof(int)*get_poe_last_uport()); l_array_poe_recovery_cfgs = (POE_PORTRECOVERYCFG_STRUCT *)malloc(sizeof(POE_PORTRECOVERYCFG_STRUCT)*get_poe_last_uport()); memset(l_array_poe_recovery_cfgs, 0, sizeof(POE_PORTRECOVERYCFG_STRUCT) * get_poe_last_uport()); // poe_recovery_id = (pal_thread_t *)POE_ALLOC(sizeof(pal_thread_t)*get_poe_last_uport()); for (user_port = get_poe_first_uport(); user_port <= get_poe_last_uport(); user_port++) { /* init thread id */ // printf("l_array_poe_recovery_ids[%d] = POE_RECOVERY_THREAD_NOT_USE; \n",user_port-1); l_array_poe_recovery_ids[user_port-1] = POE_RECOVERY_THREAD_NOT_USE; } printf("Start to load and set userconfig for auto recovery.\n"); printf("in swPoeOut.c sw_poeOut_init load flash data and set auto recovery\n"); return ERR_NO_ERROR; } /**************************************************************************************************/ /* GLOBAL_FUNCTIONS */ /**************************************************************************************************/ 画出一个流程图,专业的解释我这段代码里面的ping检测功能
10-30
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值