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
protocolmodule for your protocol. -
Create the
pom.xmlfile for the new module. -
Create a new
mspecfile insrc/main/release/with just one or two dummy types. -
Create a new
Protocolclass insrc/main/javawhich 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.Protocoland list the new protocol class. -
Test you can build the new protocol module.
Prepare a new driver module
-
Create a new
drivermodule underplc4j/drivers -
Create the
pom.xmlfile for the new module.-
Be sure to add a maven dependency to your protocol module.
-
Be sure you have the
update-generated-codeprofile in there. -
Be sure to reference the protocol name used in your protocol module.
-
-
Create the
Driverclass insrc/main/javawhich implementsorg.apache.plc4x.java.api.PlcDriver. -
Create a file called
src/main/resources/META-INF/services/org.apache.plc4x.java.api.PlcDriverand 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.xmlin the protocol modulessrc/test/resourcesdirectory. -
Start adding empty test-cases for every packet in your recording, by copying the TCP/UDP/Whatever payload in Wireshark as
hex-streamand pasting that in therawelement of a test-case. -
In the driver module, create a ParserSerializer test that extends
org.apache.plc4x.test.parserserializer.ParserSerializerTestsuiteRunnerinsrc/test/javawhich references theParserSerializerTestsuite.xmlfile of your protocol module. -
Iteratively implement all the
mspectypes needed to process your captures:-
Add/update the types in the
mspecfile -
Rebuild the protocol module
-
Rebuild the driver module (with the
update-generate-codeprofile enabled) -
Run the ParserSerializer test
-