def testChangeBlockWithNonEmptyQueue(self): self.utility() numPackets = 6 #set the queueDepth to the number of packets intending to be sent - 1 self.comp.mqd = numPackets - 1 #set the port to not block (this is default behavior s2_sri = BULKIO.StreamSRI(1, 0.0, 0.001, 1, 300, 0.0, 0.001, 1, 1, 's2', False, []) self.dataShortInput.pushSRI(s2_sri) #fill the queue half way self.dataShortInput.pushPacket([1], bulkio_helpers.createCPUTimestamp(), False, 's2') self.dataShortInput.pushPacket([1], bulkio_helpers.createCPUTimestamp(), False, 's2') self.dataShortInput.pushPacket([1], bulkio_helpers.createCPUTimestamp(), False, 's2') #now set the port the be blocking s1_sri = BULKIO.StreamSRI(1, 0.0, 0.001, 1, 300, 0.0, 0.001, 1, 1, 's1', True, []) self.dataShortInput.pushSRI(s1_sri) #should still be able to push 2 more before the queue is full self.dataShortInput.pushPacket([1], bulkio_helpers.createCPUTimestamp(), False, 's2') self.dataShortInput.pushPacket([1], bulkio_helpers.createCPUTimestamp(), False, 's2') #send the last packet in a separate thread #this call should block, not flush t2 = threading.Thread(None, self.pushOnePacketThread, 't2', ('s2', ), {}) t2.setDaemon(True) t2.start() #start the 'quasi' component thread, tell him to receive numPackets t1 = threading.Thread(None, self.getPacketThread, 't1', (numPackets, ), {}) t1.setDaemon(True) t1.start() self.comp.start() t2.join() t1.join() self.comp.stop() #should not have flushed self.assertTrue(not self.queueFlushed) self.assertTrue(self.packetsReceived == numPackets) self.comp.releaseObject()
def pushPacket(self, data, T, EOS, streamID): self.port_lock.acquire() if self.queue.maxsize == 0: self.port_lock.release() return packet = None try: sri = BULKIO.StreamSRI(1, 0.0, 1.0, 1, 0, 0.0, 0.0, 0, 0, streamID, False, []) sriChanged = False if self.sriDict.has_key(streamID): sri, sriChanged = self.sriDict[streamID] self.sriDict[streamID] = (sri, False) if self.blocking: packet = (data, T, EOS, streamID, copy.deepcopy(sri), sriChanged, False) self.stats.update(len(data), float(self.queue.qsize()) / float(self.queue.maxsize), streamID, False) self.queue.put(packet) else: if self.queue.full(): try: self.queue.mutex.acquire() self.queue.queue.clear() self.queue.mutex.release() except Queue.Empty: pass packet = (data, T, EOS, streamID, copy.deepcopy(sri), sriChanged, True) self.stats.update(len(data), float(self.queue.qsize()) / float(self.queue.maxsize), streamID, True) else: packet = (data, T, EOS, streamID, copy.deepcopy(sri), sriChanged, False) self.stats.update(len(data), float(self.queue.qsize()) / float(self.queue.maxsize), streamID, False) self.queue.put(packet) finally: self.port_lock.release()
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")
def testSRI(self): request = fe_types.frontend_tuner_allocation() upstream_sri = BULKIO.StreamSRI(hversion=1, xstart=0.0, xdelta=1 / 2e6, xunits=BULKIO.UNITS_TIME, subsize=0, ystart=0.0, ydelta=0.0, yunits=BULKIO.UNITS_NONE, mode=0, streamID="", blocking=False, keywords=[]) request.center_frequency = 100e6 request.bandwidth = 1e6 request.sample_rate = 2e6 cf = 100e6 bw = 1e6 _keywords = [ CF.DataType(id="CHAN_RF", value=_any.to_any(cf)), CF.DataType(id="FRONTEND::BANDWIDTH", value=_any.to_any(bw)) ] upstream_sri.keywords = _keywords self.assertTrue( tuner_device.validateRequestVsSRI(request, upstream_sri, False)) cf = 100.49e6 _keywords = [ CF.DataType(id="CHAN_RF", value=_any.to_any(cf)), CF.DataType(id="FRONTEND::BANDWIDTH", value=_any.to_any(bw)) ] upstream_sri.keywords = _keywords self.assertTrue( tuner_device.validateRequestVsSRI(request, upstream_sri, False)) cf = 99.51e6 _keywords = [ CF.DataType(id="CHAN_RF", value=_any.to_any(cf)), CF.DataType(id="FRONTEND::BANDWIDTH", value=_any.to_any(bw)) ] upstream_sri.keywords = _keywords self.assertTrue( tuner_device.validateRequestVsSRI(request, upstream_sri, False)) cf = 100.51e6 _keywords = [ CF.DataType(id="CHAN_RF", value=_any.to_any(cf)), CF.DataType(id="FRONTEND::BANDWIDTH", value=_any.to_any(bw)) ] upstream_sri.keywords = _keywords self.assertRaises(FRONTEND.BadParameterException, tuner_device.validateRequestVsSRI, request, upstream_sri, False) cf = 99.49e6 _keywords = [ CF.DataType(id="CHAN_RF", value=_any.to_any(cf)), CF.DataType(id="FRONTEND::BANDWIDTH", value=_any.to_any(bw)) ] upstream_sri.keywords = _keywords self.assertRaises(FRONTEND.BadParameterException, tuner_device.validateRequestVsSRI, request, upstream_sri, False)
def __init__(self, porttype): """ Instantiates a new object and generates a default StreamSRI. The porttype parameter corresponds to the type of data contained in the array of data being sent. The porttype is also used in the connectPort() method to narrow the connection """ self.file_d = None self.pkts_sent = 0 self.port_type = porttype self.byte_per_sample = 1 self.structFormat = "B" if (porttype == BULKIO__POA.dataShort): self.byte_per_sample = 2 self.structFormat = "h" elif (porttype == BULKIO__POA.dataFloat): self.byte_per_sample = 4 self.structFormat = "f" elif (porttype == BULKIO__POA.dataDouble): self.byte_per_sample = 8 self.structFormat = "d" elif (porttype == BULKIO__POA.dataChar): self.byte_per_sample = 1 self.structFormat = "b" elif (porttype == BULKIO__POA.dataOctet): self.byte_per_sample = 1 self.structFormat = "B" elif (porttype == BULKIO__POA.dataUlong): self.byte_per_sample = 4 self.structFormat = "L" elif (porttype == BULKIO__POA.dataUshort): self.byte_per_sample = 2 self.structFormat = "H" elif (porttype == BULKIO__POA.dataLong): self.byte_per_sample = 4 self.structFormat = "l" elif (porttype == BULKIO__POA.dataLongLong): self.byte_per_sample = 8 self.structFormat = "q" elif (porttype == BULKIO__POA.dataUlongLong): self.byte_per_sample = 8 self.structFormat = "Q" elif (porttype == BULKIO__POA.dataXML): self.byte_per_sample = 1 self.structFormat = "c" self.outPorts = {} self.refreshSRI = False # Create default SRI self.sri = BULKIO.StreamSRI(1, 0.0, 0.001, 1, 200, 0.0, 0.001, 1, 1, "defaultStreamID", True, []) self.port_lock = threading.Lock() self.EOS = False
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")
def create(sid='defStream', srate=1.0, xunits=1): return BULKIO.StreamSRI(hversion=1, xstart=0.0, xdelta=1.0 / srate, xunits=xunits, subsize=0, ystart=0.0, ydelta=0.0, yunits=0, mode=0, streamID=sid, blocking=False, keywords=[])
def pushPacket(self, *args): """ This function is called whenever the pushPacket call is made on the connected output port. This attempts to place a new CORBA packet on the date queue. To pull packets off of the queue use the getPacket call """ data = args[0] #the dataXML port and dataFile port don't #have time tags so check the number of args if len(args) == 4: T = args[1] EOS = args[2] streamID = args[3] else: T = None EOS = args[1] streamID = args[2] self.port_lock.acquire() packet = None try: sri = BULKIO.StreamSRI(1, 0.0, 1.0, 1, 0, 0.0, 0.0, 0, 0, streamID, False, []) sriChanged = False if self.sriDict.has_key(streamID): sri, sriChanged = self.sriDict[streamID] self.sriDict[streamID] = (sri, False) else: self.sriDict[streamID] = (sri, False) sriChanged = True if self.blocking: packet = (data, T, EOS, streamID, copy.deepcopy(sri), sriChanged, False) self.queue.put(packet) else: if self.queue.full(): try: self.queue.mutex.acquire() self.queue.queue.clear() self.queue.mutex.release() except Queue.Empty: pass packet = (data, T, EOS, streamID, copy.deepcopy(sri), sriChanged, True) else: packet = (data, T, EOS, streamID, copy.deepcopy(sri), sriChanged, False) self.queue.put(packet) finally: self.port_lock.release()
def pushSRI(self, xdelta=1, streamID='TestStreamID', mode=0, kw=[]): sri = BULKIO.StreamSRI(hversion=1, xstart=0.0, xdelta=xdelta, xunits=1, subsize=0, ystart=0.0, ydelta=0.0, yunits=0, mode=mode, streamID=streamID, blocking=False, keywords=kw) self.input_vita49_port.pushSRI(sri, timestamp.now())
def __init__(self, porttype, pushSRI, pushPacket): """ Inputs: :porttype The BULKIO__POA data type """ self.port_type = porttype self.last_sri = BULKIO.StreamSRI(1, 0.0, 0.001, 1, 200, 0.0, 0.001, 1, 1, "defaultStreamID", True, []) self.last_packet = [] self.eos = False self._pushSRI_callback = pushSRI self._pushPacket_callback = pushPacket self._logger = logging.getLogger(self.__class__.__name__)
def __init__(self, parent, vars={}, **extras): self.parent = parent self.vars = dict(vars) self.vars.update(extras) self.port_lock = threading.Lock() self.refreshSRI = False self.defaultStreamSRI = BULKIO.StreamSRI(1, 0.0, 0.001, 1, 200, 0.0, 0.001, 1, 1, "sampleStream", []) self.active = True self.refreshSRIList = {} self.connectionToStream = {} self.streamToConnection = {} self.streamToPorts = {} self.defaultSRIList = {} self.outPorts = {}
def pushPacket(self, data, T, EOS, streamID): if self._portLog: self._portLog.trace('bulkio::OutPort pushPacket ENTER ') if not self.sriDict.has_key(streamID): sri = BULKIO.StreamSRI(1, 0.0, 1.0, 1, 0, 0.0, 0.0, 0, 0, streamID, False, []) self.pushSRI(sri) with self.port_lock: self._pushPacket(data, T, EOS, streamID) if EOS: del self._streams[streamID] if self._portLog: self._portLog.trace('bulkio::OutPort pushPacket EXIT ')
def pushPacket(self, data, T, EOS, streamID): if self.logger: self.logger.trace('bulkio::OutPort pushPacket ENTER ') if not self.sriDict.has_key(streamID): sri = BULKIO.StreamSRI(1, 0.0, 1.0, 1, 0, 0.0, 0.0, 0, 0, streamID, False, []) self.pushSRI(sri) self.port_lock.acquire() try: self._pushOversizedPacket(data, T, EOS, streamID) finally: self.port_lock.release() if self.logger: self.logger.trace('bulkio::OutPort pushPacket EXIT ')
def __init__(self, porttype): """ Instantiates a new object and generates a default StreamSRI. The porttype parameter corresponds to the type of data contained in the array of data being sent. The porttype is also used in the connectPort() method to narrow the connection """ self.port_type = porttype self.outPorts = {} self.refreshSRI = False self.sri = BULKIO.StreamSRI(1, 0.0, 0.001, 1, 200, 0.0, 0.001, 1, 1, "defStream", []) self.stream_id = str(uuid.uuid4()) self.port_lock = threading.Lock()
def __init__(self, porttype): """ Instantiates a new object responsible for writing data from the port into an array. It is important to notice that the porttype is a BULKIO__POA type and not a BULKIO type. The reason is because it is used to generate a Port class that will be returned when the getPort() is invoked. The returned class is the one acting as a server and therefore must be a Portable Object Adapter rather and a simple BULKIO object. Inputs: <porttype> The BULKIO__POA data type """ self.port_type = porttype self.sri = BULKIO.StreamSRI(1, 0.0, 0.001, 1, 200, 0.0, 0.001, 1, 1, "defStream", []) self.data = [] self.port_lock = threading.Lock()
def pushPacket(self, URL, T, EOS, streamID): if self.logger: self.logger.trace('bulkio::OutFilePort pushPacket ENTER ') if not self.sriDict.has_key(streamID): sri = BULKIO.StreamSRI(1, 0.0, 1.0, 1, 0, 0.0, 0.0, 0, 0, streamID, False, []) self.pushSRI(sri) self.port_lock.acquire() try: portListed = False for connId, port in self.outConnections.items(): for ftPtr in self.filterTable: if ftPtr.port_name == self.name : portListed = True if (ftPtr.port_name == self.name) and (ftPtr.connection_id == connId) and (ftPtr.stream_id == streamID): try: if port != None: port.pushPacket(URL, T, EOS, streamID) self.stats.update(1, 0, EOS, streamID, connId) except Exception: if self.logger: self.logger.error("The call to OutFilePort::pushPacket failed on port %s connection %s instance %s", self.name, connId, port) if not portListed: for connId, port in self.outConnections.items(): try: if port != None: port.pushPacket(URL, T, EOS, streamID) self.stats.update(1, 0, EOS, streamID, connId) except Exception: if self.logger: self.logger.error("The call to OutFilePort::pushPacket failed on port %s connection %s instance %s", self.name, connId, port) if EOS==True: if self.sriDict.has_key(streamID): tmp = self.sriDict.pop(streamID) finally: self.port_lock.release() if self.logger: self.logger.trace('bulkio::OutFilePort pushPacket EXIT ')
def __init__(self, porttype, throttle=False): """ Instantiates a new object and generates a default StreamSRI. The porttype parameter corresponds to the type of data contained in the array of data being sent. The porttype is also used in the connectPort() method to narrow the connection """ self.porttype = porttype self.outPorts = {} self.refreshSRI = False self.defaultStreamSRI = BULKIO.StreamSRI(1, 0.0, 0.001, 1, 0, 0.0, 0.001, 1, 0, "sampleStream", True, []) self.port_lock = threading.Lock() self._throttle = throttle self.done = False
def setupComponent(self, endianness=BIG_ENDIAN, pkts_per_push=1, sri=None): # Set properties self.comp.interface = 'lo' compDataSddsIn = self.comp.getPort('dataSddsIn') self.comp.advanced_optimizations.sdds_pkts_per_bulkio_push = pkts_per_push if sri is None: kw = [ CF.DataType("dataRef", ossie.properties.to_tc_value(endianness, '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='TestStreamID', blocking=False, keywords=kw) compDataSddsIn.pushSRI(sri, timestamp.now()) 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")
def initialize(self): """ This is called by the framework immediately after your component registers with the NameService. In general, you should add customization here and not in the __init__ constructor. If you have a custom port implementation you can override the specific implementation here with a statement similar to the following: self.some_port = MyPortImplementation() """ SigGen_base.initialize(self) self.last_xfer_len = self.xfer_len keywords = [] if self.chan_rf != -1: keywords.append(CF.DataType('CHAN_RF', any.to_any(self.chan_rf))) if self.col_rf != -1: keywords.append(CF.DataType('COL_RF', any.to_any(self.col_rf))) if self.sri_blocking == None: self.sri_blocking = False self.sri = BULKIO.StreamSRI(1, 0.0, 0.0, BULKIO.UNITS_TIME, 0, 0.0, 0.0, BULKIO.UNITS_NONE, 0, self.stream_id, self.sri_blocking, keywords) self.sriUpdate = True self.phase = 0 self.chirp = 0 self.sample_time_delta = 0.0 self.delta_phase = 0.0 self.delta_phase_offset = 0.0 self.cached_stream_id = self.stream_id self.stream_created = False self.next_time = None self._waveform = Waveform.Waveform() # Separate listeners required. Bug fixed in CF 1.10.1 self.addPropertyChangeListener("stream_id", self.prop_update_sri) self.addPropertyChangeListener("chan_rf", self.prop_update_sri2) self.addPropertyChangeListener("col_rf", self.prop_update_sri3) self.addPropertyChangeListener("sri_blocking", self.prop_update_sri_blocking)
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")
def pushPacket(self, data, T, EOS, streamID): if self.refreshSRI: if not self.sriDict.has_key(streamID): sri = BULKIO.StreamSRI(1, 0.0, 1.0, BULKIO.UNITS_TIME, 0, 0.0, 0.0, BULKIO.UNITS_NONE, 0, streamID, True, []) self.sriDict[streamID] = copy.deepcopy(sri) self.pushSRI(self.sriDict[streamID]) self.port_lock.acquire() try: try: for connId, port in self.outConnections.items(): if port != None: port.pushPacket(data, T, EOS, streamID) self.stats.update(len(data), 0, streamID, connId) except Exception: self.parent._log.exception("The call to pushPacket failed on port %s connection %s instance %s", self.name, connId, port) raise if EOS==True: if self.sriDict.has_key(streamID): tmp = self.sriDict.pop(streamID) finally: self.port_lock.release()
def __init__(self, outputPort, stream_id="stream_id", cf=100e6, sr=10e6): self.outputPort = outputPort self.stream_id = stream_id self.cf = cf self.sr = sr self._waveform = Waveform.Waveform() self.enable = False self.phase = 0 self.chirp = 0 self.sample_time_delta = 0.0 self.delta_phase = 0.0 self.delta_phase_offset = 0.0 self.magnitude = 100 self.xfer_len = 100000 self.last_xfer_len = self.xfer_len self.next_time = None self.throttle = True self.terminate = False self.thread = None self.firstTime = True self.keyword_dict = {} self.sri = BULKIO.StreamSRI(1, 0.0, 0.0, BULKIO.UNITS_TIME, 0, 0.0, 0.0, BULKIO.UNITS_NONE, 0, self.stream_id, False, [])
def __init__(self, outputFilename, porttype): """ Instantiates a new object responsible for writing data from the port into an array. It is important to notice that the porttype is a BULKIO__POA type and not a BULKIO type. The reason is because it is used to generate a Port class that will be returned when the getPort() is invoked. The returned class is the one acting as a server and therefore must be a Portable Object Adapter rather and a simple BULKIO object. Inputs: <outputFilename> The output filename <porttype> The BULKIO__POA data type """ # If output file already exists, remove it if outputFilename != None and os.path.isfile(outputFilename): print "FileSink:__init__() WARNING - overwriting output file " + str( outputFilename) + " since it already exists " os.remove(outputFilename) # Make sure if path is provided, it is valid path = os.path.dirname(outputFilename) if len(path) == 0 or \ (len(path) > 0 and os.path.isdir(path)): self.outFile = open(outputFilename, "wb") else: print "FileSink:__init__() ERROR - invalid filename path" self.outFile = None self.port_type = porttype self.sri = BULKIO.StreamSRI(1, 0.0, 0.001, 1, 200, 0.0, 0.001, 1, 1, "defaultStreamID", True, []) self.data = [] self.gotEOS = False self.port_lock = threading.Lock()
def testSRIChanged(self): ossie.utils.testing.ScaComponentTestCase.setUp(self) ####################################################################### # Launch the component with the default execparams execparams = self.getPropertySet(kinds=("execparam", ), modes=("readwrite", "writeonly"), includeNil=False) execparams = dict([(x.id, any.from_any(x.value)) for x in execparams]) self.launch(execparams) self.comp_obj.initialize() self.comp_obj.start() self.helperShortInput = bulkio_helpers.createBULKIOInputPort( BULKIO__POA.dataShort) self.dataShortInput = self.comp_obj.getPort('dataShortIn') self.dataShortOutput = self.comp_obj.getPort('dataShortOut') self.dataShortOutput.connectPort(self.helperShortInput, 'dataShortOut') shortData = bulkio_helpers.genRandomDataSet(16, True, 1000) s1_sri = BULKIO.StreamSRI(1, 0.0, 0.001, 1, 300, 0.0, 0.001, 1, 1, "s1", False, []) s2_sri = BULKIO.StreamSRI(1, 0.0, 0.001, 1, 200, 0.0, 0.001, 1, 1, "s2", False, []) self.dataShortInput.pushPacket(shortData, bulkio_helpers.createCPUTimestamp(), False, "s1") self.dataShortInput.pushPacket(shortData, bulkio_helpers.createCPUTimestamp(), False, "s2") #pushPacket with no previous pushSRI, should have the correct streamIDs but the flags #should not be set in either getPacket call data, T, EOS, streamID, sri, sriChanged, flushed = self.helperShortInput.getPacket( -1) self.assertEquals(streamID, 's1') self.assertTrue(sriChanged) data, T, EOS, streamID, sri, sriChanged, flushed = self.helperShortInput.getPacket( -1) self.assertEquals(streamID, 's2') self.assertTrue(sriChanged) self.dataShortInput.pushSRI(s1_sri) self.dataShortInput.pushSRI(s2_sri) self.dataShortInput.pushPacket(shortData, bulkio_helpers.createCPUTimestamp(), False, "s1") self.dataShortInput.pushPacket(shortData, bulkio_helpers.createCPUTimestamp(), False, "s2") #pushSRIs followed by pushPackets. The flag should be set in both getPacket #calls and the received SRIs should match the ones sent in data, T, EOS, streamID, sri, sriChanged, flushed = self.helperShortInput.getPacket( -1) self.assertEquals(streamID, 's1') self.assertTrue(bulkio_helpers.compareSRI(sri, s1_sri)) self.assertTrue(sriChanged) data, T, EOS, streamID, sri, sriChanged, flushed = self.helperShortInput.getPacket( -1) self.assertEquals(streamID, 's2') self.assertTrue(bulkio_helpers.compareSRI(sri, s2_sri)) self.assertTrue(sriChanged) s1_sri = BULKIO.StreamSRI(1, 0.0, 0.001, 1, 400, 0.0, 0.001, 1, 1, "s1", False, []) self.dataShortInput.pushSRI(s1_sri) self.dataShortInput.pushPacket(shortData, bulkio_helpers.createCPUTimestamp(), False, "s1") self.dataShortInput.pushPacket(shortData, bulkio_helpers.createCPUTimestamp(), False, "s2") #Changed the SRI for stream s1, and pushed it, did nothing for stream s2. Should see the flag set #in the first getPacket call and the streamID should be s1, also the SRI should match the new one. #The second getPacket call should return streamID s2, flag not set, and the SRI should match the old one data, T, EOS, streamID, sri, sriChanged, flushed = self.helperShortInput.getPacket( -1) self.assertEquals(streamID, 's1') self.assertTrue(bulkio_helpers.compareSRI(sri, s1_sri)) self.assertTrue(sriChanged) data, T, EOS, streamID, sri, sriChanged, flushed = self.helperShortInput.getPacket( -1) self.assertEquals(streamID, 's2') self.assertTrue(bulkio_helpers.compareSRI(sri, s2_sri)) self.assertFalse(sriChanged) #Changed the SRI for stream s2, and pushed it, did nothing for stream s1. Should see the flag set #in the second getPacket call and the streamID should be s2, also the SRI should match the new one. #The first getPacket call should return streamID s1, flag not set, and the SRI should match the old one s2_sri = BULKIO.StreamSRI(1, 0.0, 0.001, 1, 600, 0.0, 0.001, 1, 1, "s2", False, []) self.dataShortInput.pushSRI(s2_sri) self.dataShortInput.pushPacket(shortData, bulkio_helpers.createCPUTimestamp(), False, "s1") self.dataShortInput.pushPacket(shortData, bulkio_helpers.createCPUTimestamp(), False, "s2") data, T, EOS, streamID, sri, sriChanged, flushed = self.helperShortInput.getPacket( -1) self.assertEquals(streamID, 's1') self.assertTrue(bulkio_helpers.compareSRI(sri, s1_sri)) self.assertFalse(sriChanged) data, T, EOS, streamID, sri, sriChanged, flushed = self.helperShortInput.getPacket( -1) self.assertEquals(streamID, 's2') self.assertTrue(bulkio_helpers.compareSRI(sri, s2_sri)) self.assertTrue(sriChanged) #Did nothing to change either stream s1 or stream s2. Should see no changes to SRI, and should not #see the flag set in either getPacket call. The streamIDs should still come back in order self.dataShortInput.pushPacket(shortData, bulkio_helpers.createCPUTimestamp(), False, "s1") self.dataShortInput.pushPacket(shortData, bulkio_helpers.createCPUTimestamp(), False, "s2") data, T, EOS, streamID, sri, sriChanged, flushed = self.helperShortInput.getPacket( -1) self.assertEquals(streamID, 's1') self.assertTrue(bulkio_helpers.compareSRI(sri, s1_sri)) self.assertFalse(sriChanged) data, T, EOS, streamID, sri, sriChanged, flushed = self.helperShortInput.getPacket( -1) self.assertEquals(streamID, 's2') self.assertTrue(bulkio_helpers.compareSRI(sri, s2_sri)) self.assertFalse(sriChanged) #Changed the SRI for stream s2, and pushed it, Then repeated the operation changing the SRI again before #making a pushPacket call for either stream, Should see the flag set in the getPacket call, also the SRI #should match the latest one pushed. s2_sri = BULKIO.StreamSRI(1, 0.0, 0.001, 1, 500, 0.0, 0.001, 1, 1, "s2", False, []) self.dataShortInput.pushSRI(s2_sri) s2_sri = BULKIO.StreamSRI(1, 0.0, 0.001, 1, 700, 0.0, 0.001, 1, 1, "s2", False, []) self.dataShortInput.pushSRI(s2_sri) self.dataShortInput.pushPacket(shortData, bulkio_helpers.createCPUTimestamp(), False, "s2") data, T, EOS, streamID, sri, sriChanged, flushed = self.helperShortInput.getPacket( -1) self.assertEquals(streamID, 's2') self.assertTrue(bulkio_helpers.compareSRI(sri, s2_sri)) self.assertTrue(sriChanged) #Testing that a pushPacket with an EOS flag does not break anything with SRI. The SRI is supposed #to be removed from the list that the port maintains if EOS was received for a particular streamID. #Flags should not be set and SRIs should still come back as the latest ones self.dataShortInput.pushPacket(shortData, bulkio_helpers.createCPUTimestamp(), True, "s1") self.dataShortInput.pushPacket(shortData, bulkio_helpers.createCPUTimestamp(), True, "s2") data, T, EOS, streamID, sri, sriChanged, flushed = self.helperShortInput.getPacket( -1) self.assertEquals(streamID, 's1') self.assertTrue(bulkio_helpers.compareSRI(sri, s1_sri)) self.assertFalse(sriChanged) data, T, EOS, streamID, sri, sriChanged, flushed = self.helperShortInput.getPacket( -1) self.assertEquals(streamID, 's2') self.assertTrue(bulkio_helpers.compareSRI(sri, s2_sri)) self.assertFalse(sriChanged) #This final test looks to see if the same SRI is pushed once before a pushPacket, then again after #the pushPacket, that the sriChanged flag won't be set for the next data set to be returned. A #pushSRI with the exact same SRI that already exists should not cause the flag to be set. The first #getPacket should see new SRI and the flag set, the second one should see the same SRI, no flag set s1_sri = BULKIO.StreamSRI(1, 0.0, 0.001, 1, 300, 0.0, 0.001, 1, 1, "s1", False, []) self.dataShortInput.pushSRI(s1_sri) self.dataShortInput.pushPacket(shortData, bulkio_helpers.createCPUTimestamp(), False, "s1") self.dataShortInput.pushSRI(s1_sri) self.dataShortInput.pushPacket(shortData, bulkio_helpers.createCPUTimestamp(), False, "s1") data, T, EOS, streamID, sri, sriChanged, flushed = self.helperShortInput.getPacket( -1) self.assertEquals(streamID, 's1') self.assertTrue(bulkio_helpers.compareSRI(sri, s1_sri)) self.assertTrue(sriChanged) data, T, EOS, streamID, sri, sriChanged, flushed = self.helperShortInput.getPacket( -1) self.assertEquals(streamID, 's1') self.assertTrue(bulkio_helpers.compareSRI(sri, s1_sri)) self.assertFalse(sriChanged) self.comp_obj.stop() self.comp_obj.releaseObject()
def testEOSBlockReset(self): self.utility() numPackets = 4 #set the queueDepth to the number of packets intending to be sent - 1 self.comp.mqd = numPackets - 1 #send two streamSRI, one for blocking and one to not block, should tell the port to block s1_sri = BULKIO.StreamSRI(1, 0.0, 0.001, 1, 300, 0.0, 0.001, 1, 1, 's1', True, []) s2_sri = BULKIO.StreamSRI(1, 0.0, 0.001, 1, 300, 0.0, 0.001, 1, 1, 's2', False, []) self.dataShortInput.pushSRI(s1_sri) self.dataShortInput.pushSRI(s2_sri) #start the 'quasi' component thread, tell him to receive numPackets*2 t1 = threading.Thread(None, self.getPacketThread, 't1', (numPackets * 2, ), {}) t1.setDaemon(True) t1.start() #fill the queue for x in range(numPackets - 1): self.dataShortInput.pushPacket([], bulkio_helpers.createCPUTimestamp(), False, 's1') #send the last one and the rest of the packets in a separate thread t2 = threading.Thread(None, self.pushOnePlusPacketsThread, 't2', ('s1', 's2', numPackets), {}) t2.setDaemon(True) t2.start() #start the component and let the 'quasi' component thread complete self.comp.start() t2.join() t1.join() #should not have flushed, should have gotten all packets self.assertFalse(self.queueFlushed) self.assertEquals(self.packetsReceived, numPackets * 2) self.comp.stop() #reset packetsReceived to 0 self.packetsReceived = 0 #start another receiver thread t1 = threading.Thread(None, self.getPacketThread, 't1', (numPackets * 2, ), {}) t1.setDaemon(True) t1.start() #send 2 packets, the second one with an EOS which should lift the block #since s1 was calling for the block and s2 wasn't self.comp.start() self.dataShortInput.pushPacket([], bulkio_helpers.createCPUTimestamp(), False, 's1') self.dataShortInput.pushPacket([], bulkio_helpers.createCPUTimestamp(), True, 's1') #wait to see that the EOS has passed through the component #which should reset the block to false while not self.EOSReceived: pass self.comp.stop() #push enough packets in to cause a flush self.dataShortInput.pushPacket([], bulkio_helpers.createCPUTimestamp(), False, 's2') self.dataShortInput.pushPacket([], bulkio_helpers.createCPUTimestamp(), False, 's2') self.dataShortInput.pushPacket([], bulkio_helpers.createCPUTimestamp(), False, 's2') self.dataShortInput.pushPacket([], bulkio_helpers.createCPUTimestamp(), False, 's2') self.comp.start() t1.join() self.comp.stop() #should have received the 2 packets from s1, and the single packet from s2 self.assertTrue(self.queueFlushed) self.assertTrue(self.packetsReceived == 3)
def pushPacket(self, data, T, EOS, streamID): if self.logger: self.logger.trace("bulkio::InPort pushPacket ENTER (port=" + str(self.name) + ")") self.port_lock.acquire() try: if self._maxSize == 0: if self.logger: self.logger.trace("bulkio::InPort pushPacket EXIT (port=" + str(self.name) + ")") return if self.sriDict.has_key(streamID): sri, sriChanged = self.sriDict[streamID] if EOS: self.sriDict[streamID] = (sri, True) else: self.sriDict[streamID] = (sri, False) else: # Create a default SRI for the stream ID if self.logger: self.logger.warn( "bulkio::InPort pushPacket received data for stream '%s' with no SRI", streamID) sri = BULKIO.StreamSRI(1, 0.0, 1.0, 1, 0, 0.0, 0.0, 0, 0, streamID, False, []) if self.newSriCallback: self.newSriCallback(sri) self.sriDict[streamID] = (sri, False) sriChanged = True queueFlushed = False flagEOS = False if self.blocking: while len(self.queue) >= self._maxSize: self._not_full.wait() else: # Flush the queue if not using infinite queue (maxSize == -1), blocking is not on, and # current length of queue is >= maxSize if len(self.queue) >= self._maxSize and self._maxSize > -1: queueFlushed = True if self.logger: self.logger.debug( "bulkio::InPort pushPacket PURGE INPUT QUEUE (SIZE=%d)", len(self.queue)) foundSRIChanged = False for data, T, EOS, streamID, sri, sriChangeHappened, inputQueueFlushed in self.queue: if foundSRIChanged and flagEOS: break if sriChangeHappened: sriChanged = True foundSRIChanged = True if EOS: flagEOS = True self.queue.clear() if flagEOS: EOS = True packet = (data, T, EOS, streamID, copy.deepcopy(sri), sriChanged, queueFlushed) self.stats.update(self._packetSize(data), float(len(self.queue)) / float(self._maxSize), EOS, streamID, queueFlushed) if self.logger: self.logger.trace( "bulkio::InPort pushPacket NEW Packet (QUEUE=%d)", len(self.queue)) self.queue.append(packet) # Let one waiting getPacket call know there is a packet available self._not_empty.notify() finally: self.port_lock.release() if self.logger: self.logger.trace("bulkio::InPort pushPacket EXIT (port=" + str(self.name) + ")")
def hdr_to_sri(hdr, stream_id): """ Generates a StreamSRI object based on the information contained in the X-Midas header file. Inputs: <hdr> The X-Midas header file <stream_id> The stream id Output: Returns a BULKIO.StreamSRI object """ hversion = 1 xstart = hdr['xstart'] xdelta = hdr['xdelta'] xunits = hdr['xunits'] data_type = hdr['type'] data_format = hdr['format'] # The subsize needs to be 0 if one-dimensional or > 0 otherwise so # using the data type to find out if data_type == 1000: subsize = 0 ystart = 0 ydelta = 0 else: subsize = str(data_type)[0] ystart = hdr['ystart'] ydelta = hdr['ydelta'] # The mode is based on the data type: 0 if is Scalar or 1 if it is # Complex. Setting it to -1 for any other type if data_format.startswith('S'): mode = 0 elif data_format.startswith('C'): mode = 1 else: mode = -1 kwds = [] # Getting all the items in the extended header if hdr.has_key('ext_header'): ext_hdr = hdr['ext_header'] if isinstance(ext_hdr, dict): for key, value in ext_hdr.iteritems(): # WARNING: CORBA types are hard-coded through here dt = CF.DataType(key, ossie.properties.to_tc_value(item[1], 'long')) kwds.append(dt) elif isinstance(ext_hdr, list): for item in ext_hdr: try: dt = CF.DataType( item[0], ossie.properties.to_tc_value(item[1], 'long')) kwds.append(dt) except: continue return BULKIO.StreamSRI(hversion, xstart, xdelta, xunits, subsize, ystart, ydelta, BULKIO.UNITS_NONE, mode, stream_id, True, kwds)
def pushThread(self): self.settingsAcquired = False self.threadExited = False # Make sure data passed in is within min/max bounds on port type # and is a valid type currentSampleTime = self._startTime streamSampleTimes = {} while not self._exitThread: exitInputLoop = False while not exitInputLoop: try: dataset = self._dataQueue.get(timeout=0.1) exitInputLoop = True settingsAcquired = True except: if self._exitThread: exitInputLoop = True if self._exitThread: if self.settingsAcquired: self._pushPacketAllConnectedPorts([], currentSampleTime, EOS, streamID) self._packetSent() self.threadExited = True return data = dataset[0] EOS = dataset[1] streamID = dataset[2] sampleRate = dataset[3] complexData = dataset[4] SRIKeywords = dataset[5] loop = dataset[6] currentSampleTime = streamSampleTimes.setdefault( streamID, self._startTime) # If loop is set in method call, override class attribute if loop != None: self._loop = loop try: self._sampleRate = sampleRate self._complexData = complexData self._SRIKeywords = SRIKeywords self._streamID = streamID candidateSri = None # If any SRI info is set, call pushSRI if streamID != None or \ sampleRate != None or \ complexData != None or \ len(SRIKeywords) > 0: keywords = [] for key in self._SRIKeywords: keywords.append( _CF.DataType( key._name, _properties.to_tc_value( key._value, str(key._format)))) candidateSri = _BULKIO.StreamSRI(1, 0.0, 1, 0, 0, 0.0, 0, 0, 0, streamID, self._blocking, keywords) if sampleRate > 0.0: candidateSri.xdelta = 1.0 / float(sampleRate) if complexData == True: candidateSri.mode = 1 else: candidateSri.mode = 0 if self._startTime >= 0.0: candidateSri.xstart = self._startTime else: candidateSri = _BULKIO.StreamSRI(1, 0.0, 1, 0, 0, 0.0, 0, 0, 0, "defaultStreamID", self._blocking, []) if self._sri == None or not compareSRI(candidateSri, self._sri): self._sri = candidateSri self._pushSRIAllConnectedPorts(sri=self._sri) # Call pushPacket # If necessary, break data into chunks of pktSize for each # pushPacket if len(data) > 0: self._pushPacketsAllConnectedPorts(data, currentSampleTime, EOS, streamID) # If loop is set to True, continue pushing data until loop # is set to False or stop() is called while self._loop: self._pushPacketsAllConnectedPorts( data, currentSampleTime, EOS, streamID) else: self._pushPacketAllConnectedPorts(data, currentSampleTime, EOS, streamID) self._packetSent() if self._complexData: currentSampleTime += len(data) / float(sampleRate) / 2 else: currentSampleTime += len(data) / float(sampleRate) streamSampleTimes[streamID] = currentSampleTime except Exception, e: print self.className + ":pushData() failed " + str(e)
elif isinstance(ext_hdr, list): for item in ext_hdr: try: data = item[1] if isinstance(item[1], numpy.generic): data = item[1].item() dtv = ossie.properties.numpy_to_tc_value( data, type(item[1]).__name__) dt = CF.DataType(item[0], dtv) #print "DEBUG (list) AFTER dt.value:", dt.value, dt.value.value(), type(dt.value.value()) kwds.append(dt) except Exception, e: continue return BULKIO.StreamSRI(hversion, xstart, xdelta, xunits, subsize, ystart, ydelta, yunits, mode, stream_id, True, kwds) def sri_to_hdr(sri, data_type, data_format): """ Generates an X-Midas header file from the SRI information. Inputs: <sri> The BULKIO.StreamSRI object <data_type> The X-Midas file type (1000, 2000, etc) <data_format> The X-Midas data format (SD, SF, CF, etc) Output: Returns an X-Midas header file """ kwds = {}
pass class NoDataException(Exception): pass #A BULKIO.StreamSRI that you can use for the pushPacket #call if you don't wish to define your own if haveBulkio: defaultSRI = 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='defStream', blocking=False, keywords=[]) else: defaultSRI = None def bulkioComplexToPythonComplexList(bulkioList): ''' Convert a BulkIO list of complex data to a list of Python complex data. For example, the BulkIO list: [1,2,3,4,5,6]