def test_004_invert_passb(self):

        self.dut = pdu_utils.pdu_range_filter(pmt.intern("start_time"), 1, 5,
                                              True)
        self.connectUp()

        in_data = [0, 0, 0, 0, 0, 0]
        i_meta = pmt.dict_add(pmt.make_dict(), pmt.intern("start_time"),
                              pmt.from_double(6.0))
        in_pdu = pmt.cons(i_meta, pmt.init_u8vector(len(in_data), in_data))
        expected_data = [0, 0, 0, 0, 0, 0]
        e_meta = pmt.dict_add(pmt.make_dict(), pmt.intern("start_time"),
                              pmt.from_double(6.0))
        expected_pdu = pmt.cons(
            e_meta, pmt.init_u8vector(len(expected_data), expected_data))

        self.tb.start()
        time.sleep(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()

        self.assertEqual(1, self.debug.num_messages())
        self.assertTrue(pmt.equal(self.debug.get_message(0), expected_pdu))
Example #2
0
    def test_001_t (self):
        in_data = [0, 1, 0, 0, 1, 0, 1, 1]
        print ("in_data = ", in_data)

        expected_data = [(1.000002384185791+7.219194575469601e-09j), (1.000002384185791+7.219194575469601e-09j), (1.000002384185791+7.219194575469601e-09j), (1.000002384185791+7.219194575469601e-09j), (1.000002384185791+7.219194575469601e-09j), (1.000002384185791+7.219194575469601e-09j), (1.000002384185791+7.219194575469601e-09j), (1.000002384185791+7.219194575469601e-09j), (1.000002384185791+7.219194575469601e-09j), (1.000002384185791+7.219194575469601e-09j), (1.000002384185791+7.219194575469601e-09j), (1.000002384185791+7.219194575469601e-09j), (0.9999558329582214-0.009149551391601562j), (0.9986380934715271-0.05212688446044922j), (0.9845290780067444-0.17521238327026367j), (0.9109043478965759-0.4126133918762207j), (0.6968833208084106-0.717181921005249j), (0.31042835116386414-0.950594425201416j), (-0.17273569107055664-0.9849666953086853j), (-0.6225566864013672-0.7825717926025391j), (-0.914273738861084-0.4051017761230469j), (-0.999992847442627-0.003090381622314453j), (-0.9691651463508606+0.24640250205993652j), (-0.968771755695343+0.24795293807983398j), (-0.9999971389770508+0.0017070770263671875j), (-0.9174799919128418-0.39777708053588867j), (-0.6312775611877441-0.7755542993545532j), (-0.18532180786132812-0.9826757907867432j), (0.2910269498825073-0.9567151069641113j), (0.6513003706932068-0.7588169574737549j), (0.81996750831604-0.5724067687988281j), (0.8208843469619751-0.5710964202880859j), (0.6549332737922668-0.7556841373443604j), (0.2986666262149811-0.9543551206588745j), (-0.17431020736694336-0.9846884608268738j), (-0.6225566864013672-0.7825717926025391j), (-0.9215338230133057-0.3883037567138672j), (-0.994880199432373+0.10103797912597656j), (-0.8246530294418335+0.5656423568725586j), (-0.4525153636932373+0.8917537331581116j), (0.030410051345825195+0.9995390772819519j), (0.5058896541595459+0.8625954985618591j), (0.8575133085250854+0.5144641399383545j), (0.9991825222969055+0.040370840579271317j), (0.9041904211044312-0.42713212966918945j), (0.6559781432151794-0.7547774314880371j), (0.44701042771339417-0.8945262432098389j), (0.44557973742485046-0.8952407836914062j), (0.6523504257202148-0.7579166889190674j), (0.9007443785667419-0.43434762954711914j), (0.9995729923248291+0.029183024540543556j), (0.8648265600204468+0.5020678639411926j), (0.533815860748291+0.8455996513366699j), (0.14855670928955078+0.9889022707939148j), (-0.1027672290802002+0.99470454454422j), (-0.10435843467712402+0.9945414066314697j), (0.14381003379821777+0.9896029233932495j), (0.5270366668701172+0.8498398065567017j), (0.8591512441635132+0.5117172598838806j), (0.9991825222969055+0.040370840579271317j), (0.9041904211044312-0.42713212966918945j), (0.6559781432151794-0.7547774314880371j), (0.44701042771339417-0.8945262432098389j), (0.44557973742485046-0.8952407836914062j), (0.6523504257202148-0.7579166889190674j), (0.9007443785667419-0.43434762954711914j), (0.9995729923248291+0.029183024540543556j), (0.8648265600204468+0.5020678639411926j), (0.5182530879974365+0.8552265167236328j), (0.04479217529296875+0.9989947080612183j), (-0.4396350383758545+0.8981758952140808j), (-0.8164236545562744+0.5774505138397217j), (-0.9933251738548279+0.11534643173217773j), (-0.9270230531692505-0.3749988079071045j), (-0.6337566375732422-0.773532509803772j), (-0.18532228469848633-0.9826757311820984j), (0.29976776242256165-0.954010009765625j), (0.6899716258049011-0.7238376140594482j), (0.9075756072998047-0.41988372802734375j), (0.9833885431289673-0.18150663375854492j), (0.9983774423599243-0.05691719055175781j), (0.9999259114265442-0.012347698211669922j), (0.9999974370002747-0.0015993118286132812j), (1.000002384185791+7.219194575469601e-09j), (1.000002384185791+7.219194575469601e-09j), (1.000002384185791+7.219194575469601e-09j), (1.000002384185791+7.219194575469601e-09j), (1.000002384185791+7.219194575469601e-09j), (1.000002384185791+7.219194575469601e-09j), (1.000002384185791+7.219194575469601e-09j), (1.000002384185791+7.219194575469601e-09j), (1.000002384185791+7.219194575469601e-09j), (1.000002384185791+7.219194575469601e-09j), (1.000002384185791+7.219194575469601e-09j), (1.000002384185791+7.219194575469601e-09j), (1.000002384185791+7.219194575469601e-09j), (1.000002384185791+7.219194575469601e-09j), (1.000002384185791+7.219194575469601e-09j), (1.000002384185791+7.219194575469601e-09j), (1.000002384185791+7.219194575469601e-09j), (1.000002384185791+7.219194575469601e-09j), (1.000002384185791+7.219194575469601e-09j), (1.000002384185791+7.219194575469601e-09j), (1.000002384185791+7.219194575469601e-09j)]
        in_pdu = pmt.cons(pmt.make_dict(), pmt.init_u8vector(len(in_data), in_data))
        expected_pdu = pmt.cons(pmt.make_dict(), pmt.init_c32vector(len(expected_data), expected_data))

        self.tb.start()
        time.sleep(.001)
        # handle non-pair input
        self.emitter2.emit(pmt.intern("MALFORMED PDU"))
        time.sleep(.001)
        # handle malformed pair
        self.emitter2.emit(pmt.cons(pmt.intern("NON-PDU"), pmt.intern("PAIR")))
        time.sleep(.001)
        # handle incorrect PDU
        self.emitter2.emit(in_pdu)
        time.sleep(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()

        out_data = pmt.c32vector_elements(pmt.cdr(self.debug.get_message(0)))
        self.assertComplexTuplesAlmostEqual(out_data, expected_data, 6)
Example #3
0
    def test_002_pass_empty (self):
        emitter = pdu_utils.message_emitter()
        split = pdu_utils.pdu_split(True)
        d1 = blocks.message_debug()
        d2 = blocks.message_debug()
        self.tb.msg_connect((emitter, 'msg'), (split, 'pdu_in'))
        self.tb.msg_connect((split, 'dict'), (d1, 'store'))
        self.tb.msg_connect((split, 'data'), (d2, 'store'))

        in_meta1 = pmt.dict_add(pmt.make_dict(), pmt.intern('num'), pmt.from_long(4))
        in_meta2 = pmt.dict_add(pmt.make_dict(), pmt.intern('n'), pmt.from_long(99))
        in_pdu = pmt.cons(in_meta1, pmt.init_u8vector(6, range(6)))

        self.tb.start()
        time.sleep(.001)
        emitter.emit(pmt.intern("MALFORMED PDU"))
        time.sleep(.001)
        emitter.emit(pmt.cons(pmt.PMT_NIL, pmt.init_u8vector(2, range(2))))
        time.sleep(.001)
        emitter.emit(pmt.cons(in_meta2, pmt.init_u8vector(0, [])))
        time.sleep(.001)
        emitter.emit(in_pdu)
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()

        self.assertTrue(pmt.equal(d1.get_message(0), pmt.PMT_NIL))
        self.assertTrue(pmt.equal(d1.get_message(1), in_meta2))
        self.assertTrue(pmt.equal(d1.get_message(2), in_meta1))
        self.assertTrue(pmt.equal(d2.get_message(0), pmt.init_u8vector(2, range(2))))
        self.assertTrue(pmt.equal(d2.get_message(1), pmt.init_u8vector(0, [])))
        self.assertTrue(pmt.equal(d2.get_message(2), pmt.init_u8vector(6, range(6))))
Example #4
0
    def test_002_larger(self):
        self.ht.set_length(32)
        in_data = [
            1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0,
            1, 1
        ]
        in_pdu = pmt.cons(pmt.make_dict(),
                          pmt.init_u8vector(len(in_data), in_data))
        expected_head = [
            1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0,
            1, 1, 0, 0, 0, 0, 0, 0, 0, 0
        ]
        e_head_pdu = pmt.cons(
            pmt.make_dict(),
            pmt.init_u8vector(len(expected_head), expected_head))
        expected_tail = [
            0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,
            1, 1, 0, 1, 0, 1, 0, 0, 1, 1
        ]
        e_tail_pdu = pmt.cons(
            pmt.make_dict(),
            pmt.init_u8vector(len(expected_tail), expected_tail))

        self.tb.start()
        time.sleep(.001)
        self.emitter.emit(pmt.intern("MALFORMED PDU"))
        time.sleep(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()

        self.assertTrue(pmt.equal(self.d_head.get_message(0), e_head_pdu))
        self.assertTrue(pmt.equal(self.d_tail.get_message(0), e_tail_pdu))
    def test_float(self):
        self.down = pdu_utils.pdu_downsample(3, 0)
        self.connectUp()

        i_vec = pmt.init_f32vector(9, [0, 1, 2, 3.3, 4, 5, 6, 7, 8])
        e_vec = pmt.init_f32vector(3, [0, 3.3, 6])
        in_pdu = pmt.cons(pmt.make_dict(), i_vec)
        e_pdu = pmt.cons(pmt.make_dict(), e_vec)

        self.tb.start()
        time.sleep(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()

        print("test float:")
        print("pdu expected: " + repr(pmt.car(e_pdu)))
        print("pdu got:      " + repr(pmt.car(self.debug.get_message(0))))
        print("data expected: " + repr(pmt.f32vector_elements(pmt.cdr(e_pdu))))
        print("data got:      " +
              repr(pmt.f32vector_elements(pmt.cdr(self.debug.get_message(0)))))
        print

        self.assertTrue(pmt.equal(self.debug.get_message(0), e_pdu))
Example #6
0
 def test_008_match_leading_zeros (self):
     '''
     Leading zeros at the beginning of the alignment sequence previously caused
     invalid alignments due to not checking to ensure that the entire alignment
     sequence was checked before emitting the message
     
     For an alignment sequence of:
     '00000000'*3 + '10110111'
     
     a message was kicked out with the following contents
     '00000000'*3 + '10110111' + ...
     
     if the first 8 bits of a sequence were within the threshold of the last 8
     bits of the alignment sequence, which has a 1 in 256 chance of occuring
     statistically anyway.
     
     '''
     preamble = '00000000' * 3 + '10110111'
     self.dut = pdu_utils.pdu_align(preamble, 0, 0, pdu_utils.ALIGN_EMPTY)
     self.connectUp()
     
     in_data = [int(a) for a in ('10110111' + '00000000' * 3 + '10110111' + '10100101')]
     expected_data = [1, 0, 1, 0, 0, 1, 0, 1]
     
     in_pdu = pmt.cons(pmt.make_dict(), pmt.init_u8vector(len(in_data), in_data))
     expected_pdu = pmt.cons(pmt.make_dict(), pmt.init_u8vector(len(expected_data), expected_data))
     
     self.tb.start()
     time.sleep(.001)
     self.emitter.emit(in_pdu)
     time.sleep(.1)
     self.tb.stop()
     self.tb.wait()
     
     self.assertTrue(pmt.equal(self.debug.get_message(0), expected_pdu))
    def test_longer (self):
        self.emitter = pdu_utils.message_emitter()
        self.down = pdu_utils.pdu_downsample(2,1)
        self.debug = blocks.message_debug()
        self.tb.msg_connect((self.emitter, 'msg'), (self.down, 'pdu_in'))
        self.tb.msg_connect((self.down, 'pdu_out'), (self.debug, 'store'))

        i_vec = pmt.init_u8vector(7, [0,1,2,3,4,5,6])
        e_vec = pmt.init_u8vector(3, [1,3,5])
        in_pdu = pmt.cons(pmt.make_dict(), i_vec)
        e_pdu = pmt.cons(pmt.make_dict(), e_vec)

        self.tb.start()
        time.sleep(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()

        print("test long:")
        print("pdu expected: " + repr(pmt.car(e_pdu)))
        print("pdu got:      " + repr(pmt.car(self.debug.get_message(0))))
        print("data expected: " + repr(pmt.u8vector_elements(pmt.cdr(e_pdu))))
        print("data got:      " + repr(pmt.u8vector_elements(pmt.cdr(self.debug.get_message(0)))))
        print

        self.assertTrue(pmt.equal(self.debug.get_message(0), e_pdu))
Example #8
0
    def test_005_fff_down(self):
        self.dut = pdu_utils.pdu_pfb_resamp_fff([1], 1, 0.5)
        self.connectUp()

        in_data = [1, 1, 0, 0] * 4
        in_pdu = pmt.cons(pmt.make_dict(), pmt.init_f32vector(len(in_data), in_data))

        expected_data = [1, 0] * 4
        expected_pdu = pmt.cons(pmt.make_dict(), pmt.init_f32vector(len(expected_data), expected_data))

        self.tb.start()
        time.sleep(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()

        self.assertEqual(1, self.debug.num_messages())

        print("test_005_fff_down:")
        print("pdu expected: " + repr(pmt.car(expected_pdu)))
        print("pdu got:      " + repr(pmt.car(self.debug.get_message(0))))
        print("data expected: " + repr(pmt.to_python(pmt.cdr(expected_pdu))))
        print("data got:      " + repr(pmt.to_python(pmt.cdr(self.debug.get_message(0)))))
        print

        self.assertTrue(pmt.equal(self.debug.get_message(0), expected_pdu))
Example #9
0
    def test_005_match_error0b(self):

        self.dut = pdu_utils.pdu_align('10101010', 1, 0, pdu_utils.ALIGN_DROP)
        self.connectUp()

        in_data = [1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1]
        expected_data = [1, 1, 1, 1, 1, 1, 1, 1]
        in_pdu = pmt.cons(pmt.make_dict(),
                          pmt.init_u8vector(len(in_data), in_data))
        expected_pdu = pmt.cons(
            pmt.make_dict(),
            pmt.init_u8vector(len(expected_data), expected_data))

        self.tb.start()
        time.sleep(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()

        self.assertEqual(1, self.debug.num_messages())

        print("\nEXPECTED: " + repr(pmt.car(expected_pdu)))
        print("GOT:      " + repr(pmt.car(self.debug.get_message(0))))
        print("\nEXPECTED: " +
              repr(pmt.u8vector_elements(pmt.cdr(expected_pdu))))
        print("GOT:      " +
              repr(pmt.u8vector_elements(pmt.cdr(self.debug.get_message(0)))))

        self.assertTrue(pmt.equal(self.debug.get_message(0), expected_pdu))
Example #10
0
    def test_007_match_errors2(self):
        '''
        Ensure specification of the number of errors in an alignment sequence is
        properly checked
        '''
        self.dut = pdu_utils.pdu_align('10101010', 2, 0, pdu_utils.ALIGN_EMPTY)
        self.connectUp()

        in_data = [1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1]
        expected_data = [0, 1, 0, 1, 0, 1, 0, 1]

        in_pdu = pmt.cons(pmt.make_dict(),
                          pmt.init_u8vector(len(in_data), in_data))
        expected_pdu = pmt.cons(
            pmt.make_dict(),
            pmt.init_u8vector(len(expected_data), expected_data))

        self.tb.start()
        time.sleep(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.1)
        self.tb.stop()
        self.tb.wait()

        self.assertTrue(pmt.equal(self.debug.get_message(0), expected_pdu))
Example #11
0
    def test_endian(self):
        self.emitter = pdu_utils.message_emitter()
        #self.endi = pdu_utils.pdu_binary_tools(pdu_utils.pdu_binary_tools.ENDIAN_SWAP8)
        self.endi = pdu_utils.pdu_binary_tools(4)
        self.debug = blocks.message_debug()
        self.tb.msg_connect((self.emitter, 'msg'), (self.endi, 'pdu_in'))
        self.tb.msg_connect((self.endi, 'pdu_out'), (self.debug, 'store'))

        i_vec = pmt.init_u8vector(
            16, [1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0])
        e_vec = pmt.init_u8vector(
            16, [1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1])
        in_pdu = pmt.cons(pmt.make_dict(), i_vec)
        e_pdu = pmt.cons(pmt.make_dict(), e_vec)

        self.tb.start()
        time.sleep(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()

        print "test endian_swap8:"
        print "pdu expected: " + repr(pmt.car(e_pdu))
        print "pdu got:      " + repr(pmt.car(self.debug.get_message(0)))
        print "data expected: " + repr(pmt.u8vector_elements(pmt.cdr(e_pdu)))
        print "data got:      " + repr(
            pmt.u8vector_elements(pmt.cdr(self.debug.get_message(0))))
        print

        self.assertTrue(pmt.equal(self.debug.get_message(0), e_pdu))
Example #12
0
    def test_004_n512_s32(self):
        self.upsample.set_n(512)
        self.upsample.set_repeat(True)

        in_data = [99, 44]
        expected_data = [
            99,
        ] * 512 + [
            44,
        ] * 512
        in_pdu = pmt.cons(pmt.make_dict(),
                          pmt.init_s32vector(len(in_data), in_data))
        expected_pdu = pmt.cons(
            pmt.make_dict(),
            pmt.init_s32vector(len(expected_data), expected_data))

        self.tb.start()
        time.sleep(.001)
        self.emitter.emit(pmt.intern("MALFORMED PDU"))
        time.sleep(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.05)
        self.tb.stop()
        self.tb.wait()

        self.assertTrue(pmt.equal(self.debug.get_message(0), expected_pdu))
        self.assertTrue(pmt.equal(self.debug.get_message(1), expected_pdu))
Example #13
0
    def test_001_n4_u8(self):
        in_data = [0, 1, 2, 4, 8, 16, 32]
        expected_data1 = [
            0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 4, 0, 0, 0, 8, 0, 0, 0, 16, 0,
            0, 0, 32, 0, 0, 0
        ]
        expected_data2 = [
            0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8, 16, 16,
            16, 16, 32, 32, 32, 32
        ]
        in_pdu = pmt.cons(pmt.make_dict(),
                          pmt.init_u8vector(len(in_data), in_data))
        expected_pdu1 = pmt.cons(
            pmt.make_dict(),
            pmt.init_u8vector(len(expected_data1), expected_data1))
        expected_pdu2 = pmt.cons(
            pmt.make_dict(),
            pmt.init_u8vector(len(expected_data2), expected_data2))

        self.tb.start()
        time.sleep(.001)
        self.emitter.emit(pmt.intern("MALFORMED PDU"))
        time.sleep(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.001)
        self.upsample.set_repeat(True)
        time.sleep(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.05)
        self.tb.stop()
        self.tb.wait()

        self.assertTrue(pmt.equal(self.debug.get_message(0), expected_pdu1))
        self.assertTrue(pmt.equal(self.debug.get_message(1), expected_pdu2))
Example #14
0
    def test_simple (self):
        self.emitter = pdu_utils.message_emitter()
        self.ctm2 = pdu_utils.pdu_complex_to_mag2()
        self.debug = blocks.message_debug()
        self.tb.msg_connect((self.emitter, 'msg'), (self.ctm2, 'cpdus'))
        self.tb.msg_connect((self.ctm2, 'fpdus'), (self.debug, 'store'))

        # gnuradio uses single-precision floats by default
        i_vec = pmt.init_c32vector(3, [3+4j, 1+0j, 0+1j])
        e_vec = pmt.init_f32vector(3, [25, 1, 1])

        in_pdu = pmt.cons(pmt.make_dict(), i_vec)
        e_pdu = pmt.cons(pmt.make_dict(), e_vec)

        self.tb.start()
        time.sleep(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()

        print("test ctm2:")
        print("pdu expected: " + repr(pmt.car(e_pdu)))
        print("pdu got:      " + repr(pmt.car(self.debug.get_message(0))))
        print("data expected: " + repr(pmt.to_python(pmt.cdr(e_pdu))))
        print("data got:      " + repr(pmt.to_python(pmt.cdr(self.debug.get_message(0)))))
        print

        self.assertTrue(pmt.equal(self.debug.get_message(0), e_pdu))
Example #15
0
 def msg_handler_frame(self, msg_in):
     ## print('-------------------- msg_handler_frame --------------------')
     ## print(msg_in)
     symbols = pmt.to_python(
         pmt.dict_ref(msg_in, pmt.intern('symbols'), pmt.PMT_NIL))
     soft_dec = pmt.to_python(
         pmt.dict_ref(msg_in, pmt.intern('soft_dec'), pmt.PMT_NIL))
     symb, constellation_idx, do_continue, save_soft_dec = self._obj.get_next_frame(
         symbols)
     if do_continue and len(soft_dec) != 0:
         d = self._obj.decode_soft_dec(soft_dec)
         msg_out = pmt.make_dict()
         msg_out = pmt.dict_add(msg_out, pmt.intern('packet_len'),
                                pmt.to_pmt(len(d)))
         d = np.array(d, dtype=np.float32)
         d[abs(d) == np.Inf] = 0
         vv = pmt.to_pmt(d)
         msg = pmt.cons(msg_out, vv)
         self.message_port_pub(self._port_soft_dec, msg)
         ## TODO: publish the bits if success
     ##print('symb=', symb, symb['symb'], symb['scramble'])
     msg_out = pmt.make_dict()
     msg_out = pmt.dict_add(msg_out, pmt.intern('symb'),
                            pmt.to_pmt(symb['symb']))
     msg_out = pmt.dict_add(msg_out, pmt.intern('scramble'),
                            pmt.to_pmt(symb['scramble']))
     msg_out = pmt.dict_add(msg_out, pmt.intern('constellation_idx'),
                            pmt.to_pmt(constellation_idx))
     msg_out = pmt.dict_add(msg_out, pmt.intern('do_continue'),
                            pmt.to_pmt(np.bool(do_continue)))
     msg_out = pmt.dict_add(msg_out, pmt.intern('save_soft_dec'),
                            pmt.to_pmt(np.bool(save_soft_dec)))
     ## print(msg_out)
     self.message_port_pub(self._port_frame_info, msg_out)
Example #16
0
    def test_from_pam(self):
        self.emitter = pdu_utils.message_emitter()
        #self.flip = pdu_utils.pdu_binary_tools(pdu_utils.pdu_binary_tools.FROM_PAM)
        self.flip = pdu_utils.pdu_binary_tools(2)
        self.debug = blocks.message_debug()
        self.tb.msg_connect((self.emitter, 'msg'), (self.flip, 'pdu_in'))
        self.tb.msg_connect((self.flip, 'pdu_out'), (self.debug, 'store'))

        i_vec = pmt.init_f32vector(6, [1, -1, -1, 1, -1, 1])
        e_vec = pmt.init_u8vector(6, [1, 0, 0, 1, 0, 1])
        in_pdu = pmt.cons(pmt.make_dict(), i_vec)
        e_pdu = pmt.cons(pmt.make_dict(), e_vec)

        self.tb.start()
        time.sleep(.001)
        self.emitter.emit(in_pdu)
        time.sleep(.01)
        self.tb.stop()
        self.tb.wait()

        print "test from_pam:"
        print "pdu expected: " + repr(pmt.car(e_pdu))
        print "pdu got:      " + repr(pmt.car(self.debug.get_message(0)))
        print "data expected: " + repr(pmt.u8vector_elements(pmt.cdr(e_pdu)))
        print "data got:      " + repr(
            pmt.u8vector_elements(pmt.cdr(self.debug.get_message(0))))
        print

        self.assertTrue(pmt.equal(self.debug.get_message(0), e_pdu))
Example #17
0
    def test_006_f32(self):
        '''
        float input data, complicated input, decimation, and filtering
        '''
        taps = [
            -0.1, -0.2, -0.3, 0., 0.8, 1.4, 0.7, -1.9, -4.5, -3.8, 2.9, 14.4,
            25.5, 30.1, 30.1, 25.5, 14.4, 2.9, -3.8, -4.5, -1.9, 0.7, 1.4, 0.8,
            0., -0.3, -0.2, -0.1
        ]
        print(len(taps))
        self.dut = pdu_utils.pdu_fir_filter(4, taps)
        self.connectUp()

        i_data = [
            0., 0.25, 0.48, 0.68, 0.84, 0.95, 1., 0.98, 0.91, 0.78, 0.6, 0.38,
            0.14, -0.11, -0.35, -0.57, -0.76, -0.89, -0.98, -1., -0.96, -0.86,
            -0.71, -0.51, -0.28, -0.03, 0.22, 0.45, 0.66, 0.82, 0.94, 0.99,
            0.99, 0.92, 0.8, 0.62, 0.41, 0.17, -0.08, -0.32, -0.54, -0.73,
            -0.88, -0.97, -1., -0.97, -0.88, -0.73, -0.54, -0.31, -0.07, 0.18,
            0.42, 0.63, 0.8, 0.93, 0.99, 0.99, 0.93, 0.82, 0.65, 0.44, 0.21,
            -0.04, -0.29, -0.52, -0.71, -0.86, -0.96, -1., -0.98, -0.89
        ]
        i_meta = pmt.dict_add(pmt.make_dict(), pmt.intern("sample_rate"),
                              pmt.from_double(40e3))
        i_meta = pmt.dict_add(i_meta, pmt.intern("start_time"),
                              pmt.from_double(65.4321))
        in_pdu = pmt.cons(i_meta, pmt.init_f32vector(len(i_data), i_data))

        e_data = [
            8.344998, 95.737, 121.949005, 33.454994, -85.351006, -126.05898,
            -50.684998, 71.381004, 127.386, 66.26399, -55.451004, -126.658005,
            -81.652, 38.550003, 123.046005, 94.08399, -19.649996, -123.254005
        ]
        e_meta = pmt.dict_add(pmt.make_dict(), pmt.intern("sample_rate"),
                              pmt.from_double(10e3))
        e_meta = pmt.dict_add(e_meta, pmt.intern("start_time"),
                              pmt.from_double(65.432050))
        e_pdu = pmt.cons(e_meta, pmt.init_f32vector(len(e_data), e_data))

        self.tb.start()
        time.sleep(.01)
        self.emitter.emit(in_pdu)
        time.sleep(.1)
        self.tb.stop()
        self.tb.wait()

        #print("test_005:")
        #print("pdu expected: " + repr(pmt.car(e_pdu)))
        #print("pdu got:      " + repr(pmt.car(self.debug.get_message(0))))
        #print("data expected: " + repr(pmt.to_python(pmt.cdr(e_pdu))))
        #print("data got:      " + repr(pmt.to_python(pmt.cdr(self.debug.get_message(0)))))
        #print

        self.assertTrue(pmt.equal(pmt.car(self.debug.get_message(0)), e_meta))
        v_diff = np.abs(
            pmt.f32vector_elements(pmt.cdr(self.debug.get_message(0))) -
            np.array(e_data)) / e_data
        print("Maximum error is", np.max(v_diff))
        self.assertTrue(np.max(v_diff) < 0.0001)
Example #18
0
    def test_005_c32(self):
        '''
        complex input data, no decimation, even number of taps
        '''
        self.dut = pdu_utils.pdu_fir_filter(1, [.2] * 6)
        self.connectUp()

        i_data = [
            1,
        ] * 10
        i_meta = pmt.dict_add(pmt.make_dict(), pmt.intern("sample_rate"),
                              pmt.from_double(100.0))
        i_meta = pmt.dict_add(i_meta, pmt.intern("start_time"),
                              pmt.from_double(9.9))
        in_pdu = pmt.cons(i_meta, pmt.init_c32vector(len(i_data), i_data))

        e_data = [
            .6,
            .8,
            1,
        ] + [
            1.2,
        ] * 5 + [1, .8, .6]
        e_meta = pmt.dict_add(pmt.make_dict(), pmt.intern("sample_rate"),
                              pmt.from_double(100.0))
        e_meta = pmt.dict_add(e_meta, pmt.intern("start_time"),
                              pmt.from_double(9.895))
        e_pdu = pmt.cons(e_meta, pmt.init_c32vector(len(e_data), e_data))

        self.tb.start()
        time.sleep(.01)
        self.emitter.emit(in_pdu)
        time.sleep(.1)
        self.tb.stop()
        self.tb.wait()

        #print("test_005:")
        #print("pdu expected: " + repr(pmt.car(e_pdu)))
        #print("pdu got:      " + repr(pmt.car(self.debug.get_message(0))))
        #print("data expected: " + repr(pmt.to_python(pmt.cdr(e_pdu))))
        #print("data got:      " + repr(pmt.to_python(pmt.cdr(self.debug.get_message(0)))))
        #print

        self.assertTrue(pmt.equal(pmt.car(self.debug.get_message(0)), e_meta))
        v_diff = np.abs(
            pmt.c32vector_elements(pmt.cdr(self.debug.get_message(0))) -
            np.array(e_data)) / np.abs(e_data)
        print("Maximum error is", np.max(v_diff))
        self.assertTrue(np.max(v_diff) < 0.00001)
 def set_value(self, value, conversion = pmt.from_double ):
     """
     When the set_value(value) method is called, sends a message containing a PMT dict {key, value}
     """
     pmt_val = conversion(value)
     pmt_dict = pmt.make_dict()
     pmt_dict = pmt.dict_add(pmt_dict, self._key, pmt_val)
     self.message_port_pub(self._out_port, pmt_dict)
Example #20
0
def str_to_pdu(meta, msg):
    vector = map(ord, msg)
    data = pmt.make_u8vector(len(vector), 0)
    for k in range(0, len(vector)):
        pmt.u8vector_set(data, k, vector[k])

    pdu = pmt.cons(pmt.make_dict(), data)
    return pdu
Example #21
0
def pdu_arg_add(pdu, k, v):
    meta = pmt.car(pdu);
    data = pmt.cdr(pdu);
    if(pmt.is_null(meta)):
        meta = pmt.make_dict();
    assert(pmt.is_dict(meta));
    meta = pmt.dict_add(meta, k, v);
    return pmt.cons(meta,data);
Example #22
0
    def work(self, input_items, output_items):

        tensordata = []
        input_i = []
        shapev = np.array(input_items[0]).shape

        for item in range(shapev[0]):

            inp = np.array(input_items[0][item])

            if self.dtype == np.complex64:

                # complex data must be split into real 
                # and imaginary floats for the ANN
                tensordata.append(np.array([[inp.real,inp.imag]]))

            elif self.dtype == np.float32:

                if np.mean(inp) == 0.0:
                    return len(input_items[0])

                ## Normalise data
                inp = (inp - np.mean(inp)) / np.std(inp)

                ## Reshape data as specified
                if not self.reshape == ():
                    floats = np.reshape(inp,self.reshape)
                else:
                    floats = inp

                tensordata.append(np.array([floats]))

        ne = []
        for v in tensordata:
            try:
                #print("In: ",self.inp,"Out : ",self.out)
                #print("Inp ",v)
                outp = self.sess.run(self.out, feed_dict={self.inp: [v]})[0]
                #print("OUTP ",outp)
                ne.append(outp)
            except tf.errors.InvalidArgumentError:
                print("Invalid size of input vector to TensorFlow model")
                quit()

        pmtv = pmt.make_dict()
        for outp in ne:
            pmtv = pmt.make_tuple(pmt.to_pmt(("signal",self.signum)),pmt.to_pmt((self.classes[np.argmax(outp)],outp[np.argmax(outp)].item())))

            self.message_port_pub(pmt.intern("classification"), pmtv)

        return len(input_items[0])
Example #23
0
 def test19(self):
     max_key = pmt.intern("MAX")
     _max = pmt.from_long(self.MAXINT32)
     min_key = pmt.intern("MIN")
     _min = pmt.from_long(self.MININT32)
     d = pmt.make_dict()
     d = pmt.dict_add(d, max_key, _max)
     d = pmt.dict_add(d, min_key, _min)
     s = pmt.serialize_str(d)
     deser = pmt.deserialize_str(s)
     self.assertTrue(pmt.equal(d, deser))
     p_dict = pmt.to_python(deser)
     self.assertEqual(self.MAXINT32, p_dict["MAX"])
     self.assertEqual(self.MININT32, p_dict["MIN"])
Example #24
0
def nmea_parser_core(self, nmea_str):
	fixobj = pynmea2.parse(nmea_str)
	nmea_id = fixobj.sentence_type

	if nmea_id not in ['GGA', 'GLL', 'RMC', 'VTG']:
		raise AttributeError("Unparsed Sentence")

	D = pmt.make_dict()
	D = PMT_ADD(D, PSTR("id"), PSTR(nmea_id))
	D = PMT_ADD(D, PSTR("protocol"), PSTR('nmea'))
	D = PMT_ADD(D, PSTR("host_time"), PSTR(str(self.host_time)))

	try:
		self.valid = fixobj.is_valid
		D = PMT_ADD(D, PSTR("valid"), pmt.from_bool(self.valid))
	except AttributeError:
		pass # not all sentences carry validity

	try:
		D = PMT_ADD(D, PSTR("latitude"), PDBL(fixobj.latitude))
		D = PMT_ADD(D, PSTR("longitude"), PDBL(fixobj.longitude))
	except AttributeError:
		pass

	try:
		if fixobj.altitude is not None:
			D = PMT_ADD(D, PSTR("altitude"), PDBL(fixobj.altitude))
	except AttributeError:
		pass

	try:
		D = PMT_ADD(D, PSTR("track"), PDBL(fixobj.true_track))
	except AttributeError:
		pass

	try:
		if fixobj.spd_over_grnd_kmph is not None:
			D = PMT_ADD(D, PSTR("speed"), PDBL(fixobj.spd_over_grnd_kmph))
	except AttributeError:
		pass

	try:
		self.nmea_time = dt.combine(fixobj.datestamp, fixobj.timestamp)
		D = PMT_ADD(D, PSTR("gps_time"), PSTR(str(self.nmea_time)))
	except AttributeError:
		pass

	# Send the message
	if D:
		self.message_port_pub(pmt.intern('gps_msg'), pmt.cons(D, pmt.PMT_NIL))
Example #25
0
 def run(self):
     while True:
         self.pcap = PcapReader(self.f)   
         self.lasttime = 0;
         for p in self.pcap:
             if(not (self.lasttime == 0)):
                 diff = (p.time - self.lasttime)
                 time.sleep(diff*self.time_scale);
             self.lasttime = p.time
             if(self.done):
                 return
             
             v = pmt.to_pmt(numpy.fromstring(str(p), dtype=numpy.uint8))
             meta = pmt.make_dict();
             self.message_port_pub(pmt.intern("pdus"), pmt.cons(meta, v));
Example #26
0
def gpsd_parser_core(self, gpsd_str):
	G = json.loads(gpsd_str)
	if 'TPV' not in G['class']:
		return

	D = pmt.make_dict()
	D = PMT_ADD(D, PSTR("id"), PSTR(str(G['tag'])))
	D = PMT_ADD(D, PSTR("protocol"), PSTR('gpsd'))
	D = PMT_ADD(D, PSTR("host_time"), PSTR(str(self.host_time)))
	D = PMT_ADD(D, PSTR("gps_time"), PSTR(str(G['time'])))
	D = PMT_ADD(D, PSTR("longitude"), PDBL(G['lon']))
	D = PMT_ADD(D, PSTR("latitude"), PDBL(G['lat']))
	D = PMT_ADD(D, PSTR("altitude"), PDBL(G['alt']))
	D = PMT_ADD(D, PSTR("speed"), PDBL(G['speed']))
	D = PMT_ADD(D, PSTR("track"), PDBL(G['track']))
	self.message_port_pub(pmt.intern('gps_msg'), pmt.cons(D, pmt.PMT_NIL))
Example #27
0
 def test_001_t (self):
     # set up fg
     msg_meta = pmt.make_dict()
     msg_meta = pmt.dict_add(msg_meta, pmt.to_pmt("freq"), pmt.to_pmt("val"))
     vec1 = [0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00];
     msg_vector = pmt.init_u8vector(len(vec1), vec1)
     msg = pmt.cons(msg_meta, msg_vector)
     src = blocks.message_strobe(msg, 10)
     dut = capture_tools.bit_sniffer(fade_out=500, hexadecimal=True)
     self.tb.msg_connect((src, "strobe"), (dut, "packets"))
     self.tb.start ()
     time.sleep(5)
     vec1 = [0x01, 0x00, 0x01, 0x00, 0x01, 0x00];
     msg_vector = pmt.init_u8vector(len(vec1), vec1)
     msg = pmt.cons(msg_meta, msg_vector)
     src.set_msg(msg);
     time.sleep(5)
     vec1 = [0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x01];
     msg_vector = pmt.init_u8vector(len(vec1), vec1)
     msg = pmt.cons(msg_meta, msg_vector)
     src.set_msg(msg);
     time.sleep(5)
     self.tb.stop()
Example #28
0
    def rx_handler(self, msg):
        meta = pmt.car(msg);
        data_in = array.array('B', pmt.u8vector_elements(pmt.cdr(msg)))
        data_list = data_in.tolist();
        if data_list[0:8] == self.operations["data"]:
            self.rx_cnt = self.rx_cnt + 1;
            seq = struct.unpack("<i", self.pack_bits(data_list[8:8+32]))[0];
            #print "rx sequence: %d"%(seq);
            # send ACK bak
            self.send_ack(seq);

            # pass along sequence number for fun
            if(pmt.is_null(meta)):
                meta = pmt.make_dict();
            meta = pmt.dict_add(meta, pmt.intern("arq_seq"), pmt.from_long(seq));

            if(self.rx_record.has_key(seq)):
                print "duplicate recieve data pkt seq! %d"%(seq)
                return;
            self.rx_record[seq] = time.time();

            # send payload to next layer
            data_upper = data_list[8+32:];
            self.message_port_pub(pmt.intern("rx_out"), pmt.cons(meta,pmt.init_u8vector(len(data_upper),data_upper)));
            return;

        if data_list[0:8] == self.operations["ack"]:
            self.ack_rx_cnt = self.ack_rx_cnt + 1;
            # set pkt ack'd locally
            seq = struct.unpack("<i", self.pack_bits(data_list[8:8+32]))[0];
            print "got pkt ack (%d)"%(seq)
            self.ack(seq);
            return;           

        # fall through fail
        print "got invalid ARQ header, discarding!"
Example #29
0
 def test01(self):
     a = pmt.intern("a")
     b = pmt.from_double(123765)
     d1 = pmt.make_dict()
     d2 = pmt.dict_add(d1, a, b)
     print d2
    def __init__(self):
        gr.top_block.__init__(self, "Top Block")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Top Block")
        try:
            self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        except:
            pass
        self.top_scroll_layout = Qt.QVBoxLayout()
        self.setLayout(self.top_scroll_layout)
        self.top_scroll = Qt.QScrollArea()
        self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
        self.top_scroll_layout.addWidget(self.top_scroll)
        self.top_scroll.setWidgetResizable(True)
        self.top_widget = Qt.QWidget()
        self.top_scroll.setWidget(self.top_widget)
        self.top_layout = Qt.QVBoxLayout(self.top_widget)
        self.top_grid_layout = Qt.QGridLayout()
        self.top_layout.addLayout(self.top_grid_layout)

        self.settings = Qt.QSettings("GNU Radio", "top_block")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.scroll = scroll = False
        self.samp_rate = samp_rate = 32000
        self.offset = offset = 0
        self.hex_output = hex_output = False
        self.bits_per_word = bits_per_word = 8
        self.binary_output = binary_output = True
        self.ascii_output = ascii_output = False

        ##################################################
        # Blocks
        ##################################################
        _scroll_check_box = Qt.QCheckBox("scroll")
        self._scroll_choices = {True: True, False: False}
        self._scroll_choices_inv = dict((v,k) for k,v in self._scroll_choices.iteritems())
        self._scroll_callback = lambda i: Qt.QMetaObject.invokeMethod(_scroll_check_box, "setChecked", Qt.Q_ARG("bool", self._scroll_choices_inv[i]))
        self._scroll_callback(self.scroll)
        _scroll_check_box.stateChanged.connect(lambda i: self.set_scroll(self._scroll_choices[bool(i)]))
        self.top_layout.addWidget(_scroll_check_box)
        self._offset_range = Range(0, 7, 1, 0, 200)
        self._offset_win = RangeWidget(self._offset_range, self.set_offset, "offset", "counter_slider", int)
        self.top_layout.addWidget(self._offset_win)
        _hex_output_check_box = Qt.QCheckBox("hex_output")
        self._hex_output_choices = {True: True, False: False}
        self._hex_output_choices_inv = dict((v,k) for k,v in self._hex_output_choices.iteritems())
        self._hex_output_callback = lambda i: Qt.QMetaObject.invokeMethod(_hex_output_check_box, "setChecked", Qt.Q_ARG("bool", self._hex_output_choices_inv[i]))
        self._hex_output_callback(self.hex_output)
        _hex_output_check_box.stateChanged.connect(lambda i: self.set_hex_output(self._hex_output_choices[bool(i)]))
        self.top_layout.addWidget(_hex_output_check_box)
        self._bits_per_word_range = Range(2, 8, 1, 8, 200)
        self._bits_per_word_win = RangeWidget(self._bits_per_word_range, self.set_bits_per_word, "bits_per_word", "counter_slider", int)
        self.top_layout.addWidget(self._bits_per_word_win)
        _binary_output_check_box = Qt.QCheckBox("binary_output")
        self._binary_output_choices = {True: True, False: False}
        self._binary_output_choices_inv = dict((v,k) for k,v in self._binary_output_choices.iteritems())
        self._binary_output_callback = lambda i: Qt.QMetaObject.invokeMethod(_binary_output_check_box, "setChecked", Qt.Q_ARG("bool", self._binary_output_choices_inv[i]))
        self._binary_output_callback(self.binary_output)
        _binary_output_check_box.stateChanged.connect(lambda i: self.set_binary_output(self._binary_output_choices[bool(i)]))
        self.top_layout.addWidget(_binary_output_check_box)
        _ascii_output_check_box = Qt.QCheckBox("ascii_output")
        self._ascii_output_choices = {True: True, False: False}
        self._ascii_output_choices_inv = dict((v,k) for k,v in self._ascii_output_choices.iteritems())
        self._ascii_output_callback = lambda i: Qt.QMetaObject.invokeMethod(_ascii_output_check_box, "setChecked", Qt.Q_ARG("bool", self._ascii_output_choices_inv[i]))
        self._ascii_output_callback(self.ascii_output)
        _ascii_output_check_box.stateChanged.connect(lambda i: self.set_ascii_output(self._ascii_output_choices[bool(i)]))
        self.top_layout.addWidget(_ascii_output_check_box)
        self.capture_tools_bit_sniffer_0 = capture_tools.bit_sniffer(200, hex_output, offset, bits_per_word, False, False, ascii_output, binary_output, 0, scroll)
        msg_meta = pmt.make_dict()
        msg_meta = pmt.dict_add(msg_meta, pmt.to_pmt("freq"), pmt.to_pmt("val"))
        vec1 = [0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,0x01, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00];
        msg_vector = pmt.init_u8vector(len(vec1), vec1)
        msg = pmt.cons(msg_meta, msg_vector)
        self.blocks_message_strobe_0 = blocks.message_strobe(msg, 10)

        ##################################################
        # Connections
        ##################################################
        self.msg_connect((self.blocks_message_strobe_0, 'strobe'), (self.capture_tools_bit_sniffer_0, 'packets'))    
Example #31
0
def make_header(options, filename):
    extras_present = False
    if options.freq is not None:
        extras_present = True
    # Open the file and make the header
    hdr_filename = filename + '.hdr'
    hdr_file = open(hdr_filename, 'wb')
    header = pmt.make_dict()
    # Fill in header vals
    # TODO - Read this from blocks.METADATA_VERSION
    ver_val = pmt.from_long(long(0))
    rate_val = pmt.from_double(options.sample_rate)
    time_val = pmt.make_tuple(pmt.from_uint64(options.time_sec),
                             pmt.from_double(options.time_fsec))
    ft_to_sz = parse_file_metadata.ftype_to_size
    # Map shortname to properties
    enum_type = SNAME_TO_ENUM[options.format]
    type_props = SNAME_DEFS[enum_type]
    size_val = pmt.from_long(type_props[0])
    cplx_val = pmt.from_bool(type_props[1])
    type_val = pmt.from_long(type_props[2])
    fmt = type_props[2]
    file_samp_len = long(options.length)
    seg_size = long(options.seg_size)
    bytes_val = pmt.from_uint64(long(seg_size*ft_to_sz[fmt]))
    # Set header vals
    header = pmt.dict_add(header, pmt.intern("version"), ver_val)
    header = pmt.dict_add(header, pmt.intern("size"), size_val)
    header = pmt.dict_add(header, pmt.intern("type"), type_val)
    header = pmt.dict_add(header, pmt.intern("cplx"), cplx_val)
    header = pmt.dict_add(header, pmt.intern("rx_time"), time_val)
    header = pmt.dict_add(header, pmt.intern("rx_rate"), rate_val)
    header = pmt.dict_add(header, pmt.intern("bytes"), bytes_val)

    if extras_present:
        freq_key = pmt.intern("rx_freq")
        freq_val = pmt.from_double(options.freq)
        extras = pmt.make_dict()
        extras = pmt.dict_add(extras, freq_key, freq_val)
        extras_str = pmt.serialize_str(extras)
        start_val = pmt.from_uint64(blocks.METADATA_HEADER_SIZE
                + len(extras_str))
    else:
        start_val = pmt.from_uint64(blocks.METADATA_HEADER_SIZE)
    header = pmt.dict_add(header, pmt.intern("strt"), start_val)
    num_segments = file_samp_len/seg_size
    if options.verbose:
        print "Wrote %d headers to: %s (Version %d)" % (num_segments+1,
                hdr_filename,pmt.to_long(ver_val))
    for x in range(0,num_segments,1):
        # Serialize and write out file
        if extras_present:
            header_str = pmt.serialize_str(header) + extras_str
        else:
            header_str = pmt.serialize_str(header)
        hdr_file.write(header_str)
        # Update header based on sample rate and segment size
        header = update_timestamp(header,seg_size)
    
    # Last header is special b/c file size is probably not mult. of seg_size
    header = pmt.dict_delete(header,pmt.intern("bytes"))
    bytes_remaining = ft_to_sz[fmt]*(file_samp_len - num_segments*long(seg_size))
    bytes_val = pmt.from_uint64(bytes_remaining)
    header = pmt.dict_add(header,pmt.intern("bytes"),bytes_val)
    # Serialize and write out file
    if extras_present:
        header_str = pmt.serialize_str(header) + extras_str
    else:
        header_str = pmt.serialize_str(header)
    hdr_file.write(header_str)
    hdr_file.close()
 def post_message(self):
     msg_dict = pmt.make_dict()
     msg_dict = pmt.dict_add(msg_dict, pmt.intern("scenario_number"), pmt.from_long(long(self.scenario)))
     msg_dict = pmt.dict_add(msg_dict, pmt.intern("scenario_channels"), pmt.to_pmt([bool(c) for c in self.chan_occupied]))
     msg_dict = pmt.dict_add(msg_dict, pmt.intern("scenario_tau"), pmt.from_long(long(self.scenario_send_window[self.scenario])))
     self.message_port_pub(pmt.intern("scenario"), msg_dict)
Example #33
0
    def test_001(self):
        N = 1000
	outfile = "test_out.dat"

        detached = False
        samp_rate = 200000
        key = pmt.intern("samp_rate")
        val = pmt.from_double(samp_rate)
        extras = pmt.make_dict()
        extras = pmt.dict_add(extras, key, val)
        extras_str = pmt.serialize_str(extras)

        data = sig_source_c(samp_rate, 1000, 1, N)
        src  = blocks.vector_source_c(data)
        fsnk = blocks.file_meta_sink(gr.sizeof_gr_complex, outfile,
                                     samp_rate, 1,
                                     blocks.GR_FILE_FLOAT, True,
                                     1000000, extras_str, detached)
        fsnk.set_unbuffered(True)

	self.tb.connect(src, fsnk)
	self.tb.run()
        fsnk.close()

        handle = open(outfile, "rb")
        header_str = handle.read(parse_file_metadata.HEADER_LENGTH)
        if(len(header_str) == 0):
            self.assertFalse()

        try:
            header = pmt.deserialize_str(header_str)
        except RuntimeError:
            self.assertFalse()

        info = parse_file_metadata.parse_header(header, False)

        extra_str = handle.read(info["extra_len"])
        self.assertEqual(len(extra_str) > 0, True)

        handle.close()

        try:
            extra = pmt.deserialize_str(extra_str)
        except RuntimeError:
            self.assertFalse()

        extra_info = parse_file_metadata.parse_extra_dict(extra, info, False)

        self.assertEqual(info['rx_rate'], samp_rate)
        self.assertEqual(pmt.to_double(extra_info['samp_rate']), samp_rate)


        # Test file metadata source
        src.rewind()
        fsrc = blocks.file_meta_source(outfile, False)
        vsnk = blocks.vector_sink_c()
        tsnk = blocks.tag_debug(gr.sizeof_gr_complex, "QA")
        ssnk = blocks.vector_sink_c()
        self.tb.disconnect(src, fsnk)
        self.tb.connect(fsrc, vsnk)
        self.tb.connect(fsrc, tsnk)
        self.tb.connect(src, ssnk)
        self.tb.run()

        fsrc.close() 
        # Test to make sure tags with 'samp_rate' and 'rx_rate' keys
        # were generated and received correctly.
        tags = tsnk.current_tags()
        for t in tags:
            if(pmt.eq(t.key, pmt.intern("samp_rate"))):
                self.assertEqual(pmt.to_double(t.value), samp_rate)
            elif(pmt.eq(t.key, pmt.intern("rx_rate"))):
                self.assertEqual(pmt.to_double(t.value), samp_rate)

        # Test that the data portion was extracted and received correctly.
        self.assertComplexTuplesAlmostEqual(vsnk.data(), ssnk.data(), 5)

	os.remove(outfile)