/********************************************************************* * @fn DualImageConcept_processStateChangeEvt * * @brief Process a pending GAP Role state change event. * * @param newState - new state * * @return None. */ static void DualImageConcept_processStateChangeEvt(gaprole_States_t newState) { switch ( newState ) { case GAPROLE_STARTED: { uint8_t ownAddress[B_ADDR_LEN]; GAPRole_GetParameter(GAPROLE_BD_ADDR, ownAddress); // Display device address Display_print0(dispHandle, 1, 0, Util_convertBdAddr2Str(ownAddress)); Display_print0(dispHandle, 2, 0, "Initialized"); } break; case GAPROLE_ADVERTISING: Display_print0(dispHandle, 2, 0, "Advertising"); break; case GAPROLE_CONNECTED: { uint8_t peerAddress[B_ADDR_LEN]; GAPRole_GetParameter(GAPROLE_CONN_BD_ADDR, peerAddress); Display_print0(dispHandle, 2, 0, "Connected"); Display_print0(dispHandle, 3, 0, Util_convertBdAddr2Str(peerAddress)); } break; case GAPROLE_WAITING: Display_print0(dispHandle, 2, 0, "Disconnected"); // Clear remaining lines Display_clearLines(dispHandle, 3, 5); break; case GAPROLE_WAITING_AFTER_TIMEOUT: Display_print0(dispHandle, 2, 0, "Timed Out"); // Clear remaining lines Display_clearLines(dispHandle, 3, 5); break; case GAPROLE_ERROR: break; default: break; } }
/*--------------------------------------------------------------------------- * Peripheral role of a state change handler. * - newState: new state *-------------------------------------------------------------------------*/ static void peripheralStateNotificationCB( gaprole_States_t newState ) { uint16 connHandle = INVALID_CONNHANDLE; if ( pmd.gapProfileState != newState ) { switch( newState ) { case GAPROLE_STARTED: { // Set the system ID from the bd addr uint8 systemId[8]; // from #define DEVINFO_SYSTEM_ID_LEN 8 GAPRole_GetParameter(GAPROLE_BD_ADDR, systemId); // shift three bytes up systemId[7] = systemId[5]; systemId[6] = systemId[4]; systemId[5] = systemId[3]; // set middle bytes to zero systemId[4] = 0; systemId[3] = 0; updateNameWithAddressInfo(); } break; case GAPROLE_ADVERTISING: break; case GAPROLE_CONNECTED: GAPRole_GetParameter( GAPROLE_CONNHANDLE, &connHandle ); #if defined ( PLUS_BROADCASTER ) osal_start_timerEx( pmd.taskId, PMD_ADV_IN_CONNECTION_EVT, ADV_IN_CONN_WAIT ); #endif break; case GAPROLE_WAITING: break; case GAPROLE_WAITING_AFTER_TIMEOUT: break; default: // do nothing break; } } pmd.gapProfileState = newState; }
/********************************************************************* * @fn processGapStateChange * * @brief Change the GAP state. * 1. Connected -> disconnect and start advertising * 2. Advertising -> stop advertising * 3. Disconnected/not advertising -> start advertising * * @param none * * @return none */ static void processGapStateChange(void) { if (gapProfileState != GAPROLE_CONNECTED) { uint8_t current_adv_enabled_status; uint8_t new_adv_enabled_status; // Find the current GAP advertising status GAPRole_GetParameter(GAPROLE_ADVERT_ENABLED, ¤t_adv_enabled_status); if (current_adv_enabled_status == FALSE) { new_adv_enabled_status = TRUE; } else { new_adv_enabled_status = FALSE; } // Change the GAP advertisement status to opposite of current status GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &new_adv_enabled_status); } if (gapProfileState == GAPROLE_CONNECTED) { uint8_t adv_enabled = TRUE; // Disconnect GAPRole_TerminateConnection(); // Start advertising GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &adv_enabled); } }
/*--------------------------------------------------------------------------- * Add the set the last part of hte device name to the final bytes of the * device address. Useful when mane demo devices are located in the same room. *-------------------------------------------------------------------------*/ void updateNameWithAddressInfo(void) { //uint8 status; uint8 numberString[4]; uint8 address[6]; uint8 value; //status = GAPRole_GetParameter(GAPROLE_BD_ADDR, address); GAPRole_GetParameter(GAPROLE_BD_ADDR, address); value = (address[1] & 0xF0) >> 4; numberString[0] = getAscii(value); value = address[1] & 0x0F; numberString[1] = getAscii(value); value = (address[0] & 0xF0) >> 4; numberString[2] = getAscii(value); value = address[0] & 0x0F; numberString[3] = getAscii(value); // Replace "0000" part of "OLP425-0000" osal_memcpy(&attDeviceName[7], numberString, 4); osal_memcpy(&deviceName[9], numberString, 4); osal_memcpy(&attDeviceNameNew[7], numberString, 4); osal_memcpy(&deviceNameNew[9], numberString, 4); // status = GAPRole_SetParameter( GAPROLE_SCAN_RSP_DATA, sizeof ( deviceName ), deviceName ); // status = GGS_SetParameter( GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN - 1, attDeviceName ); GAPRole_SetParameter( GAPROLE_SCAN_RSP_DATA, sizeof ( deviceName ), deviceName ); GGS_SetParameter( GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN - 1, attDeviceName ); }
/** * SNP_terminateConn * */ uint8_t SNP_terminateConn(snpTermConnReq_t *pReq) { uint8_t status = SNP_SUCCESS; if(pReq->option == SNP_GAP_TERM_CONN_IMMEDIATLY) { uint16_t value; GAPRole_GetParameter(GAPROLE_CONNHANDLE, &value); if(pReq->connHandle != value) { return SNP_INVALID_PARAMS; } else { HCI_EXT_DisconnectImmedCmd(value); } } else if(pReq->option == SNP_GAP_TERM_CONN_DEFAULT) { status = GAPRole_TerminateConnection(); } else { return SNP_INVALID_PARAMS; } return status; }
/********************************************************************* * @fn simpleBLEBroadcaster_HandleKeys * * @brief Handles all key events for this device. * * @param shift - true if in shift/alt. * @param keys - bit field for key events. Valid entries: * HAL_KEY_SW_2 * HAL_KEY_SW_1 * * @return none */ static void simpleBLEBroadcaster_HandleKeys( uint8 shift, uint8 keys ) { VOID shift; // Intentionally unreferenced parameter if ( keys & HAL_KEY_SW_1 ) { advertData[6]++; GAPRole_SetParameter( GAPROLE_ADVERT_DATA, sizeof( advertData ), advertData ); } if ( keys & HAL_KEY_SW_2 ) { // ressing the right key should toggle advertising on and off uint8 current_adv_enabled_status; uint8 new_adv_enabled_status; //Find the current GAP advertisement status GAPRole_GetParameter( GAPROLE_ADVERT_ENABLED, ¤t_adv_enabled_status ); if( current_adv_enabled_status == FALSE ) { new_adv_enabled_status = TRUE; } else { new_adv_enabled_status = FALSE; } //change the GAP advertisement status to opposite of current status GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &new_adv_enabled_status ); } }
/********************************************************************* * @fn softCmd_HandleKeys * * @brief Handles all key events for this device. * * @param shift - true if in shift/alt. * @param keys - bit field for key events. Valid entries: * HAL_KEY_SW_2 * HAL_KEY_SW_1 * * @return none */ static void softCmd_HandleKeys( uint8 shift, uint8 keys ) { if ( keys & HAL_KEY_SW_1 ) { // if in a connection send a soft key if ( softCmdGapState == GAPROLE_CONNECTED ) { softCmdSend( CMD_ENUM_SOFT_CMD_0 ); } } if ( keys & HAL_KEY_SW_2 ) { // if not in a connection, toggle advertising on and off if( softCmdGapState != GAPROLE_CONNECTED ) { uint8 status; // toggle GAP advertisement status GAPRole_GetParameter( GAPROLE_ADVERT_ENABLED, &status ); status = !status; GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &status ); } // if in a connection send a soft key else { softCmdSend( CMD_ENUM_SOFT_CMD_1 ); } } }
static void wechat_get_mac_addr(uint8 *mac_address) { uint8 ownAddress[B_ADDR_LEN]; GAPRole_GetParameter(GAPROLE_BD_ADDR, ownAddress); for ( uint8 i = 6; i > 0; ) { i--; mac_address[5-i]= ownAddress[i]; } }
/********************************************************************* * @fn Update UI * * @brief Update user interface LCD and LED * * @param none * * @return none */ static void updateUI( void ) { LCD_WRITE_STRING( "Thermometer", HAL_LCD_LINE_1 ); static uint8 ownAddress[B_ADDR_LEN]; #if (defined HAL_LCD) && (HAL_LCD == TRUE) //number of stored measuremnts uint16 count =0; //store index if( thStoreIndex > thStoreStartIndex ) { count = thStoreIndex - thStoreStartIndex; } if( thStoreStartIndex > thStoreIndex ) { count = ( TH_STORE_MAX-thStoreStartIndex ) + thStoreIndex+1; } #endif //State switch (gapProfileState) { case GAPROLE_INIT: LCD_WRITE_STRING( "Initialized", HAL_LCD_LINE_2 ); break; case GAPROLE_STARTED: LCD_WRITE_STRING( "Started", HAL_LCD_LINE_2 ); GAPRole_GetParameter(GAPROLE_BD_ADDR, ownAddress); LCD_WRITE_STRING( bdAddr2Str( ownAddress ), HAL_LCD_LINE_3 ); break; case GAPROLE_ADVERTISING: LCD_WRITE_STRING( "Advertising", HAL_LCD_LINE_2 ); LCD_WRITE_STRING( " ", HAL_LCD_LINE_3 ); LCD_WRITE_STRING_VALUE("Stored", count, 10, HAL_LCD_LINE_3 ); break; case GAPROLE_WAITING: case GAPROLE_WAITING_AFTER_TIMEOUT: LCD_WRITE_STRING( "Waiting ", HAL_LCD_LINE_2 ); LCD_WRITE_STRING_VALUE("Stored", count, 10, HAL_LCD_LINE_3 ); break; case GAPROLE_CONNECTED: LCD_WRITE_STRING( "Connected ", HAL_LCD_LINE_2 ); break; case GAPROLE_ERROR: LCD_WRITE_STRING( "Error ", HAL_LCD_LINE_2 ); break; default: break; } }
/******************************************************************************* * @fn SensorTagConnectionControl_update * * @brief Update the Connection Control service with the current connection * control settings * */ void SensorTagConnectionControl_update(void) { uint8_t buf[CCSERVICE_CHAR1_LEN]; uint16_t connInterval; uint16_t connSlaveLatency; uint16_t connTimeout; // Get the connection control data GAPRole_GetParameter(GAPROLE_CONN_INTERVAL, &connInterval); GAPRole_GetParameter(GAPROLE_SLAVE_LATENCY, &connSlaveLatency); GAPRole_GetParameter(GAPROLE_CONN_TIMEOUT, &connTimeout); buf[0] = LO_UINT16(connInterval); buf[1] = HI_UINT16(connInterval); buf[2] = LO_UINT16(connSlaveLatency); buf[3] = HI_UINT16(connSlaveLatency); buf[4] = LO_UINT16(connTimeout); buf[5] = HI_UINT16(connTimeout); CcService_setParameter(CCSERVICE_CHAR1,sizeof(buf),buf); }
static void FanPeripheralStateNotificationCallBack(gaprole_States_t newState) { switch (newState) { case GAPROLE_STARTED: { uint8 ownAddress[B_ADDR_LEN]; uint8 systemId[DEVINFO_SYSTEM_ID_LEN]; GAPRole_GetParameter(GAPROLE_BD_ADDR, ownAddress); // use 6 bytes of device address for 8 bytes of system ID value systemId[0] = ownAddress[0]; systemId[1] = ownAddress[1]; systemId[2] = ownAddress[2]; // set middle bytes to zero systemId[4] = 0x00; systemId[3] = 0x00; // shift three bytes up systemId[7] = ownAddress[5]; systemId[6] = ownAddress[4]; systemId[5] = ownAddress[3]; DevInfo_SetParameter(DEVINFO_SYSTEM_ID, DEVINFO_SYSTEM_ID_LEN, systemId); } break; case GAPROLE_ADVERTISING: break; case GAPROLE_CONNECTED: FanConnected(fanTaskId); break; case GAPROLE_WAITING: { FanDisConnected(); uint8 advertEnabled = FALSE; GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8), &advertEnabled); GAPRole_SetParameter(GAPROLE_SCAN_RSP_DATA, sizeof(scanResponseData), scanResponseData); GGS_SetParameter(GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, scanResponseData + 2); advertEnabled = TRUE; GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8), &advertEnabled); } break; case GAPROLE_WAITING_AFTER_TIMEOUT: break; case GAPROLE_ERROR: break; default: break; } };
/** * SNP_getStatus */ void SNP_getStatus(snpGetStatusCmdRsp_t *pMsg) { extern snp_ATToperation_t snp_ATTstore; GAPRole_GetParameter(GAPROLE_STATE, &pMsg->gapRoleStatus); GAPRole_GetParameter(GAPROLE_ADVERT_ENABLED, &pMsg->advStatus); if(pMsg->advStatus == FALSE) { // Connectable Advertisement not enabled, Check of non-connectable adv // enabled GAPRole_GetParameter(GAPROLE_ADV_NONCONN_ENABLED, &pMsg->advStatus); } pMsg->ATTstatus = snp_ATTstore.validity; if(snp_ATTstore.validity) { pMsg->ATTmethod = snp_ATTstore.method; } else { pMsg->ATTmethod = 0; } }
/********************************************************************* * @fn peripheralStateNotificationCB * * @brief Notification from the profile of a state change. * * @param newState - new state * * @return none */ static void peripheralStateNotificationCB( gaprole_States_t newState ) { switch ( newState ) { case GAPROLE_STARTED: { uint8 ownAddress[B_ADDR_LEN]; GAPRole_GetParameter(GAPROLE_BD_ADDR, ownAddress); #if (defined HAL_LCD) && (HAL_LCD == TRUE) // Display device address HalLcdWriteString( bdAddr2Str( ownAddress ), HAL_LCD_LINE_2 ); HalLcdWriteString( "Initialized", HAL_LCD_LINE_3 ); #endif // (defined HAL_LCD) && (HAL_LCD == TRUE) } break; case GAPROLE_ADVERTISING: { #if (defined HAL_LCD) && (HAL_LCD == TRUE) HalLcdWriteString( "Advertising", HAL_LCD_LINE_3 ); #endif // (defined HAL_LCD) && (HAL_LCD == TRUE) } break; case GAPROLE_WAITING: { #if (defined HAL_LCD) && (HAL_LCD == TRUE) HalLcdWriteString( "Waiting", HAL_LCD_LINE_3 ); #endif // (defined HAL_LCD) && (HAL_LCD == TRUE) } break; case GAPROLE_ERROR: { #if (defined HAL_LCD) && (HAL_LCD == TRUE) HalLcdWriteString( "Error", HAL_LCD_LINE_3 ); #endif // (defined HAL_LCD) && (HAL_LCD == TRUE) } break; default: { #if (defined HAL_LCD) && (HAL_LCD == TRUE) HalLcdWriteString( "", HAL_LCD_LINE_3 ); #endif // (defined HAL_LCD) && (HAL_LCD == TRUE) } break; } }
/********************************************************************* * @fn simpleBLEPeripheral_HandleKeys * * @brief Handles all key events for this device. * * @param shift - true if in shift/alt. * @param keys - bit field for key events. Valid entries: * HAL_KEY_SW_2 * HAL_KEY_SW_1 * * @return none */ static void simpleBLEPeripheral_HandleKeys( uint8 shift, uint8 keys ) { uint8 SK_Keys = 0; VOID shift; // Intentionally unreferenced parameter if ( keys & HAL_KEY_SW_1 ) { SK_Keys |= SK_KEY_LEFT; } if ( keys & HAL_KEY_SW_2 ) { SK_Keys |= SK_KEY_RIGHT; // if device is not in a connection, pressing the right key should toggle // advertising on and off // Note: If PLUS_BROADCASTER is define this condition is ignored and // Device may advertise during connections as well. #ifndef PLUS_BROADCASTER if( gapProfileState != GAPROLE_CONNECTED ) { #endif // PLUS_BROADCASTER uint8 current_adv_enabled_status; uint8 new_adv_enabled_status; //Find the current GAP advertisement status GAPRole_GetParameter( GAPROLE_ADVERT_ENABLED, ¤t_adv_enabled_status ); if( current_adv_enabled_status == FALSE ) { new_adv_enabled_status = TRUE; } else { new_adv_enabled_status = FALSE; } //change the GAP advertisement status to opposite of current status GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &new_adv_enabled_status ); #ifndef PLUS_BROADCASTER } #endif // PLUS_BROADCASTER } // Set the value of the keys state to the Simple Keys Profile; // This will send out a notification of the keys state if enabled SK_SetParameter( SK_KEY_ATTR, sizeof ( uint8 ), &SK_Keys ); }
/** * SNP_setAdvData * */ uint8_t SNP_setAdvData(snpSetAdvDataReq_t *pReq, uint8_t len) { uint8_t status = 0; uint8_t *pDataPtr; //Device must be started, or the set adv command will failed. VOID GAPRole_StartDevice(&SNP_gapRoleCBs); if(pReq->type < SNP_ADV_DATA_MAX_IDX) { pDataPtr = advPtrTable[pReq->type].pData; if(pDataPtr) { ICall_free(advPtrTable[pReq->type].pData); } advPtrTable[pReq->type].pData = pDataPtr = ICall_malloc(len); if(pDataPtr) { advPtrTable[pReq->type].length = len; memcpy(pDataPtr, pReq->pData, len); if(pReq->type == SNP_ADV_DATA_SCAN_RSP_IDX) { status = GAPRole_SetParameter(GAPROLE_SCAN_RSP_DATA, len, pDataPtr); } else if(pReq->type == SNP_ADV_DATA_NON_CONN_IDX) { status = GAPRole_SetParameter(GAPROLE_ADVERT_DATA, len, pDataPtr); } else if(pReq->type == SNP_ADV_DATA_CONN_IDX) { uint8_t value; GAPRole_GetParameter(GAPROLE_STATE, &value); if(value == GAPROLE_CONNECTED_ADV) { status = GAPRole_SetParameter(GAPROLE_ADVERT_DATA, len, pDataPtr); } } } else { status = SNP_OUT_OF_RESOURCES; } } else { //Error, bad type status = SNP_INVALID_PARAMS; } return status; }
/********************************************************************* * @fn peripheralStateNotificationCB * * @brief Notification from the profile of a state change. * * @param newState - new state * * @return none */ static void peripheralStateNotificationCB( gaprole_States_t newState ) { switch ( newState ) { case GAPROLE_STARTED: { uint8 ownAddress[B_ADDR_LEN]; uint8 systemId[DEVINFO_SYSTEM_ID_LEN]; GAPRole_GetParameter(GAPROLE_BD_ADDR, ownAddress); // use 6 bytes of device address for 8 bytes of system ID value systemId[0] = ownAddress[0]; systemId[1] = ownAddress[1]; systemId[2] = ownAddress[2]; // set middle bytes to zero systemId[4] = 0x00; systemId[3] = 0x00; // shift three bytes up systemId[7] = ownAddress[5]; systemId[6] = ownAddress[4]; systemId[5] = ownAddress[3]; DevInfo_SetParameter(DEVINFO_SYSTEM_ID, DEVINFO_SYSTEM_ID_LEN, systemId); } break; case GAPROLE_ADVERTISING: HalLedSet(HAL_LED_1, HAL_LED_MODE_ON ); break; case GAPROLE_CONNECTED: HalLedSet(HAL_LED_1, HAL_LED_MODE_OFF ); break; case GAPROLE_WAITING: // Link terminated intentionally: reset all sensors resetSensorSetup(); break; default: break; } gapProfileState = newState; }
/** * @fn SNP_paramUpdateCB * * @brief callback to be notify a update of the connection parameters * has happened. * * @param[in] connInterval : interval of the connection * @param[in] connSlaveLatency : slave latency of the connection * @param[in] connTimeout : supervision timeout of the connection * * @return status of the command. */ void SNP_paramUpdateCB(uint16_t connInterval, uint16_t connSlaveLatency, uint16_t connTimeout) { uint16_t param[4]; uint16_t temp; GAPRole_GetParameter(GAPROLE_CONNHANDLE, &temp); param[0] = BUILD_UINT16(LO_UINT16(temp), HI_UINT16(temp)); param[1] = BUILD_UINT16(LO_UINT16(connInterval), HI_UINT16(connInterval)); param[2] = BUILD_UINT16(LO_UINT16(connSlaveLatency), HI_UINT16(connSlaveLatency)); param[3] = BUILD_UINT16(LO_UINT16(connTimeout), HI_UINT16(connTimeout)); SNP_eventToHost_send(SNP_CONN_PARAM_UPDATED_EVT, NULL, sizeof(param), (uint8_t*)param); }
/********************************************************************* * @fn HeartRate_toggleAdvertising * * @brief Toggle advertising state. * * @param none * * @return status - TRUE if advertising, FALSE otherwise. */ static bool HeartRate_toggleAdvertising(void) { uint8_t advState; // Find the current GAP advertisement status. GAPRole_GetParameter(GAPROLE_ADVERT_ENABLED, &advState); // Get the opposite state. advState = !advState; // Change the GAP advertisement status to opposite of current status. GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &advState); return advState; }
/********************************************************************* * @fn heartRate_HandleKeys * * @brief Handles all key events for this device. * * @param shift - true if in shift/alt. * @param keys - bit field for key events. Valid entries: * HAL_KEY_SW_2 * HAL_KEY_SW_1 * * @return none */ static void heartRate_HandleKeys( uint8 shift, uint8 keys ) { if ( keys & HAL_KEY_SW_1 ) { // set simulated measurement flag index if (++heartRateFlagsIdx == FLAGS_IDX_MAX) { heartRateFlagsIdx = 0; } } if ( keys & HAL_KEY_SW_2 ) { // if not in a connection, toggle advertising on and off if( gapProfileState != GAPROLE_CONNECTED ) { uint8 status; // Set fast advertising interval for user-initiated connections GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MIN, DEFAULT_FAST_ADV_INTERVAL ); GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MAX, DEFAULT_FAST_ADV_INTERVAL ); GAP_SetParamValue( TGAP_GEN_DISC_ADV_MIN, DEFAULT_FAST_ADV_DURATION ); // toggle GAP advertisement status GAPRole_GetParameter( GAPROLE_ADVERT_ENABLED, &status ); status = !status; GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &status ); // Set state variable if (status == FALSE) { heartRateAdvCancelled = TRUE; } } // if in a connection toggle some the battery state bits for test purposes else { uint8 state; Batt_GetParameter( BATT_PARAM_STATE, &state ); state ^= BATT_FLAGS_CR_CRIT; Batt_SetParameter( BATT_PARAM_STATE, sizeof( uint8 ), &state ); } } }
/********************************************************************* * @fn bloodPressure_HandleKeys * * @brief Handles all key events for this device. * * @param shift - true if in shift/alt. * @param keys - bit field for key events. Valid entries: * HAL_KEY_SW_2 * HAL_KEY_SW_1 * * @return none */ static void bloodPressure_HandleKeys( uint8 shift, uint8 keys ) { if ( keys & HAL_KEY_SW_1 ) { // set simulated measurement flag index if (++bloodPressureFlagsIdx == FLAGS_IDX_MAX) { bloodPressureFlagsIdx = 0; } } if ( keys & HAL_KEY_SW_2 ) { // if device is not in a connection, pressing the right key should toggle // advertising on and off and start a measurement if( gapProfileState != GAPROLE_CONNECTED ) { uint8 current_adv_enabled_status; uint8 new_adv_enabled_status; //Find the current GAP advertisement status GAPRole_GetParameter( GAPROLE_ADVERT_ENABLED, ¤t_adv_enabled_status ); if( current_adv_enabled_status == FALSE ) new_adv_enabled_status = TRUE; else new_adv_enabled_status = FALSE; //change the GAP advertisement status to opposite of current status GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &new_adv_enabled_status ); //start simulation timer (start --> cuff -->measurement ready) osal_start_timerEx( bloodPressureTaskId, BP_TIMER_CUFF_EVT, TIMER_CUFF_PERIOD ); //reset cuff count cuffCount = 0; } else //connected mode, simulate some measurements { simulateMeas(); } } }
/** * SNP_updateConnParam * */ uint8_t SNP_updateConnParam(snpUpdateConnParamReq_t *pReq) { uint8_t enableUpdateRequest = TRUE; uint8_t status; uint8_t value; status = GAPRole_SetParameter(GAPROLE_PARAM_UPDATE_ENABLE, sizeof(uint8_t), &enableUpdateRequest); status |= GAPRole_SetParameter(GAPROLE_MIN_CONN_INTERVAL, sizeof(uint16_t), &pReq->intervalMin); status |= GAPRole_SetParameter(GAPROLE_MAX_CONN_INTERVAL, sizeof(uint16_t), &pReq->intervalMax); status |= GAPRole_SetParameter(GAPROLE_SLAVE_LATENCY, sizeof(uint16_t), &pReq->slaveLatency); status |= GAPRole_SetParameter(GAPROLE_TIMEOUT_MULTIPLIER, sizeof(uint16_t), &pReq->supervisionTimeout); if(status == bleInvalidRange) { //Error management return SNP_INVALID_PARAMS; } else if(status) { // Mix of errors return SNP_FAILURE; } //check Status, only force update if in a connection. GAPRole_GetParameter(GAPROLE_STATE, &value); if((value == GAPROLE_CONNECTED) || (value == GAPROLE_CONNECTED_ADV)) { if (GAPRole_SetParameter( GAPROLE_PARAM_UPDATE_REQ, sizeof(uint8_t), &enableUpdateRequest)) { status = SNP_INVALID_PARAMS; } } else { status = SNP_NOT_CONNECTED; } return status; }
uint8 Application_StopAdvertise() { if( gapProfileState != GAPROLE_CONNECTED ) { uint8 astatus; // toggle GAP advertisement status GAPRole_GetParameter( GAPROLE_ADVERT_ENABLED, &astatus ); if (astatus == TRUE) { astatus = FALSE; GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &astatus ); return SUCCESS; } } return FAILURE; }
bStatus_t char4_notify(uint8 state) { attHandleValueNoti_t Report; GAPRole_GetParameter(GAPROLE_CONNHANDLE, &connHandle); uint16 value = GATTServApp_ReadCharCfg( connHandle, simpleProfileChar4Config); // If notifications enabled if ( value & GATT_CLIENT_CFG_NOTIFY ) { // Set the handle Report.handle = simpleProfileAttrTbl[14].handle; Report.len = 1; osal_memcpy(Report.value, &state, 1); // Send the notification return GATT_Notification( connHandle, &Report, FALSE ); } return bleIncorrectMode; }
/********************************************************************* * @fn SimpleBLEBroadcaster_processStateChangeEvt * * @brief Notification from the profile of a state change. * * @param newState - new state * * @return none */ static void SimpleBLEBroadcaster_processStateChangeEvt(gaprole_States_t newState) { switch (newState) { case GAPROLE_STARTED: { uint8 ownAddress[B_ADDR_LEN]; GAPRole_GetParameter(GAPROLE_BD_ADDR, ownAddress); // Display device address LCD_WRITE_STRING(Util_convertBdAddr2Str(ownAddress), LCD_PAGE1); LCD_WRITE_STRING("Initialized", LCD_PAGE2); } break; case GAPROLE_ADVERTISING: { LCD_WRITE_STRING("Advertising", LCD_PAGE2); } break; case GAPROLE_WAITING: { LCD_WRITE_STRING("Waiting", LCD_PAGE2); } break; case GAPROLE_ERROR: { LCD_WRITE_STRING("Error", LCD_PAGE2); } break; default: { LCD_WRITE_STRING("", LCD_PAGE2); } break; } }
/********************************************************************* * @fn hidDevGapStateCB * * @brief Notification from the profile of a state change. * * @param newState - new state * * @return none */ static void hidDevGapStateCB( gaprole_States_t newState ) { // if connected if ( newState == GAPROLE_CONNECTED ) { // get connection handle GAPRole_GetParameter( GAPROLE_CONNHANDLE, &gapConnHandle ); // connection not secure yet hidDevConnSecure = FALSE; // don't start advertising when connection is closed uint8 param = FALSE; GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), ¶m ); // start idle timer hidDevStartIdleTimer(); } // if disconnected else if ( hidDevGapState == GAPROLE_CONNECTED && newState != GAPROLE_CONNECTED ) { hidDevDisconnected(); updateConnParams = TRUE; if ( pairingStatus == SMP_PAIRING_FAILED_CONFIRM_VALUE ) { // bonding failed due to mismatched confirm values hidDevInitialAdvertising(); pairingStatus = SUCCESS; } } // if started else if ( newState == GAPROLE_STARTED ) { // nothing to do for now! } hidDevGapState = newState; }
/********************************************************************* * @fn thermometer_Advertise * * @brief Start advertisemement when measurement is ready * * * @return none */ static void thermometer_Advertise( void ) { // Advertise if not connected if( gapProfileState != GAPROLE_CONNECTED ) { uint8 current_adv_enabled_status; uint8 new_adv_enabled_status; //Find the current GAP advertisement status GAPRole_GetParameter( GAPROLE_ADVERT_ENABLED, ¤t_adv_enabled_status ); if( current_adv_enabled_status == FALSE ) { new_adv_enabled_status = TRUE; } //change the GAP advertisement status GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &new_adv_enabled_status ); } }
uint8 Application_StartAdvertise(uint16 duration, uint16 interval) { if( gapProfileState != GAPROLE_CONNECTED ) { uint8 astatus; // toggle GAP advertisement status GAPRole_GetParameter( GAPROLE_ADVERT_ENABLED, &astatus ); if (astatus == FALSE) { //Set fast advertising interval for user-initiated connections GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MIN, interval ); GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MAX, interval ); GAP_SetParamValue( TGAP_LIM_ADV_TIMEOUT, duration ); astatus = TRUE; GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &astatus ); return SUCCESS; } } return FAILURE; }
/********************************************************************* * @fn Thermometer_advertise * * @brief Start advertisement when measurement is ready. * * @param none * * @return none */ static void Thermometer_advertise(void) { // If not connected, toggle advertising. if (gapProfileState != GAPROLE_CONNECTED) { uint8_t current_adv_enabled_status; uint8_t new_adv_enabled_status; // Find the current GAP advertisement status. GAPRole_GetParameter(GAPROLE_ADVERT_ENABLED, ¤t_adv_enabled_status); if(current_adv_enabled_status == FALSE) { new_adv_enabled_status = TRUE; } // Change the GAP advertisement status . GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &new_adv_enabled_status); } }
/********************************************************************* * @fn softCmdGapStateCB * * @brief Notification from the profile of a state change. * * @param newState - new state * * @return none */ static void softCmdGapStateCB( gaprole_States_t newState ) { // if connected if (newState == GAPROLE_CONNECTED) { linkDBItem_t *pItem; // Get connection handle GAPRole_GetParameter( GAPROLE_CONNHANDLE, &softCmdConnHandle ); // Get peer bd address if ( (pItem = linkDB_Find( softCmdConnHandle )) != NULL) { // If connected to device without bond do service discovery if ( !osal_memcmp( pItem->addr, softCmdBondedAddr, B_ADDR_LEN ) ) { softCmdDiscoveryCmpl = FALSE; } // Initiate service discovery if necessary if ( softCmdDiscoveryCmpl == FALSE ) { osal_start_timerEx( softCmdTaskId, START_DISCOVERY_EVT, DEFAULT_DISCOVERY_DELAY ); } } } // if disconnected else if (softCmdGapState == GAPROLE_CONNECTED && newState != GAPROLE_CONNECTED) { softCmdDisconnected(); // reset client characteristic configuration descriptors uint16 param = GATT_CFG_NO_OPERATION; Batt_SetParameter(BATT_PARAM_LVL_ST_CHAR_CFG, sizeof(uint16), (uint8 *) ¶m); } softCmdGapState = newState; }
/** * @fn uartServ2_SetParameter * * @brief Set a Service 2 parameter. * * @param param - Profile parameter ID * @param len - length of data to right * @param value - pointer to data to write. This is dependent on * the parameter ID and WILL be cast to the appropriate * data type (example: data type of uint16 will be cast to * uint16 pointer). * * @return bStatus_t */ bStatus_t uartServ2_SetParameter(uint8 param, uint8 len, void *value) { bStatus_t ret = SUCCESS; switch (param) { case UARTSERV2_CHAR: { attHandleValueNoti_t noti; uint16 notiHandle; uint8 *pkt = (uint8 *) value; GAPRole_GetParameter(GAPROLE_CONNHANDLE, ¬iHandle); noti.handle = uartServ2AttrTbl[2].handle; noti.len = len; osal_memcpy(¬i.value[0], pkt, noti.len); GATT_Notification(notiHandle, ¬i, FALSE); // { uint8 i; dmsg(("[ble->app]:")); for (i=0; i<noti.len; i++) { dmsg((" %02x", noti.value[i])); } dmsg(("\n")); } } break; default: ret = INVALIDPARAMETER; break; } return (ret); }