11package org .phoebus .pv .tango ;
22
3+ import java .time .Instant ;
34import java .util .HashMap ;
45import java .util .Map ;
56
910import org .epics .vtype .EnumDisplay ;
1011import org .epics .vtype .Time ;
1112import org .epics .vtype .VDouble ;
13+ import org .epics .vtype .VEnum ;
1214import org .epics .vtype .VString ;
1315import org .epics .vtype .VType ;
1416import org .phoebus .pv .PV ;
3537public class TangoPV extends PV {
3638
3739 private static enum MetaData {
38- DESC , LABEL , WRITE , EGU , HOPR , HIHI , HIGH , LOPR , LOW , LOLO
40+ DESC , LABEL , WRITE , EGU , HOPR , HIHI , HIGH , LOPR , LOW , LOLO , STAT
3941 };
4042
4143 private static final String DOT = "." ;
@@ -58,16 +60,23 @@ private static enum MetaData {
5860
5961 public TangoPV (String name , String baseName ) {
6062 super (name );
61- // First remove .DESC field
62- String fullDeviceName = baseName ;
63- // Test if it is a metadata
64- metaData = getMetadata (fullDeviceName );
65- if (metaData != null ) {
66- fullDeviceName = fullDeviceName .replace (DOT + metaData .toString (), "" );
63+ if (TangoPreferences .getInstance ().isTangoDbEnable ()) {
64+ // First remove .DESC field
65+ String fullDeviceName = baseName ;
66+ // Test if it is a metadata
67+ metaData = getMetadata (fullDeviceName );
68+ if (metaData != null ) {
69+ fullDeviceName = fullDeviceName .replace (DOT + metaData .toString (), "" );
70+ }
71+ device = TangoDeviceHelper .getDeviceName (fullDeviceName );
72+ entityName = TangoDeviceHelper .getEntityName (fullDeviceName );
73+
74+ initTangoEntity ();
75+ } else {
76+ // No attribute info found
77+ VType initValue = VString .of ("--" , Alarm .disconnected (), Time .now ());
78+ notifyListenersOfValue (initValue );
6779 }
68- device = TangoDeviceHelper .getDeviceName (fullDeviceName );
69- entityName = TangoDeviceHelper .getEntityName (fullDeviceName );
70- initTangoEntity ();
7180 }
7281
7382 private MetaData getMetadata (String fullDeviceName ) {
@@ -85,7 +94,7 @@ private MetaData getMetadata(String fullDeviceName) {
8594 }
8695
8796 private boolean isMetaData () {
88- return metaData != null && metaData != MetaData .WRITE ;
97+ return metaData != null && metaData != MetaData .WRITE && metaData != MetaData . STAT ;
8998 }
9099
91100 private void initTangoEntity () {
@@ -110,9 +119,19 @@ private void initTangoEntity() {
110119 description = attributeInfo .toString ();
111120 }
112121 attributeInfoEx = TangoAttributeHelper .getAttributeInfoEx (device , entityName );
113- display = TangoPVUtil .buildDisplayFromAttributeInfo (attributeInfo , attributeInfoEx ,
114- description );
115- enumDisplay = TangoPVUtil .buildEnumDisplayFromAttributeInfo (attributeInfoEx , display );
122+ if (metaData != null && metaData == MetaData .STAT ) {
123+ enumDisplay = TangoPVUtil .getAttributeQualityEnumDisplay (attributeInfo );
124+ display = ((AdvancedEnumDisplay ) enumDisplay ).getDisplay ();
125+
126+ } else if (entityName .equalsIgnoreCase ("State" )) {
127+ // Build State enumeration
128+ enumDisplay = TangoPVUtil .getDevStateEnumDisplay (device );
129+ display = ((AdvancedEnumDisplay ) enumDisplay ).getDisplay ();
130+ } else {
131+ display = TangoPVUtil .buildDisplayFromAttributeInfo (attributeInfo , attributeInfoEx ,
132+ description );
133+ enumDisplay = TangoPVUtil .buildEnumDisplayFromAttributeInfo (attributeInfoEx , display );
134+ }
116135 // It is not a description, read attribute value
117136 if (!isMetaData ()) {
118137 initValue = readValue ();
@@ -335,22 +354,30 @@ private VType readValue() {
335354 DeviceAttribute deviceAttribute = TangoAttributeHelper .getDeviceAttribute (deviceProxy , entityName );
336355 int type = deviceAttribute .getType ();
337356 AttrDataFormat dataFormat = deviceAttribute .getDataFormat ();
338- Object result = null ;
339- if (metaData != null && metaData == MetaData .WRITE ) {
340- result = InsertExtractUtils .extractWrite (deviceAttribute , attributeInfo .writable , dataFormat );
341- } else {
342- result = InsertExtractUtils .extractRead (deviceAttribute , dataFormat );
343- }
344357 Alarm alarm = TangoPVUtil .buildAlarmFromAttribute (deviceAttribute );
345358 long time = deviceAttribute .getTime ();
346- boolean isArray = dataFormat != null
347- && (dataFormat == AttrDataFormat .SPECTRUM || dataFormat == AttrDataFormat .IMAGE );
348- int [] sizes = null ;
349- if (dataFormat == AttrDataFormat .IMAGE ) {
350- sizes = new int [] { deviceAttribute .getDimX (), deviceAttribute .getDimY () };
359+ if (metaData != null && metaData == MetaData .STAT ) {
360+ // Read Quality of attribute
361+ int attributeQuality = TangoAttributeHelper .getAttributeQuality (deviceAttribute );
362+ Time t = Time .of (Instant .ofEpochMilli (time ));
363+ rValue = VEnum .of (attributeQuality , enumDisplay , alarm , t );
364+ } else {
365+ Object result = null ;
366+ if (metaData != null && metaData == MetaData .WRITE ) {
367+ result = InsertExtractUtils .extractWrite (deviceAttribute , attributeInfo .writable , dataFormat );
368+ } else {
369+ result = InsertExtractUtils .extractRead (deviceAttribute , dataFormat );
370+ }
371+
372+ boolean isArray = dataFormat != null
373+ && (dataFormat == AttrDataFormat .SPECTRUM || dataFormat == AttrDataFormat .IMAGE );
374+ int [] sizes = null ;
375+ if (dataFormat == AttrDataFormat .IMAGE ) {
376+ sizes = new int [] { deviceAttribute .getDimX (), deviceAttribute .getDimY () };
377+ }
378+ rValue = TangoPVUtil .convertResultToVtype (isArray , sizes , type , result , alarm , time , display ,
379+ enumDisplay );
351380 }
352- rValue = TangoPVUtil .convertResultToVtype (isArray , sizes , type , result , alarm , time , display ,
353- enumDisplay );
354381 } catch (Exception e ) {
355382 String errorMessage = TangoExceptionHelper .getErrorMessage (e );
356383 rValue = VString .of (errorMessage , Alarm .disconnected (), Time .now ());
@@ -405,7 +432,7 @@ public void write(Object new_value) throws Exception {
405432 @ Override
406433 public boolean isReadonly () {
407434 boolean isRO = true ;
408- if (!isMetaData ()) {
435+ if (!isMetaData () && metaData != MetaData . STAT ) {
409436 if (attributeInfo != null ) {
410437 AttrWriteType writable = attributeInfo .writable ;
411438 isRO = writable == AttrWriteType .READ ;
@@ -429,5 +456,6 @@ protected void close() {
429456 cb = null ;
430457 }
431458 TangoPVFactory .releasePV (this );
459+ super .close ();
432460 }
433461}
0 commit comments