Menu

Accessing event data in QM

KJC
2022-01-24
2022-01-25
  • KJC

    KJC - 2022-01-24

    Do you have any examples showing how to access user defined event data in QM? I'm using QPCPP for the DUE

     
  • Quantum Leaps

    Quantum Leaps - 2022-01-24

    I presume that by "the DUE" you mean Arduino DUE. In that case, the QPCPP-Arduino library comes with the DPP example that shows events with parameters (directory libraries\qpcpp_arm-cm\examples\dpp_bsp-sam\dpp_bsp-sam.qm).

    Specifically, the model dpp_bsp-sam.qm contains the package Events with event TableEvt. Later in the code, you will see how these events are produced (e.g. Philo state machine, state "hungry", entry action):

    TableEvt *pe = Q_NEW(TableEvt, HUNGRY_SIG);
    pe->philoNum = PHILO_ID(this);
    AO_Table->POST(pe, this);
    

    And here is an example how the Table AO accesses the TableEvt (Table state machine, state "serving", transition HUNGRY).

    uint8_t n = Q_EVT_CAST(TableEvt)->philoNum;
    

    Please note the use of the macro Q_EVT_CAST(TableEvt). This macro encapsulates downcasting of the event pointer e (passed to all state handlers as parameter) from the base class QEvt to the subclass TableEvt in this case. Using macro for that allows to encapsulate this deviation from the MISRA /AUTOSAR rules.

    --MMS

     

    Last edit: Quantum Leaps 2022-01-24
  • KJC

    KJC - 2022-01-25

    I must have missed that one.

    thanks

     

Log in to post a comment.