Beispiel #1
0
/**
 * @brief   Start periodic RSSI reads on a link.
 *
 * Public function defined in central.h.
 */
bStatus_t GAPCentralRole_StartRssi( uint16 connHandle, uint16 period )
{
  gapCentralRoleRssi_t  *pRssi;

  // Verify link is up
  if (!linkDB_Up(connHandle))
  {
    return bleIncorrectMode;
  }

  // If already allocated
  if ((pRssi = gapCentralRole_RssiFind( connHandle )) != NULL)
  {
    // Stop timer
    osal_CbTimerStop( pRssi->timerId );
  }
  // Allocate structure
  else if ((pRssi = gapCentralRole_RssiAlloc( connHandle )) != NULL)
  {
    pRssi->period = period;
  }
  // Allocate failed
  else
  {
    return bleNoResources;
  }

  // Start timer
  osal_CbTimerStart( gapCentralRole_timerCB, (uint8 *) pRssi,
                     period, &pRssi->timerId );

  return SUCCESS;
}
Beispiel #2
0
/*********************************************************************
 * @fn          hidDevHandleConnStatusCB
 *
 * @brief       Reset client char config.
 *
 * @param       connHandle - connection handle
 * @param       changeType - type of change
 *
 * @return      none
 */
static void hidDevHandleConnStatusCB( uint16 connHandle, uint8 changeType )
{
  uint8           i;
  hidRptMap_t     *p = pHidDevRptTbl;
  uint16          retHandle;
  gattAttribute_t *pAttr;

  // Make sure this is not loopback connection
  if ( connHandle != LOOPBACK_CONNHANDLE )
  {
    if ( ( changeType == LINKDB_STATUS_UPDATE_REMOVED )      ||
         ( ( changeType == LINKDB_STATUS_UPDATE_STATEFLAGS ) &&
           ( !linkDB_Up( connHandle ) ) ) )
    {
      for ( i = hidDevRptTblLen; i > 0; i--, p++ )
      {
        if ( p->cccdHandle != 0 )
        {
          if ( (pAttr = GATT_FindHandle(p->cccdHandle, &retHandle)) != NULL )
          {
            GATTServApp_InitCharCfg( connHandle, (gattCharCfg_t *) pAttr->pValue );
          }
        }
      }
    }
  }
}
/*********************************************************************
 * @fn          simpleProfile_HandleConnStatusCB
 *
 * @brief       Simple Profile link status change handler function.
 *
 * @param       connHandle - connection handle
 * @param       changeType - type of change
 *
 * @return      none
 */
static void simpleProfile_HandleConnStatusCB(uint16 connHandle, uint8 changeType) {
// Make sure this is not loopback connection
	if (connHandle != LOOPBACK_CONNHANDLE) {
		// Reset Client Char Config if connection has dropped
		if ((changeType == LINKDB_STATUS_UPDATE_REMOVED)
				|| ((changeType == LINKDB_STATUS_UPDATE_STATEFLAGS) && (!linkDB_Up( connHandle )))) {
			GATTServApp_InitCharCfg(connHandle, simpleProfileChar4Config);
		}
	}
}
/*********************************************************************
 * @fn          iBeacon_HandleConnStatusCB
 *
 * @brief       iBeacon link status change handler function.
 *
 * @param       connHandle - connection handle
 * @param       changeType - type of change
 *
 * @return      none  
 */
static void iBeacon_HandleConnStatusCB( uint16 connHandle, uint8 changeType )
{ 
  // Make sure this is not loopback connection
  if ( connHandle != LOOPBACK_CONNHANDLE )
  {
    // Reset Client Char Config if connection has dropped
    if ( ( changeType == LINKDB_STATUS_UPDATE_REMOVED )      ||
         ( ( changeType == LINKDB_STATUS_UPDATE_STATEFLAGS ) && 
           ( !linkDB_Up( connHandle ) ) ) )
    { 

    }
  }
}
Beispiel #5
0
/*********************************************************************
 * @fn      gapCentralRole_ProcessOSALMsg
 *
 * @brief   Process an incoming task message.
 *
 * @param   pMsg - message to process
 *
 * @return  none
 */
static void gapCentralRole_ProcessOSALMsg( osal_event_hdr_t *pMsg )
{
  switch ( pMsg->event )
  {
    case HCI_GAP_EVENT_EVENT:
      if ( pMsg->status == HCI_COMMAND_COMPLETE_EVENT_CODE )
      {
        hciEvt_CmdComplete_t *pPkt = (hciEvt_CmdComplete_t *) pMsg;

        if ( pPkt->cmdOpcode == HCI_READ_RSSI )
        {
          uint16 connHandle = BUILD_UINT16( pPkt->pReturnParam[1], pPkt->pReturnParam[2] );
          int8 rssi = (int8) pPkt->pReturnParam[3];

          // Report RSSI to app
          if ( pGapCentralRoleCB && pGapCentralRoleCB->rssiCB )
          {
            pGapCentralRoleCB->rssiCB( connHandle, rssi );
          }
        }
      }
      break;

    case GAP_MSG_EVENT:
      gapCentralRole_ProcessGAPMsg( (gapEventHdr_t *) pMsg );
      break;

    case GAPCENTRALROLE_RSSI_MSG_EVT:
      {
        gapCentralRoleRssi_t *pRssi = ((gapCentralRoleRssiEvent_t *) pMsg)->pRssi;

        // If link is up and RSSI reads active
        if (pRssi->connHandle != GAP_CONNHANDLE_ALL &&
            linkDB_Up(pRssi->connHandle))
        {
          // Restart timer
          osal_CbTimerStart( gapCentralRole_timerCB, (uint8 *) pRssi,
                             pRssi->period, &pRssi->timerId );

          // Read RSSI
          VOID HCI_ReadRssiCmd( pRssi->connHandle );
        }
      }
      break;

    default:
      break;
  }
}
Beispiel #6
0
/*********************************************************************
 * @fn          Temp_HandleConnStatusCB
 *
 * @brief       Heart Rate Service link status change handler function.
 *
 * @param       connHandle - connection handle
 * @param       changeType - type of change
 *
 * @return      none
 */
void Temp_HandleConnStatusCB( uint16 connHandle, uint8 changeType )
{
  // Make sure this is not loopback connection
  if ( connHandle != LOOPBACK_CONNHANDLE )
  {
    // Reset Client Char Config if connection has dropped
    if ( ( changeType == LINKDB_STATUS_UPDATE_REMOVED )      ||
         ( ( changeType == LINKDB_STATUS_UPDATE_STATEFLAGS ) &&
           ( !linkDB_Up( connHandle ) ) ) )
    {
      GATTServApp_InitCharCfg( connHandle, valueConfigCoordinates );
      enable_fast_read = 0;
    }
  }
}
Beispiel #7
0
/*********************************************************************
 * @fn          sensor_HandleConnStatusCB
 *
 * @brief       Sensor Profile link status change handler function.
 *
 * @param       connHandle - connection handle
 * @param       changeType - type of change
 *
 * @return      none
 */
static void sensor_HandleConnStatusCB( uint16 connHandle, uint8 changeType )
{
  // Make sure this is not loopback connection
  if ( connHandle != LOOPBACK_CONNHANDLE )
  {
    // Reset Client Char Config if connection has dropped
    if ( ( changeType == LINKDB_STATUS_UPDATE_REMOVED )      ||
         ( ( changeType == LINKDB_STATUS_UPDATE_STATEFLAGS ) &&
           ( !linkDB_Up( connHandle ) ) ) )
    {
      GATTServApp_InitCharCfg( connHandle, sensorDataConfig );
    }
    if ( changeType == LINKDB_STATUS_UPDATE_NEW )
    {
      GATTServApp_WriteCharCfg(connHandle,sensorDataConfig,GATT_CLIENT_CFG_NOTIFY);
    }
  }
}
Beispiel #8
0
static void blueBasic_HandleConnStatusCB(uint16 connHandle, uint8 changeType)
{
  if (connHandle == LOOPBACK_CONNHANDLE)
  {
    return;
  }
#ifdef ENABLE_BLE_CONSOLE
  if (changeType == LINKDB_STATUS_UPDATE_REMOVED || (changeType == LINKDB_STATUS_UPDATE_STATEFLAGS && !linkDB_Up(connHandle)))
  {
    GATTServApp_InitCharCfg(connHandle, consoleProfileCharCfg);
    uint8 i;
    for (i = 0; i < GATT_MAX_NUM_CONN; i++)
    {
      if (consoleProfileCharCfg[i].value == 1)
      {
        goto done;
      }
    }
    ble_console_enabled = 0;
  done:;
  }
#endif
  ble_connection_status(connHandle, changeType, 0);
}