Skip to content

Commit

Permalink
fix(plc4j/profinet): Fixed some issues around parsing gsd files and v…
Browse files Browse the repository at this point in the history
…endor id formats
  • Loading branch information
hutcheb committed Feb 4, 2023
1 parent 63b77e1 commit 0772198
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
Expand Up @@ -51,6 +51,8 @@ public Short getSuboption() {

// Arguments.
protected final Integer blockLength;
// Reserved Fields
private Integer reservedField0;

public PnDcp_Block_DevicePropertiesNameOfStation(byte[] nameOfStation, Integer blockLength) {
super();
Expand All @@ -68,6 +70,12 @@ protected void serializePnDcp_BlockChild(WriteBuffer writeBuffer) throws Seriali
int startPos = positionAware.getPos();
writeBuffer.pushContext("PnDcp_Block_DevicePropertiesNameOfStation");

// Reserved Field (reserved)
writeReservedField(
"reserved",
reservedField0 != null ? reservedField0 : (int) 0x0000,
writeUnsignedInt(writeBuffer, 16));

// Array Field (nameOfStation)
writeByteArrayField("nameOfStation", nameOfStation, writeByteArray(writeBuffer, 8));

Expand All @@ -94,6 +102,9 @@ public int getLengthInBits() {
int lengthInBits = super.getLengthInBits();
PnDcp_Block_DevicePropertiesNameOfStation _value = this;

// Reserved Field (reserved)
lengthInBits += 16;

// Array field
if (nameOfStation != null) {
lengthInBits += 8 * nameOfStation.length;
Expand All @@ -119,6 +130,9 @@ public static PnDcp_BlockBuilder staticParsePnDcp_BlockBuilder(
int startPos = positionAware.getPos();
int curPos;

Integer reservedField0 =
readReservedField("reserved", readUnsignedInt(readBuffer, 16), (int) 0x0000);

byte[] nameOfStation =
readBuffer.readByteArray("nameOfStation", Math.toIntExact((blockLength) - (2)));

Expand All @@ -131,23 +145,27 @@ public static PnDcp_BlockBuilder staticParsePnDcp_BlockBuilder(

readBuffer.closeContext("PnDcp_Block_DevicePropertiesNameOfStation");
// Create the instance
return new PnDcp_Block_DevicePropertiesNameOfStationBuilderImpl(nameOfStation, blockLength);
return new PnDcp_Block_DevicePropertiesNameOfStationBuilderImpl(
nameOfStation, blockLength, reservedField0);
}

public static class PnDcp_Block_DevicePropertiesNameOfStationBuilderImpl
implements PnDcp_Block.PnDcp_BlockBuilder {
private final byte[] nameOfStation;
private final Integer blockLength;
private final Integer reservedField0;

public PnDcp_Block_DevicePropertiesNameOfStationBuilderImpl(
byte[] nameOfStation, Integer blockLength) {
byte[] nameOfStation, Integer blockLength, Integer reservedField0) {
this.nameOfStation = nameOfStation;
this.blockLength = blockLength;
this.reservedField0 = reservedField0;
}

public PnDcp_Block_DevicePropertiesNameOfStation build() {
PnDcp_Block_DevicePropertiesNameOfStation pnDcp_Block_DevicePropertiesNameOfStation =
new PnDcp_Block_DevicePropertiesNameOfStation(nameOfStation, blockLength);
pnDcp_Block_DevicePropertiesNameOfStation.reservedField0 = reservedField0;
return pnDcp_Block_DevicePropertiesNameOfStation;
}
}
Expand Down
Expand Up @@ -424,7 +424,7 @@ public DceRpc_Packet create() {
ProfinetDeviceContext.ARUUID,
deviceContext.getSessionKey(),
deviceContext.getLocalMacAddress(),
new DceRpc_ObjectUuid((byte) 0x00, 0x0001, Integer.valueOf(deviceId), Integer.valueOf(vendorId)),
new DceRpc_ObjectUuid((byte) 0x00, 0x0001, Integer.decode("0x" + deviceId), Integer.decode("0x" + vendorId)),
false,
deviceContext.isNonLegacyStartupMode(),
false,
Expand Down Expand Up @@ -537,7 +537,7 @@ public DceRpc_Packet create() {
IntegerEncoding.BIG_ENDIAN,
CharacterEncoding.ASCII,
FloatingPointEncoding.IEEE,
new DceRpc_ObjectUuid((byte) 0x00, 0x0001, Integer.valueOf(deviceId), Integer.valueOf(vendorId)),
new DceRpc_ObjectUuid((byte) 0x00, 0x0001, Integer.decode("0x" + deviceId), Integer.decode("0x" + vendorId)),
new DceRpc_InterfaceUuid_DeviceInterface(),
deviceContext.getUuid(),
0,
Expand Down Expand Up @@ -678,7 +678,7 @@ public DceRpc_Packet create() {
return new DceRpc_Packet(
DceRpc_PacketType.REQUEST, true, false, false,
IntegerEncoding.BIG_ENDIAN, CharacterEncoding.ASCII, FloatingPointEncoding.IEEE,
new DceRpc_ObjectUuid((byte) 0x00, 0x0001, Integer.valueOf(deviceId), Integer.valueOf(vendorId)),
new DceRpc_ObjectUuid((byte) 0x00, 0x0001, Integer.decode("0x" + deviceId), Integer.decode("0x" + vendorId)),
new DceRpc_InterfaceUuid_DeviceInterface(),
deviceContext.getUuid(),
0,
Expand Down Expand Up @@ -742,7 +742,7 @@ public DceRpc_Packet create() {
return new DceRpc_Packet(
DceRpc_PacketType.REQUEST, true, false, false,
IntegerEncoding.BIG_ENDIAN, CharacterEncoding.ASCII, FloatingPointEncoding.IEEE,
new DceRpc_ObjectUuid((byte) 0x00, 0x0001, Integer.valueOf(deviceId), Integer.valueOf(vendorId)),
new DceRpc_ObjectUuid((byte) 0x00, 0x0001, Integer.decode("0x" + deviceId), Integer.decode("0x" + vendorId)),
new DceRpc_InterfaceUuid_DeviceInterface(),
deviceContext.getUuid(),
0,
Expand Down Expand Up @@ -824,7 +824,7 @@ public DceRpc_Packet create() {
IntegerEncoding.BIG_ENDIAN,
CharacterEncoding.ASCII,
FloatingPointEncoding.IEEE,
new DceRpc_ObjectUuid((byte) 0x00, 0x0001, Integer.valueOf(deviceId), Integer.valueOf(vendorId)),
new DceRpc_ObjectUuid((byte) 0x00, 0x0001, Integer.decode("0x" + deviceId), Integer.decode("0x" + vendorId)),
new DceRpc_InterfaceUuid_ControllerInterface(),
activityUuid,
0,
Expand Down
Expand Up @@ -40,6 +40,9 @@ public class ProfinetDataItem {
@JacksonXmlProperty(isAttribute=true, localName="TextId")
private String textId;

@JacksonXmlProperty(isAttribute=true, localName="Length")
private int length;

@JacksonXmlProperty(isAttribute=true, localName="UseAsBits")
private boolean useAsBits;

Expand All @@ -51,6 +54,10 @@ public String getTextId() {
return textId;
}

public int getLength() {
return length;
}

public boolean isUseAsBits() {
return useAsBits;
}
Expand Down
Expand Up @@ -554,6 +554,7 @@
[padding uint 8 pad '0x00' 'STATIC_CALL("arrayLength", deviceVendorValue) % 2']
]
['DEVICE_PROPERTIES_OPTION','2' PnDcp_Block_DevicePropertiesNameOfStation(uint 16 blockLength)
[reserved uint 16 '0x0000' ]
[array byte nameOfStation count 'blockLength-2' ]
[padding uint 8 pad '0x00' 'STATIC_CALL("arrayLength", nameOfStation) % 2']
]
Expand Down

0 comments on commit 0772198

Please sign in to comment.