diff --git a/ioc/pvalink_lset.cpp b/ioc/pvalink_lset.cpp index ccbe72f..e92f795 100644 --- a/ioc/pvalink_lset.cpp +++ b/ioc/pvalink_lset.cpp @@ -4,6 +4,7 @@ * in file LICENSE that is included with this distribution. */ +#include #include #include #include @@ -267,6 +268,9 @@ long pvaGetValue(DBLINK *plink, short dbrType, void *pbuffer, long *pnRequest) n self->pfieldname); if(self->time) { plink->precord->time = self->snap_time; +#if DBR_UTAG + plink->precord->utag = self->snap_tag; +#endif } log_debug_printf(_logger, "%s: %s not valid\n", __func__, self->channelName.c_str()); return -1; @@ -404,7 +408,8 @@ long pvaGetValue(DBLINK *plink, short dbrType, void *pbuffer, long *pnRequest) n } if(self->fld_usertag) { - self->snap_tag = self->fld_usertag.as(); + // convert to uint32_t to avoid sign extension (Normative Types defines userTag as 32 bits) + self->snap_tag = self->fld_usertag.as(); } else { self->snap_tag = 0; } @@ -432,6 +437,9 @@ long pvaGetValue(DBLINK *plink, short dbrType, void *pbuffer, long *pnRequest) n if(self->time) { plink->precord->time = self->snap_time; +#if DBR_UTAG + plink->precord->utag = self->snap_tag; +#endif } log_debug_printf(_logger, "%s: %s %s snapalrm=%d,\"%s\" OK\n", __func__, plink->precord->name, diff --git a/test/testpvalink.cpp b/test/testpvalink.cpp index efa7831..566e5df 100644 --- a/test/testpvalink.cpp +++ b/test/testpvalink.cpp @@ -4,6 +4,7 @@ * in file LICENSE that is included with this distribution. */ +#include "epicsTime.h" #include #include #include @@ -36,6 +37,7 @@ #include "qsrvpvt.h" #include "pvalink.h" #include "capturestd.h" +#include "testioc.h" using namespace pvxs::ioc; using namespace pvxs; @@ -647,6 +649,62 @@ namespace { } } + void testUserTag() + { + testDiag("==== %s ====", __func__); + auto serv(ioc::server()); + TestClient ctxt; + + // create SharedPV to manipulate userTag + auto srcutag_shpv(server::SharedPV::buildReadonly()); + auto top = nt::NTScalar{TypeCode::Int32}.create(); + top["value"] = 0; + top["timeStamp.secondsPastEpoch"] = 0; + top["timeStamp.nanoseconds"] = 0; + top["timeStamp.userTag"] = 0; + srcutag_shpv.open(top); + serv.addPV("source:utag", srcutag_shpv); + + // routine check if link is connected + testqsrvWaitForLinkConnected("target:utag.INP"); + + // publish update to be reflected in target:utag + { + auto update = top.cloneEmpty(); + update["value"] = 42; + update["timeStamp.secondsPastEpoch"] = 0x12345678; + update["timeStamp.nanoseconds"] = 0x10203040; + update["timeStamp.userTag"] = 0x90010002; + QSrvWaitForLinkUpdate A("target:utag.INP"); + srcutag_shpv.post(update); + } + + // Check if record was updated with timeStamp + userTag from link + auto prec(testdbRecordPtr("target:utag")); + { + ioc::DBLocker L(prec); + testEq(prec->time.secPastEpoch, (0x12345678u-POSIX_TIME_AT_EPICS_EPOCH)); + testEq(prec->time.nsec, 0x10203040u); +#if DBR_UTAG + testEq(prec->utag, 0x90010002u); +#else + testSkip(1, "No UTAG"); +#endif + } + + // get PV from target:utag and verify if timeStamp is the same from source:utag + auto val(ctxt.get("target:utag").exec()->wait(5.0)); + testEq(val["value"].as(), 42); + testEq(val["timeStamp.secondsPastEpoch"].as(), 0x12345678); + testEq(val["timeStamp.nanoseconds"].as(), 0x10203040); +#if DBR_UTAG + testEq(val["timeStamp.userTag"].as(), (int32_t)0x90010002); +#else + testSkip(1, "No UTAG"); +#endif + ctxt.close(); + } + } // namespace @@ -654,7 +712,7 @@ extern "C" void testioc_registerRecordDeviceDriver(struct dbBase *); MAIN(testpvalink) { - testPlan(106); + testPlan(113); testSetup(); pvxs::logger_config_env(); @@ -687,6 +745,7 @@ MAIN(testpvalink) testEnum(); testNTNDArray(); testiocsh(); + testUserTag(); } catch (std::exception &e) { diff --git a/test/testpvalink.db b/test/testpvalink.db index 3204280..d76e5f0 100644 --- a/test/testpvalink.db +++ b/test/testpvalink.db @@ -224,3 +224,8 @@ record(aai, "target:ntndarray_inp") { field(NELM, "5") field(FTVL, "FLOAT") } + +record(longin, "target:utag") { + field(INP, {pva:{pv:"source:utag", time:true, proc:"CP"}}) + field(TSE, "-2") +} diff --git a/test/testqgroup.cpp b/test/testqgroup.cpp index 9a6916b..0fcaae4 100644 --- a/test/testqgroup.cpp +++ b/test/testqgroup.cpp @@ -40,7 +40,7 @@ int testTimeCurrent(epicsTimeStamp *pDest) void checkUTAG(Value& v, int32_t expect, const char *fld="timeStamp.userTag") { -#ifdef DBR_UTAG +#if DBR_UTAG auto utag = v[fld]; int32_t tag = -1; if(!utag.isMarked() || (tag = utag.as())!=expect) diff --git a/test/testqsingle.cpp b/test/testqsingle.cpp index 7b66e89..d91fd38 100644 --- a/test/testqsingle.cpp +++ b/test/testqsingle.cpp @@ -56,7 +56,7 @@ void forceUTAG(const char *rec) { dbCommon *prec = testdbRecordPtr(rec); dbScanLock(prec); -#ifdef DBR_UTAG +#if DBR_UTAG prec->utag = 42; #endif dbScanUnlock(prec); @@ -64,7 +64,7 @@ void forceUTAG(const char *rec) void checkUTAG(Value& v, int32_t expect=42) { -#ifdef DBR_UTAG +#if DBR_UTAG auto utag = v["timeStamp.userTag"]; if(!utag.isMarked() || utag.as()!=expect) testFail("userTag not set"); @@ -278,7 +278,7 @@ void testGetScalar() forceUTAG("test:nsec"); // forced value should be ignored val = ctxt.get("test:nsec").exec()->wait(5.0); -#ifdef DBR_UTAG +#if DBR_UTAG testFldEq(val, "timeStamp.userTag", 142); val["timeStamp.userTag"].unmark(); #else