Skip to content

Commit

Permalink
fix(s7comm): Commented out some recent changes in order to get the bu…
Browse files Browse the repository at this point in the history
…ild running again.
  • Loading branch information
chrisdutz committed Jan 29, 2023
1 parent 09b3714 commit 46ed026
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 49 deletions.
6 changes: 3 additions & 3 deletions plc4c/generated-sources/s7/src/s7_var_payload_data_item.c
Expand Up @@ -83,7 +83,7 @@ plc4c_return_code plc4c_s7_read_write_s7_var_payload_data_item_parse(plc4c_spi_r

// Padding Field (padding)
{
int _timesPadding = (int) ((plc4c_spi_read_has_more(readBuffer, 8)) && ((plc4c_spi_evaluation_helper_count(data)) % (2)));
int _timesPadding = (int) ((plc4c_spi_read_has_more(readBuffer, 8)) && (((plc4c_spi_evaluation_helper_count(data)) % (2))));
while (_timesPadding-- > 0) {
// Just read the padding data and ignore it
uint8_t _paddingValue = 0;
Expand Down Expand Up @@ -130,7 +130,7 @@ plc4c_return_code plc4c_s7_read_write_s7_var_payload_data_item_serialize(plc4c_s

// Padding Field (padding)
{
int _timesPadding = (int) ((plc4c_spi_evaluation_helper_count(_message->data)) % (2));
int _timesPadding = (int) (((plc4c_spi_evaluation_helper_count(_message->data)) % (2)));
while (_timesPadding-- > 0) {
// Just output the default padding data
_res = plc4c_spi_write_unsigned_byte(writeBuffer, 8, 0x00);
Expand Down Expand Up @@ -163,7 +163,7 @@ uint16_t plc4c_s7_read_write_s7_var_payload_data_item_length_in_bits(plc4c_s7_re
lengthInBits += 8 * plc4c_utils_list_size(_message->data);

// Padding Field (padding)
int _needsPadding = (int) ((plc4c_spi_evaluation_helper_count(_message->data)) % (2));
int _needsPadding = (int) (((plc4c_spi_evaluation_helper_count(_message->data)) % (2)));
while(_needsPadding-- > 0) {
lengthInBits += 8;
}
Expand Down
4 changes: 2 additions & 2 deletions plc4go/protocols/s7/readwrite/model/S7VarPayloadDataItem.go

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

Expand Up @@ -103,7 +103,7 @@ public static S7PayloadBuilder staticParseS7PayloadBuilder(
readCountArrayField(
"items",
new DataReaderComplexDefault<>(
() -> S7VarPayloadDataItem.staticParse(readBuffer, (boolean) (true)), readBuffer),
() -> S7VarPayloadDataItem.staticParse(readBuffer), readBuffer),
CAST(parameter, S7ParameterReadVarResponse.class).getNumItems());

readBuffer.closeContext("S7PayloadReadVarResponse");
Expand Down
Expand Up @@ -42,19 +42,12 @@ public class S7VarPayloadDataItem implements Message {
protected final DataTransportSize transportSize;
protected final byte[] data;

// Arguments.
protected final Boolean hasNext;

public S7VarPayloadDataItem(
DataTransportErrorCode returnCode,
DataTransportSize transportSize,
byte[] data,
Boolean hasNext) {
DataTransportErrorCode returnCode, DataTransportSize transportSize, byte[] data) {
super();
this.returnCode = returnCode;
this.transportSize = transportSize;
this.data = data;
this.hasNext = hasNext;
}

public DataTransportErrorCode getReturnCode() {
Expand Down Expand Up @@ -109,10 +102,7 @@ public void serialize(WriteBuffer writeBuffer) throws SerializationException {

// Padding Field (padding)
writePaddingField(
"padding",
(int) (((PADCOUNT(data, hasNext)) % (2))),
(short) 0x00,
writeUnsignedShort(writeBuffer, 8));
"padding", (int) (((COUNT(data)) % (2))), (short) 0x00, writeUnsignedShort(writeBuffer, 8));

writeBuffer.popContext("S7VarPayloadDataItem");
}
Expand Down Expand Up @@ -142,7 +132,7 @@ public int getLengthInBits() {
}

// Padding Field (padding)
int _timesPadding = (int) (((PADCOUNT(data, hasNext)) % (2)));
int _timesPadding = (int) (((COUNT(data)) % (2)));
while (_timesPadding-- > 0) {
lengthInBits += 8;
}
Expand All @@ -153,25 +143,10 @@ public int getLengthInBits() {
public static S7VarPayloadDataItem staticParse(ReadBuffer readBuffer, Object... args)
throws ParseException {
PositionAware positionAware = readBuffer;
if ((args == null) || (args.length != 1)) {
throw new PlcRuntimeException(
"Wrong number of arguments, expected 1, but got " + args.length);
}
Boolean hasNext;
if (args[0] instanceof Boolean) {
hasNext = (Boolean) args[0];
} else if (args[0] instanceof String) {
hasNext = Boolean.valueOf((String) args[0]);
} else {
throw new PlcRuntimeException(
"Argument 0 expected to be of type Boolean or a string which is parseable but was "
+ args[0].getClass().getName());
}
return staticParse(readBuffer, hasNext);
return staticParse(readBuffer);
}

public static S7VarPayloadDataItem staticParse(ReadBuffer readBuffer, Boolean hasNext)
throws ParseException {
public static S7VarPayloadDataItem staticParse(ReadBuffer readBuffer) throws ParseException {
readBuffer.pullContext("S7VarPayloadDataItem");
PositionAware positionAware = readBuffer;
int startPos = positionAware.getPos();
Expand Down Expand Up @@ -199,12 +174,12 @@ public static S7VarPayloadDataItem staticParse(ReadBuffer readBuffer, Boolean ha
Math.toIntExact(
((transportSize.getSizeInBits()) ? CEIL((dataLength) / (8.0)) : dataLength)));

readPaddingField(readUnsignedShort(readBuffer, 8), (int) (((PADCOUNT(data, hasNext)) % (2))));
readPaddingField(readUnsignedShort(readBuffer, 8), (int) (((COUNT(data)) % (2))));

readBuffer.closeContext("S7VarPayloadDataItem");
// Create the instance
S7VarPayloadDataItem _s7VarPayloadDataItem;
_s7VarPayloadDataItem = new S7VarPayloadDataItem(returnCode, transportSize, data, hasNext);
_s7VarPayloadDataItem = new S7VarPayloadDataItem(returnCode, transportSize, data);
return _s7VarPayloadDataItem;
}

Expand Down
Expand Up @@ -931,7 +931,7 @@ private S7VarPayloadDataItem serializePlcValue(S7Tag tag, PlcValue plcValue, Boo
}
if (byteBuffer != null) {
byte[] data = byteBuffer.array();
return new S7VarPayloadDataItem(DataTransportErrorCode.OK, transportSize, data, hasNext);
return new S7VarPayloadDataItem(DataTransportErrorCode.OK, transportSize, data/*, hasNext*/);
}
} catch (SerializationException e) {
logger.warn("Error serializing tag item of type: '{}'", tag.getDataType().name(), e);
Expand Down
3 changes: 1 addition & 2 deletions plc4j/drivers/s7/src/test/java/S7IoTest.java
Expand Up @@ -340,8 +340,7 @@ void TestS7MessageBytes() throws Exception {
new S7VarPayloadDataItem(
DataTransportErrorCode.OK,
DataTransportSize.BIT,
new byte[]{0x1},
false
new byte[]{0x1}
)
)
),
Expand Down
Expand Up @@ -254,17 +254,17 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
final byte bitAddress = addressAny.getBitAddress();
switch (addressAny.getTransportSize()) {
case BOOL:
payloadItems.add(new S7VarPayloadDataItem(DataTransportErrorCode.OK, DataTransportSize.BIT, new byte[]{1}, true));
payloadItems.add(new S7VarPayloadDataItem(DataTransportErrorCode.OK, DataTransportSize.BIT, new byte[]{1}));
break;
case INT:
case UINT: {
String firstKey = context.getMemory().keySet().iterator().next();
Object value = context.getMemory().get(firstKey);
short shortValue = 42; // ((Number) value).shortValue();
short shortValue = ((Number) value).shortValue();
byte[] data = new byte[2];
data[1] = (byte) (shortValue & 0xff);
data[0] = (byte) ((shortValue >> 8) & 0xff);
payloadItems.add(new S7VarPayloadDataItem(DataTransportErrorCode.OK, DataTransportSize.BYTE_WORD_DWORD, data, true));
payloadItems.add(new S7VarPayloadDataItem(DataTransportErrorCode.OK, DataTransportSize.BYTE_WORD_DWORD, data));
break;
}
default: {
Expand All @@ -280,7 +280,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
addressAny.getNumberOfElements() : addressAny.getTransportSize().getSizeInBytes() * 8;
final BitSet bitSet = toBitSet(context.getDigitalInputs(), ioNumber, numElements);
final byte[] data = Arrays.copyOf(bitSet.toByteArray(), (numElements + 7) / 8);
payloadItems.add(new S7VarPayloadDataItem(DataTransportErrorCode.OK, DataTransportSize.BYTE_WORD_DWORD, data, true));
payloadItems.add(new S7VarPayloadDataItem(DataTransportErrorCode.OK, DataTransportSize.BYTE_WORD_DWORD, data));
break;
}
}
Expand Down
8 changes: 4 additions & 4 deletions protocols/s7/src/main/resources/protocols/s7/s7.mspec
Expand Up @@ -223,7 +223,7 @@
[discriminatedType S7Payload (uint 8 messageType, S7Parameter parameter)
[typeSwitch parameter.parameterType, messageType
['0x04','0x03' S7PayloadReadVarResponse
[array S7VarPayloadDataItem ('true') items count 'CAST(parameter, "S7ParameterReadVarResponse").numItems']
[array S7VarPayloadDataItem /*('true')*/ items count 'CAST(parameter, "S7ParameterReadVarResponse").numItems']
]
['0x05','0x01' S7PayloadWriteVarRequest
[array S7VarPayloadDataItem items count 'COUNT(CAST(parameter, "S7ParameterWriteVarRequest").items)']
Expand All @@ -240,13 +240,13 @@
// This is actually not quite correct as depending pon the transportSize the length is either defined in bits or bytes.
//@param hasNext In the serialization process, if you have multiple write
// requests the last element does not require padding.
[type S7VarPayloadDataItem(bit hasNext)
[type S7VarPayloadDataItem/*(bit hasNext)*/
[simple DataTransportErrorCode returnCode]
[simple DataTransportSize transportSize]
[implicit uint 16 dataLength 'COUNT(data) * ((transportSize == DataTransportSize.BIT) ? 1 : (transportSize.sizeInBits ? 8 : 1))']
[array byte data count 'transportSize.sizeInBits ? CEIL(dataLength / 8.0) : dataLength']
//[padding uint 8 pad '0x00' '(COUNT(data) % 2)']
[padding uint 8 pad '0x00' '(PADCOUNT(data, hasNext) % 2)']
[padding uint 8 pad '0x00' '(COUNT(data) % 2)']
//[padding uint 8 pad '0x00' '(PADCOUNT(data, hasNext) % 2)']
]
[type S7VarPayloadStatusItem
Expand Down

0 comments on commit 46ed026

Please sign in to comment.