diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2015-03-28 21:52:46 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2015-03-28 21:52:46 +0100 |
commit | 8d9760f9bfc8be9b1abad9a8212b14ffd4552fd7 (patch) | |
tree | d38b8762e08ecb33a4a94ad89b0d058e54a542b8 /apps | |
parent | f110a0912efb7245d6d548aa8a5ac0c89bcd9dc0 (diff) | |
download | ble-toys-8d9760f9bfc8be9b1abad9a8212b14ffd4552fd7.tar.gz ble-toys-8d9760f9bfc8be9b1abad9a8212b14ffd4552fd7.tar.bz2 ble-toys-8d9760f9bfc8be9b1abad9a8212b14ffd4552fd7.tar.xz ble-toys-8d9760f9bfc8be9b1abad9a8212b14ffd4552fd7.zip |
o Adding timestamp by default when converting samples.
Diffstat (limited to 'apps')
-rw-r--r-- | apps/sample-convert.cpp | 21 | ||||
-rw-r--r-- | apps/sample-timestamp.cpp | 2 |
2 files changed, 15 insertions, 8 deletions
diff --git a/apps/sample-convert.cpp b/apps/sample-convert.cpp index c7173a1..1cedf42 100644 --- a/apps/sample-convert.cpp +++ b/apps/sample-convert.cpp @@ -18,6 +18,7 @@ namespace po = boost::program_options; class sample_convert : public app { string fields; string timestamp_field; + bool add_timestamp; public: void add_options(po::options_description_easy_init &options) override { @@ -28,7 +29,8 @@ public: ("output", po::value<string>(&output_file)->default_value("-")) ("output-format", po::value<sample_format_type>(&output_format)->default_value(sample_format_type::KEY_VALUE)) ("fields", po::value<string>(&fields)) - ("timestamp-field", po::value<string>(×tamp_field)); + ("add-timestamp", po::value<bool>(&add_timestamp)->default_value(true)) + ("timestamp-field", po::value<string>(×tamp_field)->default_value("timestamp")); } void add_extra_options(po::options_description &all_options) override { @@ -67,12 +69,10 @@ public: } } - std::vector<sample_output_stream_option *> options; + sample_output_stream_options options; trygvis::sensor::io::timestamp_field_option tf(timestamp_field); - if (!timestamp_field.empty()) { - options.push_back(&tf); - } + options.push_back(&tf); tokenizer<> tok(fields); output_fields_option fs; @@ -81,14 +81,21 @@ public: options.push_back(&fs); } - shared_ptr<SampleOutputStream> output = open_sample_output_stream(outputStream, dict, output_format, options); + unique_ptr<SampleOutputStream> o = open_sample_output_stream(outputStream, dict, output_format, options); + + if (add_timestamp) { + o = make_unique<AddTimestampSampleOutputStream>(move(o), dict, timestamp_field); + } + + shared_ptr<SampleOutputStream> output(move(o)); auto input = make_shared<KeyValueSampleStreamParser>(output, dict); char data[100]; while (!inputStream->eof()) { inputStream->get(data[0]); - input->process(boost::asio::buffer(data, 1)); + auto buf = boost::asio::buffer(data, 1); + input->process(buf); } return EXIT_SUCCESS; diff --git a/apps/sample-timestamp.cpp b/apps/sample-timestamp.cpp index 85431ae..cf0b7fe 100644 --- a/apps/sample-timestamp.cpp +++ b/apps/sample-timestamp.cpp @@ -178,7 +178,7 @@ public: return EXIT_FAILURE; } - vector<sample_output_stream_option*> options = {}; + sample_output_stream_options options; unique_ptr<SampleOutputStream> unique_output_stream = open_sample_output_stream(shared_ptr<ostream>(&cout, noop_deleter), dict, parser->type(), options); shared_ptr<SampleOutputStream> output_stream{std::move(unique_output_stream)}; shared_ptr<SampleOutputStream> p = make_shared<TimestampFixingSampleOutputStream>(output_stream, dict, timestamp_name, relative_name, relative_resolution, start_time); |