Magic Draw
-
- Create a new empty model and add a package to it.

- Add the Embedded Engineer Profile by opening main menu:
-
FileUse ProjectUse Local
-
- Project In the Use Project dialog select
From predefined location<install.root>\profilesEmbeddedEngineerProfile.mdzip 
- Project In the Use Project dialog select
-
- Download and import the FSM Project Template
- Download link: MagicDraw_FSMProjectTemplate.mdzip
-
- Main menu:
FileImport FromAnother Project...and select the downloaded File. 

- Main menu:
-
- Apply the
LL EmbeddedStereotype to the new package 
- Set the
GenerationLanguageTagged Value to the language you would like to generate -
- Set the
GenSrcDirTagged Value to the output path where you would like to generate the code to (relative paths will be relative to the current EAP file location) 
- Set the
- Apply the
-
- Create a class diagram in the new package

-
- Create a new class

-
- To this class you may add child element such as StateMachines, Activities, Operations and Attributes

-
- When finished simply open the context menu in the new package in the containment tree and select
LL Embedded EngineerGenerate code 

- When finished simply open the context menu in the new package in the containment tree and select
- Using the generated code in your code
Example
This is just an example implementation to show you how to use the generated code.
// Include the main header file of the class
#include "MyClass.h"
int main(void)
{
// Get an instance for this class (statically allocated, will always return the same instance!)
MyClass* myClass = MyClass_new();
// Example on how to call the constructor (if one was modelled)
MyClass_MyConstructor(myClass);
// Example on how to initialize a state machine (if one was modelled)
MyClass_StateMachine_init(&myClass->StateMachine);
// Example on how to run a state machine (if one was modelled)
// The implementation on your target may differ
while (true)
{
// Call the state machine with no signal
MyClass_StateMachine(myClass, &myClass->StateMachine, NOSIG);
}
}
