ook 模块 基础测试完成 准备调整参数

 

ook

 

import numpy as np

def int2bit(data):
    data = int(data)
    d = []
    b = "{0:b}".format(data)
    if len(b) < 8:
            x = 8 - len(b)
            for p in range(0,x):
                d.append("0")
    for i in range(0,len(b)):
        d.append(b[i])
    return d

def ook(bits):
    data = []
    for i in bits:
        if i == "1":
            for x in range(0,64):
                data.append("127")
        if i == "0":
            for y in range(0,64):
                data.append("0")

    return data


def tx_data(data):
    ret = []
    txdata = []
    for x in data:
        ret.append(ook(int2bit(x)))
    for a in ret:
        for b in a:
            txdata.append(str(b))
    return np.array(txdata).astype(np.int8).tobytes()




buffer = [0xff,0x02,0xff,0x99,0x08,0x09,0x11]

data = tx_data(buffer)
print(data)
import pyhackrf2 as pyhackrf
import numpy as np 
import ook as ook



hackrf = pyhackrf.HackRF()
hackrf.center_freq = 433.92e6
hackrf.lna_gain = 40
hackrf.txvga_gain = 62
hackrf.filter_bandwidth = hackrf.set_bw(1000000)

raw = ook.tx_data(ook.buffer)


while True:
    hackrf.buffer = bytearray(raw)
    hackrf.start_tx()
    hackrf.stop_tx()

你可能感兴趣的:(python,linux,学习,算法)