From a207a54ec1e80f647fd1156047204b2c2eab09ab Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Wed, 11 Dec 2019 11:18:48 -0800 Subject: [PATCH] start NT --- src/Makefile | 2 ++ src/nt.cpp | 77 ++++++++++++++++++++++++++++++++++++++++++++++ src/pvxs/nt.h | 27 ++++++++++++++++ test/dummyserv.cpp | 6 ++-- 4 files changed, 108 insertions(+), 4 deletions(-) create mode 100644 src/nt.cpp create mode 100644 src/pvxs/nt.h diff --git a/src/Makefile b/src/Makefile index 796567c..ba5523b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -41,6 +41,7 @@ INC += pvxs/util.h INC += pvxs/bitmask.h INC += pvxs/sharedArray.h INC += pvxs/data.h +INC += pvxs/nt.h INC += pvxs/server.h LIBRARY = pvxs @@ -52,6 +53,7 @@ LIB_SRCS += bitmask.cpp LIB_SRCS += type.cpp LIB_SRCS += data.cpp LIB_SRCS += dataencode.cpp +LIB_SRCS += nt.cpp LIB_SRCS += evhelper.cpp LIB_SRCS += udp_collector.cpp LIB_SRCS += server.cpp diff --git a/src/nt.cpp b/src/nt.cpp new file mode 100644 index 0000000..b5adc68 --- /dev/null +++ b/src/nt.cpp @@ -0,0 +1,77 @@ +/** + * Copyright - See the COPYRIGHT that is included with this distribution. + * pvxs is distributed subject to a Software License Agreement found + * in file LICENSE that is included with this distribution. + */ + +#include + +namespace pvxs { +namespace nt { + + +TypeDef NTScalar::build() +{ + TypeDef def(TypeCode::Struct, + value.isarray() ? "epics:nt/NTScalarArray:1.0" : "epics:nt/NTScalar:1.0"); + + const bool isnumeric = value.kind()==Kind::Integer || value.kind()==Kind::Real; + const auto scalar = value.scalarOf(); + + def.begin() + .insert("value", value) + .insert("alarm", "alarm_t", TypeCode::Struct).seek("alarm") + .insert("severity", TypeCode::Int32) + .insert("status", TypeCode::Int32) + .insert("message", TypeCode::String) + .up() + .insert("timeStamp", "time_t", TypeCode::Struct).seek("timeStamp") + .insert("secondsPastEpoch", TypeCode::Int64) + .insert("nanoseconds", TypeCode::Int32) + .insert("userTag", TypeCode::Int32) + .up() + ; + + if(display && isnumeric) { + def.begin() + .insert("display", TypeCode::Struct).seek("display") + .insert("limitLow", scalar) + .insert("limitHigh", scalar) + .insert("description", TypeCode::String) + //.insert("format", TypeCode::String) + .insert("units", TypeCode::String) + .up() + ; + } + + if(control && isnumeric) { + def.begin() + .insert("control", TypeCode::Struct).seek("control") + .insert("limitLow", scalar) + .insert("limitHigh", scalar) + .insert("minStep", scalar) + .up() + ; + } + + if(valueAlarm && isnumeric) { + def.begin() + .insert("valueAlarm", TypeCode::Struct).seek("valueAlarm") + .insert("active", TypeCode::Bool) // useless? + .insert("lowAlarmLimit", scalar) + .insert("lowWarningLimit", scalar) + .insert("highWarningLimit", scalar) + .insert("highAlarmLimit", scalar) + .insert("lowAlarmSeverity", TypeCode::Int32) + .insert("lowWarningSeverity", TypeCode::Int32) + .insert("highWarningSeverity", TypeCode::Int32) + .insert("highAlarmSeverity", TypeCode::Int32) + .insert("hysteresis", TypeCode::Float64) + .up() + ; + } + + return def; +} + +}} // namespace pvxs::nt diff --git a/src/pvxs/nt.h b/src/pvxs/nt.h new file mode 100644 index 0000000..6e9d07d --- /dev/null +++ b/src/pvxs/nt.h @@ -0,0 +1,27 @@ +/** + * Copyright - See the COPYRIGHT that is included with this distribution. + * pvxs is distributed subject to a Software License Agreement found + * in file LICENSE that is included with this distribution. + */ +#ifndef PVXS_NT_H +#define PVXS_NT_H + +#include +#include + +namespace pvxs { +namespace nt { + +struct NTScalar { + TypeCode value; + bool display; + bool control; + bool valueAlarm; + + PVXS_API + TypeDef build(); +}; + +}} // namespace pvxs::nt + +#endif // PVXS_NT_H diff --git a/test/dummyserv.cpp b/test/dummyserv.cpp index ef5ecba..9e8bfb0 100644 --- a/test/dummyserv.cpp +++ b/test/dummyserv.cpp @@ -13,6 +13,7 @@ #include #include +#include #include @@ -22,10 +23,7 @@ using namespace pvxs::server; DEFINE_LOGGER(dummy,"dummyserv"); -const Value mytype = TypeDef(TypeCode::Struct) - .begin() - .insert("value", TypeCode::Float64) - .create(); +const Value mytype = nt::NTScalar{TypeCode::Int32}.build().create(); struct DummyHandler : public Handler {