diff --git a/documentation/nt.rst b/documentation/nt.rst index ced5075..129e816 100644 --- a/documentation/nt.rst +++ b/documentation/nt.rst @@ -24,6 +24,9 @@ time_t Commonly used sub-structure to represent a time +.. doxygenstruct:: pvxs::nt::TimeStamp + :members: + **"secondsPastEpoch"** Seconds since POSIX epoch of 1 Jan 1970 UTC. Note that the EPICS epoch is 631152000 seconds after the POSIX epoch. @@ -37,6 +40,9 @@ Commonly used sub-structure to represent a time alarm_t ------- +.. doxygenstruct:: pvxs::nt::Alarm + :members: + **"severity"** Enumeration of 0 - No Alarm, 1 - Minor, 2 - Major, 3 - Invalid. diff --git a/src/nt.cpp b/src/nt.cpp index 6f3c955..5f65b21 100644 --- a/src/nt.cpp +++ b/src/nt.cpp @@ -9,6 +9,30 @@ namespace pvxs { namespace nt { +TypeDef TimeStamp::build() +{ + using namespace pvxs::members; + + TypeDef def(TypeCode::Struct, "time_t", { + Int64("secondsPastEpoch"), + Int32("nanoseconds"), + Int32("userTag"), + }); + return def; +} + +TypeDef Alarm::build() +{ + using namespace pvxs::members; + + TypeDef def(TypeCode::Struct, "alarm_t", { + Int32("severity"), + Int32("status"), + String("message"), + }); + return def; +} + TypeDef NTScalar::build() const { using namespace pvxs::members; @@ -24,11 +48,7 @@ TypeDef NTScalar::build() const Int32("status"), String("message"), }), - Struct("timeStamp", "time_t", { - Int64("secondsPastEpoch"), - Int32("nanoseconds"), - Int32("userTag"), - }), + TimeStamp{}.build().as("timeStamp"), }); const bool isnumeric = value.kind()==Kind::Integer || value.kind()==Kind::Real; @@ -88,11 +108,7 @@ TypeDef NTNDArray::build() const { using namespace pvxs::members; - auto time_t = { - Int64("secondsPastEpoch"), - Int32("nanoseconds"), - Int32("userTag"), - }; + auto time_t(TimeStamp{}.build()); auto alarm_t = { Int32("severity"), Int32("status"), @@ -120,9 +136,9 @@ TypeDef NTNDArray::build() const Int64("compressedSize"), Int64("uncompressedSize"), Int32("uniqueId"), - Struct("dataTimeStamp", "time_t", time_t), + time_t.as("dataTimeStamp"), Struct("alarm", "alarm_t", alarm_t), - Struct("timeStamp", "time_t", time_t), + time_t.as("timeStamp"), StructA("dimension", "dimension_t", { Int32("size"), Int32("offset"), @@ -136,7 +152,7 @@ TypeDef NTNDArray::build() const StringA("tags"), String("descriptor"), Struct("alarm", "alarm_t", alarm_t), - Struct("timeStamp", "time_t", time_t), + time_t.as("timeStamp"), Int32("sourceType"), String("source"), }), diff --git a/src/pvxs/nt.h b/src/pvxs/nt.h index ebe82e0..9acc74b 100644 --- a/src/pvxs/nt.h +++ b/src/pvxs/nt.h @@ -14,11 +14,38 @@ struct epicsTimeStamp; // epicsTime.h namespace pvxs { namespace nt { +/** The time_t struct + * + * @code + * // equivalent + * struct time_t { + * int64_t secondsPastEpoch; + * int32_t nanoseconds; + * int32_t userTag; + * }; + * @endcode + */ struct TimeStamp { PVXS_API TypeDef build(); }; +/** The alarm_t struct + * + * @code + * // equivalent + * struct alarm_t { + * int32_t severity; + * int32_t status; + * string message; + * }; + * @endcode + */ +struct Alarm { + PVXS_API + TypeDef build(); +}; + /** A scalar, or array of scalars, and meta-data * * @code diff --git a/test/testnt.cpp b/test/testnt.cpp index 72420be..7393243 100644 --- a/test/testnt.cpp +++ b/test/testnt.cpp @@ -22,7 +22,7 @@ void testNTScalar() // plain, without display meta auto top = nt::NTScalar{TypeCode::Int32}.create(); - testTrue(top.idStartsWith("epics:nt/NTScalar:")); + testTrue(top.idStartsWith("epics:nt/NTScalar:"))<<"\n"<(), 42u); testEq(top["query.arg2"].as(), "hello"); }