Skip to content

Commit

Permalink
add access to property of SICS controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
nxi committed May 29, 2024
1 parent 75f6bee commit 16e2ccb
Show file tree
Hide file tree
Showing 13 changed files with 284 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ public interface Property {
*/
List<String> getValue();

/**
* Set a String value to the first attribute of the property.
* <!-- begin-user-doc -->
* <p>
* Only change the first item of the list.
* </p>
* <!-- end-user-doc -->
* @model unique="false" dataType="org.eclipse.emf.ecore.xml.type.String"
* extendedMetaData="kind='element' name='value'"
* @generated
*/
void setValue(String stringValue);

/**
* Returns the value of the '<em><b>Id</b></em>' attribute.
* <!-- begin-user-doc -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ public List<String> getValue() {
return value;
}

public void setValue(String stringValue) {
if (value == null) {
value = new EDataTypeEList<String>(String.class, this, HipadabaPackageImpl.PROPERTY__VALUE);
}
value.set(0, stringValue);
}

/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ private void execute(IBatchBuffer buffer) throws IOException {

// Modified by nxi. Change the uploading strategy. Save the script in the mounted folder instead.
// // Ready to upload
// asyncSend("exe clear", null, ISicsProxy.CHANNEL_RAW_BATCH);
// asyncSend("exe clearupload", null, ISicsProxy.CHANNEL_RAW_BATCH);
asyncSend("exe clear", null, ISicsProxy.CHANNEL_RAW_BATCH);
asyncSend("exe clearupload", null, ISicsProxy.CHANNEL_RAW_BATCH);
// asyncSend("exe upload", null, ISicsProxy.CHANNEL_RAW_BATCH);
// // Upload
// BufferedReader reader = new BufferedReader(new StringReader(buffer.getContent()));
Expand Down Expand Up @@ -369,6 +369,10 @@ private void execute(IBatchBuffer buffer) throws IOException {

// Enqueue (due to the delay in general channel, wait until it is ready)
final boolean[] enqueued = new boolean[] { false };
try {
Thread.sleep(500);
} catch (InterruptedException e1) {
}
asyncSend("exe enqueue {" + filename + "}", new SicsCallbackAdapter() {
public void receiveReply(ISicsReplyData data) {
enqueued[0] = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.slf4j.LoggerFactory;

import ch.psi.sics.hipadaba.Component;
import ch.psi.sics.hipadaba.Property;

public abstract class ComponentController implements IComponentController {

Expand Down Expand Up @@ -106,6 +107,19 @@ public String getDeviceId() {
return deviceId;
}

@Override
public List<String> getPropertyValue(String propId) {
List<Property> propList = getComponent().getProperty();
if (propList != null) {
for (Property prop : propList) {
if (propId.equals(prop.getId())) {
return prop.getValue();
}
}
}
return new ArrayList<String>();
}

public ControllerStatus getStatus() {
return status;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
package org.gumtree.gumnix.sics.control.controllers;


import java.util.List;

import org.gumtree.gumnix.sics.control.ControllerStatus;
import org.gumtree.gumnix.sics.control.events.IComponentControllerListener;

Expand Down Expand Up @@ -99,5 +101,13 @@ public interface IComponentController {
* @param listener
*/
public void removeComponentListener(IComponentControllerListener listener);

/**
* Return the value of a specific property ID. Return null if not found.
*
* @param propId in List of String type
* @return
*/
public List<String> getPropertyValue(String propId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public class SicsUtils {

private static List<String> drivableIdCache;

private static final String PROP_NXALIAS = "nxalias";

private static final String PREFIX_SAMPLE = "sample";

public static List<String> getSicsDrivableIdList() {
if (drivableIdCache == null) {
// SICS proxy is not yet ready
Expand Down Expand Up @@ -423,4 +427,22 @@ private SicsUtils() {
super();
}

public static IComponentController getNicknameController(IComponentController seItem) {
List<String> prop = seItem.getPropertyValue(PROP_NXALIAS);
if (prop.size() > 0) {
String alias = prop.get(0);
String[] path = alias.split("_");
String nickPath = null;
if (!PREFIX_SAMPLE.equals(path[0])) {
nickPath = "/" + PREFIX_SAMPLE;
}
for (int i = 0; i < path.length - 1; i++) {
nickPath += "/" + path[i];
}
nickPath += "/nick";
return SicsCore.getSicsController().findComponentController(nickPath);
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.net.URI;
import java.text.Normalizer.Form;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -86,6 +87,7 @@ protected void handleRender() {
label = getWidgetFactory().createLabel(this,
deviceContext.label + ": ");
label.setFont(UIResources.getDefaultFont(SWT.BOLD));
deviceContext.widget = label;
// Part 3: Value
label = createDeviceLabel(this, deviceContext.path, "--",
SWT.RIGHT, deviceContext.converter, deviceContext.showSoftLimits);
Expand Down Expand Up @@ -269,6 +271,10 @@ public void run() throws Exception {
});
}

protected void sortDevices() {
Collections.sort(deviceContexts);
}

@Override
protected void disposeWidget() {
if (deviceContexts != null) {
Expand Down Expand Up @@ -381,14 +387,23 @@ public void setDelayEventExecutor(IDelayEventExecutor delayEventExecutor) {
* Utilities
*************************************************************************/

private class DeviceContext {
private class DeviceContext implements Comparable<DeviceContext> {
String path;
Image icon;
String label;
String unit;
Label widget;
boolean isSeparator;
LabelConverter converter;
boolean showSoftLimits;

@Override
public int compareTo(DeviceContext arg0) {
if (label == null) {
return -1;
}
return label.compareTo(arg0.label);
}
}

private class LabelContext {
Expand Down Expand Up @@ -683,4 +698,21 @@ protected void checkSicsConnection() {
} catch (InterruptedException e) {
}
}

public void setDeviceTitle(String path, String newTitle) {
for (final DeviceContext device : deviceContexts) {
if (device.path.equals(path)) {
device.label = newTitle;
SafeUIRunner.asyncExec(new SafeRunnable() {
@Override
public void run() throws Exception {
if (device.widget != null && !device.widget.isDisposed()) {
device.widget.setText(device.label);
device.widget.pack();
}
}
});
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@

import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.gumtree.gumnix.sics.control.ControllerStatus;
import org.gumtree.gumnix.sics.control.controllers.IComponentController;
import org.gumtree.gumnix.sics.control.controllers.IComponentData;
import org.gumtree.gumnix.sics.control.controllers.IDynamicController;
import org.gumtree.gumnix.sics.control.events.DynamicControllerListenerAdapter;
import org.gumtree.gumnix.sics.control.events.IComponentControllerListener;
import org.gumtree.gumnix.sics.core.SicsCore;
import org.gumtree.gumnix.sics.core.SicsUtils;

public class EnvironmentControlWidget extends DeviceStatusWidget {

Expand All @@ -35,9 +41,24 @@ public int compare(IComponentController o1,
return o1.getId().compareTo(o2.getId());
}
});
for (IComponentController item : itemList) {
for (final IComponentController item : itemList) {
String id = item.getId();
String label = id;
String nickname = null;
List<String> nickList = item.getPropertyValue("nick");
if (nickList != null && nickList.size() > 0) {
nickname = nickList.get(0);
}
String aliasName = null;
List<String> aliasList = item.getPropertyValue("nxalias");
if (aliasList != null && aliasList.size() > 0) {
aliasName = aliasList.get(0);
}
String units = null;
List<String> unitsList = item.getPropertyValue("units");
if (unitsList != null && unitsList.size() > 0) {
units = unitsList.get(0);
}
// String units = "";
// if (id.startsWith("T")) {
// units = "K";
Expand All @@ -50,18 +71,43 @@ public int compare(IComponentController o1,
// } else if (id.startsWith("I")) {
// units = "A";
// }
if (label.contains("SP")) {
label = id.replace("SP", " SetPoint");
} else if (label.contains("S")) {
label = id.replace("S", " Sensor");
if (aliasName != null) {
label = aliasName;
} else {
if (label.contains("SP")) {
label = id.replace("SP", " SetPoint");
} else if (label.contains("S")) {
label = id.replace("S", " Sensor");
}
}
String fullname = null;
if (nickname != null) {
fullname = label + "(" + nickname + ")";
} else {
fullname = label;
}
try {
addDevice(item.getPath(), label, null, null);
// addDevice(item.getPath(), label, null, null);
addDevice(item.getPath(), fullname, null, units);
} catch (Exception e) {
// TODO: handle exception
}

final String labelPrefix = label;
IComponentController nickController = SicsUtils.getNicknameController(item);
if (nickController != null) {
if (nickController instanceof IDynamicController) {
((IDynamicController) nickController).addComponentListener(new DynamicControllerListenerAdapter() {

private String prefix = labelPrefix;
@Override
public void valueChanged(IDynamicController controller, IComponentData newValue) {
String newTitle = prefix + "(" + newValue.getStringData() + ")";
setDeviceTitle(item.getPath(), newTitle);
}
});
}
}
}
sortDevices();
Display.getDefault().asyncExec(new Runnable() {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

package org.gumtree.sics.control;

import java.util.List;

import org.gumtree.core.object.IDisposable;
import org.gumtree.sics.io.ISicsProxy;

Expand Down Expand Up @@ -76,4 +78,8 @@ public interface ISicsController extends IDisposable {

public ISicsController findChildByDeviceId(String deviceId);

public List<String> getPropertyValue(String propId);

public void setPropertyValue(String propId, String newValue);

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.gumtree.util.string.StringUtils;

import ch.psi.sics.hipadaba.Component;
import ch.psi.sics.hipadaba.Property;

import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
Expand Down Expand Up @@ -66,6 +67,31 @@ public void setDeviceId(String deviceId) {
this.deviceId = deviceId;
}

@Override
public List<String> getPropertyValue(String propId) {
List<Property> propList = componentModel.getProperty();
if (propList != null) {
for (Property prop : propList) {
if (propId.equals(prop.getId())) {
return prop.getValue();
}
}
}
return null;
}

@Override
public void setPropertyValue(String propId, String newValue) {
List<Property> propList = componentModel.getProperty();
if (propList != null) {
for (Property prop : propList) {
if (propId.equals(prop.getId())) {
prop.setValue(newValue);
}
}
}
}

@Override
public String getPath() {
if (path == null) {
Expand Down
Loading

0 comments on commit 16e2ccb

Please sign in to comment.