import subprocessimport serial# 假设接收到的16进制字符是 01 03 00 AF AF# ser=serialSerialcom1115200timeout=50# hex_str1 = serreadlinehex_str = 01 03 1F AF AF# 去除空格得到一个没有空格的字符串while True hex_str = hex_strr
import subprocess import serial
def process_hex_string(hex_str): hex_str = hex_str.replace(' ', '') hex_value = hex_str[4:6] hex_value = int(hex_value, 16) binary_str = bin(hex_value)[2:].zfill(8) print(binary_str)
frequencies = [400, 800, 900, 1200, 1400, 5800]
for i in range(len(binary_str)-1, 0, -1):
if binary_str[i] == '1':
subprocess.run(['hackrf_transfer', '-f', str(frequencies[i-1]), '-s', '2000000', '-x', '20', '-t', 'sweep_400_500MHz.bin'])
break
hex_str = '01 03 1F AF AF' process_hex_string(hex_str
原文地址: https://www.cveoy.top/t/topic/irKO 著作权归作者所有。请勿转载和采集!