Skip to content

Commit

Permalink
feat(modbus): Added some initial tests for Modbus-RTU and Modbus-ASCII
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdutz committed Mar 28, 2022
1 parent cc013c6 commit 48839ac
Show file tree
Hide file tree
Showing 11 changed files with 268 additions and 19 deletions.
26 changes: 21 additions & 5 deletions plc4go/internal/plc4go/knxnetip/readwrite/model/KnxManufacturer.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
@@ -0,0 +1,29 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.plc4x.java.modbus.ascii;

import org.apache.plc4x.test.parserserializer.ParserSerializerTestsuiteRunner;

public class ModbusAsciiParserSerializerTest extends ParserSerializerTestsuiteRunner {

public ModbusAsciiParserSerializerTest() {
super("/protocols/modbus/ascii/ParserSerializerTestsuite.xml");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.plc4x.java.modbus;
package org.apache.plc4x.java.modbus.rtu;

import org.apache.plc4x.test.parserserializer.ParserSerializerTestsuiteRunner;

public class ModbusParserSerializerTest extends ParserSerializerTestsuiteRunner {
public class ModbusRtuParserSerializerTest extends ParserSerializerTestsuiteRunner {

public ModbusParserSerializerTest() {
super("/protocols/modbus/ParserSerializerTestsuite.xml");
public ModbusRtuParserSerializerTest() {
super("/protocols/modbus/rtu/ParserSerializerTestsuite.xml");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.plc4x.java.modbus;
package org.apache.plc4x.java.modbus.tcp;

import org.apache.plc4x.test.driver.DriverTestsuiteRunner;

public class ModbusDriverIT extends DriverTestsuiteRunner {
public class ModbusTcpDriverIT extends DriverTestsuiteRunner {

public ModbusDriverIT() {
super("/protocols/modbus/DriverTestsuite.xml");
public ModbusTcpDriverIT() {
super("/protocols/modbus/tcp/DriverTestsuite.xml");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.plc4x.java.modbus.tcp;

import org.apache.plc4x.test.parserserializer.ParserSerializerTestsuiteRunner;

public class ModbusTcpParserSerializerTest extends ParserSerializerTestsuiteRunner {

public ModbusTcpParserSerializerTest() {
super("/protocols/modbus/tcp/ParserSerializerTestsuite.xml");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,9 @@ public enum KnxManufacturer
M_SHENZHEN_CONGXUN_INTELLIGENT_TECHNOLOGY_CO___LTD = 583,
M_ANDAS = 584,
M_HEFEI_CHUANG_YUE_INTELLIGENT_TECHNOLOGY_CO__LTD = 585,
M_ABB___RESERVED = 586,
M_BUSCH_JAEGER_ELEKTRO___RESERVED = 587,
M_LARFE = 586,
M_ABB___RESERVED = 587,
M_BUSCH_JAEGER_ELEKTRO___RESERVED = 588,
}

public static class KnxManufacturerInfo
Expand Down Expand Up @@ -2244,10 +2245,13 @@ public static class KnxManufacturerInfo
case KnxManufacturer.M_HEFEI_CHUANG_YUE_INTELLIGENT_TECHNOLOGY_CO__LTD: { /* '585' */
return 643;
}
case KnxManufacturer.M_ABB___RESERVED: { /* '586' */
case KnxManufacturer.M_LARFE: { /* '586' */
return 644;
}
case KnxManufacturer.M_ABB___RESERVED: { /* '587' */
return 43954;
}
case KnxManufacturer.M_BUSCH_JAEGER_ELEKTRO___RESERVED: { /* '587' */
case KnxManufacturer.M_BUSCH_JAEGER_ELEKTRO___RESERVED: { /* '588' */
return 43959;
}
case KnxManufacturer.M_ELECTRAK: { /* '59' */
Expand Down Expand Up @@ -4018,10 +4022,13 @@ public static string Name(this KnxManufacturer value)
case KnxManufacturer.M_HEFEI_CHUANG_YUE_INTELLIGENT_TECHNOLOGY_CO__LTD: { /* '585' */
return "Hefei Chuang Yue Intelligent Technology Co.,LTD";
}
case KnxManufacturer.M_ABB___RESERVED: { /* '586' */
case KnxManufacturer.M_LARFE: { /* '586' */
return "Larfe";
}
case KnxManufacturer.M_ABB___RESERVED: { /* '587' */
return "ABB - reserved";
}
case KnxManufacturer.M_BUSCH_JAEGER_ELEKTRO___RESERVED: { /* '587' */
case KnxManufacturer.M_BUSCH_JAEGER_ELEKTRO___RESERVED: { /* '588' */
return "Busch-Jaeger Elektro - reserved";
}
case KnxManufacturer.M_ELECTRAK: { /* '59' */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<test:testsuite xmlns:test="https://plc4x.apache.org/schemas/parser-serializer-testsuite.xsd"
byteOrder="BIG_ENDIAN">

<name>Modbus-ASCII</name>

<protocolName>modbus</protocolName>
<outputFlavor>read-write</outputFlavor>

<testcase>
<name>Read Holding Registers Request</name>
<raw>01030000000AF2</raw>
<root-type>ModbusADU</root-type>
<parser-arguments>
<driverType>MODBUS_ASCII</driverType>
<response>false</response>
</parser-arguments>
<xml>
<ModbusADU>
<ModbusAsciiADU>
<address dataType="uint" bitLength="8">1</address>
<pdu>
<ModbusPDU>
<errorFlag dataType="bit" bitLength="1">false</errorFlag>
<functionFlag dataType="uint" bitLength="7">3</functionFlag>
<ModbusPDUReadHoldingRegistersRequest>
<startingAddress dataType="uint" bitLength="16">0</startingAddress>
<quantity dataType="uint" bitLength="16">10</quantity>
</ModbusPDUReadHoldingRegistersRequest>
</ModbusPDU>
</pdu>
<crc dataType="uint" bitLength="8">242</crc>
</ModbusAsciiADU>
</ModbusADU>
</xml>
</testcase>

<testcase>
<name>Read Holding Registers Response</name>
<raw>0103140000000000000000000000000000000000000000E8</raw>
<root-type>ModbusADU</root-type>
<parser-arguments>
<driverType>MODBUS_ASCII</driverType>
<response>true</response>
</parser-arguments>
<xml>
<ModbusADU>
<ModbusAsciiADU>
<address dataType="uint" bitLength="8">1</address>
<pdu>
<ModbusPDU>
<errorFlag dataType="bit" bitLength="1">false</errorFlag>
<functionFlag dataType="uint" bitLength="7">3</functionFlag>
<ModbusPDUReadHoldingRegistersResponse>
<byteCount dataType="uint" bitLength="8">20</byteCount>
<value dataType="byte" bitLength="160">0x0000000000000000000000000000000000000000</value>
</ModbusPDUReadHoldingRegistersResponse>
</ModbusPDU>
</pdu>
<crc dataType="uint" bitLength="8">232</crc>
</ModbusAsciiADU>
</ModbusADU>
</xml>
</testcase>

</test:testsuite>
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<test:testsuite xmlns:test="https://plc4x.apache.org/schemas/parser-serializer-testsuite.xsd"
byteOrder="BIG_ENDIAN">

<name>Modbus-ADU</name>

<protocolName>modbus</protocolName>
<outputFlavor>read-write</outputFlavor>

<testcase>
<name>Read Holding Registers Request</name>
<raw>01030000000ac5cd</raw>
<root-type>ModbusADU</root-type>
<parser-arguments>
<driverType>MODBUS_RTU</driverType>
<response>false</response>
</parser-arguments>
<xml>
<ModbusADU>
<ModbusRtuADU>
<address dataType="uint" bitLength="8">1</address>
<pdu>
<ModbusPDU>
<errorFlag dataType="bit" bitLength="1">false</errorFlag>
<functionFlag dataType="uint" bitLength="7">3</functionFlag>
<ModbusPDUReadHoldingRegistersRequest>
<startingAddress dataType="uint" bitLength="16">0</startingAddress>
<quantity dataType="uint" bitLength="16">10</quantity>
</ModbusPDUReadHoldingRegistersRequest>
</ModbusPDU>
</pdu>
<crc dataType="uint" bitLength="16">50637</crc>
</ModbusRtuADU>
</ModbusADU>
</xml>
</testcase>

<testcase>
<name>Read Holding Registers Response</name>
<raw>0103140000000000000000000000000000000000000000a367</raw>
<root-type>ModbusADU</root-type>
<parser-arguments>
<driverType>MODBUS_RTU</driverType>
<response>true</response>
</parser-arguments>
<xml>
<ModbusADU>
<ModbusRtuADU>
<address dataType="uint" bitLength="8">1</address>
<pdu>
<ModbusPDU>
<errorFlag dataType="bit" bitLength="1">false</errorFlag>
<functionFlag dataType="uint" bitLength="7">3</functionFlag>
<ModbusPDUReadHoldingRegistersResponse>
<byteCount dataType="uint" bitLength="8">20</byteCount>
<value dataType="byte" bitLength="160">0x0000000000000000000000000000000000000000</value>
</ModbusPDUReadHoldingRegistersResponse>
</ModbusPDU>
</pdu>
<crc dataType="uint" bitLength="16">41831</crc>
</ModbusRtuADU>
</ModbusADU>
</xml>
</testcase>

</test:testsuite>

0 comments on commit 48839ac

Please sign in to comment.