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: '1195'
  39. states:
  40. bus_sink: false
  41. bus_source: false
  42. bus_structure: null
  43. coordinate: [670, 313]
  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: '10'
  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: qtgui_time_sink_x_0
  86. id: qtgui_time_sink_x
  87. parameters:
  88. affinity: ''
  89. alias: ''
  90. alpha1: '1.0'
  91. alpha10: '1.0'
  92. alpha2: '1.0'
  93. alpha3: '1.0'
  94. alpha4: '1.0'
  95. alpha5: '1.0'
  96. alpha6: '1.0'
  97. alpha7: '1.0'
  98. alpha8: '1.0'
  99. alpha9: '1.0'
  100. autoscale: 'False'
  101. axislabels: 'True'
  102. color1: blue
  103. color10: dark blue
  104. color2: red
  105. color3: green
  106. color4: black
  107. color5: cyan
  108. color6: magenta
  109. color7: yellow
  110. color8: dark red
  111. color9: dark green
  112. comment: ''
  113. ctrlpanel: 'False'
  114. entags: 'True'
  115. grid: 'False'
  116. gui_hint: ''
  117. label1: Signal 1
  118. label10: Signal 10
  119. label2: Signal 2
  120. label3: Signal 3
  121. label4: Signal 4
  122. label5: Signal 5
  123. label6: Signal 6
  124. label7: Signal 7
  125. label8: Signal 8
  126. label9: Signal 9
  127. legend: 'False'
  128. marker1: '-1'
  129. marker10: '-1'
  130. marker2: '-1'
  131. marker3: '-1'
  132. marker4: '-1'
  133. marker5: '-1'
  134. marker6: '-1'
  135. marker7: '-1'
  136. marker8: '-1'
  137. marker9: '-1'
  138. name: '""'
  139. nconnections: '1'
  140. size: int(sample_rate_hz*1)
  141. srate: sample_rate_hz
  142. stemplot: 'False'
  143. style1: '1'
  144. style10: '1'
  145. style2: '1'
  146. style3: '1'
  147. style4: '1'
  148. style5: '1'
  149. style6: '1'
  150. style7: '1'
  151. style8: '1'
  152. style9: '1'
  153. tr_chan: '0'
  154. tr_delay: '0'
  155. tr_level: '0.0'
  156. tr_mode: qtgui.TRIG_MODE_FREE
  157. tr_slope: qtgui.TRIG_SLOPE_POS
  158. tr_tag: '""'
  159. type: float
  160. update_time: '0.10'
  161. width1: '1'
  162. width10: '1'
  163. width2: '1'
  164. width3: '1'
  165. width4: '1'
  166. width5: '1'
  167. width6: '1'
  168. width7: '1'
  169. width8: '1'
  170. width9: '1'
  171. ylabel: Signal
  172. ymax: '1'
  173. ymin: '0'
  174. yunit: '""'
  175. states:
  176. bus_sink: false
  177. bus_source: false
  178. bus_structure: null
  179. coordinate: [883, 144]
  180. rotation: 0
  181. state: enabled
  182. - name: serial_sink_block
  183. id: epy_block
  184. parameters:
  185. _source_code: "import ctypes\nimport ctypes.util\nimport time\n\nimport gnuradio.gr\n\
  186. import numpy\nimport serial\n\n_LIBC_NAME = ctypes.util.find_library(\"c\")\n\
  187. if not _LIBC_NAME:\n raise Exception(\"couldn't find libc\")\n_LIBC = ctypes.CDLL(_LIBC_NAME)\n\
  188. \n\nclass _Timespec(ctypes.Structure):\n # pylint: disable=too-few-public-methods\n\
  189. \ \"\"\"\n > struct timespec {\n > time_t tv_sec; /* seconds\
  190. \ */\n > long tv_nsec; /* nanoseconds */\n > };\n\n > The\
  191. \ value of the nanoseconds field must be in the range 0 to 999999999.\n \"\
  192. \"\"\n _fields_ = [(\"tv_sec\", ctypes.c_uint32), (\"tv_nsec\", ctypes.c_long)]\n\
  193. \n\n_NANOSLEEP = _LIBC.nanosleep\n_NANOSLEEP.argtypes = [ctypes.POINTER(_Timespec),\
  194. \ ctypes.POINTER(_Timespec)]\n_NANOSLEEP.restype = ctypes.c_int\n\n\nclass SerialSinkBlock(gnuradio.gr.basic_block):\n\
  195. \ _SLEEP_THRESHOLD_NS = 10000\n\n def __init__(self, port=\"/dev/ttyUSB0\"\
  196. , baud_rate=115200, sample_rate_hz=1000):\n gnuradio.gr.basic_block.__init__(\n\
  197. \ self, name=\"Serial Sink Block\", in_sig=[numpy.uint8], out_sig=None\n\
  198. \ )\n self._serial_port = serial.Serial(\n port=port,\
  199. \ baudrate=baud_rate, bytesize=serial.EIGHTBITS\n )\n self._tick_interval_ns\
  200. \ = int(1e9 / sample_rate_hz)\n # periodically return from .general_work()\
  201. \ to handle signals\n self._work_max_samples = max(int(sample_rate_hz\
  202. \ * 2), 1)\n self._next_tick_time_ns = None\n self._libc = ctypes.CDLL(ctypes.util.find_library(\"\
  203. c\"))\n\n def general_work(self, input_items, output_items) -> int:\n \
  204. \ # pylint: disable=unused-argument\n if not self._next_tick_time_ns:\n\
  205. \ self._next_tick_time_ns = time.perf_counter_ns()\n for byte\
  206. \ in input_items[0][: self._work_max_samples]:\n while (\n \
  207. \ self._next_tick_time_ns - time.perf_counter_ns()\n ) >\
  208. \ self._SLEEP_THRESHOLD_NS:\n _NANOSLEEP(\n \
  209. \ _Timespec(\n 0,\n # negative\
  210. \ values make nanosleep return -1\n min(\n \
  211. \ self._next_tick_time_ns\n - time.perf_counter_ns()\n\
  212. \ - self._SLEEP_THRESHOLD_NS,\n \
  213. \ 999999999,\n ),\n ),\n\
  214. \ None,\n )\n while (self._next_tick_time_ns\
  215. \ - time.perf_counter_ns()) > 0:\n pass\n self._serial_port.write(b\"\
  216. \\x01\" if byte else b\"\\0\")\n self._next_tick_time_ns += self._tick_interval_ns\n\
  217. \ self.consume(0, min(len(input_items[0]), self._work_max_samples))\n\
  218. \ return 0\n"
  219. affinity: ''
  220. alias: ''
  221. baud_rate: '115200'
  222. comment: ''
  223. maxoutbuf: '0'
  224. minoutbuf: '0'
  225. port: '"/dev/ttyUSB0"'
  226. sample_rate_hz: sample_rate_hz
  227. states:
  228. _io_cache: ('Serial Sink Block', 'SerialSinkBlock', [('port', "'/dev/ttyUSB0'"),
  229. ('baud_rate', '115200'), ('sample_rate_hz', '1000')], [('0', 'byte', 1)], [],
  230. '', [])
  231. bus_sink: false
  232. bus_source: false
  233. bus_structure: null
  234. coordinate: [625, 417]
  235. rotation: 0
  236. state: true
  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