示例#1
0
 def dhost(self, program=False):
     if self._dhost is not None:
         return self._dhost
     else:
         self.config_filename = '/etc/corr/{}-{}'.format(self.array_name, self.instrument)
         if os.path.exists(self.config_filename):
             LOGGER.info('Retrieving dsim engine info from config file: %s' % self.config_filename)
             self.corr_config = corr2.utils.parse_ini_file(self.config_filename)
             self.dsim_conf = self.corr_config['dsimengine']
         elif self.instrument is not None:
             self.corr2ini_path = '/etc/corr/templates/{}'.format(self.instrument)
             LOGGER.info('Setting CORR2INI system enviroment to point to %s' % self.corr2ini_path)
             os.environ['CORR2INI'] = self.corr2ini_path
             self.corr_config = corr2.utils.parse_ini_file(self.corr2ini_path)
             self.dsim_conf = self.corr_config['dsimengine']
         else:
             errmsg = ('Could not retrieve dsim information from running config file in /etc/corr, '
                       'Perhaps, restart CBF manually and ensure dsim is running.\n'
                       'File:%s Line:%s' % (getframeinfo(currentframe()).filename.split('/')[-1],
                                            getframeinfo(currentframe()).lineno))
             LOGGER.error(errmsg)
             sys.exit(errmsg)
         try:
             dig_host = self.dsim_conf['host']
             self._dhost = FpgaDsimHost(dig_host, config=self.dsim_conf)
         except Exception:
             errmsg = 'Digitiser Simulator failed to retrieve information'
             LOGGER.exception(errmsg)
             sys.exit(errmsg)
         else:
             # Check if D-eng is running else start it.
             if self._dhost.is_running():
                 LOGGER.info('D-Eng is already running.')
             # Disabled DSim programming as it would alter the systems sync epoch
             elif program and not self._dhost.is_running():
                 LOGGER.info('Programming and starting the Digitiser Simulator.')
                 self._dhost.initialise()
                 self._dhost.enable_data_output(enabled=True)
                 self._dhost.registers.control.write(gbe_txen=True)
             else:
                 LOGGER.info('D-Eng started succesfully')
             return self._dhost
示例#2
0
 def dhost(self, program=False):
     if self._dhost is not None:
         return self._dhost
     else:
         if os.path.exists(self.config_filename):
             LOGGER.info(
                 'Retrieving dsim engine info from config file: %s' %
                 self.config_filename)
             self.corr_config = parse_ini_file(self.config_filename)
             self.dsim_conf = self.corr_config['dsimengine']
         elif self.instrument is not None:
             self.corr2ini_path = '/etc/corr/templates/{}'.format(
                 self.instrument)
             LOGGER.info(
                 'Setting CORR2INI system environment to point to %s' %
                 self.corr2ini_path)
             os.environ['CORR2INI'] = self.corr2ini_path
             self.corr_config = parse_ini_file(self.corr2ini_path)
             self.dsim_conf = self.corr_config['dsimengine']
         else:
             errmsg = (
                 'Could not retrieve dsim information from running config file in /etc/corr, '
                 'Perhaps, restart CBF manually and ensure dsim is running.\n'
             )
             LOGGER.error(errmsg)
             sys.exit(errmsg)
         try:
             dig_host = self.dsim_conf['host']
             self._dhost = None
             self._dhost = FpgaDsimHost(dig_host, config=self.dsim_conf)
         except Exception:
             errmsg = 'Digitiser Simulator failed to retrieve information'
             LOGGER.exception(errmsg)
             sys.exit(errmsg)
         else:
             # Check if D-eng is running else start it.
             if self._dhost.is_running():
                 LOGGER.info('D-Eng is already running.')
                 return self._dhost
示例#3
0
            help='Constant wave output scale')
    parser.add_argument(
            '-n', '--noise_scale', type=float, default=0.05,
            help='Noise output scale')

    args = parser.parse_args()
    cw_scale = args.cw_scale
    n_scale = args.noise_scale
    freq = args.frequency

    #Connect to DSIM
    corr_conf = utils.parse_ini_file(args.config, ['dsimengine'])
    dsim_conf = corr_conf['dsimengine']
    dig_host = dsim_conf['host']
    dsim_fpg = dsim_conf['bitstream']
    dhost = FpgaDsimHost(dig_host, config=dsim_conf)
    if dig_host.lower().find('skarab') != -1:
        dhost.get_system_information(filename=dsim_fpg)
    else:
        dhost.get_system_information()


    #Clear all noise sources
    sources_names = dhost.noise_sources.names()
    for source in sources_names:
        try:
            noise_source = getattr(dhost.noise_sources, '{}'.format(source))
            noise_source.set(0)
            print("noise source {}, set to {}.".format(noise_source.name,
                                                       noise_source.scale))
        except:
def SpeadRx(config_file, rx_port, dsim_start, capture_start, debug, verbose):
    """
    Receive data from Correlator and play
    """
    if config_file is None:
        sys.exit("Usage: %s --help" % __file__)

    try:
        assert verbose
        _level = 'DEBUG'
        logging.basicConfig(
            level=logging.DEBUG,
            format=
            '%(asctime)s - %(name)s - %(levelname)s - %(module)s - %(pathname)s : '
            '%(lineno)d - %(message)s')
        corr_rx_logger.setLevel(logging.DEBUG)
        spead2_logger.setLevel(logging.DEBUG)
        logging.debug('DEBUG MODE ENABLED')
    except:
        _level = 'INFO'
        logging.basicConfig(
            level=logging.INFO,
            format=
            '%(asctime)s - %(name)s - %(levelname)s - %(module)s - %(pathname)s : '
            '%(lineno)d - %(message)s')
        corr_rx_logger.setLevel(logging.INFO)
        spead2_logger.setLevel(logging.INFO)
    finally:
        logger = logging.getLogger(__name__)
        coloredlogs.install(level=_level, logger=logger)

    if dsim_start and config_file:
        corr_conf = utils.parse_ini_file(config_file, ['dsimengine'])
        dsim_conf = corr_conf['dsimengine']
        dhost = FpgaDsimHost(dsim_conf['host'], config=dsim_conf)
        try:
            assert dhost.is_running()
            dhost.get_system_information()
        except:
            logger.error('DEngine Not Running!')

    try:
        assert capture_start
    except AssertionError:

        @atexit.register
        def Cleanup():
            logger.info('baseline-correlation-products capture stopped!')
            receiver.stop()
            receiver.join()
            logger.info('Receiver stopped.')
            fab.local(
                "kcpcmd -t 60 -s localhost:$(kcpcmd array-list | grep -a array-list | cut -f3 -d ' ' ) capture-stop baseline-correlation-products"
            )
    else:
        logger.info('baseline-correlation-products capture started!')
        fab.local(
            "kcpcmd -t 60 -s localhost:$(kcpcmd array-list | grep -a array-list | cut -f3 -d ' ' ) capture-start baseline-correlation-products"
        )

    try:
        receiver = CorrRx(port=rx_port, queue_size=5)
        _multicast_ips = corr_conf['xengine'].get(
            'multicast_interface_address', '239.100.0.1')
        # import IPython; IPython.embed(header='Python Debugger')
    except Exception as ex:
        template = "An exception of type {0} occured while trying to instantiate receiver. Arguments:\n{1!r}"
        message = template.format(type(ex), ex.args)
        logger.info(message)
    else:
        logger.info('Waiting for receiver to report running')
        receiver.daemon = True
        receiver.start(timeout=10)
        if receiver.running_event.wait(timeout=10):
            logger.info('Receiver ready')
        else:
            msg = 'Receiver not ready'
            logger.info(msg)
            raise RuntimeError(msg)
        try:
            raw_input('Press Enter get clean dump')
            dump = receiver.get_clean_dump()
        except KeyboardInterrupt:
            logger.info('Keyboard interrupt')
        except Exception:
            raise
        else:
            logger.info('Dump received')
        if debug:
            corr_rx_logger.setLevel(logging.FATAL)
            spead2_logger.setLevel(logging.FATAL)
            import IPython
            IPython.embed(header='Python Debugger')