extern void eom_emsappl_hid_userdef_on_entry_CFG(EOMtheEMSappl* p)
{    
    // pulse led3 forever at 0.50 hz.       
    eo_ledpulser_Start(eo_ledpulser_GetHandle(), eo_ledpulser_led_three, 2*EOK_reltime1sec, 0);

    // EOtheCANservice: set straight mode and force parsing of all packets in the RX queues.
    eo_canserv_SetMode(eo_canserv_GetHandle(), eocanserv_mode_straight);
    eo_canserv_ParseAll(eo_canserv_GetHandle());
    
    // tell the ethmonitor to alert the task of the configurator
//    eo_ethmonitor_SetAlert(eo_ethmonitor_GetHandle(), eom_emsconfigurator_GetTask(eom_emsconfigurator_GetHandle()), emsconfigurator_evt_userdef02);
    
    // prefer sending a tx request just in case. because cfg state transmit only if requested an we dont want to have missed a previous request.
    eom_task_SetEvent(eom_emsconfigurator_GetTask(eom_emsconfigurator_GetHandle()), emsconfigurator_evt_ropframeTx);    
}
extern void eom_emsconfigurator_hid_userdef_DoJustAfterPacketParsing(EOMtheEMSconfigurator *p)
{
#if defined(TOGGLE_RUN_CFG_WITH3RXPACKETS)
    static uint8_t num = 0;
    // just for debug
    if(0 == p->numofrxrops)
    {
        num++;
        if(3 == num)
        {
            num = 0;
//            eom_emsappl_ProcessEvent(eom_emsappl_GetHandle(), eo_sm_emsappl_EVgo2run);
            eom_task_SetEvent(eom_emsconfigurator_GetTask(eom_emsconfigurator_GetHandle()), emsconfigurator_evt_go2runner);
        }
    }
#endif
} 
static void s_eom_emsdiscoverylistener_task_run(EOMtask *p, uint32_t t)
{
    // the event that we have received
    eOevent_t evt = (eOevent_t)t;
    EOpacket* rxpkt = s_emsdiscoverylistener_singleton.rxpkt;
    EOpacket* replypkt = NULL;
    eOsizecntnr_t remainingrxpkts = 0;    

    
    if(eobool_true == eo_common_event_check(evt, emsdiscoverylistener_evt_packet_received))
    {   // process the reception of a packet. it must contain a frame with a particular protocol
        
    
        // 1. get the packet.    
        if(eores_OK == eo_socketdtg_Get(s_emsdiscoverylistener_singleton.socket, rxpkt, eok_reltimeZERO))
        {
                 
            // 2. process the packet with the transceiver
            if(eores_OK == eom_emsdiscoverytransceiver_Parse(eom_emsdiscoverytransceiver_GetHandle(), rxpkt))
            {
             
                // 3. retrieve the reply                
                if(eores_OK == eom_emsdiscoverytransceiver_GetReply(eom_emsdiscoverytransceiver_GetHandle(), &replypkt))
                {
                    // 4.  send a packet back. but only if the get_reply gave us a good one.
                    s_eom_emsdiscoverylistener_Transmit(&s_emsdiscoverylistener_singleton, replypkt);
                }
                
            }
        }
        
    
        // 5. if another packet is in the rx fifo, send a new event to process its retrieval again   
        eo_socketdtg_Received_NumberOf(s_emsdiscoverylistener_singleton.socket, &remainingrxpkts);
        
        if(remainingrxpkts > 0)
        {
            eom_task_SetEvent(p, emsdiscoverylistener_evt_packet_received); 
        }
        
    }
     
}
extern void eupdater_cangtw_start(eOipv4addr_t remipaddr)
{   
    if(1 != s_status)
    {
        return;
    }
    
    char str[128];
    snprintf(str, sizeof(str), "sending event_cangtw_start = %d", event_cangtw_start);
    hal_trace_puts(str); 

    eupdater_cangtw_set_remote_addr(remipaddr);
    
    // just emit the start event. the sm embedded in the can gateway task shall process it
    eom_task_SetEvent(eupdater_task_cangateway, event_cangtw_start);
    
    
    s_status = 2;
}
static void s_eo_candiscovery2_on_timer_expiry(void *arg)
{
    EOtheCANdiscovery2* p = (EOtheCANdiscovery2*)arg;
    
    p->searchstatus.tickingenabled = eobool_true;
    
    p->searchstatus.discoverynumretries ++;
    
    if(p->searchstatus.discoverynumretries >= p->discoverymaxretries)
    {   // make it stop ...
        p->searchstatus.forcestop = eobool_true;        
    }
        
    // ok, ... if we are in run i dont do anything else because i regularly call _Tick() every 1 ms.    
    // however, if in config mode i must alert the processing task to execute a _Tick().
    eOsmStatesEMSappl_t state = eo_sm_emsappl_STerr;
    eom_emsappl_GetCurrentState(eom_emsappl_GetHandle(), &state);
    if(eo_sm_emsappl_STcfg == state)
    {   // must send an event to the handling task
        eom_task_SetEvent(eom_emsconfigurator_GetTask(eom_emsconfigurator_GetHandle()), emsconfigurator_evt_userdef01);
    }    
}