/********************************************************************* * @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 ExampleService_AddService( void ) { static uint8 excute_time =0; uint8 status = SUCCESS; if(excute_time > 0) //make sure it is only excuted once, because everytime it excuted, it add the attr to the list ,no matter wheather it exists in it. return(status); else excute_time++; HalLcdWriteStringValue("excute_time",excute_time,10,HAL_LCD_LINE_6); // Initialize Client Characteristic Configuration attributes GATTServApp_InitCharCfg( INVALID_CONNHANDLE, simpleProfileChar2Config ); // Register with Link DB to receive link status change callback VOID linkDB_Register( simpleProfile_HandleConnStatusCB ); // Register GATT attribute list and CBs with GATT Server App status = GATTServApp_RegisterService( simpleProfileAttrTbl, GATT_NUM_ATTRS( simpleProfileAttrTbl ), &simpleProfileCBs ); return ( status ); }
/********************************************************************* * @fn SK_AddService * * @brief Initializes the Simple Key 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 SK_AddService( uint32 services ) { uint8 status = SUCCESS; // Initialize Client Characteristic Configuration attributes for ( uint8 i = 0; i < GATT_MAX_NUM_CONN; i++ ) { skConfig[i].connHandle = INVALID_CONNHANDLE; skConfig[i].value = GATT_CFG_NO_OPERATION; } // Register with Link DB to receive link status change callback VOID linkDB_Register( sk_HandleConnStatusCB ); if ( services & SK_SERVICE ) { // Register GATT attribute list and CBs with GATT Server App status = GATTServApp_RegisterService( simplekeysAttrTbl, GATT_NUM_ATTRS( simplekeysAttrTbl ), sk_ReadAttrCB, sk_WriteAttrCB, NULL ); } 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; // Allocate Client Characteristic Configuration table simpleProfileChar4Config = (gattCharCfg_t *)osal_mem_alloc( sizeof(gattCharCfg_t) * linkDBNumConns ); if ( simpleProfileChar4Config == NULL ) { return ( bleMemAllocError ); } // Initialize Client Characteristic Configuration attributes GATTServApp_InitCharCfg( INVALID_CONNHANDLE, simpleProfileChar4Config ); // 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 ), GATT_MIN_ENCRYPT_KEY_SIZE, &simpleProfileCBs ); } return ( status ); }
/********************************************************************* * @fn OADTarget_AddService * * @brief Initializes the OAD Service by registering GATT attributes * with the GATT server. Only call this function once. * * @return The return value of GATTServApp_RegisterForMsg(). */ bStatus_t OADTarget_AddService(void) { // Initialize Client Characteristic Configuration attributes GATTServApp_InitCharCfg( INVALID_CONNHANDLE, oadImgIdentifyConfig ); GATTServApp_InitCharCfg( INVALID_CONNHANDLE, oadImgBlockConfig ); // Register with Link DB to receive link status change callback VOID linkDB_Register( oadHandleConnStatusCB ); return GATTServApp_RegisterService(oadAttrTbl, GATT_NUM_ATTRS(oadAttrTbl), &oadCBs); }
bStatus_t buttonsProfile_AddService(uint32 services) { uint8 status = SUCCESS; VOID linkDB_Register(buttonsProfile_HandleConnStatusCB); if (services & BLE_BUTTONS_PROFILE_SERVICE) { status = GATTServApp_RegisterService(buttonsProfileAttributesTable, GATT_NUM_ATTRS(buttonsProfileAttributesTable), &buttonsProfileCBs); } return (status); };
/********************************************************************* * @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 ); }
/** * @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); }
/********************************************************************* * @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); // 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); }
/********************************************************************* * @fn iBeacon_AddService * * @brief Initializes the iBeacon 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 iBeacon_AddService( uint32 services ) { uint8 status = SUCCESS; // Register with Link DB to receive link status change callback VOID linkDB_Register( iBeacon_HandleConnStatusCB ); if ( services & IBEACON_SERVICE ) { // Register GATT attribute list and CBs with GATT Server App status = GATTServApp_RegisterService( iBeaconAttrTbl, GATT_NUM_ATTRS( iBeaconAttrTbl ), &iBeaconCBs ); } return ( status ); }
/********************************************************************* * @fn Gyro_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 Gyro_AddService( uint32 services ) { uint8 status = SUCCESS; // Register with Link DB to receive link status change callback VOID linkDB_Register( gyro_HandleConnStatusCB ); if (services & GYROSCOPE_SERVICE ) { // Register GATT attribute list and CBs with GATT Server App status = GATTServApp_RegisterService( sensorGyroscopeAttrTbl, GATT_NUM_ATTRS( sensorGyroscopeAttrTbl ), &gyroCBs ); } 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 ); }
/********************************************************************* * @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 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 ); }
/********************************************************************* * @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 ); }
/********************************************************************* * @fn RoboRoachProfile_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 RoboRoachProfile_AddService( uint8 taskID ) { uint8 status = SUCCESS; roboRoachApp_TaskID = taskID; // Initialize Client Characteristic Configuration attributes //GATTServApp_InitCharCfg( INVALID_CONNHANDLE, rrCharStimulateLeftConfig ); // Register with Link DB to receive link status change callback VOID linkDB_Register( roboRoachProfile_HandleConnStatusCB ); // Register GATT attribute list and CBs with GATT Server App status = GATTServApp_RegisterService( roboRoachAttrTbl, GATT_NUM_ATTRS( roboRoachAttrTbl ), &roboRoachCBs ); return ( status ); }
/********************************************************************* * @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 ); }
/********************************************************************* * @fn Glucose_AddService * * @brief Initializes the Glucose 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 Glucose_AddService( uint32 services ) { uint8 status = SUCCESS; // Initialize Client Characteristic Configuration attributes GATTServApp_InitCharCfg( INVALID_CONNHANDLE, glucoseMeasConfig ); GATTServApp_InitCharCfg( INVALID_CONNHANDLE, glucoseContextConfig ); GATTServApp_InitCharCfg( INVALID_CONNHANDLE, glucoseControlConfig ); // Register with Link DB to receive link status change callback VOID linkDB_Register( glucose_HandleConnStatusCB ); if ( services & GLUCOSE_SERVICE ) { // Register GATT attribute list and CBs with GATT Server App status = GATTServApp_RegisterService( glucoseAttrTbl, GATT_NUM_ATTRS( glucoseAttrTbl ), &glucoseCBs ); } return ( status ); }
/********************************************************************* * @fn BloodPressure_AddService * * @brief Initializes the BloodPressure 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 BloodPressure_AddService( uint32 services ) { uint8 status = SUCCESS; // Initialize Client Characteristic Configuration attributes GATTServApp_InitCharCfg( INVALID_CONNHANDLE, bloodPressureMeasConfig ); GATTServApp_InitCharCfg( INVALID_CONNHANDLE, bloodPressureIMeasConfig ); // Register with Link DB to receive link status change callback VOID linkDB_Register( bloodPressure_HandleConnStatusCB ); if ( services & BLOODPRESSURE_SERVICE ) { // Register GATT attribute list and CBs with GATT Server App status = GATTServApp_RegisterService( bloodPressureAttrTbl, GATT_NUM_ATTRS( bloodPressureAttrTbl ), &bloodPressureCBs ); } return ( status ); }
/********************************************************************* * @fn BLECTRL_AddService * * @brief Initializes the BLECTRL 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 BLECTRL_AddService( uint32 services ) { uint8 status = SUCCESS; // Initialize Client Characteristic Configuration attributes GATTServApp_InitCharCfg( INVALID_CONNHANDLE, blectrlStatusConfig ); GATTServApp_InitCharCfg( INVALID_CONNHANDLE, blectrlUnclsNotifConfig ); // Register with Link DB to receive link status change callback VOID linkDB_Register( blectrl_HandleConnStatusCB ); if ( services & BLECTRL_SERVICE ) { // Register GATT attribute list and CBs with GATT Server App status = GATTServApp_RegisterService( blectrlAttrTbl, GATT_NUM_ATTRS( blectrlAttrTbl ), &blectrlCBs ); } return ( status ); }
/********************************************************************* * @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 ); }
/********************************************************************* * @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 ); }
/********************************************************************* * @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 ); }
/********************************************************************* * @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; }