pulse_generator_console_logreg.py 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. from dis import pretty_flags
  2. from PySide6 import QtWidgets # Импорт модуля QtWidgets из библиотеки PySide6
  3. from PySide6.QtGui import QPixmap,QFont
  4. import sys # Импорт модуля sys для работы с системными параметрами и выходом из программы
  5. import numpy as np
  6. import struct
  7. import xml.etree.ElementTree as ET
  8. from xml.dom import minidom
  9. def switch(metric):
  10. if metric == 'nS':
  11. return 10**-9
  12. elif metric == 'uS':
  13. return 10**-6
  14. elif metric == 'mS':
  15. return 10**-3
  16. elif metric == 'S':
  17. return 1
  18. def set_params(period, period_metric, width, width_metric, delay1, d1_metric, delay2, d2_metric, number, sr):
  19. pulse_period_metric = period_metric
  20. pulse_period = (np.int32(period)) * switch(pulse_period_metric)
  21. pulse_width_metric = width_metric
  22. pulse_width = (np.int32(width)) * switch(pulse_width_metric)
  23. delay1_metric = d1_metric
  24. delay1 = (np.int32(delay1)) * switch(delay1_metric)
  25. delay2_metric = d2_metric
  26. delay2 = (np.int32(delay2)) * switch(delay2_metric)
  27. sample_freq = np.int32(sr)
  28. pulse_number = np.int32(number)
  29. print(f""" Pulse parameters:
  30. pulse width - {pulse_width} S
  31. pulse period - {pulse_period} S
  32. delay 1 - {delay1} S
  33. delay 2 - {delay2} S
  34. pulse_number - {pulse_number}
  35. sample frequency {sample_freq} MHz""")
  36. #add = (pulse_width * pulse_number * sample_freq * (10**6) * 2)
  37. counter = 0
  38. n_high = round(pulse_width * sample_freq * (10 ** 6))
  39. print(f"high samples {n_high}")
  40. n_low = round((pulse_period - pulse_width) * sample_freq * (10 ** 6))
  41. print(f"low samples {n_low}")
  42. size_1 =(n_low + n_high) * 2
  43. print(f'rf array size_1 = {size_1}')
  44. size_2 = np.int32(size_1) * np.int32(pulse_number)
  45. print(f'rf array size_2 = {size_2}')
  46. rf_array = np.zeros(size_2, dtype=np.int8)
  47. for _ in range(0, pulse_number, 1):
  48. for _ in range(0, n_high, 1):
  49. rf_array[counter] = np.int8(127)
  50. rf_array[counter + 1] = np.int8(0)
  51. counter += 2
  52. for _ in range(0, n_low, 1):
  53. rf_array[counter] = np.int8(0)
  54. rf_array[counter + 1] = np.int8(0)
  55. counter += 2
  56. print(rf_array)
  57. f = open(f'test_linreg.bin', 'wb') # открываем файл на чтение
  58. # f = open(f'test_100_pulses_10Msps_1ms.bin', 'wb') # открываем файл на чтение
  59. for elem in rf_array: # берём каждую строчку из файла f
  60. f.write(struct.pack('<b',elem))
  61. f.close()
  62. # write sync params in XML file
  63. root = ET.Element('root')
  64. rf = ET.SubElement(root, 'RF')
  65. sw = ET.SubElement(root, 'SW')
  66. adc = ET.SubElement(root, 'ADC')
  67. gru1 = ET.SubElement(root, 'GR')
  68. first_pulse_delay = 17 * 10 ** -6
  69. if int(sr) == 2:
  70. first_pulse_delay = 17 * 10 ** -6
  71. elif int(sr) == 8:
  72. first_pulse_delay = 4.12 * 10 ** -6
  73. elif int(sr) == 10:
  74. first_pulse_delay = 3.26 * 10 ** -6
  75. elif (sr) == 20:
  76. first_pulse_delay = 1.5 * 10 ** -6
  77. cl = ET.SubElement(root, 'CL')
  78. ET.SubElement(rf,'RF1').text = '0'
  79. ET.SubElement(sw,'SW1').text = '0'
  80. ET.SubElement(adc,'ADC1').text = '0'
  81. ET.SubElement(gru1,'GR1').text = '1'
  82. ET.SubElement(cl, 'CL1').text = str(round(first_pulse_delay/ (20*(10**-9))))
  83. param_count = 1
  84. delay1_cycles = round(delay1 / (20*(10**-9)))
  85. pw_cycles = round(pulse_width / (20*(10**-9)))
  86. low_cycles = round((pulse_period - pulse_width - 2*delay1) / (20*(10**-9)))
  87. delay2_cycles = round (delay2 / (20*(10**-9)))
  88. recieve_time = low_cycles - 2 * delay2_cycles
  89. param_count += 1
  90. ET.SubElement(rf, 'RF' + str(param_count)).text = "0"
  91. ET.SubElement(sw, 'SW' + str(param_count)).text = "0"
  92. ET.SubElement(adc, 'ADC' + str(param_count)).text = "0"
  93. ET.SubElement(gru1, 'GR' + str(param_count)).text = "0"
  94. ET.SubElement(cl, 'CL' + str(param_count)).text = str((2 * delay1_cycles + pw_cycles + recieve_time + 2 * delay2_cycles) * (pulse_number-1))
  95. for _ in range (0, 1):
  96. param_count += 1
  97. ET.SubElement(rf, 'RF' + str(param_count)).text = "1"
  98. ET.SubElement(sw, 'SW' + str(param_count)).text = "0"
  99. ET.SubElement(adc, 'ADC' + str(param_count)).text = "0"
  100. ET.SubElement(gru1, 'GR' + str(param_count)).text = "0"
  101. ET.SubElement(cl, 'CL' + str(param_count)).text = str(2 * delay1_cycles + pw_cycles)
  102. param_count += 1
  103. ET.SubElement(rf, 'RF' + str(param_count)).text = "0"
  104. ET.SubElement(sw, 'SW' + str(param_count)).text = "0"
  105. ET.SubElement(adc, 'ADC' + str(param_count)).text = "0"
  106. ET.SubElement(gru1, 'GR' + str(param_count)).text = "0"
  107. ET.SubElement(cl, 'CL' + str(param_count)).text = str(delay2_cycles)
  108. param_count += 1
  109. ET.SubElement(rf, 'RF' + str(param_count)).text = "0"
  110. ET.SubElement(sw, 'SW' + str(param_count)).text = "0"
  111. ET.SubElement(adc, 'ADC' + str(param_count)).text = "1"
  112. ET.SubElement(gru1, 'GR' + str(param_count)).text = "0"
  113. ET.SubElement(cl, 'CL' + str(param_count)).text = str(recieve_time)
  114. param_count += 1
  115. ET.SubElement(rf, 'RF'+ str(param_count)).text = "0"
  116. ET.SubElement(sw,'SW'+ str(param_count)).text = "0"
  117. ET.SubElement(adc, 'ADC' + str(param_count)).text = "0"
  118. ET.SubElement(gru1, 'GR' + str(param_count)).text = "0"
  119. ET.SubElement(cl, 'CL' + str(param_count)).text = str(delay2_cycles)
  120. for RF_END in root.iter(f'RF{param_count-3}'):
  121. RF_END.text = '1'
  122. ET.SubElement(root, 'ParamCount').text = str(param_count)
  123. xml_str = ET.tostring(root, encoding='utf-8', method='xml')
  124. parsed_str = minidom.parseString(xml_str) # Парсим строку
  125. pretty_xml_str = parsed_str.toprettyxml(indent=" ") # Добавляем отступы
  126. # Сохраняем форматированный XML в файл
  127. with open('Sync_param.xml', 'w', encoding='utf-8') as f:
  128. f.write(pretty_xml_str)
  129. root_pico = ET.Element('root')
  130. points = ET.SubElement(root_pico, 'points')
  131. noc = ET.SubElement(root_pico, 'num_of_channels')
  132. times = ET.SubElement(root_pico, 'times')
  133. sr_pico = ET.SubElement(root_pico, 'sample_freq')
  134. ET.SubElement(sr_pico, 'title').text = 'Sample Frequency'
  135. ET.SubElement(sr_pico, 'value').text = str(80000000.0 * 5) # лютые костыли
  136. ET.SubElement(points, 'title').text = 'Points'
  137. ET.SubElement(points, 'value').text = str([round(80000000 * pulse_width)]) # лютые костыли
  138. ET.SubElement(noc, 'title').text = 'Number of Channels'
  139. ET.SubElement(noc, 'value').text = '4'
  140. ET.SubElement(times, 'title').text = 'Times'
  141. ET.SubElement(times, 'value').text = str([0.021])
  142. xml_str = ET.tostring(root_pico, encoding='utf-8', method='xml')
  143. parsed_str = minidom.parseString(xml_str) # Парсим строку
  144. pretty_xml_str = parsed_str.toprettyxml(indent=" ") # Добавляем отступы
  145. with open('pico_params.xml', 'w', encoding='utf-8') as f:
  146. f.write(pretty_xml_str)
  147. set_params(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5], sys.argv[6], sys.argv[7], sys.argv[8], sys.argv[9], sys.argv[10])