duggabe

test_strip.grc

Sep 10th, 2023
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.19 KB | None | 0 0
  1. options:
  2. parameters:
  3. author: Barry Duggan
  4. catch_exceptions: 'True'
  5. category: '[GRC Hier Blocks]'
  6. cmake_opt: ''
  7. comment: ''
  8. copyright: ''
  9. description: test base64 conversion
  10. gen_cmake: 'On'
  11. gen_linking: dynamic
  12. generate_options: qt_gui
  13. hier_block_src_path: '.:'
  14. id: test_strip
  15. max_nouts: '0'
  16. output_language: python
  17. placement: (0,0)
  18. qt_qss_theme: ''
  19. realtime_scheduling: ''
  20. run: 'True'
  21. run_command: '{python} -u {filename}'
  22. run_options: prompt
  23. sizing_mode: fixed
  24. thread_safe_setters: ''
  25. title: test_strip
  26. window_size: (1000,1000)
  27. states:
  28. bus_sink: false
  29. bus_source: false
  30. bus_structure: null
  31. coordinate: [16, 12.0]
  32. rotation: 0
  33. state: enabled
  34.  
  35. blocks:
  36. - name: samp_rate
  37. id: variable
  38. parameters:
  39. comment: ''
  40. value: '48000'
  41. states:
  42. bus_sink: false
  43. bus_source: false
  44. bus_structure: null
  45. coordinate: [200, 12.0]
  46. rotation: 0
  47. state: enabled
  48. - name: blocks_file_sink_0
  49. id: blocks_file_sink
  50. parameters:
  51. affinity: ''
  52. alias: ''
  53. append: 'False'
  54. comment: ''
  55. file: ./output.tmp
  56. type: byte
  57. unbuffered: 'True'
  58. vlen: '1'
  59. states:
  60. bus_sink: false
  61. bus_source: false
  62. bus_structure: null
  63. coordinate: [1248, 180.0]
  64. rotation: 0
  65. state: enabled
  66. - name: blocks_throttle2_0
  67. id: blocks_throttle2
  68. parameters:
  69. affinity: ''
  70. alias: ''
  71. comment: ''
  72. ignoretag: 'True'
  73. limit: auto
  74. maximum: '0.1'
  75. maxoutbuf: '0'
  76. minoutbuf: '0'
  77. samples_per_second: samp_rate
  78. type: byte
  79. vlen: '1'
  80. states:
  81. bus_sink: false
  82. bus_source: false
  83. bus_structure: null
  84. coordinate: [1072, 188.0]
  85. rotation: 0
  86. state: true
  87. - name: epy_block_0
  88. id: epy_block
  89. parameters:
  90. FileName: '"./gr-logo.png"'
  91. Pkt_len: '60'
  92. _source_code: "\"\"\"\nEmbedded Python Block: File Source to Tagged Stream\n\"\
  93. \"\"\n\nimport numpy as np\nfrom gnuradio import gr\nimport time\nimport pmt\n\
  94. import os.path\nimport sys\nimport base64\n\n\"\"\"\nState definitions\n \
  95. \ 0 idle\n 1 send preamble\n 2 send file data\n 3 send file\
  96. \ name\n 4 send post filler\n\"\"\"\n\nclass blk(gr.sync_block):\n def\
  97. \ __init__(self, FileName='None', Pkt_len=52):\n gr.sync_block.__init__(\n\
  98. \ self,\n name='EPB: File Source to Tagged Stream',\n\
  99. \ in_sig=None,\n out_sig=[np.uint8])\n self.FileName\
  100. \ = FileName\n self.Pkt_len = Pkt_len\n self.state = 0 #\
  101. \ idle state\n self.pre_count = 0\n self.indx = 0\n self._debug\
  102. \ = 0 # debug\n self.data = \"\"\n\n if (os.path.exists(self.FileName)):\n\
  103. \ # open input file\n self.f_in = open (self.FileName,\
  104. \ 'rb')\n self._eof = False\n if (self._debug):\n \
  105. \ print (\"File name:\", self.FileName)\n self.state =\
  106. \ 1\n else:\n print(self.FileName, 'does not exist')\n \
  107. \ self._eof = True\n self.state = 0\n\n self.char_list\
  108. \ = [37,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85, 85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,\
  109. \ 85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85, 85,85,85,93]\n self.c_len\
  110. \ = len (self.char_list)\n # print (self.c_len)\n self.filler\
  111. \ = [37,85,85,85, 35,69,79,70, 85,85,85,85,85,85,85,85, 85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,\
  112. \ 85,85,85,85,85,85,85,85,85,85,85,85,85,85,85,85, 85,85,85,93]\n self.f_len\
  113. \ = len (self.filler)\n\n def work(self, input_items, output_items):\n\n\
  114. \ if (self.state == 0):\n # idle\n return (0)\n\
  115. \n elif (self.state == 1):\n # send preamble\n \
  116. \ if (self._debug):\n print (\"state = 1\", self.pre_count)\n\
  117. \ key1 = pmt.intern(\"packet_len\")\n val1 = pmt.from_long(self.c_len)\n\
  118. \ self.add_item_tag(0, # Write to output port 0\n \
  119. \ self.indx, # Index of the tag\n key1, # Key of the tag\n\
  120. \ val1 # Value of the tag\n )\n \
  121. \ self.indx += self.c_len\n i = 0\n while (i < self.c_len):\n\
  122. \ output_items[0][i] = self.char_list[i]\n i +=\
  123. \ 1\n self.pre_count += 1\n if (self.pre_count > 64):\n\
  124. \ self.pre_count = 0\n self.state = 2 # send\
  125. \ msg\n return (self.c_len)\n\n elif (self.state == 2):\n\
  126. \ while (not (self._eof)):\n buff = self.f_in.read\
  127. \ (self.Pkt_len)\n b_len = len(buff)\n if b_len\
  128. \ == 0:\n print ('End of file')\n self._eof\
  129. \ = True\n self.f_in.close()\n self.state\
  130. \ = 3 # send file name\n self.pre_count = 0\n \
  131. \ break\n # convert to Base64\n encoded\
  132. \ = base64.b64encode (buff)\n e_len = len(encoded)\n \
  133. \ if (self._debug):\n print ('b64 length =', e_len)\n\
  134. \ key0 = pmt.intern(\"packet_len\")\n val0 = pmt.from_long(e_len)\n\
  135. \ self.add_item_tag(0, # Write to output port 0\n \
  136. \ self.indx, # Index of the tag\n key0, # Key\
  137. \ of the tag\n val0 # Value of the tag\n \
  138. \ )\n self.indx += e_len\n i = 0\n \
  139. \ while (i < e_len):\n output_items[0][i] = encoded[i]\n\
  140. \ i += 1\n return (e_len)\n\n elif\
  141. \ (self.state == 3):\n # send file name\n fn_len = len\
  142. \ (self.FileName)\n key1 = pmt.intern(\"packet_len\")\n \
  143. \ val1 = pmt.from_long(fn_len+8)\n self.add_item_tag(0, # Write\
  144. \ to output port 0\n self.indx, # Index of the tag\n \
  145. \ key1, # Key of the tag\n val1 # Value of the\
  146. \ tag\n )\n self.indx += (fn_len+8)\n i\
  147. \ = 0\n while (i < 8):\n output_items[0][i] = self.filler[i]\n\
  148. \ i += 1\n j = 0\n while (i < (fn_len+8)):\n\
  149. \ output_items[0][i] = ord(self.FileName[j])\n \
  150. \ i += 1\n j += 1\n self.state = 4\n return\
  151. \ (fn_len+8)\n\n elif (self.state == 4):\n # send post filler\n\
  152. \ if (self._debug):\n print (\"state = 4\", self.pre_count)\n\
  153. \ key1 = pmt.intern(\"packet_len\")\n val1 = pmt.from_long(self.f_len)\n\
  154. \ self.add_item_tag(0, # Write to output port 0\n \
  155. \ self.indx, # Index of the tag\n key1, # Key of the tag\n\
  156. \ val1 # Value of the tag\n )\n \
  157. \ self.indx += self.f_len\n i = 0\n while (i < self.f_len):\n\
  158. \ output_items[0][i] = self.filler[i]\n i += 1\n\
  159. \ self.pre_count += 1\n if (self.pre_count > 16):\n \
  160. \ self.pre_count = 0\n self.state = 0 # idle\n\
  161. \ return (self.f_len)\n\n return (0)\n\n"
  162. affinity: ''
  163. alias: ''
  164. comment: ''
  165. maxoutbuf: '0'
  166. minoutbuf: '0'
  167. states:
  168. _io_cache: '(''EPB: File Source to Tagged Stream'', ''blk'', [(''FileName'', "''None''"),
  169. (''Pkt_len'', ''52'')], [], [(''0'', ''byte'', 1)], '''', [''FileName'', ''Pkt_len''])'
  170. bus_sink: false
  171. bus_source: false
  172. bus_structure: null
  173. coordinate: [16, 188.0]
  174. rotation: 0
  175. state: true
  176. - name: epy_block_0_0
  177. id: epy_block
  178. parameters:
  179. _source_code: "import numpy as np\nfrom gnuradio import gr\nimport pmt\nimport\
  180. \ array\nimport base64\n\nclass blk(gr.sync_block):\n def __init__(self):\n\
  181. \ gr.sync_block.__init__(\n self,\n name='EPB:\
  182. \ Decode Packet', # will show up in GRC\n in_sig=None,\n \
  183. \ out_sig=None)\n self.message_port_register_in(pmt.intern('msg_in'))\n\
  184. \ self.message_port_register_out(pmt.intern('msg_out'))\n self.set_msg_handler(pmt.intern('msg_in'),\
  185. \ self.handle_msg)\n\n def handle_msg(self, msg):\n _debug = 1 \
  186. \ # set to zero to turn off diagnostics\n try:\n buff\
  187. \ = pmt.to_python(pmt.cdr(msg))\n except Exception as e:\n \
  188. \ gr.log.error(\"Error with message conversion: %s\" % str(e))\n \
  189. \ return\n\n b_len = len (buff)\n\n if (b_len != 52):\n \
  190. \ tmp_char_list = np.array([],dtype=int)\n tmp_char_list =\
  191. \ np.append(tmp_char_list, buff)\n tmp_char_list_len = len(tmp_char_list)\n\
  192. \ byte_array = array.array('B',tmp_char_list)\n\n # decode\
  193. \ Base64\n data = base64.b64decode(byte_array)\n d_len\
  194. \ = len (data)\n if (_debug):\n print (\"data =\"\
  195. , data, d_len)\n\n # create PMT u8vector using byte array\n \
  196. \ new_pmt = pmt.cons (pmt.PMT_NIL, pmt.init_u8vector(d_len,bytearray(data,'UTF-8')))\n\
  197. \n self.message_port_pub(pmt.intern('msg_out'), new_pmt)\n\n \
  198. \ elif ((buff[0] != 37) and (buff[51] != 93)):\n tmp_char_list\
  199. \ = np.array([],dtype=int)\n tmp_char_list = np.append(tmp_char_list,\
  200. \ buff)\n tmp_char_list_len = len(tmp_char_list)\n byte_array\
  201. \ = array.array('B',tmp_char_list)\n\n # decode Base64\n \
  202. \ data = base64.b64decode(byte_array)\n d_len = len (data)\n \
  203. \ if (_debug):\n print (\"data =\", data, d_len)\n\n\
  204. \ # create PMT u8vector using byte array\n new_pmt = pmt.cons\
  205. \ (pmt.PMT_NIL, pmt.init_u8vector(d_len,bytearray(data,'UTF-8')))\n\n \
  206. \ self.message_port_pub(pmt.intern('msg_out'), new_pmt)\n\n"
  207. affinity: ''
  208. alias: ''
  209. comment: ''
  210. maxoutbuf: '0'
  211. minoutbuf: '0'
  212. states:
  213. _io_cache: '(''EPB: Decode Packet'', ''blk'', [], [(''msg_in'', ''message'', 1)],
  214. [(''msg_out'', ''message'', 1)], '''', [])'
  215. bus_sink: false
  216. bus_source: false
  217. bus_structure: null
  218. coordinate: [584, 200.0]
  219. rotation: 0
  220. state: true
  221. - name: pdu_pdu_to_tagged_stream_0
  222. id: pdu_pdu_to_tagged_stream
  223. parameters:
  224. affinity: ''
  225. alias: ''
  226. comment: ''
  227. maxoutbuf: '0'
  228. minoutbuf: '0'
  229. tag: packet_len
  230. type: byte
  231. states:
  232. bus_sink: false
  233. bus_source: false
  234. bus_structure: null
  235. coordinate: [840, 196.0]
  236. rotation: 0
  237. state: true
  238. - name: pdu_tagged_stream_to_pdu_0
  239. id: pdu_tagged_stream_to_pdu
  240. parameters:
  241. affinity: ''
  242. alias: ''
  243. comment: ''
  244. maxoutbuf: '0'
  245. minoutbuf: '0'
  246. tag: packet_len
  247. type: byte
  248. states:
  249. bus_sink: false
  250. bus_source: false
  251. bus_structure: null
  252. coordinate: [304, 196.0]
  253. rotation: 0
  254. state: true
  255.  
  256. connections:
  257. - [blocks_throttle2_0, '0', blocks_file_sink_0, '0']
  258. - [epy_block_0, '0', pdu_tagged_stream_to_pdu_0, '0']
  259. - [epy_block_0_0, msg_out, pdu_pdu_to_tagged_stream_0, pdus]
  260. - [pdu_pdu_to_tagged_stream_0, '0', blocks_throttle2_0, '0']
  261. - [pdu_tagged_stream_to_pdu_0, pdus, epy_block_0_0, msg_in]
  262.  
  263. metadata:
  264. file_format: 1
  265. grc_version: 3.10.6.0
Add Comment
Please, Sign In to add comment