A Word on TIME_WAIT and CLOSE_WAIT

本文探讨了在网络编程中常见的TIME_WAIT状态及其解决方案, 对于如何避免和处理TIME_WAIT状态进行了深入分析。
#include “FreeRTOS.h” #include “task.h” #include “main.h” #include “cmsis_os.h” #include “usart.h” #include “u_microros.h” #include “canopen_app.h” #include <rcl/rcl.h> #include <rclc/rclc.h> #include <rclc/executor.h> #include <rcl/error_handling.h> #include <uxr/client/transport.h> #include <rmw_microxrcedds_c/config.h> #include <rmw_microros/rmw_microros.h> #include <std_msgs/msg/string.h> #include <std_msgs/msg/int32.h> #include <std_msgs/msg/int32_multi_array.h> #include <rcl/error_handling.h> #include “example_interfaces/srv/add_two_ints.h” #include <stdio.h> #include <unistd.h> #include <rcl/subscription.h> bool cubemx_transport_open(struct uxrCustomTransport *transport); bool cubemx_transport_close(struct uxrCustomTransport *transport); size_t cubemx_transport_write(struct uxrCustomTransport *transport, const uint8_t *buf, size_t len, uint8_t *err); size_t cubemx_transport_read(struct uxrCustomTransport *transport, uint8_t *buf, size_t len, int timeout, uint8_t *err); void* microros_allocate(size_t size, void *state); void microros_deallocate(void *pointer, void state); void microros_reallocate(void *pointer, size_t size, void state); void microros_zero_allocate(size_t number_of_elements, size_t size_of_element, void *state); #define RCCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){printf(“Failed status on line %d: %d. Aborting.\n”,LINE,(int)temp_rc);}} #define RCSOFTCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){printf(“Failed status on line %d: %d. Continuing.\n”,LINE,(int)temp_rc);}} rcl_allocator_t allocator; rclc_support_t support; rcl_node_t node; rclc_executor_t executor; void microros_init() { rmw_uros_set_custom_transport( true, (void*) &huart2, cubemx_transport_open, cubemx_transport_close, cubemx_transport_write, cubemx_transport_read); rcl_allocator_t freeRTOS_allocator = rcutils_get_zero_initialized_allocator(); freeRTOS_allocator.allocate = microros_allocate; freeRTOS_allocator.deallocate = microros_deallocate; freeRTOS_allocator.reallocate = microros_reallocate; freeRTOS_allocator.zero_allocate = microros_zero_allocate; if (!rcutils_set_default_allocator(&freeRTOS_allocator)) { printf(“Error on default allocators (line %d)\n”, LINE); } allocator = rcl_get_default_allocator(); //create init_options rclc_support_init(&support, 0, NULL, &allocator); } attribute((used)) void service_callback(const void *req, void *res) { example_interfaces__srv__AddTwoInts_Request req_in = (example_interfaces__srv__AddTwoInts_Request) req; example_interfaces__srv__AddTwoInts_Response res_in = (example_interfaces__srv__AddTwoInts_Response) res; printf(“Service request value: %d + %d.\n”, (int) req_in->a, (int) req_in->b); res_in->sum = req_in->a + req_in->b; } void callback_led_control(const void *msgin) { const std_msgs__msg__Int32 msg = (const std_msgs__msg__Int32) msgin; if (msg->data == 0) { // control_word = 0x06; // sendPDOevent(My_Data); HAL_GPIO_WritePin(LED0_GPIO_Port, LED0_Pin, GPIO_PIN_SET); } else if (msg->data == 1) { // control_word = 0x0f; // sendPDOevent(My_Data); HAL_GPIO_WritePin(LED0_GPIO_Port, LED0_Pin, GPIO_PIN_RESET); } } void callback_canopen_start(const void *msgin) { const std_msgs__msg__Int32 msg = (const std_msgs__msg__Int32) msgin; if ((msg->data >= 1) ||(msg->data <= 2)) { if (SDO_Config_slave(msg->data)) { return; } check_and_start_node(My_Data, msg->data); uint32_t SendData = 0x3; writeNetworkDict(My_Data, msg->data, 0x6060, 0x00, 0x01, uint8, &SendData, 0); //模式 MyFun_Wait_SDO(msg->data); SendData = 0xf; writeNetworkDict(My_Data, msg->data, 0x6040, 0x00, 0x02, uint16, &SendData, 0); //控制字 MyFun_Wait_SDO(msg->data); SendData = 0x010000; writeNetworkDict(My_Data, msg->data, 0x60ff, 0x00, 0x04, int32, &SendData, 0); //速度 MyFun_Wait_SDO(msg->data); } } void callback_canopen_pdo(const void *msgin) { const std_msgs__msg__Int32MultiArray msg = (const std_msgs__msg__Int32MultiArray) msgin; struct nodeid_var *pNode = &(masterVar.nodeid1); int32_t *pdodata = msg->data.data; uint8_t nodeid = pdodata[0] - 1; *pNode[nodeid].W_controlWord = pdodata[1]; int32_t speed = pdodata[2]; if(speed >500 ) { speed = 500; }else if(speed <-500) { speed = -500; } speed *=2730; *pNode[nodeid].W_speed = speed; sendPDOevent(My_Data); } void my_microros_service() { microros_init(); // micro-ROS app rcl_service_t service; allocator = rcl_get_default_allocator(); //create init_options rclc_support_init(&support, 0, NULL, &allocator); // create node rclc_node_init_default(&node, “cubemx_node”, “”, &support); rclc_executor_init(&executor, &support.context, 1, &allocator); rclc_service_init_default(&service, &node, ROSIDL_GET_SRV_TYPE_SUPPORT(example_interfaces, srv, AddTwoInts), “add_two_ints”); example_interfaces__srv__AddTwoInts_Response response_msg; example_interfaces__srv__AddTwoInts_Request request_msg; rclc_executor_add_service(&executor, &service, &request_msg, &response_msg, service_callback); //rclc_executor_spin(&executor); while (1) { vTaskDelay(100); rclc_executor_spin_some(&executor, RCL_MS_TO_NS(100)); } } rcl_publisher_t pub; rcl_subscription_t sub_pdo; rcl_subscription_t sub_start; std_msgs__msg__Int32 sub_msg_start; std_msgs__msg__Int32MultiArray sub_msg_pdo; std_msgs__msg__Int32MultiArray pubArray_msg; void my_microros_run() { microros_init(); rclc_node_init_default(&node, “cubemx_node”, “”, &support); std_msgs__msg__Int32__init(&sub_msg_start); std_msgs__msg__Int32MultiArray__init(&pubArray_msg); std_msgs__msg__Int32MultiArray__init(&sub_msg_pdo); // rclc_publisher_init_default(&pub, &node, ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Int32MultiArray), // “dataArray”); rcl_ret_t rc; rc=rclc_subscription_init_default(&sub_start, &node, ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Int32), “pub_start”); rc=rclc_subscription_init_default(&sub_pdo, &node, ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Int32MultiArray), “pub_pdo”); rclc_executor_init(&executor, &support.context, 2, &allocator); rc = rclc_executor_add_subscription(&executor, &sub_pdo, &sub_msg_pdo, &callback_canopen_pdo, ON_NEW_DATA); rc=rclc_executor_add_subscription(&executor, &sub_start, &sub_msg_start, &callback_canopen_start, ON_NEW_DATA); // int32_t tee[] = { 1, 2, 3 }; while (1) { vTaskDelay(10); // Set message value // pubArray_msg.data.data = tee; // pubArray_msg.data.size = 3; // pubArray_msg.data.capacity = 3; // Publish message //rcl_publish(&pub, &pubArray_msg, NULL); rclc_executor_spin(&executor); //rclc_executor_spin_some(&executor, RCL_MS_TO_NS(100)); } } 话题都正常发布,结合这整段代码分析一下这段代码为什么pub_start话题能进回调,而pub_pdo不能进回调
07-02
(1)普通用户端(全平台) 音乐播放核心体验: 个性化首页:基于 “听歌历史 + 收藏偏好” 展示 “推荐歌单(每日 30 首)、新歌速递、相似曲风推荐”,支持按 “场景(通勤 / 学习 / 运动)” 切换推荐维度。 播放页功能:支持 “无损音质切换、倍速播放(0.5x-2.0x)、定时关闭、歌词逐句滚动”,提供 “沉浸式全屏模式”(隐藏冗余控件,突出歌词与专辑封面)。 多端同步:自动同步 “播放进度、收藏列表、歌单” 至所有登录设备(如手机暂停后,电脑端打开可继续播放)。 音乐发现与管理: 智能搜索:支持 “歌曲名 / 歌手 / 歌词片段” 搜索,提供 “模糊匹配(如输入‘晴天’联想‘周杰伦 - 晴天’)、热门搜索词推荐”,结果按 “热度 / 匹配度” 排序。 歌单管理:创建 “公开 / 私有 / 加密” 歌单,支持 “批量添加歌曲、拖拽排序、一键分享到社交平台”,系统自动生成 “歌单封面(基于歌曲风格配色)”。 音乐分类浏览:按 “曲风(流行 / 摇滚 / 古典)、语言(国语 / 英语 / 日语)、年代(80 后经典 / 2023 新歌)” 分层浏览,每个分类页展示 “TOP50 榜单”。 社交互动功能: 动态广场:查看 “关注的用户 / 音乐人发布的动态(如‘分享新歌感受’)、好友正在听的歌曲”,支持 “点赞 / 评论 / 转发”,可直接点击动态中的歌曲播放。 听歌排行:个人页展示 “本周听歌 TOP10、累计听歌时长”,平台定期生成 “全球 / 好友榜”(如 “好友中你本周听歌时长排名第 3”)。 音乐圈:加入 “特定曲风圈子(如‘古典音乐爱好者’)”,参与 “话题讨论(如‘你心中最经典的钢琴曲’)、线上歌单共创”。 (2)音乐人端(创作者中心) 作品管理: 音乐上传:支持 “无损音频(FLAC/WAV)+ 歌词文件(LRC)+ 专辑封面” 上传,填写 “歌曲信息
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值