-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Timestaming with UTAG #107 from jerzyjamroz/utag-rc
- Loading branch information
Showing
9 changed files
with
290 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Usage of "evreventutag.db" | ||
## Timestaming + UTAG support: import "evreventutag.db" instead of "evrevent.db". | ||
## Timestaming support only: import "evrevent.db" and ignore "evreventutag.db". | ||
|
||
# Macros: | ||
# EN = record name prefix | ||
# OBJ = EVR devObj name | ||
# CODE = Event code (hardware) | ||
|
||
record(int64out, "$(EN)-SP") { | ||
field(DTYP, "EVR Event Utag") | ||
field(SCAN, "I/O Intr") | ||
field(OUT , "@OBJ=$(OBJ),Code=$(CODE)") | ||
field(VAL , "0") | ||
field(TSE , "-2") # from device support | ||
field(FLNK, "$(EN)Cnt-I") | ||
info(autosaveFields_pass0, "OUT") | ||
} | ||
|
||
record(calc, "$(EN)Cnt-I") { | ||
field(DESC, "TS and UTAG source") | ||
#field(SDIS, "$(EN)-SP") | ||
#field(DISV, "0") | ||
field(CALC, "A+1") | ||
field(INPA, "$(EN)Cnt-I NPP") | ||
field(TSEL, "$(EN)-SP.TIME") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
/*************************************************************************\ | ||
* Copyright (c) 2023 European Spallation Source ERIC (ESS), Lund, Sweden | ||
* mrfioc2 is distributed subject to a Software License Agreement found | ||
* in file LICENSE that is included with this distribution. | ||
\*************************************************************************/ | ||
/* | ||
* Date: 5.12.2023 | ||
* Authors: Joao Paulo Martins <joaopaulosm@gmail.com> | ||
* Jerzy Jamroz <jerzy.jamroz@gmail.com> | ||
*/ | ||
|
||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <epicsExport.h> | ||
#include <dbAccess.h> | ||
#include <devSup.h> | ||
#include <recGbl.h> | ||
#include <devLib.h> // For S_dev_* | ||
#include <alarm.h> | ||
#include <errlog.h> | ||
|
||
#include <int64outRecord.h> | ||
#include <epicsVersion.h> | ||
|
||
#include "devObj.h" | ||
#include "evr/evr.h" | ||
|
||
#include "linkoptions.h" | ||
|
||
#include <stdexcept> | ||
#include <string> | ||
|
||
/***************** Event *****************/ | ||
|
||
struct priv | ||
{ | ||
EVR *evr; | ||
char obj[30]; | ||
int event; | ||
}; | ||
|
||
static const linkOptionDef eventdef[] = | ||
{ | ||
linkString(priv, obj, "OBJ", 1, 0), | ||
linkInt32(priv, event, "Code", 1, 0), | ||
linkOptionEnd}; | ||
|
||
static long add_record(struct dbCommon *prec, struct link *link) | ||
{ | ||
long ret = 0; | ||
try | ||
{ | ||
assert(link->type == INST_IO); | ||
|
||
mrf::auto_ptr<priv> p(new priv); | ||
p->event = 0; | ||
|
||
if (linkOptionsStore(eventdef, p.get(), link->value.instio.string, 0)) | ||
throw std::runtime_error("Couldn't parse link string"); | ||
|
||
mrf::Object *O = mrf::Object::getObject(p->obj); | ||
if (!O) | ||
{ | ||
errlogPrintf("%s: failed to find object '%s'\n", prec->name, p->obj); | ||
return S_db_errArg; | ||
} | ||
p->evr = dynamic_cast<EVR *>(O); | ||
if (!p->evr) | ||
throw std::runtime_error("Failed to lookup device"); | ||
|
||
if (!p->evr->interestedInEvent(p->event, true)) | ||
throw std::runtime_error("Failed to register interest"); | ||
|
||
prec->dpvt = (void *)p.release(); | ||
|
||
return 0; | ||
} | ||
catch (std::runtime_error &e) | ||
{ | ||
recGblRecordError(S_dev_noDevice, (void *)prec, e.what()); | ||
ret = S_dev_noDevice; | ||
} | ||
catch (std::exception &e) | ||
{ | ||
recGblRecordError(S_db_noMemory, (void *)prec, e.what()); | ||
ret = S_db_noMemory; | ||
} | ||
return ret; | ||
} | ||
|
||
static long del_record(struct dbCommon *prec) | ||
{ | ||
priv *p = static_cast<priv *>(prec->dpvt); | ||
long ret = 0; | ||
if (!p) | ||
return 0; | ||
try | ||
{ | ||
|
||
p->evr->interestedInEvent(p->event, false); | ||
delete p; | ||
prec->dpvt = 0; | ||
} | ||
catch (std::runtime_error &e) | ||
{ | ||
recGblRecordError(S_dev_noDevice, (void *)prec, e.what()); | ||
ret = S_dev_noDevice; | ||
} | ||
catch (std::exception &e) | ||
{ | ||
recGblRecordError(S_db_noMemory, (void *)prec, e.what()); | ||
ret = S_db_noMemory; | ||
} | ||
return ret; | ||
} | ||
|
||
static long get_ioint_info(int, dbCommon *prec, IOSCANPVT *io) | ||
{ | ||
if (!prec->dpvt) | ||
return S_db_errArg; | ||
priv *p = static_cast<priv *>(prec->dpvt); | ||
long ret = 0; | ||
try | ||
{ | ||
|
||
if (!p) | ||
return 1; | ||
|
||
*io = p->evr->eventOccurred(p->event); | ||
|
||
return 0; | ||
} | ||
catch (std::runtime_error &e) | ||
{ | ||
recGblRecordError(S_dev_noDevice, (void *)prec, e.what()); | ||
ret = S_dev_noDevice; | ||
} | ||
catch (std::exception &e) | ||
{ | ||
recGblRecordError(S_db_noMemory, (void *)prec, e.what()); | ||
ret = S_db_noMemory; | ||
} | ||
*io = NULL; | ||
return ret; | ||
} | ||
|
||
static long process_int64out(int64outRecord *prec) | ||
{ | ||
priv *p = static_cast<priv *>(prec->dpvt); | ||
long ret = 0; | ||
try | ||
{ | ||
|
||
if (p->event >= 0 && p->event <= 255) | ||
post_event(p->event); | ||
|
||
if (prec->tse == epicsTimeEventDeviceTime) | ||
{ | ||
p->evr->getTimeStamp(&prec->time, p->event); | ||
#ifdef DBR_UTAG | ||
prec->utag = static_cast<epicsUTag>(prec->val); | ||
p->evr->setUtag(prec->utag, p->event); | ||
#endif | ||
} | ||
|
||
return 0; | ||
} | ||
catch (std::runtime_error &e) | ||
{ | ||
recGblRecordError(S_dev_noDevice, (void *)prec, e.what()); | ||
ret = S_dev_noDevice; | ||
} | ||
catch (std::exception &e) | ||
{ | ||
recGblRecordError(S_db_noMemory, (void *)prec, e.what()); | ||
ret = S_db_noMemory; | ||
} | ||
return ret; | ||
} | ||
|
||
static long add_int64out(struct dbCommon *precord) | ||
{ | ||
return add_record(precord, &((struct int64outRecord *)precord)->out); | ||
} | ||
|
||
dsxt dxtI64OEventUtagEVR = {add_int64out, del_record}; | ||
static common_dset devI64OEventUtagEVR = { | ||
6, NULL, | ||
dset_cast(&init_dset<&dxtI64OEventUtagEVR>), | ||
(DEVSUPFUN)init_record_empty, | ||
(DEVSUPFUN)&get_ioint_info, | ||
dset_cast(&process_int64out), | ||
NULL}; | ||
|
||
extern "C" | ||
{ | ||
epicsExportAddress(dset, devI64OEventUtagEVR); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# '@C=..., Code=hweventnum' | ||
device(int64out, INST_IO, devI64OEventUtagEVR, "EVR Event Utag") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters