Advertisement
duggabe

str_pkt_3_epy_block_0.py

Mar 16th, 2023
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. """
  2. Embedded Python Block: File Source to Tagged Stream
  3. """
  4.  
  5. import numpy as np
  6. from gnuradio import gr
  7. import pmt
  8. import os.path
  9. import sys
  10.  
  11. class blk(gr.sync_block):
  12. def __init__(self):
  13. gr.sync_block.__init__(
  14. self,
  15. name='EPB: File Source to Tagged Stream',
  16. in_sig=None,
  17. out_sig=[np.uint8])
  18.  
  19. global _eof
  20. global indx
  21. _eof = False
  22. indx = 0
  23. fn = "/home/barry/Documents/Gettysburg.txt"
  24. if (os.path.exists(fn)):
  25. # open input file
  26. global f_in
  27. f_in = open (fn, 'rb')
  28. else:
  29. print('The input file does not exist')
  30. _eof = True
  31.  
  32. def work(self, input_items, output_items):
  33. global _eof
  34. global indx
  35. global f_in
  36. Pkt_len = 252
  37. # print(type(output_items[0][0]))
  38. while (not (_eof)):
  39. buff = f_in.read (Pkt_len)
  40. b_len = len(buff)
  41. if b_len == 0:
  42. print ('End of file')
  43. _eof = 1
  44. f_in.close()
  45. break
  46. key0 = pmt.intern("packet_len")
  47. val0 = pmt.from_long(b_len)
  48. self.add_item_tag(0, # Write to output port 0
  49. indx, # Index of the tag
  50. key0, # Key of the tag
  51. val0 # Value of the tag
  52. )
  53. # print (indx, b_len)
  54. indx += b_len
  55. i = 0
  56. while (i < b_len):
  57. output_items[0][i] = buff[i]
  58. i += 1
  59. return (b_len)
  60.  
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement