diff --git a/include/villas/format.hpp b/include/villas/format.hpp index 4f670ce3a..76ba1571f 100644 --- a/include/villas/format.hpp +++ b/include/villas/format.hpp @@ -50,8 +50,8 @@ public: int getFlags() const { return flags; } - void start(const SignalList::Ptr sigs, int fl = (int)SampleFlags::HAS_ALL); - void start(const std::string &dtypes, int fl = (int)SampleFlags::HAS_ALL); + void start(const SignalList::Ptr sigs, int fl = (int)SampleFlags::ALL); + void start(const std::string &dtypes, int fl = (int)SampleFlags::ALL); virtual void start() {} diff --git a/include/villas/sample.hpp b/include/villas/sample.hpp index 8de132db0..4c4059170 100644 --- a/include/villas/sample.hpp +++ b/include/villas/sample.hpp @@ -47,11 +47,12 @@ enum class SampleFlags { HAS_TS = HAS_TS_ORIGIN | HAS_TS_RECEIVED, // Include origin timestamp in output. - HAS_ALL = (1 << 5) - 1, // Enable all output options. NEW_FRAME = (1 << 16), // This sample is the last of a running simulation case NEW_SIMULATION = - (1 << 17) | NEW_FRAME // This sample is the first of a new simulation case + (1 << 17), // This sample is the first of a new simulation case + + ALL = -1 }; struct Sample { diff --git a/lib/hooks/frame.cpp b/lib/hooks/frame.cpp index f13b05bbf..02faed7a9 100644 --- a/lib/hooks/frame.cpp +++ b/lib/hooks/frame.cpp @@ -64,14 +64,19 @@ private: bool changed = false; if (!last_smp.get() || - (next_smp->flags & (int)SampleFlags::NEW_SIMULATION) == - (int)SampleFlags::NEW_SIMULATION) { + (next_smp->flags & (int)SampleFlags::NEW_SIMULATION)) { changed = true; } else if (trigger == Trigger::SEQUENCE) { + if (!(next_smp->flags & (int)SampleFlags::HAS_SEQUENCE)) + throw RuntimeError{"Missing sequence number."}; + auto last_interval = (last_smp->sequence + interval - offset) / interval; auto next_interval = (next_smp->sequence + interval - offset) / interval; changed = last_interval != next_interval; - } else + } else { + if (!(next_smp->flags & (int)SampleFlags::HAS_TS_ORIGIN)) + throw RuntimeError{"Missing origin timestamp."}; + switch (unit.value()) { case Unit::HOURS: { auto last_hour = last_smp->ts.origin.tv_sec / 3'600; @@ -156,6 +161,7 @@ private: break; } } + } if (changed) logger->debug("new frame"); diff --git a/src/villas-hook.cpp b/src/villas-hook.cpp index 97b41782e..0a3985b91 100644 --- a/src/villas-hook.cpp +++ b/src/villas-hook.cpp @@ -218,7 +218,7 @@ protected: if (!(*d.formatter)) throw RuntimeError("Failed to initialize {} IO", d.dir); - (*d.formatter)->start(dtypes, (int)SampleFlags::HAS_ALL); + (*d.formatter)->start(dtypes, (int)SampleFlags::ALL); } // Initialize hook diff --git a/tests/unit/format.cpp b/tests/unit/format.cpp index 54abc41bb..c97120e4e 100644 --- a/tests/unit/format.cpp +++ b/tests/unit/format.cpp @@ -269,7 +269,7 @@ ParameterizedTest(Param *p, format, lowlevel, .init = init_memory) { cr_assert_not_null(fmt, "Failed to create formatter of type '%s'", p->fmt.c_str()); - fmt->start(signals, (int)SampleFlags::HAS_ALL); + fmt->start(signals, (int)SampleFlags::ALL); cnt = fmt->sprint(buf, sizeof(buf), &wbytes, smps, p->cnt); cr_assert_eq(cnt, p->cnt, "Written only %d of %d samples", cnt, p->cnt); @@ -370,7 +370,7 @@ ParameterizedTest(Param *p, format, highlevel, .init = init_memory) { cr_assert_not_null(fmt, "Failed to create formatter of type '%s'", p->fmt.c_str()); - fmt->start(signals, (int)SampleFlags::HAS_ALL); + fmt->start(signals, (int)SampleFlags::ALL); auto *stream = fopen(fn, "w+"); cr_assert_not_null(stream);