from urh.dev.native.lib import hackrf
from urh.dev.native.HackRF import HackRF
import numpy as np
import time
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)
buffer = [1,1,1,1,1,0,0,0,0,1,1,1,1]
data = tx_data(buffer)
hfc = HackRF(433.92e6,1e6,1e6,47)
hfc.start_tx_mode(np.array(data))
while not hfc.sending_finished:
print("Repeat: {0} Current Sample: {1}/{2}".format(
hfc.current_sending_repeat + 1,hfc.current_sent_sample,len(hfc.samples_to_send),))
time.sleep(1)
hfc.stop_tx_mode("Test finished")