# -*- coding: UTF-8 -*- """ @Project :Matrix_Check @File :SignalInitTableCheck.py @Author :haojiang @Date :2022/9/28 18:15 """ import csv from enum import Enum import logging import re class TableColumnHeaderType(Enum): Signal = 0 Type = 1 Bit = 2 App = 3 AppValue = 4 Raw = 5 RawValue = 6 Controller = 7 Frame = 8 PDU = 9 class SignalInitValueTableCheck: Column_Need_Check = [TableColumnHeaderType.Signal, TableColumnHeaderType.Type, TableColumnHeaderType.Bit, TableColumnHeaderType.RawValue] # Type_Mapping = { # 'Boolean': bool, # 'UInt': , # 'SInt': , # 'Composite':, # 'Bytes': # } def __init__(self, project_path: str): pass def check_row(self, row: dict) -> bool: # raw missing validation # type validation, between[Boolean Composite SInt UInt Bytes] signal_value_type = row[TableColumnHeaderType.Type.name] try: # bit length validation signal_bit_len = int(row[TableColumnHeaderType.Bit.name]) # raw value range validation except ValueError as e: logging.error(f'Signal Bit Transform Failed! Origin bit str is {row[TableColumnHeaderType.Bit.name]}') signal_bit_len = 0 def get_signal_init_value_table(self) -> list: pass def get_rx_tx_csv_file_name(self) -> tuple: pass def get_csv_data(self, file_name: str) -> list: with open(file_name, 'r') as csvfile: spamreader = csv.reader(csvfile, delimiter=',') is_header_readed = False table_data = list() for row in spamreader: if not is_header_readed: is_header_readed = True continue row_data = dict() for col in SignalInitValueTableCheck.Column_Need_Check: row_data[col.name] = row[col.value] table_data.append(row_data) return table_data def get_range_by_bit_length(self, bit_len: int, is_signed: bool = False): # [0, 2^n-1] 2^n = 1<