Ejemplo n.º 1
0
    def _check_FileSourceTimecode(self, hdr, data, framesize, delta):
        # Put a known timecode value into the header and write out the data
        start = bulkio.timestamp.now()
        hdr['timecode'] = bluefile_helpers.unix_to_j1950(start.twsec +
                                                         start.tfsec)
        filename = self._tempfileName('source_timecode_%d_%s' %
                                      (hdr['type'], hdr['format']))
        bluefile.write(filename, hdr, data)

        # Bytes per push is chosen specifically to require multiple packets
        source = sb.FileSource(filename,
                               bytesPerPush=2048,
                               midasFile=True,
                               dataFormat='float')
        sink = sb.DataSink()
        source.connect(sink)
        sb.start()

        # There should have been at least two push packets (plus one more for
        # the end-of-stream, but that's not strictly required)
        outdata, tstamps = sink.getData(eos_block=True, tstamps=True)
        self.assertTrue(len(tstamps) >= 2)

        # Check that the first timestamp (nearly) matches the timestamp created
        # above
        offset, ts = tstamps[0]
        self.assertAlmostEqual(start - ts, 0.0, 5)

        # Check that the synthesized timestamps match our expectations
        for offset, tnext in tstamps[1:]:
            # Offset is in samples, not frames (and/or complex pairs)
            offset /= float(framesize)
            self.assertAlmostEqual(tnext - ts, offset * delta, 5)
Ejemplo n.º 2
0
    def _test_FileSource(self, format):
        filename = self._tempfileName('source_%s' % format)

        complexData = format.startswith('C')
        typecode = format[1]
        dataFormat, dataType = self.TYPEMAP[typecode]

        indata = self._generateSourceData(format, 16)
        hdr = bluefile.header(1000, format)
        bluefile.write(filename, hdr, indata)

        source = sb.FileSource(filename, midasFile=True, dataFormat=dataFormat)
        sink = sb.DataSink()
        source.connect(sink)
        sb.start()
        outdata = sink.getData(eos_block=True)
        if complexData:
            self.assertEqual(sink.sri().mode, 1)
            if dataFormat in ('float', 'double'):
                outdata = bulkio_helpers.bulkioComplexToPythonComplexList(
                    outdata)
            else:
                outdata = numpy.reshape(outdata, (len(outdata) / 2, 2))
        else:
            self.assertEqual(sink.sri().mode, 0)
        self.assertTrue(numpy.array_equal(indata, outdata),
                        msg='%s != %s' % (indata, outdata))
Ejemplo n.º 3
0
    def _test_FileSourceType2000(self, format, subsize):
        filename = self._tempfileName('source_2000_%s' % format)

        complexData = format.startswith('C')
        typecode = format[1]
        dataFormat, dataType = self.TYPEMAP[typecode]

        frames = 4
        indata = [
            self._generateSourceData(format, subsize) for x in xrange(frames)
        ]
        hdr = bluefile.header(2000, format, subsize=subsize)
        bluefile.write(filename, hdr, indata)

        source = sb.FileSource(filename, midasFile=True, dataFormat=dataFormat)
        sink = sb.DataSink()
        source.connect(sink)
        sb.start()
        outdata = sink.getData(eos_block=True)
        if complexData:
            if format == 'CF':
                outdata = numpy.array(outdata, dtype=numpy.float32).view(
                    numpy.complex64)
                outdata = numpy.reshape(outdata, (-1, subsize))
            elif format == 'CD':
                outdata = numpy.array(outdata, dtype=numpy.float64).view(
                    numpy.complex128)
                outdata = numpy.reshape(outdata, (-1, subsize))
            else:
                outdata = numpy.reshape(outdata, (-1, subsize, 2))
            self.assertEqual(sink.sri().mode, 1)
        else:
            self.assertEqual(sink.sri().mode, 0)

        self.assertTrue(numpy.array_equal(indata, outdata),
                        msg="Format '%s' %s != %s" % (format, indata, outdata))
Ejemplo n.º 4
0
f.write('sink.numberOfBuffers = 200\n')
sink.advanced_configuration.endian_representation = 2
f.write('sink.advanced_configuration.endian_representation = 2\n')
sink.advanced_configuration.max_payload_size = 1428
f.write('sink.advanced_configuration.max_payload_size = 1500\n\n')
sink.VITA49IFContextPacket.class_identifier = "DEFAULT"
sink.VITA49IFContextPacket.device_identifier = "FF-FF-FA:1333"
output_result = sb.FileSink('results.tmp')
source.connect(output_result, providesPortName='shortIn')
#sink.api()
#time.sleep(100)
f.write('\n********** Starting Components **********\n')
sb.start()
f.write('Components started\n')

input_file = sb.FileSource('golden.tmp', dataFormat='short')

kw = sb.SRIKeyword("COL_BW", 20000000.0, 'double')
kw1 = sb.SRIKeyword("COL_IF_FREQUENCY_OFFSET", 70000000.0, 'double')
kw2 = sb.SRIKeyword("COL_RF", 155500000.0, 'double')
kw3 = sb.SRIKeyword("COL_RF_OFFSET", 20.0, 'double')
kw5 = sb.SRIKeyword("COL_REFERENCE_LEVEL", 10.2969, 'float')
kw6 = sb.SRIKeyword("COL_GAIN", 10.0, 'float')
kw7 = sb.SRIKeyword("DATA_GAIN", 0.0, 'float')
kw8 = sb.SRIKeyword("ATTENUATION_SUM", 10.0, 'float')
kw9 = sb.SRIKeyword("OVER_RANGE_SUM", 0, 'long')
kw10 = sb.SRIKeyword("TIMESTAMP_ADJUSTMENT", 2, 'long')
kw11 = sb.SRIKeyword("TIMESTAMP_CALIBRATION", 100, 'long')
kw12 = sb.SRIKeyword("TEMPERATURE", 100, 'float')
kw13 = sb.SRIKeyword("DEVICE_IDENTIFIER", 1111, 'long')
def main(argv):
    sadfile = ''
    inputfile = ''
    dataformat = ''
    samplerate = ''
    iscomplex = False
    outputfile = ''
    try:
        opts, args = getopt.getopt(argv, "hs:i:f:r:co:", [
            "sadfile=", "ifile=", "dataformat=", "samplerate=", "complex",
            "ofile="
        ])
    except getopt.GetoptError:
        print 'runWaveform.py -s <sadfile> -i <inputfile> -f <dataFormat> -r <sampleRate> -c -o <outputfile>'
        sys.exit(2)
    for opt, arg in opts:
        #print 'evaluating opt - ',opt,' arg - ',arg
        if opt == '-h':
            print 'runWaveform.py -s <sadfile> -i <inputfile> -f <dataFormat> -r <sampleRate> -c o <outputfile>'
            sys.exit()
        elif opt in ("-s", "--sadfile"):
            sadfile = arg
        elif opt in ("-i", "--ifile"):
            inputfile = arg
        elif opt in ("-f", "--dataformat"):
            dataformat = arg
        elif opt in ("-r", "--samplerate"):
            samplerate = arg
        elif opt in ("-c", "--complex"):
            iscomplex = True
        elif opt in ("-o", "--ofile"):
            outputfile = arg
            print 'setting outputfile', outputfile
    print 'Processing ', inputfile, " through waveform - ", sadfile
    sadFile = open(sadfile)
    sadFileString = sadFile.read()
    usesPort = ''
    usesComponent = ''
    providesPort = ''
    providesComponent = ''
    sadXML = parsers.sad.parseString(sadFileString)
    if sadXML.get_externalports():
        for port in sadXML.get_externalports().get_port():
            if port.get_usesidentifier():
                usesPort = port.get_usesidentifier()
                usesComponent = port.get_componentinstantiationref()
            elif port.get_providesidentifier():
                providesPort = port.get_providesidentifier()
                providesComponent = port.get_componentinstantiationref()
        if not usesPort and not providesPort:
            print 'Need uses and provides external ports'
            sys.exit()
    else:
        print 'No external ports'
        sys.exit()
    print usesPort, providesPort
    if not usesPort or not providesPort:
        print 'Require external uses & provides port'
        sys.exit()
    sb.loadSADFile(sadfile)
    fileSource = sb.FileSource(filename=inputfile,
                               dataFormat=dataformat,
                               sampleRate=samplerate)
    fileSink = sb.FileSink(filename=outputfile)
    #FIXME check file type matches external port
    fileSource.connect(sb.getComponent(providesComponent.get_refid()),
                       providesPortName=providesPort)
    sb.getComponent(usesComponent.get_refid()).connect(fileSink,
                                                       usesPortName=usesPort)
    sb.start()
    fileSink.waitForEOS()
    sb.stop()
    sb.release()