import numpy as np
import pyhackrf2 as pyhackrf
import threading
bits =[1, 0, 1, 0, 1, 1, 0, 0, 0, 1]
def bit_array_to_number(bits,end,start=0):
if end < 1:
return 0
acc = 1
ret =0
for i in range(start,end):
ret += bits[end-1-i]*acc
acc *= 2
return ret
def fsk_mod(fw):
i = 0
i_p = 0
f = 0
f_p = 0
pc = np.zeros((100000))
i = bit_array_to_number(bits,i*2,i*2)
i_p = bit_array_to_number(bits,i*2,(i-1)*2)
f = fw[i]
f_p = fw[i_p]
if f != f_p:
t = ( i * 100 + 0 - 1 ) / 1e6
pc[i] = (pc[i-1] + 2 * np.pi * (f_p - f) * t) / (2 * np.pi)
else:
pc[i] = pc[i-1]
return pc
fw = [-20e3, -10e3, 10e3, 20e3]
data = np.zeros((100000))
data = fsk_mod(fw)
data = np.array(data).astype(np.int8).tobytes()
class hackrf_threading(threading.Thread):
def __init__(self):
self.hackrf = pyhackrf.HackRF()
self.hackrf.center_freq = 433.92e6
self.hackrf.lna_gain = 40
self.hackrf.txvga_gain = 47
self.hackrf.filter_bandwidth = self.hackrf.set_bw(1000000)
self.hackrf.buffer = bytearray(data)
def run(self):
self.hackrf.start_tx()
h = hackrf_threading()
h.run()