/********************************************************************* * @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 peripheralStateNotificationCB * * @brief Notification from the profile of a state change. * * @param newState - new state * * @return none */ static void peripheralStateNotificationCB( gaprole_States_t newState ) { #ifdef PLUS_BROADCASTER static uint8 first_conn_flag = 0; #endif // PLUS_BROADCASTER 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); #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_CONNECTED: { #if (defined HAL_LCD) && (HAL_LCD == TRUE) HalLcdWriteString( "Connected", HAL_LCD_LINE_3 ); #endif // (defined HAL_LCD) && (HAL_LCD == TRUE) #ifdef PLUS_BROADCASTER // Only turn advertising on for this state when we first connect // otherwise, when we go from connected_advertising back to this state // we will be turning advertising back on. if ( first_conn_flag == 0 ) { uint8 adv_enabled_status = 1; GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8), &adv_enabled_status); // Turn on Advertising first_conn_flag = 1; } #endif // PLUS_BROADCASTER } break; case GAPROLE_CONNECTED_ADV: { #if (defined HAL_LCD) && (HAL_LCD == TRUE) HalLcdWriteString( "Connected Advertising", HAL_LCD_LINE_3 ); #endif // (defined HAL_LCD) && (HAL_LCD == TRUE) } break; case GAPROLE_WAITING: { // Link terminated intentionally: reset all sensors resetSensorSetup(); #if (defined HAL_LCD) && (HAL_LCD == TRUE) HalLcdWriteString( "Disconnected", HAL_LCD_LINE_3 ); #endif // (defined HAL_LCD) && (HAL_LCD == TRUE) } break; case GAPROLE_WAITING_AFTER_TIMEOUT: { #if (defined HAL_LCD) && (HAL_LCD == TRUE) HalLcdWriteString( "Timed Out", HAL_LCD_LINE_3 ); #endif // (defined HAL_LCD) && (HAL_LCD == TRUE) #ifdef PLUS_BROADCASTER // Reset flag for next connection. first_conn_flag = 0; #endif //#ifdef (PLUS_BROADCASTER) } 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; } gapProfileState = newState; #if !defined( CC2540_MINIDK ) VOID gapProfileState; // added to prevent compiler warning with // "CC2540 Slave" configurations #endif }