GNU Radio 3.6.3 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 <blocks/api.h> 00027 #include <gr_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 sink_blk 00049 * 00050 * These files represent data as binary information in between 00051 * meta-data headers. The headers contain information about the 00052 * type of data and properties of the data in the next segment of 00053 * samples. The information includes: 00054 * 00055 * rx_rate (double): sample rate of data. 00056 * rx_time (uint64_t, double): time stamp of first sample in segment. 00057 * size (uint32_t): item size in bytes. 00058 * type (gr_file_types as int32_t): data type. 00059 * cplx (bool): Is data complex? 00060 * strt (uint64_t): Starting byte of data in this segment. 00061 * bytes (uint64_t): Size in bytes of data in this segment. 00062 * 00063 * Tags can be sent to the file to update the information, which 00064 * will create a new header. Headers are found by searching from 00065 * the first header (at position 0 in the file) and reading where 00066 * the data segment starts plus the data segment size. Following 00067 * will either be a new header or EOF. 00068 */ 00069 class BLOCKS_API file_meta_sink : virtual public gr_sync_block 00070 { 00071 public: 00072 // gr::blocks::file_meta_sink::sptr 00073 typedef boost::shared_ptr<file_meta_sink> sptr; 00074 00075 /*! 00076 * \brief Create a meta-data file sink. 00077 * 00078 * \param itemsize (size_t): Size of data type. 00079 * \param filename (string): Name of file to write data to. 00080 * \param samp_rate (double): Sample rate of data. If sample rate will be 00081 * set by a tag, such as rx_tag from a UHD source, this is 00082 * basically ignored. 00083 * \param relative_rate (double): Rate chance from source of sample 00084 * rate tag to sink. 00085 * \param type (gr_file_types): Data type (int, float, etc.) 00086 * \param complex (bool): If data stream is complex 00087 * \param max_segment_size (size_t): Length of a single segment 00088 * before the header is repeated (in items). 00089 * \param extra_dict (string): a serialized PMT dictionary of extra 00090 * information. Currently not supported. 00091 * \param detached_header (bool): Set to true to store the header 00092 * info in a separate file (named filename.hdr) 00093 */ 00094 static sptr make(size_t itemsize, const std::string &filename, 00095 double samp_rate=1, double relative_rate=1, 00096 gr_file_types type=GR_FILE_FLOAT, bool complex=true, 00097 size_t max_segment_size=1000000, 00098 const std::string &extra_dict="", 00099 bool detached_header=false); 00100 00101 virtual bool open(const std::string &filename) = 0; 00102 virtual void close() = 0; 00103 virtual void do_update() = 0; 00104 00105 virtual void set_unbuffered(bool unbuffered) = 0; 00106 }; 00107 00108 } /* namespace blocks */ 00109 } /* namespace gr */ 00110 00111 #endif /* INCLUDED_BLOCKS_FILE_META_SINK_H */