Exemplo n.º 1
0
def tx_thread(sdr, rate, txStream, rxStream, waveTx, numSamps, numSyms, txSymNum, startSymbol):
    global running
    firstTime = True
    waveRxA = np.array([0]*numSamps, np.uint32)
    waveRxB = np.array([0]*numSamps, np.uint32)
    flags = 0
    sdr.activateStream(txStream)
    sdr.activateStream(rxStream, flags, 0)
    while(running):
        sr = sdr.readStream(rxStream, [waveRxA, waveRxB], numSamps)
        if sr.ret == numSamps:
            txTime = sr.timeNs & 0xFFFFFFFF00000000
            txTime += (0x500000000 + (startSymbol << 16))
            if firstTime:
                print("first receive time 0x%X" % sr.timeNs)
                print("first transmit time 0x%X" % txTime)
                firstTime = False
        else:
            continue
        flags = SOAPY_SDR_HAS_TIME #| SOAPY_SDR_END_BURST
        for j in range(txSymNum):
            txTimeNs = txTime #SoapySDR.ticksToTimeNs(txTime, rate)
            if j == txSymNum-1:
                flags |= SOAPY_SDR_END_BURST 
            st = sdr.writeStream(txStream, [waveTx, waveTx], numSamps, flags, timeNs=txTimeNs)
            sts = sdr.readStreamStatus(txStream)
            if sts.ret != 0:
                print(SoapySDR.errToStr(sts.ret))
            txTime += 0x10000
    sdr.deactivateStream(rxStream)
    sdr.deactivateStream(txStream)
    sdr.closeStream(rxStream)
    sdr.closeStream(txStream)
    print("Exiting TX Thread")
def tx_task_fn(sdr, tx_stream, tx_sig, tx_buff_len):
    """ Transmit task that can be made a background process """
    rc = sdr.writeStream(tx_stream, [tx_sig], tx_buff_len)
    if rc.ret != tx_buff_len:
        raise IOError('Tx Error {}:{}'.format(rc.ret,
                                              SoapySDR.errToStr(rc.ret)))
    print('*', end='',
          flush=True)  # print an asterisk when a signal is repeated
Exemplo n.º 3
0
    def read(self):
        status = self.soapy.readStream(self.stream, self.buf, len(self.buf[0]))
        while status.ret == SoapySDR.SOAPY_SDR_OVERFLOW:
            print('warning: data dropped from radio')
            status = self.soapy.readStream(self.stream, self.buf,
                                           len(self.buf[0]))

        if status.ret <= 0:
            raise Exception(SoapySDR.errToStr(status.ret))
        if status.flags & SoapySDR.SOAPY_SDR_END_ABRUPT != 0:
            raiseException('Stream terminated prematurely (overflow)')
        # status.timeNs is accurate if SOAPY_SDR_HAS_TIME
        return self.buf
Exemplo n.º 4
0
    def read_stream_into_buffer(self, output_buffer):
        """Read samples into supplied output_buffer (blocks until output_buffer is full)"""
        output_buffer_size = len(output_buffer)
        ptr = 0
        while True:
            res = self.read_stream()
            if res.ret > 0:
                output_buffer[ptr:ptr + res.ret] = self.buffer[:min(
                    res.ret, output_buffer_size - ptr)]
                ptr += res.ret
            elif res.ret == -4:
                self.buffer_overflow_count += 1
                logger.debug(
                    'Buffer overflow error in readStream ({:d})!'.format(
                        self.buffer_overflow_count))
                logger.debug(
                    'Value of ptr when overflow happened: {}'.format(ptr))
            else:
                raise RuntimeError(
                    'Unhandled readStream() error: {} ({})'.format(
                        res.ret, SoapySDR.errToStr(res.ret)))

            if ptr >= len(output_buffer):
                return