1- package org .phoebus .pv .tango ;
1+ package org .phoebus .pv .tga ;
22
33import fr .esrf .Tango .DevFailed ;
44import fr .esrf .Tango .EventProperties ;
55import fr .esrf .TangoApi .AttributeInfoEx ;
66import fr .esrf .TangoApi .AttributeProxy ;
77import fr .esrf .TangoApi .DeviceAttribute ;
8- import fr .soleil .tango .clientapi .TangoCommand ;
98import org .epics .vtype .*;
109import org .phoebus .pv .PV ;
1110import org .tango .attribute .AttributeTangoType ;
12- import org .tango .command .CommandTangoType ;
1311import org .tango .server .events .EventType ;
1412
1513import java .util .concurrent .ConcurrentHashMap ;
1614import java .util .logging .Level ;
1715
1816;
1917
20- public class TangoContext {
21- private static TangoContext instance ;
18+ public class TangoAttrContext {
19+ private static TangoAttrContext instance ;
2220 private final ConcurrentHashMap <String , AttributeProxy > attributeProxys ;
2321 private final ConcurrentHashMap <String , Integer > events ;
2422 private final ConcurrentHashMap <String , AttributeTangoType > types ;
25- private final ConcurrentHashMap <String , TangoCommand > commands ;
2623
2724
28- private TangoContext () {
25+
26+ private TangoAttrContext () {
2927 events = new ConcurrentHashMap <>();
3028 attributeProxys = new ConcurrentHashMap <>();
3129 types = new ConcurrentHashMap <>();
32- commands = new ConcurrentHashMap <>();
3330 }
3431
35- public static synchronized TangoContext getInstance () throws Exception {
32+ public static synchronized TangoAttrContext getInstance () throws Exception {
3633 if (instance == null )
37- instance = new TangoContext ();
34+ instance = new TangoAttrContext ();
3835 return instance ;
3936 }
4037
41- public void subscribeAttributeEvent (String deviceName , String attributeName , String baseName , Tango_PV pv ) throws DevFailed {
38+ public void subscribeAttributeEvent (String deviceName , String attributeName , String baseName , TangoAttr_PV pv ) throws DevFailed {
4239 String name = deviceName +"/" + attributeName ;
4340 AttributeProxy attributeProxy ;
4441 if (attributeProxys .get (baseName ) == null ) {
@@ -48,11 +45,10 @@ public void subscribeAttributeEvent(String deviceName, String attributeName, Str
4845 }else {
4946 //nothing to do
5047 }
51- }
5248
53- private void subscribeAttributeEvent (String baseName , AttributeProxy attributeProxy , Tango_PV pv ) throws DevFailed {
54- System .out .println ("subscribe tango attribute : " + baseName );
49+ }
5550
51+ private void subscribeAttributeEvent (String baseName , AttributeProxy attributeProxy , TangoAttr_PV pv ) throws DevFailed {
5652 AttributeInfoEx attribute_info_ex ;
5753 try {
5854 attribute_info_ex = attributeProxy .get_info_ex ();
@@ -111,7 +107,6 @@ public void writeAttribute(String baseName, String attributeName, Object new_val
111107 PV .logger .log (Level .WARNING , "Could not find type of attribute :" + baseName );
112108 throw new Exception ("Tango attribute write failed: attribute type not found." );
113109 }
114- System .out .println ("Tango attribute write: attribute:" + attributeName + " value:" + new_value );
115110 VType vType ;
116111 String value ;
117112 switch (type ){
@@ -164,83 +159,4 @@ public void writeAttribute(String baseName, String attributeName, Object new_val
164159
165160 }
166161
167-
168- public void createTangoCommand (String deviceName , String commandName , String baseName , Tango_PV pv ) throws DevFailed {
169- TangoCommand tangoCommand = commands .get (baseName );
170- if ( tangoCommand == null ){
171- tangoCommand = new TangoCommand (deviceName , commandName );
172- commands .put (baseName , tangoCommand );
173- }
174- pv .StartCommand (tangoCommand .getCommandName ());
175- }
176-
177- public void removeTangoCommand (String baseName ) throws Exception {
178- TangoCommand tangoCommand = commands .get (baseName );
179- if (tangoCommand == null ){
180- PV .logger .log (Level .WARNING , "Could not remove Tango command \" " + baseName
181- + "\" due to no internal record of command" );
182- throw new Exception ("Tango command remove failed: no command record." );
183- }
184- commands .remove (baseName , tangoCommand );
185- }
186-
187- public void executeTangoCommand (String baseName , Object new_value , Tango_PV pv ) throws Exception {
188- TangoCommand tangoCommand = commands .get (baseName );
189- if (tangoCommand == null ){
190- PV .logger .log (Level .WARNING , "Could not find Tango command \" " + baseName
191- + "\" due to no internal record of command" );
192- throw new Exception ("Tango command execute failed: no command record." );
193- }
194-
195- CommandTangoType typeFromTango = CommandTangoType .getTypeFromTango (tangoCommand .getArginType ());
196- Object res ;
197- VType value ;
198- switch (typeFromTango ){
199- case DEVBOOLEAN :
200- res = tangoCommand .execute (Boolean .class , new_value );
201- value = TangoTypeUtil .convert (res , VBoolean .class );
202- pv .endCommand (value );
203- break ;
204- case DEVSHORT :
205- res = tangoCommand .execute (Short .class , new_value );
206- value = TangoTypeUtil .convert (res , VShort .class );
207- pv .endCommand (value );
208- break ;
209- case DEVLONG64 :
210- res = tangoCommand .execute (Long .class , new_value );
211- value = TangoTypeUtil .convert (res , VLong .class );
212- pv .endCommand (value );
213- break ;
214- case DEVFLOAT :
215- res = tangoCommand .execute (Float .class , new_value );
216- value = TangoTypeUtil .convert (res , VFloat .class );
217- pv .endCommand (value );
218- break ;
219- case DEVDOUBLE :
220- res = tangoCommand .execute (Double .class ,new_value );
221- value = TangoTypeUtil .convert (res , VDouble .class );
222- pv .endCommand (value );
223- break ;
224- case DEVSTRING :
225- res = tangoCommand .execute (String .class ,new_value );
226- value = TangoTypeUtil .convert (res , VString .class );
227- pv .endCommand (value );
228- break ;
229- case DEVLONG :
230- res = tangoCommand .execute (Integer .class ,new_value );
231- value = TangoTypeUtil .convert (res , VInt .class );
232- pv .endCommand (value );
233- break ;
234- case DEVUCHAR :
235- res = tangoCommand .execute (Byte .class ,new_value );
236- value = TangoTypeUtil .convert (res , VByte .class );
237- pv .endCommand (value );
238- break ;
239- default :
240- throw new IllegalArgumentException ("Value " + new_value + " cannot be converted." );
241- }
242-
243-
244-
245- }
246162}
0 commit comments