SignalInitTableCheck.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # -*- coding: UTF-8 -*-
  2. """
  3. @Project :Matrix_Check
  4. @File :SignalInitTableCheck.py
  5. @Author :haojiang
  6. @Date :2022/9/28 18:15
  7. """
  8. import csv
  9. from enum import Enum
  10. import logging
  11. import re
  12. class TableColumnHeaderType(Enum):
  13. Signal = 0
  14. Type = 1
  15. Bit = 2
  16. App = 3
  17. AppValue = 4
  18. Raw = 5
  19. RawValue = 6
  20. Controller = 7
  21. Frame = 8
  22. PDU = 9
  23. class SignalInitValueTableCheck:
  24. Column_Need_Check = [TableColumnHeaderType.Signal,
  25. TableColumnHeaderType.Type,
  26. TableColumnHeaderType.Bit,
  27. TableColumnHeaderType.RawValue]
  28. # Type_Mapping = {
  29. # 'Boolean': bool,
  30. # 'UInt': ,
  31. # 'SInt': ,
  32. # 'Composite':,
  33. # 'Bytes':
  34. # }
  35. def __init__(self, project_path: str):
  36. pass
  37. def check_row(self, row: dict) -> bool:
  38. # raw missing validation
  39. # type validation, between[Boolean Composite SInt UInt Bytes]
  40. signal_value_type = row[TableColumnHeaderType.Type.name]
  41. try:
  42. # bit length validation
  43. signal_bit_len = int(row[TableColumnHeaderType.Bit.name])
  44. # raw value range validation
  45. except ValueError as e:
  46. logging.error(f'Signal Bit Transform Failed! Origin bit str is {row[TableColumnHeaderType.Bit.name]}')
  47. signal_bit_len = 0
  48. def get_signal_init_value_table(self) -> list:
  49. pass
  50. def get_rx_tx_csv_file_name(self) -> tuple:
  51. pass
  52. def get_csv_data(self, file_name: str) -> list:
  53. with open(file_name, 'r') as csvfile:
  54. spamreader = csv.reader(csvfile, delimiter=',')
  55. is_header_readed = False
  56. table_data = list()
  57. for row in spamreader:
  58. if not is_header_readed:
  59. is_header_readed = True
  60. continue
  61. row_data = dict()
  62. for col in SignalInitValueTableCheck.Column_Need_Check:
  63. row_data[col.name] = row[col.value]
  64. table_data.append(row_data)
  65. return table_data
  66. def get_range_by_bit_length(self, bit_len: int, is_signed: bool = False):
  67. # [0, 2^n-1] 2^n = 1<<n
  68. # [-2^{n-1}, 2^{n-1}-1]
  69. if is_signed:
  70. return (-(1<<(bit_len-1)), (1<<(bit_len-1))-1)
  71. else:
  72. return (0, (1<<bit_len)-1)
  73. if __name__ == '__main__':
  74. 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'
  75. sc = SignalInitValueTableCheck()
  76. sc.get_csv_data(matrix_path)