Пример #1
0
static void powerSupplyTest()
{
    cout << endl << endl << "****powerSupplyTest****" << endl;
    RequesterPtr requester(new MyRequester("exampleTest"));
    PowerSupplyPtr pvRecord;
    string request;
    PVStructurePtr pvRequest;
    PVCopyPtr pvCopy;
    string builder;
    string valueNameRecord;
    string valueNameCopy;

    CreateRequest::shared_pointer createRequest = CreateRequest::create();
    PVStructurePtr pv = createPowerSupply();
    pvRecord = PowerSupply::create("powerSupply",pv);
    valueNameRecord = request = "power.value";
    pvRequest = createRequest->createRequest(request);
    cout << "request " << request << endl << "pvRequest" << *pvRequest << endl ;
    pvCopy = PVCopy::create(pvRecord->getPVRecordStructure()->getPVStructure(),pvRequest,"");
    valueNameCopy = "power.value";
    testPVScalar(valueNameRecord,valueNameCopy,pvRecord,pvCopy);
    request = "";
    valueNameRecord = "power.value";
    pvRequest = createRequest->createRequest(request);
    cout << "request " << request << endl << "pvRequest" << *pvRequest << endl ;
    pvCopy = PVCopy::create(pvRecord->getPVRecordStructure()->getPVStructure(),pvRequest,"");
    valueNameCopy = "power.value";
    testPVScalar(valueNameRecord,valueNameCopy,pvRecord,pvCopy);
    request = "alarm,timeStamp,voltage.value,power.value,current.value";
    valueNameRecord = "power.value";
    pvRequest = createRequest->createRequest(request);
    cout << "request " << request << endl << "pvRequest" << *pvRequest << endl ;
    pvCopy = PVCopy::create(pvRecord->getPVRecordStructure()->getPVStructure(),pvRequest,"");
    valueNameCopy = "power.value";
    testPVScalar(valueNameRecord,valueNameCopy,pvRecord,pvCopy);
    request = "alarm,timeStamp,voltage{value,alarm},power{value,alarm,display},current.value";
    valueNameRecord = "power.value";
    pvRequest = createRequest->createRequest(request);
    cout << "request " << request << endl << "pvRequest" << *pvRequest << endl ;
    pvCopy = PVCopy::create(pvRecord->getPVRecordStructure()->getPVStructure(),pvRequest,"");
    valueNameCopy = "power.value";
    testPVScalar(valueNameRecord,valueNameCopy,pvRecord,pvCopy);
    pvRecord->destroy();
}
Пример #2
0
static void test()
{
    StandardPVFieldPtr standardPVField = getStandardPVField();
    string properties;
    ScalarType scalarType;
    string recordName;
    properties = "alarm,timeStamp";
    scalarType = pvDouble;
    recordName = "exampleDouble";
    PVStructurePtr pvStructure;
    pvStructure = standardPVField->scalar(scalarType,properties);
    PVRecordPtr exampleRecord = PVRecord::create(recordName,pvStructure);
    exampleRecord->setTraceLevel(traceLevel);
    RecordClientPtr exampleRecordClient(RecordClient::create(exampleRecord));
    ListenerPtr exampleListener(Listener::create(exampleRecord));
    {
        exampleRecord->lock();
        exampleRecord->process();
        exampleRecord->unlock();
    }
    if(debug) {cout << "processed exampleDouble "  << endl; }
    exampleRecord->destroy();
    recordName = "powerSupplyExample";
    PowerSupplyPtr psr;
    pvStructure = createPowerSupply();
    psr = PowerSupply::create("powerSupply",pvStructure);
    psr->setTraceLevel(traceLevel);
    RecordClientPtr psrRecordClient(RecordClient::create(psr));
    ListenerPtr psrListener(Listener::create(psr));
    testOk1(psr.get()!=0);
    if(!psr) {
        if(debug) {cout << "PowerSupplyRecordTest::create failed" << endl;}
        return;
    }
    double voltage,power,current;
    {
        psr->lock();
        voltage = psr->getVoltage();
        power = psr->getPower();
        current = psr->getCurrent();
        psr->unlock();
    }
    if(debug ) {
        cout << "initial ";
        cout << " voltage " << voltage ;
        cout << " power " << power;
        cout <<  " current " << current;
        cout << endl;
    }
    testOk1(psr->getVoltage()==0.0);
    testOk1(psr->getPower()==0.0);
    testOk1(psr->getCurrent()==0.0);
    voltage = 1.0;
    power = 1.0;
    if(debug) {
        cout << "before put ";
        cout << " voltage " << voltage ;
        cout << " power " << power;
        cout << endl;
    }
    {
        psr->lock();
        psr->put(power,voltage);
        psr->process();
        psr->unlock();
    }
    {
        psr->lock();
        if(debug) {
            cout << "after put ";
            cout << " voltage " << psr->getVoltage() ;
            cout << " power " << psr->getPower();
            cout <<  " current " << psr->getCurrent();
            cout << endl;
        }
        psr->unlock();
    }
    testOk1(psr->getVoltage()==1.0);
    testOk1(psr->getPower()==1.0);
    testOk1(psr->getCurrent()==1.0);
    psr->destroy();
}