Skip to content

Commit

Permalink
fix(plc4net): Changed the KnxDatatypes to use BitStrings for BYTE, WO…
Browse files Browse the repository at this point in the history
…RD, DWORD and LWORD
  • Loading branch information
chrisdutz committed May 31, 2022
1 parent 57d5c1e commit 06a9b34
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ private String toStaticCallParseExpression(Field field, TypeReference resultType
}*/
}
sb.append(")");
if (variableLiteral.getIndex() != VariableLiteral.NO_INDEX) {
if (variableLiteral.getIndex().isPresent()) {
// TODO: If this is a byte typed field, this needs to be an array accessor instead.
sb.append(".get(").append(variableLiteral.getIndex()).append(")");
}
Expand All @@ -949,7 +949,7 @@ private String toFunctionCallParseExpression(Field field, TypeReference resultTy
}
sb.append(")");
}
if (variableLiteral.getIndex() != VariableLiteral.NO_INDEX) {
if (variableLiteral.getIndex().isPresent()) {
// TODO: If this is a byte typed field, this needs to be an array accessor instead.
sb.append(".get(").append(variableLiteral.getIndex()).append(")");
}
Expand Down Expand Up @@ -1127,10 +1127,10 @@ private String toVariableExpressionRest(Field field, TypeReference resultType, V
String variableLiteralName = variableLiteral.getName();
if (variableLiteralName.equals("length")) {
tracer = tracer.dive("length");
return tracer + variableLiteralName + "()" + ((variableLiteral.isIndexed() ? ".get(" + variableLiteral.getIndex() + ")" : "") +
return tracer + variableLiteralName + "()" + ((variableLiteral.getIndex().isPresent() ? ".get(" + variableLiteral.getIndex() + ")" : "") +
variableLiteral.getChild().map(child -> "." + toVariableExpressionRest(field, resultType, child)).orElse(""));
}
return tracer + "get" + WordUtils.capitalize(variableLiteralName) + "()" + ((variableLiteral.isIndexed() ? ".get(" + variableLiteral.getIndex() + ")" : "") +
return tracer + "get" + WordUtils.capitalize(variableLiteralName) + "()" + ((variableLiteral.getIndex().isPresent() ? ".get(" + variableLiteral.getIndex() + ")" : "") +
variableLiteral.getChild().map(child -> "." + toVariableExpressionRest(field, resultType, child)).orElse(""));
}

Expand Down
24 changes: 12 additions & 12 deletions plc4go/protocols/knxnetip/readwrite/model/KnxDatapoint.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static IPlcValue StaticParse(ReadBuffer readBuffer, KnxDatapointType data
var value = readBuffer.ReadBit("");

return new PlcBOOL(value);
} else if( datapointType == KnxDatapointType.BYTE ) { // BYTE
} else if( datapointType == KnxDatapointType.BYTE ) { // BitString

// Reserved Field (Compartmentalized so the "reserved" variable can't leak)
{
Expand All @@ -63,8 +63,8 @@ public static IPlcValue StaticParse(ReadBuffer readBuffer, KnxDatapointType data
// Simple Field (value)
var value = readBuffer.ReadByte("", 8);

return new PlcBYTE(value);
} else if( datapointType == KnxDatapointType.WORD ) { // WORD
return new PlcBitString(value);
} else if( datapointType == KnxDatapointType.WORD ) { // BitString

// Reserved Field (Compartmentalized so the "reserved" variable can't leak)
{
Expand All @@ -77,8 +77,8 @@ public static IPlcValue StaticParse(ReadBuffer readBuffer, KnxDatapointType data
// Simple Field (value)
var value = readBuffer.ReadUshort("", 16);

return new PlcWORD(value);
} else if( datapointType == KnxDatapointType.DWORD ) { // DWORD
return new PlcBitString(value);
} else if( datapointType == KnxDatapointType.DWORD ) { // BitString

// Reserved Field (Compartmentalized so the "reserved" variable can't leak)
{
Expand All @@ -91,8 +91,8 @@ public static IPlcValue StaticParse(ReadBuffer readBuffer, KnxDatapointType data
// Simple Field (value)
var value = readBuffer.ReadUint("", 32);

return new PlcDWORD(value);
} else if( datapointType == KnxDatapointType.LWORD ) { // LWORD
return new PlcBitString(value);
} else if( datapointType == KnxDatapointType.LWORD ) { // BitString

// Reserved Field (Compartmentalized so the "reserved" variable can't leak)
{
Expand All @@ -105,7 +105,7 @@ public static IPlcValue StaticParse(ReadBuffer readBuffer, KnxDatapointType data
// Simple Field (value)
var value = readBuffer.ReadUlong("", 64);

return new PlcLWORD(value);
return new PlcBitString(value);
} else if( datapointType == KnxDatapointType.USINT ) { // USINT

// Reserved Field (Compartmentalized so the "reserved" variable can't leak)
Expand Down Expand Up @@ -6541,7 +6541,7 @@ public static WriteBuffer StaticSerialize(IPlcValue _value, KnxDatapointType dat
var value = (bool) _value.GetBool();
writeBuffer.WriteBit("", (value));
return writeBuffer;
} else if( datapointType == KnxDatapointType.BYTE ) { // BYTE
} else if( datapointType == KnxDatapointType.BYTE ) { // BitString
var writeBuffer = new WriteBuffer();

// Reserved Field
Expand All @@ -6550,7 +6550,7 @@ public static WriteBuffer StaticSerialize(IPlcValue _value, KnxDatapointType dat
var value = (byte) _value.GetByte();
writeBuffer.WriteByte("", 8, (byte) (value));
return writeBuffer;
} else if( datapointType == KnxDatapointType.WORD ) { // WORD
} else if( datapointType == KnxDatapointType.WORD ) { // BitString
var writeBuffer = new WriteBuffer();

// Reserved Field
Expand All @@ -6559,7 +6559,7 @@ public static WriteBuffer StaticSerialize(IPlcValue _value, KnxDatapointType dat
var value = (ushort) _value.GetUshort();
writeBuffer.WriteUshort("", 16, (ushort) (value));
return writeBuffer;
} else if( datapointType == KnxDatapointType.DWORD ) { // DWORD
} else if( datapointType == KnxDatapointType.DWORD ) { // BitString
var writeBuffer = new WriteBuffer();

// Reserved Field
Expand All @@ -6568,7 +6568,7 @@ public static WriteBuffer StaticSerialize(IPlcValue _value, KnxDatapointType dat
var value = (uint) _value.GetUint();
writeBuffer.WriteUint("", 32, (uint) (value));
return writeBuffer;
} else if( datapointType == KnxDatapointType.LWORD ) { // LWORD
} else if( datapointType == KnxDatapointType.LWORD ) { // BitString
var writeBuffer = new WriteBuffer();

// Reserved Field
Expand Down
19 changes: 19 additions & 0 deletions plc4net/spi/spi/model/values/PlcBitString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,25 @@ namespace org.apache.plc4net.spi.model.values
{
public class PlcBitString : PlcValueAdapter
{
public PlcBitString()
{
}

public PlcBitString(byte value)
{
}

public PlcBitString(ushort value)
{
}

public PlcBitString(uint value)
{
}

public PlcBitString(ulong value)
{
}

}
}

0 comments on commit 06a9b34

Please sign in to comment.