Ejemplo n.º 1
0
void MonitorRequesterImpl::ParseScalarArray(PVScalarArray::shared_pointer const & pvArray,  knobData* kPtr)
{
    size_t length = pvArray->getLength();
    qDebug() << "lenght of array " << length;
    PVDoubleArrayPtr ArrayData = static_pointer_cast<epics::pvData::PVDoubleArray> (pvArray);
    DoubleArrayData valuesArrayData;
    int valuesLength = ArrayData->get(0, ArrayData->getLength(), valuesArrayData);

    if((double) (valuesLength * sizeof(double)) != kPtr->edata.dataSize) {
        free(kPtr->edata.dataB);
        kPtr->edata.dataB = (void*) malloc(valuesLength * sizeof(double));
        kPtr->edata.dataSize = valuesLength * sizeof(double);
    }
    kPtr->edata.valueCount = valuesLength;
    kPtr->edata.precision = 3;  // for the time beeing, set to 3
    kPtr->edata.fieldtype = caDOUBLE;
    memcpy(kPtr->edata.dataB, &valuesArrayData.data[0],  valuesLength * sizeof(double));

}
void RequestResponseHandler::makeStrings(epics::pvData::PVStructurePtr const & response)
{
    using namespace epics::pvData;
    using namespace std;

    PVStructurePtr responseValues = response->getStructureField("value");
    if (!responseValues)
    {
        cerr << "Data invalid: No value field in table." << endl;
        m_ok = false;  
        return; 
    }

    //  Handle each of the fields in the archiver query response in turn.

    //  Values.
    PVDoubleArrayPtr values = getDoubleArrayField(responseValues, "value");
    if (!values)
    {
        cerr << "Data invalid: No value field in table values." << endl;
        m_ok = false;  
        return;
    }    
    int valuesLength = values->getLength();

    if (isPresent(VALUE, m_parameters.outputtedFields))
    {

        arrayValuesToStrings(outputFieldValues[VALUE], values->view(),
            m_parameters.format, m_parameters.precision);
    }


    //  Seconds.
    PVLongArrayPtr secPastEpochs = getLongArrayField(responseValues, "secondsPastEpoch");
    if (!secPastEpochs)
    {
        cerr << "Data invalid: No secondsPastEpoch field in table values." << endl;
        m_ok = false;  
        return;
    }

    int secPastEpochsLength = secPastEpochs->getLength();
    if (secPastEpochsLength != valuesLength)
    {
        cerr << "Data invalid: secondsPastEpoch and value lengths don't match." << endl;
        m_ok = false;  
        return; 
    }

    PVLongArray::const_svector secPastEpochsData = secPastEpochs->view();

    if (isPresent(SECONDS_PAST_EPOCH, m_parameters.outputtedFields)
     || isPresent(REAL_TIME, m_parameters.outputtedFields))
    {
        arrayValuesToStrings(outputFieldValues[SECONDS_PAST_EPOCH], secPastEpochsData);
    }


    //  Nanoseconds.
    PVIntArrayPtr nsecs = getIntArrayField(responseValues, "nanoseconds");
    if (!nsecs)
    {
        cerr << "Data invalid: No nanoseconds field in table values." << endl;
        m_ok = false;  
        return;
    }

    int nsecsLength =  nsecs->getLength();
    if (nsecsLength != valuesLength)
    {
        cerr << "Data invalid: nanoseconds past epoch and value lengths don't match." << endl;
        m_ok = false;  
        return;  
    }

    PVIntArray::const_svector nsecsData = nsecs->view();

    if (isPresent(NANO_SECONDS, m_parameters.outputtedFields)
     || isPresent(REAL_TIME, m_parameters.outputtedFields))
    {
        arrayValuesToStrings(outputFieldValues[NANO_SECONDS], nsecsData);
    }


    //  Real time in seconds.
    if (isPresent(REAL_TIME, m_parameters.outputtedFields))
    {
        int realTimeLength = min(secPastEpochsLength, nsecsLength);
        vector<string> & realTimeStrings = outputFieldValues[REAL_TIME];
        realTimeStrings.reserve(realTimeLength);

        {
            ostringstream oss;
            for (int i = 0; i < realTimeLength; ++i)
            {
                oss << secPastEpochsData[i]  << ".";
                oss << setfill('0') << setw(9) << nsecsData[i];
                realTimeStrings.push_back(oss.str());
                oss.str("");
           }
        }
    }


    //  Dates.
    if (isPresent(DATE, m_parameters.outputtedFields))
    {
        vector<string> & dateStrings = outputFieldValues[DATE];
        int dateLength = min(secPastEpochsLength, nsecsLength);
        dateStrings.reserve(dateLength);

        for (int i = 0; i < dateLength; ++i)
        {     
            string dateString = getDate(secPastEpochsData[i], nsecsData[i]);
            dateStrings.push_back(dateString);
        }
    }


    //  Alarm status.
    PVIntArrayPtr statuses = getIntArrayField(responseValues, "status");
    if (!statuses)
    {
        cerr << "Data invalid: No status field in table values." << endl;
        m_ok = false;  
        return;
    }

    int statusesLength = statuses->getLength();
    if (statusesLength != valuesLength)
    {
        cerr << "Data invalid: status and value lengths don't match." << endl;
        m_ok = false;  
        return; 
    }
    if (isPresent(STATUS, m_parameters.outputtedFields))
    {
        PVIntArray::const_svector statusData = statuses->view();
        arrayValuesToStrings(outputFieldValues[STATUS], statusData, FormatParameters::HEX);
    }


    //  Alarm severity.
    PVIntArrayPtr severities = getIntArrayField(responseValues, "severity");
    if (!severities)
    {
        cerr << "Data invalid: No severity field in table values." << endl;
        m_ok = false;  
        return;
    }

    int severitiesLength = severities->getLength();
    if (severitiesLength != valuesLength)
    {
        cerr << "Data invalid: severity and value lengths don't match." << endl;
        m_ok = false;  
        return; 
    }
    if (isPresent(SEVERITY, m_parameters.outputtedFields))
    {        
        PVIntArray::const_svector severityData = severities->view();
        arrayValuesToStrings(outputFieldValues[SEVERITY], severityData, FormatParameters::HEX);
    }


    //  Alarm string.
    int alarmStringsLength = min(secPastEpochsLength, nsecsLength);
    
    if (isPresent(ALARM, m_parameters.outputtedFields))
    {
        vector<string> & alarmStrings = outputFieldValues[ALARM];        
        alarmStrings.reserve(alarmStringsLength); 

        PVIntArray::const_svector statusData = statuses->view();
        PVIntArray::const_svector severityData = severities->view();

        for (int i = 0; i < valuesLength; ++i)
        {     
            string alarmString = makeAlarmString(statusData[i], severityData[i]);
            alarmStrings.push_back(alarmString);
        }
    }
}