Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/ornl-epics/pvws
Browse files Browse the repository at this point in the history
  • Loading branch information
kasemir committed Aug 27, 2024
2 parents bdeed84 + 5f38341 commit 1abce99
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
22 changes: 16 additions & 6 deletions src/main/java/pvws/ws/Vtype2Json.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class Vtype2Json
* @return JSON text
* @throws Exception on error
*/
public static String toJson(final String name, final VType value, final VType last_value, final boolean last_readonly, final boolean readonly) throws Exception
public static String toJson(final String name, final VType value, final VType last_value, final Boolean last_readonly, final Boolean readonly) throws Exception
{
final ByteArrayOutputStream buf = new ByteArrayOutputStream();
final JsonGenerator g = json_factory.createGenerator(buf);
Expand Down Expand Up @@ -94,7 +94,7 @@ else if (value != null)
// null: Neither 'value' nor 'text'

// Change in read/write access?
if (last_readonly != readonly)
if (last_readonly == null || !last_readonly.equals(readonly))
g.writeBooleanField("readonly", readonly);

final Time time = Time.timeOf(value);
Expand All @@ -113,10 +113,20 @@ else if (value != null)
private static void handleString(final JsonGenerator g, final VString value, final VType last_value) throws Exception
{
final AlarmSeverity severity = value.getAlarm().getSeverity();
if (last_value == null ||
(last_value instanceof VString &&
((VString) last_value).getAlarm().getSeverity() != severity))
g.writeStringField("severity", value.getAlarm().getSeverity().name());
if (last_value == null)
{
// Initially, add complete metadata
g.writeStringField("vtype", VType.typeOf(value).getSimpleName());
// Initial severity
g.writeStringField("severity", severity.name());
}
else
{
// Add severity if it changed
if ((last_value instanceof VString) &&
((VString) last_value).getAlarm().getSeverity() != severity)
g.writeStringField("severity", severity.name());
}

g.writeStringField("text", value.getValue());
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/pvws/ws/WebSocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ public void onError(final Throwable ex)
* @param last_readonly Was the PV read-only?
* @param readonly Is the PV read-only?
*/
public void sendUpdate(final String name, final VType value, final VType last_value, final boolean last_readonly, final boolean readonly)
public void sendUpdate(final String name, final VType value, final VType last_value, final Boolean last_readonly, final Boolean readonly)
{
try
{
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/pvws/ws/WebSocketPV.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class WebSocketPV
subscription_access = new AtomicReference<>();
private volatile boolean subscribed_for_array = false;
private volatile VType last_value = null;
private volatile boolean last_readonly = true;
private volatile Boolean last_readonly = null;

static
{
Expand Down Expand Up @@ -134,18 +134,20 @@ private void handleUpdates(final VType value)
}
}

socket.sendUpdate(name, value, last_value, last_readonly, pv.isReadonly() || !PV_WRITE_SUPPORT);
Boolean current_readonly = pv.isReadonly() || !PV_WRITE_SUPPORT;
socket.sendUpdate(name, value, last_value, last_readonly, current_readonly);
last_value = value;
last_readonly = pv.isReadonly();
last_readonly = current_readonly;
}

/** Handle change in access permissions
* @param readonly Latest access mode
*/
private void handleAccessChanges(final Boolean readonly)
{
socket.sendUpdate(name, last_value, last_value, last_readonly, pv.isReadonly() || !PV_WRITE_SUPPORT);
last_readonly = pv.isReadonly();
Boolean current_readonly = pv.isReadonly() || !PV_WRITE_SUPPORT;
socket.sendUpdate(name, last_value, last_value, last_readonly, current_readonly);
last_readonly = current_readonly;
}

/** @return Most recent value or null */
Expand Down

0 comments on commit 1abce99

Please sign in to comment.