nt: add TimeStamp and Alarm

Add helpers for common time and alarm sub-structures
This commit is contained in:
Michael Davidsaver
2021-04-15 07:36:28 -07:00
parent 47a563cac2
commit 3a55005609
4 changed files with 65 additions and 16 deletions
+6
View File
@@ -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.
+29 -13
View File
@@ -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"),
}),
+27
View File
@@ -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
+3 -3
View File
@@ -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"<<top;
testEq(top["value"].type(), TypeCode::Int32);
testEq(top["display.limitLow"].type(), TypeCode::Null);
@@ -52,7 +52,7 @@ void testNTNDArray()
auto top = nt::NTNDArray{}.create();
testTrue(top.idStartsWith("epics:nt/NTNDArray:"));
testTrue(top.idStartsWith("epics:nt/NTNDArray:"))<<"\n"<<top;
}
void testNTURI()
@@ -68,7 +68,7 @@ void testNTURI()
auto top = def.call(42, "hello");
testTrue(top.idStartsWith("epics:nt/NTURI:"));
testTrue(top.idStartsWith("epics:nt/NTURI:"))<<"\n"<<top;
testEq(top["query.arg1"].as<uint32_t>(), 42u);
testEq(top["query.arg2"].as<std::string>(), "hello");
}