Skip to content

Commit e6d03db

Browse files
authored
Merge pull request #75 from epics-base/Issue_69
Issue_69 Support for enums over CA in GPClient
2 parents e080d1a + ffc1a52 commit e6d03db

File tree

7 files changed

+130
-63
lines changed

7 files changed

+130
-63
lines changed

epics-util/src/test/java/org/epics/util/text/NumberFormatsTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
package org.epics.util.text;
66

77
import java.text.NumberFormat;
8+
import java.util.Locale;
9+
810
import static org.hamcrest.CoreMatchers.equalTo;
11+
12+
import org.junit.Before;
13+
import org.junit.BeforeClass;
914
import org.junit.Test;
1015
import static org.junit.Assert.*;
1116
import static org.hamcrest.Matchers.*;
@@ -19,6 +24,11 @@ public class NumberFormatsTest {
1924
public NumberFormatsTest() {
2025
}
2126

27+
@Before
28+
public void setLocale(){
29+
Locale.setDefault(new Locale("en", "US"));
30+
}
31+
2232
@Test
2333
public void format1() {
2434
NumberFormat format = NumberFormats.precisionFormat(2);

epics-vtype/vtype/src/test/java/org/epics/vtype/SimpleValueFormatTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import java.util.Arrays;
1111
import java.util.List;
12+
import java.util.Locale;
1213

1314
import org.epics.util.array.ArrayByte;
1415
import org.epics.util.array.ArrayDouble;
@@ -20,6 +21,7 @@
2021
import org.epics.util.array.ListFloat;
2122
import org.epics.util.stats.Range;
2223
import org.epics.util.text.NumberFormats;
24+
import org.junit.Before;
2325
import org.junit.Test;
2426
import org.mockito.Mockito;
2527

@@ -28,6 +30,11 @@
2830
* @author carcassi
2931
*/
3032
public class SimpleValueFormatTest {
33+
34+
static {
35+
Locale.setDefault(new Locale("en", "US"));
36+
}
37+
3138
Range maxDoubleRange = Range.of(Double.MIN_VALUE, Double.MAX_VALUE);
3239
Display display = Display.of(maxDoubleRange, maxDoubleRange, maxDoubleRange, maxDoubleRange, "",
3340
NumberFormats.precisionFormat(3));

gpclient/gpclient-ca/src/main/java/org/epics/gpclient/datasource/ca/types/CAVTypeAdapterSet.java

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55
package org.epics.gpclient.datasource.ca.types;
66

7+
import org.epics.vtype.EnumDisplay;
8+
import org.epics.vtype.VEnumArray;
79
import org.epics.vtype.VFloat;
810
import org.epics.vtype.VInt;
911
import org.epics.vtype.VString;
@@ -259,14 +261,28 @@ public VString createValue(DBR value, DBR metadata, CAConnectionPayload connPayl
259261
}
260262
};
261263

262-
// // DBR_TIME_Enum -> VEnum
263-
// final static CATypeAdapter DBREnumToVEnum = new CATypeAdapter(VEnum.class, DBR_TIME_Enum.TYPE, DBR_LABELS_Enum.TYPE, false) {
264-
//
265-
// @Override
266-
// public VEnum createValue(DBR value, DBR metadata, CAConnectionPayload connPayload) {
267-
// return new VEnumFromDbr((DBR_TIME_Enum) value, (DBR_LABELS_Enum) metadata, connPayload);
268-
// }
269-
// };
264+
// DBR_TIME_Enum -> VEnum
265+
final static CATypeAdapter DBREnumToVEnum = new CATypeAdapter(VEnum.class, DBR_TIME_Enum.TYPE, DBR_LABELS_Enum.TYPE, false) {
266+
267+
@Override
268+
public VEnum createValue(DBR value, DBR rawMetadata, CAConnectionPayload connPayload) {
269+
DBR_TIME_Enum message = (DBR_TIME_Enum)value;
270+
DBR_LABELS_Enum metadata = (DBR_LABELS_Enum)rawMetadata;
271+
Alarm alarm;
272+
if (!connPayload.isChannelConnected()) {
273+
alarm = Alarm.disconnected();
274+
} else {
275+
alarm = CADataUtils.fromEpics(message.getSeverity());
276+
}
277+
Time timestamp;
278+
if (!connPayload.isChannelConnected()) {
279+
timestamp = Time.of(connPayload.getEventTime());
280+
} else {
281+
timestamp = CADataUtils.timestampOf(message.getTimeStamp());
282+
}
283+
return VEnum.of(message.getEnumValue()[0], EnumDisplay.of(metadata.getLabels()), alarm, timestamp);
284+
}
285+
};
270286

271287
// DBR_TIME_Float -> VFloatArray
272288
final static CATypeAdapter DBRFloatToVFloatArray = new CATypeAdapter(VFloatArray.class, DBR_TIME_Float.TYPE, DBR_CTRL_Double.TYPE, true) {
@@ -410,7 +426,7 @@ public VShortArray createValue(DBR value, DBR rawMetadata, CAConnectionPayload c
410426
};
411427

412428
// DBR_TIME_Int -> VIntArray
413-
final static CATypeAdapter DBRIntToVIntArray = new CATypeAdapter(VIntArray.class, DBR_TIME_Int.TYPE, DBR_CTRL_Double.TYPE, true) {
429+
final static CATypeAdapter DBRIntToVIntArray = new CATypeAdapter(VIntArray.class, DBR_TIME_Int.TYPE, DBR_CTRL_Double.TYPE, true) {
414430

415431
@Override
416432
public VIntArray createValue(DBR value, DBR rawMetadata, CAConnectionPayload connPayload) {
@@ -443,7 +459,7 @@ public VIntArray createValue(DBR value, DBR rawMetadata, CAConnectionPayload con
443459
};
444460

445461
// DBR_TIME_String -> VString
446-
final static CATypeAdapter DBRStringToVStringArray = new CATypeAdapter(VStringArray.class, DBR_TIME_String.TYPE, null, false) {
462+
final static CATypeAdapter DBRStringToVStringArray = new CATypeAdapter(VStringArray.class, DBR_TIME_String.TYPE, null, true) {
447463

448464
@Override
449465
public VStringArray createValue(DBR rawMessage, DBR metadata, CAConnectionPayload connPayload) {
@@ -476,7 +492,7 @@ public VStringArray createValue(DBR rawMessage, DBR metadata, CAConnectionPayloa
476492
newFactories.add(DBRIntToVInt);
477493
newFactories.add(DBRStringToVString);
478494
newFactories.add(DBRByteToVString);
479-
// newFactories.add(DBREnumToVEnum);
495+
newFactories.add(DBREnumToVEnum);
480496

481497
// Add all ARRAYs
482498
newFactories.add(DBRFloatToVFloatArray);

gpclient/gpclient-ca/src/test/java/org/epics/gpclient/datasource/ca/CAChannelTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void createSimpleChannel() throws InterruptedException {
6767
PVEventRecorder recorder = probe.getRecorder();
6868
PVReader<VType> pv = gpClient.read("ca://test_double_0").addListener(recorder).start();
6969
recorder.wait(500, PVEventRecorder.forAConnectionEvent());
70-
recorder.wait(100, PVEventRecorder.anEventOfType(PVEvent.Type.VALUE));
70+
recorder.wait(200, PVEventRecorder.anEventOfType(PVEvent.Type.VALUE));
7171
pv.close();
7272
Thread.sleep(1000);
7373
}
@@ -79,7 +79,7 @@ public void createSimpleWriteChannel() throws InterruptedException {
7979
PVEventRecorder recorder = probe.getRecorder();
8080
PV<VType, Object> pv = gpClient.readAndWrite("ca://test_double_0").addListener(recorder).start();
8181
recorder.wait(1000, PVEventRecorder.forAConnectionEvent());
82-
recorder.wait(100, PVEventRecorder.anEventOfType(PVEvent.Type.VALUE));
82+
recorder.wait(200, PVEventRecorder.anEventOfType(PVEvent.Type.VALUE));
8383
pv.write(VDouble.of(1.0, Alarm.none(), Time.now(), Display.none()));
8484
Thread.sleep(1000);
8585
pv.write(VDouble.of(2.0, Alarm.none(), Time.now(), Display.none()));

pom.xml

Lines changed: 74 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
23
<modelVersion>4.0.0</modelVersion>
34

45
<groupId>org.epics</groupId>
@@ -51,8 +52,8 @@
5152
<connection>scm:git:https://github.com/epics-base/epicsCoreJava.git</connection>
5253
<developerConnection>scm:git:https://github.com/epics-base/epicsCoreJava.git</developerConnection>
5354
<url>https://github.com/epics-base/epicsCoreJava</url>
54-
<tag>HEAD</tag>
55-
</scm>
55+
<tag>HEAD</tag>
56+
</scm>
5657

5758
<!-- Project developers (alphabetically) taken from SCM logs -->
5859
<developers>
@@ -316,7 +317,7 @@
316317
<!-- Hardcoding the java 8 docs since 11.0.2 and maven javadoc
317318
plugin hit the following jdk bug https://bugs.openjdk.java.net/browse/JDK-8212233 -->
318319
<links>
319-
<link>https://docs.oracle.com/javase/8/docs/api/</link>
320+
<link>https://docs.oracle.com/javase/8/docs/api/</link>
320321
</links>
321322
<source>8</source>
322323
</configuration>
@@ -329,11 +330,11 @@
329330
</execution>
330331
</executions>
331332
<dependencies>
332-
<dependency>
333-
<groupId>org.ow2.asm</groupId>
334-
<artifactId>asm</artifactId>
335-
<version>${asm.version}</version>
336-
</dependency>
333+
<dependency>
334+
<groupId>org.ow2.asm</groupId>
335+
<artifactId>asm</artifactId>
336+
<version>${asm.version}</version>
337+
</dependency>
337338
</dependencies>
338339
</plugin>
339340

@@ -361,6 +362,30 @@
361362
</configuration>
362363
</plugin>
363364

365+
<!-- In case one wishes to integrate with Sonarqube running on localhost -->
366+
<plugin>
367+
<groupId>org.jacoco</groupId>
368+
<artifactId>jacoco-maven-plugin</artifactId>
369+
<version>0.8.5</version>
370+
<executions>
371+
<execution>
372+
<id>default-prepare-agent</id>
373+
<goals>
374+
<goal>prepare-agent</goal>
375+
</goals>
376+
</execution>
377+
<execution>
378+
<id>default-report</id>
379+
<phase>prepare-package</phase>
380+
<goals>
381+
<goal>report</goal>
382+
</goals>
383+
</execution>
384+
</executions>
385+
<configuration>
386+
<destFile>${build.directory}/jacoco.exec</destFile>
387+
</configuration>
388+
</plugin>
364389
</plugins>
365390
</build>
366391

@@ -398,46 +423,45 @@
398423
</profile>
399424

400425
<profile>
401-
<id>java-9+</id>
402-
<activation>
403-
<jdk>[9,)</jdk>
404-
</activation>
405-
<properties>
406-
<javadoc.opts>-html5</javadoc.opts>
407-
</properties>
408-
<modules>
409-
<module>bundleJava</module>
410-
</modules>
411-
<build>
412-
<plugins>
413-
<plugin>
414-
<groupId>org.apache.maven.plugins</groupId>
415-
<artifactId>maven-javadoc-plugin</artifactId>
416-
<configuration>
417-
<overview>documentation/${mainpage.name}.html</overview>
418-
</configuration>
419-
<dependencies>
420-
<dependency>
421-
<groupId>org.apache.commons</groupId>
422-
<artifactId>commons-lang3</artifactId>
423-
<version>3.7</version>
424-
</dependency>
425-
</dependencies>
426-
<executions>
427-
<execution>
428-
<id>attach-javadocs</id>
429-
<goals>
430-
<goal>jar</goal>
431-
</goals>
432-
<configuration>
433-
<additionalOptions>-html5</additionalOptions>
434-
</configuration>
435-
</execution>
436-
</executions>
437-
</plugin>
438-
</plugins>
439-
</build>
440-
</profile>
426+
<id>java-9+</id>
427+
<activation>
428+
<jdk>[9,)</jdk>
429+
</activation>
430+
<properties>
431+
<javadoc.opts>-html5</javadoc.opts>
432+
</properties>
433+
<modules>
434+
<module>bundleJava</module>
435+
</modules>
436+
<build>
437+
<plugins>
438+
<plugin>
439+
<groupId>org.apache.maven.plugins</groupId>
440+
<artifactId>maven-javadoc-plugin</artifactId>
441+
<configuration>
442+
<overview>documentation/${mainpage.name}.html</overview>
443+
</configuration>
444+
<dependencies>
445+
<dependency>
446+
<groupId>org.apache.commons</groupId>
447+
<artifactId>commons-lang3</artifactId>
448+
<version>3.7</version>
449+
</dependency>
450+
</dependencies>
451+
<executions>
452+
<execution>
453+
<id>attach-javadocs</id>
454+
<goals>
455+
<goal>jar</goal>
456+
</goals>
457+
<configuration>
458+
<additionalOptions>-html5</additionalOptions>
459+
</configuration>
460+
</execution>
461+
</executions>
462+
</plugin>
463+
</plugins>
464+
</build>
465+
</profile>
441466
</profiles>
442-
443467
</project>

pvDataJava/test/org/epics/pvdata/BitSetUtilTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
import org.epics.pvdata.pv.PVStructure;
1717
import org.epics.pvdata.pv.ScalarType;
1818
import org.epics.pvdata.pv.StandardField;
19+
import org.junit.Before;
1920

21+
import java.util.Locale;
2022

2123

2224
/**
@@ -29,6 +31,11 @@ public class BitSetUtilTest extends TestCase {
2931
private static final StandardField standardField = StandardFieldFactory.getStandardField();
3032
private static final BitSetUtil bitSetUtil = BitSetUtilFactory.getCompressBitSet();
3133
private static boolean debug = false;
34+
35+
@Before
36+
public void setLocale(){
37+
Locale.setDefault(new Locale("en", "US"));
38+
}
3239

3340
static private void print(String name,String value) {
3441
if(!debug) return;

pvDataJava/test/org/epics/pvdata/NumberFormatTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.text.FieldPosition;
88
import java.text.NumberFormat;
99
import java.text.ParsePosition;
10+
import java.util.Locale;
1011

1112
import junit.framework.TestCase;
1213

@@ -18,7 +19,9 @@
1819
*/
1920
public class NumberFormatTest extends TestCase {
2021

22+
2123
public void testNumberFormat() {
24+
Locale.setDefault(new Locale("en", "US"));
2225
NumberFormat nf = new NumberFormatDouble("%12.2f");
2326
StringBuffer sb = new StringBuffer();
2427
FieldPosition fp = new FieldPosition(0);

0 commit comments

Comments
 (0)