123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- # -*- 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<<n
- # [-2^{n-1}, 2^{n-1}-1]
- if is_signed:
- return (-(1<<(bit_len-1)), (1<<(bit_len-1))-1)
- else:
- return (0, (1<<bit_len)-1)
-
- if __name__ == '__main__':
- matrix_path = r'D:\01_Work\02_WP\EP39_EREV\branch\src\MatrixAssistant_V2.0\EP39_EREV_SIMU+_GW\20220729-qy1-EP39EREV_SIMU+_GW_Rx_初值表.csv'
- sc = SignalInitValueTableCheck()
- sc.get_csv_data(matrix_path)
|