transmit.grc 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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: blocks_throttle_0
  47. id: blocks_throttle
  48. parameters:
  49. affinity: ''
  50. alias: ''
  51. comment: ''
  52. ignoretag: 'True'
  53. maxoutbuf: '0'
  54. minoutbuf: '0'
  55. samples_per_second: sample_rate_hz
  56. type: byte
  57. vlen: '1'
  58. states:
  59. bus_sink: false
  60. bus_source: false
  61. bus_structure: null
  62. coordinate: [649, 177]
  63. rotation: 0
  64. state: bypassed
  65. - name: message_generator_block
  66. id: epy_block
  67. parameters:
  68. _source_code: "import json\nimport pathlib\n\nimport gnuradio.gr\nimport numpy\n\
  69. \n\nclass MessageGeneratorBlock(gnuradio.gr.basic_block):\n def __init__(self):\n\
  70. \ gnuradio.gr.basic_block.__init__(\n self, name=\"Message\
  71. \ Generator\", in_sig=None, out_sig=[numpy.uint8]\n )\n # __file__\
  72. \ is not available\n self._messages = json.loads(\n pathlib.Path().resolve().parent.joinpath(\"\
  73. messages.json\").read_text()\n )\n\n def general_work(self, input_items,\
  74. \ output_items) -> int:\n # pylint: disable=unused-argument\n \
  75. \ message = self._messages[\"ON0\"] + [0] * 128\n if len(output_items[0])\
  76. \ < len(message):\n print(\"output buffer too short\", len(output_items[0]))\n\
  77. \ output_items[0][:] = 0\n return len(output_items[0])\n\
  78. \ output_items[0][: len(message)] = message\n return len(message)\n"
  79. affinity: ''
  80. alias: ''
  81. comment: ''
  82. maxoutbuf: '0'
  83. minoutbuf: '0'
  84. states:
  85. _io_cache: ('Message Generator', 'MessageGeneratorBlock', [], [], [('0', 'byte',
  86. 1)], '', [])
  87. bus_sink: false
  88. bus_source: false
  89. bus_structure: null
  90. coordinate: [286, 318]
  91. rotation: 0
  92. state: true
  93. - name: qtgui_time_raster_sink_x_0
  94. id: qtgui_time_raster_sink_x
  95. parameters:
  96. affinity: ''
  97. alias: ''
  98. alpha1: '1.0'
  99. alpha10: '1.0'
  100. alpha2: '1.0'
  101. alpha3: '1.0'
  102. alpha4: '1.0'
  103. alpha5: '1.0'
  104. alpha6: '1.0'
  105. alpha7: '1.0'
  106. alpha8: '1.0'
  107. alpha9: '1.0'
  108. axislabels: 'True'
  109. color1: '2'
  110. color10: '0'
  111. color2: '0'
  112. color3: '0'
  113. color4: '0'
  114. color5: '0'
  115. color6: '0'
  116. color7: '0'
  117. color8: '0'
  118. color9: '0'
  119. comment: ''
  120. grid: 'False'
  121. gui_hint: ''
  122. label1: ''
  123. label10: ''
  124. label2: ''
  125. label3: ''
  126. label4: ''
  127. label5: ''
  128. label6: ''
  129. label7: ''
  130. label8: ''
  131. label9: ''
  132. mult: '[]'
  133. name: '""'
  134. ncols: int(sample_rate_hz)
  135. nconnections: '1'
  136. nrows: '60'
  137. offset: '[]'
  138. samp_rate: sample_rate_hz
  139. type: byte
  140. update_time: '0.10'
  141. zmax: '1'
  142. zmin: '0'
  143. states:
  144. bus_sink: false
  145. bus_source: false
  146. bus_structure: null
  147. coordinate: [1091, 145]
  148. rotation: 0
  149. state: true
  150. - name: serial_sink_block
  151. id: epy_block
  152. parameters:
  153. _source_code: "import ctypes\nimport ctypes.util\nimport time\n\nimport gnuradio.gr\n\
  154. import numpy\nimport serial\n\n_LIBC_NAME = ctypes.util.find_library(\"c\")\n\
  155. if not _LIBC_NAME:\n raise Exception(\"couldn't find libc\")\n_LIBC = ctypes.CDLL(_LIBC_NAME)\n\
  156. \n\nclass _Timespec(ctypes.Structure):\n # pylint: disable=too-few-public-methods\n\
  157. \ \"\"\"\n > struct timespec {\n > time_t tv_sec; /* seconds\
  158. \ */\n > long tv_nsec; /* nanoseconds */\n > };\n\n > The\
  159. \ value of the nanoseconds field must be in the range 0 to 999999999.\n \"\
  160. \"\"\n _fields_ = [(\"tv_sec\", ctypes.c_uint32), (\"tv_nsec\", ctypes.c_long)]\n\
  161. \n\n_NANOSLEEP = _LIBC.nanosleep\n_NANOSLEEP.argtypes = [ctypes.POINTER(_Timespec),\
  162. \ ctypes.POINTER(_Timespec)]\n_NANOSLEEP.restype = ctypes.c_int\n\n\nclass SerialSinkBlock(gnuradio.gr.basic_block):\n\
  163. \ _SLEEP_THRESHOLD_NS = 10000\n\n def __init__(self, port=\"/dev/ttyUSB0\"\
  164. , baud_rate=115200, sample_rate_hz=1000):\n gnuradio.gr.basic_block.__init__(\n\
  165. \ self, name=\"Serial Sink Block\", in_sig=[numpy.uint8], out_sig=None\n\
  166. \ )\n self._serial_port = serial.Serial(\n port=port,\
  167. \ baudrate=baud_rate, bytesize=serial.EIGHTBITS\n )\n self._tick_interval_ns\
  168. \ = int(1e9 / sample_rate_hz)\n # periodically return from .general_work()\
  169. \ to handle signals\n self._work_max_samples = max(int(sample_rate_hz\
  170. \ * 2), 1)\n self._next_tick_time_ns = None\n self._libc = ctypes.CDLL(ctypes.util.find_library(\"\
  171. c\"))\n\n def general_work(self, input_items, output_items) -> int:\n \
  172. \ # pylint: disable=unused-argument\n if not self._next_tick_time_ns:\n\
  173. \ self._next_tick_time_ns = time.perf_counter_ns()\n for byte\
  174. \ in input_items[0][: self._work_max_samples]:\n while (\n \
  175. \ self._next_tick_time_ns - time.perf_counter_ns()\n ) >\
  176. \ self._SLEEP_THRESHOLD_NS:\n _NANOSLEEP(\n \
  177. \ _Timespec(\n 0,\n # negative\
  178. \ values make nanosleep return -1\n min(\n \
  179. \ self._next_tick_time_ns\n - time.perf_counter_ns()\n\
  180. \ - self._SLEEP_THRESHOLD_NS,\n \
  181. \ 999999999,\n ),\n ),\n\
  182. \ None,\n )\n while (self._next_tick_time_ns\
  183. \ - time.perf_counter_ns()) > 0:\n pass\n self._serial_port.write(b\"\
  184. \\x01\" if byte else b\"\\0\")\n self._next_tick_time_ns += self._tick_interval_ns\n\
  185. \ self.consume(0, min(len(input_items[0]), self._work_max_samples))\n\
  186. \ return 0\n"
  187. affinity: ''
  188. alias: ''
  189. baud_rate: '115200'
  190. comment: ''
  191. maxoutbuf: '0'
  192. minoutbuf: '0'
  193. port: '"/dev/ttyUSB0"'
  194. sample_rate_hz: sample_rate_hz
  195. states:
  196. _io_cache: ('Serial Sink Block', 'SerialSinkBlock', [('port', "'/dev/ttyUSB0'"),
  197. ('baud_rate', '115200'), ('sample_rate_hz', '1000')], [('0', 'byte', 1)], [],
  198. '', [])
  199. bus_sink: false
  200. bus_source: false
  201. bus_structure: null
  202. coordinate: [625, 417]
  203. rotation: 0
  204. state: enabled
  205. connections:
  206. - [blocks_throttle_0, '0', qtgui_time_raster_sink_x_0, '0']
  207. - [message_generator_block, '0', blocks_throttle_0, '0']
  208. - [message_generator_block, '0', serial_sink_block, '0']
  209. metadata:
  210. file_format: 1