transmit.grc 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. options:
  2. parameters:
  3. author: ''
  4. category: '[GRC Hier Blocks]'
  5. cmake_opt: ''
  6. comment: ''
  7. copyright: ''
  8. description: ''
  9. gen_cmake: 'On'
  10. gen_linking: dynamic
  11. generate_options: qt_gui
  12. hier_block_src_path: '.:'
  13. id: transmit
  14. max_nouts: '0'
  15. output_language: python
  16. placement: (0,0)
  17. qt_qss_theme: ''
  18. realtime_scheduling: ''
  19. run: 'True'
  20. run_command: '{python} -u {filename}'
  21. run_options: prompt
  22. sizing_mode: fixed
  23. thread_safe_setters: ''
  24. title: Arduino Serial Transmitter
  25. window_size: ''
  26. states:
  27. bus_sink: false
  28. bus_source: false
  29. bus_structure: null
  30. coordinate: [70, 37]
  31. rotation: 0
  32. state: enabled
  33. blocks:
  34. - name: sample_rate_hz
  35. id: variable
  36. parameters:
  37. comment: ''
  38. value: '1000'
  39. states:
  40. bus_sink: false
  41. bus_source: false
  42. bus_structure: null
  43. coordinate: [668, 314]
  44. rotation: 0
  45. state: enabled
  46. - name: analog_sig_source_x_0
  47. id: analog_sig_source_x
  48. parameters:
  49. affinity: ''
  50. alias: ''
  51. amp: '1'
  52. comment: ''
  53. freq: '200'
  54. maxoutbuf: '0'
  55. minoutbuf: '0'
  56. offset: '0'
  57. phase: '0'
  58. samp_rate: sample_rate_hz
  59. type: byte
  60. waveform: analog.GR_SQR_WAVE
  61. states:
  62. bus_sink: false
  63. bus_source: false
  64. bus_structure: null
  65. coordinate: [70, 187]
  66. rotation: 0
  67. state: true
  68. - name: blocks_char_to_float_0
  69. id: blocks_char_to_float
  70. parameters:
  71. affinity: ''
  72. alias: ''
  73. comment: ''
  74. maxoutbuf: '0'
  75. minoutbuf: '0'
  76. scale: '1'
  77. vlen: '1'
  78. states:
  79. bus_sink: false
  80. bus_source: false
  81. bus_structure: null
  82. coordinate: [627, 176]
  83. rotation: 0
  84. state: enabled
  85. - name: serial_sink_block
  86. id: epy_block
  87. parameters:
  88. _source_code: "import ctypes\nimport ctypes.util\nimport time\n\nimport gnuradio.gr\n\
  89. import numpy\nimport serial\n\n_LIBC_NAME = ctypes.util.find_library(\"c\")\n\
  90. if not _LIBC_NAME:\n raise Exception(\"couldn't find libc\")\n_LIBC = ctypes.CDLL(_LIBC_NAME)\n\
  91. \n\nclass _Timespec(ctypes.Structure):\n # pylint: disable=too-few-public-methods\n\
  92. \ \"\"\"\n > struct timespec {\n > time_t tv_sec; /* seconds\
  93. \ */\n > long tv_nsec; /* nanoseconds */\n > };\n\n > The\
  94. \ value of the nanoseconds field must be in the range 0 to 999999999.\n \"\
  95. \"\"\n _fields_ = [(\"tv_sec\", ctypes.c_uint32), (\"tv_nsec\", ctypes.c_long)]\n\
  96. \n\n_NANOSLEEP = _LIBC.nanosleep\n_NANOSLEEP.argtypes = [ctypes.POINTER(_Timespec),\
  97. \ ctypes.POINTER(_Timespec)]\n_NANOSLEEP.restype = ctypes.c_int\n\n\nclass SerialSinkBlock(gnuradio.gr.basic_block):\n\
  98. \ _SLEEP_THRESHOLD_NS = 10000\n\n def __init__(self, port=\"/dev/ttyUSB0\"\
  99. , baud_rate=115200, sample_rate_hz=1000):\n gnuradio.gr.basic_block.__init__(\n\
  100. \ self, name=\"Serial Sink Block\", in_sig=[numpy.uint8], out_sig=None\n\
  101. \ )\n self._serial_port = serial.Serial(\n port=port,\
  102. \ baudrate=baud_rate, bytesize=serial.EIGHTBITS\n )\n self._tick_interval_ns\
  103. \ = int(1e9 / sample_rate_hz)\n # periodically return from .general_work()\
  104. \ to handle signals\n self._work_max_samples = max(int(sample_rate_hz\
  105. \ * 2), 1)\n self._next_tick_time_ns = None\n self._libc = ctypes.CDLL(ctypes.util.find_library(\"\
  106. c\"))\n\n def general_work(self, input_items, output_items) -> int:\n \
  107. \ # pylint: disable=unused-argument\n if not self._next_tick_time_ns:\n\
  108. \ self._next_tick_time_ns = time.perf_counter_ns()\n for byte\
  109. \ in input_items[0][: self._work_max_samples]:\n while (\n \
  110. \ self._next_tick_time_ns - time.perf_counter_ns()\n ) >\
  111. \ self._SLEEP_THRESHOLD_NS:\n _NANOSLEEP(\n \
  112. \ _Timespec(\n 0,\n # negative\
  113. \ values make nanosleep return -1\n min(\n \
  114. \ self._next_tick_time_ns\n - time.perf_counter_ns()\n\
  115. \ - self._SLEEP_THRESHOLD_NS,\n \
  116. \ 999999999,\n ),\n ),\n\
  117. \ None,\n )\n while (self._next_tick_time_ns\
  118. \ - time.perf_counter_ns()) > 0:\n pass\n self._serial_port.write(b\"\
  119. \\x01\" if byte else b\"\\0\")\n self._next_tick_time_ns += self._tick_interval_ns\n\
  120. \ self.consume(0, min(len(input_items[0]), self._work_max_samples))\n\
  121. \ return 0\n"
  122. affinity: ''
  123. alias: ''
  124. baud_rate: '115200'
  125. comment: ''
  126. maxoutbuf: '0'
  127. minoutbuf: '0'
  128. port: '"/dev/ttyUSB0"'
  129. sample_rate_hz: sample_rate_hz
  130. states:
  131. _io_cache: ('Serial Sink Block', 'SerialSinkBlock', [('port', "'/dev/ttyUSB0'"),
  132. ('baud_rate', '115200'), ('sample_rate_hz', '1000')], [('0', 'byte', 1)], [],
  133. '', [])
  134. bus_sink: false
  135. bus_source: false
  136. bus_structure: null
  137. coordinate: [625, 417]
  138. rotation: 0
  139. state: true
  140. - name: qtgui_time_sink_x_0
  141. id: qtgui_time_sink_x
  142. parameters:
  143. affinity: ''
  144. alias: ''
  145. alpha1: '1.0'
  146. alpha10: '1.0'
  147. alpha2: '1.0'
  148. alpha3: '1.0'
  149. alpha4: '1.0'
  150. alpha5: '1.0'
  151. alpha6: '1.0'
  152. alpha7: '1.0'
  153. alpha8: '1.0'
  154. alpha9: '1.0'
  155. autoscale: 'False'
  156. axislabels: 'True'
  157. color1: blue
  158. color10: dark blue
  159. color2: red
  160. color3: green
  161. color4: black
  162. color5: cyan
  163. color6: magenta
  164. color7: yellow
  165. color8: dark red
  166. color9: dark green
  167. comment: ''
  168. ctrlpanel: 'False'
  169. entags: 'True'
  170. grid: 'False'
  171. gui_hint: ''
  172. label1: Signal 1
  173. label10: Signal 10
  174. label2: Signal 2
  175. label3: Signal 3
  176. label4: Signal 4
  177. label5: Signal 5
  178. label6: Signal 6
  179. label7: Signal 7
  180. label8: Signal 8
  181. label9: Signal 9
  182. legend: 'False'
  183. marker1: '-1'
  184. marker10: '-1'
  185. marker2: '-1'
  186. marker3: '-1'
  187. marker4: '-1'
  188. marker5: '-1'
  189. marker6: '-1'
  190. marker7: '-1'
  191. marker8: '-1'
  192. marker9: '-1'
  193. name: '""'
  194. nconnections: '1'
  195. size: int(sample_rate_hz*1)
  196. srate: sample_rate_hz
  197. stemplot: 'False'
  198. style1: '1'
  199. style10: '1'
  200. style2: '1'
  201. style3: '1'
  202. style4: '1'
  203. style5: '1'
  204. style6: '1'
  205. style7: '1'
  206. style8: '1'
  207. style9: '1'
  208. tr_chan: '0'
  209. tr_delay: '0'
  210. tr_level: '0.0'
  211. tr_mode: qtgui.TRIG_MODE_FREE
  212. tr_slope: qtgui.TRIG_SLOPE_POS
  213. tr_tag: '""'
  214. type: float
  215. update_time: '0.10'
  216. width1: '1'
  217. width10: '1'
  218. width2: '1'
  219. width3: '1'
  220. width4: '1'
  221. width5: '1'
  222. width6: '1'
  223. width7: '1'
  224. width8: '1'
  225. width9: '1'
  226. ylabel: Signal
  227. ymax: '1'
  228. ymin: '0'
  229. yunit: '""'
  230. states:
  231. bus_sink: false
  232. bus_source: false
  233. bus_structure: null
  234. coordinate: [883, 144]
  235. rotation: 0
  236. state: enabled
  237. connections:
  238. - [analog_sig_source_x_0, '0', blocks_char_to_float_0, '0']
  239. - [analog_sig_source_x_0, '0', serial_sink_block, '0']
  240. - [blocks_char_to_float_0, '0', qtgui_time_sink_x_0, '0']
  241. metadata:
  242. file_format: 1