Like names, destinies are more of others than ourselves

本文探讨了内心的真正感受往往与外界所见不同,生活的美好不在于它应该是什么样子,而在于我们拥有感受快乐与悲伤的能力。珍惜已经拥有的比追求所谓的理想状态更能带来幸福感。命运在我们去世后才成为封闭的话题,对后人而言才有意义。
True inside feelings always have great chances to differ from what was seen from outside, beauty of lives is not what it should to be or what is supposed to be, both happiness and sadness are because we have the ability to feel. Honour what we had been given than what "should" but had not, is always a way leads to feel of good life.

Destiny be a matter of enclosement after our death, that's meaningful for successors' talk, not ours.

No matter what is going on, we are alive, that's certain enough for cheers!
import serial import time import random # ============================================================ # 串口发送端程序 (Sender) # 实现功能: # 1. 按字节发送数据帧,包含序号与奇偶校验位 # 2. 使用停止-等待协议 (Stop-and-Wait ARQ) # 3. 支持超时重传与 NAK 重传机制 # 4. 模拟随机“丢帧”情况 # ============================================================ # ------------------------------------------------------------ # 函数:make_frame(ch, seq) # 作用:构造一帧数据 # 参数: # ch : 一个字节的数据(字符) # seq : 当前帧的序号(0或1) # 返回: # bytes 格式的帧: [帧头'D'][数据][序号][奇偶校验位] # ------------------------------------------------------------ def make_frame(ch, seq): # 计算数据字节中“1”的数量 bits = bin(ch).count('1') # 奇校验规则:若1的个数为偶数,校验位取1以保证总数为奇数 parity = 0 if bits % 2 else 1 # 拼接帧:D(68) + 数据 + 序号 + 校验位 return b'D' + bytes([ch]) + bytes([seq]) + bytes([parity]) # ------------------------------------------------------------ # 打开发送端串口 # 替换路径为 socat 输出的另一端 (如 /dev/pts/1) # 波特率 9600bps,8数据位,无硬件校验(我们用奇偶校验手动实现) # ------------------------------------------------------------ ser = serial.Serial('com7', 9600, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=1) # ------------------------------------------------------------ # 要发送的数据 # 注意:这里是一大段说明文字,会逐字节发送 # ------------------------------------------------------------ data = b"Honkai star rail is set in a science fiction universe[18], where there are star gods in the galaxy. Star gods are a highly condensed embodiment of philosophical concepts, and are the existences of those conscious beings who practice certain beliefs and reach the end of their destiny[19]. Star gods hold the power to change reality and create the world, and they can manipulate the imaginary energy of their own destiny[20]. This game contains 18 different destinies, each of which represents a belief and power, and 8 of them are set as character professions in the game. There is a mutually dependent relationship between each star god and his destiny. Star gods can move the energy of their destiny, but they are also bound by their destiny[20]. Once a destiny is opened, it cannot be closed. Even if the star god falls, the destiny still exists[21]. Of the 18 known star gods, some have fallen or disappeared[19]." # 初始帧序号 seq = 0 seq = 0 print(f"[Sender] Sending on {ser.port}...") # ============================================================ # 主循环:逐字节发送数据 # ============================================================ for ch in data: # 构造一帧完整数据 frame = make_frame(ch, seq) # ======================================================== # 模拟“丢帧”场景 (10% 概率) # 用于测试协议的超时重传机制 # ======================================================== if random.random() < 0.1: print(f"🚫 模拟丢帧 (seq={seq}) — 此帧不会发送") # 故意跳过发送,让接收方收不到,从而触发超时重传 else: # 正常发送帧 print(f"📤 发送帧: {chr(ch)} (seq={seq})") ser.write(frame) # ======================================================== # 等待接收方反馈 (ACK/NAK),并实现超时机制 # ======================================================== start = time.time() # 启动计时器 while True: # 读取最多2字节(可能是 'A'+seq 或 'N'+seq) ack = ser.read(2) # ✅ 收到反馈帧 if len(ack) == 2: t, s = ack[0], ack[1] # 收到 ACK(seq):说明当前帧已成功接收 if t == ord('A') and s == seq: print(f"✅ 收到 ACK (seq={seq}),继续发送下一帧\n") seq = 1 - seq # 序号在 0 和 1 之间交替 break # 收到 NAK(seq):说明接收端检测到错误,立即重发 elif t == ord('N') and s == seq: print(f"❌ 收到 NAK,重传该帧 (seq={seq})") ser.write(frame) start = time.time() # 重置计时器 # ⏰ 超时检测:若等待超过2秒无反馈 → 重传 if time.time() - start > 2: print(f"⏰ 超时!重发该帧 (seq={seq})") ser.write(frame) start = time.time() # 重置计时器Cannot configure port, something went wrong. Original message: PermissionError(13, '连到系统上的设备没有发挥作用。', None, 31)
11-17
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值