Skip to content

Commit

Permalink
ioc: pvalink add newer lset functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mdavidsaver committed Oct 11, 2023
1 parent 4a19ae0 commit 75df3a5
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 10 deletions.
17 changes: 13 additions & 4 deletions ioc/pvalink.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
#include "utilpvt.h"
#include "dbmanylocker.h"


#if EPICS_VERSION_INT<VERSION_INT(7,0,6,0)
typedef epicsUInt64 epicsUTag;
#endif

extern "C" {
extern int pvaLinkNWorkers;
}
Expand Down Expand Up @@ -215,19 +220,23 @@ struct pvaLink final : public pvaLinkConfig

// cached fields from channel op_mon
// updated in onTypeChange()
Value fld_value;
Value fld_severity,
Value fld_value,
fld_severity,
fld_message,
fld_seconds,
fld_nanoseconds;
Value fld_display,
fld_nanoseconds,
fld_usertag,
fld_display,
fld_control,
fld_valueAlarm;

// cached snapshot of alarm and timestamp
// captured in pvaGetValue().
// we choose not to ensure consistency with display/control meta-data
epicsTimeStamp snap_time = {};
epicsUTag snap_tag = 0;
short snap_severity = INVALID_ALARM;
std::string snap_message;

pvaLink();
virtual ~pvaLink();
Expand Down
2 changes: 2 additions & 0 deletions ioc/pvalink_link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ void pvaLink::onTypeChange()
fld_value = getSubField("value");
fld_seconds = getSubField("timeStamp.secondsPastEpoch");
fld_nanoseconds = getSubField("timeStamp.nanoseconds");
fld_usertag = getSubField("timeStamp.userTag");
fld_severity = getSubField("alarm.severity");
fld_message = getSubField("alarm.message");
fld_display = getSubField("display");
fld_control = getSubField("control");
fld_valueAlarm = getSubField("valueAlarm");
Expand Down
58 changes: 52 additions & 6 deletions ioc/pvalink_lset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ long pvaGetValue(DBLINK *plink, short dbrType, void *pbuffer,
if(self->time) {
plink->precord->time = self->snap_time;
}
log_debug_printf(_logger, "%s: %s not valid", __func__, self->channelName.c_str());
log_debug_printf(_logger, "%s: %s not valid\n", __func__, self->channelName.c_str());
return -1;
}

Expand Down Expand Up @@ -367,6 +367,12 @@ long pvaGetValue(DBLINK *plink, short dbrType, void *pbuffer,
self->snap_severity = NO_ALARM;
}

if(self->fld_message && self->snap_severity!=0) {
self->snap_message = self->fld_message.as<std::string>();
} else {
self->snap_message.clear();
}

if((self->snap_severity!=NO_ALARM && self->sevr == pvaLink::MS) ||
(self->snap_severity==INVALID_ALARM && self->sevr == pvaLink::MSI))
{
Expand Down Expand Up @@ -489,8 +495,9 @@ long pvaGetUnits(const DBLINK *plink, char *units, int unitsSize)
return -1;
}

long pvaGetAlarm(const DBLINK *plink, epicsEnum16 *status,
epicsEnum16 *severity)
long pvaGetAlarmMsg(const DBLINK *plink,
epicsEnum16 *status, epicsEnum16 *severity,
char *msgbuf, size_t msgbuflen)
{
TRY {
Guard G(self->lchan->lock);
Expand All @@ -502,14 +509,28 @@ long pvaGetAlarm(const DBLINK *plink, epicsEnum16 *status,
if(status) {
*status = self->snap_severity ? LINK_ALARM : NO_ALARM;
}
if(msgbuf && msgbuflen) {
if(self->snap_message.empty()) {
msgbuf[0] = '\0';
} else {
epicsSnprintf(msgbuf, msgbuflen-1u, "%s", self->snap_message.c_str());
msgbuf[msgbuflen-1u] = '\0';
}
}
log_debug_printf(_logger, "%s: %s %s %i %i\n",
__func__, plink->precord->name, self->channelName.c_str(), severity ? *severity : 0, status ? *status : 0);
return 0;
}CATCH()
return -1;
}

long pvaGetTimeStamp(const DBLINK *plink, epicsTimeStamp *pstamp)
long pvaGetAlarm(const DBLINK *plink, epicsEnum16 *status,
epicsEnum16 *severity)
{
return pvaGetAlarmMsg(plink, status, severity, nullptr, 0);
}

long pvaGetTimeStampTag(const DBLINK *plink, epicsTimeStamp *pstamp, epicsUTag *ptag)
{
TRY {
Guard G(self->lchan->lock);
Expand All @@ -518,12 +539,20 @@ long pvaGetTimeStamp(const DBLINK *plink, epicsTimeStamp *pstamp)
if(pstamp) {
*pstamp = self->snap_time;
}
if(ptag) {
*ptag = self->snap_tag;
}
log_debug_printf(_logger, "%s: %s %s %i %i\n", __func__, plink->precord->name, self->channelName.c_str(), pstamp ? pstamp->secPastEpoch : 0, pstamp ? pstamp->nsec : 0);
return 0;
}CATCH()
return -1;
}

long pvaGetTimeStamp(const DBLINK *plink, epicsTimeStamp *pstamp)
{
return pvaGetTimeStampTag(plink, pstamp, nullptr);
}

long pvaPutValueX(DBLINK *plink, short dbrType,
const void *pbuffer, long nRequest, bool wait)
{
Expand Down Expand Up @@ -615,6 +644,17 @@ void pvaScanForward(DBLINK *plink)
}CATCH()
}

#if EPICS_VERSION_INT>=VERSION_INT(3,16,1,0)
long pvaDoLocked(struct link *plink, dbLinkUserCallback rtn, void *priv)
{
TRY {
Guard G(self->lchan->lock);
return (*rtn)(plink, priv);
}CATCH()
return 1;
}
#endif // >= 3.16.1

#undef TRY
#undef CATCH

Expand All @@ -638,8 +678,14 @@ lset pva_lset = {
&pvaGetTimeStamp,
&pvaPutValue,
&pvaPutValueAsync,
&pvaScanForward
//&pvaReportLink,
&pvaScanForward,
#if EPICS_VERSION_INT>=VERSION_INT(3,16,1,0)
&pvaDoLocked,
#endif
#if EPICS_VERSION_INT>=VERSION_INT(7,0,6,0)
&pvaGetAlarmMsg,
&pvaGetTimeStampTag,
#endif
};

} // namespace pvxlink

0 comments on commit 75df3a5

Please sign in to comment.