mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
Fix SampleFlags HAS_ALL and NEW_FRAME
SampleFlags::HAS_ALL was not including the NEW_* style flags. The NEW_SIMULATION flag is now independent from the NEW_FRAME flag, since the dependency made checking that flag unnecessarily difficult. Checking a composite flag like this if ((smp->flags & SampleFlags::NEW_SIMULATION) == SampleFlags::NEW_SIMULATION); is more verbose than checking a simple flag like if (smp->flags & SampleFlags::NEW_SIMULATION); Signed-off-by: Philipp Jungkamp <Philipp.Jungkamp@opal-rt.com>
This commit is contained in:
parent
065de3ab6d
commit
043ff81eb5
5 changed files with 17 additions and 10 deletions
|
@ -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() {}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue