The following were made to all special pvdbcr modules

1) Much cleaner implementation.
2) pvdbSpecialRegister.dbd is new
This commit is contained in:
mrkraimer
2021-03-20 10:48:08 -04:00
parent dafc37b585
commit 333cd44da0
17 changed files with 577 additions and 928 deletions

View File

@@ -10,35 +10,24 @@
/* Author: Marty Kraimer */
#include <epicsThread.h>
#include <iocsh.h>
#include <pv/event.h>
#include <pv/pvAccess.h>
#include <pv/serverContext.h>
#include <pv/pvData.h>
#include <pv/pvTimeStamp.h>
#include <pv/rpcService.h>
#include <pv/ntscalarArray.h>
// The following must be the last include for code pvDatabase uses
#include <pv/standardField.h>
#include <pv/pvDatabase.h>
// The following must be the last include for code exampleLink uses
#include <epicsExport.h>
#define epicsExportSharedSymbols
#include "pv/pvStructureCopy.h"
#include "pv/pvDatabase.h"
using namespace epics::pvData;
using namespace epics::nt;
using namespace epics::pvAccess;
using namespace epics::pvDatabase;
using namespace std;
static const iocshArg testArg0 = { "recordName", iocshArgString };
static const iocshArg testArg1 = { "scalarType", iocshArgString };
static const iocshArg testArg2 = { "asLevel", iocshArgInt };
static const iocshArg *testArgs[] = {&testArg0,&testArg1,&testArg2};
static const iocshArg arg0 = { "recordName", iocshArgString };
static const iocshArg arg1 = { "scalarType", iocshArgString };
static const iocshArg arg2 = { "asLevel", iocshArgInt };
static const iocshArg arg3 = { "asGroup", iocshArgString };
static const iocshArg *args[] = {&arg0,&arg1,&arg2,&arg3};
static const iocshFuncDef pvdbcrScalarArrayFuncDef = {"pvdbcrScalarArray", 3,testArgs};
static const iocshFuncDef pvdbcrScalarArrayFuncDef = {"pvdbcrScalarArray", 4,args};
static void pvdbcrScalarArrayCallFunc(const iocshArgBuf *args)
{
@@ -53,22 +42,27 @@ static void pvdbcrScalarArrayCallFunc(const iocshArgBuf *args)
}
string scalarType = string(sval);
int asLevel = args[2].ival;
try {
ScalarType st = epics::pvData::ScalarTypeFunc::getScalarType(scalarType);
NTScalarArrayBuilderPtr ntScalarArrayBuilder = NTScalarArray::createBuilder();
PVStructurePtr pvStructure = ntScalarArrayBuilder->
value(st)->
addAlarm()->
addTimeStamp()->
createPVStructure();
PVRecordPtr record = PVRecord::create(recordName,pvStructure);
record->setAsLevel(asLevel);
PVDatabasePtr master = PVDatabase::getMaster();
bool result = master->addRecord(record);
if(!result) cout << "recordname " << recordName << " not added" << endl;
} catch(std::exception& ex) {
cerr << "failure " << ex.what() << "/n";
string asGroup("DEFAULT");
sval = args[3].sval;
if(sval) {
asGroup = string(sval);
}
ScalarType st = epics::pvData::ScalarTypeFunc::getScalarType(scalarType);
FieldCreatePtr fieldCreate = getFieldCreate();
StandardFieldPtr standardField = getStandardField();
PVDataCreatePtr pvDataCreate = getPVDataCreate();
StructureConstPtr top = fieldCreate->createFieldBuilder()->
addArray("value",st) ->
add("timeStamp",standardField->timeStamp()) ->
add("alarm",standardField->alarm()) ->
createStructure();
PVStructurePtr pvStructure = pvDataCreate->createPVStructure(top);
PVRecordPtr record = PVRecord::create(recordName,pvStructure);
record->setAsLevel(asLevel);
record->setAsGroup(asGroup);
PVDatabasePtr master = PVDatabase::getMaster();
bool result = master->addRecord(record);
if(!result) cout << "recordname " << recordName << " not added" << endl;
}
static void pvdbcrScalarArrayRegister(void)