Sunday, October 14, 2012

File Descriptors in GNU Radio


When a program opens a file, the operating system returns a corresponding file descriptor that the program refers to in order to process the file. A file descriptor is a low positive integer.

The first three file descriptors (0,1, and 2,) are associated with the standard input (stdin), the standard output (stdout), and the standard error (stderr), respectively.


Lets take following example in GNU Radio :

# open socket output :
         port=7001
         self.fd = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 


# socket() is also an operator which returns the file descriptor number

# fd will contain the value 1 as it is related to output at port 7001
# this value of fd is used as input argument to the gr_file_descriptor_source/sink
 
         self.fd.connect(('192.168.1.53',7001))  
         self.file = gr.file_descriptor_sink(gr.sizeof_gr_complex,self.fd.fileno() )
         self.connect(self.u,self.file


file descriptor can also be obtained in python by

seld.fid = open(....)

example :

self.file = open(filename,"w")  
self.save = gr.file_descriptor_sink(gr.sizeof_short,self.file.fileno()) 


To use a gr_file_descriptor, you need to open the file  yourself beforehand, the closing should thus happen in the same scope.

Reference : http://gnuradio.4.n7.nabble.com/Passing-file-descriptors-via-SWIG-tc26287.html#a26288

Here is the wikipedia link about file descriptors, here you can see the general operators which create a file descriptors as well the common operation which can be done on file descriptors

http://en.wikipedia.org/wiki/File_descriptor  


details of gr_file_descriptor are at :

http://gnuradio.org/doc/doxygen/classgr__file__descriptor__sink.html#details

http://gnuradio.org/doc/doxygen/gr__file__descriptor__source_8h.html


       




No comments:

Post a Comment