Skip to content

Commit

Permalink
fix(eip): Adjusted the CIPAttributes type to allow the packet structu…
Browse files Browse the repository at this point in the history
…re used by my AB CompactLogix controller.
  • Loading branch information
chrisdutz committed May 24, 2023
1 parent b2ba923 commit 07fa836
Showing 1 changed file with 33 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ public class CIPAttributes implements Message {

// Properties.
protected final List<Integer> classId;
protected final int numberAvailable;
protected final int numberActive;
protected final Integer numberAvailable;
protected final Integer numberActive;
protected final byte[] data;

public CIPAttributes(List<Integer> classId, int numberAvailable, int numberActive, byte[] data) {
public CIPAttributes(
List<Integer> classId, Integer numberAvailable, Integer numberActive, byte[] data) {
super();
this.classId = classId;
this.numberAvailable = numberAvailable;
Expand All @@ -55,11 +56,11 @@ public List<Integer> getClassId() {
return classId;
}

public int getNumberAvailable() {
public Integer getNumberAvailable() {
return numberAvailable;
}

public int getNumberActive() {
public Integer getNumberActive() {
return numberActive;
}

Expand All @@ -80,11 +81,11 @@ public void serialize(WriteBuffer writeBuffer) throws SerializationException {
// Array Field (classId)
writeSimpleTypeArrayField("classId", classId, writeUnsignedInt(writeBuffer, 16));

// Simple Field (numberAvailable)
writeSimpleField("numberAvailable", numberAvailable, writeUnsignedInt(writeBuffer, 16));
// Optional Field (numberAvailable) (Can be skipped, if the value is null)
writeOptionalField("numberAvailable", numberAvailable, writeUnsignedInt(writeBuffer, 16));

// Simple Field (numberActive)
writeSimpleField("numberActive", numberActive, writeUnsignedInt(writeBuffer, 16));
// Optional Field (numberActive) (Can be skipped, if the value is null)
writeOptionalField("numberActive", numberActive, writeUnsignedInt(writeBuffer, 16));

// Array Field (data)
writeByteArrayField("data", data, writeByteArray(writeBuffer, 8));
Expand All @@ -111,11 +112,15 @@ public int getLengthInBits() {
lengthInBits += 16 * classId.size();
}

// Simple field (numberAvailable)
lengthInBits += 16;
// Optional Field (numberAvailable)
if (numberAvailable != null) {
lengthInBits += 16;
}

// Simple field (numberActive)
lengthInBits += 16;
// Optional Field (numberActive)
if (numberActive != null) {
lengthInBits += 16;
}

// Array field
if (data != null) {
Expand Down Expand Up @@ -156,13 +161,25 @@ public static CIPAttributes staticParse(ReadBuffer readBuffer, Integer packetLen
List<Integer> classId =
readCountArrayField("classId", readUnsignedInt(readBuffer, 16), numberOfClasses);

int numberAvailable = readSimpleField("numberAvailable", readUnsignedInt(readBuffer, 16));
Integer numberAvailable =
readOptionalField(
"numberAvailable",
readUnsignedInt(readBuffer, 16),
(packetLength) >= (((((numberOfClasses) * (2))) + (4))));

int numberActive = readSimpleField("numberActive", readUnsignedInt(readBuffer, 16));
Integer numberActive =
readOptionalField(
"numberActive",
readUnsignedInt(readBuffer, 16),
(packetLength) >= (((((numberOfClasses) * (2))) + (6))));

byte[] data =
readBuffer.readByteArray(
"data", Math.toIntExact((((packetLength) - (2)) - (((COUNT(classId)) * (2)))) - (4)));
"data",
Math.toIntExact(
((((packetLength) > (((((numberOfClasses) * (2))) + (6)))))
? (packetLength) - (((((numberOfClasses) * (2))) + (6)))
: 0)));

readBuffer.closeContext("CIPAttributes");
// Create the instance
Expand Down

0 comments on commit 07fa836

Please sign in to comment.