7 Replies Latest reply on Nov 21, 2014 10:25 AM by VictorZ_46

    How to register callback for ADV events ?

    madmax

      How can I register callback for ADV events, for example when the timer for HIGH_UNDIRECTED_DISCOVERABLE expires ?

      I managed to do similar thing for SCAN events using:

      blecen_usertimerCb = hello_client_timer_callback;

      but this does not work for ADV events.



        • 1. Re: How to register callback for ADV events ?
          VictorZ_46

          you can register event to be notified when advertisements stop

          bleprofile_regAppEvtHandler(BLECM_APP_EVT_ADV_TIMEOUT, hello_sensor_advertisement_stopped);

          If you need to know when advertisement changes from high duty to low duty, you will need to monitor time.  For example if you configured high duty advertisement durations for 30 seconds

          /*.high_undirect_adv_duration =*/ 30,  // seconds

          and you have 1 second timer running

           

          bleprofile_regTimerCb(hello_sensor_fine_timeout, hello_sensor_timeout);

           

          bleprofile_StartTimer();

          you can bet that after 30 times you enter hello_sensor_timeout the advertisements will go from high duty to low duty.

           

          1 of 1 people found this helpful
          • 2. Re: How to register callback for ADV events ?
            madmax

            I need to intercept the transition HIGH->LOW and LOW->OFF (before it happens)

            For SCAN it can be done this way:

             

            extern BLEAPP_TIMER_CB  blecen_usertimerCb;

            void app_create(void)

            {

                ...

                blecen_usertimerCb = app_timer_callback ;

                ...

            }

            void app_timer_callback(UINT32 arg)

            {

                switch(arg)

                {

                case BLEAPP_APP_TIMER_SCAN:

                    if (blecen_GetScan() == HIGH_SCAN)

                    {

                      //custom code here

                    }

                    else if (blecen_GetScan() == LOW_SCAN)

                    {

                      //custom code here       

                    }

                    break;

                }

            }

             

            Please note that the above also works for CONN:

            just add:

                 case BLEAPP_APP_TIMER_CONN:

            but it does not work for:

                 case BLEAPP_APP_TIMER_ADV:

             

            So how can I do same thing for ADV ?

            Why is BLEAPP_APP_TIMER_ADV special ? how to handle it ?

             

            VictorZ_46

            • 3. Re: How to register callback for ADV events ?
              VictorZ_46

              There is no API for that.  If you set high duty advertisements for 30 seconds and you want to be notified before that the best resolution you can get is 30 seconds - 12.5 milliseconds.  And this is done only using timers.  And as I mentioned you are notified when transition is to OFF.

              1 of 1 people found this helpful
              • 4. Re: How to register callback for ADV events ?
                madmax

                The reason I want to intercept this event is that I want to control the transition:

                Here is working example for SCAN:

                    case BLEAPP_APP_TIMER_SCAN:

                        if (blecen_GetScan() == HIGH_SCAN)

                        {

                          //decide whether change to LOW_SCAN or not

                          if (change_to_low)

                               blecen_Scan(LOW_SCAN);

                        }


                Knowing only when this happens using different timer does not help here.

                Is it possible at all for ADV ?

                • 5. Re: How to register callback for ADV events ?
                  VictorZ_46

                  on_timer_events()

                  {

                      if (running_high_duty_adverts && (time_since_started_high_duty_adverts == 31) && need_to_keep_high_duty_adverts)

                      {

                          start_high_duty_adverts();

                      }

                  }

                  • 6. Re: How to register callback for ADV events ?
                    madmax

                    is there a reason why :

                    BLEAPP_APP_TIMER_ADV


                    unlike:

                    BLEAPP_APP_TIMER_CONN and

                    BLEAPP_APP_TIMER_SCAN

                     

                    cannot be handled in user's timer callback ?

                    • 7. Re: How to register callback for ADV events ?
                      VictorZ_46

                      Very good question.  We will consider your suggestion for the next version of ROM.

                      1 of 1 people found this helpful