Exemplo n.º 1
0
void  MonitorRequesterImpl::monitorEvent(Monitor::shared_pointer const & monitor)
{
    qDebug() << "monitorEvent " << m_channelIndex;
    MonitorElement::shared_pointer element;

    knobData *kPtr = m_mutexData->GetMutexKnobDataPtr(m_channelIndex);  // use pointer
    if(kPtr->index == -1) return;
    qDebug() << "connection state" << kPtr->edata.connected;

    while (element = monitor->poll()) {

        PVField::shared_pointer value = element->pvStructurePtr->getSubField("value");
        if (value.get() == 0) {
             std::cout <<  "no 'value' field" << m_channelName  << std::endl;
             std::cout << *(element->pvStructurePtr.get())  << std::endl;
        } else {
            Type valueType = value->getField()->getType();

            // we have a structure
            if (valueType != scalar && valueType != scalarArray) {
                 std::cout << "structure " <<  m_channelName << std::endl;
                 std::cout << *(element->pvStructurePtr.get()) << std::endl;

                // we have a scalar value or scalar array
            } else {
                if (value->getField()->getType() == scalar) {
                     std::cout << "scalar "<<  m_channelName << std::endl;

                    ParseScalar("", static_pointer_cast<PVScalar>(value), kPtr);

                    PVField::shared_pointer alarm = element->pvStructurePtr->getSubField("alarm");
                    if (alarm.get() != 0) ParsePVStructure(static_pointer_cast<PVStructure>(alarm), kPtr, false);

                    PVField::shared_pointer display = element->pvStructurePtr->getSubField("display");
                    if (display.get() != 0) ParsePVStructure(static_pointer_cast<PVStructure>(display), kPtr, false);

                    PVField::shared_pointer control = element->pvStructurePtr->getSubField("control");
                    if (control.get() != 0) ParsePVStructure(static_pointer_cast<PVStructure>(control), kPtr, false);

                    PVField::shared_pointer valueAlarm = element->pvStructurePtr->getSubField("valueAlarm");
                    if (valueAlarm.get() != 0) ParsePVStructure(static_pointer_cast<PVStructure>(valueAlarm), kPtr, false);

                } else {
                     std::cout <<  "scalar array " << m_channelName << " values: "  << std::endl;
                    ParseScalarArray(static_pointer_cast<PVScalarArray>(value), kPtr);
                }
            }
        }
    }

    kPtr->edata.accessW = true;
    kPtr->edata.accessR = true;
    kPtr->edata.monitorCount++;
    strcpy(kPtr->edata.fec, "EPICS4");
    m_mutexData->SetMutexKnobDataReceived(kPtr);

    monitor->release(element);
}
    virtual void monitorEvent(Monitor::shared_pointer const & monitor)
    {
        std::cout << "monitorEvent" << std::endl;

        MonitorElement::shared_pointer element = monitor->poll();

        std::cout << "changed/overrun " << *element->changedBitSet << '/' <<
                     *element->overrunBitSet << std::endl << *element->pvStructurePtr << std::endl;

        monitor->release(element);
    }
Exemplo n.º 3
0
Monitor::shared_pointer CAChannelMonitor::create(
        CAChannel::shared_pointer const & channel,
        epics::pvData::MonitorRequester::shared_pointer const & monitorRequester,
        epics::pvData::PVStructure::shared_pointer const & pvRequest)
{
    // TODO use std::make_shared
    std::tr1::shared_ptr<CAChannelMonitor> tp(
                new CAChannelMonitor(channel, monitorRequester, pvRequest)
                );
    Monitor::shared_pointer thisPtr = tp;
    static_cast<CAChannelMonitor*>(thisPtr.get())->activate();
    return thisPtr;
}
    virtual void monitorEvent(Monitor::shared_pointer const & monitor)
    {

        MonitorElement::shared_pointer element;
        while ((element = monitor->poll()))
        {
            channelCount++;
            if (channelCount == channels)
            {
                iterationCount++;
                channelCount = 0;
            }

            if (iterationCount == iterations)
            {
                epicsTimeStamp endTime;
                epicsTimeGetCurrent(&endTime);

                double duration = epicsTime(endTime) - epicsTime(startTime);
                double getPerSec = iterations*channels/duration;
                double gbit = getPerSec*arraySize*sizeof(double)*8/(1000*1000*1000); // * bits / giga; NO, it's really 1000 and not 1024
                if (verbose)
                    printf("%5.6f seconds, %.3f (x %d = %.3f) monitors/s, data throughput %5.3f Gbits/s\n",
                           duration, iterations/duration, channels, getPerSec, gbit);
                sum += getPerSec;

                iterationCount = 0;
                epicsTimeGetCurrent(&startTime);

                runCount++;
                if (runs == 0 || runCount < runs)
                {
                    // noop
                }
                else
                {
                    printf("%d %d %d %d %.3f\n", channels, arraySize, iterations, runs, sum/runs);

                    Lock guard(waitLoopPtrMutex);
                    waitLoopEvent->signal();	// all done
                }
            }
            else if (channelCount == 0)
            {
                // noop
            }

            monitor->release(element);
        }

    }
Exemplo n.º 5
0
void  MonitorRequesterImpl::monitorConnect(const epics::pvData::Status& status, Monitor::shared_pointer const & monitor, StructureConstPtr const & /*structure*/)
{
    qDebug() << "monitorConnect";
    if (status.isSuccess()) {
        Status startStatus = monitor->start();
        // show error
        if (!startStatus.isSuccess()) {
            std::cerr << "[" << m_channelName << "] channel monitor start: " << startStatus.toString() << std::endl;
        }

    } else {
        std::cerr << "monitorConnect(" << status.toString() << ")" << std::endl;
    }
}
Exemplo n.º 6
0
    virtual void monitorConnect(const epics::pvData::Status& status, Monitor::shared_pointer const & monitor, StructureConstPtr const & /*structure*/)
    {
        if (status.isSuccess())
        {
            /*
            string str;
            structure->toString(&str);
            std::cout << str << std::endl;
            */

            Status startStatus = monitor->start();
            // show error
            // TODO and exit
            if (!startStatus.isSuccess())
            {
                std::cerr << "[" << m_channelName << "] channel monitor start: " << startStatus << std::endl;
            }

        }
        else
        {
            std::cerr << "monitorConnect(" << status << ")" << std::endl;
        }
    }
Exemplo n.º 7
0
    virtual void monitorEvent(Monitor::shared_pointer const & monitor)
    {

        MonitorElement::shared_pointer element;
        while ((element = monitor->poll()))
        {
            if (mode == ValueOnlyMode)
            {
                PVField::shared_pointer value = element->pvStructurePtr->getSubField("value");
                if (value.get() == 0)
                {
                    std::cerr << "no 'value' field" << std::endl;
                    std::cout << m_channelName << std::endl;
                    //std::cout << *(element->pvStructurePtr.get()) << std::endl << std::endl;
                    pvutil_ostream myos(std::cout.rdbuf());
                    myos << *(element->pvStructurePtr.get()) << std::endl << std::endl;
                }
                else
                {
                    Type valueType = value->getField()->getType();
                    if (valueType != scalar && valueType != scalarArray)
                    {
                        // switch to structure mode, unless it's T-type
                        if (valueType == structure && isTType(static_pointer_cast<PVStructure>(value)))
                        {
                            std::cout << std::setw(30) << std::left << m_channelName;
                            std::cout << fieldSeparator;
                            formatTType(std::cout, static_pointer_cast<PVStructure>(value));
                            std::cout << std::endl;
                        }
                        else
                        {
                            std::cout << m_channelName << std::endl;
                            //std::cout << *(element->pvStructurePtr.get()) << std::endl << std::endl;
                            pvutil_ostream myos(std::cout.rdbuf());
                            myos << *(element->pvStructurePtr.get()) << std::endl << std::endl;
                        }
                    }
                    else
                    {
                        if (fieldSeparator == ' ' && value->getField()->getType() == scalar)
                            std::cout << std::setw(30) << std::left << m_channelName;
                        else
                            std::cout << m_channelName;

                        std::cout << fieldSeparator;

                        terse(std::cout, value) << std::endl;
                    }
                }
            }
            else if (mode == TerseMode)
            {
                if (fieldSeparator == ' ')
                    std::cout << std::setw(30) << std::left << m_channelName;
                else
                    std::cout << m_channelName;

                std::cout << fieldSeparator;

                terseStructure(std::cout, element->pvStructurePtr) << std::endl;
            }
            else
            {
                std::cout << m_channelName << std::endl;
                //std::cout << *(element->pvStructurePtr.get()) << std::endl << std::endl;
                pvutil_ostream myos(std::cout.rdbuf());
                myos << *(element->pvStructurePtr.get()) << std::endl << std::endl;
            }

            monitor->release(element);
        }

    }
int main()
{
    for (int i = 0; i < 10; i++) {
    {
    /*
    ClientContextImpl::shared_pointer context = createClientContextImpl();
    context->printInfo();

    context->initialize();
    context->printInfo();

    epicsThreadSleep ( SLEEP_TIME );
    
    ChannelProvider::shared_pointer provider = context->getProvider();
    */
    
    ClientFactory::start();
    ChannelProvider::shared_pointer provider = getChannelProviderRegistry()->getProvider("pva");

    ChannelFindRequester::shared_pointer findRequester(new ChannelFindRequesterImpl());
    ChannelFind::shared_pointer channelFind = provider->channelFind("testSomething", findRequester);
    epicsThreadSleep ( SLEEP_TIME );
    //channelFind->destroy();

    ChannelRequester::shared_pointer channelRequester(new ChannelRequesterImpl());
    Channel::shared_pointer channel = provider->createChannel("testStructureArrayTest", channelRequester);
    epicsThreadSleep ( SLEEP_TIME );
    channel->printInfo();
        
        {
    GetFieldRequester::shared_pointer getFieldRequesterImpl(new GetFieldRequesterImpl());
    channel->getField(getFieldRequesterImpl, "");
    epicsThreadSleep ( SLEEP_TIME );
        }
        
        {
    ChannelProcessRequester::shared_pointer channelProcessRequester(new ChannelProcessRequesterImpl());
    PVStructure::shared_pointer pvRequest;
    ChannelProcess::shared_pointer channelProcess = channel->createChannelProcess(channelProcessRequester, pvRequest);
    epicsThreadSleep ( SLEEP_TIME );
    channelProcess->process();
    epicsThreadSleep ( SLEEP_TIME );
    channelProcess->destroy();
    epicsThreadSleep ( SLEEP_TIME );
        }
        
        {
    ChannelGetRequester::shared_pointer channelGetRequesterImpl(new ChannelGetRequesterImpl());
    PVStructure::shared_pointer pvRequest = CreateRequest::create()->createRequest("field()");
    ChannelGet::shared_pointer channelGet = channel->createChannelGet(channelGetRequesterImpl, pvRequest);
    epicsThreadSleep ( 3.0 );
    channelGet->get();
    epicsThreadSleep ( 3.0 );
    channelGet->destroy();
        }
    
        {
    ChannelPutRequester::shared_pointer channelPutRequesterImpl(new ChannelPutRequesterImpl());
    PVStructure::shared_pointer pvRequest = CreateRequest::create()->createRequest("field(value,timeStamp)");
    ChannelPut::shared_pointer channelPut = channel->createChannelPut(channelPutRequesterImpl, pvRequest);
    epicsThreadSleep ( SLEEP_TIME );
    channelPut->get();
    epicsThreadSleep ( SLEEP_TIME );
    // TODO !!!
    //channelPut->put();
    //epicsThreadSleep ( SLEEP_TIME );
    channelPut->destroy();
        }

        {
    ChannelPutGetRequester::shared_pointer channelPutGetRequesterImpl(new ChannelPutGetRequesterImpl());
    PVStructure::shared_pointer pvRequest = CreateRequest::create()->createRequest("putField(value,timeStamp)getField(timeStamp)");
    ChannelPutGet::shared_pointer channelPutGet = channel->createChannelPutGet(channelPutGetRequesterImpl, pvRequest);
    epicsThreadSleep ( SLEEP_TIME );
    channelPutGet->getGet();
    epicsThreadSleep ( SLEEP_TIME );
    channelPutGet->getPut();
    epicsThreadSleep ( SLEEP_TIME );
    // TODO !!!
    //channelPutGet->putGet();
    //epicsThreadSleep ( SLEEP_TIME );
    channelPutGet->destroy();
        }

        {
    ChannelRPCRequester::shared_pointer channelRPCRequesterImpl(new ChannelRPCRequesterImpl());
    PVStructure::shared_pointer pvRequest = CreateRequest::create()->createRequest("record[]field(arguments)");
    ChannelRPC::shared_pointer channelRPC = channel->createChannelRPC(channelRPCRequesterImpl, pvRequest);
    epicsThreadSleep ( SLEEP_TIME );
    // for test simply use pvRequest as arguments
    channelRPC->request(pvRequest);
    epicsThreadSleep ( SLEEP_TIME );
    channelRPC->destroy();
        }
         
        {
    ChannelArrayRequester::shared_pointer channelArrayRequesterImpl(new ChannelArrayRequesterImpl());
    StringArray fieldNames; fieldNames.push_back("field");
    FieldConstPtrArray fields; fields.push_back(getFieldCreate()->createScalar(pvString));
    PVStructure::shared_pointer pvRequest(getPVDataCreate()->createPVStructure(getFieldCreate()->createStructure(fieldNames, fields)));

    ChannelArray::shared_pointer channelArray = channel->createChannelArray(channelArrayRequesterImpl, pvRequest);
    epicsThreadSleep ( SLEEP_TIME );
    channelArray->getArray(0,0,1);
    epicsThreadSleep ( SLEEP_TIME );
    // TODO !!!
    //channelArray->putArray(0,0,1);
    //epicsThreadSleep ( SLEEP_TIME );
    channelArray->setLength(3);
    epicsThreadSleep ( SLEEP_TIME );
    channelArray->getLength();
    epicsThreadSleep ( SLEEP_TIME );
    channelArray->destroy();
        }

        {
    MonitorRequester::shared_pointer monitorRequesterImpl(new MonitorRequesterImpl());
    PVStructure::shared_pointer pvRequest = CreateRequest::create()->createRequest("field()");
    Monitor::shared_pointer monitor = channel->createMonitor(monitorRequesterImpl, pvRequest);

    epicsThreadSleep( SLEEP_TIME );

    Status status = monitor->start();
    std::cout << "monitor->start() = " << status << std::endl;

    epicsThreadSleep( 3*SLEEP_TIME );

    status = monitor->stop();
    std::cout << "monitor->stop() = " << status << std::endl;


    monitor->destroy();
        }
    
    epicsThreadSleep ( 3*SLEEP_TIME );
    printf("Destroying channel... \n");
    channel->destroy();
    printf("done.\n");

    epicsThreadSleep ( 3*SLEEP_TIME );
        
    }
    
    ClientFactory::stop();

    /*
    printf("Destroying context... \n");
    context->destroy();
    printf("done.\n");
    */
    
    epicsThreadSleep ( SLEEP_TIME ); }
    //std::cout << "-----------------------------------------------------------------------" << std::endl;
    //epicsExitCallAtExits();
    return(0);
}