Example #1
0
    def testUnicastTTVBecomesTrue(self):

        self.setupComponent()

        # Get ports
        sink = sb.DataSink()

        # Connect components
        self.comp.connect(sink, providesPortName='octetIn')

        # Start components
        self.comp.start()
        sink.start()

        # Create data
        fakeData = [x % 256 for x in range(1024)]

        # Create packets and send
        # 2112 assumes every 31st packet is a parity packet.
        for i in range(0, 2112):
            if i != 0 and i % 32 == 31:
                continue  # skip parity packet
            if i <= 500:
                h = Sdds.SddsHeader(i,
                                    DM=[0, 0, 1],
                                    BPS=[0, 1, 0, 0, 0],
                                    TTV=0,
                                    TT=i,
                                    FREQ=60000000)
                p = Sdds.SddsCharPacket(h.header, fakeData)
                p.encode()
                self.userver.send(p.encodedPacket)
            elif i > 500:
                h = Sdds.SddsHeader(i,
                                    DM=[0, 0, 1],
                                    BPS=[0, 1, 0, 0, 0],
                                    TTV=1,
                                    TT=i,
                                    FREQ=60000000)
                p = Sdds.SddsCharPacket(h.header, fakeData)
                p.encode()
                self.userver.send(p.encodedPacket)

        # Wait for data to be received
        time.sleep(3)
        data = sink.getData()

        # Validate correct amount of data was received
        self.assertEqual(len(data), 2095104)
        self.assertEqual(self.comp.status.dropped_packets, 0)

        sink.stop()
Example #2
0
    def testMergeBulkIOSRI(self):
        # Get ports
        compDataShortOut_out = self.comp.getPort('dataShortOut')

        # Connect components
        self.comp.connect(self.sink, providesPortName='shortIn')
        
        # Here we are using the BULKIO SRI with a modified xdelta and complex flag but the sdds xdelta and cx should merge in
        sri = BULKIO.StreamSRI(hversion=1, xstart=0.0, xdelta=1.234e-9, xunits=1, subsize=0, ystart=0.0, ydelta=0.0, yunits=0, mode=0, streamID='StreamID1234', blocking=False, keywords=[])
        self.setupComponent(sri=sri)
            
        # Start components
        self.comp.start()
        
        # Create data
        fakeData = [x for x in range(0, 512)]
        
        h = Sdds.SddsHeader(0, CX=1)
        p = Sdds.SddsShortPacket(h.header, fakeData)
        p.encode() # Defaults to big endian encoding
        self.userver.send(p.encodedPacket)
        time.sleep(0.05)
        data,stream = self.getData()
        sri_rx = stream.sri
        
        self.assertNotEqual(sri_rx.mode, sri.mode, "SDDS Packet Mode should have overridden the supplied SRI")
        self.assertNotEqual(sri_rx.xdelta, sri.xdelta, "SDDS Packet xdelta should have overridden the supplied SRI")
        self.assertEqual(sri_rx.streamID, sri.streamID, "Output SRI StreamID should have been inherited from the SRI")
Example #3
0
    def testUnicastFloatPort(self):
        """Sends unicast data to the float port and asserts the data sent equals the data received"""

        self.setupComponent()
        
        # Get ports
        compDataFloatOut_out = self.comp.getPort('dataFloatOut')
 
        # Connect components
        self.comp.connect(self.sink, providesPortName='floatIn')
        
        #Start components.
        self.comp.start()

        # Create data
        fakeData = [float(x) for x in range(0, 256)]
        
        # Create packet and send
        h = Sdds.SddsHeader(0, DM = [0, 1, 0], BPS = [1, 1, 1, 1, 1], TTV = 1, TT = 0)
        p = Sdds.SddsFloatPacket(h.header, fakeData)
        p.encode()
        self.userver.send(p.encodedPacket)

        # Wait for data to be received
        time.sleep(1)
        
        # Get data
        data,stream = self.getData()
        
        # Validate correct amount of data was received
        self.assertEqual(len(data), 256)
        
        # Validate data is correct
        self.assertEqual(fakeData, list(struct.unpack('256f', struct.pack('<256f', *data))))
        self.assertEqual(self.comp.status.dropped_packets, 0)
Example #4
0
    def testUnicastShortPort(self):

        self.setupComponent()
        
        # Get ports
        compDataShortOut_out = self.comp.getPort('dataShortOut')

        # Connect components
        self.comp.connect(self.sink, providesPortName='shortIn')
        
        # Start components
        self.comp.start()

        # Create data
        fakeData = [x for x in range(0, 512)]
        
        # Create packet and send
        h = Sdds.SddsHeader(0, DM = [0, 1, 0], TTV = 1, TT = 0)
        p = Sdds.SddsShortPacket(h.header, fakeData)
        p.encode()
        self.userver.send(p.encodedPacket)
        
        # Wait for data to be received
        time.sleep(1)
        
        # Get data
        data,stream = self.getData()
        
        # Validate correct amount of data was received
        self.assertEqual(len(data), 512)

        # Validate data is correct        
        self.assertEqual(fakeData, list(struct.unpack('>512H', struct.pack('>512H', *data))))
Example #5
0
    def testUnicastCxBit(self):
        
        self.setupComponent()
        
        # Get ports
        compDataShortOut_out = self.comp.getPort('dataShortOut')

        # Connect components
        self.comp.connect(self.sink, providesPortName='shortIn')
        
        # Start components
        self.comp.start()
        
        # Create data
        fakeData = [x for x in range(0, 512)]
        
        # Create packet and send
        h = Sdds.SddsHeader(0, SF = 0, TTV = 1, TT = 7820928000000000000, CX = 1, DM = [0, 1, 0])
        p = Sdds.SddsShortPacket(h.header, fakeData)
        p.encode()
        self.userver.send(p.encodedPacket)

        # Wait for data to be received
        time.sleep(1)
        
        data,stream = self.getData()
        
        # Validate sri mode is correct
        self.assertEqual(stream.sri.mode, 1)
Example #6
0
    def testShortBigEndianness(self):
        self.setupComponent(endianness=BIG_ENDIAN)

        # Get ports
        compDataShortOut_out = self.comp.getPort('dataShortOut')

        sink = sb.DataSink()

        # Connect components
        self.comp.connect(sink, providesPortName='shortIn')

        # Start components
        self.comp.start()
        sink.start()

        # Create data
        fakeData = [x for x in range(0, 512)]

        h = Sdds.SddsHeader(0)
        p = Sdds.SddsShortPacket(h.header, fakeData)
        p.encode()  # Defaults to big endian encoding
        self.userver.send(p.encodedPacket)
        time.sleep(0.05)
        data = sink.getData()

        self.assertEqual(self.comp.status.input_endianness, "4321",
                         "Status property for endianness is not 4321")
        self.assertEqual(data, fakeData,
                         "Big Endian short did not match expected")
Example #7
0
    def testUnicastBadFsn(self):

        self.setupComponent()
        
        # Get ports
        compDataShortOut_out = self.comp.getPort('dataShortOut')
        
        # Connect components
        self.comp.connect(self.sink, providesPortName='shortIn')
        
        # Start components
        self.comp.start()

        # Create data
        fakeData = [x for x in range(0, 512)]
        
        # Create packets and send 
        for i in range(0, 2):
            h = Sdds.SddsHeader(1)
            p = Sdds.SddsShortPacket(h.header, fakeData)
            p.encode()
            self.userver.send(p.encodedPacket)

        # Wait for data to be received
        time.sleep(1)
        
        # Get data
        data,stream = self.getData()
        
        # Validate correct amount of data was received
        self.assertEqual(len(data), 1024)
        self.assertEqual(2*fakeData, list(struct.unpack('>1024H', struct.pack('>1024H', *data[:]))))
        self.assertEqual(self.comp.status.dropped_packets, 65535)
Example #8
0
    def testShortLittleEndianness(self):
        self.setupComponent(endianness=LITTLE_ENDIAN)
        
        # Get ports
        compDataShortOut_out = self.comp.getPort('dataShortOut')

        # Connect components
        self.comp.connect(self.sink, providesPortName='shortIn')
        
        # Start components
        self.comp.start()
        
        # Create data
        fakeData = [x for x in range(0, 512)]
        # Byte Swap it here to make it little endian on send since encode does big endian (swap)
        fakeData_bs = list(struct.unpack('>512H', struct.pack('@512H', *fakeData)))
        
        # Convert fakeData to BIG ENDIAN
        h = Sdds.SddsHeader(0)
        p = Sdds.SddsShortPacket(h.header, fakeData_bs)
        p.encode() # Defaults to big endian encoding
        self.userver.send(p.encodedPacket)
        time.sleep(0.05)
        data,stream = self.getData()
        
        self.assertEqual(self.comp.status.input_endianness, "1234", "Status property for endianness is not 1234")
        self.assertEqual(data, fakeData, "Little Endian short did not match expected")
Example #9
0
    def testNewYear(self):
        self.setupComponent()
        
        # Get ports
        compDataShortOut_out = self.comp.getPort('dataShortOut')
            
        # Start components
        self.comp.start()

        # Create data
        fakeData = [x for x in range(0, 512)]
        pktNum = 0
        
        sr=1e6
        xdelta_ns=int(1/sr * 1e9)
        ns_in_year = 1e9*31536000
        time_ns=ns_in_year - xdelta_ns*512*20
        
        # No time slips here
        while pktNum < 100:
            # Create data
            h = Sdds.SddsHeader(pktNum, FREQ=(sr*73786976294.838211), TT=(time_ns*4))
            p = Sdds.SddsShortPacket(h.header, fakeData)
            p.encode()
            self.userver.send(p.encodedPacket)
            pktNum = pktNum + 1
            
            if pktNum != 0 and pktNum % 32 == 31:
                pktNum = pktNum + 1
                
            time_ns = time_ns + 512*xdelta_ns
            if time_ns > ns_in_year:
                time_ns = time_ns - ns_in_year
            
        self.assertEqual(self.comp.status.time_slips, 0, "There should be no time slips!")
Example #10
0
    def testUnicastOctetPort(self):
        """Sends unicast data to the octet port and asserts the data sent equals the data received"""

        self.setupComponent()
        
        # Get ports
        compDataOctetOut_out = self.comp.getPort('dataOctetOut')

        # Connect components
        self.comp.connect(self.sink, providesPortName='octetIn')

        # Start components
        self.comp.start()

        # Create data
        fakeData = [x % 256 for x in range(1024)]

        # Create packet and send
        h = Sdds.SddsHeader(0, DM = [0, 0, 1], BPS = [0, 1, 0, 0, 0], TTV = 1, TT = 0, FREQ = 60000000)
        p = Sdds.SddsCharPacket(h.header, fakeData)
        p.encode()
        self.userver.send(p.encodedPacket)

        # Wait for data to be received
        time.sleep(1)
        
        # Get data
        data,stream = self.getData()
        
        # Validate correct amount of data was received
        self.assertEqual(len(data), 1024)
        # Validate data is correct
        self.assertEqual([chr(i) for i in data[:256]], list(struct.pack('256B', *fakeData[:256])))
        self.assertEqual(self.comp.status.dropped_packets, 0)
Example #11
0
    def testRestart(self):
        """Checks that an Component will run after being stopped without a new attach """
        self.setupComponent()
        
        # Get ports
        compDataFloatOut_out = self.comp.getPort('dataShortOut')
        
        # Connect components
        self.comp.connect(self.sink, providesPortName='shortIn')

        # Start components
        self.comp.start()
        
        compDataSddsIn = self.comp.getPort('dataSddsIn')

        # Create data
        fakeData = [x for x in range(0, 512)]
        
        # Create packet and send
        h = Sdds.SddsHeader(0, DM = [0, 1, 0], TTV = 1, TT = 0)
        p = Sdds.SddsShortPacket(h.header, fakeData)
        p.encode()
        self.userver.send(p.encodedPacket)


        # Wait for data to be received
        time.sleep(1)
        
        # Get data
        data,stream = self.getData()
        
        # Validate correct amount of data was received
        self.assertEqual(len(data), 512)

        # Validate data is correct        
        self.assertEqual(fakeData, list(struct.unpack('>512H', struct.pack('>512H', *data))))
        
        self.comp.stop()
        
        time.sleep(1)
        # Get data
        data,stream = self.getData()
         
        self.assertTrue(stream.eos)
        
        #Restart Component and send more data
        self.comp.start()
        self.userver.send(p.encodedPacket)      
        
        # Wait for data to be received
        time.sleep(1)
        
        # Get data
        data,stream = self.getData()
        
        # Validate correct amount of data was received
        self.assertEqual(len(data), 512)

        # Validate data is correct        
        self.assertEqual(fakeData, list(struct.unpack('>512H', struct.pack('>512H', *data))))  
Example #12
0
    def testUseBulkIOSRI(self):

        # Get ports
        compDataShortOut_out = self.comp.getPort('dataShortOut')

        sink = sb.DataSink()

        # Connect components
        self.comp.connect(sink, providesPortName='shortIn')

        # Here we are using the BULKIO SRI with a modified xdelta and complex flag.
        kw = [
            CF.DataType("BULKIO_SRI_PRIORITY",
                        ossie.properties.to_tc_value(1, 'long'))
        ]
        sri = BULKIO.StreamSRI(hversion=1,
                               xstart=0.0,
                               xdelta=1.234e-9,
                               xunits=1,
                               subsize=0,
                               ystart=0.0,
                               ydelta=0.0,
                               yunits=0,
                               mode=0,
                               streamID='TestStreamID',
                               blocking=False,
                               keywords=kw)
        self.setupComponent(sri=sri)

        # Start components
        self.comp.start()
        sink.start()

        # Create data
        fakeData = [x for x in range(0, 512)]

        h = Sdds.SddsHeader(0, CX=1)
        p = Sdds.SddsShortPacket(h.header, fakeData)
        p.encode()  # Defaults to big endian encoding
        self.userver.send(p.encodedPacket)
        time.sleep(0.05)
        data = sink.getData()
        sri_rx = sink.sri()

        # compareSRI does not work for CF.DataType with keywords so we check those first then zero them out
        self.assertEqual(sri.keywords[0].id, sri_rx.keywords[0].id,
                         "SRI Keyword ID do not match")
        self.assertEqual(sri.keywords[0].value.value(),
                         sri_rx.keywords[0].value.value(),
                         "SRI Keyword Value do not match")
        self.assertEqual(sri.keywords[0].value.typecode(),
                         sri_rx.keywords[0].value.typecode(),
                         "SRI Keyword Type codes do not match")
        sri.keywords = []
        sri_rx.keywords = []
        self.assertTrue(compareSRI(sri, sri_rx),
                        "Attach SRI does not match received SRI")
Example #13
0
 def testBulkIOTiming(self):
     self.setupComponent()
     
     # Get ports
     compDataShortOut_out = self.comp.getPort('dataShortOut')
     
     # Connect components
     self.comp.connect(self.sink, providesPortName='shortIn')
         
     # Start components
     self.comp.start()
     
     # Create data
     fakeData = [x for x in range(0, 512)]
     pktNum = 0
     
     sr=1e6
     xdelta_ns=int(1/(sr) * 1e9)
     time_ns=0
     
     # No time slips here
     while pktNum < 100:
         # Create data
         h = Sdds.SddsHeader(pktNum, FREQ=(sr*73786976294.838211), TT=(time_ns*4), CX=1)
         p = Sdds.SddsShortPacket(h.header, fakeData)
         p.encode()
         self.userver.send(p.encodedPacket)
         pktNum = pktNum + 1
         
         if pktNum != 0 and pktNum % 32 == 31:
             pktNum = pktNum + 1
             
         time_ns = time_ns + 512*xdelta_ns
         
     time.sleep(0.5)
     data,stream,tsamps = self.getData(wanttstamps=True)
     
     now = datetime.datetime.utcnow()
     first_of_year = datetime.datetime(now.year, 1, 1, tzinfo=UTC())
     begin_of_time = datetime.datetime(1970, 1, 1, tzinfo=UTC())
     
     seconds_since_new_year = timedelta_total_seconds(first_of_year - begin_of_time)
     
     expected_time_ns = 0
     
     # So we expect the received bulkIO stream to be the start of the year + the time delta from the sample rate.
     for bulkIO_time in tsamps:
         twsec = bulkIO_time[1].twsec
         tfsec = bulkIO_time[1].tfsec
         self.assertEqual(twsec, seconds_since_new_year, "BulkIO time stamp does not match received SDDS time stamp")
         self.assertEqual(tfsec, expected_time_ns/1.0e9)
         expected_time_ns = expected_time_ns + 512*xdelta_ns
Example #14
0
    def testWaitOnTTV(self):
        '''
        Wait on TTV will send nothing unless the pkt contains a TTV flag
        '''
        self.setupComponent(pkts_per_push=10)

        # Get ports
        compDataShortOut_out = self.comp.getPort('dataShortOut')

        self.comp.advanced_configuration.wait_on_ttv = True

        sink = sb.DataSink()

        # Connect components
        self.comp.connect(sink, providesPortName='shortIn')

        # Start components
        self.comp.start()
        sink.start()
        ttv = 0
        pktNum = 0
        num_changes = 0

        # We'll do a ttv change every 7th packet
        while pktNum < 100:

            if pktNum % 7 == 0:
                ttv = (ttv + 1) % 2  # aka if 0 become 1, if 1 become 0
                num_changes += 1

            # Create data
            fakeData = [x for x in range(0, 512)]
            h = Sdds.SddsHeader(pktNum, TTV=ttv)
            p = Sdds.SddsShortPacket(h.header, fakeData)
            p.encode()
            self.userver.send(p.encodedPacket)
            pktNum = pktNum + 1
            if pktNum != 0 and pktNum % 32 == 31:
                pktNum = pktNum + 1

            time.sleep(0.05)

        data = sink.getData(tstamps=True)
        self.assertEqual(
            num_changes / 2, len(data[1]),
            "The number of bulkIO pushes (" + str(len(data[1])) +
            ") does not match the expected (" + str(num_changes / 2) + ").")

        self.comp.stop()
        sink.stop()
Example #15
0
    def getHeader(self, p):
        SF_MASK = (1 << 7 + 8)
        SOS_MASK = (1 << 6 + 8)
        PP_MASK = (1 << 5 + 8)
        OF_MASK = (1 << 4 + 8)
        SS_MASK = (1 << 3 + 8)
        DM_MASK = (7 << 0 + 8)

        CX_MASK = (1 << 7)
        BPS_MASK = (31 << 0)

        MSV_MASK = (1 << 7 + 8)
        TTV_MASK = (1 << 6 + 8)
        SSV_MASK = (1 << 5 + 8)

        tlen = len(p[:56])
        self.assertEqual(tlen, 56,
                         "Incorrect SDDS header len (" + str(tlen) + ")")

        raw_header = struct.unpack('>HHHHQLLQ24B', p[:56])
        SF = (raw_header[0] & SF_MASK) >> (7 + 8)
        SoS = (raw_header[0] & SOS_MASK) >> (6 + 8)
        PP = (raw_header[0] & PP_MASK) >> (5 + 8)
        OF = (raw_header[0] & OF_MASK) >> (4 + 8)
        SS = (raw_header[0] & SS_MASK) >> (3 + 8)
        DM = (raw_header[0] & DM_MASK) >> (0 + 8)
        DM = [DM & 1 << 2, DM & 1 << 1, DM & 1 << 0]
        CX = raw_header[0] & CX_MASK
        BPS = raw_header[0] & BPS_MASK
        BPS = [
            BPS & 1 << 4, BPS & 1 << 3, BPS & 1 << 2, BPS & 1 << 1,
            BPS & 1 << 0
        ]

        FSN = raw_header[1]

        MSV = (raw_header[2] & MSV_MASK) >> 7 + 8
        TTV = (raw_header[2] & TTV_MASK) >> 6 + 8
        SSV = (raw_header[2] & SSV_MASK) >> 5 + 8

        DFDT = raw_header[6]
        FREQ = raw_header[7]

        # TODO: Fix these by shifting them down
        MSD = raw_header[3]
        TT = raw_header[4]
        TTE = raw_header[5]
        return Sdds.SddsHeader(FSN, SF, SoS, PP, OF, SS, DM, BPS, MSV, TTV,
                               SSV, MSD, TT, TTE, DFDT, FREQ)
Example #16
0
    def testEOSonDetach(self):
        """Checks that an EOS is sent on Detach"""
        self.setupComponent()

        # Get ports
        compDataFloatOut_out = self.comp.getPort('dataShortOut')

        sink = sb.DataSink()

        # Connect components
        self.comp.connect(sink, providesPortName='shortIn')

        # Start components
        self.comp.start()
        sink.start()

        compDataSddsIn = self.comp.getPort('dataSddsIn')

        # Create data
        fakeData = [x for x in range(0, 512)]

        # Create packet and send
        h = Sdds.SddsHeader(0, DM=[0, 1, 0], TTV=1, TT=0)
        p = Sdds.SddsShortPacket(h.header, fakeData)
        p.encode()
        self.userver.send(p.encodedPacket)

        # Wait for data to be received
        time.sleep(1)

        # Get data
        data = sink.getData()

        # Validate correct amount of data was received
        self.assertEqual(len(data), 512)

        # Validate data is correct
        self.assertEqual(
            fakeData, list(struct.unpack('>512H', struct.pack('>512H',
                                                              *data))))

        #Send Detach
        compDataSddsIn.detach(self.attachId)
        time.sleep(1)

        data = sink.getData()
        self.assertTrue(sink.eos())
Example #17
0
    def testXDeltaChange(self):
        self.setupComponent()

        # Get ports
        compDataShortOut_out = self.comp.getPort('dataShortOut')

        sink = sb.DataSink()
        # Connect components
        self.comp.connect(sink, providesPortName='shortIn')

        # Start components
        self.comp.start()
        sink.start()

        # Create data
        fakeData = [x for x in range(0, 512)]
        pktNum = 0

        sr = 1e6
        xdelta_ns = int(1 / (sr) * 1e9)
        time_ns = 0

        # No time slips here
        while pktNum < 100:
            # Create data
            h = Sdds.SddsHeader(pktNum,
                                FREQ=(sr * 73786976294.838211),
                                TT=(time_ns * 4),
                                CX=1)
            p = Sdds.SddsShortPacket(h.header, fakeData)
            p.encode()
            self.userver.send(p.encodedPacket)
            pktNum = pktNum + 1

            if pktNum != 0 and pktNum % 32 == 31:
                pktNum = pktNum + 1

            time_ns = time_ns + 512 * xdelta_ns
            if pktNum > 50:
                sr = 1e6 * 4
                xdelta_ns = int(1 / (sr) * 1e9)

        time.sleep(0.5)
        self.assertEqual(
            self.comp.status.time_slips, 0,
            "There should be no time slips! However %s reported" %
            self.comp.status.time_slips)
Example #18
0
    def testEmptyInterface(self):

        self.setupComponent()
        self.comp.interface = ''

        # Get ports
        compDataOctetOut_out = self.comp.getPort('dataOctetOut')

        # Set properties
        sink = sb.DataSink()
        # Connect components
        self.comp.connect(sink, providesPortName='octetIn')

        # Start components
        self.comp.start()
        sink.start()

        # Create data
        fakeData = [x % 256 for x in range(1024)]

        # Create packet and send
        h = Sdds.SddsHeader(0,
                            DM=[0, 0, 1],
                            BPS=[0, 1, 0, 0, 0],
                            TTV=1,
                            TT=0,
                            FREQ=60000000)
        p = Sdds.SddsCharPacket(h.header, fakeData)
        p.encode()
        self.userver.send(p.encodedPacket)

        # Wait for data to be received
        time.sleep(1)

        # Get data
        data = sink.getData()

        # Validate correct amount of data was received
        self.assertEqual(len(data), 1024)
        # Validate data is correct
        self.assertEqual(data[:256], list(struct.pack('256B',
                                                      *fakeData[:256])))
        self.assertEqual(self.comp.status.dropped_packets, 0)

        sink.stop()
Example #19
0
    def testSddsPacketsPerBulkIOPush(self):
        self.setupComponent()
        
        # Get ports
        compDataShortOut_out = self.comp.getPort('dataShortOut')
        sdds_pkts_per_push = (1, 2, 4, 8, 16, 32, 64)



        for pkts_per_push in sdds_pkts_per_push:
            self.comp.advanced_optimizations.sdds_pkts_per_bulkio_push = pkts_per_push

            # Start components
            self.comp.start()

            num_sends = 0
            data = []
            

            sink = sb.StreamSink()
            self.comp.connect(sink, providesPortName='shortIn')
            
            while (not(data) and num_sends < 3*max(sdds_pkts_per_push)):
                # Create data
                fakeData = [x for x in range(0, 512)]
                h = Sdds.SddsHeader(num_sends)
                p = Sdds.SddsShortPacket(h.header, fakeData)
                p.encode()
                self.userver.send(p.encodedPacket)
                num_sends = num_sends + 1
                if num_sends != 0 and num_sends % 32 == 31:
                    num_sends = num_sends + 1
                    
                time.sleep(0.05)               
                packet = sink.port.getPacket()
                if packet.dataBuffer:
                    data = packet.dataBuffer

            # Validate correct amount of data was received
            self.assertEqual(len(data), pkts_per_push * 512)
            self.comp.stop()
Example #20
0
    def testUseBulkIOSRI(self):
        
        # Get ports
        compDataShortOut_out = self.comp.getPort('dataShortOut')

        # Connect components
        self.comp.connect(self.sink, providesPortName='shortIn')
        
        # Here we are using the BULKIO SRI with a modified xdelta and complex flag.
        # Adding other keywords to ensure they are passed through correctly
        kw=[CF.DataType("BULKIO_SRI_PRIORITY", ossie.properties.to_tc_value(1, 'long'))]
        kw.append(CF.DataType("Test_Keyword_string", ossie.properties.to_tc_value('test', 'string')))
        kw.append(CF.DataType("Test_Keyword_long", ossie.properties.to_tc_value(10, 'long')))
        kw.append(CF.DataType("COL_RF", ossie.properties.to_tc_value(100000000, 'double')))
        sri = BULKIO.StreamSRI(hversion=1, xstart=0.0, xdelta=1.234e-9, xunits=1, subsize=0, ystart=0.0, ydelta=0.0, yunits=0, mode=0, streamID='TestStreamID', blocking=False, keywords=kw)
        self.setupComponent(sri=sri)
        
        # Start components
        self.comp.start()
        
        # Create data
        fakeData = [x for x in range(0, 512)]
        
        h = Sdds.SddsHeader(0, CX=1)
        p = Sdds.SddsShortPacket(h.header, fakeData)
        p.encode() # Defaults to big endian encoding
        self.userver.send(p.encodedPacket)
        time.sleep(0.05)
        data,stream = self.getData()
        sri_rx = stream.sri
        
        # compareSRI does not work for CF.DataType with keywords so we check those first then zero them out
        for index,keyword in enumerate(sri.keywords):
            self.assertEqual(keyword.id, sri_rx.keywords[index].id, "SRI Keyword ID do not match")
            self.assertEqual(keyword.value.value(), sri_rx.keywords[index].value.value(), "SRI Keyword Value do not match")
            self.assertEqual(keyword.value.typecode().kind(), sri_rx.keywords[index].value.typecode().kind(), "SRI Keyword Type codes do not match")

        sri.keywords = []
        sri_rx.keywords = []
        self.assertTrue(compareSRI(sri, sri_rx), "Attach SRI does not match received SRI")
Example #21
0
    def testTimeSlips(self):
        self.setupComponent()
        
        # Get ports
        compDataShortOut_out = self.comp.getPort('dataShortOut')

        # Start components
        self.comp.start()

        # Create data
        fakeData = [x for x in range(0, 512)]
        pktNum = 0
        
        sr=1e6
        xdelta_ns=int(1/sr * 1e9)
        time_ns=0
        
        # No time slips here
        while pktNum < 100:
            # Create data
            h = Sdds.SddsHeader(pktNum, FREQ=(sr*73786976294.838211), TT=(time_ns*4))
            p = Sdds.SddsShortPacket(h.header, fakeData)
            p.encode()
            self.userver.send(p.encodedPacket)
            pktNum = pktNum + 1
            
            if pktNum != 0 and pktNum % 32 == 31:
                pktNum = pktNum + 1
                
            time_ns = time_ns + 512*xdelta_ns
            
        self.assertEqual(self.comp.status.time_slips, 0, "There should be no time slips!")
        
        # Introduce accumulator time slip
        while pktNum < 200:
            # Create data
            h = Sdds.SddsHeader(pktNum, FREQ=(sr*73786976294.838211), TT=(time_ns*4))
            p = Sdds.SddsShortPacket(h.header, fakeData)
            p.encode()
            self.userver.send(p.encodedPacket)
            pktNum = pktNum + 1
            
            if pktNum != 0 and pktNum % 32 == 31:
                pktNum = pktNum + 1
                
            time_ns = time_ns + 512*xdelta_ns + 15 # The additional 15 ps is enough for ana cumulator time slip
            
        self.assertEqual(self.comp.status.time_slips, 1, "There should be one time slip from the accumulator")
        
        # Introduce one jump time slip
        while pktNum < 300:
            # Create data
            h = Sdds.SddsHeader(pktNum, FREQ=(sr*73786976294.838211), TT=(time_ns*4))
            p = Sdds.SddsShortPacket(h.header, fakeData)
            p.encode()
            self.userver.send(p.encodedPacket)
            pktNum = pktNum + 1
            
            if pktNum == 245:
                time_ns += 5000
            
            if pktNum != 0 and pktNum % 32 == 31:
                pktNum = pktNum + 1
                
            time_ns = time_ns + 512*xdelta_ns
            
        self.assertEqual(self.comp.status.time_slips, 2, "There should be one time slip from the jump time slip!")
Example #22
0
    def testNonConformingConformingSwitch(self):
        self.setupComponent()
        
        # Get ports
        compDataShortOut_out = self.comp.getPort('dataShortOut')
        compDataSddsIn = self.comp.getPort('dataSddsIn')
        
        # Connect components
        self.comp.connect(self.sink, providesPortName='shortIn')
            
        # Start components
        self.comp.start()
        
        # Create data
        fakeData = [x for x in range(0, 512)]
        pktNum = 0
        
        sr=1e6
        xdelta_ns=int(1/(sr*2) * 1e9)
        time_ns=0
        
        recSRI = False
        # No time slips here
        while pktNum < 100:
            # Create data
            h = Sdds.SddsHeader(pktNum, FREQ=(sr*73786976294.838211), TT=(time_ns*4), CX=1)
            p = Sdds.SddsShortPacket(h.header, fakeData)
            p.encode()
            self.userver.send(p.encodedPacket)
            pktNum = pktNum + 1
            
            if pktNum != 0 and pktNum % 32 == 31:
                pktNum = pktNum + 1
                
            time_ns = time_ns + 512*xdelta_ns
            
        self.assertEqual(self.comp.status.time_slips, 0, "There should be no time slips!")
        
        # Stop the component, detach, then re-attach a new stream that is using the conforming sampleRate
        self.comp.stop()
        
        compDataSddsIn.detach(self.attachId)
        
        kw = [CF.DataType("dataRef", ossie.properties.to_tc_value(BIG_ENDIAN, 'long'))]
        sri = BULKIO.StreamSRI(hversion=1, xstart=0.0, xdelta=1.0, xunits=1, subsize=0, ystart=0.0, ydelta=0.0, yunits=0, mode=0, streamID='TestStreamID2', blocking=False, keywords=kw)
            
        compDataSddsIn.pushSRI(sri,timestamp.now())  
        
        streamDef = BULKIO.SDDSStreamDefinition('id2', BULKIO.SDDS_SI, self.uni_ip, 0, self.port, 8000, True, 'testing')
        self.attachId = compDataSddsIn.attach(streamDef, 'test') 

        self.comp.start()
        # Create data
        fakeData = [x for x in range(0, 512)]
        pktNum = 0
        
        sr=1e6
        xdelta_ns=int(1/(sr) * 1e9)
        time_ns=0
        
        recSRI = False
        # No time slips here
        while pktNum < 100:
            # Create data
            h = Sdds.SddsHeader(pktNum, FREQ=(sr*73786976294.838211), TT=(time_ns*4), CX=1)
            p = Sdds.SddsShortPacket(h.header, fakeData)
            p.encode()
            self.userver.send(p.encodedPacket)
            pktNum = pktNum + 1
            
            if pktNum != 0 and pktNum % 32 == 31:
                pktNum = pktNum + 1
                
            time_ns = time_ns + 512*xdelta_ns
            
        self.assertEqual(self.comp.status.time_slips, 0, "There should be no time slips!")
Example #23
0
    def testRestartAfterDetach(self):
        """Checks that an Component will run after being detached and reattached without stopping """
        self.setupComponent()
        
        # Get ports
        compDataFloatOut_out = self.comp.getPort('dataShortOut')
 
        # Connect components
        self.comp.connect(self.sink, providesPortName='shortIn')

        # Start components
        self.comp.start()
        
        compDataSddsIn = self.comp.getPort('dataSddsIn')

        # Create data
        fakeData = [x for x in range(0, 512)]
        
        # Create packet and send
        h = Sdds.SddsHeader(0, DM = [0, 1, 0], TTV = 1, TT = 0)
        p = Sdds.SddsShortPacket(h.header, fakeData)
        p.encode()
        self.userver.send(p.encodedPacket)

        # Wait for data to be received
        time.sleep(1)
        
        # Get data
        data,stream = self.getData()
        
        # Validate correct amount of data was received
        self.assertEqual(len(data), 512)

        # Validate data is correct        
        self.assertEqual(fakeData, list(struct.unpack('>512H', struct.pack('>512H', *data))))
        
        
        #Send Detach
        compDataSddsIn.detach(self.attachId )
        time.sleep(1)
        
        # Get data
        data,stream = self.getData()
                
        self.assertTrue(stream.eos)
        
        #Re-Attach
        streamDef = BULKIO.SDDSStreamDefinition('id', BULKIO.SDDS_SI, self.uni_ip, 0, self.port, 8000, True, 'testing')
        
        # Try to attach
        self.attachId = ''
        
        try:
            self.attachId = compDataSddsIn.attach(streamDef, 'test') 
        except:
            print "ATTACH FAILED"
            attachId = ''
        
        self.assertTrue(self.attachId != '', "Failed to attach to SourceSDDS component")
        
        #Resend Data
        self.userver.send(p.encodedPacket)      
        
        # Wait for data to be received
        time.sleep(1)
        
        # Get data
        data,stream = self.getData()
        
        # Validate correct amount of data was received
        self.assertEqual(len(data), 512)

        # Validate data is correct        
        self.assertEqual(fakeData, list(struct.unpack('>512H', struct.pack('>512H', *data))))