Back to mbed
Overview
The adapter java file is used to help generate the code for the specific actor. It is paired with a file with the actual code template to be used with the generated code.
File Structure
When the Code generation actor is used, it looks at the package specified for the adapter and template files. In the case of the mbed, generic.program.procedural.c.mbed
is used, which will search at ptolemy/cg/generic/program/procedural/c/mbed
where the makefile.in
file is located. From here, the file structure from the actual actor file is mirrored. So the adapter java file and c template files are located farther under the mbed directory, near adapters/ptolemy/actor/lib
then whatever sub-directory the actual actor java is located in. For example, the Display is under gui
, and the GPIOWriter is under io
instead. When a new adapter is added, the makefile in the directory it is located in must add the java file, if a new folder is added (such as when I created a new io
folder), then the makefile under the lib
folder must update to include this.
If an adapter is not found in the given package, it will traverse upwards until it finds one. So if mbed
does not have the Display.java actor adaptor, it will then look up at c
, then procedural
, and so on.
Getting Started
The class should have the same name as the actor class itself. If no other adapter for this actor exists, then this class will extend NamedProgramCodeGeneratorActor
, otherwise it should extend the adapter closest to package you are in. For example, the Display adapter for mbed
will extend the adapter in generic.program.procedural.c
. This is convenient since the adapter did not even need to be modified.
TODO: Add more sections, I pretty much just copied the display actor adapter, more work is being done to learn how the adapter works.
Creating the c template file