2017-09-05 18:46:27 +08:00
|
|
|
import numpy
|
2017-09-18 19:15:20 +08:00
|
|
|
import logging
|
2017-09-08 20:09:27 +08:00
|
|
|
###############################################################
|
|
|
|
# Further work on fork
|
|
|
|
# Copyright (C) 2017 David Robinson
|
2017-09-05 18:46:27 +08:00
|
|
|
class HackRF:
|
|
|
|
"""The HackRF class has functions from converting data into a format into which the hackrf can process
|
|
|
|
"""
|
|
|
|
|
2017-09-18 19:15:20 +08:00
|
|
|
logger = None
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.logger = logging.getLogger(__name__)
|
2017-09-05 18:46:27 +08:00
|
|
|
|
|
|
|
def hackrf_raw_IQ_format(self, ppm):
|
|
|
|
"""
|
|
|
|
Args:
|
|
|
|
ppm: this is some data in ppm (pulse position modulation) which you want to convert into raw IQ format
|
|
|
|
|
|
|
|
Returns:
|
2017-09-07 14:59:24 +08:00
|
|
|
bytearray: containing the IQ data
|
2017-09-05 18:46:27 +08:00
|
|
|
"""
|
2017-09-18 19:15:20 +08:00
|
|
|
self.logger.debug('Creating hackRF bytearray from the ppm stuff')
|
2017-09-05 18:46:27 +08:00
|
|
|
signal = []
|
|
|
|
bits = numpy.unpackbits(numpy.asarray(ppm, dtype=numpy.uint8))
|
|
|
|
for bit in bits:
|
|
|
|
if bit == 1:
|
|
|
|
I = 127
|
|
|
|
Q = 127
|
|
|
|
else:
|
|
|
|
I = 0
|
|
|
|
Q = 0
|
|
|
|
signal.append(I)
|
|
|
|
signal.append(Q)
|
|
|
|
|
|
|
|
return bytearray(signal)
|