Hi,

I am trying to make a python OOT with 2 i/p & 1 o/p port.
The 1st i/p port should act like a trigger. For example whenever a ‘1’ is found 
in 1st input port, first 2 items in the list of 2nd input port will pass 
through, else dropped.

I have written the code as follows but its giving me an error: Can you help me 
in finding out where is the mistake?
======================================================================
FAIL: test_001_t (__main__.qa_Detector)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "qa_Detector.py", line 44, in test_001_t
    self.assertEqual(sink.data(), (1,2))
AssertionError: Tuples differ: (0.0, 0.0, 0.0, 0.0, 0.0) != (1, 2)

First differing element 0:
0.0
1

First tuple contains 3 additional elements.
First extra element 2:
0.0

- (0.0, 0.0, 0.0, 0.0, 0.0)
+ (1, 2)

----------------------------------------------------------------------
Ran 1 test in 0.003s

FAILED (failures=1)

Codes are as follows:

from gnuradio import gr, gr_unittest
from gnuradio import blocks
from Detector import Detector


class qa_Detector (gr_unittest.TestCase):

    def setUp (self):
        self.tb = gr.top_block ()

    def tearDown (self):
        self.tb = None

    def test_001_t (self):
                src0 = blocks.vector_source_f([1,0,0,0,0], False)
                src1 = blocks.vector_source_f([1,2,3,4,5], False)
                det = Detector()
                sink = blocks.vector_sink_f()
                self.tb.connect((src0, 0), (det, 0))
        self.tb.connect((src1, 0), (det, 1))
        self.tb.connect(det, sink)
                self.tb.run ()
                self.assertEqual(sink.data(), (1,2))


if __name__ == '__main__':
    gr_unittest.run(qa_Detector, "qa_Detector.xml")

import numpy
from gnuradio import gr
import numpy as np

class Detector(gr.sync_block):
    """
    docstring for block Detector
    """
    def __init__(self):
        gr.sync_block.__init__(self,
            name="Detector",
            in_sig=[numpy.float32,numpy.float32],
            out_sig=[numpy.float32])

    def work(self, input_items, output_items):
        in0 = input_items[0]
        in1 = input_items[1]
        out = output_items[0]
        for i in range(len(in1)):
            if in0[i] == 1:
                out = in1[i:2]
            else:
                None
        return len(output_items[0])

Thanks
Ayaz
_______________________________________________
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio

Reply via email to