Skip to content
Snippets Groups Projects
Commit cc145047 authored by Katy Saintin's avatar Katy Saintin
Browse files

Add a free textarea for EPICS DataSource to read a PV

parent ab2a7b55
No related branches found
No related merge requests found
Showing
with 111 additions and 26 deletions
...@@ -12,6 +12,7 @@ import heps.epics.ca.client.ProcessVariableManager; ...@@ -12,6 +12,7 @@ import heps.epics.ca.client.ProcessVariableManager;
import heps.epics.ca.interfaces.DataType; import heps.epics.ca.interfaces.DataType;
import heps.epics.ca.interfaces.ICafeProcessVariableListener; import heps.epics.ca.interfaces.ICafeProcessVariableListener;
import heps.epics.ca.interfaces.IRecord; import heps.epics.ca.interfaces.IRecord;
import heps.epics.ca.interfaces.ISimpleRecord;
import heps.epics.ca.interfaces.IocEvent; import heps.epics.ca.interfaces.IocEvent;
public class EpicsDataSourceProducer implements IDataSourceProducer, ICafeProcessVariableListener { public class EpicsDataSourceProducer implements IDataSourceProducer, ICafeProcessVariableListener {
...@@ -28,7 +29,7 @@ public class EpicsDataSourceProducer implements IDataSourceProducer, ICafeProces ...@@ -28,7 +29,7 @@ public class EpicsDataSourceProducer implements IDataSourceProducer, ICafeProces
if (dataSource == null) { if (dataSource == null) {
IKey parseKey = parseKey(arg0); IKey parseKey = parseKey(arg0);
if (parseKey != null) { if (parseKey != null) {
IRecord record = EpicsKey.getRecord(parseKey); ISimpleRecord record = EpicsKey.getRecord(parseKey);
if (record.isBoolean()) { if (record.isBoolean()) {
dataSource = new EpicsBooleanDataSource(parseKey); dataSource = new EpicsBooleanDataSource(parseKey);
} else { } else {
...@@ -123,8 +124,8 @@ public class EpicsDataSourceProducer implements IDataSourceProducer, ICafeProces ...@@ -123,8 +124,8 @@ public class EpicsDataSourceProducer implements IDataSourceProducer, ICafeProces
@Override @Override
public boolean isSourceSettable(IKey key) { public boolean isSourceSettable(IKey key) {
boolean settable = false; boolean settable = false;
IRecord record = EpicsKey.getRecord(key); ISimpleRecord record = EpicsKey.getRecord(key);
settable = record != null && (!record.isReadOnly() || record.getLinkedRecord() != null); settable = record != null && (!record.isReadOnly() || (record instanceof IRecord && ((IRecord)record).getLinkedRecord() != null));
return settable; return settable;
} }
......
...@@ -9,6 +9,7 @@ import fr.cea.irfu.interfaces.IrfuKey; ...@@ -9,6 +9,7 @@ import fr.cea.irfu.interfaces.IrfuKey;
import fr.soleil.data.service.IKey; import fr.soleil.data.service.IKey;
import heps.epics.ca.interfaces.DataType; import heps.epics.ca.interfaces.DataType;
import heps.epics.ca.interfaces.IRecord; import heps.epics.ca.interfaces.IRecord;
import heps.epics.ca.interfaces.ISimpleRecord;
public class EpicsKey extends IrfuKey { public class EpicsKey extends IrfuKey {
...@@ -45,7 +46,7 @@ public class EpicsKey extends IrfuKey { ...@@ -45,7 +46,7 @@ public class EpicsKey extends IrfuKey {
return aparameterList; return aparameterList;
} }
public static void createPvListForEpicsFile(final IKey deviceKey ,Map<String, IRecord> recordMap) { public static void createPvListForEpicsFile(final IKey deviceKey ,Map<String, ? extends ISimpleRecord> recordMap) {
if (recordMap != null) { if (recordMap != null) {
if (deviceKey.containProperty(NAME_PROP)) { if (deviceKey.containProperty(NAME_PROP)) {
Object name = deviceKey.getPropertyValue(NAME_PROP); Object name = deviceKey.getPropertyValue(NAME_PROP);
...@@ -59,16 +60,18 @@ public class EpicsKey extends IrfuKey { ...@@ -59,16 +60,18 @@ public class EpicsKey extends IrfuKey {
IKey writeKey = null; IKey writeKey = null;
// Suppression des records ao ou bo qui sont linkes avec des ai bi // Suppression des records ao ou bo qui sont linkes avec des ai bi
Collection<IRecord> paramList = recordMap.values(); Collection<? extends ISimpleRecord> paramList = recordMap.values();
for (IRecord param : paramList) { for (ISimpleRecord param : paramList) {
createParameterKey = createParameterKey(deviceKey,param ); createParameterKey = createParameterKey(deviceKey,param );
if (!aparameterList.contains(createParameterKey)) { if (!aparameterList.contains(createParameterKey)) {
if (param.isReadOnly() || param.getGeneratedRecord() == null) { boolean simpleKey = (param instanceof IRecord && ((IRecord)param).getGeneratedRecord() == null) || !(param instanceof IRecord);
if (param.isReadOnly() || simpleKey) {
aparameterList.add(createParameterKey); aparameterList.add(createParameterKey);
} }
if(param.getLinkedRecord() != null){ if(param instanceof IRecord && ((IRecord)param).getLinkedRecord() != null){
writeKey = createParameterKey(deviceKey,param.getLinkedRecord()); writeKey = createParameterKey(deviceKey,((IRecord)param).getLinkedRecord());
createParameterKey.registerProperty(WRITE_KEY,writeKey); createParameterKey.registerProperty(WRITE_KEY,writeKey);
} }
} }
...@@ -93,10 +96,10 @@ public class EpicsKey extends IrfuKey { ...@@ -93,10 +96,10 @@ public class EpicsKey extends IrfuKey {
return format; return format;
} }
public static IRecord getRecord(final IKey key) { public static ISimpleRecord getRecord(final IKey key) {
IRecord rec = null; ISimpleRecord rec = null;
if (key != null && key.containProperty(RECORD_PROP)) { if (key != null && key.containProperty(RECORD_PROP)) {
rec = (IRecord) key.getPropertyValue(RECORD_PROP); rec = (ISimpleRecord) key.getPropertyValue(RECORD_PROP);
} }
return rec; return rec;
} }
...@@ -132,7 +135,7 @@ public class EpicsKey extends IrfuKey { ...@@ -132,7 +135,7 @@ public class EpicsKey extends IrfuKey {
return settableKey; return settableKey;
} }
private static IKey createParameterKey(final IKey deviceKey, final IRecord record) { private static IKey createParameterKey(final IKey deviceKey, final ISimpleRecord record) {
IKey iKey = new EpicsKey(); IKey iKey = new EpicsKey();
iKey.registerProperty(DEVICE_PROP, deviceKey); iKey.registerProperty(DEVICE_PROP, deviceKey);
iKey.registerProperty(NAME_PROP, record.getName()); iKey.registerProperty(NAME_PROP, record.getName());
......
...@@ -29,7 +29,7 @@ import fr.soleil.data.service.HistoryKey; ...@@ -29,7 +29,7 @@ import fr.soleil.data.service.HistoryKey;
import fr.soleil.data.service.IKey; import fr.soleil.data.service.IKey;
import fr.soleil.data.service.PolledRefreshingStrategy; import fr.soleil.data.service.PolledRefreshingStrategy;
import fr.soleil.data.source.HistoryDataSourceProducer; import fr.soleil.data.source.HistoryDataSourceProducer;
import heps.epics.ca.interfaces.IRecord; import heps.epics.ca.interfaces.ISimpleRecord;
public class EpicsDataSourceBrowser extends AbstractDataSourceProducerBrowser { public class EpicsDataSourceBrowser extends AbstractDataSourceProducerBrowser {
...@@ -96,7 +96,7 @@ public class EpicsDataSourceBrowser extends AbstractDataSourceProducerBrowser { ...@@ -96,7 +96,7 @@ public class EpicsDataSourceBrowser extends AbstractDataSourceProducerBrowser {
@Override @Override
public ITreeNode createNode(IKey key) throws DataBrowserException { public ITreeNode createNode(IKey key) throws DataBrowserException {
ITreeNode sourceNode = null; ITreeNode sourceNode = null;
System.out.println("createNode=" + key); //System.out.println("createNode=" + key);
if (key instanceof EpicsKey) { if (key instanceof EpicsKey) {
List<IKey> parameterListForDevice = EpicsKey.getParameterListForDevice(key); List<IKey> parameterListForDevice = EpicsKey.getParameterListForDevice(key);
if ((parameterListForDevice != null) && (!parameterListForDevice.isEmpty())) { if ((parameterListForDevice != null) && (!parameterListForDevice.isEmpty())) {
...@@ -188,7 +188,7 @@ public class EpicsDataSourceBrowser extends AbstractDataSourceProducerBrowser { ...@@ -188,7 +188,7 @@ public class EpicsDataSourceBrowser extends AbstractDataSourceProducerBrowser {
public DataFormat getFormat(IKey key) { public DataFormat getFormat(IKey key) {
DataFormat format = DataFormat.TEXT; DataFormat format = DataFormat.TEXT;
// TODO gerer les autres formats // TODO gerer les autres formats
IRecord record = EpicsKey.getRecord(key); ISimpleRecord record = EpicsKey.getRecord(key);
if (record == null && key instanceof HistoryKey) { if (record == null && key instanceof HistoryKey) {
IKey history = ((HistoryKey) key).getHistory(); IKey history = ((HistoryKey) key).getHistory();
...@@ -275,7 +275,7 @@ public class EpicsDataSourceBrowser extends AbstractDataSourceProducerBrowser { ...@@ -275,7 +275,7 @@ public class EpicsDataSourceBrowser extends AbstractDataSourceProducerBrowser {
informations.put(LABEL_INFO + "DataType Epics", dataType.toString()); informations.put(LABEL_INFO + "DataType Epics", dataType.toString());
} }
IRecord record = EpicsKey.getRecord(key); ISimpleRecord record = EpicsKey.getRecord(key);
if (record != null) { if (record != null) {
Set<String> fieldKeys = record.getFieldKeys(); Set<String> fieldKeys = record.getFieldKeys();
if (fieldKeys != null && !fieldKeys.isEmpty()) { if (fieldKeys != null && !fieldKeys.isEmpty()) {
......
...@@ -3,20 +3,30 @@ package org.cdma.gui.databrowser.impl.epics; ...@@ -3,20 +3,30 @@ package org.cdma.gui.databrowser.impl.epics;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.ResourceBundle;
import javax.swing.BorderFactory;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField; import javax.swing.JTextField;
import javax.swing.border.TitledBorder;
import org.cdma.gui.databrowser.impl.AbstractFileDataSourceSeeker; import org.cdma.gui.databrowser.impl.AbstractFileDataSourceSeeker;
import org.cdma.gui.databrowser.interfaces.IDataSourceBrowser; import org.cdma.gui.databrowser.interfaces.IDataSourceBrowser;
import org.jdesktop.swingx.prompt.PromptSupport;
import fr.cea.irfu.epics.EpicsKey; import fr.cea.irfu.epics.EpicsKey;
import fr.soleil.data.service.IKey; import fr.soleil.data.service.IKey;
import heps.epics.ca.client.ProcessVariableManager;
import heps.epics.ca.interfaces.IRecord; import heps.epics.ca.interfaces.IRecord;
import heps.epics.ca.interfaces.ISimpleRecord;
import heps.epics.plcparser.interfaces.IPlcIoc; import heps.epics.plcparser.interfaces.IPlcIoc;
import heps.epics.plcparser.model.ioc.PlcParserApi; import heps.epics.plcparser.model.ioc.PlcParserApi;
...@@ -24,7 +34,13 @@ public class EpicsDataSourceSeeker extends AbstractFileDataSourceSeeker { ...@@ -24,7 +34,13 @@ public class EpicsDataSourceSeeker extends AbstractFileDataSourceSeeker {
private static JPanel containPane = null; private static JPanel containPane = null;
private static final String LOCAL_HOST = "127.0.0.1"; private static final String LOCAL_HOST = "127.0.0.1";
private JTextField hostField = null; private JTextField hostField = null;
private JTextArea pvListArea = null;
private static final String DB_EXT = ".db"; private static final String DB_EXT = ".db";
protected static final ResourceBundle MESSAGES = ResourceBundle
.getBundle("org.cdma.gui.databrowser.impl.epics.messages");
private static final Map<String, Map<String, ISimpleRecord>> userSourceMap = new HashMap<String, Map<String, ISimpleRecord>>();
private static final String USER_PVLIST = "UserPvList_";
private static int lastIndex = 0;
public EpicsDataSourceSeeker(IDataSourceBrowser browser) { public EpicsDataSourceSeeker(IDataSourceBrowser browser) {
super(browser); super(browser);
...@@ -39,15 +55,23 @@ public class EpicsDataSourceSeeker extends AbstractFileDataSourceSeeker { ...@@ -39,15 +55,23 @@ public class EpicsDataSourceSeeker extends AbstractFileDataSourceSeeker {
public JComponent getComponent() { public JComponent getComponent() {
if (containPane == null) { if (containPane == null) {
containPane = new JPanel(new BorderLayout()); containPane = new JPanel(new BorderLayout());
pvListArea = new JTextArea();
PromptSupport.setPrompt("ID:DEVICE:PVName", pvListArea);
String pvTitle = MESSAGES.getString("Epics.PvList");
TitledBorder createTitledBorder = BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
pvTitle);
JScrollPane scrollPane = new JScrollPane(pvListArea);
scrollPane.setSize(400, 400);
scrollPane.setMinimumSize(scrollPane.getSize());
scrollPane.setPreferredSize(scrollPane.getSize());
scrollPane.setBorder(createTitledBorder);
JPanel northPanel = new JPanel(); JPanel northPanel = new JPanel();
northPanel.add(new JLabel("Dfinir le host ou adresse IP :")); northPanel.add(new JLabel(MESSAGES.getString("Epics.Host")));
hostField = new JTextField(LOCAL_HOST); hostField = new JTextField(LOCAL_HOST);
// TODO connexion a distance impossible pour le moment IP test 132.166.12.134
// (LIQUE)
hostField.setEditable(true); hostField.setEditable(true);
northPanel.add(hostField); northPanel.add(hostField);
containPane.add(northPanel, BorderLayout.NORTH); containPane.add(northPanel, BorderLayout.NORTH);
containPane.add(scrollPane, BorderLayout.WEST);
containPane.add(getFileChooser(), BorderLayout.CENTER); containPane.add(getFileChooser(), BorderLayout.CENTER);
} }
...@@ -79,20 +103,67 @@ public class EpicsDataSourceSeeker extends AbstractFileDataSourceSeeker { ...@@ -79,20 +103,67 @@ public class EpicsDataSourceSeeker extends AbstractFileDataSourceSeeker {
// Creation des variables decrite dans un fichier // Creation des variables decrite dans un fichier
try { try {
IPlcIoc iocItem = PlcParserApi.loadIocFromEpicsDbFile(parentDirectory, selectedFile.getName(), false,null); IPlcIoc iocItem = PlcParserApi.loadIocFromEpicsDbFile(parentDirectory, selectedFile.getName(), false,
null);
Map<String, IRecord> recordMap = iocItem.getRecordMap(); Map<String, IRecord> recordMap = iocItem.getRecordMap();
EpicsKey.createPvListForEpicsFile(createDeviceKey, recordMap); EpicsKey.createPvListForEpicsFile(createDeviceKey, recordMap);
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
} }
}
String pvList = pvListArea.getText();
if (pvList != null && !pvList.trim().isEmpty()) {
String[] split = pvList.trim().split("\n");
if (split != null && split.length > 0) {
IRecord recordForName = null;
IKey userSourceKey = null;
String userSourceName = null;
Map<String, ISimpleRecord> recordMap = null;
for (String recordname : split) {
if (!foundPV(recordname)) {
recordForName = PlcParserApi.getRecordForName(recordname);
if (recordForName == null) {
ProcessVariableManager.getInstance(host);//Init cacontext with host
ISimpleRecord createRecord = ProcessVariableManager.getInstance().createRecord(recordname);
if(createRecord != null) {
if (userSourceKey == null) {
userSourceName = USER_PVLIST + lastIndex;
lastIndex++;
userSourceKey = EpicsKey.createDeviceKey(host,userSourceName);
deviceList.add(userSourceKey);
userSourceMap.put(userSourceName, new HashMap<>());
}
recordMap = userSourceMap.get(userSourceName);
recordMap.put(recordname, createRecord);
}
}
}
} }
if(userSourceKey != null) {
EpicsKey.createPvListForEpicsFile(userSourceKey, recordMap);
}
}
}
return deviceList; return deviceList;
} }
private static boolean foundPV(final String pv) {
boolean found = false;
Collection<Map<String, ISimpleRecord>> values = userSourceMap.values();
for (Map<String, ISimpleRecord> map : values) {
if (map.containsKey(pv)) {
found = true;
break;
}
}
return found;
}
@Override @Override
public boolean acceptFile(File file) { public boolean acceptFile(File file) {
boolean accept = false; boolean accept = false;
......
...@@ -7,6 +7,7 @@ import java.io.FileReader; ...@@ -7,6 +7,7 @@ import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.ResourceBundle;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JLabel; import javax.swing.JLabel;
...@@ -45,6 +46,7 @@ public class MuscadeDataSourceSeeker extends AbstractFileDataSourceSeeker { ...@@ -45,6 +46,7 @@ public class MuscadeDataSourceSeeker extends AbstractFileDataSourceSeeker {
private static final String CFG_REAL = "REAL"; private static final String CFG_REAL = "REAL";
private static final String CFG_INT = "INT"; private static final String CFG_INT = "INT";
private static final String CFG_BOOL = "BOOL"; private static final String CFG_BOOL = "BOOL";
protected static final ResourceBundle MESSAGES = ResourceBundle.getBundle("org.cdma.gui.databrowser.impl.muscade.messages");
private enum FileType { private enum FileType {
...@@ -65,7 +67,7 @@ public class MuscadeDataSourceSeeker extends AbstractFileDataSourceSeeker { ...@@ -65,7 +67,7 @@ public class MuscadeDataSourceSeeker extends AbstractFileDataSourceSeeker {
if (containPane == null) { if (containPane == null) {
containPane = new JPanel(new BorderLayout()); containPane = new JPanel(new BorderLayout());
JPanel northPanel = new JPanel(); JPanel northPanel = new JPanel();
northPanel.add(new JLabel("D�finir le host ou adresse IP :")); northPanel.add(new JLabel(MESSAGES.getString("Muscade.Host")));
hostField = new JTextField(LOCAL_HOST); hostField = new JTextField(LOCAL_HOST);
// TODO connexion a distance impossible pour le moment IP test 132.166.12.134 // TODO connexion a distance impossible pour le moment IP test 132.166.12.134
// (LIQUE) // (LIQUE)
......
Epics.PvList = Type a list of process variable
Epics.Host = Define a host name or an IP address
Epics.PvList = Saisir une liste de variables process
Epics.Host = D\u00e9finir le host ou une adresse IP
\ No newline at end of file
Muscade.Host = = Define a host name or an IP address
Muscade.Host = D\u00e9finir le host ou une adresse IP
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment