Skip to content

Commit c6d122a

Browse files
committed
Merge remote-tracking branch 'origin/master' into Ticket2593_ips
2 parents 8e65d84 + 1ef90b3 commit c6d122a

File tree

28 files changed

+5144
-4574
lines changed

28 files changed

+5144
-4574
lines changed
Lines changed: 76 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package uk.ac.stfc.isis.ibex.configserver.configuration;
22

33

4+
import uk.ac.stfc.isis.ibex.configserver.AlarmState;
45
import uk.ac.stfc.isis.ibex.epics.observing.BaseObserver;
56
import uk.ac.stfc.isis.ibex.epics.observing.ForwardingObservable;
67
import uk.ac.stfc.isis.ibex.epics.switching.ObservableFactory;
78
import uk.ac.stfc.isis.ibex.epics.switching.OnInstrumentSwitch;
89
import uk.ac.stfc.isis.ibex.instrument.InstrumentUtils;
9-
import uk.ac.stfc.isis.ibex.instrument.channels.BooleanChannel;
10+
import uk.ac.stfc.isis.ibex.instrument.channels.DefaultChannel;
11+
import uk.ac.stfc.isis.ibex.instrument.channels.EnumChannel;
12+
import uk.ac.stfc.isis.ibex.logger.IsisLog;
1013
import uk.ac.stfc.isis.ibex.model.ModelObject;
1114

1215
/**
@@ -19,79 +22,115 @@ public class BannerItem extends ModelObject {
1922

2023
private String name;
2124
private String pv;
22-
private String type;
23-
private BannerItemState true_state;
24-
private BannerItemState false_state;
25-
private BannerItemState unknown_state;
26-
private BannerItemState currentState;
25+
private Boolean local = true;
26+
27+
private String currentValue = null;
28+
private AlarmState currentAlarmState = AlarmState.UNDEFINED;
2729

28-
private ObservableFactory obsFactory = null;
29-
private ForwardingObservable<Boolean> pvObservable;
30+
private static final ObservableFactory OBSERVABLE_FACTORY = new ObservableFactory(OnInstrumentSwitch.CLOSE);
31+
private ForwardingObservable<String> pvObservable;
32+
private ForwardingObservable<AlarmState> alarmObservable;
3033

3134
/**
3235
* Creates an observable for the PV holding the current state of this banner
3336
* item.
3437
*/
3538
public void createPVObservable() {
36-
obsFactory = new ObservableFactory(OnInstrumentSwitch.CLOSE);
37-
38-
pvObservable = obsFactory.getSwitchableObservable(new BooleanChannel(),
39-
InstrumentUtils.addPrefix(this.pv));
40-
pvObservable.addObserver(stateAdapter);
39+
String pv = this.pv;
40+
if (local) {
41+
pv = InstrumentUtils.addPrefix(pv);
42+
}
43+
44+
pvObservable = OBSERVABLE_FACTORY.getSwitchableObservable(new DefaultChannel(), pv);
45+
alarmObservable = OBSERVABLE_FACTORY.getSwitchableObservable(new EnumChannel<>(AlarmState.class), pv + ".SEVR");
46+
pvObservable.addObserver(valueAdapter);
47+
alarmObservable.addObserver(alarmAdapter);
4148
}
4249

43-
private final BaseObserver<Boolean> stateAdapter = new BaseObserver<Boolean>() {
50+
private final BaseObserver<String> valueAdapter = new BaseObserver<String>() {
51+
52+
@Override
53+
public void onValue(String value) {
54+
setCurrentValue(value);
55+
}
56+
57+
@Override
58+
public void onError(Exception e) {
59+
setCurrentValue(null);
60+
IsisLog.getLogger(getClass()).error("Exception in banner item state adapter: " + e.getMessage());
61+
}
62+
63+
@Override
64+
public void onConnectionStatus(boolean isConnected) {
65+
if (!isConnected) {
66+
setCurrentValue(null);
67+
}
68+
}
69+
};
70+
71+
private final BaseObserver<AlarmState> alarmAdapter = new BaseObserver<AlarmState>() {
4472

4573
@Override
46-
public void onValue(Boolean value) {
47-
setCurrentState(value);
74+
public void onValue(AlarmState alarm) {
75+
setCurrentAlarm(alarm);
4876
}
4977

5078
@Override
5179
public void onError(Exception e) {
52-
setCurrentState(null);
80+
setCurrentAlarm(AlarmState.INVALID);
81+
IsisLog.getLogger(getClass()).error("Exception in banner item state adapter: " + e.getMessage());
5382
}
5483

5584
@Override
5685
public void onConnectionStatus(boolean isConnected) {
5786
if (!isConnected) {
58-
setCurrentState(null);
87+
setCurrentAlarm(AlarmState.INVALID);
5988
}
6089
}
6190
};
6291

92+
/**
93+
* Returns the display name of this banner item.
94+
* @return the display name of this banner item.
95+
*/
6396
public String name() {
64-
return this.name;
97+
return name;
98+
}
99+
100+
/**
101+
* Returns the current value of this banner item.
102+
* @return the current value of this banner item.
103+
*/
104+
public String value() {
105+
return currentValue;
106+
}
107+
108+
/**
109+
* Returns the alarm status of this banner item.
110+
* @return the alarm status of this banner item.
111+
*/
112+
public AlarmState alarm() {
113+
return currentAlarmState;
65114
}
66115

67116
/**
68-
* Returns the display specification for the banner item in its current
69-
* state.
117+
* Sets the current state of the property based on the PV value and fires a
118+
* property change for listeners.
70119
*
71-
* @return the current state
120+
* @param value the state value of the property.
72121
*/
73-
public BannerItemState getCurrentState() {
74-
return currentState;
122+
public synchronized void setCurrentValue(String value) {
123+
firePropertyChange("value", this.currentValue, this.currentValue = value);
75124
}
76-
125+
77126
/**
78127
* Sets the current state of the property based on the PV value and fires a
79128
* property change for listeners.
80129
*
81130
* @param value the state value of the property.
82131
*/
83-
public void setCurrentState(Boolean value) {
84-
BannerItemState newState;
85-
if (value == null) {
86-
newState = this.unknown_state;
87-
} else {
88-
if (value) {
89-
newState = this.true_state;
90-
} else {
91-
newState = this.false_state;
92-
}
93-
}
94-
firePropertyChange("currentState", this.currentState, this.currentState = newState);
132+
public synchronized void setCurrentAlarm(AlarmState alarm) {
133+
firePropertyChange("alarm", this.currentAlarmState, this.currentAlarmState = alarm);
95134
}
96135

97136
}

base/uk.ac.stfc.isis.ibex.configserver/src/uk/ac/stfc/isis/ibex/configserver/configuration/BannerItemState.java

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)