bool PVTimeStamp::attach(PVFieldPtr const & pvField) { if(pvField->getField()->getType()!=structure) return false; PVStructurePtr xxx = static_pointer_cast<PVStructure>(pvField); PVStructure* pvStructure = xxx.get(); while(true) { PVLongPtr pvLong = pvStructure->getLongField("secondsPastEpoch"); if(pvLong.get()!=NULL) { pvSecs = pvLong; pvNano = pvStructure->getIntField("nanoseconds"); pvUserTag = pvStructure->getIntField("userTag"); } if(pvSecs.get()!=NULL && pvNano.get()!=NULL && pvUserTag.get()!=NULL) return true; detach(); // look up the tree for a timeSyamp pvStructure = pvStructure->getParent(); if(pvStructure==NULL) break; } return false; }
void MonitorRequesterImpl::ParseScalar(QString fieldName, PVScalarPtr const & pvs, knobData* kPtr) { QString thisFieldName = QString::fromStdString(pvs->getFieldName()); //qDebug() << "ParseScalar -- field/subfield" << fieldName << thisFieldName; ScalarConstPtr scalar = pvs->getScalar(); ScalarType scalarType = scalar->getScalarType(); switch(scalarType) { case pvBoolean: { PVBooleanPtr data = static_pointer_cast<PVBoolean>(pvs); if(thisFieldName.contains("value")) { kPtr->edata.fieldtype = caINT; kPtr->edata.ivalue = (int)data->get(); } } break; case pvByte: { PVBytePtr data = static_pointer_cast<PVByte>(pvs); if(thisFieldName.contains("value")) { kPtr->edata.fieldtype = caCHAR; kPtr->edata.ivalue = (int)data->get(); } } break; case pvShort: { PVShortPtr data = static_pointer_cast<PVShort>(pvs); if(thisFieldName.contains("value")) { kPtr->edata.fieldtype = caINT; kPtr->edata.rvalue = data->get(); kPtr->edata.ivalue = (int)data->get(); } } break; case pvInt: { PVIntPtr data = static_pointer_cast<PVInt>(pvs); if(fieldName.contains("alarm") && thisFieldName.contains("severity")) { kPtr->edata.severity =(int) data->get(); } else if(fieldName.contains("alarm") && thisFieldName.contains("status")) { kPtr->edata.status = (int) data->get(); } if(thisFieldName.contains("value")) { kPtr->edata.fieldtype = caINT; kPtr->edata.rvalue = data->get(); kPtr->edata.ivalue = (int)data->get(); } } break; case pvLong: { PVLongPtr data = static_pointer_cast<PVLong>(pvs); if(thisFieldName.contains("value")) { kPtr->edata.fieldtype = caLONG; kPtr->edata.rvalue = data->get(); kPtr->edata.ivalue = (int64)data->get(); } } break; case pvFloat: { PVFloatPtr data = static_pointer_cast<PVFloat>(pvs); if(thisFieldName.contains("value")) { kPtr->edata.fieldtype = caFLOAT; kPtr->edata.rvalue = data->get(); } } break; case pvDouble: { PVDoublePtr data = static_pointer_cast<PVDouble>(pvs); if(fieldName.contains("display") && thisFieldName.contains("limitLow")) { kPtr->edata.lower_disp_limit = data->get(); } else if(fieldName.contains("display") && thisFieldName.contains("limitHigh")) { kPtr->edata.upper_disp_limit = data->get(); } else if(fieldName.contains("control") && thisFieldName.contains("limitLow")) { kPtr->edata.lower_ctrl_limit = data->get(); } else if(fieldName.contains("control") && thisFieldName.contains("limitHigh")) { kPtr->edata.upper_ctrl_limit = data->get(); } else if(fieldName.contains("valueAlarm") && thisFieldName.contains("lowAlarmLimit")) { kPtr->edata.lower_alarm_limit = data->get(); } else if(fieldName.contains("valueAlarm") && thisFieldName.contains("highAlarmLimit")) { kPtr->edata.upper_alarm_limit = data->get(); } else if(fieldName.contains("valueAlarm") && thisFieldName.contains("lowWarningLimit")) { kPtr->edata.lower_warning_limit = data->get(); } else if(fieldName.contains("valueAlarm") && thisFieldName.contains("highWarningLimit")) { kPtr->edata.upper_warning_limit = data->get(); // fill value and type } else if(thisFieldName.contains("value")) { kPtr->edata.precision = 3; // for the time beeing, set to 3 kPtr->edata.fieldtype = caDOUBLE; kPtr->edata.rvalue = data->get(); } } break; case pvString: { PVStringPtr data = static_pointer_cast<PVString>(pvs); // fill units if(fieldName.contains("display") && thisFieldName.contains("units")) { strcpy(kPtr->edata.units, data->get().c_str()); } else if(fieldName.contains("display") && thisFieldName.contains("description")) { } else if(fieldName.contains("display") && thisFieldName.contains("format")) { // should use now precision // fill value and type } else if(thisFieldName.contains("value")) { qDebug() << "String :" << data->get().c_str(); } } break; default: qDebug() << "(unknown ScalarType)" << endl; } }
static void testPVScalarWithProperties( string /*fieldName*/,ScalarType stype) { PVStructurePtr pvStructure; bool hasValueAlarm = false; bool hasBooleanAlarm = false; bool hasDisplayControl = false; switch(stype) { case pvBoolean: { pvStructure = standardPVField->scalar( stype,alarmTimeStampValueAlarm); hasBooleanAlarm = true; PVBooleanPtr pvField = pvStructure->getSubField<PVBoolean>("value"); pvField->put(true); break; } case pvByte: { pvStructure = standardPVField->scalar( stype,allProperties); hasValueAlarm = true; hasDisplayControl = true; PVBytePtr pvField = pvStructure->getSubField<PVByte>("value"); pvField->put(127); break; } case pvShort: { pvStructure = standardPVField->scalar( stype,allProperties); hasValueAlarm = true; hasDisplayControl = true; PVShortPtr pvField = pvStructure->getSubField<PVShort>("value"); pvField->put(32767); break; } case pvInt: { pvStructure = standardPVField->scalar( stype,allProperties); hasValueAlarm = true; hasDisplayControl = true; PVIntPtr pvField = pvStructure->getSubField<PVInt>("value"); pvField->put((int32)0x80000000); break; } case pvLong: { pvStructure = standardPVField->scalar( stype,allProperties); hasValueAlarm = true; hasDisplayControl = true; PVLongPtr pvField = pvStructure->getSubField<PVLong>("value"); int64 value = 0x80000000; value <<= 32; value |= 0xffffffff; pvField->put(value); break; } case pvUByte: { pvStructure = standardPVField->scalar( stype,allProperties); hasValueAlarm = true; hasDisplayControl = true; PVUBytePtr pvField = pvStructure->getSubField<PVUByte>("value"); pvField->put(255); break; } case pvUShort: { pvStructure = standardPVField->scalar( stype,allProperties); hasValueAlarm = true; hasDisplayControl = true; PVUShortPtr pvField = pvStructure->getSubField<PVUShort>("value"); pvField->put(65535); break; } case pvUInt: { pvStructure = standardPVField->scalar( stype,allProperties); hasValueAlarm = true; hasDisplayControl = true; PVUIntPtr pvField = pvStructure->getSubField<PVUInt>("value"); pvField->put((uint32)0x80000000); break; } case pvULong: { pvStructure = standardPVField->scalar( stype,allProperties); hasValueAlarm = true; hasDisplayControl = true; PVULongPtr pvField = pvStructure->getSubField<PVULong>("value"); int64 value = 0x80000000; value <<= 32; value |= 0xffffffff; pvField->put(value); break; } case pvFloat: { pvStructure = standardPVField->scalar( stype,allProperties); hasValueAlarm = true; hasDisplayControl = true; PVFloatPtr pvField = pvStructure->getSubField<PVFloat>("value"); pvField->put(1.123e8); break; } case pvDouble: { pvStructure = standardPVField->scalar( stype,allProperties); hasValueAlarm = true; hasDisplayControl = true; PVDoublePtr pvField = pvStructure->getSubField<PVDouble>("value"); pvField->put(1.123e35); break; } case pvString: { pvStructure = standardPVField->scalar( stype,alarmTimeStamp); PVStringPtr pvField = pvStructure->getSubField<PVString>("value"); pvField->put(string("this is a string")); break; } } PVLongPtr seconds = pvStructure->getSubField<PVLong>( string("timeStamp.secondsPastEpoch")); testOk1(seconds.get()!=0); seconds->put(123456789); PVIntPtr nano = pvStructure->getSubField<PVInt>(string("timeStamp.nanoseconds")); testOk1(nano.get()!=0); nano->put(1000000); PVIntPtr severity = pvStructure->getSubField<PVInt>(string("alarm.severity")); testOk1(severity.get()!=0); severity->put(2); PVStringPtr message = pvStructure->getSubField<PVString>(string("alarm.message")); testOk1(message.get()!=0); message->put(string("messageForAlarm")); if(hasDisplayControl) { PVStringPtr desc = pvStructure->getSubField<PVString>( string("display.description")); testOk1(desc.get()!=0); desc->put(string("this is a description")); PVStringPtr format = pvStructure->getSubField<PVString>( string("display.format")); testOk1(format.get()!=0); format->put(string("f10.2")); PVStringPtr units = pvStructure->getSubField<PVString>( string("display.units")); testOk1(units.get()!=0); units->put(string("SomeUnits")); PVDoublePtr limit = pvStructure->getSubField<PVDouble>( string("display.limitLow")); testOk1(limit.get()!=0); limit->put(0.0); limit = pvStructure->getSubField<PVDouble>( string("display.limitHigh")); testOk1(limit.get()!=0); limit->put(10.0); limit = pvStructure->getSubField<PVDouble>( string("control.limitLow")); testOk1(limit.get()!=0); limit->put(1.0); limit = pvStructure->getSubField<PVDouble>( string("control.limitHigh")); testOk1(limit.get()!=0); limit->put(9.0); } if(hasValueAlarm) { PVBooleanPtr pvBoolean = pvStructure->getSubField<PVBoolean>("valueAlarm.active"); pvBoolean->put(true); PVScalarPtr pvtemp = pvStructure->getSubField<PVScalar>("valueAlarm.lowAlarmLimit"); testOk1(pvtemp.get()!=0); convert->fromDouble(pvtemp,1.0); pvtemp = pvStructure->getSubField<PVScalar>("valueAlarm.highAlarmLimit"); testOk1(pvtemp.get()!=0); convert->fromDouble(pvtemp,9.0); severity = pvStructure->getSubField<PVInt>( string("valueAlarm.lowAlarmSeverity")); testOk1(severity.get()!=0); severity->put(2); severity = pvStructure->getSubField<PVInt>( string("valueAlarm.highAlarmSeverity")); testOk1(severity.get()!=0); severity->put(2); PVBooleanPtr active = pvStructure->getSubField<PVBoolean>( string("valueAlarm.active")); testOk1(active.get()!=0); active->put(true); } if(hasBooleanAlarm) { PVBooleanPtr pvBoolean = pvStructure->getSubField<PVBoolean>("valueAlarm.active"); pvBoolean->put(true); severity = pvStructure->getSubField<PVInt>( string("valueAlarm.falseSeverity")); testOk1(severity.get()!=0); severity->put(0); severity = pvStructure->getSubField<PVInt>( string("valueAlarm.trueSeverity")); testOk1(severity.get()!=0); severity->put(2); severity = pvStructure->getSubField<PVInt>( string("valueAlarm.changeStateSeverity")); testOk1(severity.get()!=0); severity->put(1); } }