GNU Radio 3.6.3 C++ API
file_meta_sink.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2012 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef INCLUDED_BLOCKS_FILE_META_SINK_H
24 #define INCLUDED_BLOCKS_FILE_META_SINK_H
25 
26 #include <blocks/api.h>
27 #include <gr_sync_block.h>
28 
29 namespace gr {
30  namespace blocks {
31 
32  const char METADATA_VERSION = 0;
33  const size_t METADATA_HEADER_SIZE = 149;
34 
44  };
45 
46  /*!
47  * \brief Write stream to file with meta-data headers.
48  * \ingroup sink_blk
49  *
50  * These files represent data as binary information in between
51  * meta-data headers. The headers contain information about the
52  * type of data and properties of the data in the next segment of
53  * samples. The information includes:
54  *
55  * rx_rate (double): sample rate of data.
56  * rx_time (uint64_t, double): time stamp of first sample in segment.
57  * size (uint32_t): item size in bytes.
58  * type (gr_file_types as int32_t): data type.
59  * cplx (bool): Is data complex?
60  * strt (uint64_t): Starting byte of data in this segment.
61  * bytes (uint64_t): Size in bytes of data in this segment.
62  *
63  * Tags can be sent to the file to update the information, which
64  * will create a new header. Headers are found by searching from
65  * the first header (at position 0 in the file) and reading where
66  * the data segment starts plus the data segment size. Following
67  * will either be a new header or EOF.
68  */
69  class BLOCKS_API file_meta_sink : virtual public gr_sync_block
70  {
71  public:
72  // gr::blocks::file_meta_sink::sptr
74 
75  /*!
76  * \brief Create a meta-data file sink.
77  *
78  * \param itemsize (size_t): Size of data type.
79  * \param filename (string): Name of file to write data to.
80  * \param samp_rate (double): Sample rate of data. If sample rate will be
81  * set by a tag, such as rx_tag from a UHD source, this is
82  * basically ignored.
83  * \param relative_rate (double): Rate chance from source of sample
84  * rate tag to sink.
85  * \param type (gr_file_types): Data type (int, float, etc.)
86  * \param complex (bool): If data stream is complex
87  * \param max_segment_size (size_t): Length of a single segment
88  * before the header is repeated (in items).
89  * \param extra_dict (string): a serialized PMT dictionary of extra
90  * information. Currently not supported.
91  * \param detached_header (bool): Set to true to store the header
92  * info in a separate file (named filename.hdr)
93  */
94  static sptr make(size_t itemsize, const std::string &filename,
95  double samp_rate=1, double relative_rate=1,
96  gr_file_types type=GR_FILE_FLOAT, bool complex=true,
97  size_t max_segment_size=1000000,
98  const std::string &extra_dict="",
99  bool detached_header=false);
100 
101  virtual bool open(const std::string &filename) = 0;
102  virtual void close() = 0;
103  virtual void do_update() = 0;
104 
105  virtual void set_unbuffered(bool unbuffered) = 0;
106  };
107 
108  } /* namespace blocks */
109 } /* namespace gr */
110 
111 #endif /* INCLUDED_BLOCKS_FILE_META_SINK_H */