Files
pvDatabase/src/special/pvdbcrScalarArrayRegister.cpp
mrkraimer dafc37b585 The following changes were made:
1) PVRecord now has two new methods: setAsLevel and setAsGroup.
2) The following special records are DEPRECATED: addRecord,processRecord,removeRecord, and traceRecord.
    They are replaced by pvdbcrAddRecord,pvdbcrProcessRecord,pvdbcrRemoveRecord, and pvdbcrTraceRecord.
3) A new convention is that all special records start with pvdbcr, which means pvDatabase Create Record.
4) pvdbcrAddRecord,pvdbcrProcessRecord,pvdbcrRemoveRecord, and pvdbcrTraceRecord are like what they replace.
   But they also allow the asLevel to be set when they are created.
5) pvdbcrScalar and pvdbcrScalarArray are new special records.
   They created records that have fields value, alarm, and timeStamp.
   value can have any of the allowed scalar types, i.e. boolean,byte,...,string.
2021-03-15 07:04:32 -04:00

86 lines
2.5 KiB
C++

/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
/**
* @author mrk
* @date 2021.03.12
*/
/* 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 <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 iocshFuncDef pvdbcrScalarArrayFuncDef = {"pvdbcrScalarArray", 3,testArgs};
static void pvdbcrScalarArrayCallFunc(const iocshArgBuf *args)
{
char *sval = args[0].sval;
if(!sval) {
throw std::runtime_error("pvdbcrScalarArrayCreate recordName not specified");
}
string recordName = string(sval);
sval = args[1].sval;
if(!sval) {
throw std::runtime_error("pvdbcrScalarArrayCreate scalarType not specified");
}
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";
}
}
static void pvdbcrScalarArrayRegister(void)
{
static int firstTime = 1;
if (firstTime) {
firstTime = 0;
iocshRegister(&pvdbcrScalarArrayFuncDef, pvdbcrScalarArrayCallFunc);
}
}
extern "C" {
epicsExportRegistrar(pvdbcrScalarArrayRegister);
}