Skip to content

Commit ea6065e

Browse files
committed
tango command and attribute implement the PVFactory interface respectively.
1 parent 8acd9d2 commit ea6065e

File tree

11 files changed

+257
-167
lines changed

11 files changed

+257
-167
lines changed

core/pv/doc/index.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,5 +161,6 @@ Currently, all types of scalars are supported, but SPECTRUM and IMAGE are not ye
161161

162162
Examples ::
163163

164-
tango://att:/devicename/attributename
165-
tango://com:/devicename/comandname
164+
tga://device/attribute
165+
tgc://device/command
166+

core/pv/pom.xml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,23 @@
7171
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
7272
<version>1.2.2</version>
7373
</dependency>
74-
7574
<dependency>
7675
<groupId>org.tango-controls</groupId>
77-
<artifactId>JTango</artifactId>
76+
<artifactId>JTangoCommons</artifactId>
77+
<version>9.7.0</version>
78+
<scope>compile</scope>
79+
</dependency>
80+
<dependency>
81+
<groupId>org.tango-controls</groupId>
82+
<artifactId>JTangoClientLang</artifactId>
83+
<version>9.6.8</version>
84+
<scope>compile</scope>
85+
</dependency>
86+
<dependency>
87+
<groupId>org.tango-controls</groupId>
88+
<artifactId>JTangoServer</artifactId>
7889
<version>9.6.8</version>
90+
<scope>compile</scope>
7991
</dependency>
8092
</dependencies>
8193
</project>

core/pv/src/main/java/org/phoebus/pv/tango/TangoContext.java renamed to core/pv/src/main/java/org/phoebus/pv/tga/TangoAttrContext.java

Lines changed: 10 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,41 @@
1-
package org.phoebus.pv.tango;
1+
package org.phoebus.pv.tga;
22

33
import fr.esrf.Tango.DevFailed;
44
import fr.esrf.Tango.EventProperties;
55
import fr.esrf.TangoApi.AttributeInfoEx;
66
import fr.esrf.TangoApi.AttributeProxy;
77
import fr.esrf.TangoApi.DeviceAttribute;
8-
import fr.soleil.tango.clientapi.TangoCommand;
98
import org.epics.vtype.*;
109
import org.phoebus.pv.PV;
1110
import org.tango.attribute.AttributeTangoType;
12-
import org.tango.command.CommandTangoType;
1311
import org.tango.server.events.EventType;
1412

1513
import java.util.concurrent.ConcurrentHashMap;
1614
import 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
}

core/pv/src/main/java/org/phoebus/pv/tango/Tango_PV.java renamed to core/pv/src/main/java/org/phoebus/pv/tga/TangoAttr_PV.java

Lines changed: 18 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.phoebus.pv.tango;
1+
package org.phoebus.pv.tga;
22

33
import fr.esrf.Tango.DevFailed;
44
import fr.esrf.TangoApi.CallBack;
@@ -11,96 +11,53 @@
1111
import java.time.Instant;
1212
import java.util.logging.Level;
1313

14-
15-
public class Tango_PV extends PV {
14+
public class TangoAttr_PV extends PV {
1615

1716
private final String baseName;
18-
private String deviceName;
19-
private String variableType;
20-
private String memberVariable;
17+
private String device;
18+
private String attribute;
19+
2120

22-
public Tango_PV(String name, String baseName) throws Exception {
21+
public TangoAttr_PV(String name, String baseName) throws Exception {
2322
super(name);
2423
this.baseName = baseName;
2524
parseRawName(baseName);
26-
if ("att".equals(variableType)){
27-
TangoContext.getInstance().subscribeAttributeEvent(deviceName, memberVariable, baseName,this);
28-
}else if ("com".equals(variableType)){
29-
TangoContext.getInstance().createTangoCommand(deviceName, memberVariable, baseName, this);
30-
}
25+
TangoAttrContext.getInstance().subscribeAttributeEvent(device, attribute, baseName,this);
3126
}
3227

33-
/** Handles these types of tango names:
34-
* <pre>
35-
* att:/device_name/attribute_name --> att && device_name && attribute_name
36-
* com:/device_name/command_name --> com && device_name && command_name
37-
* </pre>
38-
*/
39-
private void parseRawName(final String name) throws Exception {
40-
//String variableType, deviceName, memberVariable;
41-
String[] str= name.split(":/");
42-
43-
if (name.length() <= 4 && str.length > 2)
44-
throw new Exception("Invalid input:" + name);
4528

46-
//Locate tango attribute or command
47-
variableType = str[0];
48-
String prefix = str[1];
49-
50-
int pos = prefix.lastIndexOf('/');
51-
if (pos <= 0)
52-
throw new Exception("Invalid input:" + name);
29+
private void parseRawName(final String name) throws Exception {
30+
int pos = name.lastIndexOf('/');
31+
if (pos <= 0)
32+
throw new Exception("Invalid input:" + name);
5333
//Locate device name
54-
deviceName = prefix.substring(0,pos);
55-
56-
//Locate tango attribute or command name
57-
memberVariable = prefix.substring(pos+1);
34+
device = name.substring(0,pos);
35+
//Locate tango attribute
36+
attribute = name.substring(pos+1);
5837
}
5938

60-
/**
61-
* attributes and commands need to be closed separately.
62-
*/
39+
6340
@Override
6441
protected void close()
6542
{
6643
try
6744
{
68-
if ("att".equals(variableType)){
69-
TangoContext.getInstance().unSubscribeAttributeEvent(baseName);
70-
}else if ("com".equals(variableType)){
71-
TangoContext.getInstance().removeTangoCommand(baseName);
72-
}
73-
45+
TangoAttrContext.getInstance().unSubscribeAttributeEvent(baseName);
7446
}
7547
catch (Exception ex)
7648
{
77-
logger.log(Level.WARNING, "Failed to unsubscribe Tango Attribute/Command from base name " + baseName);
49+
logger.log(Level.WARNING, "Failed to unsubscribe Tango Attribute from base name " + baseName);
7850
ex.printStackTrace();
7951
}
8052
}
8153

82-
8354
@Override
8455
public void write(final Object new_value) throws Exception{
8556
if (new_value == null)
8657
throw new Exception(getName() + " got null");
87-
if ("att".equals(variableType)){
88-
TangoContext.getInstance().writeAttribute(baseName, memberVariable, new_value);
89-
}else if ("com".equals(variableType)){
90-
TangoContext.getInstance().executeTangoCommand(baseName, new_value, this);
91-
}
58+
TangoAttrContext.getInstance().writeAttribute(baseName, attribute, new_value);
9259
}
9360

94-
public void StartCommand(final String commandName) {
95-
notifyListenersOfValue(VType.toVType(commandName));
96-
}
97-
98-
/**
99-
Return the result after the command is executed。
100-
*/
101-
public void endCommand(final VType value) {
102-
notifyListenersOfValue(value);
103-
}
10461

10562
class TangoCallBack extends CallBack {
10663
private final AttributeTangoType type;
@@ -169,4 +126,3 @@ public void push_event(EventData evt) {
169126
}
170127
}
171128
}
172-
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.phoebus.pv.tga;
2+
3+
import org.phoebus.pv.PV;
4+
import org.phoebus.pv.PVFactory;
5+
6+
7+
public class TangoAttr_PVFactory implements PVFactory {
8+
9+
/** PV type implemented by this factory */
10+
final public static String TYPE = "tga";
11+
12+
@Override
13+
public String getType() {
14+
return TYPE;
15+
}
16+
17+
@Override
18+
public PV createPV(String name, String base_name) throws Exception {
19+
return new TangoAttr_PV(name, base_name);
20+
}
21+
22+
23+
}

core/pv/src/main/java/org/phoebus/pv/tango/TangoTypeUtil.java renamed to core/pv/src/main/java/org/phoebus/pv/tga/TangoTypeUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.phoebus.pv.tango;
1+
package org.phoebus.pv.tga;
22

33

44
import org.epics.vtype.*;

0 commit comments

Comments
 (0)