Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Embedded Python Block: File Source to Tagged Stream
- """
- import numpy as np
- from gnuradio import gr
- import pmt
- import os.path
- import sys
- class blk(gr.sync_block):
- def __init__(self):
- gr.sync_block.__init__(
- self,
- name='EPB: File Source to Tagged Stream',
- in_sig=None,
- out_sig=[np.uint8])
- global _eof
- global indx
- _eof = False
- indx = 0
- fn = "/home/barry/Documents/Gettysburg.txt"
- if (os.path.exists(fn)):
- # open input file
- global f_in
- f_in = open (fn, 'rb')
- else:
- print('The input file does not exist')
- _eof = True
- def work(self, input_items, output_items):
- global _eof
- global indx
- global f_in
- Pkt_len = 252
- # print(type(output_items[0][0]))
- while (not (_eof)):
- buff = f_in.read (Pkt_len)
- b_len = len(buff)
- if b_len == 0:
- print ('End of file')
- _eof = 1
- f_in.close()
- break
- key0 = pmt.intern("packet_len")
- val0 = pmt.from_long(b_len)
- self.add_item_tag(0, # Write to output port 0
- indx, # Index of the tag
- key0, # Key of the tag
- val0 # Value of the tag
- )
- # print (indx, b_len)
- indx += b_len
- i = 0
- while (i < b_len):
- output_items[0][i] = buff[i]
- i += 1
- return (b_len)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement