From cb7441a051422ac03c1c05fa04896654c2ba56a4 Mon Sep 17 00:00:00 2001 From: georgweiss Date: Mon, 28 Aug 2023 16:25:19 +0200 Subject: [PATCH 01/12] Backup commit --- .../saveandrestore/common/Utilities.java | 45 +++---------------- app/save-and-restore/model/pom.xml | 7 +++ .../model/json/VTypeSerializer.java | 3 +- pom.xml | 2 +- 4 files changed, 17 insertions(+), 40 deletions(-) diff --git a/app/save-and-restore/common/src/main/java/org/phoebus/applications/saveandrestore/common/Utilities.java b/app/save-and-restore/common/src/main/java/org/phoebus/applications/saveandrestore/common/Utilities.java index 3e9a0dc8d0..27eda8a32a 100644 --- a/app/save-and-restore/common/src/main/java/org/phoebus/applications/saveandrestore/common/Utilities.java +++ b/app/save-and-restore/common/src/main/java/org/phoebus/applications/saveandrestore/common/Utilities.java @@ -39,44 +39,7 @@ import org.epics.util.number.UShort; import org.epics.util.number.UnsignedConversions; import org.epics.util.text.NumberFormats; -import org.epics.vtype.Alarm; -import org.epics.vtype.AlarmSeverity; -import org.epics.vtype.AlarmStatus; -import org.epics.vtype.Array; -import org.epics.vtype.Display; -import org.epics.vtype.EnumDisplay; -import org.epics.vtype.SimpleValueFormat; -import org.epics.vtype.Time; -import org.epics.vtype.VBoolean; -import org.epics.vtype.VBooleanArray; -import org.epics.vtype.VByte; -import org.epics.vtype.VByteArray; -import org.epics.vtype.VDouble; -import org.epics.vtype.VDoubleArray; -import org.epics.vtype.VEnum; -import org.epics.vtype.VEnumArray; -import org.epics.vtype.VFloat; -import org.epics.vtype.VFloatArray; -import org.epics.vtype.VInt; -import org.epics.vtype.VIntArray; -import org.epics.vtype.VLong; -import org.epics.vtype.VLongArray; -import org.epics.vtype.VNumber; -import org.epics.vtype.VNumberArray; -import org.epics.vtype.VShort; -import org.epics.vtype.VShortArray; -import org.epics.vtype.VString; -import org.epics.vtype.VStringArray; -import org.epics.vtype.VType; -import org.epics.vtype.VUByte; -import org.epics.vtype.VUByteArray; -import org.epics.vtype.VUInt; -import org.epics.vtype.VUIntArray; -import org.epics.vtype.VULong; -import org.epics.vtype.VULongArray; -import org.epics.vtype.VUShort; -import org.epics.vtype.VUShortArray; -import org.epics.vtype.ValueFormat; +import org.epics.vtype.*; import org.phoebus.core.vtypes.VTypeHelper; import java.math.BigInteger; @@ -381,6 +344,9 @@ public static Object toRawValue(VType type) { } else if (type instanceof VBoolean) { return ((VBoolean) type).getValue(); } + else if(type instanceof VTable) { + return type; + } return null; } @@ -512,6 +478,9 @@ public static String valueToString(VType type, int arrayLimit) { } else if (type instanceof VBoolean) { return String.valueOf(((VBoolean) type).getValue()); } + else if(type instanceof VTable){ + return "[VTable]"; + } // no support for MultiScalars (VMultiDouble, VMultiInt, VMultiString, VMultiEnum), VStatistics, VTable and // VImage) return "Type " + VType.typeOf(type).getSimpleName() + " not supported"; diff --git a/app/save-and-restore/model/pom.xml b/app/save-and-restore/model/pom.xml index 6a9eb57c45..a0d6b7261b 100644 --- a/app/save-and-restore/model/pom.xml +++ b/app/save-and-restore/model/pom.xml @@ -57,6 +57,13 @@ javax.json 1.1.4 + + + diff --git a/app/save-and-restore/model/src/main/java/org/phoebus/applications/saveandrestore/model/json/VTypeSerializer.java b/app/save-and-restore/model/src/main/java/org/phoebus/applications/saveandrestore/model/json/VTypeSerializer.java index 16b22018c5..28ab8f3a79 100644 --- a/app/save-and-restore/model/src/main/java/org/phoebus/applications/saveandrestore/model/json/VTypeSerializer.java +++ b/app/save-and-restore/model/src/main/java/org/phoebus/applications/saveandrestore/model/json/VTypeSerializer.java @@ -36,6 +36,7 @@ public class VTypeSerializer extends JsonSerializer { @Override public void serialize(VType vType, JsonGenerator gen, SerializerProvider serializers) throws IOException { - gen.writeRawValue(VTypeToJson.toJson(vType).toString()); + String s = VTypeToJson.toJson(vType).toString(); + gen.writeRawValue(s); } } diff --git a/pom.xml b/pom.xml index 5ca708b084..1696ccb07c 100644 --- a/pom.xml +++ b/pom.xml @@ -66,7 +66,7 @@ 2023-05-24T19:31:02Z 7.0.9 - 1.0.6 + 1.0.7-SNAPSHOT 19 2.12.3 1.14 From 1100460764f35fc7f6b95b4a18327edac2681522 Mon Sep 17 00:00:00 2001 From: georgweiss Date: Wed, 30 Aug 2023 14:11:49 +0200 Subject: [PATCH 02/12] Initial attempts to construct PVATable from VTable for the purpose of write operations --- app/save-and-restore/common/pom.xml | 6 ++ .../saveandrestore/common/Utilities.java | 10 +++- .../phoebus/pv/pva/PVAStructureHelper.java | 60 ++++++++++++++----- 3 files changed, 58 insertions(+), 18 deletions(-) diff --git a/app/save-and-restore/common/pom.xml b/app/save-and-restore/common/pom.xml index 031a67dbb3..421f16f118 100644 --- a/app/save-and-restore/common/pom.xml +++ b/app/save-and-restore/common/pom.xml @@ -30,6 +30,12 @@ ${vtype.version} + + org.phoebus + core-pv + 4.7.3-SNAPSHOT + + org.epics vtype-json diff --git a/app/save-and-restore/common/src/main/java/org/phoebus/applications/saveandrestore/common/Utilities.java b/app/save-and-restore/common/src/main/java/org/phoebus/applications/saveandrestore/common/Utilities.java index 27eda8a32a..03e7490063 100644 --- a/app/save-and-restore/common/src/main/java/org/phoebus/applications/saveandrestore/common/Utilities.java +++ b/app/save-and-restore/common/src/main/java/org/phoebus/applications/saveandrestore/common/Utilities.java @@ -41,6 +41,7 @@ import org.epics.util.text.NumberFormats; import org.epics.vtype.*; import org.phoebus.core.vtypes.VTypeHelper; +import org.phoebus.pv.pva.PVAStructureHelper; import java.math.BigInteger; import java.text.NumberFormat; @@ -345,7 +346,12 @@ public static Object toRawValue(VType type) { return ((VBoolean) type).getValue(); } else if(type instanceof VTable) { - return type; + try{ + return PVAStructureHelper.fromVTable((VTable) type); + } + catch (Exception e){ + e.printStackTrace(); + } } return null; } @@ -481,7 +487,7 @@ public static String valueToString(VType type, int arrayLimit) { else if(type instanceof VTable){ return "[VTable]"; } - // no support for MultiScalars (VMultiDouble, VMultiInt, VMultiString, VMultiEnum), VStatistics, VTable and + // no support for MultiScalars (VMultiDouble, VMultiInt, VMultiString, VMultiEnum), VStatistics and // VImage) return "Type " + VType.typeOf(type).getSimpleName() + " not supported"; } diff --git a/core/pv/src/main/java/org/phoebus/pv/pva/PVAStructureHelper.java b/core/pv/src/main/java/org/phoebus/pv/pva/PVAStructureHelper.java index 55c78b734c..a601da5f26 100644 --- a/core/pv/src/main/java/org/phoebus/pv/pva/PVAStructureHelper.java +++ b/core/pv/src/main/java/org/phoebus/pv/pva/PVAStructureHelper.java @@ -12,27 +12,17 @@ import static org.phoebus.pv.pva.Decoders.decodeAlarm; import static org.phoebus.pv.pva.Decoders.decodeTime; +import java.time.Instant; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Optional; -import org.epics.pva.data.PVAArray; -import org.epics.pva.data.PVABool; -import org.epics.pva.data.PVABoolArray; -import org.epics.pva.data.PVAByteArray; -import org.epics.pva.data.PVAData; -import org.epics.pva.data.PVADoubleArray; -import org.epics.pva.data.PVAFloatArray; -import org.epics.pva.data.PVAIntArray; -import org.epics.pva.data.PVALongArray; -import org.epics.pva.data.PVANumber; -import org.epics.pva.data.PVAShortArray; -import org.epics.pva.data.PVAString; -import org.epics.pva.data.PVAStringArray; -import org.epics.pva.data.PVAStructure; -import org.epics.pva.data.PVAStructureArray; -import org.epics.pva.data.PVAUnion; +import org.epics.pva.data.*; +import org.epics.pva.data.nt.MustBeArrayException; +import org.epics.pva.data.nt.PVAAlarm; +import org.epics.pva.data.nt.PVATable; +import org.epics.pva.data.nt.PVATimeStamp; import org.epics.util.array.ArrayByte; import org.epics.util.array.ArrayDouble; import org.epics.util.array.ArrayFloat; @@ -55,6 +45,7 @@ import org.epics.vtype.VStringArray; import org.epics.vtype.VTable; import org.epics.vtype.VType; +import org.phoebus.core.vtypes.VTypeHelper; /** Helper for handling 'structure' type PVA data */ @SuppressWarnings("nls") @@ -256,6 +247,43 @@ else if (column instanceof PVABoolArray) return VTable.of(types, names, values); } + public static PVATable fromVTable(VTable vTable) throws MustBeArrayException { + PVATable.PVATableBuilder builder = PVATable.PVATableBuilder.aPVATable(); + builder.alarm(new PVAAlarm()); + builder.timeStamp(new PVATimeStamp(Instant.now())); + List table = new ArrayList<>(); + + int columnCount = vTable.getColumnCount(); + String[] columnNames = new String[columnCount]; + for(int i = 0; i < columnCount; i++){ + columnNames[i] = vTable.getColumnName(i); + } + PVAStringArray names = new PVAStringArray("labels", columnNames); + //table.add(names); + + List valuesData = new ArrayList<>(); + for(int i = 0; i < columnCount; i++){ + Class clazz = vTable.getColumnType(i); + if(clazz.equals(Integer.TYPE)){ + ArrayInteger arrayInteger = (ArrayInteger) vTable.getColumnData(i); + int[] integers = new int[arrayInteger.size()]; + for(int j = 0; j < arrayInteger.size(); j++){ + integers[j] = arrayInteger.getInt(j); + } + PVAIntArray ints = + new PVAIntArray(i == 0 ? "A" : "B", false, integers); + builder.addColumn(ints); + } + } + + PVAStructure valueStruct = new PVAStructure("value", "", valuesData); + //table.add(valueStruct); + + builder.name(""); + //builder.table(valuesData); + return builder.build(); + } + /** Decode 'value', 'timeStamp', 'alarm' of NTArray * @param struct * @return From ea53e33292055d29feb95d32b3fdedd009d9261b Mon Sep 17 00:00:00 2001 From: georgweiss Date: Thu, 28 Sep 2023 12:08:36 +0200 Subject: [PATCH 03/12] Parking WIP --- .../saveandrestore/ui/Utilities.java | 91 ++++++++++++++- .../snapshot/SnapshotTableViewController.java | 2 +- .../saveandrestore/ui/UtilitiesTest.java | 60 ++++++++++ app/save-and-restore/common/pom.xml | 107 ------------------ .../phoebus/pv/pva/PVAStructureHelper.java | 13 ++- .../main/java/org/epics/pva/data/PVAData.java | 2 +- .../java/org/epics/pva/data/PVAStructure.java | 33 +++++- .../java/org/epics/pva/server/TableDemo.java | 10 +- 8 files changed, 197 insertions(+), 121 deletions(-) delete mode 100644 app/save-and-restore/common/pom.xml diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/Utilities.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/Utilities.java index 9e7c829488..319b5b32de 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/Utilities.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/Utilities.java @@ -17,6 +17,9 @@ */ package org.phoebus.applications.saveandrestore.ui; +import org.epics.pva.data.*; +import org.epics.pva.data.nt.PVAAlarm; +import org.epics.pva.data.nt.PVATimeStamp; import org.epics.util.array.*; import org.epics.util.number.*; import org.epics.util.text.NumberFormats; @@ -26,6 +29,7 @@ import java.math.BigInteger; import java.text.NumberFormat; +import java.time.Instant; import java.util.*; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -323,12 +327,39 @@ public static Object toRawValue(VType type) { return ((VBoolean) type).getValue(); } else if(type instanceof VTable) { + VTable vTable = (VTable)type; + /* + PVAAlarm alarm = new PVAAlarm(); + PVATimeStamp time = new PVATimeStamp(Instant.now()); + PVAStringArray labels = new PVAStringArray("label", vTable.getColumnName(0), vTable.getColumnName(1)); + List data = new ArrayList<>(); + PVAIntArray d1 = null; + PVAIntArray d2 = null; + for(int i = 0; i < vTable.getColumnCount(); i++){ + ArrayInteger ai = (ArrayInteger)vTable.getColumnData(0); + int[] ii = new int[ai.size()]; + for(int j = 0; j < ai.size(); j++){ + ii[j] = ai.getInt(j); + } + if(i == 0){ + d1 = new PVAIntArray("A", false, ii); + } + if(i == 1){ + d2 = new PVAIntArray("B", false, ii); + } + } + PVAStructure value = new PVAStructure("value", "", data); + PVAStructure table = new PVAStructure("epics:nt/NTTable:1.0","", List.of(d1, d2)); + return table; + */ + try{ return PVAStructureHelper.fromVTable((VTable) type); } catch (Exception e){ e.printStackTrace(); } + } return null; } @@ -898,7 +929,12 @@ public static VTypeComparison deltaValueToString(VType value, VType baseValue, O } else if (value instanceof VBooleanArray && baseValue instanceof VBooleanArray) { boolean equal = areValuesEqual(value, baseValue, Optional.empty()); return new VTypeComparison(equal ? "---" : "NOT EQUAL", equal ? 0 : 1, equal); - } else { + } + else if (value instanceof VTable && baseValue instanceof VTable) { + boolean equal = areValuesEqual(value, baseValue, Optional.empty()); + return new VTypeComparison(equal ? "---" : "NOT EQUAL", equal ? 0 : 1, equal); + } + else { String str = valueToString(value); boolean valuesEqual = areValuesEqual(value, baseValue, Optional.empty()); return new VTypeComparison(str, valuesEqual ? 0 : 1, valuesEqual); @@ -940,7 +976,7 @@ public static String deltaValueToPercentage(VType value, VType baseValue) { } /** - * Checks if the values of the given vtype are equal and returns true if they are or false if they are not. + * Checks if the values of the given {@link VType} are equal and returns true if they are or false if they are not. * Timestamps, alarms and other parameters are ignored. * * @param v1 the first value to check @@ -1128,11 +1164,62 @@ public static boolean areValuesEqual(VType v1, VType v2, Optional> } return true; } + else if(v1 instanceof VTable && v2 instanceof VTable){ + VTable vTable1 = (VTable)v1; + VTable vTable2 = (VTable)v2; + if(vTable1.getColumnCount() != vTable2.getColumnCount() || + vTable1.getRowCount() != vTable2.getRowCount()){ + return false; + } + for(int i = 0; i < vTable1.getColumnCount(); i++){ + if(!vTable1.getColumnType(i).equals(vTable2.getColumnType(i))){ + return false; + } + if(!vTable1.getColumnName(i).equals(vTable2.getColumnName(i))){ + return false; + } + if(!areVTypeArraysEqual(vTable1.getColumnType(i), vTable1.getColumnData(i), vTable2.getColumnData(i))){ + return false; + } + } + return true; + } // no support for MultiScalars (VMultiDouble, VMultiInt, VMultiString, VMultiEnum), VStatistics, VTable, // VImage return false; } + /** + * Compares objects based on the + * @param clazz + * @param a1 + * @param a2 + * @return + */ + public static boolean areVTypeArraysEqual(Class clazz, Object a1, Object a2){ + switch(clazz.getName()){ + case "int": + case "long": + case "double": + case "float": + case "short": + case "byte": + return areValuesEqual(VNumberArray.of((ListNumber) a1, Alarm.none(), Time.now(), Display.none()), + VNumberArray.of((ListNumber) a2, Alarm.none(), Time.now(), Display.none()), + Optional.empty()); + case "boolean": + return areValuesEqual(VBooleanArray.of((ListBoolean) a1, Alarm.none(), Time.now()), + VBooleanArray.of((ListBoolean) a2, Alarm.none(), Time.now()), + Optional.empty()); + case "java.lang.String": + return areValuesEqual(VStringArray.of((List) a1, Alarm.none(), Time.now()), + VStringArray.of((List) a2, Alarm.none(), Time.now()), + Optional.empty()); + default: + return false; + } + } + /** * Compares two instances of {@link VType} and returns true if they are identical or false of they are not. Values * are identical if their alarm signatures are identical, timestamps are the same, values are the same and in case diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotTableViewController.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotTableViewController.java index e84dcfb842..20842f739e 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotTableViewController.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotTableViewController.java @@ -369,7 +369,7 @@ public void restore(Snapshot snapshot, Consumer> completion) { } try { - countDownLatch.await(); + countDownLatch.await(10, TimeUnit.MINUTES); } catch (InterruptedException e) { LOGGER.log(Level.INFO, "Encountered InterruptedException", e); } diff --git a/app/save-and-restore/app/src/test/java/org/phoebus/applications/saveandrestore/ui/UtilitiesTest.java b/app/save-and-restore/app/src/test/java/org/phoebus/applications/saveandrestore/ui/UtilitiesTest.java index 5df126e743..4d5086ac06 100644 --- a/app/save-and-restore/app/src/test/java/org/phoebus/applications/saveandrestore/ui/UtilitiesTest.java +++ b/app/save-and-restore/app/src/test/java/org/phoebus/applications/saveandrestore/ui/UtilitiesTest.java @@ -18,12 +18,18 @@ package org.phoebus.applications.saveandrestore.ui; +import org.apache.xalan.xsltc.util.IntegerArray; +import org.epics.pva.data.PVAStringArray; +import org.epics.pva.data.nt.PVAAlarm; +import org.epics.pva.data.nt.PVATable; +import org.epics.pva.data.nt.PVATimeStamp; import org.epics.util.array.*; import org.epics.vtype.*; import org.junit.jupiter.api.Test; import java.time.temporal.ChronoUnit; import java.util.Arrays; +import java.util.List; import java.util.Optional; import static org.junit.jupiter.api.Assertions.*; @@ -1491,4 +1497,58 @@ public void testAreValuesEqual() { val2 = VStringArray.of(Arrays.asList("a", "b", "c"), alarm, time); assertTrue(Utilities.areValuesEqual(val1, val2, Optional.empty())); } + + @Test + public void testAreVTablesEqual(){ + + VTable vTable1 = VTable.of(List.of(Integer.TYPE, Double.TYPE), + List.of("a", "b"), + List.of(ArrayInteger.of(1, 2, 3), ArrayDouble.of(7.0, 8.0, 9.0))); + VTable vTable2 = VTable.of(List.of(Integer.TYPE, Double.TYPE), + List.of("a", "b"), + List.of(ArrayInteger.of(1, 2, 3), ArrayDouble.of(7.0, 8.0, 9.0))); + + assertTrue(Utilities.areValuesEqual(vTable1, vTable2, Optional.empty())); + + vTable2 = VTable.of(List.of(Integer.TYPE, Integer.TYPE), + List.of("a", "b"), + List.of(ArrayInteger.of(1, 2, 3), ArrayInteger.of(7, 8, 9))); + + assertFalse(Utilities.areValuesEqual(vTable1, vTable2, Optional.empty())); + + vTable2 = VTable.of(List.of(Integer.TYPE, Double.TYPE), + List.of("a", "b"), + List.of(ArrayInteger.of(1, 2, 3), ArrayDouble.of(7.0, 8.0))); + + assertFalse(Utilities.areValuesEqual(vTable1, vTable2, Optional.empty())); + + vTable1 = VTable.of(List.of(String.class, Double.TYPE), + List.of("a", "b"), + List.of(List.of("AAA", "BBB", "CCC"), ArrayDouble.of(7.0, 8.0, 9.0))); + + vTable2 = VTable.of(List.of(String.class, Double.TYPE), + List.of("a", "b"), + List.of(List.of("AAA", "BBB", "CCC"), ArrayDouble.of(7.0, 8.0, 9.0))); + + assertTrue(Utilities.areValuesEqual(vTable1, vTable2, Optional.empty())); + } + + @Test + public void testAreVTypeArraysEqual(){ + assertTrue(Utilities.areVTypeArraysEqual(Integer.TYPE, ArrayInteger.of(1, 2, 3), ArrayInteger.of(1, 2, 3))); + assertTrue(Utilities.areVTypeArraysEqual(Integer.TYPE, ArrayUInteger.of(1, 2, 3), ArrayUInteger.of(1, 2, 3))); + assertTrue(Utilities.areVTypeArraysEqual(Long.TYPE, ArrayLong.of(1L, 2L, 3L), ArrayLong.of(1L, 2L, 3L))); + assertTrue(Utilities.areVTypeArraysEqual(Long.TYPE, ArrayULong.of(1L, 2L, 3L), ArrayULong.of(1L, 2L, 3L))); + assertTrue(Utilities.areVTypeArraysEqual(Double.TYPE, ArrayDouble.of(7.0, 8.0, 9.0), ArrayDouble.of(7.0, 8.0, 9.0))); + assertTrue(Utilities.areVTypeArraysEqual(Float.TYPE, ArrayFloat.of(7.0f, 8.0f, 9.0f), ArrayFloat.of(7.0f, 8.0f, 9.0f))); + assertTrue(Utilities.areVTypeArraysEqual(Short.TYPE, ArrayShort.of((short)7.0, (short)8.0, (short)9.0), ArrayShort.of((short)7.0, (short)8.0, (short)9.0))); + assertTrue(Utilities.areVTypeArraysEqual(Short.TYPE, ArrayUShort.of((short)7.0, (short)8.0, (short)9.0), ArrayUShort.of((short)7.0, (short)8.0, (short)9.0))); + assertTrue(Utilities.areVTypeArraysEqual(Byte.TYPE, ArrayByte.of((byte)7, (byte)8, (byte)9), ArrayByte.of((byte)7, (byte)8, (byte)9))); + assertTrue(Utilities.areVTypeArraysEqual(Byte.TYPE, ArrayUByte.of((byte)7, (byte)8, (byte)9), ArrayUByte.of((byte)7, (byte)8, (byte)9))); + assertTrue(Utilities.areVTypeArraysEqual(Boolean.TYPE, ArrayBoolean.of(true, false), ArrayBoolean.of(true, false))); + + assertTrue(Utilities.areVTypeArraysEqual(String.class, List.of("AAA", "BBB", "CCC"), List.of("AAA", "BBB", "CCC"))); + + assertFalse(Utilities.areVTypeArraysEqual(Byte.TYPE, ArrayShort.of((byte)7, (byte)8, (byte)9), ArrayShort.of((byte)7, (byte)8, (byte)10))); + } } diff --git a/app/save-and-restore/common/pom.xml b/app/save-and-restore/common/pom.xml deleted file mode 100644 index 421f16f118..0000000000 --- a/app/save-and-restore/common/pom.xml +++ /dev/null @@ -1,107 +0,0 @@ - - - 4.0.0 - - - org.phoebus - app-save-and-restore - 4.7.3-SNAPSHOT - - - save-and-restore-common - - - - - org.phoebus - save-and-restore-model - 4.7.3-SNAPSHOT - - - - org.phoebus - core-vtype - 4.7.3-SNAPSHOT - - - - org.epics - vtype - ${vtype.version} - - - - org.phoebus - core-pv - 4.7.3-SNAPSHOT - - - - org.epics - vtype-json - ${vtype.version} - - - - org.epics - vtype-gson - ${vtype.version} - - - - - - org.junit.jupiter - junit-jupiter - ${junit.version} - test - - - - org.mockito - mockito-core - ${mockito.version} - test - - - - - - - - org.jacoco - jacoco-maven-plugin - 0.8.5 - - - default-prepare-agent - - prepare-agent - - - - default-report - prepare-package - - report - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 3.0.1 - - - - attach-javadocs - - jar - - - - - - - diff --git a/core/pv/src/main/java/org/phoebus/pv/pva/PVAStructureHelper.java b/core/pv/src/main/java/org/phoebus/pv/pva/PVAStructureHelper.java index a601da5f26..4010b2795c 100644 --- a/core/pv/src/main/java/org/phoebus/pv/pva/PVAStructureHelper.java +++ b/core/pv/src/main/java/org/phoebus/pv/pva/PVAStructureHelper.java @@ -253,6 +253,7 @@ public static PVATable fromVTable(VTable vTable) throws MustBeArrayException { builder.timeStamp(new PVATimeStamp(Instant.now())); List table = new ArrayList<>(); + int columnCount = vTable.getColumnCount(); String[] columnNames = new String[columnCount]; for(int i = 0; i < columnCount; i++){ @@ -261,6 +262,8 @@ public static PVATable fromVTable(VTable vTable) throws MustBeArrayException { PVAStringArray names = new PVAStringArray("labels", columnNames); //table.add(names); + builder.descriptor(""); + List valuesData = new ArrayList<>(); for(int i = 0; i < columnCount; i++){ Class clazz = vTable.getColumnType(i); @@ -272,15 +275,17 @@ public static PVATable fromVTable(VTable vTable) throws MustBeArrayException { } PVAIntArray ints = new PVAIntArray(i == 0 ? "A" : "B", false, integers); + //valuesData.add(ints); builder.addColumn(ints); + //builder.addColumn(ints); } } - PVAStructure valueStruct = new PVAStructure("value", "", valuesData); - //table.add(valueStruct); + PVAStructure valueStruct = new PVAStructure("value", "value", valuesData); + + builder.name("record"); + //builder.table(table); - builder.name(""); - //builder.table(valuesData); return builder.build(); } diff --git a/core/pva/src/main/java/org/epics/pva/data/PVAData.java b/core/pva/src/main/java/org/epics/pva/data/PVAData.java index 12a5594b12..1d52225527 100644 --- a/core/pva/src/main/java/org/epics/pva/data/PVAData.java +++ b/core/pva/src/main/java/org/epics/pva/data/PVAData.java @@ -22,7 +22,7 @@ public abstract class PVAData { /** Name */ - protected final String name; + protected String name; /** @param name Name for data item */ protected PVAData(final String name) diff --git a/core/pva/src/main/java/org/epics/pva/data/PVAStructure.java b/core/pva/src/main/java/org/epics/pva/data/PVAStructure.java index 73dbd5c574..8965ffa3cf 100644 --- a/core/pva/src/main/java/org/epics/pva/data/PVAStructure.java +++ b/core/pva/src/main/java/org/epics/pva/data/PVAStructure.java @@ -7,6 +7,8 @@ ******************************************************************************/ package org.epics.pva.data; +import org.epics.pva.data.nt.PVATable; + import static org.epics.pva.PVASettings.logger; import java.nio.ByteBuffer; @@ -68,7 +70,7 @@ static PVAStructure decodeType(final PVATypeRegistry types, final String name, f } /** Structure type name */ - private final String struct_name; + private String struct_name; /** Unmodifiable list of elements. * @@ -76,7 +78,7 @@ static PVAStructure decodeType(final PVATypeRegistry types, final String name, f * no elements can be added, removed, replaced. * */ - private final List elements; + private List elements; /** @param name Name of the structure (may be "") * @param struct_name Type name of the structure (may be "") @@ -109,8 +111,31 @@ public void setValue(final Object new_value) throws Exception if (! (new_value instanceof PVAStructure)) throw new Exception("Cannot set " + getStructureName() + " " + name + " to " + new_value); - final PVAStructure other = (PVAStructure) new_value; - final int N = elements.size(); + if(new_value instanceof PVATable){ + this.name = "value"; + this.struct_name = "structure"; + PVAInt pvaInt = new PVAInt("queueSize", true, 0); + PVABool pvaBool = new PVABool("atomic", false); + PVAStructure options = new PVAStructure("_options", "", List.of(pvaInt, pvaBool)); + PVAStructure record = new PVAStructure("record", "", List.of(options)); + /* + elements = new ArrayList<>(); + elements.add(record); + elements.add(((PVAStructure)new_value).elements.get(2)); + elements.add(((PVAStructure)new_value).elements.get(3)); + elements.add(((PVAStructure)new_value).elements.get(0)); + elements.add(((PVAStructure)new_value).elements.get(1)); + + */ + PVAStringArray a = new PVAStringArray("_0", "0", "1"); + PVAStringArray b = new PVAStringArray("_1", "6", "7"); + elements = List.of(a, b); + return; + } + + PVAStructure other = (PVAStructure) new_value; + int N = elements.size(); + if (other.elements.size() != N) throw new Exception("Incompatible structures, got " + other.elements.size() + " elements but expected " + N); for (int i=0; i Date: Mon, 2 Oct 2023 14:32:27 +0200 Subject: [PATCH 04/12] Parking WIP --- core/pva/src/main/java/org/epics/pva/data/PVAStructure.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/pva/src/main/java/org/epics/pva/data/PVAStructure.java b/core/pva/src/main/java/org/epics/pva/data/PVAStructure.java index 8965ffa3cf..5c091a71af 100644 --- a/core/pva/src/main/java/org/epics/pva/data/PVAStructure.java +++ b/core/pva/src/main/java/org/epics/pva/data/PVAStructure.java @@ -127,8 +127,8 @@ public void setValue(final Object new_value) throws Exception elements.add(((PVAStructure)new_value).elements.get(1)); */ - PVAStringArray a = new PVAStringArray("_0", "0", "1"); - PVAStringArray b = new PVAStringArray("_1", "6", "7"); + PVADoubleArray a = new PVADoubleArray("A", 0,1); + PVADoubleArray b = new PVADoubleArray("B", 6,7); elements = List.of(a, b); return; } From 8370889dee067eb767a75c0c724057585c01e235 Mon Sep 17 00:00:00 2001 From: georgweiss Date: Tue, 3 Oct 2023 11:19:08 +0200 Subject: [PATCH 05/12] Parking WIP --- .../main/java/org/epics/pva/client/PutRequest.java | 14 ++++++++++++++ .../main/java/org/epics/pva/data/PVABitSet.java | 3 ++- .../main/java/org/epics/pva/data/PVAStructure.java | 10 +++++++--- .../test/java/org/epics/pva/data/BitSetTest.java | 7 +++++++ 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/core/pva/src/main/java/org/epics/pva/client/PutRequest.java b/core/pva/src/main/java/org/epics/pva/client/PutRequest.java index b14400946a..2e1c4e4b57 100644 --- a/core/pva/src/main/java/org/epics/pva/client/PutRequest.java +++ b/core/pva/src/main/java/org/epics/pva/client/PutRequest.java @@ -11,6 +11,7 @@ import java.nio.ByteBuffer; import java.util.BitSet; +import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.logging.Level; @@ -111,6 +112,7 @@ public void encodeRequest(final byte version, final ByteBuffer buffer) throws Ex final int pos = buffer.position(); buffer.putInt(channel.getSID()); buffer.putInt(request_id); + //buffer.put((byte)0x04); buffer.put(PVAHeader.CMD_SUB_DESTROY); // Locate the field to write @@ -149,6 +151,15 @@ public void encodeRequest(final byte version, final ByteBuffer buffer) throws Ex // Bitset to describe which field we're about to write final BitSet changed = new BitSet(); changed.set(data.getIndex(field)); + if (field instanceof PVAStructure) { + final PVAStructure struct = (PVAStructure) field; + List elements = struct.getElements(); + if(elements != null){ + for(int i = 0; i < elements.size(); i++){ + changed.set(data.getIndex(elements.get(i))); + } + } + } logger.log(Level.FINE, () -> "Updated structure elements: " + changed); PVABitSet.encodeBitSet(changed, buffer); @@ -211,8 +222,11 @@ else if (subcmd == PVAHeader.CMD_SUB_DESTROY) // Indicate completion now that server confirmed PUT complete(null); } + /* else fail(new Exception("Cannot decode Put " + subcmd + " Reply #" + request_id)); + + */ } /** Handle failure by both notifying whoever waits for this request to complete diff --git a/core/pva/src/main/java/org/epics/pva/data/PVABitSet.java b/core/pva/src/main/java/org/epics/pva/data/PVABitSet.java index b51ffbea2f..64f2ee6206 100644 --- a/core/pva/src/main/java/org/epics/pva/data/PVABitSet.java +++ b/core/pva/src/main/java/org/epics/pva/data/PVABitSet.java @@ -22,7 +22,8 @@ public static void encodeBitSet(final BitSet bits, final ByteBuffer buffer) { final byte[] bytes = bits.toByteArray(); PVASize.encodeSize(bytes.length, buffer); - buffer.put(bits.toByteArray()); + byte[] b = bits.toByteArray(); + buffer.put(b); } /** @param buffer Source buffer diff --git a/core/pva/src/main/java/org/epics/pva/data/PVAStructure.java b/core/pva/src/main/java/org/epics/pva/data/PVAStructure.java index 5c091a71af..94208c7f5d 100644 --- a/core/pva/src/main/java/org/epics/pva/data/PVAStructure.java +++ b/core/pva/src/main/java/org/epics/pva/data/PVAStructure.java @@ -80,6 +80,10 @@ static PVAStructure decodeType(final PVATypeRegistry types, final String name, f */ private List elements; + public List getElements(){ + return elements; + } + /** @param name Name of the structure (may be "") * @param struct_name Type name of the structure (may be "") * @param elements Elements, must be named @@ -127,8 +131,8 @@ public void setValue(final Object new_value) throws Exception elements.add(((PVAStructure)new_value).elements.get(1)); */ - PVADoubleArray a = new PVADoubleArray("A", 0,1); - PVADoubleArray b = new PVADoubleArray("B", 6,7); + PVAIntArray a = new PVAIntArray("A", false, 0,1); + PVAIntArray b = new PVAIntArray("B", false, 6,7); elements = List.of(a, b); return; } @@ -410,7 +414,7 @@ public PVA get(final int index) * @param index Desired element index * @return Located {@link PVAData} or {@link Integer} for next i */ - private Object getElementOrNextIndex(int i, final int index) + public Object getElementOrNextIndex(int i, final int index) { // Does index refer to complete structure? if (i == index) diff --git a/core/pva/src/test/java/org/epics/pva/data/BitSetTest.java b/core/pva/src/test/java/org/epics/pva/data/BitSetTest.java index 37ac5d02b2..64892be4b0 100644 --- a/core/pva/src/test/java/org/epics/pva/data/BitSetTest.java +++ b/core/pva/src/test/java/org/epics/pva/data/BitSetTest.java @@ -58,6 +58,13 @@ public void testBitSet() buffer.flip(); System.out.println(Hexdump.toHexdump(buffer)); + bits.clear(); + bits.set(14); + buffer.clear(); + PVABitSet.encodeBitSet(bits, buffer); + buffer.flip(); + System.out.println(Hexdump.toHexdump(buffer)); + final BitSet copy = PVABitSet.decodeBitSet(buffer); assertThat(copy, equalTo(bits)); } From d6765ce7a718a9d51deaa20147a23fee64702598 Mon Sep 17 00:00:00 2001 From: georgweiss Date: Thu, 19 Oct 2023 14:51:02 +0200 Subject: [PATCH 06/12] Save&restore support for NTTables --- .../ui/SaveAndRestoreController.java | 2 +- .../saveandrestore/ui/Utilities.java | 113 +++++++++++----- .../ui/snapshot/SaveAndRestorePV.java | 2 +- .../saveandrestore/ui/UtilitiesTest.java | 127 +++++++++++++++++- .../phoebus/pv/pva/PVAStructureHelper.java | 67 +++------ 5 files changed, 226 insertions(+), 85 deletions(-) diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/SaveAndRestoreController.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/SaveAndRestoreController.java index eedbb968b4..dfd81ac409 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/SaveAndRestoreController.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/SaveAndRestoreController.java @@ -286,7 +286,7 @@ public Filter fromString(String s) { /** * Loads the data for the tree root as provided (persisted) by the current - * {@link org.phoebus.applications.saveandrestore.SaveAndRestoreClient}. + * {@link org.phoebus.applications.saveandrestore.client.SaveAndRestoreClient}. */ public void loadTreeData() { diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/Utilities.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/Utilities.java index 319b5b32de..47580b1856 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/Utilities.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/Utilities.java @@ -19,7 +19,9 @@ import org.epics.pva.data.*; import org.epics.pva.data.nt.PVAAlarm; +import org.epics.pva.data.nt.PVATable; import org.epics.pva.data.nt.PVATimeStamp; +import org.epics.pvdata.pv.PVULongArray; import org.epics.util.array.*; import org.epics.util.number.*; import org.epics.util.text.NumberFormats; @@ -286,7 +288,7 @@ public static VType valueFromString(String indata, VType type) throws IllegalArg /** * Extracts the raw value from the given data object. The raw value is either one of the primitive wrappers or some - * kind of a list type if the value is an {@link Array}. + * list type if the value is an {@link Array}. * * @param type the value to extract the raw data from * @return the raw data @@ -328,44 +330,19 @@ public static Object toRawValue(VType type) { } else if(type instanceof VTable) { VTable vTable = (VTable)type; - /* - PVAAlarm alarm = new PVAAlarm(); - PVATimeStamp time = new PVATimeStamp(Instant.now()); - PVAStringArray labels = new PVAStringArray("label", vTable.getColumnName(0), vTable.getColumnName(1)); - List data = new ArrayList<>(); - PVAIntArray d1 = null; - PVAIntArray d2 = null; - for(int i = 0; i < vTable.getColumnCount(); i++){ - ArrayInteger ai = (ArrayInteger)vTable.getColumnData(0); - int[] ii = new int[ai.size()]; - for(int j = 0; j < ai.size(); j++){ - ii[j] = ai.getInt(j); - } - if(i == 0){ - d1 = new PVAIntArray("A", false, ii); - } - if(i == 1){ - d2 = new PVAIntArray("B", false, ii); - } + int columnCount = vTable.getColumnCount(); + List dataArrays = new ArrayList(); + for(int i = 0; i < columnCount; i++){ + dataArrays.add(toPVArrayType(vTable.getColumnName(i), vTable.getColumnData(i))); } - PVAStructure value = new PVAStructure("value", "", data); - PVAStructure table = new PVAStructure("epics:nt/NTTable:1.0","", List.of(d1, d2)); + PVAStructure table = new PVAStructure(PVATable.STRUCT_NAME,"", dataArrays); return table; - */ - - try{ - return PVAStructureHelper.fromVTable((VTable) type); - } - catch (Exception e){ - e.printStackTrace(); - } - } return null; } /** - * Transforms the value of the given {@link VType} to a human readable string. This method uses formatting to format + * Transforms the value of the given {@link VType} to a human-readable string. This method uses formatting to format * all values, which may result in the arrays being truncated. * * @param type the data to transform @@ -1385,4 +1362,76 @@ private static boolean isAlarmAndTimeEqual(VType a1, VType a2) { } return false; } + + /** + * + * @param name + * @param object + * @return + */ + protected static Object toPVArrayType(String name, Object object) { + if (object instanceof ListBoolean) { + ListBoolean listBoolean = (ListBoolean) object; + boolean[] booleans = new boolean[listBoolean.size()]; + for (int i = 0; i < listBoolean.size(); i++) { + booleans[i] = listBoolean.getBoolean(i); + } + return new PVABoolArray(name, booleans); + } + else if (object instanceof ListNumber) { + ListNumber listNumber = (ListNumber) object; + if (object instanceof ArrayByte || object instanceof ArrayUByte) { + byte[] bytes = new byte[listNumber.size()]; + for (int i = 0; i < listNumber.size(); i++) { + bytes[i] = listNumber.getByte(i); + } + return new PVAByteArray(name, object instanceof ArrayUByte, bytes); + } else if (object instanceof ArrayShort || object instanceof ArrayUShort) { + short[] shorts = new short[listNumber.size()]; + for (int i = 0; i < listNumber.size(); i++) { + shorts[i] = listNumber.getShort(i); + } + return new PVAShortArray(name, object instanceof ArrayUShort, shorts); + } else if (object instanceof ArrayInteger || object instanceof ArrayUInteger) { + int[] ints = new int[listNumber.size()]; + for (int i = 0; i < listNumber.size(); i++) { + ints[i] = listNumber.getInt(i); + } + return new PVAIntArray(name, object instanceof ArrayUInteger, ints); + } else if (object instanceof ArrayUInteger) { + int[] ints = new int[listNumber.size()]; + for (int i = 0; i < listNumber.size(); i++) { + ints[i] = listNumber.getInt(i); + } + return new PVAIntArray(name, object instanceof ArrayUInteger, ints); + } else if (object instanceof ArrayLong || object instanceof ArrayULong) { + long[] longs = new long[listNumber.size()]; + for (int i = 0; i < listNumber.size(); i++) { + longs[i] = listNumber.getLong(i); + } + return new PVALongArray(name, object instanceof ArrayULong, longs); + } else if (object instanceof ArrayFloat) { + float[] floats = new float[listNumber.size()]; + for (int i = 0; i < listNumber.size(); i++) { + floats[i] = listNumber.getFloat(i); + } + return new PVAFloatArray(name, floats); + } else if (object instanceof ArrayDouble) { + double[] doubles = new double[listNumber.size()]; + for (int i = 0; i < listNumber.size(); i++) { + doubles[i] = listNumber.getDouble(i); + } + return new PVADoubleArray(name, doubles); + } + else { + throw new IllegalArgumentException("Conversion of type " + object.getClass().getCanonicalName() + " not supported"); + } + } + else { // Assume this always is for string arrays + Collection list = (Collection) object; + String[] strings = new String[list.size()]; + strings = list.toArray(strings); + return new PVAStringArray(name, strings); + } + } } diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SaveAndRestorePV.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SaveAndRestorePV.java index 450247cac7..37fd14c6e8 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SaveAndRestorePV.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SaveAndRestorePV.java @@ -73,7 +73,7 @@ protected SaveAndRestorePV(TableEntry snapshotTableEntry) { this.snapshotTableEntry.setReadbackValue(this.readbackValue); }); } else { - // If configuration does not define readback PV, then UI should show "no data" rather than "disconnected" + // If configuration does not define read-back PV, then UI should show "no data" rather than "disconnected" this.snapshotTableEntry.setReadbackValue(VNoData.INSTANCE); } } catch (Exception e) { diff --git a/app/save-and-restore/app/src/test/java/org/phoebus/applications/saveandrestore/ui/UtilitiesTest.java b/app/save-and-restore/app/src/test/java/org/phoebus/applications/saveandrestore/ui/UtilitiesTest.java index 4d5086ac06..496bd76cd9 100644 --- a/app/save-and-restore/app/src/test/java/org/phoebus/applications/saveandrestore/ui/UtilitiesTest.java +++ b/app/save-and-restore/app/src/test/java/org/phoebus/applications/saveandrestore/ui/UtilitiesTest.java @@ -19,7 +19,7 @@ package org.phoebus.applications.saveandrestore.ui; import org.apache.xalan.xsltc.util.IntegerArray; -import org.epics.pva.data.PVAStringArray; +import org.epics.pva.data.*; import org.epics.pva.data.nt.PVAAlarm; import org.epics.pva.data.nt.PVATable; import org.epics.pva.data.nt.PVATimeStamp; @@ -28,6 +28,7 @@ import org.junit.jupiter.api.Test; import java.time.temporal.ChronoUnit; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Optional; @@ -388,6 +389,31 @@ public void testToRawValue() { assertTrue(((Boolean) d)); assertNull(Utilities.toRawValue(VDisconnectedData.INSTANCE)); + + List> types = Arrays.asList(Integer.TYPE, Integer.TYPE, Integer.TYPE); + List values = Arrays.asList(ArrayInteger.of(-1, 2, 3), ArrayInteger.of(1, 2, 3), ArrayUInteger.of(11, 22, 33)); + List names = Arrays.asList("a", "b", "c"); + VTable vTable = VTable.of(types, names, values); + + d = Utilities.toRawValue(vTable); + assertInstanceOf(PVAStructure.class, d); + PVAStructure pvaStructure = (PVAStructure)d; + assertEquals(3, pvaStructure.getElements().size()); + assertInstanceOf(PVAIntArray.class, pvaStructure.getElements().get(0)); + assertInstanceOf(PVAIntArray.class, pvaStructure.getElements().get(1)); + assertInstanceOf(PVAIntArray.class, pvaStructure.getElements().get(2)); + + PVAIntArray pvaIntArray = (PVAIntArray) pvaStructure.getElements().get(0); + assertEquals(3, pvaIntArray.get().length); + assertArrayEquals(new int[]{-1, 2, 3}, pvaIntArray.get()); + pvaIntArray = (PVAIntArray) pvaStructure.getElements().get(1); + assertArrayEquals(new int[]{1, 2, 3}, pvaIntArray.get()); + assertEquals(3, pvaIntArray.get().length); + pvaIntArray = (PVAIntArray) pvaStructure.getElements().get(2); + assertArrayEquals(new int[]{11, 22, 33}, pvaIntArray.get()); + assertEquals(3, pvaIntArray.get().length); + + } @@ -1551,4 +1577,103 @@ public void testAreVTypeArraysEqual(){ assertFalse(Utilities.areVTypeArraysEqual(Byte.TYPE, ArrayShort.of((byte)7, (byte)8, (byte)9), ArrayShort.of((byte)7, (byte)8, (byte)10))); } + + @Test + public void testToPVArrayType(){ + + boolean[] bools = new boolean[]{true, false, true}; + Object converted = Utilities.toPVArrayType("bools", ArrayBoolean.of(bools)); + assertInstanceOf(PVABoolArray.class, converted); + assertEquals(3, ((PVABoolArray)converted).get().length); + assertArrayEquals(bools, ((PVABoolArray)converted).get()); + assertEquals("bools", ((PVABoolArray)converted).getName()); + + byte[] bytes = new byte[]{(byte)-1, (byte)2, (byte)3}; + converted = Utilities.toPVArrayType("bytes", ArrayByte.of(bytes)); + assertInstanceOf(PVAByteArray.class, converted); + assertEquals(3, ((PVAByteArray)converted).get().length); + assertArrayEquals(bytes, ((PVAByteArray)converted).get()); + assertEquals("bytes", ((PVAByteArray)converted).getName()); + assertFalse(((PVAByteArray)converted).isUnsigned()); + + bytes = new byte[]{(byte)1, (byte)2, (byte)3}; + converted = Utilities.toPVArrayType("ubytes", ArrayUByte.of(bytes)); + assertInstanceOf(PVAByteArray.class, converted); + assertEquals(3, ((PVAByteArray)converted).get().length); + assertArrayEquals(bytes, ((PVAByteArray)converted).get()); + assertEquals("ubytes", ((PVAByteArray)converted).getName()); + assertTrue(((PVAByteArray)converted).isUnsigned()); + + short[] shorts = new short[]{(short)-1, (short)2, (short)3}; + converted = Utilities.toPVArrayType("shorts", ArrayShort.of(shorts)); + assertInstanceOf(PVAShortArray.class, converted); + assertEquals(3, ((PVAShortArray)converted).get().length); + assertArrayEquals(shorts, ((PVAShortArray)converted).get()); + assertEquals("shorts", ((PVAShortArray)converted).getName()); + assertFalse(((PVAShortArray)converted).isUnsigned()); + + shorts = new short[]{(short)1, (short)2, (short)3}; + converted = Utilities.toPVArrayType("ushorts", ArrayUShort.of(shorts)); + assertInstanceOf(PVAShortArray.class, converted); + assertEquals(3, ((PVAShortArray)converted).get().length); + assertArrayEquals(shorts, ((PVAShortArray)converted).get()); + assertEquals("ushorts", ((PVAShortArray)converted).getName()); + assertTrue(((PVAShortArray)converted).isUnsigned()); + + int[] ints = new int[]{-1, 2, 3}; + converted = Utilities.toPVArrayType("ints", ArrayInteger.of(ints)); + assertInstanceOf(PVAIntArray.class, converted); + assertEquals(3, ((PVAIntArray)converted).get().length); + assertArrayEquals(ints, ((PVAIntArray)converted).get()); + assertEquals("ints", ((PVAIntArray)converted).getName()); + assertFalse(((PVAIntArray)converted).isUnsigned()); + + ints = new int[]{1, 2, 3}; + converted = Utilities.toPVArrayType("uints", ArrayUInteger.of(ints)); + assertInstanceOf(PVAIntArray.class, converted); + assertEquals(3, ((PVAIntArray)converted).get().length); + assertArrayEquals(ints, ((PVAIntArray)converted).get()); + assertEquals("uints", ((PVAIntArray)converted).getName()); + assertTrue(((PVAIntArray)converted).isUnsigned()); + + long[] longs = new long[]{-1L, 2L, 3L}; + converted = Utilities.toPVArrayType("longs", ArrayLong.of(longs)); + assertInstanceOf(PVALongArray.class, converted); + assertEquals(3, ((PVALongArray)converted).get().length); + assertArrayEquals(longs, ((PVALongArray)converted).get()); + assertEquals("longs", ((PVALongArray)converted).getName()); + assertFalse(((PVALongArray)converted).isUnsigned()); + + longs = new long[]{1L, 2L, 3L}; + converted = Utilities.toPVArrayType("ulongs", ArrayULong.of(longs)); + assertInstanceOf(PVALongArray.class, converted); + assertEquals(3, ((PVALongArray)converted).get().length); + assertArrayEquals(longs, ((PVALongArray)converted).get()); + assertEquals("ulongs", ((PVALongArray)converted).getName()); + assertTrue(((PVALongArray)converted).isUnsigned()); + + float[] floats = new float[]{-1.0f, 2.0f, 3.0f}; + converted = Utilities.toPVArrayType("floats", ArrayFloat.of(floats)); + assertInstanceOf(PVAFloatArray.class, converted); + assertEquals(3, ((PVAFloatArray)converted).get().length); + assertArrayEquals(floats, ((PVAFloatArray)converted).get()); + assertEquals("floats", ((PVAFloatArray)converted).getName()); + + double[] doubles = new double[]{-1.0, 2.0, 3.0}; + converted = Utilities.toPVArrayType("doubles", ArrayDouble.of(doubles)); + assertInstanceOf(PVADoubleArray.class, converted); + assertEquals(3, ((PVADoubleArray)converted).get().length); + assertArrayEquals(doubles, ((PVADoubleArray)converted).get()); + assertEquals("doubles", ((PVADoubleArray)converted).getName()); + + List strings = new ArrayList<>(); + strings.add("a"); + strings.add("b"); + strings.add("c"); + converted = Utilities.toPVArrayType("strings", strings); + assertInstanceOf(PVAStringArray.class, converted); + assertEquals(3, ((PVAStringArray)converted).get().length); + assertArrayEquals(new String[]{"a", "b", "c"}, ((PVAStringArray)converted).get()); + assertEquals("strings", ((PVAStringArray)converted).getName()); + } } diff --git a/core/pv/src/main/java/org/phoebus/pv/pva/PVAStructureHelper.java b/core/pv/src/main/java/org/phoebus/pv/pva/PVAStructureHelper.java index 4010b2795c..3d5f8d4d74 100644 --- a/core/pv/src/main/java/org/phoebus/pv/pva/PVAStructureHelper.java +++ b/core/pv/src/main/java/org/phoebus/pv/pva/PVAStructureHelper.java @@ -12,17 +12,27 @@ import static org.phoebus.pv.pva.Decoders.decodeAlarm; import static org.phoebus.pv.pva.Decoders.decodeTime; -import java.time.Instant; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Optional; -import org.epics.pva.data.*; -import org.epics.pva.data.nt.MustBeArrayException; -import org.epics.pva.data.nt.PVAAlarm; -import org.epics.pva.data.nt.PVATable; -import org.epics.pva.data.nt.PVATimeStamp; +import org.epics.pva.data.PVAArray; +import org.epics.pva.data.PVABool; +import org.epics.pva.data.PVABoolArray; +import org.epics.pva.data.PVAByteArray; +import org.epics.pva.data.PVAData; +import org.epics.pva.data.PVADoubleArray; +import org.epics.pva.data.PVAFloatArray; +import org.epics.pva.data.PVAIntArray; +import org.epics.pva.data.PVALongArray; +import org.epics.pva.data.PVANumber; +import org.epics.pva.data.PVAShortArray; +import org.epics.pva.data.PVAString; +import org.epics.pva.data.PVAStringArray; +import org.epics.pva.data.PVAStructure; +import org.epics.pva.data.PVAStructureArray; +import org.epics.pva.data.PVAUnion; import org.epics.util.array.ArrayByte; import org.epics.util.array.ArrayDouble; import org.epics.util.array.ArrayFloat; @@ -45,7 +55,6 @@ import org.epics.vtype.VStringArray; import org.epics.vtype.VTable; import org.epics.vtype.VType; -import org.phoebus.core.vtypes.VTypeHelper; /** Helper for handling 'structure' type PVA data */ @SuppressWarnings("nls") @@ -238,7 +247,7 @@ else if (column instanceof PVABoolArray) // Convert to boxed Integer to add to List values.add(range(0, data.length).mapToObj(i -> data[i]).collect(toList())); } - else + else { throw new IllegalArgumentException("Could not decode table column of type: " + column.getClass()); } @@ -247,48 +256,6 @@ else if (column instanceof PVABoolArray) return VTable.of(types, names, values); } - public static PVATable fromVTable(VTable vTable) throws MustBeArrayException { - PVATable.PVATableBuilder builder = PVATable.PVATableBuilder.aPVATable(); - builder.alarm(new PVAAlarm()); - builder.timeStamp(new PVATimeStamp(Instant.now())); - List table = new ArrayList<>(); - - - int columnCount = vTable.getColumnCount(); - String[] columnNames = new String[columnCount]; - for(int i = 0; i < columnCount; i++){ - columnNames[i] = vTable.getColumnName(i); - } - PVAStringArray names = new PVAStringArray("labels", columnNames); - //table.add(names); - - builder.descriptor(""); - - List valuesData = new ArrayList<>(); - for(int i = 0; i < columnCount; i++){ - Class clazz = vTable.getColumnType(i); - if(clazz.equals(Integer.TYPE)){ - ArrayInteger arrayInteger = (ArrayInteger) vTable.getColumnData(i); - int[] integers = new int[arrayInteger.size()]; - for(int j = 0; j < arrayInteger.size(); j++){ - integers[j] = arrayInteger.getInt(j); - } - PVAIntArray ints = - new PVAIntArray(i == 0 ? "A" : "B", false, integers); - //valuesData.add(ints); - builder.addColumn(ints); - //builder.addColumn(ints); - } - } - - PVAStructure valueStruct = new PVAStructure("value", "value", valuesData); - - builder.name("record"); - //builder.table(table); - - return builder.build(); - } - /** Decode 'value', 'timeStamp', 'alarm' of NTArray * @param struct * @return From cf5573f7f5cf1d865aa086cf8de3ce34083eab41 Mon Sep 17 00:00:00 2001 From: georgweiss Date: Thu, 19 Oct 2023 14:57:48 +0200 Subject: [PATCH 07/12] Reverting unneeded changes --- .../java/org/epics/pva/data/PVAStructure.java | 39 +++---------------- 1 file changed, 5 insertions(+), 34 deletions(-) diff --git a/core/pva/src/main/java/org/epics/pva/data/PVAStructure.java b/core/pva/src/main/java/org/epics/pva/data/PVAStructure.java index 29082558bf..6f0c424188 100644 --- a/core/pva/src/main/java/org/epics/pva/data/PVAStructure.java +++ b/core/pva/src/main/java/org/epics/pva/data/PVAStructure.java @@ -7,8 +7,6 @@ ******************************************************************************/ package org.epics.pva.data; -import org.epics.pva.data.nt.PVATable; - import static org.epics.pva.PVASettings.logger; import java.nio.ByteBuffer; @@ -70,7 +68,7 @@ static PVAStructure decodeType(final PVATypeRegistry types, final String name, f } /** Structure type name */ - private String struct_name; + private final String struct_name; /** Unmodifiable list of elements. * @@ -78,11 +76,7 @@ static PVAStructure decodeType(final PVATypeRegistry types, final String name, f * no elements can be added, removed, replaced. * */ - private List elements; - - public List getElements(){ - return elements; - } + private final List elements; /** @param name Name of the structure (may be "") @@ -116,31 +110,8 @@ public void setValue(final Object new_value) throws Exception if (! (new_value instanceof PVAStructure)) throw new Exception("Cannot set " + getStructureName() + " " + name + " to " + new_value); - if(new_value instanceof PVATable){ - this.name = "value"; - this.struct_name = "structure"; - PVAInt pvaInt = new PVAInt("queueSize", true, 0); - PVABool pvaBool = new PVABool("atomic", false); - PVAStructure options = new PVAStructure("_options", "", List.of(pvaInt, pvaBool)); - PVAStructure record = new PVAStructure("record", "", List.of(options)); - /* - elements = new ArrayList<>(); - elements.add(record); - elements.add(((PVAStructure)new_value).elements.get(2)); - elements.add(((PVAStructure)new_value).elements.get(3)); - elements.add(((PVAStructure)new_value).elements.get(0)); - elements.add(((PVAStructure)new_value).elements.get(1)); - - */ - PVAIntArray a = new PVAIntArray("A", false, 0,1); - PVAIntArray b = new PVAIntArray("B", false, 6,7); - elements = List.of(a, b); - return; - } - - PVAStructure other = (PVAStructure) new_value; - int N = elements.size(); - + final PVAStructure other = (PVAStructure) new_value; + final int N = elements.size(); if (other.elements.size() != N) throw new Exception("Incompatible structures, got " + other.elements.size() + " elements but expected " + N); for (int i=0; i PVA get(final int index) * @param index Desired element index * @return Located {@link PVAData} or {@link Integer} for next i */ - public Object getElementOrNextIndex(int i, final int index) + private Object getElementOrNextIndex(int i, final int index) { // Does index refer to complete structure? if (i == index) From ba0a3bfba34b711201ba12e8c5c573cf4f582684 Mon Sep 17 00:00:00 2001 From: georgweiss Date: Thu, 19 Oct 2023 15:29:52 +0200 Subject: [PATCH 08/12] Syncing with master and cleaning up some code --- .../saveandrestore/ui/UtilitiesTest.java | 214 +++++++++--------- .../java/org/epics/pva/client/PutRequest.java | 2 +- 2 files changed, 105 insertions(+), 111 deletions(-) diff --git a/app/save-and-restore/app/src/test/java/org/phoebus/applications/saveandrestore/ui/UtilitiesTest.java b/app/save-and-restore/app/src/test/java/org/phoebus/applications/saveandrestore/ui/UtilitiesTest.java index 496bd76cd9..68b753c8c2 100644 --- a/app/save-and-restore/app/src/test/java/org/phoebus/applications/saveandrestore/ui/UtilitiesTest.java +++ b/app/save-and-restore/app/src/test/java/org/phoebus/applications/saveandrestore/ui/UtilitiesTest.java @@ -18,11 +18,7 @@ package org.phoebus.applications.saveandrestore.ui; -import org.apache.xalan.xsltc.util.IntegerArray; import org.epics.pva.data.*; -import org.epics.pva.data.nt.PVAAlarm; -import org.epics.pva.data.nt.PVATable; -import org.epics.pva.data.nt.PVATimeStamp; import org.epics.util.array.*; import org.epics.vtype.*; import org.junit.jupiter.api.Test; @@ -221,7 +217,7 @@ public void testValueFromString() { Utilities.valueFromString("invalid", val); fail("Should throw exception"); } catch (IllegalArgumentException e) { - e.printStackTrace(); + // Ignore } val = VBoolean.of(false, alarm, time); @@ -287,12 +283,12 @@ public void testValueFromString() { val = VLongArray.of(ArrayLong.of(1, 2, 3, 4, 5), alarm, time, display); result = Utilities.valueFromString("1, 2, 3, 4, 5", val); assertTrue(result instanceof VLongArray); - assertTrue(((VLongArray) result).getData() instanceof ListLong); + assertNotNull(((VLongArray) result).getData()); val = VBooleanArray.of(ArrayBoolean.of(true, true, false, true), alarm, time); result = Utilities.valueFromString("[1, 1, 0, 2]", val); assertTrue(result instanceof VBooleanArray); - assertTrue(((VBooleanArray) result).getData() instanceof ListBoolean); + assertNotNull(((VBooleanArray) result).getData()); val = VDisconnectedData.INSTANCE; result = Utilities.valueFromString("5", val); @@ -397,23 +393,21 @@ public void testToRawValue() { d = Utilities.toRawValue(vTable); assertInstanceOf(PVAStructure.class, d); - PVAStructure pvaStructure = (PVAStructure)d; - assertEquals(3, pvaStructure.getElements().size()); - assertInstanceOf(PVAIntArray.class, pvaStructure.getElements().get(0)); - assertInstanceOf(PVAIntArray.class, pvaStructure.getElements().get(1)); - assertInstanceOf(PVAIntArray.class, pvaStructure.getElements().get(2)); + PVAStructure pvaStructure = (PVAStructure) d; + assertEquals(3, pvaStructure.get().size()); + assertInstanceOf(PVAIntArray.class, pvaStructure.get().get(0)); + assertInstanceOf(PVAIntArray.class, pvaStructure.get().get(1)); + assertInstanceOf(PVAIntArray.class, pvaStructure.get().get(2)); - PVAIntArray pvaIntArray = (PVAIntArray) pvaStructure.getElements().get(0); + PVAIntArray pvaIntArray = (PVAIntArray) pvaStructure.get().get(0); assertEquals(3, pvaIntArray.get().length); assertArrayEquals(new int[]{-1, 2, 3}, pvaIntArray.get()); - pvaIntArray = (PVAIntArray) pvaStructure.getElements().get(1); + pvaIntArray = (PVAIntArray) pvaStructure.get().get(1); assertArrayEquals(new int[]{1, 2, 3}, pvaIntArray.get()); assertEquals(3, pvaIntArray.get().length); - pvaIntArray = (PVAIntArray) pvaStructure.getElements().get(2); + pvaIntArray = (PVAIntArray) pvaStructure.get().get(2); assertArrayEquals(new int[]{11, 22, 33}, pvaIntArray.get()); assertEquals(3, pvaIntArray.get().length); - - } @@ -466,7 +460,7 @@ public void testValueToCompareString() { val1 = VDouble.of(5d, alarm, time, display); VType val2 = VDouble.of(6d, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, threshold); - assertEquals("5 \u0394-1.0", result.getString()); + assertEquals("5 Δ-1.0", result.getString()); assertTrue(result.getValuesEqual() < 0); assertTrue(result.isWithinThreshold()); assertEquals(1, result.getAbsoluteDelta(), 0.0); @@ -474,7 +468,7 @@ public void testValueToCompareString() { val1 = VDouble.of(15d, alarm, time, display); val2 = VDouble.of(6d, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, threshold); - assertEquals("15 \u0394+9.0", result.getString()); + assertEquals("15 Δ+9.0", result.getString()); assertTrue(result.getValuesEqual() > 0); assertFalse(result.isWithinThreshold()); assertEquals(9, result.getAbsoluteDelta(), 0.0); @@ -482,7 +476,7 @@ public void testValueToCompareString() { val1 = VFloat.of(15f, alarm, time, display); val2 = VFloat.of(6f, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, threshold); - assertEquals("15 \u0394+9.0", result.getString()); + assertEquals("15 Δ+9.0", result.getString()); assertTrue(result.getValuesEqual() > 0); assertFalse(result.isWithinThreshold()); assertEquals(9, result.getAbsoluteDelta(), 0.0); @@ -490,7 +484,7 @@ public void testValueToCompareString() { val1 = VDouble.of(6d, alarm, time, display); val2 = VDouble.of(6d, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, threshold); - assertEquals("6 \u03940.0", result.getString()); + assertEquals("6 Δ0.0", result.getString()); assertEquals(0, result.getValuesEqual()); assertTrue(result.isWithinThreshold()); assertEquals(0, result.getAbsoluteDelta(), 0.0); @@ -498,7 +492,7 @@ public void testValueToCompareString() { val1 = VFloat.of(5f, alarm, time, display); val2 = VFloat.of(6f, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, threshold); - assertEquals("5 \u0394-1.0", result.getString()); + assertEquals("5 Δ-1.0", result.getString()); assertTrue(result.getValuesEqual() < 0); assertTrue(result.isWithinThreshold()); assertEquals(1, result.getAbsoluteDelta(), 0.0); @@ -506,7 +500,7 @@ public void testValueToCompareString() { val1 = VFloat.of(5f, alarm, time, display); val2 = VFloat.of(6f, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, Optional.empty()); - assertEquals("5 \u0394-1.0", result.getString()); + assertEquals("5 Δ-1.0", result.getString()); assertTrue(result.getValuesEqual() < 0); assertFalse(result.isWithinThreshold()); assertEquals(1, result.getAbsoluteDelta(), 0.0); @@ -514,7 +508,7 @@ public void testValueToCompareString() { val1 = VFloat.of(5f, alarm, time, display); val2 = VFloat.of(6f, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, Optional.empty()); - assertEquals("5 \u0394-1.0", result.getString()); + assertEquals("5 Δ-1.0", result.getString()); assertTrue(result.getValuesEqual() < 0); assertFalse(result.isWithinThreshold()); assertEquals(1, result.getAbsoluteDelta(), 0.0); @@ -523,14 +517,14 @@ public void testValueToCompareString() { val1 = VLong.of(15L, alarm, time, display); val2 = VDouble.of(6d, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, threshold); - assertEquals("15 \u0394+9", result.getString()); + assertEquals("15 Δ+9", result.getString()); assertTrue(result.getValuesEqual() > 0); assertFalse(result.isWithinThreshold()); val1 = VLong.of(15L, alarm, time, display); val2 = VDouble.of(6d, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, Optional.empty()); - assertEquals("15 \u0394+9", result.getString()); + assertEquals("15 Δ+9", result.getString()); assertTrue(result.getValuesEqual() > 0); assertFalse(result.isWithinThreshold()); assertEquals(9, result.getAbsoluteDelta(), 0.0); @@ -538,7 +532,7 @@ public void testValueToCompareString() { val1 = VULong.of(15L, alarm, time, display); val2 = VULong.of(6L, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, threshold); - assertEquals("15 \u0394+9", result.getString()); + assertEquals("15 Δ+9", result.getString()); assertTrue(result.getValuesEqual() > 0); assertFalse(result.isWithinThreshold()); assertEquals(9, result.getAbsoluteDelta(), 0.0); @@ -546,7 +540,7 @@ public void testValueToCompareString() { val1 = VULong.of(5L, alarm, time, display); val2 = VULong.of(6L, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, Optional.empty()); - assertEquals("5 \u0394-1", result.getString()); + assertEquals("5 Δ-1", result.getString()); assertTrue(result.getValuesEqual() < 0); assertFalse(result.isWithinThreshold()); assertEquals(1, result.getAbsoluteDelta(), 0.0); @@ -554,7 +548,7 @@ public void testValueToCompareString() { val1 = VUInt.of(15, alarm, time, display); val2 = VUInt.of(6, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, threshold); - assertEquals("15 \u0394+9", result.getString()); + assertEquals("15 Δ+9", result.getString()); assertTrue(result.getValuesEqual() > 0); assertFalse(result.isWithinThreshold()); assertEquals(9, result.getAbsoluteDelta(), 0.0); @@ -562,7 +556,7 @@ public void testValueToCompareString() { val1 = VUInt.of(15, alarm, time, display); val2 = VUInt.of(6, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, Optional.empty()); - assertEquals("15 \u0394+9", result.getString()); + assertEquals("15 Δ+9", result.getString()); assertTrue(result.getValuesEqual() > 0); assertFalse(result.isWithinThreshold()); assertEquals(9, result.getAbsoluteDelta(), 0.0); @@ -570,7 +564,7 @@ public void testValueToCompareString() { val1 = VInt.of(15, alarm, time, display); val2 = VInt.of(6, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, Optional.empty()); - assertEquals("15 \u0394+9", result.getString()); + assertEquals("15 Δ+9", result.getString()); assertTrue(result.getValuesEqual() > 0); assertFalse(result.isWithinThreshold()); assertEquals(9, result.getAbsoluteDelta(), 0.0); @@ -578,7 +572,7 @@ public void testValueToCompareString() { val1 = VDouble.of(15d, alarm, time, display); val2 = VLong.of(6L, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, threshold); - assertEquals("15 \u0394+9.0", result.getString()); + assertEquals("15 Δ+9.0", result.getString()); assertTrue(result.getValuesEqual() > 0); assertFalse(result.isWithinThreshold()); assertEquals(9, result.getAbsoluteDelta(), 0.0); @@ -586,7 +580,7 @@ public void testValueToCompareString() { val1 = VDouble.of(15d, alarm, time, display); val2 = VLong.of(6L, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, Optional.empty()); - assertEquals("15 \u0394+9.0", result.getString()); + assertEquals("15 Δ+9.0", result.getString()); assertTrue(result.getValuesEqual() > 0); assertFalse(result.isWithinThreshold()); assertEquals(9, result.getAbsoluteDelta(), 0.0); @@ -594,7 +588,7 @@ public void testValueToCompareString() { val1 = VDouble.of(15d, alarm, time, display); val2 = VLong.of(15L, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, Optional.empty()); - assertEquals("15 \u03940.0", result.getString()); + assertEquals("15 Δ0.0", result.getString()); assertEquals(0, result.getValuesEqual()); assertTrue(result.isWithinThreshold()); assertEquals(0, result.getAbsoluteDelta(), 0.0); @@ -627,7 +621,7 @@ public void testValueToCompareString() { val1 = VLong.of(6L, alarm, time, display); val2 = VLong.of(6L, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, threshold); - assertEquals("6 \u03940", result.getString()); + assertEquals("6 Δ0", result.getString()); assertEquals(0, result.getValuesEqual()); assertTrue(result.isWithinThreshold()); assertEquals(0, result.getAbsoluteDelta(), 0.0); @@ -635,7 +629,7 @@ public void testValueToCompareString() { val1 = VLong.of(5L, alarm, time, display); val2 = VLong.of(6L, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, threshold); - assertEquals("5 \u0394-1", result.getString()); + assertEquals("5 Δ-1", result.getString()); assertTrue(result.getValuesEqual() < 0); assertTrue(result.isWithinThreshold()); assertEquals(1, result.getAbsoluteDelta(), 0.0); @@ -643,7 +637,7 @@ public void testValueToCompareString() { val1 = VLong.of(6L, alarm, time, display); val2 = VLong.of(5L, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, threshold); - assertEquals("6 \u0394+1", result.getString()); + assertEquals("6 Δ+1", result.getString()); assertTrue(result.getValuesEqual() > 0); assertTrue(result.isWithinThreshold()); assertEquals(1, result.getAbsoluteDelta(), 0.0); @@ -652,7 +646,7 @@ public void testValueToCompareString() { val1 = VInt.of(6, alarm, time, display); val2 = VInt.of(6, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, threshold); - assertEquals("6 \u03940", result.getString()); + assertEquals("6 Δ0", result.getString()); assertEquals(0, result.getValuesEqual()); assertTrue(result.isWithinThreshold()); assertEquals(0, result.getAbsoluteDelta(), 0.0); @@ -660,7 +654,7 @@ public void testValueToCompareString() { val1 = VInt.of(5, alarm, time, display); val2 = VInt.of(6, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, threshold); - assertEquals("5 \u0394-1", result.getString()); + assertEquals("5 Δ-1", result.getString()); assertTrue(result.getValuesEqual() < 0); assertTrue(result.isWithinThreshold()); assertEquals(1, result.getAbsoluteDelta(), 0.0); @@ -668,7 +662,7 @@ public void testValueToCompareString() { val1 = VInt.of(6, alarm, time, display); val2 = VInt.of(5, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, threshold); - assertEquals("6 \u0394+1", result.getString()); + assertEquals("6 Δ+1", result.getString()); assertTrue(result.getValuesEqual() > 0); assertTrue(result.isWithinThreshold()); @@ -676,14 +670,14 @@ public void testValueToCompareString() { val1 = VShort.of((short) 6, alarm, time, display); val2 = VShort.of((short) 6, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, threshold); - assertEquals("6 \u03940", result.getString()); + assertEquals("6 Δ0", result.getString()); assertEquals(0, result.getValuesEqual()); assertTrue(result.isWithinThreshold()); val1 = VShort.of((short) 5, alarm, time, display); val2 = VShort.of((short) 6, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, threshold); - assertEquals("5 \u0394-1", result.getString()); + assertEquals("5 Δ-1", result.getString()); assertTrue(result.getValuesEqual() < 0); assertTrue(result.isWithinThreshold()); assertEquals(1, result.getAbsoluteDelta(), 0.0); @@ -691,7 +685,7 @@ public void testValueToCompareString() { val1 = VShort.of((short) 6, alarm, time, display); val2 = VShort.of((short) 5, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, threshold); - assertEquals("6 \u0394+1", result.getString()); + assertEquals("6 Δ+1", result.getString()); assertTrue(result.getValuesEqual() > 0); assertTrue(result.isWithinThreshold()); assertEquals(1, result.getAbsoluteDelta(), 0.0); @@ -699,7 +693,7 @@ public void testValueToCompareString() { val1 = VUShort.of((short) 6, alarm, time, display); val2 = VUShort.of((short) 5, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, threshold); - assertEquals("6 \u0394+1", result.getString()); + assertEquals("6 Δ+1", result.getString()); assertTrue(result.getValuesEqual() > 0); assertTrue(result.isWithinThreshold()); assertEquals(1, result.getAbsoluteDelta(), 0.0); @@ -707,7 +701,7 @@ public void testValueToCompareString() { val1 = VUShort.of((short) 6, alarm, time, display); val2 = VUShort.of((short) 6, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, threshold); - assertEquals("6 \u03940", result.getString()); + assertEquals("6 Δ0", result.getString()); assertEquals(0, result.getValuesEqual()); assertTrue(result.isWithinThreshold()); assertEquals(0, result.getAbsoluteDelta(), 0.0); @@ -715,7 +709,7 @@ public void testValueToCompareString() { val1 = VUShort.of((short) 5, alarm, time, display); val2 = VUShort.of((short) 6, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, threshold); - assertEquals("5 \u0394-1", result.getString()); + assertEquals("5 Δ-1", result.getString()); assertTrue(result.getValuesEqual() < 0); assertTrue(result.isWithinThreshold()); assertEquals(1, result.getAbsoluteDelta(), 0.0); @@ -723,7 +717,7 @@ public void testValueToCompareString() { val1 = VShort.of((short) 5, alarm, time, display); val2 = VShort.of((short) 6, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, Optional.empty()); - assertEquals("5 \u0394-1", result.getString()); + assertEquals("5 Δ-1", result.getString()); assertTrue(result.getValuesEqual() < 0); assertFalse(result.isWithinThreshold()); assertEquals(1, result.getAbsoluteDelta(), 0.0); @@ -731,7 +725,7 @@ public void testValueToCompareString() { val1 = VUShort.of((short) 5, alarm, time, display); val2 = VUShort.of((short) 6, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, Optional.empty()); - assertEquals("5 \u0394-1", result.getString()); + assertEquals("5 Δ-1", result.getString()); assertTrue(result.getValuesEqual() < 0); assertFalse(result.isWithinThreshold()); assertEquals(1, result.getAbsoluteDelta(), 0.0); @@ -766,7 +760,7 @@ public void testValueToCompareString() { val1 = VByte.of((byte) 5, alarm, time, display); val2 = VByte.of((byte) 6, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, threshold); - assertEquals("5 \u0394-1", result.getString()); + assertEquals("5 Δ-1", result.getString()); assertTrue(result.getValuesEqual() < 0); assertTrue(result.isWithinThreshold()); assertEquals(1, result.getAbsoluteDelta(), 0.0); @@ -774,7 +768,7 @@ public void testValueToCompareString() { val1 = VByte.of((byte) 6, alarm, time, display); val2 = VByte.of((byte) 5, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, threshold); - assertEquals("6 \u0394+1", result.getString()); + assertEquals("6 Δ+1", result.getString()); assertTrue(result.getValuesEqual() > 0); assertTrue(result.isWithinThreshold()); assertEquals(1, result.getAbsoluteDelta(), 0.0); @@ -782,7 +776,7 @@ public void testValueToCompareString() { val1 = VByte.of((byte) 6, alarm, time, display); val2 = VByte.of((byte) 5, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, Optional.empty()); - assertEquals("6 \u0394+1", result.getString()); + assertEquals("6 Δ+1", result.getString()); assertTrue(result.getValuesEqual() > 0); assertFalse(result.isWithinThreshold()); assertEquals(1, result.getAbsoluteDelta(), 0.0); @@ -790,7 +784,7 @@ public void testValueToCompareString() { val1 = VUByte.of((byte) 5, alarm, time, display); val2 = VUByte.of((byte) 6, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, threshold); - assertEquals("5 \u0394-1", result.getString()); + assertEquals("5 Δ-1", result.getString()); assertTrue(result.getValuesEqual() < 0); assertTrue(result.isWithinThreshold()); assertEquals(1, result.getAbsoluteDelta(), 0.0); @@ -798,14 +792,14 @@ public void testValueToCompareString() { val1 = VUByte.of((byte) 6, alarm, time, display); val2 = VUByte.of((byte) 5, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, threshold); - assertEquals("6 \u0394+1", result.getString()); + assertEquals("6 Δ+1", result.getString()); assertTrue(result.getValuesEqual() > 0); assertTrue(result.isWithinThreshold()); val1 = VUByte.of((byte) 6, alarm, time, display); val2 = VUByte.of((byte) 5, alarm, time, display); result = Utilities.valueToCompareString(val1, val2, Optional.empty()); - assertEquals("6 \u0394+1", result.getString()); + assertEquals("6 Δ+1", result.getString()); assertTrue(result.getValuesEqual() > 0); assertFalse(result.isWithinThreshold()); assertEquals(1, result.getAbsoluteDelta(), 0.0); @@ -1525,7 +1519,7 @@ public void testAreValuesEqual() { } @Test - public void testAreVTablesEqual(){ + public void testAreVTablesEqual() { VTable vTable1 = VTable.of(List.of(Integer.TYPE, Double.TYPE), List.of("a", "b"), @@ -1560,111 +1554,111 @@ public void testAreVTablesEqual(){ } @Test - public void testAreVTypeArraysEqual(){ + public void testAreVTypeArraysEqual() { assertTrue(Utilities.areVTypeArraysEqual(Integer.TYPE, ArrayInteger.of(1, 2, 3), ArrayInteger.of(1, 2, 3))); assertTrue(Utilities.areVTypeArraysEqual(Integer.TYPE, ArrayUInteger.of(1, 2, 3), ArrayUInteger.of(1, 2, 3))); assertTrue(Utilities.areVTypeArraysEqual(Long.TYPE, ArrayLong.of(1L, 2L, 3L), ArrayLong.of(1L, 2L, 3L))); assertTrue(Utilities.areVTypeArraysEqual(Long.TYPE, ArrayULong.of(1L, 2L, 3L), ArrayULong.of(1L, 2L, 3L))); assertTrue(Utilities.areVTypeArraysEqual(Double.TYPE, ArrayDouble.of(7.0, 8.0, 9.0), ArrayDouble.of(7.0, 8.0, 9.0))); assertTrue(Utilities.areVTypeArraysEqual(Float.TYPE, ArrayFloat.of(7.0f, 8.0f, 9.0f), ArrayFloat.of(7.0f, 8.0f, 9.0f))); - assertTrue(Utilities.areVTypeArraysEqual(Short.TYPE, ArrayShort.of((short)7.0, (short)8.0, (short)9.0), ArrayShort.of((short)7.0, (short)8.0, (short)9.0))); - assertTrue(Utilities.areVTypeArraysEqual(Short.TYPE, ArrayUShort.of((short)7.0, (short)8.0, (short)9.0), ArrayUShort.of((short)7.0, (short)8.0, (short)9.0))); - assertTrue(Utilities.areVTypeArraysEqual(Byte.TYPE, ArrayByte.of((byte)7, (byte)8, (byte)9), ArrayByte.of((byte)7, (byte)8, (byte)9))); - assertTrue(Utilities.areVTypeArraysEqual(Byte.TYPE, ArrayUByte.of((byte)7, (byte)8, (byte)9), ArrayUByte.of((byte)7, (byte)8, (byte)9))); + assertTrue(Utilities.areVTypeArraysEqual(Short.TYPE, ArrayShort.of((short) 7.0, (short) 8.0, (short) 9.0), ArrayShort.of((short) 7.0, (short) 8.0, (short) 9.0))); + assertTrue(Utilities.areVTypeArraysEqual(Short.TYPE, ArrayUShort.of((short) 7.0, (short) 8.0, (short) 9.0), ArrayUShort.of((short) 7.0, (short) 8.0, (short) 9.0))); + assertTrue(Utilities.areVTypeArraysEqual(Byte.TYPE, ArrayByte.of((byte) 7, (byte) 8, (byte) 9), ArrayByte.of((byte) 7, (byte) 8, (byte) 9))); + assertTrue(Utilities.areVTypeArraysEqual(Byte.TYPE, ArrayUByte.of((byte) 7, (byte) 8, (byte) 9), ArrayUByte.of((byte) 7, (byte) 8, (byte) 9))); assertTrue(Utilities.areVTypeArraysEqual(Boolean.TYPE, ArrayBoolean.of(true, false), ArrayBoolean.of(true, false))); assertTrue(Utilities.areVTypeArraysEqual(String.class, List.of("AAA", "BBB", "CCC"), List.of("AAA", "BBB", "CCC"))); - assertFalse(Utilities.areVTypeArraysEqual(Byte.TYPE, ArrayShort.of((byte)7, (byte)8, (byte)9), ArrayShort.of((byte)7, (byte)8, (byte)10))); + assertFalse(Utilities.areVTypeArraysEqual(Byte.TYPE, ArrayShort.of((byte) 7, (byte) 8, (byte) 9), ArrayShort.of((byte) 7, (byte) 8, (byte) 10))); } @Test - public void testToPVArrayType(){ + public void testToPVArrayType() { boolean[] bools = new boolean[]{true, false, true}; Object converted = Utilities.toPVArrayType("bools", ArrayBoolean.of(bools)); assertInstanceOf(PVABoolArray.class, converted); - assertEquals(3, ((PVABoolArray)converted).get().length); - assertArrayEquals(bools, ((PVABoolArray)converted).get()); - assertEquals("bools", ((PVABoolArray)converted).getName()); + assertEquals(3, ((PVABoolArray) converted).get().length); + assertArrayEquals(bools, ((PVABoolArray) converted).get()); + assertEquals("bools", ((PVABoolArray) converted).getName()); - byte[] bytes = new byte[]{(byte)-1, (byte)2, (byte)3}; + byte[] bytes = new byte[]{(byte) -1, (byte) 2, (byte) 3}; converted = Utilities.toPVArrayType("bytes", ArrayByte.of(bytes)); assertInstanceOf(PVAByteArray.class, converted); - assertEquals(3, ((PVAByteArray)converted).get().length); - assertArrayEquals(bytes, ((PVAByteArray)converted).get()); - assertEquals("bytes", ((PVAByteArray)converted).getName()); - assertFalse(((PVAByteArray)converted).isUnsigned()); + assertEquals(3, ((PVAByteArray) converted).get().length); + assertArrayEquals(bytes, ((PVAByteArray) converted).get()); + assertEquals("bytes", ((PVAByteArray) converted).getName()); + assertFalse(((PVAByteArray) converted).isUnsigned()); - bytes = new byte[]{(byte)1, (byte)2, (byte)3}; + bytes = new byte[]{(byte) 1, (byte) 2, (byte) 3}; converted = Utilities.toPVArrayType("ubytes", ArrayUByte.of(bytes)); assertInstanceOf(PVAByteArray.class, converted); - assertEquals(3, ((PVAByteArray)converted).get().length); - assertArrayEquals(bytes, ((PVAByteArray)converted).get()); - assertEquals("ubytes", ((PVAByteArray)converted).getName()); - assertTrue(((PVAByteArray)converted).isUnsigned()); + assertEquals(3, ((PVAByteArray) converted).get().length); + assertArrayEquals(bytes, ((PVAByteArray) converted).get()); + assertEquals("ubytes", ((PVAByteArray) converted).getName()); + assertTrue(((PVAByteArray) converted).isUnsigned()); - short[] shorts = new short[]{(short)-1, (short)2, (short)3}; + short[] shorts = new short[]{(short) -1, (short) 2, (short) 3}; converted = Utilities.toPVArrayType("shorts", ArrayShort.of(shorts)); assertInstanceOf(PVAShortArray.class, converted); - assertEquals(3, ((PVAShortArray)converted).get().length); - assertArrayEquals(shorts, ((PVAShortArray)converted).get()); - assertEquals("shorts", ((PVAShortArray)converted).getName()); - assertFalse(((PVAShortArray)converted).isUnsigned()); + assertEquals(3, ((PVAShortArray) converted).get().length); + assertArrayEquals(shorts, ((PVAShortArray) converted).get()); + assertEquals("shorts", ((PVAShortArray) converted).getName()); + assertFalse(((PVAShortArray) converted).isUnsigned()); - shorts = new short[]{(short)1, (short)2, (short)3}; + shorts = new short[]{(short) 1, (short) 2, (short) 3}; converted = Utilities.toPVArrayType("ushorts", ArrayUShort.of(shorts)); assertInstanceOf(PVAShortArray.class, converted); - assertEquals(3, ((PVAShortArray)converted).get().length); - assertArrayEquals(shorts, ((PVAShortArray)converted).get()); - assertEquals("ushorts", ((PVAShortArray)converted).getName()); - assertTrue(((PVAShortArray)converted).isUnsigned()); + assertEquals(3, ((PVAShortArray) converted).get().length); + assertArrayEquals(shorts, ((PVAShortArray) converted).get()); + assertEquals("ushorts", ((PVAShortArray) converted).getName()); + assertTrue(((PVAShortArray) converted).isUnsigned()); int[] ints = new int[]{-1, 2, 3}; converted = Utilities.toPVArrayType("ints", ArrayInteger.of(ints)); assertInstanceOf(PVAIntArray.class, converted); - assertEquals(3, ((PVAIntArray)converted).get().length); - assertArrayEquals(ints, ((PVAIntArray)converted).get()); - assertEquals("ints", ((PVAIntArray)converted).getName()); - assertFalse(((PVAIntArray)converted).isUnsigned()); + assertEquals(3, ((PVAIntArray) converted).get().length); + assertArrayEquals(ints, ((PVAIntArray) converted).get()); + assertEquals("ints", ((PVAIntArray) converted).getName()); + assertFalse(((PVAIntArray) converted).isUnsigned()); ints = new int[]{1, 2, 3}; converted = Utilities.toPVArrayType("uints", ArrayUInteger.of(ints)); assertInstanceOf(PVAIntArray.class, converted); - assertEquals(3, ((PVAIntArray)converted).get().length); - assertArrayEquals(ints, ((PVAIntArray)converted).get()); - assertEquals("uints", ((PVAIntArray)converted).getName()); - assertTrue(((PVAIntArray)converted).isUnsigned()); + assertEquals(3, ((PVAIntArray) converted).get().length); + assertArrayEquals(ints, ((PVAIntArray) converted).get()); + assertEquals("uints", ((PVAIntArray) converted).getName()); + assertTrue(((PVAIntArray) converted).isUnsigned()); long[] longs = new long[]{-1L, 2L, 3L}; converted = Utilities.toPVArrayType("longs", ArrayLong.of(longs)); assertInstanceOf(PVALongArray.class, converted); - assertEquals(3, ((PVALongArray)converted).get().length); - assertArrayEquals(longs, ((PVALongArray)converted).get()); - assertEquals("longs", ((PVALongArray)converted).getName()); - assertFalse(((PVALongArray)converted).isUnsigned()); + assertEquals(3, ((PVALongArray) converted).get().length); + assertArrayEquals(longs, ((PVALongArray) converted).get()); + assertEquals("longs", ((PVALongArray) converted).getName()); + assertFalse(((PVALongArray) converted).isUnsigned()); longs = new long[]{1L, 2L, 3L}; converted = Utilities.toPVArrayType("ulongs", ArrayULong.of(longs)); assertInstanceOf(PVALongArray.class, converted); - assertEquals(3, ((PVALongArray)converted).get().length); - assertArrayEquals(longs, ((PVALongArray)converted).get()); - assertEquals("ulongs", ((PVALongArray)converted).getName()); - assertTrue(((PVALongArray)converted).isUnsigned()); + assertEquals(3, ((PVALongArray) converted).get().length); + assertArrayEquals(longs, ((PVALongArray) converted).get()); + assertEquals("ulongs", ((PVALongArray) converted).getName()); + assertTrue(((PVALongArray) converted).isUnsigned()); float[] floats = new float[]{-1.0f, 2.0f, 3.0f}; converted = Utilities.toPVArrayType("floats", ArrayFloat.of(floats)); assertInstanceOf(PVAFloatArray.class, converted); - assertEquals(3, ((PVAFloatArray)converted).get().length); - assertArrayEquals(floats, ((PVAFloatArray)converted).get()); - assertEquals("floats", ((PVAFloatArray)converted).getName()); + assertEquals(3, ((PVAFloatArray) converted).get().length); + assertArrayEquals(floats, ((PVAFloatArray) converted).get()); + assertEquals("floats", ((PVAFloatArray) converted).getName()); double[] doubles = new double[]{-1.0, 2.0, 3.0}; converted = Utilities.toPVArrayType("doubles", ArrayDouble.of(doubles)); assertInstanceOf(PVADoubleArray.class, converted); - assertEquals(3, ((PVADoubleArray)converted).get().length); - assertArrayEquals(doubles, ((PVADoubleArray)converted).get()); - assertEquals("doubles", ((PVADoubleArray)converted).getName()); + assertEquals(3, ((PVADoubleArray) converted).get().length); + assertArrayEquals(doubles, ((PVADoubleArray) converted).get()); + assertEquals("doubles", ((PVADoubleArray) converted).getName()); List strings = new ArrayList<>(); strings.add("a"); @@ -1672,8 +1666,8 @@ public void testToPVArrayType(){ strings.add("c"); converted = Utilities.toPVArrayType("strings", strings); assertInstanceOf(PVAStringArray.class, converted); - assertEquals(3, ((PVAStringArray)converted).get().length); - assertArrayEquals(new String[]{"a", "b", "c"}, ((PVAStringArray)converted).get()); - assertEquals("strings", ((PVAStringArray)converted).getName()); + assertEquals(3, ((PVAStringArray) converted).get().length); + assertArrayEquals(new String[]{"a", "b", "c"}, ((PVAStringArray) converted).get()); + assertEquals("strings", ((PVAStringArray) converted).getName()); } } diff --git a/core/pva/src/main/java/org/epics/pva/client/PutRequest.java b/core/pva/src/main/java/org/epics/pva/client/PutRequest.java index 636c7554a4..1223cb200b 100644 --- a/core/pva/src/main/java/org/epics/pva/client/PutRequest.java +++ b/core/pva/src/main/java/org/epics/pva/client/PutRequest.java @@ -167,7 +167,7 @@ public void encodeRequest(final byte version, final ByteBuffer buffer) throws Ex changed.set(data.getIndex(field)); if (field instanceof PVAStructure) { final PVAStructure struct = (PVAStructure) field; - List elements = struct.getElements(); + List elements = struct.get(); if(elements != null){ for(int i = 0; i < elements.size(); i++){ changed.set(data.getIndex(elements.get(i))); From 04dee2238f00f2ac641aa294a9ed2f9591ddd40f Mon Sep 17 00:00:00 2001 From: georgweiss Date: Wed, 29 Nov 2023 16:26:06 +0100 Subject: [PATCH 09/12] PVATable column names fix --- .../org/phoebus/applications/saveandrestore/ui/Utilities.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/Utilities.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/Utilities.java index 47580b1856..a09f92e3fb 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/Utilities.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/Utilities.java @@ -333,7 +333,7 @@ else if(type instanceof VTable) { int columnCount = vTable.getColumnCount(); List dataArrays = new ArrayList(); for(int i = 0; i < columnCount; i++){ - dataArrays.add(toPVArrayType(vTable.getColumnName(i), vTable.getColumnData(i))); + dataArrays.add(toPVArrayType("Col " + i, vTable.getColumnData(i))); } PVAStructure table = new PVAStructure(PVATable.STRUCT_NAME,"", dataArrays); return table; From 84874e646f1206afba75cd3771d6871b62504b81 Mon Sep 17 00:00:00 2001 From: georgweiss Date: Wed, 3 Jan 2024 14:27:33 +0100 Subject: [PATCH 10/12] Update to released epics core --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 1696ccb07c..4174561b06 100644 --- a/pom.xml +++ b/pom.xml @@ -65,8 +65,8 @@ 2023-05-24T19:31:02Z - 7.0.9 - 1.0.7-SNAPSHOT + 7.0.10 + 1.0.7 19 2.12.3 1.14 From d86f2121de0d0e9a862e1c8b201db4dea8de9738 Mon Sep 17 00:00:00 2001 From: georgweiss Date: Fri, 12 Jan 2024 20:09:20 +0100 Subject: [PATCH 11/12] Reverted unnecessary changes --- core/pva/src/main/java/org/epics/pva/client/PutRequest.java | 4 ---- core/pva/src/main/java/org/epics/pva/data/PVAData.java | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/core/pva/src/main/java/org/epics/pva/client/PutRequest.java b/core/pva/src/main/java/org/epics/pva/client/PutRequest.java index 1223cb200b..23ee9d4149 100644 --- a/core/pva/src/main/java/org/epics/pva/client/PutRequest.java +++ b/core/pva/src/main/java/org/epics/pva/client/PutRequest.java @@ -112,7 +112,6 @@ public void encodeRequest(final byte version, final ByteBuffer buffer) throws Ex final int pos = buffer.position(); buffer.putInt(channel.getSID()); buffer.putInt(request_id); - //buffer.put((byte)0x04); buffer.put(PVAHeader.CMD_SUB_DESTROY); // Locate the field to write @@ -236,11 +235,8 @@ else if (subcmd == PVAHeader.CMD_SUB_DESTROY) // Indicate completion now that server confirmed PUT complete(null); } - /* else fail(new Exception("Cannot decode Put " + subcmd + " Reply #" + request_id)); - - */ } /** Handle failure by both notifying whoever waits for this request to complete diff --git a/core/pva/src/main/java/org/epics/pva/data/PVAData.java b/core/pva/src/main/java/org/epics/pva/data/PVAData.java index 1d52225527..12a5594b12 100644 --- a/core/pva/src/main/java/org/epics/pva/data/PVAData.java +++ b/core/pva/src/main/java/org/epics/pva/data/PVAData.java @@ -22,7 +22,7 @@ public abstract class PVAData { /** Name */ - protected String name; + protected final String name; /** @param name Name for data item */ protected PVAData(final String name) From d0f0a6bdab73a2b7e379658d701206c734184875 Mon Sep 17 00:00:00 2001 From: georgweiss Date: Fri, 12 Jan 2024 20:21:38 +0100 Subject: [PATCH 12/12] Some code cleanup --- .../saveandrestore/ui/Utilities.java | 96 ++++++++----------- 1 file changed, 38 insertions(+), 58 deletions(-) diff --git a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/Utilities.java b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/Utilities.java index a09f92e3fb..4442fb8a65 100644 --- a/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/Utilities.java +++ b/app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/Utilities.java @@ -18,20 +18,15 @@ package org.phoebus.applications.saveandrestore.ui; import org.epics.pva.data.*; -import org.epics.pva.data.nt.PVAAlarm; import org.epics.pva.data.nt.PVATable; -import org.epics.pva.data.nt.PVATimeStamp; -import org.epics.pvdata.pv.PVULongArray; import org.epics.util.array.*; import org.epics.util.number.*; import org.epics.util.text.NumberFormats; import org.epics.vtype.*; import org.phoebus.core.vtypes.VTypeHelper; -import org.phoebus.pv.pva.PVAStructureHelper; import java.math.BigInteger; import java.text.NumberFormat; -import java.time.Instant; import java.util.*; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -107,7 +102,7 @@ public double getAbsoluteDelta() { /** * The character code for the greek delta letter */ - public static final char DELTA_CHAR = '\u0394'; + public static final char DELTA_CHAR = 'Δ'; private static final char COMMA = ','; // All formats use thread locals, to avoid problems if any of the static methods are invoked concurrently @@ -152,7 +147,7 @@ public static VType valueFromString(String indata, VType type) throws IllegalArg Time time = Time.now(); if (type instanceof VNumberArray) { ListNumber list = null; - String[] elements = data.split("\\,"); + String[] elements = data.split(","); if (((VNumberArray) type).getData().size() != elements.length) { throw new IllegalArgumentException("The number of array elements is different from the original."); } @@ -220,12 +215,12 @@ public static VType valueFromString(String indata, VType type) throws IllegalArg return VNumberArray.of(list, alarm, time, Display.none()); } else if (type instanceof VStringArray) { - String[] elements = data.split("\\,"); + String[] elements = data.split(","); List list = Arrays.stream(elements).map(String::trim).collect(Collectors.toList()); list = list.stream().map(s -> s.substring(1, s.length() - 1)).collect(Collectors.toList()); return VStringArray.of(list, alarm, time); } else if (type instanceof VBooleanArray) { - String[] elements = data.split("\\,"); + String[] elements = data.split(","); List list = Arrays.stream(elements).map(String::trim).collect(Collectors.toList()); boolean[] booleans = new boolean[list.size()]; for (int i = 0; i < list.size(); i++) { @@ -327,16 +322,14 @@ public static Object toRawValue(VType type) { return ((VString) type).getValue(); } else if (type instanceof VBoolean) { return ((VBoolean) type).getValue(); - } - else if(type instanceof VTable) { - VTable vTable = (VTable)type; + } else if (type instanceof VTable) { + VTable vTable = (VTable) type; int columnCount = vTable.getColumnCount(); List dataArrays = new ArrayList(); - for(int i = 0; i < columnCount; i++){ + for (int i = 0; i < columnCount; i++) { dataArrays.add(toPVArrayType("Col " + i, vTable.getColumnData(i))); } - PVAStructure table = new PVAStructure(PVATable.STRUCT_NAME,"", dataArrays); - return table; + return new PVAStructure(PVATable.STRUCT_NAME, "", dataArrays); } return null; } @@ -370,16 +363,16 @@ public static String valueToString(VType type, int arrayLimit) { int size = Math.min(arrayLimit, list.size()); StringBuilder sb = new StringBuilder(size * 15 + 2); sb.append('['); - Pattern pattern = Pattern.compile("\\,"); + Pattern pattern = Pattern.compile(","); NumberFormat formatter = ((SimpleValueFormat) FORMAT.get()).getNumberFormat(); if (type instanceof VDoubleArray) { for (int i = 0; i < size; i++) { - sb.append(pattern.matcher(formatter.format(list.getDouble(i))).replaceAll("\\.")).append(COMMA) + sb.append(pattern.matcher(formatter.format(list.getDouble(i))).replaceAll(".")).append(COMMA) .append(' '); } } else if (type instanceof VFloatArray) { for (int i = 0; i < size; i++) { - sb.append(pattern.matcher(formatter.format(list.getFloat(i))).replaceAll("\\.")).append(COMMA) + sb.append(pattern.matcher(formatter.format(list.getFloat(i))).replaceAll(".")).append(COMMA) .append(' '); } } else if (type instanceof VULongArray) { @@ -468,8 +461,7 @@ public static String valueToString(VType type, int arrayLimit) { return ((VString) type).getValue(); } else if (type instanceof VBoolean) { return String.valueOf(((VBoolean) type).getValue()); - } - else if(type instanceof VTable){ + } else if (type instanceof VTable) { return "[VTable]"; } // no support for MultiScalars (VMultiDouble, VMultiInt, VMultiString, VMultiEnum), VStatistics and @@ -906,12 +898,10 @@ public static VTypeComparison deltaValueToString(VType value, VType baseValue, O } else if (value instanceof VBooleanArray && baseValue instanceof VBooleanArray) { boolean equal = areValuesEqual(value, baseValue, Optional.empty()); return new VTypeComparison(equal ? "---" : "NOT EQUAL", equal ? 0 : 1, equal); - } - else if (value instanceof VTable && baseValue instanceof VTable) { + } else if (value instanceof VTable && baseValue instanceof VTable) { boolean equal = areValuesEqual(value, baseValue, Optional.empty()); return new VTypeComparison(equal ? "---" : "NOT EQUAL", equal ? 0 : 1, equal); - } - else { + } else { String str = valueToString(value); boolean valuesEqual = areValuesEqual(value, baseValue, Optional.empty()); return new VTypeComparison(str, valuesEqual ? 0 : 1, valuesEqual); @@ -1140,22 +1130,21 @@ public static boolean areValuesEqual(VType v1, VType v2, Optional> } } return true; - } - else if(v1 instanceof VTable && v2 instanceof VTable){ - VTable vTable1 = (VTable)v1; - VTable vTable2 = (VTable)v2; - if(vTable1.getColumnCount() != vTable2.getColumnCount() || - vTable1.getRowCount() != vTable2.getRowCount()){ + } else if (v1 instanceof VTable && v2 instanceof VTable) { + VTable vTable1 = (VTable) v1; + VTable vTable2 = (VTable) v2; + if (vTable1.getColumnCount() != vTable2.getColumnCount() || + vTable1.getRowCount() != vTable2.getRowCount()) { return false; } - for(int i = 0; i < vTable1.getColumnCount(); i++){ - if(!vTable1.getColumnType(i).equals(vTable2.getColumnType(i))){ + for (int i = 0; i < vTable1.getColumnCount(); i++) { + if (!vTable1.getColumnType(i).equals(vTable2.getColumnType(i))) { return false; } - if(!vTable1.getColumnName(i).equals(vTable2.getColumnName(i))){ + if (!vTable1.getColumnName(i).equals(vTable2.getColumnName(i))) { return false; } - if(!areVTypeArraysEqual(vTable1.getColumnType(i), vTable1.getColumnData(i), vTable2.getColumnData(i))){ + if (!areVTypeArraysEqual(vTable1.getColumnType(i), vTable1.getColumnData(i), vTable2.getColumnData(i))) { return false; } } @@ -1167,14 +1156,15 @@ else if(v1 instanceof VTable && v2 instanceof VTable){ } /** - * Compares objects based on the - * @param clazz - * @param a1 - * @param a2 - * @return + * Compares array objects + * + * @param clazz Class of the input data objects + * @param a1 First object + * @param a2 Second object + * @return true if all elements in arrays are equal. */ - public static boolean areVTypeArraysEqual(Class clazz, Object a1, Object a2){ - switch(clazz.getName()){ + public static boolean areVTypeArraysEqual(Class clazz, Object a1, Object a2) { + switch (clazz.getName()) { case "int": case "long": case "double": @@ -1364,12 +1354,11 @@ private static boolean isAlarmAndTimeEqual(VType a1, VType a2) { } /** - * - * @param name - * @param object - * @return + * @param name Data item name + * @param object The object subject to conversion + * @return Converted object */ - protected static Object toPVArrayType(String name, Object object) { + public static Object toPVArrayType(String name, Object object) { if (object instanceof ListBoolean) { ListBoolean listBoolean = (ListBoolean) object; boolean[] booleans = new boolean[listBoolean.size()]; @@ -1377,8 +1366,7 @@ protected static Object toPVArrayType(String name, Object object) { booleans[i] = listBoolean.getBoolean(i); } return new PVABoolArray(name, booleans); - } - else if (object instanceof ListNumber) { + } else if (object instanceof ListNumber) { ListNumber listNumber = (ListNumber) object; if (object instanceof ArrayByte || object instanceof ArrayUByte) { byte[] bytes = new byte[listNumber.size()]; @@ -1398,12 +1386,6 @@ else if (object instanceof ListNumber) { ints[i] = listNumber.getInt(i); } return new PVAIntArray(name, object instanceof ArrayUInteger, ints); - } else if (object instanceof ArrayUInteger) { - int[] ints = new int[listNumber.size()]; - for (int i = 0; i < listNumber.size(); i++) { - ints[i] = listNumber.getInt(i); - } - return new PVAIntArray(name, object instanceof ArrayUInteger, ints); } else if (object instanceof ArrayLong || object instanceof ArrayULong) { long[] longs = new long[listNumber.size()]; for (int i = 0; i < listNumber.size(); i++) { @@ -1422,12 +1404,10 @@ else if (object instanceof ListNumber) { doubles[i] = listNumber.getDouble(i); } return new PVADoubleArray(name, doubles); - } - else { + } else { throw new IllegalArgumentException("Conversion of type " + object.getClass().getCanonicalName() + " not supported"); } - } - else { // Assume this always is for string arrays + } else { // Assume this always is for string arrays Collection list = (Collection) object; String[] strings = new String[list.size()]; strings = list.toArray(strings);