Example #1
0
    def _setup_session(self, config):
        if len(config.sensor) > 1:
            raise ValueError("the register protocol does not support multiple sensors")
        if config.sensor[0] != 1:
            raise ValueError("the register protocol currently only supports using sensor 1")

        mode = protocol.get_mode(config.mode)
        self._mode = mode

        self._experimental_stitching = bool(config.experimental_stitching)
        sweep_rate = None if config.experimental_stitching else config.sweep_rate
        self.__cmd_proc("set_mode_and_rate", mode, sweep_rate)

        self._write_reg("main_control", "stop")

        self._write_reg("mode_selection", mode)

        if config.experimental_stitching:
            self._write_reg("repetition_mode", "max")
            log.warning("experimental stitching on - switching to max freq. mode")
        else:
            self._write_reg("repetition_mode", "fixed")

        self._write_reg("streaming_control", "disable")
        self._write_reg("sensor_power_mode", "d")

        if mode == "iq":
            self._write_reg("output_data_compression", 1)

        rvs = utils.get_reg_vals_for_config(config)
        for rv in rvs:
            self._write_reg_raw(rv.addr, rv.val)

        self._write_reg("main_control", "create")
        sleep(SPI_MAIN_CTRL_SLEEP)
        status = self._read_reg("status")

        if status & protocol.STATUS_ERROR_ON_SERVICE_CREATION_MASK:
            raise ClientError("session setup failed")

        info = {}
        info_regs = utils.get_session_info_regs(mode)
        for reg in info_regs:
            info[reg.name] = self._read_reg(reg)

        self._num_subsweeps = info.get("number_of_subsweeps")

        # data rate check
        data_length = info.get("data_length")
        freq = info.get("frequency")
        bpp = protocol.BYTE_PER_POINT.get(mode)
        if data_length:
            log.debug("assumed data length: {}".format(data_length))

            if bpp and freq and not config.experimental_stitching:
                data_rate = 8 * bpp * data_length * freq
                log_text = "data rate: {:.2f} Mbit/s".format(data_rate*1e-6)
                log.info(log_text)

        return info
    def _setup_session(self, config):
        if len(config.sensor) > 1:
            raise ValueError("the register protocol does not support multiple sensors")
        if config.sensor[0] != 1:
            raise ValueError("the register protocol currently only supports using sensor 1")

        mode = protocol.get_mode(config.mode)
        self._mode = mode

        self._write_reg("main_control", "stop")

        self._write_reg("mode_selection", mode)
        self._write_reg("repetition_mode", "fixed")
        self._write_reg("streaming_control", "uart")

        if mode == "iq":
            self._write_reg("output_data_compression", 1)

        rvs = utils.get_reg_vals_for_config(config)
        for rv in rvs:
            self._write_reg_raw(rv.addr, rv.val)

        self._write_reg("main_control", "create")

        info = {}
        info_regs = utils.get_session_info_regs(mode)
        for reg in info_regs:
            info[reg.name] = self._read_reg(reg, mode)

        # data rate check
        data_length = info.get("data_length")
        freq = info.get("frequency")
        bpp = protocol.BYTE_PER_POINT.get(mode)
        if data_length:
            log.debug("data length: {}".format(data_length))

            if bpp and freq:
                data_rate = 8 * bpp * data_length * freq
                log_text = "data rate: {:.2f} Mbit/s".format(data_rate*1e-6)
                if data_rate > 2/3 * self._link.baudrate:
                    log.warn(log_text)
                    log.warn("data rate might be too high")
                else:
                    log.info(log_text)

        return info