def test_FileSinkTimecode(self): filename = self._tempfileName('source_timecode') # Create a source with a known start time time_in = time.time() source = sb.DataSource(dataFormat='float', startTime=time_in) sink = sb.FileSink(filename, midasFile=True) source.connect(sink) sb.start() # The data isn't important, other than to cause a pushPacket with the # initial timestamp source.push(range(16), EOS=True) sink.waitForEOS() # Read back the timecode from the output file hdr = bluefile.readheader(filename) time_out = bluefile_helpers.j1950_to_unix(hdr['timecode']) self.assertAlmostEqual(time_in, time_out, 5)
def _test_FileSink(self, format): filename = self._tempfileName('sink_%s' % format) complexData = format.startswith('C') typecode = format[1] dataFormat, dataType = self.TYPEMAP[typecode] indata = [dataType(x) for x in xrange(16)] source = sb.DataSource(dataFormat=dataFormat) sink = sb.FileSink(filename, midasFile=True) source.connect(sink) sb.start() source.push(indata, complexData=complexData, EOS=True) sink.waitForEOS() hdr, outdata = bluefile.read(filename) self.assertEqual(hdr['format'], format) if complexData: if dataFormat in ('double', 'float'): outdata = list(self._flatten(outdata)) else: outdata = outdata.flatten() self.assertTrue(numpy.array_equal(indata, outdata), msg="Format '%s' %s != %s" % (format, indata, outdata))
def _test_FileSinkOctet(self, format): filename = self._tempfileName('sink_octet_' + format.lower()) source = sb.DataSource(dataFormat='octet') sink = sb.FileSink(filename, midasFile=True) source.connect(sink) sb.start() # Push a 256-element ramp (the maximum range of octet) indata = range(256) isComplex = bool(format[0] == 'C') source.push(indata, complexData=isComplex, EOS=True) sink.waitForEOS() # Check the BLUE file format matches hdr, data = bluefile.read(filename) self.assertEqual(format, hdr['format']) # Have to "cast" the data to unsigned 8-bit, since 'B' is a signed type # (as are all BLUE formats), and flattening the array re-interleaves # complex data outdata = data.view(numpy.uint8).reshape(-1) self.assertTrue(numpy.array_equal(indata, outdata), msg="Format '%s' %s != %s" % (format, indata, outdata))
def _test_FileSinkType2000(self, format, subsize): filename = self._tempfileName('sink_2000_%s' % format) complexData = format.startswith('C') typecode = format[1] dataFormat, dataType = self.TYPEMAP[typecode] sink = sb.FileSink(filename, midasFile=True) sb.start() # Manually create our own SRI, because DataSource doesn't support # setting the Y-axis fields sri = bulkio.sri.create('test_stream') if complexData: sri.mode = 1 else: sri.mode = 0 sri.subsize = subsize sri.ystart = subsize / -2.0 sri.ydelta = 1.0 sri.yunits = 3 # Generate test data; unlike the type 1000 tests, we have to generate # input data compatible with CORBA because we're bypassing DataSource frames = 4 samples = subsize * frames if complexData: samples *= 2 if dataFormat == 'char': indata = numpy.arange(samples, dtype=numpy.int8) packet = indata.tostring() else: indata = [dataType(x) for x in xrange(samples)] packet = indata # Push the SRI and data directly to the sink's port port = sink.getPort(dataFormat + 'In') port.pushSRI(sri) port.pushPacket(packet, bulkio.timestamp.now(), True, sri.streamID) sink.waitForEOS() hdr, outdata = bluefile.read(filename) self.assertEqual(hdr['format'], format) self.assertEqual(hdr['subsize'], subsize) self.assertEqual(hdr['ystart'], sri.ystart) self.assertEqual(hdr['ydelta'], sri.ydelta) self.assertEqual(hdr['yunits'], sri.yunits) self.assertEqual(len(outdata), frames) if complexData: if dataFormat == 'float': indata = numpy.array(indata, dtype=numpy.float32).view(numpy.complex64) indata = numpy.reshape(indata, (-1, subsize)) elif dataFormat == 'double': indata = numpy.array(indata, dtype=numpy.float64).view( numpy.complex128) indata = numpy.reshape(indata, (-1, subsize)) else: indata = numpy.reshape(indata, (-1, subsize, 2)) else: indata = numpy.reshape(indata, (-1, subsize)) self.assertTrue(numpy.array_equal(indata, outdata), msg="Format '%s' %s != %s" % (format, indata, outdata))
f.write('sink.network_settings.address = ip_address\n') sink.network_settings.enable = True f.write('sink.network_settings.enable = True\n') sink.VITA49Encapsulation.use_vrl_frames = True f.write('sink.VITA49Encapsulation.useVRLFrames = True\n') sink.VITA49Encapsulation.use_crc = False f.write('sink.VITA49Encapsulation.useCRC = True\n') sink.numberOfBuffers = 200 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')
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()
def listen_waveform_ports(domain, waveform_ports): """Listen to message events on specific waveform ports on domain Parameters ---------- domain : str The Redhawk domain to connect waveform_ports : list of tuples This will be a list of ports. Each tuple is a combination of (WAVEFORM_NAME, PORT_NAME, PORT_DATA_TYPE OUTPUT_FILE) PORT_DATA_TYPE should match an input port of the sb.FileSink {"floatIn", "shortIn", "octetIn"} Returns ------- my_msgs : dict Dictionary where keys is the combo of waveform + port name The value will be the recorded messages. """ # -------------- connect and get list of waveforms -------------------- dom = redhawk.attach(domain) waveforms = dom.applications # ------------------------ prepare variables -------------------------- my_sink_list = {} # add a message sink per port for (c_name, c_port, c_type, c_file) in waveform_ports: # enforce strings c_name = str(c_name) c_port = str(c_port) c_type = str(c_type) c_file = str(c_file) print("Name = %s, Port = %s" % (str(c_name), str(c_port))) # select waveform from the list c_wave = find_waveform(waveforms, c_name) try: # get the port of interest port_inst = c_wave.getPort(c_port) # --------------- connect to message sink --------------------- f_sink = sb.FileSink(filename=c_file, midasFile=True) port_inst.connectPort(\ f_sink.getPort(c_type), "conn_"+ str(uuid.uuid1())) f_sink.start() # track sink key = c_name + ":" + c_port my_sink_list[key] = f_sink except: print("Failed to connect to port:\t%s:%s" % (c_name, c_port)) # ----------------------- user prompt to end -------------------------- if len(my_sink_list) > 0: prompt("Hit enter to end...") else: print("No connections set...exiting") # -------------------------- stop and release ------------------------- for key in my_sink_list.keys(): try: my_sink_list[key].stop() my_sink_list[key].releaseObject() except Exception as e: print("Failed to release sink: %s" % str(e))