Logging state-transition from stateflow in generated code

1 view (last 30 days)
I've been working with stateflow for a project, where I want to create some statecharts to run. I generated the code in C. To get some extra information when the statecharts are running, but I'm not connected to them I would like to add some logging of the state changes. I've been researching this for the better part of yesterday and found one option (https://nl.mathworks.com/help/rtw/ug/use-c-api-to-access-model-signals-and-states.html)
For my logging I would like to 'print' the state changes as they happen so I also have some idea of timing while running my application, something lile LED:off -> LED:on. In an ideal world you'd don't have to change anything in stateflow itself to add the logging, having to add a signal to every state for me is already a little bit of a feature I might forget from time to time.
When I look at how the signals are generated I see the following:
{ 0, 0, TARGET_STRING("statemachine/PoC/PoC/LED/LED.Off"),
TARGET_STRING("Off"), 0, 0, 0, 0, 0 },
{ 0, 0, TARGET_STRING("statemachine/PoC/PoC/LED/LED.On"),
TARGET_STRING("On"), 0, 0, 0, 0, 0 },
{ 0, 0, TARGET_STRING("statemachine/PoC/PoC/Button/Button.Pressed"),
TARGET_STRING("Pressed"), 0, 0, 0, 0, 0 },
In the list it's not initally clear that the upper two states are together and the third one is from another statemachine. I can make an implemenation that looks at this with the target strings and paths, but to me it feels that it doesn't have to be that complicated.
I thought there might be a more intiutive/easier option to do this, but haven't been able to find it. Does anyone know if some type of magical button that automatically add this logging into C code? Or makes the information accesable there? Are the signals the best way to go, or are there better options?

Answers (1)

Mark McBroom
Mark McBroom on 3 Aug 2022
Edited: Mark McBroom on 3 Aug 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by