It provides a way to store several differently behaving applications in a single binary, and a way to define a function for each event state.
The App_Tag end device combines the handling of several sensors into a single application and switches the behaviour depending on the configuration.
Each vProcessEv_? .c file contains the definition of the application and the procedures for its individual behaviour.
Defining a callback function
Callback functions are defined statically, which is not a good way to combine multiple application behaviours into one. Here, they are defined static in the source file.
Finally, we have the tsCbHandler structure in the list.
/** * Application Handler Definition * If it is not used, set it to `NULL`. */static tsCbHandler sCbHandler = {NULL, // cbAppToCoNet_u8HwInt, cbAppToCoNet_vHwEvent,NULL, // cbAppToCoNet_vMain,NULL, // cbAppToCoNet_vNwkEvent,NULL, // cbAppToCoNet_vRxEvent, cbAppToCoNet_vTxEvent};
State definitions
You can define as many events as you wish to use.
/** * Event processing function list */staticconst tsToCoNet_Event_StateHandler asStateFuncTbl[]= {PRSEV_HANDLER_TBL_DEF(E_STATE_IDLE),PRSEV_HANDLER_TBL_DEF(E_STATE_RUNNING),PRSEV_HANDLER_TBL_DEF(E_STATE_APP_WAIT_TX),PRSEV_HANDLER_TBL_DEF(E_STATE_APP_SLEEP), PRSEV_HANDLER_TBL_TRM};
An entity is defined as follows:
PRSEV_HANDLER_TBL_DEF(E_STATE_IDLE, tsEvent *pEv, teEvent eEvent, uint32 u32evarg) {// State at the startif (eEvent == E_EVENT_START_UP) {// Event handling on power-up or sleep-wake ...ToCoNet_Event_SetState(pEv, E_STATE_RUNNING); }}PRSEV_HANDLER_TBL_DEF(E_STATE_RUNNING, tsEvent *pEv, teEvent eEvent, uint32 u32evarg) {// Running (acquisition of sensors data, transmission requests, etc.) bOk =bTransmitToParent( ... ); // Sending process.if ( bOk ) {ToCoNet_Event_SetState(pEv, E_STATE_APP_WAIT_TX); } else {ToCoNet_Event_SetState(pEv, E_STATE_APP_SLEEP); }}PRSEV_HANDLER_TBL_DEF(E_STATE_APP_WAIT_TX, tsEvent *pEv, teEvent eEvent, uint32 u32evarg) {// Waiting for transmission completionif (..) {ToCoNet_Event_SetState(pEv, E_STATE_APP_SLEEP); // スリープ状態へ遷移 }}PRSEV_HANDLER_DEF(E_STATE_APP_SLEEP, tsEvent *pEv, teEvent eEvent, uint32 u32evarg) {// Sleep procedure (example code below)if (eEvent == E_EVENT_NEW_STATE) {// Sleep API is always called in a place where it is called only once, such as in `E_EVENT_NEW_STATE`.V_PRINTF(LB"Sleeping...");V_FLUSH();// In the case of Mininode, there is no special processing, but the pause processingToCoNet_Nwk_bPause(sAppData.pContextNwk);// Enters cyclic sleep// - 5 seconds after the first time, 5 seconds after the next time, based on the return to sleepvSleep(sAppData.sFlash.sData.u32Slp,sAppData.u16frame_count ==1?FALSE:TRUE,FALSE); }}
Event handling functions
The event handling function is defined as follows. The event processing is done according to asStateFuncTbl prepared in the previous state definition.
This section describes the main file which contains the callback functions. The main file handles the calling of the functions for the individual processes defined above.
The user-defined event processing function and the TWELITE NET callback function should be defined as follows Call the application's own callback function, specified by the function pointer, to execute the application's own user-defined event processing.