예제 #1
0
/*********************************************************************
 * @fn      ScanParam_AddService
 *
 * @brief   Initializes the Battery Service by registering
 *          GATT attributes with the GATT server.
 *
 * @return  Success or Failure
 */
bStatus_t ScanParam_AddService( void )
{
  uint8 status = SUCCESS;

  // Initialize Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, scanParamRefreshClientCharCfg );

  // Register GATT attribute list and CBs with GATT Server App
  status = GATTServApp_RegisterService( scanParamAttrTbl, GATT_NUM_ATTRS( scanParamAttrTbl ),
                                        &scanParamCBs );

  return ( status );
}
/*********************************************************************
 * @fn      SimpleProfile_AddService
 *
 * @brief   Initializes the Simple Profile service by registering
 *          GATT attributes with the GATT server.
 *
 * @param   services - services to add. This is a bit map and can
 *                     contain more than one service.
 *
 * @return  Success or Failure
 */
bStatus_t SimpleProfile_AddService( uint32 services )
{
  uint8 status = SUCCESS;

  // Initialize Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, simpleProfileChar4Config );
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, simpleProfileChar6Config );
  //GATTServApp_InitCharCfg( INVALID_CONNHANDLE, simpleProfileChar7Config );

  // Register with Link DB to receive link status change callback
  VOID linkDB_Register( simpleProfile_HandleConnStatusCB );  
  
  if ( services & SIMPLEPROFILE_SERVICE )
  {
    // Register GATT attribute list and CBs with GATT Server App
    status = GATTServApp_RegisterService( simpleProfileAttrTbl, 
                                          GATT_NUM_ATTRS( simpleProfileAttrTbl ),
                                          &simpleProfileCBs );
  }

  return ( status );
}
예제 #3
0
파일: ther_profile.c 프로젝트: yzkqfll/baby
/*********************************************************************
 * @fn      Thermometer_AddService
 *
 * @brief   Initializes the Thermometer   service by registering
 *          GATT attributes with the GATT server.
 *
 * @param   services - services to add. This is a bit map and can
 *                     contain more than one service.
 *
 * @return  Success or Failure
 */
bStatus_t Thermometer_AddService( uint32 services )
{
  uint8 status = SUCCESS;

  // Initialize Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, thermometerTempConfig );
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, thermometerIMeasConfig );
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, thermometerIntervalConfig );

  // Register with Link DB to receive link status change callback
  VOID linkDB_Register( thermometer_HandleConnStatusCB );  
  
  if ( services & THERMOMETER_SERVICE )
  {
    // Register GATT attribute list and CBs with GATT Server App
    status = GATTServApp_RegisterService( thermometerAttrTbl, 
                                          GATT_NUM_ATTRS( thermometerAttrTbl ),
                                          &thermometerCBs );
  }

  return ( status );
}
예제 #4
0
/*********************************************************************
 * @fn      Accel_AddService
 *
 * @brief   Initializes the Accelerometer service by
 *          registering GATT attributes with the GATT server. Only
 *          call this function once.
 *
 * @param   services - services to add. This is a bit map and can
 *                     contain more than one service.
 *
 * @return  Success or Failure
 */
bStatus_t Accel_AddService( uint32 services )
{
  uint8 status = SUCCESS;

  // Initialize Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, accelXConfigCoordinates );
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, accelYConfigCoordinates );
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, accelZConfigCoordinates );

  // Register with Link DB to receive link status change callback
  VOID linkDB_Register( accel_HandleConnStatusCB );  

  if ( services & ACCEL_SERVICE )
  {
    // Register GATT attribute list and CBs with GATT Server App
    status = GATTServApp_RegisterService( accelAttrTbl, 
                                          GATT_NUM_ATTRS( accelAttrTbl ),
                                          &accelCBs );
  }

  return ( status );
}
예제 #5
0
/*********************************************************************
 * @fn          test_HandleConnStatusCB
 *
 * @brief       Test Profile link status change handler function.
 *
 * @param       connHandle - connection handle
 * @param       changeType - type of change
 *
 * @return      none
 */
static void test_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, testDataConfig );
    }
  }
}
예제 #6
0
/*********************************************************************
 * @fn      Temp_AddService
 *
 * @brief   Initializes the Heart Rate service by registering
 *          GATT attributes with the GATT server.
 *
 * @param   services - services to add. This is a bit map and can
 *                     contain more than one service.
 *
 * @return  Success or Failure
 */
bStatus_t Temp_AddService( uint32 services )
{
    uint8 status = SUCCESS;

    VOID linkDB_Register( Temp_HandleConnStatusCB );
    
    GATTServApp_InitCharCfg( INVALID_CONNHANDLE, valueConfigCoordinates );    
    
    status = GATTServApp_RegisterService( tempAttrTbl, 
      GATT_NUM_ATTRS( tempAttrTbl ),
      &tempCBs );

    return ( status );
}
예제 #7
0
/*********************************************************************
 * @fn      Batt_AddService
 *
 * @brief   Initializes the Battery Service by registering
 *          GATT attributes with the GATT server.
 *
 * @return  Success or Failure
 */
bStatus_t Batt_AddService( void )
{
  uint8 status = SUCCESS;

  // Initialize Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, battLevelClientCharCfg );

  // Register GATT attribute list and CBs with GATT Server App
  status = GATTServApp_RegisterService( battAttrTbl,
                                        GATT_NUM_ATTRS( battAttrTbl ),
                                        &battCBs );

  return ( status );
}
예제 #8
0
파일: uartserv.c 프로젝트: wythe-lin/ZTKBLE
/**
 * @fn      UartProfile_AddService
 *
 * @brief   Initializes the Simple Profile service by registering
 *          GATT attributes with the GATT server.
 *
 * @param   services - services to add. This is a bit map and can
 *                     contain more than one service.
 *
 * @return  Success or Failure
 */
bStatus_t UartProfile_AddService(void)
{
	uint8	status = SUCCESS;

	// Initialize Client Characteristic Configuration attributes
	GATTServApp_InitCharCfg(INVALID_CONNHANDLE, uartServ2CharCfg);

	// Register with Link DB to receive link status change callback
	linkDB_Register(UartProfile_HandleConnStatusCB);

	// Register GATT attribute list and CBs with GATT Server App
	GATTServApp_RegisterService(uartServ1AttrTbl, GATT_NUM_ATTRS(uartServ1AttrTbl), &uartServ1CBs);
	GATTServApp_RegisterService(uartServ2AttrTbl, GATT_NUM_ATTRS(uartServ2AttrTbl), &uartServ2CBs);
	return (status);
}
예제 #9
0
/*********************************************************************
 * @fn      util_initCharacteristicConfig
 *
 * @brief   Initialise a characteristics configuration
 *
 * @param   pDataConfig - pointer to characteristics configuration
 *
 * @return  Success or bleMemAllocError
 */
bStatus_t util_initCharacteristicConfig( gattCharCfg_t **pDataConfig )
{
  // Allocate Client Characteristic Configuration table
  *pDataConfig = (gattCharCfg_t *)osal_mem_alloc(sizeof(gattCharCfg_t) *
                                                    linkDBNumConns);
  if (*pDataConfig == NULL)
  {
    return (bleMemAllocError);
  }
  
  // Register with Link DB to receive link status change callback
  GATTServApp_InitCharCfg(INVALID_CONNHANDLE, *pDataConfig);
  
  return SUCCESS;
}
예제 #10
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;
    }
  }
}
예제 #11
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 );
      GATTServApp_InitCharCfg( connHandle, sensorData1Config );
      GATTServApp_InitCharCfg( connHandle, sensorData2Config );
      GATTServApp_InitCharCfg( connHandle, sensorData3Config );
    }
    if ( changeType == LINKDB_STATUS_UPDATE_NEW )
    {
      GATTServApp_WriteCharCfg(connHandle,sensorDataConfig,GATT_CLIENT_CFG_NOTIFY);
      GATTServApp_WriteCharCfg(connHandle,sensorData1Config,GATT_CLIENT_CFG_NOTIFY);
      GATTServApp_WriteCharCfg(connHandle,sensorData2Config,GATT_CLIENT_CFG_NOTIFY);
      GATTServApp_WriteCharCfg(connHandle,sensorData3Config,GATT_CLIENT_CFG_NOTIFY);
    }
  }
}
예제 #12
0
/*********************************************************************
 * @fn      HeartRate_AddService
 *
 * @brief   Initializes the Heart Rate service by registering
 *          GATT attributes with the GATT server.
 *
 * @param   services - services to add. This is a bit map and can
 *                     contain more than one service.
 *
 * @return  Success or Failure
 */
bStatus_t HeartRate_AddService( uint32 services )
{
  uint8 status = SUCCESS;

  // Initialize Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, heartRateMeasClientCharCfg );

  if ( services & HEARTRATE_SERVICE )
  {
    // Register GATT attribute list and CBs with GATT Server App
    status = GATTServApp_RegisterService( heartRateAttrTbl, 
                                          GATT_NUM_ATTRS( heartRateAttrTbl ),
                                          &heartRateCBs );
  }

  return ( status );
}
예제 #13
0
/*********************************************************************
 * @fn      proxReporter_AddService
 *
 * @brief   Initializes the Proximity Reporter service by
 *          registering GATT attributes with the GATT server.
 *          Only call this function once.
 *
 * @param   services - services to add. This is a bit map and can
 *                     contain more than one service.
 *
 * @return   Success or Failure
 */
bStatus_t ProxReporter_AddService( uint32 services )
{
  uint8 status = SUCCESS;

  if ( services & PP_LINK_LOSS_SERVICE )
  {
    // Register Link Loss attribute list and CBs with GATT Server App  
    status = GATTServApp_RegisterService( linkLossAttrTbl, 
                                          GATT_NUM_ATTRS( linkLossAttrTbl ),
                                          GATT_MAX_ENCRYPT_KEY_SIZE,
                                          &proxReporterCBs );
  }

  if ( ( status == SUCCESS ) && ( services & PP_IM_ALETR_SERVICE ) )
  {
    // Register Link Loss attribute list and CBs with GATT Server App
    status = GATTServApp_RegisterService( imAlertAttrTbl, 
                                          GATT_NUM_ATTRS( imAlertAttrTbl ),
                                          GATT_MAX_ENCRYPT_KEY_SIZE,
                                          &proxReporterCBs );
  }
  
  if ( ( status == SUCCESS )  && ( services & PP_TX_PWR_LEVEL_SERVICE ) )
  {
    // Allocate Client Characteristic Configuration table
    txPwrLevelConfig = (gattCharCfg_t *)osal_mem_alloc( sizeof(gattCharCfg_t) *
                                                        linkDBNumConns );
    if ( txPwrLevelConfig != NULL )
    {
      // Initialize Client Characteristic Configuration attributes
      GATTServApp_InitCharCfg( INVALID_CONNHANDLE, txPwrLevelConfig ); 
      
      // Register Tx Power Level attribute list and CBs with GATT Server App
      status = GATTServApp_RegisterService( txPwrLevelAttrTbl, 
                                            GATT_NUM_ATTRS( txPwrLevelAttrTbl ),
                                            GATT_MAX_ENCRYPT_KEY_SIZE,
                                            &proxReporterCBs );
    }
    else
    {
      status = bleMemAllocError;
    }
  }

  return ( status );
}
예제 #14
0
/*********************************************************************
 * @fn      Accel_AddService
 *
 * @brief   Initializes the Sensor Profile service by registering
 *          GATT attributes with the GATT server.
 *
 * @param   services - services to add. This is a bit map and can
 *                     contain more than one service.
 *
 * @return  Success or Failure
 */
bStatus_t Accel_AddService( uint32 services )
{
  uint8 status = SUCCESS;

  // Register with Link DB to receive link status change callback
  VOID linkDB_Register( acc_HandleConnStatusCB );
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, accelDataConfig );

  if (services & ACCELEROMETER_SERVICE )
  {
       // Register GATT attribute list and CBs with GATT Server App
    status = GATTServApp_RegisterService( accelAttrTbl,
                                          GATT_NUM_ATTRS( accelAttrTbl ),
                                          &accCBs );
  }

  return ( status );
}
/*********************************************************************
 * @fn      IRTemp_AddService
 *
 * @brief   Initializes the Sensor Profile service by registering
 *          GATT attributes with the GATT server.
 *
 * @param   services - services to add. This is a bit map and can
 *                     contain more than one service.
 *
 * @return  Success or Failure
 */
bStatus_t IRTemp_AddService( uint32 services )
{
  uint8 status = SUCCESS;

  // Register with Link DB to receive link status change callback
  VOID linkDB_Register( irTemp_HandleConnStatusCB );
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, irTempDataConfig );

  if (services & IRTEMPERATURE_SERVICE )
  {
       // Register GATT attribute list and CBs with GATT Server App
    status = GATTServApp_RegisterService( irTempAttrTbl,
                                          GATT_NUM_ATTRS( irTempAttrTbl ),
                                          &irTempCBs );
  }

  return ( status );
}
예제 #16
0
/*********************************************************************
 * @fn      Humidity_AddService
 *
 * @brief   Initializes the Sensor Profile service by registering
 *          GATT attributes with the GATT server.
 *
 * @param   services - services to add. This is a bit map and can
 *                     contain more than one service.
 *
 * @return  Success or Failure
 */
bStatus_t Humidity_AddService( uint32 services )
{
  uint8 status = SUCCESS;

  // Register with Link DB to receive link status change callback
  VOID linkDB_Register( humid_HandleConnStatusCB );
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, humidDataConfig );

  if (services & HUMIDITY_SERVICE )
  {
       // Register GATT attribute list and CBs with GATT Server App
    status = GATTServApp_RegisterService( humidAttrTbl,
                                          GATT_NUM_ATTRS( humidAttrTbl ),
                                          &humidCBs );
  }

  return ( status );
}
예제 #17
0
/*********************************************************************
 * @fn      Pir_AddService
 *
 * @brief   Initializes the Sensor Profile service by registering
 *          GATT attributes with the GATT server.
 *
 * @param   services - services to add. This is a bit map and can
 *                     contain more than one service.
 *
 * @return  Success or Failure
 */
bStatus_t Pir_AddService( uint32 services )
{
  uint8 status = SUCCESS;

  // Register with Link DB to receive link status change callback
  VOID linkDB_Register( sensor_HandleConnStatusCB );
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, sensorDataConfig );

  if (services & SENSOR_SERVICE )
  {
       // Register GATT attribute list and CBs with GATT Server App
    status = GATTServApp_RegisterService( sensorAttrTable,
                                          GATT_NUM_ATTRS( sensorAttrTable ),
                                          &sensorCBs );
  }

  return ( status );
}
예제 #18
0
/*********************************************************************
 * @fn      AHRS_addService
 *
 * @brief   Initializes the AHRS Profile service by registering
 *          GATT attributes with the GATT server.
 *
 * @return  Success or Failure
 */
bStatus_t AHRS_addService(void)
{
  // Allocate Client Characteristic Configuration table
  sensorDataConfig = (gattCharCfg_t *)ICall_malloc(sizeof(gattCharCfg_t) *
                                                    linkDBNumConns);
  if (sensorDataConfig == NULL)
  {
    return (bleMemAllocError);
  }
  
  // Register with Link DB to receive link status change callback
  GATTServApp_InitCharCfg(INVALID_CONNHANDLE, sensorDataConfig);

  // Register GATT attribute list and CBs with GATT Server App
  return GATTServApp_RegisterService(sensorAttrTable,
                                     GATT_NUM_ATTRS (sensorAttrTable),
                                     GATT_MAX_ENCRYPT_KEY_SIZE,
                                     &sensorCBs);
}
예제 #19
0
/*********************************************************************
* @fn      CcService_addService
*
* @brief   Initializes the service by registering
*          GATT attributes with the GATT server.
*
* @return  Success or Failure
*/
bStatus_t CcService_addService(void)
{
  // Allocate Client Characteristic Configuration table
  ccDataConfig = (gattCharCfg_t *)ICall_malloc(sizeof(gattCharCfg_t) *
                                                linkDBNumConns);
  if (ccDataConfig == NULL)
  {
    return (bleMemAllocError);
  }
  
  // Initialize Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg(INVALID_CONNHANDLE, ccDataConfig);
  
  // Register GATT attribute list and CBs with GATT Server App
  return GATTServApp_RegisterService(ccServiceAttrTbl,
                                     GATT_NUM_ATTRS(ccServiceAttrTbl),
                                     GATT_MAX_ENCRYPT_KEY_SIZE,
                                     &ccServiceCBs);
}
예제 #20
0
/*********************************************************************
 * @fn      Test_AddService
 *
 * @brief   Initializes the Test Profile service by registering
 *          GATT attributes with the GATT server.
 *
 * @param   services - services to add. This is a bit map and can
 *                     contain more than one service.
 *
 * @return  Success or Failure
 */
bStatus_t Test_AddService( uint32 services )
{
  uint8 status = SUCCESS;

  // Initialize Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, testDataConfig );

  // Register with Link DB to receive link status change callback
  VOID linkDB_Register( test_HandleConnStatusCB );

  if ( services & TEST_SERVICE )
  {
    // Register GATT attribute list and CBs with GATT Server App
    status = GATTServApp_RegisterService( testAttrTbl,
                                          GATT_NUM_ATTRS( testAttrTbl ),
                                          &testCBs );
  }

  return ( status );
}
예제 #21
0
/*********************************************************************
 * @fn      ScanParam_AddService
 *
 * @brief   Initializes the Battery Service by registering
 *          GATT attributes with the GATT server.
 *
 * @return  Success or Failure
 */
bStatus_t ScanParam_AddService( void )
{
  uint8 status;

  scanParamRefreshClientCharCfg = (gattCharCfg_t *)osal_mem_alloc( sizeof(gattCharCfg_t) *
                                                                   linkDBNumConns);
  
  if (scanParamRefreshClientCharCfg == NULL)
  {     
    return ( bleMemAllocError );
  }
  
  // Initialize Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, scanParamRefreshClientCharCfg );

  // Register GATT attribute list and CBs with GATT Server App
  status = GATTServApp_RegisterService( scanParamAttrTbl, GATT_NUM_ATTRS( scanParamAttrTbl ),
                                        GATT_MAX_ENCRYPT_KEY_SIZE, &scanParamCBs );

  return ( status );
}
예제 #22
0
/*
 * BatteryService_AddService- Initializes the BatteryService service by registering
 *          GATT attributes with the GATT server.
 *
 */
bStatus_t BatteryService_AddService( void )
{
  uint8_t status;

  // Allocate Client Characteristic Configuration table
  bs_Battery_LevelConfig = (gattCharCfg_t *)ICall_malloc( sizeof(gattCharCfg_t) * linkDBNumConns );
  if ( bs_Battery_LevelConfig == NULL )
  {     
    return ( bleMemAllocError );
  }
  
  // Initialize Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, bs_Battery_LevelConfig );
  // Register GATT attribute list and CBs with GATT Server App
  status = GATTServApp_RegisterService( Battery_ServiceAttrTbl, 
                                        GATT_NUM_ATTRS( Battery_ServiceAttrTbl ),
                                        GATT_MAX_ENCRYPT_KEY_SIZE,
                                        &Battery_ServiceCBs );

  return ( status );
}
예제 #23
0
파일: proxreporter.c 프로젝트: AubrCool/BLE
/*********************************************************************
 * @fn      proxReporter_AddService
 *
 * @brief   Initializes the Proximity Reporter service by
 *          registering GATT attributes with the GATT server.
 *          Only call this function once.
 *
 * @param   services - services to add. This is a bit map and can
 *                     contain more than one service.
 *
 * @return   Success or Failure
 */
bStatus_t ProxReporter_AddService( uint32 services )
{
  uint8 status = SUCCESS;

  if ( services & PP_LINK_LOSS_SERVICE )
  {
    // Register Link Loss attribute list and CBs with GATT Server App  
    status = GATTServApp_RegisterService( linkLossAttrTbl, 
                                          GATT_NUM_ATTRS( linkLossAttrTbl ),
                                          &proxReporterCBs );
  }

  if ( ( status == SUCCESS ) && ( services & PP_IM_ALETR_SERVICE ) )
  {
    // Register Link Loss attribute list and CBs with GATT Server App
    status = GATTServApp_RegisterService( imAlertAttrTbl, 
                                          GATT_NUM_ATTRS( imAlertAttrTbl ),
                                          &proxReporterCBs );
  }
  
  if ( ( status == SUCCESS )  && ( services & PP_TX_PWR_LEVEL_SERVICE ) )
  {
    
    // Initialize Client Characteristic Configuration attributes
    GATTServApp_InitCharCfg( INVALID_CONNHANDLE, txPwrLevelConfig );

    // Register with Link DB to receive link status change callback
    VOID linkDB_Register( proxReporter_HandleConnStatusCB );  

    
    // Register Tx Power Level attribute list and CBs with GATT Server App
    status = GATTServApp_RegisterService( txPwrLevelAttrTbl, 
                                          GATT_NUM_ATTRS( txPwrLevelAttrTbl ),
                                          &proxReporterCBs );
  }

  return ( status );
}
/*
 * DataService_AddService- Initializes the DataService service by registering
 *          GATT attributes with the GATT server.
 *
 *    rspTaskId - The ICall Task Id that should receive responses for Indications.
 */
extern bStatus_t DataService_AddService( uint8_t rspTaskId )
{
  uint8_t status;

  // Allocate Client Characteristic Configuration table
  ds_StreamConfig = (gattCharCfg_t *)ICall_malloc( sizeof(gattCharCfg_t) * linkDBNumConns );
  if ( ds_StreamConfig == NULL )
  {
    return ( bleMemAllocError );
  }

  // Initialize Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, ds_StreamConfig );
  // Register GATT attribute list and CBs with GATT Server App
  status = GATTServApp_RegisterService( Data_ServiceAttrTbl,
                                        GATT_NUM_ATTRS( Data_ServiceAttrTbl ),
                                        GATT_MAX_ENCRYPT_KEY_SIZE,
                                        &Data_ServiceCBs );
  Log_info1("Registered service, %d attributes", (IArg)GATT_NUM_ATTRS( Data_ServiceAttrTbl ));
  ds_icall_rsp_task_id = rspTaskId;

  return ( status );
}
예제 #25
0
파일: BlueBasic.c 프로젝트: JBtje/BlueBasic
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);
}
/*********************************************************************
 * @fn      HidKbM_AddService
 *
 * @brief   Initializes the HID Service by registering
 *          GATT attributes with the GATT server.
 *
 * @return  Success or Failure
 */
bStatus_t HidKbM_AddService( void )
{
  uint8 status = SUCCESS;

  // Initialize Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, hidReportMouseInClientCharCfg );
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, hidReportKeyInClientCharCfg );
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, hidReportCCInClientCharCfg );
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, hidReportBootKeyInClientCharCfg );
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, hidReportBootMouseInClientCharCfg );

  // Register GATT attribute list and CBs with GATT Server App
  status = GATTServApp_RegisterService( hidAttrTbl, GATT_NUM_ATTRS( hidAttrTbl ), &hidKbdMsCBs );

  // Set up included service
  Batt_GetParameter( BATT_PARAM_SERVICE_HANDLE,
                     &GATT_INCLUDED_HANDLE( hidAttrTbl, HID_INCLUDED_SERVICE_IDX ) );

  // Construct map of reports to characteristic handles
  // Each report is uniquely identified via its ID and type

  // Mouse input report
  hidRptMap[0].id = hidReportRefMouseIn[0];
  hidRptMap[0].type = hidReportRefMouseIn[1];
  hidRptMap[0].handle = hidAttrTbl[HID_REPORT_MOUSE_IN_IDX].handle;
  hidRptMap[0].cccdHandle = hidAttrTbl[HID_REPORT_MOUSE_IN_CCCD_IDX].handle;
  hidRptMap[0].mode = HID_PROTOCOL_MODE_REPORT;

  // Key input report
  hidRptMap[1].id = hidReportRefKeyIn[0];
  hidRptMap[1].type = hidReportRefKeyIn[1];
  hidRptMap[1].handle = hidAttrTbl[HID_REPORT_KEY_IN_IDX].handle;
  hidRptMap[1].cccdHandle = hidAttrTbl[HID_REPORT_KEY_IN_CCCD_IDX].handle;
  hidRptMap[1].mode = HID_PROTOCOL_MODE_REPORT;

  // Consumer Control input report
  hidRptMap[2].id = hidReportRefCCIn[0];
  hidRptMap[2].type = hidReportRefCCIn[1];
  hidRptMap[2].handle = hidAttrTbl[HID_REPORT_CC_IN_IDX].handle;
  hidRptMap[2].cccdHandle = hidAttrTbl[HID_REPORT_CC_IN_CCCD_IDX].handle;
  hidRptMap[2].mode = HID_PROTOCOL_MODE_REPORT;

  // LED output report
  hidRptMap[3].id = hidReportRefLedOut[0];
  hidRptMap[3].type = hidReportRefLedOut[1];
  hidRptMap[3].handle = hidAttrTbl[HID_REPORT_LED_OUT_IDX].handle;
  hidRptMap[3].cccdHandle = 0;
  hidRptMap[3].mode = HID_PROTOCOL_MODE_REPORT;

  // Boot keyboard input report
  // Use same ID and type as key input report
  hidRptMap[4].id = hidReportRefKeyIn[0];
  hidRptMap[4].type = hidReportRefKeyIn[1];
  hidRptMap[4].handle = hidAttrTbl[HID_BOOT_KEY_IN_IDX].handle;
  hidRptMap[4].cccdHandle = hidAttrTbl[HID_BOOT_KEY_IN_CCCD_IDX].handle;
  hidRptMap[4].mode = HID_PROTOCOL_MODE_BOOT;

  // Boot keyboard output report
  // Use same ID and type as LED output report
  hidRptMap[5].id = hidReportRefLedOut[0];
  hidRptMap[5].type = hidReportRefLedOut[1];
  hidRptMap[5].handle = hidAttrTbl[HID_BOOT_KEY_OUT_IDX].handle;
  hidRptMap[5].cccdHandle = 0;
  hidRptMap[5].mode = HID_PROTOCOL_MODE_BOOT;

  // Boot mouse input report
  hidRptMap[6].id = HID_RPT_ID_MOUSE_IN;
  hidRptMap[6].type = HID_REPORT_TYPE_INPUT;
  hidRptMap[6].handle = hidAttrTbl[HID_BOOT_MOUSE_IN_IDX].handle;
  hidRptMap[6].cccdHandle = hidAttrTbl[HID_BOOT_MOUSE_IN_CCCD_IDX].handle;
  hidRptMap[6].mode = HID_PROTOCOL_MODE_BOOT;

  // Feature report
  hidRptMap[7].id = hidReportRefFeature[0];
  hidRptMap[7].type = hidReportRefFeature[1];
  hidRptMap[7].handle = hidAttrTbl[HID_FEATURE_IDX].handle;
  hidRptMap[7].cccdHandle = 0;
  hidRptMap[7].mode = HID_PROTOCOL_MODE_REPORT;

  // Battery level input report
  VOID Batt_GetParameter( BATT_PARAM_BATT_LEVEL_IN_REPORT, &(hidRptMap[8]) );

  // Setup report ID map
  HidDev_RegisterReports( HID_NUM_REPORTS, hidRptMap );

  return ( status );
}
예제 #27
0
파일: BlueBasic.c 프로젝트: JBtje/BlueBasic
/*********************************************************************
 * @fn      BlueBasic_ProcessEvent
 *
 * @brief   Blue Basic Application Task event processor.  This function
 *          is called to process all events for the task.  Events
 *          include timers, messages and any other user defined events.
 *
 * @param   task_id  - The OSAL assigned task ID.
 * @param   events - events to process.  This is a bit map and can
 *                   contain more than one event.
 *
 * @return  events not processed
 */
uint16 BlueBasic_ProcessEvent( uint8 task_id, uint16 events )
{
  unsigned char i;

  VOID task_id; // OSAL required parameter that isn't used in this function

  if ( events & SYS_EVENT_MSG )
  {
    uint8 *pMsg;

    if ( (pMsg = osal_msg_receive( blueBasic_TaskID )) != NULL )
    {
      // Release the OSAL message
      VOID osal_msg_deallocate( pMsg );
    }

    // return unprocessed events
    return (events ^ SYS_EVENT_MSG);
  }

  if ( events & BLUEBASIC_START_DEVICE_EVT )
  {
    // Start the Device
    VOID GAPRole_StartDevice( &blueBasic_PeripheralCBs );

#ifdef GAP_BOND_MGR
    // Start Bond Manager
    VOID GAPBondMgr_Register( &blueBasic_BondMgrCBs );
#endif
    // Start monitoring links
    VOID linkDB_Register( blueBasic_HandleConnStatusCB );

#ifdef ENABLE_BLE_CONSOLE
    GATTServApp_InitCharCfg(INVALID_CONNHANDLE, consoleProfileCharCfg);
    GATTServApp_RegisterService(consoleProfile, GATT_NUM_ATTRS(consoleProfile), &consoleProfileCB);
#endif

    // Start Interpreter
    interpreter_setup();

    return ( events ^ BLUEBASIC_START_DEVICE_EVT );
  }

#ifdef ENABLE_BLE_CONSOLE
  if ( events & BLUEBASIC_CONNECTION_EVENT )
  {
    while (io.writein != io.writeout)
    {
      uint8* save = io.writeout;
      if (GATTServApp_ProcessCharCfg(consoleProfileCharCfg, io.write, FALSE, consoleProfile, GATT_NUM_ATTRS(consoleProfile), INVALID_TASK_ID) != SUCCESS)
      {
        io.writeout = save;
        break;
      }
    }
    return ( events ^ BLUEBASIC_CONNECTION_EVENT );
  }
#endif

  if ( events & BLUEBASIC_INPUT_AVAILABLE )
  {
    interpreter_loop();
    return (events ^ BLUEBASIC_INPUT_AVAILABLE);
  }

  if ( events & BLUEBASIC_EVENT_INTERRUPTS )
  {
    for (i = 0; i < OS_MAX_INTERRUPT; i++)
    {
      if (blueBasic_interrupts[i].linenum && (events & (BLUEBASIC_EVENT_INTERRUPT << i)))
      {
        interpreter_run(blueBasic_interrupts[i].linenum, 1);
      }
    }
    return (events ^ (events & BLUEBASIC_EVENT_INTERRUPTS));
  }

  if ( events & BLUEBASIC_EVENT_TIMERS )
  {
    for (i = 0; i < OS_MAX_TIMER; i++)
    {
      if (blueBasic_timers[i].linenum && (events & (BLUEBASIC_EVENT_TIMER << i)))
      {
        interpreter_run(blueBasic_timers[i].linenum, i == DELAY_TIMER ? 0 : 1);
      }
    }
    return (events ^ (events & BLUEBASIC_EVENT_TIMERS));
  }
  
  if ( events & BLUEBASIC_EVENT_SERIAL )
  {
    if (serial[0].onread && Hal_UART_RxBufLen(HAL_UART_PORT_0) > 0)
    {
      interpreter_run(serial[0].onread, 1);
    }
    if (serial[0].onwrite && Hal_UART_TxBufLen(HAL_UART_PORT_0) > 0)
    {
      interpreter_run(serial[0].onwrite, 1);
    }

    return (events ^ BLUEBASIC_EVENT_SERIAL);
  }

  // Discard unknown events
  return 0;
}
예제 #28
0
/*********************************************************************
 * @fn      HidKbd_AddService
 *
 * @brief   Initializes the HID Service by registering
 *          GATT attributes with the GATT server.
 *
 * @return  Success or Failure
 */
bStatus_t HidKbd_AddService( void )
{
  uint8 status;

  // Allocate Client Charateristic Configuration tables.
  hidReportKeyInClientCharCfg = (gattCharCfg_t *)osal_mem_alloc( sizeof(gattCharCfg_t) *
                                                                 linkDBNumConns);
  
  if (hidReportKeyInClientCharCfg == NULL)
  {
    return ( bleMemAllocError );
  }
  
  hidReportBootKeyInClientCharCfg = (gattCharCfg_t *)osal_mem_alloc( sizeof(gattCharCfg_t) *
                                                                     linkDBNumConns);
  
  if (hidReportBootKeyInClientCharCfg == NULL)
  {
    osal_mem_free(hidReportKeyInClientCharCfg);
    
    return ( bleMemAllocError );
  }
  
  hidReportBootMouseInClientCharCfg = (gattCharCfg_t *)osal_mem_alloc( sizeof(gattCharCfg_t) *
                                                                       linkDBNumConns);
  if (hidReportBootMouseInClientCharCfg == NULL)
  {     
    osal_mem_free(hidReportKeyInClientCharCfg);
    
    osal_mem_free(hidReportBootKeyInClientCharCfg);
    
    return ( bleMemAllocError );
  }
  
  // Initialize Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, hidReportKeyInClientCharCfg );
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, hidReportBootKeyInClientCharCfg );
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE, hidReportBootMouseInClientCharCfg );

  // Register GATT attribute list and CBs with GATT Server App
  status = GATTServApp_RegisterService( hidAttrTbl, GATT_NUM_ATTRS( hidAttrTbl ),
                                        GATT_MAX_ENCRYPT_KEY_SIZE, &hidKbdCBs );

  // Set up included service
  Batt_GetParameter( BATT_PARAM_SERVICE_HANDLE,
                     &GATT_INCLUDED_HANDLE( hidAttrTbl, HID_INCLUDED_SERVICE_IDX ) );

  // Construct map of reports to characteristic handles
  // Each report is uniquely identified via its ID and type

  // Key input report
  hidRptMap[0].id = hidReportRefKeyIn[0];
  hidRptMap[0].type = hidReportRefKeyIn[1];
  hidRptMap[0].handle = hidAttrTbl[HID_REPORT_KEY_IN_IDX].handle;
  hidRptMap[0].pCccdAttr = &hidAttrTbl[HID_REPORT_KEY_IN_CCCD_IDX];
  hidRptMap[0].mode = HID_PROTOCOL_MODE_REPORT;

  // LED output report
  hidRptMap[1].id = hidReportRefLedOut[0];
  hidRptMap[1].type = hidReportRefLedOut[1];
  hidRptMap[1].handle = hidAttrTbl[HID_REPORT_LED_OUT_IDX].handle;
  hidRptMap[1].pCccdAttr = NULL;
  hidRptMap[1].mode = HID_PROTOCOL_MODE_REPORT;

  // Boot keyboard input report
  // Use same ID and type as key input report
  hidRptMap[2].id = hidReportRefKeyIn[0];
  hidRptMap[2].type = hidReportRefKeyIn[1];
  hidRptMap[2].handle = hidAttrTbl[HID_BOOT_KEY_IN_IDX].handle;
  hidRptMap[2].pCccdAttr = &hidAttrTbl[HID_BOOT_KEY_IN_CCCD_IDX];
  hidRptMap[2].mode = HID_PROTOCOL_MODE_BOOT;

  // Boot keyboard output report
  // Use same ID and type as LED output report
  hidRptMap[3].id = hidReportRefLedOut[0];
  hidRptMap[3].type = hidReportRefLedOut[1];
  hidRptMap[3].handle = hidAttrTbl[HID_BOOT_KEY_OUT_IDX].handle;
  hidRptMap[3].pCccdAttr = NULL;
  hidRptMap[3].mode = HID_PROTOCOL_MODE_BOOT;

  // Boot mouse input report
  hidRptMap[4].id = HID_RPT_ID_MOUSE_IN;
  hidRptMap[4].type = HID_REPORT_TYPE_INPUT;
  hidRptMap[4].handle = hidAttrTbl[HID_BOOT_MOUSE_IN_IDX].handle;
  hidRptMap[4].pCccdAttr = &hidAttrTbl[HID_BOOT_MOUSE_IN_CCCD_IDX];
  hidRptMap[4].mode = HID_PROTOCOL_MODE_BOOT;

  // Feature report
  hidRptMap[5].id = hidReportRefFeature[0];
  hidRptMap[5].type = hidReportRefFeature[1];
  hidRptMap[5].handle = hidAttrTbl[HID_FEATURE_IDX].handle;
  hidRptMap[5].pCccdAttr = NULL;
  hidRptMap[5].mode = HID_PROTOCOL_MODE_REPORT;

  // Battery level input report
  VOID Batt_GetParameter( BATT_PARAM_BATT_LEVEL_IN_REPORT, &(hidRptMap[6]) );

  // Setup report ID map
  HidDev_RegisterReports( HID_NUM_REPORTS, hidRptMap );

  return ( status );
}