Skip to content

Commit c66ee77

Browse files
committed
feat: Got the first tests working with UMAS.
1 parent 76e025d commit c66ee77

22 files changed

Lines changed: 1664 additions & 77 deletions

File tree

plc4j/drivers/umas/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@
110110
<groupId>io.netty</groupId>
111111
<artifactId>netty-buffer</artifactId>
112112
</dependency>
113+
<dependency>
114+
<groupId>io.netty</groupId>
115+
<artifactId>netty-transport</artifactId>
116+
</dependency>
113117

114118
<dependency>
115119
<groupId>org.slf4j</groupId>

plc4j/drivers/umas/src/main/generated/org/apache/plc4x/java/umas/readwrite/DataItem.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,16 @@ public static PlcValue staticParse(
6161
return new PlcBOOL(value);
6262
} else if (EvaluationHelper.equals(dataType, UmasDataType.BYTE)
6363
&& EvaluationHelper.equals(numberOfValues, (int) 1)) { // BYTE
64-
byte value = readSimpleField("value", readByte(readBuffer, 8));
64+
short value = readSimpleField("value", readUnsignedShort(readBuffer, 8));
6565
return new PlcBYTE(value);
6666
} else if (EvaluationHelper.equals(dataType, UmasDataType.BYTE)) { // List
67-
byte[] value = readBuffer.readByteArray("value", Math.toIntExact(numberOfValues));
68-
return new PlcRawByteArray(value);
67+
List<Short> _value =
68+
readCountArrayField("value", readUnsignedShort(readBuffer, 8), numberOfValues);
69+
List<PlcValue> value = new ArrayList<>(_value.size());
70+
for (short _item : _value) {
71+
value.add(new PlcUSINT(_item));
72+
}
73+
return new PlcList(value);
6974
} else if (EvaluationHelper.equals(dataType, UmasDataType.WORD)) { // WORD
7075
int value = readSimpleField("value", readUnsignedInt(readBuffer, 16));
7176
return new PlcWORD(value);
@@ -240,7 +245,7 @@ public static int getLengthInBits(
240245
} else if (EvaluationHelper.equals(dataType, UmasDataType.BYTE)) { // List
241246
// Array field
242247
if (_value != null) {
243-
lengthInBits += 8 * _value.getRaw().length;
248+
lengthInBits += 8 * _value.getList().size();
244249
}
245250
} else if (EvaluationHelper.equals(dataType, UmasDataType.WORD)) { // WORD
246251
// Simple field (value)
@@ -387,10 +392,13 @@ public static void staticSerialize(
387392
} else if (EvaluationHelper.equals(dataType, UmasDataType.BYTE)
388393
&& EvaluationHelper.equals(numberOfValues, (int) 1)) { // BYTE
389394
// Simple Field (value)
390-
writeSimpleField("value", (byte) _value.getByte(), writeByte(writeBuffer, 8));
395+
writeSimpleField("value", (short) _value.getShort(), writeUnsignedShort(writeBuffer, 8));
391396
} else if (EvaluationHelper.equals(dataType, UmasDataType.BYTE)) { // List
392397
// Array Field (value)
393-
writeByteArrayField("value", _value.getRaw(), writeByteArray(writeBuffer, 8));
398+
writeSimpleTypeArrayField(
399+
"value",
400+
_value.getList().stream().map(PlcValue::getShort).collect(Collectors.toList()),
401+
writeUnsignedShort(writeBuffer, 8));
394402
} else if (EvaluationHelper.equals(dataType, UmasDataType.WORD)) { // WORD
395403
// Simple Field (value)
396404
writeSimpleField("value", (int) _value.getInteger(), writeUnsignedInt(writeBuffer, 16));
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.plc4x.java.umas.readwrite;
20+
21+
import static org.apache.plc4x.java.spi.codegen.fields.FieldReaderFactory.*;
22+
import static org.apache.plc4x.java.spi.codegen.fields.FieldWriterFactory.*;
23+
import static org.apache.plc4x.java.spi.codegen.io.DataReaderFactory.*;
24+
import static org.apache.plc4x.java.spi.codegen.io.DataWriterFactory.*;
25+
import static org.apache.plc4x.java.spi.generation.StaticHelper.*;
26+
27+
import java.time.*;
28+
import java.util.*;
29+
import org.apache.plc4x.java.api.exceptions.*;
30+
import org.apache.plc4x.java.api.value.*;
31+
import org.apache.plc4x.java.spi.codegen.*;
32+
import org.apache.plc4x.java.spi.codegen.fields.*;
33+
import org.apache.plc4x.java.spi.codegen.io.*;
34+
import org.apache.plc4x.java.spi.generation.*;
35+
36+
// Code generated by code-generation. DO NOT EDIT.
37+
38+
/**
39+
* Read current values for all registered variables. Returns concatenated raw values in the response
40+
* — the driver must know each variable's data type to parse the byte stream.
41+
*/
42+
public class MonitorPlcReadAll extends MonitorPlcSubOperation implements Message {
43+
44+
// Accessors for discriminator values.
45+
public Short getOperationType() {
46+
return (short) 0x07;
47+
}
48+
49+
public MonitorPlcReadAll() {
50+
super();
51+
}
52+
53+
@Override
54+
protected void serializeMonitorPlcSubOperationChild(WriteBuffer writeBuffer)
55+
throws SerializationException {
56+
PositionAware positionAware = writeBuffer;
57+
boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get();
58+
writeBuffer.pushContext("MonitorPlcReadAll");
59+
60+
writeBuffer.popContext("MonitorPlcReadAll");
61+
}
62+
63+
@Override
64+
public int getLengthInBytes() {
65+
return (int) Math.ceil((float) getLengthInBits() / 8.0);
66+
}
67+
68+
@Override
69+
public int getLengthInBits() {
70+
int lengthInBits = super.getLengthInBits();
71+
MonitorPlcReadAll _value = this;
72+
boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get();
73+
74+
return lengthInBits;
75+
}
76+
77+
public static MonitorPlcSubOperationBuilder staticParseMonitorPlcSubOperationBuilder(
78+
ReadBuffer readBuffer) throws ParseException {
79+
readBuffer.pullContext("MonitorPlcReadAll");
80+
PositionAware positionAware = readBuffer;
81+
boolean _lastItem = ThreadLocalHelper.lastItemThreadLocal.get();
82+
83+
readBuffer.closeContext("MonitorPlcReadAll");
84+
// Create the instance
85+
return new MonitorPlcReadAllBuilderImpl();
86+
}
87+
88+
public static class MonitorPlcReadAllBuilderImpl
89+
implements MonitorPlcSubOperation.MonitorPlcSubOperationBuilder {
90+
91+
public MonitorPlcReadAllBuilderImpl() {}
92+
93+
public MonitorPlcReadAll build() {
94+
MonitorPlcReadAll monitorPlcReadAll = new MonitorPlcReadAll();
95+
return monitorPlcReadAll;
96+
}
97+
}
98+
99+
@Override
100+
public boolean equals(Object o) {
101+
if (this == o) {
102+
return true;
103+
}
104+
if (!(o instanceof MonitorPlcReadAll)) {
105+
return false;
106+
}
107+
MonitorPlcReadAll that = (MonitorPlcReadAll) o;
108+
return super.equals(that) && true;
109+
}
110+
111+
@Override
112+
public int hashCode() {
113+
return Objects.hash(super.hashCode());
114+
}
115+
116+
@Override
117+
public String toString() {
118+
WriteBufferBoxBased writeBufferBoxBased = new WriteBufferBoxBased(true, true);
119+
try {
120+
writeBufferBoxBased.writeSerializable(this);
121+
} catch (SerializationException e) {
122+
throw new RuntimeException(e);
123+
}
124+
return "\n" + writeBufferBoxBased.getBox().toString() + "\n";
125+
}
126+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.plc4x.java.umas.readwrite;
20+
21+
import java.util.HashMap;
22+
import java.util.Map;
23+
24+
// Code generated by code-generation. DO NOT EDIT.
25+
26+
public enum MonitorPlcRegisterAction {
27+
DEREGISTER((short) 0x01),
28+
REGISTER((short) 0x02);
29+
private static final Map<Short, MonitorPlcRegisterAction> map;
30+
31+
static {
32+
map = new HashMap<>();
33+
for (MonitorPlcRegisterAction value : MonitorPlcRegisterAction.values()) {
34+
map.put((short) value.getValue(), value);
35+
}
36+
}
37+
38+
private final short value;
39+
40+
MonitorPlcRegisterAction(short value) {
41+
this.value = value;
42+
}
43+
44+
public short getValue() {
45+
return value;
46+
}
47+
48+
public static MonitorPlcRegisterAction enumForValue(short value) {
49+
return map.get(value);
50+
}
51+
52+
public static Boolean isDefined(short value) {
53+
return map.containsKey(value);
54+
}
55+
}

0 commit comments

Comments
 (0)