New Event_submit Asset_tracker_V2 Issue

I adding an Event to Asset_Tracker_V2. I have created bms_module_evnet.h and bms_event.c files in events folder and bms_module.c. I have defined inclusion of these files in corresponding CMakeLists.TXT files.  I added the BMS related states, enumerated parameters etc in app_module_event.c and app_module_event.h file also. I have added code of bms part in app_event_handler function of main.c. 

I wrote code to :

1. sent BMS Events in response to (IS_EVENT(msg, app, APP_EVT_START)), (IS_EVENT(msg, app, APP_EVT_CONFIG_GET)) ,  (IS_EVENT(msg, app, APP_EVT_DATA_GET)) Events generated by app_module. When, I run the program and observe the various Events. The APP_EVT_START event by event_manager is generated at initial stage. In response to it various other modules like UI, DATA, CLOUD, MODEM etc submit their events, but BMS event is not seen, while I have written the code to respond to APP_EVT_START event in on_state_init() function.

What may be the reason ? 1.  BMS_THREAD not initialized 2. module_get_next_msg(&self, &msg); function not getting any messages 3.   In the  on_state_init() function, Event is not detected or Event is not submitted. So, please explain me how to add an event.

The major files, where  I have added BMS code are in attachment. At last, the log file created by LTE_LINK_MONITOR is attached. 

         

Parents
  • Hi,

    One potential problem I see in your code is that you don't create a unique name for your BMS module event listener. So it might be that your event handler is overwritten by another module (e.g. the main module).

    I also notice that your BMS log_event function doesn't actually do anything. Are you sure this isn't just a case of missing logging?

    Best regards,

    Didrik

Reply
  • Hi,

    One potential problem I see in your code is that you don't create a unique name for your BMS module event listener. So it might be that your event handler is overwritten by another module (e.g. the main module).

    I also notice that your BMS log_event function doesn't actually do anything. Are you sure this isn't just a case of missing logging?

    Best regards,

    Didrik

Children
  • Hi, I have changed the name of event_handler fucntion. I want to know little more about log_event function. It is used to stingfy the event. The log_event function returns int and sprintf function is used to display the event information. Is the information returned by

    return snprintf(buf, buf_len, "%s", get_evt_type_str(event->type));

    displayed in LTE_LINK _MONITOR also ? 

    How is log_event handled in EVENT_TYPE_DEFINE ?

    Also, there are two functions in the thread_fn, LOG_ERR() and SEND_ERROR()... What is operational and execution difference in these ? Where are these used ? Where the LOG functions stores the information and where SEND_ERROR sends the information ?

    Where is the information sent by LOG_DBG ?

    //***

    After testing as per your suggestions in previous reply, I shall report you the status of results. Meanwhile, may please you clarify my doubts ? 

  • mexco said:

    Is the information returned by

    return snprintf(buf, buf_len, "%s", get_evt_type_str(event->type));

    displayed in LTE_LINK _MONITOR also ? 

    Yes, if CONFIG_LOG is set. Though this way of doing it (snprintf into buf) has been deprecated, and will be removed in a future NCS version.

    The new way to use the log function is shown in our documentation: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.9.1/nrf/libraries/others/event_manager.html#create-a-source-file

    mexco said:
    Also, there are two functions in the thread_fn, LOG_ERR() and SEND_ERROR()... What is operational and execution difference in these ? Where are these used ? Where the LOG functions stores the information and where SEND_ERROR sends the information ?

    If we look at this piece of code from your bms module, assuming err is -5:

    	err = module_start(&self);
    	if (err) {
    		LOG_ERR("Failed starting module, error: %d", err);
    		SEND_ERROR(bms, BMS_DATA_ERROR, err);
    	}

    LOG_ERR will log (print to the console) "Failed starting module, error -5" with log level ERROR.

    SEND_ERROR will create a event from the bms module, of type BMS_DATA_ERROR, and data.err will be -5. The event is sent to anyone who is listening for that type of events.

    mexco said:
    Where is the information sent by LOG_DBG ?

    If log level debug (DBG) is enabled, and uart is used as the log backend, the information will be sent over the uart.

Related