Skip to content

Commit ab51b02

Browse files
authored
Merge pull request #5 from ControlSystemStudio/update_readme
Update readme
2 parents 0c3f6ea + 5554491 commit ab51b02

File tree

4 files changed

+252
-24
lines changed

4 files changed

+252
-24
lines changed

README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,72 @@
11
This is an attempt to port the original work https://github.com/ornl-epics/pvws to a Spring Boot-based web application. While the code is adapted to the web socket APIs of Spring Boot, most of the code is essentially unchanged.
2+
3+
Requirements
4+
------------
5+
6+
To build: JDK 17, Maven 3.8+
7+
8+
To run: JRE 17
9+
10+
Build
11+
=====
12+
13+
Executable jar
14+
--------------
15+
16+
To build an executable Spring Boot jar (embedded Tomcat):
17+
18+
``>mvn clean install``
19+
20+
Output is ``pvws.jar`` in the ``target`` directory.
21+
22+
Tomcat war
23+
----------
24+
25+
To build war for deployment in Tomcat container:
26+
27+
``>mvn -Pwar clean install``
28+
29+
Output is ``pvws.war`` in the ``target`` directory.
30+
31+
Run
32+
===
33+
34+
Settings
35+
--------
36+
37+
Bundled ``application.properties`` defines a few settings (e.g. default protocol). To define other settings or override
38+
settings, one may create a file named exactly ``application.properties`` and edit as needed. This
39+
file must be readable by the user account owning the application process.
40+
41+
Executable jar
42+
--------------
43+
44+
Launch like so:
45+
46+
``>java -Dspring.config.location=file:/path/to/directory/ -jar /path/to/pvws.jar``
47+
48+
where ``/path/to/directory/`` is the directory holding ``application.properties``. Note that
49+
this string **must** end in a slash ("/").
50+
51+
It is also possible to define properties on the command line, e.g.
52+
53+
``>java -Dspring.config.location=file:/path/to/directory/ -DEPICS_PVA_ADDR_LIST=1.2.3.4 -jar /path/to/pvws.jar``
54+
55+
Combining ``application.properties`` with JVM options is possible.
56+
Command line options will override definitions in ``application.properties``.
57+
58+
Tomcat war
59+
----------
60+
61+
**NOTE:** Verified on Tomcat 9 only.
62+
63+
Copy ``pvws.war`` to ``TOMCAT_ROOT/webapps``. Set environment variable:
64+
65+
``>export JAVA_OPTS=-Dspring.config.location=file:/path/to/directory/``
66+
67+
and launch Tomcat.
68+
69+
70+
71+
72+

src/main/java/org/phoebus/pvws/PvwsWebListener.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public class PvwsWebListener implements ServletContextListener {
3838

3939
@Override
4040
public void contextDestroyed(ServletContextEvent event) {
41-
System.out.println("sdjhgfdfugh");
4241
WebApplicationContext context = ContextLoader.getCurrentWebApplicationContext();
4342
sockets = (List<WebSocket>) context.getBean("sockets");
4443
if (sockets == null) {

src/main/java/org/phoebus/pvws/ws/Vtype2Json.java

Lines changed: 95 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
import java.nio.ByteBuffer;
1818
import java.nio.ByteOrder;
1919
import java.nio.DoubleBuffer;
20+
import java.nio.FloatBuffer;
2021
import java.nio.IntBuffer;
22+
import java.nio.ShortBuffer;
2123
import java.nio.charset.Charset;
2224
import java.nio.charset.StandardCharsets;
2325
import java.text.DecimalFormat;
@@ -58,15 +60,15 @@ else if (value instanceof VString)
5860
else if (value instanceof VEnum)
5961
handleEnum(g, (VEnum) value, last_value);
6062
else if (value instanceof VByteArray)
61-
handleLongString(g, (VByteArray) value);
63+
handleBytes(g, (VNumberArray) value, last_value);
6264

6365
// Serialize double and float arrays as b64dbl
6466
else if (value instanceof VDoubleArray)
6567
handleDoubles(g, (VNumberArray) value, last_value);
6668
else if (value instanceof VFloatArray)
67-
handleDoubles(g, (VNumberArray) value, last_value);
69+
handleFloats(g, (VNumberArray) value, last_value);
6870

69-
// Serialize remaining number arrays (int, short) as b64int
71+
// Serialize remaining number arrays (int) as b64int
7072
else if (value instanceof VNumberArray)
7173
handleInts(g, (VNumberArray) value, last_value);
7274

@@ -239,7 +241,7 @@ private static void handleInts(final JsonGenerator g, final VNumberArray value,
239241
{
240242
// Add severity if it changed
241243
if ((last_value instanceof VNumber) &&
242-
((VNumber) last_value).getAlarm().getSeverity() != severity)
244+
((VNumber) last_value).getAlarm().getSeverity() != severity)
243245
g.writeStringField("severity", severity.name());
244246
}
245247

@@ -256,6 +258,7 @@ private static void handleInts(final JsonGenerator g, final VNumberArray value,
256258
}
257259

258260

261+
259262
private static void handleEnum(final JsonGenerator g, final VEnum value, final VType last_value) throws Exception
260263
{
261264
final AlarmSeverity severity = value.getAlarm().getSeverity();
@@ -275,11 +278,98 @@ private static void handleEnum(final JsonGenerator g, final VEnum value, final V
275278
{
276279
// Add severity if it changed
277280
if ((last_value instanceof VNumber) &&
278-
((VNumber) last_value).getAlarm().getSeverity() != severity)
281+
((VNumber) last_value).getAlarm().getSeverity() != severity)
279282
g.writeStringField("severity", severity.name());
280283
}
281284

282285
g.writeNumberField("value", value.getIndex());
283286
g.writeStringField("text", value.getValue());
284287
}
288+
289+
private static void handleFloats(final JsonGenerator g, final VNumberArray value, final VType last_value) throws Exception
290+
{
291+
final AlarmSeverity severity = value.getAlarm().getSeverity();
292+
if (last_value == null)
293+
{
294+
// Initially, add complete metadata
295+
g.writeStringField("vtype", VType.typeOf(value).getSimpleName());
296+
handleDisplay(g, value.getDisplay());
297+
// Initial severity
298+
g.writeStringField("severity", severity.name());
299+
}
300+
else
301+
{
302+
// Add severity if it changed
303+
if ((last_value instanceof VNumber) &&
304+
((VNumber) last_value).getAlarm().getSeverity() != severity)
305+
g.writeStringField("severity", severity.name());
306+
}
307+
308+
final ListNumber data = value.getData();
309+
final int N = data.size();
310+
final ByteBuffer buf = ByteBuffer.allocate(N * Float.BYTES);
311+
buf.order(ByteOrder.LITTLE_ENDIAN);
312+
final FloatBuffer fltbuf = buf.asFloatBuffer();
313+
for (int i=0; i<N; ++i)
314+
fltbuf.put(data.getFloat(i));
315+
g.writeStringField("b64flt", Base64.getEncoder().encodeToString(buf.array()));
316+
}
317+
318+
private static void handleShorts(final JsonGenerator g, final VNumberArray value, final VType last_value) throws Exception
319+
{
320+
final AlarmSeverity severity = value.getAlarm().getSeverity();
321+
if (last_value == null)
322+
{
323+
// Initially, add complete metadata
324+
g.writeStringField("vtype", VType.typeOf(value).getSimpleName());
325+
handleDisplay(g, value.getDisplay());
326+
// Initial severity
327+
g.writeStringField("severity", severity.name());
328+
}
329+
else
330+
{
331+
// Add severity if it changed
332+
if ((last_value instanceof VNumber) &&
333+
((VNumber) last_value).getAlarm().getSeverity() != severity)
334+
g.writeStringField("severity", severity.name());
335+
}
336+
337+
final ListNumber data = value.getData();
338+
final int N = data.size();
339+
final ByteBuffer buf = ByteBuffer.allocate(N * Short.BYTES);
340+
buf.order(ByteOrder.LITTLE_ENDIAN);
341+
final ShortBuffer srtbuf = buf.asShortBuffer();
342+
for (int i=0; i<N; ++i)
343+
srtbuf.put(data.getShort(i));
344+
g.writeStringField("b64srt", Base64.getEncoder().encodeToString(buf.array()));
345+
}
346+
347+
private static void handleBytes(final JsonGenerator g, final VNumberArray value, final VType last_value) throws Exception
348+
{
349+
final AlarmSeverity severity = value.getAlarm().getSeverity();
350+
if (last_value == null)
351+
{
352+
// Initially, add complete metadata
353+
g.writeStringField("vtype", VType.typeOf(value).getSimpleName());
354+
handleDisplay(g, value.getDisplay());
355+
// Initial severity
356+
g.writeStringField("severity", severity.name());
357+
}
358+
else
359+
{
360+
// Add severity if it changed
361+
if ((last_value instanceof VNumber) &&
362+
((VNumber) last_value).getAlarm().getSeverity() != severity)
363+
g.writeStringField("severity", severity.name());
364+
}
365+
366+
// Convert into Base64 int64 array
367+
final ListNumber data = value.getData();
368+
final int N = data.size();
369+
final ByteBuffer buf = ByteBuffer.allocate(N * Byte.BYTES);
370+
buf.order(ByteOrder.LITTLE_ENDIAN);
371+
for (int i=0; i<N; ++i)
372+
buf.put(data.getByte(i));
373+
g.writeStringField("b64byt", Base64.getEncoder().encodeToString(buf.array()));
374+
}
285375
}

0 commit comments

Comments
 (0)