Example #1
0
    def testStartStopStart(self):
        self.octetConnect()
        sink = sb.DataSinkSDDS()
        ad_cb = SddsAttachDetachCB()
        sink.registerAttachCallback(ad_cb.attach_cb)
        sink.registerDetachCallback(ad_cb.detach_cb)

        self.comp.connect(sink)
        sb.start()

        fakeData = 1024 * [1]
        fakeData2 = 1024 * [2]
        self.assertEqual(len(ad_cb.get_attach()), 0,
                         "Should not have received any attaches")
        self.source.push(fakeData,
                         EOS=False,
                         streamID=self.id(),
                         sampleRate=1.0,
                         complexData=False,
                         loop=False)
        rcv = self.getPacket()[-1024:]
        self.assertEqual(fakeData, list(struct.unpack('1024B', rcv)))
        self.comp.stop()
        time.sleep(0.1)
        self.comp.start()
        time.sleep(0.1)
        self.source.push(fakeData2,
                         EOS=False,
                         streamID=self.id(),
                         sampleRate=1.0,
                         complexData=False,
                         loop=False)
        rcv = self.getPacket()[-1024:]
        self.assertEqual(fakeData2, list(struct.unpack('1024B', rcv)))
Example #2
0
    def testEndianChange(self):
        self.octetConnect()
        sink = sb.DataSinkSDDS()
        sink._sink = SDDSSink2(sink)  # Work around for framework bug
        sink._snk = sink._sink
        ad_cb = SddsAttachDetachCB()
        sink.registerAttachCallback(ad_cb.attach_cb)
        sink.registerDetachCallback(ad_cb.detach_cb)

        self.comp.connect(sink)
        self.comp.sdds_settings.endian_representation = 0  # Little Endian
        sb.start()

        fakeData = 1024 * [1]
        self.source.push(fakeData,
                         EOS=False,
                         streamID=self.id(),
                         sampleRate=1.0,
                         complexData=False,
                         loop=False)
        time.sleep(1)

        # Check the keywords
        self.comp.stop()
        time.sleep(0.1)
        self.comp.sdds_settings.endian_representation = 1  # Big Endian
        self.comp.start()
        time.sleep(0.1)
        self.source.push(fakeData,
                         EOS=False,
                         streamID=self.id(),
                         sampleRate=1.0,
                         complexData=False,
                         loop=False)
        time.sleep(0.1)
Example #3
0
    def testCxOverride(self):
        self.octetConnect()
        sink = sb.DataSinkSDDS()
        self.comp.override_sdds_header.enabled = True

        for cx in range(2):
            time.sleep(0.1)
            self.comp.override_sdds_header.cx = cx
            sb.start()
            fakeData = 1024 * [1]
            self.source.push(fakeData,
                             EOS=False,
                             streamID=self.id(),
                             sampleRate=1.0,
                             complexData=False,
                             loop=False)
            rcv = self.getPacket()
            self.assertEqual(self.getCx(rcv), cx,
                             "Received CX that did not match expected")
            sb.stop()
Example #4
0
    def testStandardFormat(self):
        self.octetConnect()
        sink = sb.DataSinkSDDS()

        for sf in range(2):
            time.sleep(0.1)
            self.comp.sdds_settings.standard_format = sf
            sb.start()
            fakeData = 1024 * [1]
            self.source.push(fakeData,
                             EOS=False,
                             streamID=self.id(),
                             sampleRate=1.0,
                             complexData=False,
                             loop=False)
            rcv = self.getPacket()
            sdds_header = self.getHeader(rcv)
            self.assertEqual(sdds_header.SF, sf,
                             "Received SF that did not match expected")
            sb.stop()
    def testSingleTunerAllocation(self):
        
        self.comp.start()

        self.fei_dev, alloc_params = self.getAllocationContext(ALLOCATE_RCV)
        
        sink = sb.DataSinkSDDS()
               
        alloc = self._generateAlloc(cf=110e6,sr=0,bw=0)
        allocationID = properties.props_to_dict(alloc)['FRONTEND::tuner_allocation']['FRONTEND::tuner_allocation::allocation_id']
        self.fei_dev.connect(sink,usesPortName = "dataSDDS_out",connectionId=allocationID)
        sink.start()
        
        try:
            retval = self.fei_dev.allocateCapacity(alloc)
        except Exception, e:
            print "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
            print "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
            print "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
            print str(e)
            self.assertFalse("Exception thrown on allocateCapactiy %s" % str(e))
Example #6
0
    def testBPSOverride(self):
        self.octetConnect()
        sink = sb.DataSinkSDDS()
        self.comp.override_sdds_header.enabled = True

        for bps in range(32):
            time.sleep(0.1)
            self.comp.override_sdds_header.bps = bps
            sb.start()
            fakeData = 1024 * [1]
            self.source.push(fakeData,
                             EOS=False,
                             streamID=self.id(),
                             sampleRate=1.0,
                             complexData=False,
                             loop=False)
            rcv = self.getPacket()
            sdds_header = self.getHeader(rcv)
            self.assertEqual(bps, sum(sdds_header.bps),
                             "Received BPS that did not match expected")
            sb.stop()
Example #7
0
    def testDfdtOverride(self):
        self.octetConnect()
        sink = sb.DataSinkSDDS()
        self.comp.override_sdds_header.enabled = True

        for dfdt in [x * .1 for x in range(10)]:
            time.sleep(0.1)
            self.comp.override_sdds_header.dfdt = dfdt
            sb.start()
            fakeData = 1024 * [1]
            self.source.push(fakeData,
                             EOS=False,
                             streamID=self.id(),
                             sampleRate=1.0,
                             complexData=False,
                             loop=False)
            rcv = self.getPacket()
            sdds_header = self.getHeader(rcv)
            self.assertEqual(sdds_header.dfdt, int(1073741824 * dfdt),
                             "Received MSdelta that did not match expected")
            sb.stop()
Example #8
0
    def testFrequencyOverride(self):
        self.octetConnect()
        sink = sb.DataSinkSDDS()
        self.comp.override_sdds_header.enabled = True

        for freq in [x * .1 for x in range(10)]:
            time.sleep(0.1)
            self.comp.override_sdds_header.frequency = freq
            sb.start()
            fakeData = 1024 * [1]
            self.source.push(fakeData,
                             EOS=False,
                             streamID=self.id(),
                             sampleRate=1.0,
                             complexData=False,
                             loop=False)
            rcv = self.getPacket()
            sdds_header = self.getHeader(rcv)
            self.assertEqual(sdds_header.freq, int(73786976294.838211 * freq),
                             "Received freq that did not match expected")
            sb.stop()
Example #9
0
    def testMsptrOverride(self):
        self.octetConnect()
        sink = sb.DataSinkSDDS()
        self.comp.override_sdds_header.enabled = True

        for i in range(10):
            msptr = random.randint(0, 2047)
            time.sleep(0.1)
            self.comp.override_sdds_header.msptr = msptr
            sb.start()
            fakeData = 1024 * [1]
            self.source.push(fakeData,
                             EOS=False,
                             streamID=self.id(),
                             sampleRate=1.0,
                             complexData=False,
                             loop=False)
            rcv = self.getPacket()
            rcv_msptr = self.getMsptr(rcv)
            self.assertEqual(rcv_msptr, msptr,
                             "Received msptr that did not match expected")
            sb.stop()
Example #10
0
    def testMsdelOverride(self):
        self.octetConnect()
        sink = sb.DataSinkSDDS()
        self.comp.override_sdds_header.enabled = True

        for i in range(10):
            msdel = random.randint(0, 65535)
            time.sleep(0.1)
            self.comp.override_sdds_header.msdel = msdel
            sb.start()
            fakeData = 1024 * [1]
            self.source.push(fakeData,
                             EOS=False,
                             streamID=self.id(),
                             sampleRate=1.0,
                             complexData=False,
                             loop=False)
            rcv = self.getPacket()
            sdds_header = self.getHeader(rcv)
            self.assertEqual(sdds_header.timeCode1msDelta, msdel,
                             "Received MSdelta that did not match expected")
            sb.stop()
Example #11
0
    def testReleaseWhileStreaming(self):
        problem = False
        self.octetConnect()
        sink = sb.DataSinkSDDS()
        self.comp.connect(sink)
        sb.start()
        fakeData = 1024 * [10]
        self.source.push(1000 * fakeData,
                         EOS=False,
                         streamID=self.id(),
                         sampleRate=1.0,
                         complexData=False,
                         loop=True)
        time.sleep(1)
        try:
            sb.release()
        except:
            e = sys.exc_info()[0]
            print(type(e.message))
            print("Unexpected error: %s", e)
            problem = True

        self.assertTrue(not problem,
                        "exception was raised while releasing the component")
Example #12
0
    def testMultipleStreamsSamePort(self):
        self.octetConnect()
        sink = sb.DataSinkSDDS()
        ad_cb = SddsAttachDetachCB()
        sink.registerAttachCallback(ad_cb.attach_cb)
        sink.registerDetachCallback(ad_cb.detach_cb)
        self.comp.connect(sink)
        sb.start()

        goodData1 = 1024 * [1]
        deckedStream = 1024 * [2]
        goodData2 = 1024 * [3]

        # No data pushed, no attaches or detaches
        self.assertEqual(
            len(ad_cb.get_attach()), 0,
            "Should not have received any attaches but we have: %s " %
            len(ad_cb.get_attach()))
        #         self.assertEqual(len(ad_cb.get_detach()), 0, "Should not have received any detaches")

        # Push one good packet and confirm it was received
        self.source.push(goodData1,
                         EOS=False,
                         streamID=self.id(),
                         sampleRate=1.0,
                         complexData=False,
                         loop=False)
        self.assertEqual(
            goodData1, list(struct.unpack('1024B',
                                          self.getPacket()[-1024:])))
        # Since we pushed, we should get an attach, no detach
        self.assertEqual(len(ad_cb.get_attach()), 1,
                         "Should have received 1 attach total")
        #         self.assertEqual(len(ad_cb.get_detach()), 0, "Should not have received any detaches")

        # Push a new stream, it should get ignored, confirm we receive no data and still have only a single attach
        self.source.push(deckedStream,
                         EOS=False,
                         streamID="Decked Stream",
                         sampleRate=1.0,
                         complexData=False,
                         loop=False)
        self.assertEqual(
            len(self.getPacket()), 0,
            "Should not have passed on new stream, stream already active")
        self.assertEqual(len(ad_cb.get_attach()), 1,
                         "Should have received 1 attach total")
        #         self.assertEqual(len(ad_cb.get_detach()), 0, "Should not have received any detaches")

        # Push an EOS which should cause a detach
        self.source.push(goodData1,
                         EOS=True,
                         streamID=self.id(),
                         sampleRate=1.0,
                         complexData=False,
                         loop=False)
        self.assertEqual(
            goodData1, list(struct.unpack('1024B',
                                          self.getPacket()[-1024:])))
        time.sleep(1)
        self.source.push(deckedStream,
                         EOS=False,
                         streamID="Decked Stream",
                         sampleRate=1.0,
                         complexData=False,
                         loop=False)
        time.sleep(1)
        self.assertEqual(len(ad_cb.get_attach()), 2,
                         "Should have received 2 attach total")
        #         self.assertEqual(len(ad_cb.get_detach()), 1, "Should have received 1 detach total")

        # Send a new stream, which means a new attach
        self.source.push(goodData2,
                         EOS=False,
                         streamID="Another on the deck stream",
                         sampleRate=1.0,
                         complexData=False,
                         loop=False)
        self.assertEqual(
            deckedStream, list(struct.unpack('1024B',
                                             self.getPacket()[-1024:])))
        self.assertEqual(len(ad_cb.get_attach()), 2,
                         "Should have received 2 attach total")
        #         self.assertEqual(len(ad_cb.get_detach()), 1, "Should have received 1 detach total")

        # Tear stuff down, confirm we get the final detach
        sb.release()
        self.assertEqual(len(ad_cb.get_attach()), 2,
                         "Should have received 2 attach total")
        self.assertEqual(len(ad_cb.get_detach()), 2,
                         "Should have received 2 detach total")
Example #13
0
    def testMultipleStreamsDifferentPort(self):
        self.octetConnect()

        short_source = sb.DataSource()
        short_source.connect(self.comp, usesPortName='shortOut')

        sink = sb.DataSinkSDDS()
        ad_cb = SddsAttachDetachCB()
        sink.registerAttachCallback(ad_cb.attach_cb)
        sink.registerDetachCallback(ad_cb.detach_cb)
        self.comp.connect(sink)
        sb.start()

        goodData1 = 1024 * [1]
        deckedData = 512 * [2]
        goodData2 = 512 * [3]

        # No data pushed, no attaches or detaches
        self.assertEqual(len(ad_cb.get_attach()), 0,
                         "Should not have received any attaches")

        # Push one good packet and confirm it was received
        self.source.push(goodData1,
                         EOS=False,
                         streamID=self.id(),
                         sampleRate=1.0,
                         complexData=False,
                         loop=False)
        self.assertEqual(
            goodData1, list(struct.unpack('1024B',
                                          self.getPacket()[-1024:])))

        # Since we pushed, we should get an attach, no detach
        self.assertEqual(len(ad_cb.get_attach()), 1,
                         "Should have received 1 attach total")

        # Push a new stream, it should get decked, and disabled, confirm we receive no data and still have only a single attach
        short_source.push(deckedData,
                          EOS=False,
                          streamID="Decked Stream",
                          sampleRate=1.0,
                          complexData=False,
                          loop=False)
        self.assertEqual(
            len(self.getPacket()), 0,
            "Should not have passed on new stream, stream already active")
        self.assertEqual(len(ad_cb.get_attach()), 1,
                         "Should have received 1 attach total")

        # Push an EOS which should cause a detach, the decked stream to become active and the goodData pushed and us to have another attach called.
        self.source.push(goodData1,
                         EOS=True,
                         streamID=self.id(),
                         sampleRate=1.0,
                         complexData=False,
                         loop=False)
        self.assertEqual(
            goodData1, list(struct.unpack('1024B',
                                          self.getPacket()[-1024:])))
        time.sleep(2)
        self.assertEqual(len(ad_cb.get_attach()), 2,
                         "Should have received 2 attach total")

        # Push decked data and EOS It.
        short_source.push(deckedData,
                          EOS=True,
                          streamID="Decked Stream",
                          sampleRate=1.0,
                          complexData=False,
                          loop=False)
        self.assertEqual(
            deckedData, list(struct.unpack('!512H',
                                           self.getPacket()[-1024:])))

        # Send a new stream, which means a new attach
        short_source.push(goodData2,
                          EOS=False,
                          streamID="New Stream",
                          sampleRate=1.0,
                          complexData=False,
                          loop=False)
        self.assertEqual(
            goodData2, list(struct.unpack('!512H',
                                          self.getPacket()[-1024:])))
        self.assertEqual(len(ad_cb.get_attach()), 3,
                         "Should have received 3 attach total")

        # Tear stuff down, confirm we get the final detach
        sb.release()
        self.assertEqual(len(ad_cb.get_attach()), 3,
                         "Should have received 3 attach total")
        self.assertEqual(len(ad_cb.get_detach()), 3,
                         "Should have received 3 detach total")