Ejemplo n.º 1
0
def createCPUTimestamp():
    """
    Generates a BULKIO.PrecisionUTCTime object using the current
    CPU time that you can use in the pushPacket call
    """
    ts = time.time()
    return BULKIO.PrecisionUTCTime(BULKIO.TCM_CPU, BULKIO.TCS_VALID, 0.0,
                                   int(ts), ts - int(ts))
Ejemplo n.º 2
0
def notSet():
    """
    Generates a BULKIO.PrecisionUTCTime object with zero time 
    and an invalid flag. This is used by the automatic EOS
    """
    return BULKIO.PrecisionUTCTime(BULKIO.TCM_OFF,
                                   BULKIO.TCS_INVALID, 0.0,
                                   0.0, 0.0)
Ejemplo n.º 3
0
    def testNavSetter(self):
        input_parent = self.nav_port_sample()
        input_parent_2 = self.nav_port_sample()
        input_port_1 = InNavDataPort("input_1", input_parent)
        output_port = OutNavDataPort("output")

        self.assertEquals(input_parent.get_source_id(), "original")

        _time = BULKIO.PrecisionUTCTime(1, 1, 1.0, 1.0, 1.0)
        _positioninfo = FRONTEND.PositionInfo(False, 'DATUM_WGS84', 0.0, 0.0,
                                              0.0)
        _cartesianpos = FRONTEND.CartesianPositionInfo(False, 'DATUM_WGS84',
                                                       0.0, 0.0, 0.0)
        _velocityinfo = FRONTEND.VelocityInfo(False, 'DATUM_WGS84', '', 0.0,
                                              0.0, 0.0)
        _accelerationinfo = FRONTEND.AccelerationInfo(False, 'DATUM_WGS84', '',
                                                      0.0, 0.0, 0.0)
        _attitudeinfo = FRONTEND.AttitudeInfo(False, 0.0, 0.0, 0.0)
        navpacket = FRONTEND.NavigationPacket('', '', _positioninfo,
                                              _cartesianpos, _velocityinfo,
                                              _accelerationinfo, _attitudeinfo,
                                              _time, [])
        navpacket.source_id = "newvalue"

        output_port._set_nav_packet(navpacket)
        self.assertEquals(input_parent.get_source_id(), "original")
        self.assertRaises(PortCallError, output_port._set_nav_packet,
                          navpacket, "hello")

        output_port.connectPort(input_port_1._this(), "hello")

        output_port._set_nav_packet(navpacket)
        self.assertEquals(input_parent.get_source_id(), "newvalue")

        navpacket.source_id = "newvalue_2"
        output_port._set_nav_packet(navpacket, "hello")
        self.assertEquals(input_parent.get_source_id(), "newvalue_2")

        self.assertRaises(PortCallError, output_port._set_nav_packet,
                          navpacket, "foo")

        navpacket.source_id = "newvalue_3"
        input_port_2 = InNavDataPort("input_2", input_parent_2)
        output_port.connectPort(input_port_2._this(), "foo")

        output_port._set_nav_packet(navpacket)
        self.assertEquals(input_parent.get_source_id(), "newvalue_3")
        self.assertEquals(input_parent_2.get_source_id(), "newvalue_3")

        navpacket.source_id = "newvalue_4"
        output_port._set_nav_packet(navpacket, "hello")
        self.assertEquals(input_parent.get_source_id(), "newvalue_4")
        self.assertEquals(input_parent_2.get_source_id(), "newvalue_3")

        self.assertRaises(PortCallError, output_port._set_nav_packet,
                          navpacket, "something")

        output_port.disconnectPort("hello")
Ejemplo n.º 4
0
    def _pushData(self, connection, dataString, numBytes, currentSampleTime):

        # Gather information about the connection
        arraySrcInst = connection['arraySrcInst']
        bytesPerSample = 1
        srcPortType = connection['srcPortType']

        for i in self.supportedPorts.values():
            if i['portType'] == srcPortType:
                bytesPerSample = i['bytesPerSample']
                break

        outputSize = numBytes / bytesPerSample

        # Set the byte swap to use
        if self.byte_swap == 1:
            byte_swap = bytesPerSample
        else:
            byte_swap = self.byte_swap

        # Perform the byte swap
        if byte_swap > 1:
            if byte_swap != bytesPerSample:
                log.warn("Data size " + str(bytesPerSample) +
                         " is not equal to byte swap size " + str(byte_swap))

            output = self._flip(dataString[:numBytes], byte_swap)
        else:
            output = dataString[:numBytes]

        # Convert from a string to a list of
        # the type expected for the port
        outputList = self._stringToList(output, bytesPerSample, srcPortType)

        formattedOutput = _bulkio_helpers.formatData(
            outputList, BULKIOtype=eval(srcPortType))

        EOS = False

        if len(formattedOutput) == 0:
            EOS = True

        T = _BULKIO.PrecisionUTCTime(
            _BULKIO.TCM_CPU, _BULKIO.TCS_VALID, 0.0, int(currentSampleTime),
            currentSampleTime - int(currentSampleTime))

        if srcPortType != "_BULKIO__POA.dataXML":
            _bulkio_data_helpers.ArraySource.pushPacket(arraySrcInst,
                                                        data=formattedOutput,
                                                        T=T,
                                                        EOS=EOS,
                                                        streamID='testing')
        else:
            _bulkio_data_helpers.XmlArraySource.pushPacket(
                arraySrcInst,
                data=formattedOutput,
                EOS=EOS,
                streamID='testing')
Ejemplo n.º 5
0
def create_cputime_stamp():
    """
    Generates a PrecisionUTCTime object using the current CPU time.
    
    Output:
        Returns a BULKIO.PrecisionUTCTime object
    """
    ts = time.time()
    return BULKIO.PrecisionUTCTime(BULKIO.TCM_CPU,
                                   BULKIO.TCS_VALID, 0.0,
                                   int(ts), ts - int(ts))
Ejemplo n.º 6
0
def create( whole_secs=-1.0, fractional_secs=-1.0, tsrc=BULKIO.TCM_CPU ):
    """
    Generates a BULKIO.PrecisionUTCTime object using the current 
    CPU time that you can use in the pushPacket call
    """
    wsec = whole_secs;
    fsec = fractional_secs;
    if wsec < 0.0 and fsec < 0.0 :
        ts=time.time()
        wsec=int(ts)
        fsec = ts-int(ts)

    return BULKIO.PrecisionUTCTime(tsrc,
                                   BULKIO.TCS_VALID, 0.0,
                                   wsec, fsec )
Ejemplo n.º 7
0
    def pushSRI(self, streamId="defaultStreamId", xstart=0.0):
        sri = bulkio.sri.create(streamId)
        sri.xstart = xstart
        ts = time.time()
        T = BULKIO.PrecisionUTCTime(BULKIO.TCM_CPU, BULKIO.TCS_VALID, 0.0,
                                    int(ts), ts - int(ts))
        expected_packets = self.source.packets_ingested + 1
        inFloatPort = self.source.getPort("dataFloat_in")
        inFloatPort.pushSRI(sri)
        inFloatPort.pushPacket(range(1, 100), T, False, streamId)

        # Wait until we know that the packet and SRI have been processed by the
        # source; this prevents some tests from reporting spurious failures due
        # to the appearance of an SRI change versus a new SRI, especially when
        # running the Python implemenation.
        self.waitForPacketIngestion(self.source, expected_packets, delay=0.1)
Ejemplo n.º 8
0
 def get_nav_packet(self, port_name):
     _time = BULKIO.PrecisionUTCTime(1, 1, 1.0, 1.0, 1.0)
     _positioninfo = FRONTEND.PositionInfo(False, 'DATUM_WGS84', 0.0, 0.0,
                                           0.0)
     _cartesianpos = FRONTEND.CartesianPositionInfo(False, 'DATUM_WGS84',
                                                    0.0, 0.0, 0.0)
     _velocityinfo = FRONTEND.VelocityInfo(False, 'DATUM_WGS84', '', 0.0,
                                           0.0, 0.0)
     _accelerationinfo = FRONTEND.AccelerationInfo(False, 'DATUM_WGS84', '',
                                                   0.0, 0.0, 0.0)
     _attitudeinfo = FRONTEND.AttitudeInfo(False, 0.0, 0.0, 0.0)
     _navpacket = FRONTEND.NavigationPacket('', '', _positioninfo,
                                            _cartesianpos, _velocityinfo,
                                            _accelerationinfo,
                                            _attitudeinfo, _time, [])
     return _navpacket
Ejemplo n.º 9
0
    def testGPSSetter(self):
        input_parent = self.gps_port_sample()
        input_parent_2 = self.gps_port_sample()
        input_port_1 = InGPSPort("input_1", input_parent)
        output_port = OutGPSPort("output")

        self.assertEquals(input_parent.get_source_id(), "original")

        gpsinfo = FRONTEND.GPSInfo(
            '', '', '', 1L, 1L, 1L, 1.0, 1.0, 1.0, 1.0, 1, 1.0, '',
            BULKIO.PrecisionUTCTime(1, 1, 1.0, 1.0, 1.0), [])
        gpsinfo.source_id = "newvalue"

        output_port._set_gps_info(gpsinfo)
        self.assertEquals(input_parent.get_source_id(), "original")
        self.assertRaises(PortCallError, output_port._set_gps_info, gpsinfo,
                          "hello")

        output_port.connectPort(input_port_1._this(), "hello")

        output_port._set_gps_info(gpsinfo)
        self.assertEquals(input_parent.get_source_id(), "newvalue")

        gpsinfo.source_id = "newvalue_2"
        output_port._set_gps_info(gpsinfo, "hello")
        self.assertEquals(input_parent.get_source_id(), "newvalue_2")

        self.assertRaises(PortCallError, output_port._set_gps_info, gpsinfo,
                          "foo")

        gpsinfo.source_id = "newvalue_3"
        input_port_2 = InGPSPort("input_2", input_parent_2)
        output_port.connectPort(input_port_2._this(), "foo")

        output_port._set_gps_info(gpsinfo)
        self.assertEquals(input_parent.get_source_id(), "newvalue_3")
        self.assertEquals(input_parent_2.get_source_id(), "newvalue_3")

        gpsinfo.source_id = "newvalue_4"
        output_port._set_gps_info(gpsinfo, "hello")
        self.assertEquals(input_parent.get_source_id(), "newvalue_4")
        self.assertEquals(input_parent_2.get_source_id(), "newvalue_3")

        self.assertRaises(PortCallError, output_port._set_gps_info, gpsinfo,
                          "something")

        output_port.disconnectPort("hello")
    def testBasicBehavior(self):
        self.assertEquals(self.got_logmsg, False)
        #######################################################################
        # Make sure start and stop can be called without throwing exceptions
        exc_src = sb.launch('./build/fei_exception_through/tests/fei_exc_src/fei_exc_src.spd.xml')
        self.comp.connect(exc_src,usesPortName='DigitalTuner_out')
        self.comp.connect(exc_src,usesPortName='RFInfo_out')
        self.comp.connect(exc_src,usesPortName='GPS_out')
        self.comp.connect(exc_src,usesPortName='NavData_out')
        self.comp.connect(exc_src,usesPortName='RFSource_out')
        for port in self.comp.ports:
            if port.name == 'DigitalTuner_in':
                DigitalTuner_in = port
            if port.name == 'RFInfo_in':
                RFInfo_in = port
            if port.name == 'GPS_in':
                GPS_in = port
            if port.name == 'NavData_in':
                NavData_in = port
            if port.name == 'RFSource_in':
                RFSource_in = port
                
        _time = BULKIO.PrecisionUTCTime(1,1,1.0,1.0,1.0)
        _gpsinfo = FRONTEND.GPSInfo('','','',1L,1L,1L,1.0,1.0,1.0,1.0,1,1.0,'',_time,[])
        _positioninfo = FRONTEND.PositionInfo(False,'DATUM_WGS84',0.0,0.0,0.0)
        _gpstimepos = FRONTEND.GpsTimePos(_positioninfo,_time)
        _cartesianpos=FRONTEND.CartesianPositionInfo(False,'DATUM_WGS84',0.0,0.0,0.0)
        _velocityinfo=FRONTEND.VelocityInfo(False,'DATUM_WGS84','',0.0,0.0,0.0)
        _accelerationinfo=FRONTEND.AccelerationInfo(False,'DATUM_WGS84','',0.0,0.0,0.0)
        _attitudeinfo=FRONTEND.AttitudeInfo(False,0.0,0.0,0.0)
        _navpacket=FRONTEND.NavigationPacket('','',_positioninfo,_cartesianpos,_velocityinfo,_accelerationinfo,_attitudeinfo,_time,[])
        _antennainfo=FRONTEND.AntennaInfo('','','','')
        _freqrange=FRONTEND.FreqRange(0,0,[])
        _feedinfo=FRONTEND.FeedInfo('','',_freqrange)
        _sensorinfo=FRONTEND.SensorInfo('','','',_antennainfo,_feedinfo)
        _rfcapabilities=FRONTEND.RFCapabilities(_freqrange,_freqrange)
        _rfinfopkt=FRONTEND.RFInfoPkt('',0.0,0.0,0.0,False,_sensorinfo,[],_rfcapabilities,[])
        _strat = FRONTEND.ScanningTuner.ScanStrategy(FRONTEND.ScanningTuner.DISCRETE_SCAN, FRONTEND.ScanningTuner.ScanModeDefinition(discrete_freq_list=[]), FRONTEND.ScanningTuner.TIME_BASED, 0.1)

        DigitalTuner_in.ref.getScanStatus('hello')
        DigitalTuner_in.ref.setScanStartTime('hello', _time)
        DigitalTuner_in.ref.setScanStrategy('hello', _strat)
        DigitalTuner_in.ref.getTunerType('hello')
        DigitalTuner_in.ref.getTunerDeviceControl('hello')
        DigitalTuner_in.ref.getTunerGroupId('hello')
        DigitalTuner_in.ref.getTunerRfFlowId('hello')
        DigitalTuner_in.ref.setTunerCenterFrequency('hello', 1.0)
        DigitalTuner_in.ref.getTunerCenterFrequency('hello')
        DigitalTuner_in.ref.setTunerBandwidth('hello', 1.0)
        DigitalTuner_in.ref.getTunerBandwidth('hello')
        DigitalTuner_in.ref.setTunerAgcEnable('hello', True)
        DigitalTuner_in.ref.getTunerAgcEnable('hello')
        DigitalTuner_in.ref.setTunerGain('hello', 1.0)
        DigitalTuner_in.ref.getTunerGain('hello')
        DigitalTuner_in.ref.setTunerReferenceSource('hello', 1L)
        DigitalTuner_in.ref.getTunerReferenceSource('hello')
        DigitalTuner_in.ref.setTunerEnable('hello', True)
        DigitalTuner_in.ref.getTunerEnable('hello')
        DigitalTuner_in.ref.setTunerOutputSampleRate('hello', 1.0)
        DigitalTuner_in.ref.getTunerOutputSampleRate('hello')
        GPS_in.ref._get_gps_info()
        GPS_in.ref._set_gps_info(_gpsinfo)
        GPS_in.ref._get_gps_time_pos()
        GPS_in.ref._set_gps_time_pos(_gpstimepos)
        NavData_in.ref._get_nav_packet()
        NavData_in.ref._set_nav_packet(_navpacket)
        RFInfo_in.ref._get_rf_flow_id()
        RFInfo_in.ref._set_rf_flow_id('rf_flow')
        RFInfo_in.ref._get_rfinfo_pkt()
        RFInfo_in.ref._set_rfinfo_pkt(_rfinfopkt)
        
        os.killpg(exc_src._pid, 9)
        
        while True:
            try:
                os.kill(exc_src._pid, 0)
                time.sleep(0.1)
            except:
                break
        
        exception = (CORBA.COMM_FAILURE, CORBA.TRANSIENT)

        self.assertRaises(exception, DigitalTuner_in.ref.getScanStatus, 'hello')
        self.assertRaises(exception, DigitalTuner_in.ref.setScanStartTime, 'hello', _time)
        self.assertRaises(exception, DigitalTuner_in.ref.setScanStrategy, 'hello', _strat)
        self.assertRaises(exception, DigitalTuner_in.ref.getTunerType, 'hello')
        self.assertRaises(exception, DigitalTuner_in.ref.getTunerDeviceControl, 'hello')
        self.assertRaises(exception, DigitalTuner_in.ref.getTunerGroupId, 'hello')
        self.assertRaises(exception, DigitalTuner_in.ref.getTunerRfFlowId, 'hello')
        self.assertRaises(exception, DigitalTuner_in.ref.setTunerCenterFrequency, 'hello', 1.0)
        self.assertRaises(exception, DigitalTuner_in.ref.getTunerCenterFrequency, 'hello')
        self.assertRaises(exception, DigitalTuner_in.ref.setTunerBandwidth, 'hello', 1.0)
        self.assertRaises(exception, DigitalTuner_in.ref.getTunerBandwidth, 'hello')
        self.assertRaises(exception, DigitalTuner_in.ref.setTunerAgcEnable, 'hello', True)
        self.assertRaises(exception, DigitalTuner_in.ref.getTunerAgcEnable, 'hello')
        self.assertRaises(exception, DigitalTuner_in.ref.setTunerGain, 'hello', 1.0)
        self.assertRaises(exception, DigitalTuner_in.ref.getTunerGain, 'hello')
        self.assertRaises(exception, DigitalTuner_in.ref.setTunerReferenceSource, 'hello', 1L)
        self.assertRaises(exception, DigitalTuner_in.ref.getTunerReferenceSource, 'hello')
        self.assertRaises(exception, DigitalTuner_in.ref.setTunerEnable, 'hello', True)
        self.assertRaises(exception, DigitalTuner_in.ref.getTunerEnable, 'hello')
        self.assertRaises(exception, DigitalTuner_in.ref.setTunerOutputSampleRate, 'hello', 1.0)
        self.assertRaises(exception, DigitalTuner_in.ref.getTunerOutputSampleRate, 'hello')
        self.assertRaises(exception, GPS_in.ref._get_gps_info)
        self.assertRaises(exception, GPS_in.ref._set_gps_info, _gpsinfo)
        self.assertRaises(exception, GPS_in.ref._get_gps_time_pos)
        self.assertRaises(exception, GPS_in.ref._set_gps_time_pos, _gpstimepos)
        self.assertRaises(exception, NavData_in.ref._get_nav_packet)
        self.assertRaises(exception, NavData_in.ref._set_nav_packet, _navpacket)
        self.assertRaises(exception, RFInfo_in.ref._get_rf_flow_id)
        self.assertRaises(exception, RFInfo_in.ref._set_rf_flow_id, 'rf_flow')
        self.assertRaises(exception, RFInfo_in.ref._get_rfinfo_pkt)
        self.assertRaises(exception, RFInfo_in.ref._set_rfinfo_pkt, _rfinfopkt)
Ejemplo n.º 11
0
 def get_gps_time_pos(self, port_name):
     _positioninfo = FRONTEND.PositionInfo(False, 'DATUM_WGS84', 0.0, 0.0,
                                           0.0)
     _gpstimepos = FRONTEND.GpsTimePos(
         _positioninfo, BULKIO.PrecisionUTCTime(1, 1, 1.0, 1.0, 1.0))
     return _gpstimepos
Ejemplo n.º 12
0
 def get_gps_info(self, port_name):
     _gpsinfo = FRONTEND.GPSInfo(
         '', '', '', 1L, 1L, 1L, 1.0, 1.0, 1.0, 1.0, 1, 1.0, '',
         BULKIO.PrecisionUTCTime(1, 1, 1.0, 1.0, 1.0), [])
     return _gpsinfo
    def run(self, filename, sri=None, pktsize=1024, numpkts=0, startTime=0.0, sampleRate=1.0, complexData=False, streamID=None):
        """
        Pushes the data through the connected port.  Each packet of data
        contains no more than pktsize elements.  Once all the elements have
        been sent, the method sends an empty list with the EOS set to True to
        indicate the end of the stream.

        Inputs:
            <data>       A list of elements containing the data to push
            <sri>        SRI to send before pushing data
            <pktsize>    The maximum number of elements to send on each push
            <numpkts>    The maximum number of packets to send
            <startTime>  The time of the first sample
            <sampleRate> The sample rate of the data used to set xdelta in the SRI
            <complexData>The mode of the data (real=0(False),complex=1(True)) in the SRI
            <streamID>   The streamID of the data
        """

        # Update SRI based on arguments passed in
        if sri != None:
            self.sri = sri
        else:
            if sampleRate > 0:
                self.sri.xdelta = 1/sampleRate
            if complexData:
                self.sri.mode = 1
            else:
                self.sri.mode = 0
            if streamID != None:
                self.sri.streamID = streamID
            if startTime >= 0.0:
                self.sri.xstart = startTime

        self.pushSRI(self.sri)

        run_complete = False
        self.pkts_sent = 0
        if self.file_d == None or self.file_d.closed:
            self.file_d = open( filename, 'rb' );
            self.EOS = False

        if self.file_d.closed:
            log.info("file data has been exhausted!")

        currentSampleTime = self.sri.xstart
        while not self.EOS and not run_complete:
            T = BULKIO.PrecisionUTCTime(BULKIO.TCM_CPU, BULKIO.TCS_VALID, 0.0, int(currentSampleTime), currentSampleTime - int(currentSampleTime))
            byteData = self.file_d.read(pktsize * self.byte_per_sample)
            if (len(byteData) < pktsize * self.byte_per_sample):
                self.EOS = True
            signalData = byteData
            if self.structFormat not in ('b', 'B', 'c'):
                dataSize = len(byteData)/self.byte_per_sample
                fmt = self._byteswap + str(dataSize) + self.structFormat
                signalData = struct.unpack(fmt, byteData)
            else:
                dataSize = len(byteData)                                                                     
            if self.sri.mode == 1:                                                                                 
                dataSize = dataSize/2                                                                      

            self.pushPacket(signalData,T, False, self.sri.streamID)
            sampleRate = 1.0/self.sri.xdelta
            currentSampleTime = currentSampleTime + dataSize/sampleRate
            self.pkts_sent += 1
            if numpkts != 0 and numpkts == self.pkts_sent:
                run_complete = True

        if self.EOS:
            # Send EOS flag = true
            T = BULKIO.PrecisionUTCTime(BULKIO.TCM_CPU, BULKIO.TCS_VALID, 0.0, int(currentSampleTime), currentSampleTime - int(currentSampleTime))
            if self.structFormat not in ('b', 'B', 'c'):
                self.pushPacket([], T, True, self.sri.streamID)
            else:
                self.pushPacket('', T, True, self.sri.streamID)
            self.file_d.close()
        else:
            pass
    def run(self, data, sri=None, pktsize=1024, startTime=0.0, sampleRate=1.0, complexData=False, streamID=None):
        """
        Pushes the data through the connected port.  Each packet of data
        contains no more than pktsize elements.  Once all the elements have
        been sent, the method sends an empty list with the EOS set to True to
        indicate the end of the stream.

        Inputs:
            <data>       A list of elements containing the data to push
            <sri>        SRI to send before pushing data
            <pktsize>    The maximum number of elements to send on each push
            <startTime>  The time of the first sample
            <sampleRate> The sample rate of the data used to set xdelta in the SRI
            <complexData>The mode of the data (real=0(False),complex=1(True)) in the SRI
            <streamID>   The streamID of the data
        """
        start = 0           # stores the start of the packet
        end = start         # stores the end of the packet
        sz = len(data)
        self.done = False
        if sri != None:
            self.sri = sri
        else:
            if sampleRate > 0:
                self.sri.xdelta = 1/sampleRate
            if complexData:
                self.sri.mode = 1
            else:
                self.sri.mode = 0
            if streamID != None:
                self.sri.streamID = streamID
            if startTime >= 0.0:
                self.sri.xstart = startTime
        self.pushSRI(self.sri)

        currentSampleTime = self.sri.xstart
        while not self.done:
            chunk = start + pktsize
            # if the next chunk is greater than the file, then grab remaining
            # only, otherwise grab a whole packet size
            if chunk > sz:
                end = sz
                self.done = True
            else:
                end = chunk

            # there are cases when this happens: array has 6 elements and
            # pktsize = 2 (end = length - 1 = 5 and start = 6)
            if start > end:
                self.done = True
                continue

            d = data[start:end]
            start = end

            T = BULKIO.PrecisionUTCTime(BULKIO.TCM_CPU, BULKIO.TCS_VALID, 0.0, int(currentSampleTime), currentSampleTime - int(currentSampleTime))
            self.pushPacket(d, T, False, self.sri.streamID)
            dataSize = len(d)
            if self.sri.mode == 1:
                dataSize = dataSize / 2
            currentSampleTime = currentSampleTime + dataSize/sampleRate
        T = BULKIO.PrecisionUTCTime(BULKIO.TCM_CPU, BULKIO.TCS_VALID, 0.0, int(currentSampleTime), currentSampleTime - int(currentSampleTime))
        self.pushPacket([], T, True, self.sri.streamID)
Ejemplo n.º 15
0
    def run(self, infile, pktsize=1024, streamID=None):
        """
        Pushes the data through the connected port.  Each packet of data 
        contains no more than pktsize elements.  Once all the elements have 
        been sent, the method sends an empty list with the EOS set to True to 
        indicate the end of the stream.
        
        Inputs:
            <infile>     The name of the X-Midas file containing the data 
                         to push
            <pktsize>    The maximum number of elements to send on each push
            <streamID>   The stream ID to be used, if None, then it defaults to filename 
        """
        hdr, data = bluefile.read(infile, list)
        # generates a new SRI based on the header of the file
        path, stream_id = os.path.split(infile)
        if streamID == None:
            sri = hdr_to_sri(hdr, stream_id)
        else:
            sri = hdr_to_sri(hdr, streamID)
        self.pushSRI(sri)

        start = 0  # stores the start of the packet
        end = start  # stores the end of the packet

        if hdr['format'].startswith('C'):
            data = data.flatten()
            if hdr['format'].endswith('F'):
                data = data.view(float32)
            elif hdr['format'].endswith('D'):
                data = data.view(float64)

        sz = len(data)
        self.done = False

        # Use midas header timecode to set time of first sample
        # NOTE: midas time is seconds since Jan. 1 1950
        #       Redhawk time is seconds since Jan. 1 1970
        currentSampleTime = 0.0
        if hdr.has_key('timecode'):
            # Set sample time to seconds since Jan. 1 1970
            currentSampleTime = hdr['timecode'] - long(631152000)
            if currentSampleTime < 0:
                currentSampleTime = 0.0

        while not self.done:
            chunk = start + pktsize
            # if the next chunk is greater than the file, then grab remaining
            # only, otherwise grab a whole packet size
            if chunk > sz:
                end = sz
                self.done = True
            else:
                end = chunk

            dataset = data[start:end]

            # X-Midas returns an array, so we need to generate a list
            if hdr['format'].endswith('B'):
                d = dataset.tostring()
            else:
                d = dataset.tolist()
            start = end

            T = BULKIO.PrecisionUTCTime(
                BULKIO.TCM_CPU, BULKIO.TCS_VALID, 0.0, int(currentSampleTime),
                currentSampleTime - int(currentSampleTime))
            self.pushPacket(d, T, False, sri.streamID)
            dataSize = len(d)
            sampleRate = 1.0 / sri.xdelta
            currentSampleTime = currentSampleTime + dataSize / sampleRate
        T = BULKIO.PrecisionUTCTime(BULKIO.TCM_CPU, BULKIO.TCS_VALID, 0.0,
                                    int(currentSampleTime),
                                    currentSampleTime - int(currentSampleTime))
        if hdr['format'].endswith('B'):
            self.pushPacket('', T, True, sri.streamID)
        else:
            self.pushPacket([], T, True, sri.streamID)
Ejemplo n.º 16
0
def createTimestamp(wsec, fsec=0.0):
    return BULKIO.PrecisionUTCTime(BULKIO.TCM_CPU, BULKIO.TCS_VALID, 0.0, wsec,
                                   fsec)
Ejemplo n.º 17
0
        try:
            self.port_digitaltuner_out.setTunerOutputSampleRate(tmp, 1.0)
        except PortCallError, e:
            self.set_tuneroutputsamplerate = str(e)

        self.get_gpsinfo = "ok"
        try:
            self.port_gps_out.gps_info()
        except PortCallError, e:
            self.get_gpsinfo = str(e)

        self.set_gpsinfo = "ok"
        try:
            _gps = FRONTEND.GPSInfo(
                '', '', '', 1L, 1L, 1L, 1.0, 1.0, 1.0, 1.0, 1, 1.0, '',
                BULKIO.PrecisionUTCTime(1, 1, 1.0, 1.0, 1.0), [])
            self.port_gps_out._set_gps_info(_gps)
        except PortCallError, e:
            self.set_gpsinfo = str(e)

        self.get_gps_timepos = "ok"
        try:
            self.port_gps_out.gps_time_pos()
        except PortCallError, e:
            self.get_gps_timepos = str(e)

        self.set_gps_timepos = "ok"
        try:
            _positioninfo = FRONTEND.PositionInfo(False, 'DATUM_WGS84', 0.0,
                                                  0.0, 0.0)
            _gps = FRONTEND.GpsTimePos(