GNU Radio 3.7.1 C++ API
|
00001 /* -*- c++ -*- */ 00002 /* 00003 * Copyright 2012 Free Software Foundation, Inc. 00004 * 00005 * This file is part of GNU Radio 00006 * 00007 * GNU Radio is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 3, or (at your option) 00010 * any later version. 00011 * 00012 * GNU Radio is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with GNU Radio; see the file COPYING. If not, write to 00019 * the Free Software Foundation, Inc., 51 Franklin Street, 00020 * Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #ifndef INCLUDED_BLOCKS_FILE_META_SINK_H 00024 #define INCLUDED_BLOCKS_FILE_META_SINK_H 00025 00026 #include <gnuradio/blocks/api.h> 00027 #include <gnuradio/sync_block.h> 00028 00029 namespace gr { 00030 namespace blocks { 00031 00032 const char METADATA_VERSION = 0; 00033 const size_t METADATA_HEADER_SIZE = 149; 00034 00035 enum gr_file_types { 00036 GR_FILE_BYTE=0, 00037 GR_FILE_CHAR=0, 00038 GR_FILE_SHORT=1, 00039 GR_FILE_INT, 00040 GR_FILE_LONG, 00041 GR_FILE_LONG_LONG, 00042 GR_FILE_FLOAT, 00043 GR_FILE_DOUBLE, 00044 }; 00045 00046 /*! 00047 * \brief Write stream to file with meta-data headers. 00048 * \ingroup file_operators_blk 00049 * 00050 * \details 00051 * These files represent data as binary information in between 00052 * meta-data headers. The headers contain information about the 00053 * type of data and properties of the data in the next segment of 00054 * samples. The information includes: 00055 * 00056 * rx_rate (double): sample rate of data. 00057 * rx_time (uint64_t, double): time stamp of first sample in segment. 00058 * size (uint32_t): item size in bytes. 00059 * type (gr_file_types as int32_t): data type. 00060 * cplx (bool): Is data complex? 00061 * strt (uint64_t): Starting byte of data in this segment. 00062 * bytes (uint64_t): Size in bytes of data in this segment. 00063 * 00064 * Tags can be sent to the file to update the information, which 00065 * will create a new header. Headers are found by searching from 00066 * the first header (at position 0 in the file) and reading where 00067 * the data segment starts plus the data segment size. Following 00068 * will either be a new header or EOF. 00069 */ 00070 class BLOCKS_API file_meta_sink : virtual public sync_block 00071 { 00072 public: 00073 // gr::blocks::file_meta_sink::sptr 00074 typedef boost::shared_ptr<file_meta_sink> sptr; 00075 00076 /*! 00077 * \brief Create a meta-data file sink. 00078 * 00079 * \param itemsize (size_t): Size of data type. 00080 * \param filename (string): Name of file to write data to. 00081 * \param samp_rate (double): Sample rate of data. If sample rate will be 00082 * set by a tag, such as rx_tag from a UHD source, this is 00083 * basically ignored. 00084 * \param relative_rate (double): Rate chance from source of sample 00085 * rate tag to sink. 00086 * \param type (gr_file_types): Data type (int, float, etc.) 00087 * \param complex (bool): If data stream is complex 00088 * \param max_segment_size (size_t): Length of a single segment 00089 * before the header is repeated (in items). 00090 * \param extra_dict (string): a serialized PMT dictionary of extra 00091 * information. Currently not supported. 00092 * \param detached_header (bool): Set to true to store the header 00093 * info in a separate file (named filename.hdr) 00094 */ 00095 static sptr make(size_t itemsize, const std::string &filename, 00096 double samp_rate=1, double relative_rate=1, 00097 gr_file_types type=GR_FILE_FLOAT, bool complex=true, 00098 size_t max_segment_size=1000000, 00099 const std::string &extra_dict="", 00100 bool detached_header=false); 00101 00102 virtual bool open(const std::string &filename) = 0; 00103 virtual void close() = 0; 00104 virtual void do_update() = 0; 00105 00106 virtual void set_unbuffered(bool unbuffered) = 0; 00107 }; 00108 00109 } /* namespace blocks */ 00110 } /* namespace gr */ 00111 00112 #endif /* INCLUDED_BLOCKS_FILE_META_SINK_H */