This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Question about GAP_DeviceDiscoveryRequest();

 

Hello,

I´m implementing a master bluetooth on development kit dongle based on SimpleBLEPeripheral code. My system will receive the commands from UART and it performs the tasks according commands. The uart communication is working fine and now I've been programming  the code to request the Devices discovery when the command arrives from uart which generates a event that is processeced by  the code showed below:


 if ( events & ESCANEARDEVICES )

 {

    bStatus_t retorno;

    gapDevDivReq.taskID    = EMGsensor_TaskID;

    gapDevDivReq.mode      = DEVDISC_MODE_ALL;

    gapDevDivReq.nameMode  = TRUE;

    gapDevDivReq.whiteList = FALSE;

   return = GAP_DeviceDiscoveryRequest (&gapDevDivReq);

    HalUARTWrite(HAL_UART_PORT_1,&return, 1);

    return ( events ^ ESCANEARDEVICES );

 }


The return variable always receive 0x12 that means : bleIncorrectMode (Not setup properly to perform that task.) . Would I have to do to use properly this function?

Note: The GAP layer was initialized at began of program.


Looking forward to reply,


Sincerely 


Frederico

 

  • I can see one of the following reasons why this may be failing:

    1. You are using the wrong library file for a master device. Page 15 of the SW developer's guide (http://www.ti.com/litv/pdf/swru271) contains a table of the different library files.

    2. Even though you are calling GAP_DeviceInit, are you waiting for the GAP_DeviceInitDone event to be returned?

    3. When you call GAP_DeviceInit, do you have the parameter profileRole set to GAP_PROFILE_PERIPHERAL?

  • Hello,

    1 - I´m using ble_single_chip_master_pm_off.lib.

    2 - I´m not finding at the code where the program process GAP_DeviceInitDone event, but the first command to discovery devices arrives 5 seconds after the system turns on.

    3 - Yes, The parameter profileRole is set to GAP_PROFILE_PERIPHERAL.

     

    Looking forward to  reply

    Sincerely 

    Frederico

  • Hello,

    I corrected the startup gap parameters where the code is showed below:

    // Initialize the Profile Advertising and Connection Parameters gapRole_profileRole = GAP_PROFILE_CENTRAL; VOID osal_memset( gapRole_IRK, 0, KEYLEN ); VOID osal_memset( gapRole_SRK, 0, KEYLEN ); gapRole_signCounter = 0; gapRole_AdvEventType = GAP_ADTYPE_ADV_IND; gapRole_AdvDirectType = ADDRTYPE_PUBLIC; gapRole_AdvChanMap = GAP_ADVCHAN_ALL; gapRole_AdvFilterPolicy = GAP_FILTER_POLICY_ALL;

    .

    .

    .

    VOID GAP_DeviceInit( gapRole_TaskID, gapRole_profileRole, 5, gapRole_IRK, gapRole_SRK, &gapRole_signCounter );

     

    Now, the code returns 0x00 when it tries request for discoverable devices and if the function GAP_DeviceDiscoveryRequest (&gapDevDivReq) is called is called immediately after, it returns 0x11 which means "bleAlreadyInRequestedMode", but no event is generated when DeviceDiscoveryRequest is lauched. Why is event not generated?


    Looking foward to reply

    Sincerely

    Frederico

  • Hello,

    The function device discovery request is working now. 

    Thanks for your help!

    Frederico

  • Frederico,

    I am working a problem very similar to this....  would you have a small source-code example to share of exactly what you did....

    I have successfully called GAP_DeviceInit and received an event, but then my successful call to GAP_DeviceDiscoveryRequest never returns an event within the default 10 seconds...

    thanks in advance.

     

  • How did you solve that problem?

  • Hello,


    I´m sorry for a late answer, but I was travelling.
    So,you must to treat the event in the function that works with OSALMsg. If you are using the simpleBLEPeripheral demo code you can find this function with name

    static void simpleBLEPeripheral_ProcessOSALMsg (osal_event_hdr_t * PMsg)

    To example how I did, I pasted my code below. (I changed the function name according my project name)

     

    /*********************************************************************
     * @fn      Sensor_ProcessOSALMsg
     *
     * @brief   Process an incoming task message.
     *
     * @param   pMsg - message to process
     *
     * @return  none
     */
    static void Sensor_ProcessOSALMsg( uint8 *pMsg )
    {
      uint8 i0,i1;    // Contadores auxiliares
      uint8 frase[5];
      // Cria ponteiro do tipo gapDevEvent_t apontado para a mesma posição de memória que pMsg.
      pGapDevDiscEvent = (gapDevDiscEvent_t *)pMsg;
     
      switch ( pGapDevDiscEvent->opcode )
      {
        // Se processo de escaneamento terminou, guardar quantidade da dispositivos encontrados e
        // a respectiva lista de endereços.
        case GAP_DEVICE_DISCOVERY_EVENT:
         
          // Armazenar número de dispositivos encontrados.
          endDevicesOn.qtdDevAchados = pGapDevDiscEvent->numDevs;
     
          // Avisa quantos dispostivos foram encontrados e quais são seus respectivos endereços.
          HalUARTWrite(HAL_UART_PORT_1,&pGapDevDiscEvent->numDevs, 1);
          HalUARTWrite(HAL_UART_PORT_1,pGapDevDiscEvent->pDevList->addr, 14);
         
          for(i0 = 0; i0 < endDevicesOn.qtdDevAchados; i0++)
          {
            for(i1 = 0 ; i1 < 6 ; i1++)
            {
              // Copiar endereços para o Buffer.
              endDevicesOn.enderecosDevicesOn[i0][i1] = pGapDevDiscEvent->pDevList->addr[i1];
            }
           
            // Ignora bytes de transição.
            pGapDevDiscEvent->pDevList ++;
          } 
         
        break;
       
        case GAP_LINK_ESTABLISHED_EVENT:
            frase[0] = 'L';
            frase[1] = 'i';
            frase[2] = 'n';
            frase[3] = 'k';
            frase[4] = ' ';
           HalUARTWrite(HAL_UART_PORT_1,frase, 5);
          
           // Permite processo de desconexão.
           statusConexao = 1;
        break;
       
        case GAP_LINK_TERMINATED_EVENT:
           frase[0] = 'D';
           frase[1] = 'e';
           frase[2] = 's';
           frase[3] = 'c';
           frase[4] = ' ';
           HalUARTWrite(HAL_UART_PORT_1,frase, 5);
        
           if(coletarAmostras)  statusConexao = 2;   // Permite conexão.
           else                 statusConexao = 0;   // Não permite mais conexão.

        break;
      }
    }

    Best Regards

    Frederico

  • my problem, it turned out, was that i was linking with a library with power-mgmt *ON* and not *OFF*!!!!   for some reason, the power-mgmt stuff did seem to work on the master side....