Strategy for creating a new Driver
Please inspect other existing modules on how to implement some of this.
Prepare a new protocol module
-
Create a new
protocol
module for your protocol. -
Create the
pom.xml
file for the new module. -
Create a new
mspec
file insrc/main/release/
with just one or two dummy types. -
Create a new
Protocol
class insrc/main/java
which implementsorg.apache.plc4x.plugins.codegenerator.protocol.Protocol
.-
The value returned by
getName()
will be used in the maven driver code generation.
-
-
Create a new file called
src/main/resources/META-INF/services/org.apache.plc4x.plugins.codegenerator.protocol.Protocol
and list the new protocol class. -
Test you can build the new protocol module.
Prepare a new driver module
-
Create a new
driver
module underplc4j/drivers
-
Create the
pom.xml
file for the new module.-
Be sure to add a maven dependency to your protocol module.
-
Be sure you have the
update-generated-code
profile in there. -
Be sure to reference the protocol name used in your protocol module.
-
-
Create the
Driver
class insrc/main/java
which implementsorg.apache.plc4x.java.api.PlcDriver
. -
Create a file called
src/main/resources/META-INF/services/org.apache.plc4x.java.api.PlcDriver
and list the new driver class. -
Test you can build the new driver module and the code generation works.
Start implementing the protocol parser and serializer
-
Create a capture of the communication you want to create a driver for.
-
Open the capture in WireShark
-
Start defining the types you see in your mspec file
-
Create a file
ParserSerializerTestsuite.xml
in the protocol modulessrc/test/resources
directory. -
Start adding empty test-cases for every packet in your recording, by copying the TCP/UDP/Whatever payload in Wireshark as
hex-stream
and pasting that in theraw
element of a test-case. -
In the driver module, create a ParserSerializer test that extends
org.apache.plc4x.test.parserserializer.ParserSerializerTestsuiteRunner
insrc/test/java
which references theParserSerializerTestsuite.xml
file of your protocol module. -
Iteratively implement all the
mspec
types needed to process your captures:-
Add/update the types in the
mspec
file -
Rebuild the protocol module
-
Rebuild the driver module (with the
update-generate-code
profile enabled) -
Run the ParserSerializer test
-