Example #1
0
 def frequency_changed(self):
     actual_frequency = utils.bound(self.__clb_dll.get_frequency(),
                                    clb.MIN_FREQUENCY, clb.MAX_FREQUENCY)
     if self.__frequency != actual_frequency:
         self.__frequency = actual_frequency
         return True
     else:
         return False
Example #2
0
 def limit_amplitude(self, a_amplitude, a_lower, a_upper):
     """
     Обрезает значение амплитуды с учетом типа сигнала и параметров пользователя
     :param a_amplitude: Заданная амплитуда
     :param a_lower: Нижняя граница
     :param a_upper: Верхняя граница
     """
     return utils.bound(
         clb.bound_amplitude(a_amplitude, self.__signal_type), a_lower,
         a_upper)
Example #3
0
def bound_frequency(a_frequency: float, a_signal_type: SignalType) -> float:
    """
    Обрезает частоту в допустимых для калибратора границах, в зависимости от типа сигнала (постоянный или переменный)
    Если тип сигнала постоянный, то всегда возвращает 0
    :param a_frequency: Уставка частоты
    :param a_signal_type: Тип сигнала
    :return: Обрезанная уставка частоты
    """
    min_frequency = MIN_FREQUENCY if is_ac_signal[a_signal_type] else 0
    max_frequency = MAX_FREQUENCY if is_ac_signal[a_signal_type] else 0
    return round(bound(a_frequency, min_frequency, max_frequency), 9)
 def get_display_precision(a_value: float, a_full_precision: int) -> str:
     """
     Конвертирует число в строку с учетом количества разрядов до запятой
     Например для числа 0,123 precision=a_full_precision
     Для числа 1,234 precision=a_full_precision - 1
     Для числа 12,345 precision=a_full_precision - 2
     """
     value_str = f"{a_value:.9f}"
     before_decimal_count = len(value_str.split('.')[0])
     precision = utils.bound(a_full_precision + 1 - before_decimal_count, 0,
                             a_full_precision)
     return precision
Example #5
0
def bound_amplitude(a_amplitude: float, a_signal_type: SignalType) -> float:
    """
    Обрезает амплитуду в допустимых для калибратора границах, в зависимости от типа сигнала
    Для постоянных типов сигнала может возвращать амплитуду с отрицательным знаком
    :param a_amplitude: Уставка амплитуды
    :param a_signal_type: Тип сигнала
    :return: Обрезанная уставка амплитуды
    """
    min_value = MIN_VOLTAGE
    max_value = MAX_VOLTAGE
    if not is_voltage_signal[a_signal_type]:
        min_value = MIN_CURRENT
        max_value = MAX_CURRENT
    if is_ac_signal[a_signal_type]:
        min_value = MIN_AC_AMPLITUDE
    return round(bound(a_amplitude, min_value, max_value), 9)
Example #6
0
 def bound_input(self, a_value):
     return utils.bound(a_value, self.min_value, self.max_value)
    def tick(self):
        if self.__prev_stage != self.__stage:
            self.__prev_stage = self.__stage
            try:
                logging.debug(CorrectionFlasher.STAGE_IN_MESSAGE[self.__stage])
            except KeyError:
                pass

        if self.__stage == CorrectionFlasher.Stage.REST:
            pass

        elif self.__stage == CorrectionFlasher.Stage.RESET_EEPROM:
            self.__funnel_client.destroy()
            self.__metadata_are_read = False

            if self.__started:
                self.__stage = CorrectionFlasher.Stage.SET_UP_FUNNEL
            else:
                self.__stage = CorrectionFlasher.Stage.DONE

        elif self.__stage == CorrectionFlasher.Stage.SET_UP_FUNNEL:
            self.__current_flash_data = self.__flash_data[
                self.__current_flash_data_idx]
            if self.__action == CorrectionFlasher.Action.READ:
                if not self.__metadata_are_read:
                    # Чтение начинаем с чтения метаданных, чтобы не читать с запасом
                    data_size = self.__get_flash_metadata_size()
                else:
                    self.__correct_map.create()
                    self.__correct_map.connect(
                        self.__funnel_client.get_address())
                    x_count = self.__correct_map.get_x_points_count()
                    y_count = self.__correct_map.get_y_points_count()
                    data_size = self.__get_flash_data_size(x_count, y_count)
            else:
                data_size = self.__get_flash_data_size(
                    len(self.__current_flash_data.x_points),
                    len(self.__current_flash_data.y_points))

            self.__funnel_client.create(
                self.__mxdata, CorrectionFlasher.FUNNEL_MXDATA_OFFSET,
                self.__current_flash_data.eeprom_offset, data_size)

            self.__stage = CorrectionFlasher.NEXT_STAGE[self.__stage]

        elif self.__stage == CorrectionFlasher.Stage.CONNECT_TO_FUNNEL:
            self.__funnel_client.tick()
            if self.__funnel_client.connected():
                self.__stage = CorrectionFlasher.NEXT_STAGE[self.__stage]

        elif self.__stage == CorrectionFlasher.Stage.READ_WRITE_START:
            if self.__action == CorrectionFlasher.Action.READ:
                self.__funnel_client.reset_stat_read_complete()

                if not self.__metadata_are_read:
                    self.__stage = CorrectionFlasher.Stage.WAIT_EEPROM_READ_METADATA
                else:
                    logging.info(
                        f"Верификация диапазона: {self.__current_flash_data.diapason_name}"
                    )
                    self.__stage = CorrectionFlasher.Stage.WAIT_EEPROM_READ_DATA
            else:
                logging.info(
                    f"Прошивка диапазона: {self.__current_flash_data.diapason_name}"
                )
                self.__stage = CorrectionFlasher.Stage.WRITE_TO_EEPROM

        elif self.__stage == CorrectionFlasher.Stage.WAIT_EEPROM_READ_METADATA:
            if not self.__funnel_client.is_read_complete():
                self.__funnel_client.tick()
            else:
                self.__metadata_are_read = True
                self.__stage = CorrectionFlasher.NEXT_STAGE[self.__stage]

        elif self.__stage == CorrectionFlasher.Stage.WAIT_EEPROM_READ_DATA:
            if not self.__funnel_client.is_read_complete():
                self.__funnel_client.tick()

                data_size = self.__funnel_client.data_size()
                self.__progress = (
                    data_size -
                    self.__funnel_client.get_read_size()) / data_size * 100
                self.__progress = utils.bound(self.__progress, 0., 100.)
            else:
                self.__progress = 100
                self.__stage = CorrectionFlasher.NEXT_STAGE[self.__stage]

        elif self.__stage == CorrectionFlasher.Stage.VERIFY_DATA:
            self.__correct_map.connect(self.__funnel_client.get_address())
            x_points = self.__correct_map.x_points
            y_points = self.__correct_map.y_points
            coefs_points = self.__correct_map.coef_points

            if self.__save_instead_of_verify:
                real_coefs = []
                for num, coef in enumerate(self.__correct_map.coef_points):
                    y = self.__correct_map.y_points[num // (len(
                        self.__correct_map.x_points))]
                    real_coefs.append(y * coef)

                self.__read_data[
                    self.__current_flash_data.diapason_name].append(
                        (self.__correct_map.x_points,
                         self.__correct_map.y_points, real_coefs))
                logging.debug(
                    f"Измерение {self.__current_flash_data.diapason_name}. Данные считаны."
                )
            else:
                if x_points == list(self.__current_flash_data.x_points) and \
                        y_points == list(self.__current_flash_data.y_points) and \
                        coefs_points == list(self.__current_flash_data.coef_points):
                    logging.info(
                        "Данные в калибраторе соответствуют данным в таблице")
                else:
                    logging.warning(
                        "ВНИМАНИЕ! Данные в калибраторе отличаются от данных в таблице"
                    )

            self.__stage = CorrectionFlasher.NEXT_STAGE[self.__stage]

        elif self.__stage == CorrectionFlasher.Stage.WRITE_TO_EEPROM:
            self.__correct_map.create()
            self.__correct_map.connect(self.__funnel_client.get_address())
            self.__correct_map.set_x_points_count(
                len(self.__current_flash_data.x_points))
            self.__correct_map.set_y_points_count(
                len(self.__current_flash_data.y_points))
            self.__correct_map.connect(self.__funnel_client.get_address())

            self.__correct_map.x_points = self.__current_flash_data.x_points
            self.__correct_map.y_points = self.__current_flash_data.y_points
            self.__correct_map.coef_points = self.__current_flash_data.coef_points

            self.__stage = CorrectionFlasher.NEXT_STAGE[self.__stage]

        elif self.__stage == CorrectionFlasher.Stage.WAIT_WRITE:
            write_remain_bytes = self.__funnel_client.get_write_size()
            if write_remain_bytes > 0:
                self.__funnel_client.tick()

                data_size = self.__funnel_client.data_size()
                self.__progress = (data_size -
                                   write_remain_bytes) / data_size * 100
            else:
                self.__progress = 100
                self.__stage = CorrectionFlasher.NEXT_STAGE[self.__stage]

        elif self.__stage == CorrectionFlasher.Stage.NEXT_DIAPASON:
            self.__progress = 0
            if self.__current_flash_data_idx + 1 != len(self.__flash_data):
                self.__current_flash_data_idx += 1
                self.__current_flash_data = self.__flash_data[
                    self.__current_flash_data_idx]
            else:
                self.__action = CorrectionFlasher.Action.NONE
                self.__started = False

            self.__stage = CorrectionFlasher.NEXT_STAGE[self.__stage]

        elif self.__stage == CorrectionFlasher.Stage.DONE:
            self.__stage = CorrectionFlasher.NEXT_STAGE[self.__stage]
Example #8
0
 def frequency(self, a_frequency: float):
     frequency = utils.bound(a_frequency, clb.MIN_FREQUENCY,
                             clb.MAX_FREQUENCY)
     self.__clb_dll.set_frequency(frequency)