微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 无线和射频 > TI蓝牙设计交流 > ANCS的问题

ANCS的问题

时间:10-02 整理:3721RD 点击:

我把ANCS集成到KeyFob里了,添加了两个task,分别是处理KeyFob和Ancs的任务

  /* Application */

  KeyFobApp_Init( taskID++ );

  TimeApp_Init(taskID);

并在初始化的时候通过调用GATT_RegisterForInd注册了ancs的task做为接收task,现在的问题是与手机上的APP连接上(Keyfob里的服务和ANCS都连接上,功能也正常),然后把APP杀掉,但ANCS也不会断开,于是设备端不知道KeyFob里的服务断开了,不能继续广播,于是再打开APP就搜索不到设备了,我要怎么获取KeyFob里的服务是否断开了?断开后我要重新广播。

两个task的init函数如下 :

void TimeApp_Init( uint8 task_id )

{

  timeAppTaskId = task_id;

  

  // Register to receive incoming ATT Indications/Notifications

  GATT_RegisterForInd( timeAppTaskId );

  // Setup a delayed profile startup

  osal_set_event( timeAppTaskId, START_DEVICE_EVT );

}

oid KeyFobApp_Init( uint8 task_id )

{

  keyfobapp_TaskID = task_id;

  // Setup the GAP

  VOID GAP_SetParamValue( TGAP_CONN_PAUSE_PERIPHERAL, DEFAULT_CONN_PAUSE_PERIPHERAL );

  

  // Setup the GAP Peripheral Role Profile

  {

    // For the CC2540DK-MINI keyfob, device doesn't start advertising until button is pressed

    uint8 initial_advertising_enable = FALSE;

    

    // By setting this to zero, the device will go into the waiting state after

    // being discoverable for 30.72 second, and will not being advertising again

    // until the enabler is set back to TRUE

    uint16 gapRole_AdvertOffTime = 0;

  

    uint8 enable_update_request = DEFAULT_ENABLE_UPDATE_REQUEST;

    uint16 desired_min_interval = DEFAULT_DESIRED_MIN_CONN_INTERVAL;

    uint16 desired_max_interval = DEFAULT_DESIRED_MAX_CONN_INTERVAL;

    uint16 desired_slave_latency = DEFAULT_DESIRED_SLAVE_LATENCY;

    uint16 desired_conn_timeout = DEFAULT_DESIRED_CONN_TIMEOUT;

   

    // Set the GAP Role Parameters

    GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &initial_advertising_enable );

    GAPRole_SetParameter( GAPROLE_ADVERT_OFF_TIME, sizeof( uint16 ), &gapRole_AdvertOffTime );

  

    GAPRole_SetParameter( GAPROLE_SCAN_RSP_DATA, sizeof ( deviceName ), deviceName );

    GAPRole_SetParameter( GAPROLE_ADVERT_DATA, sizeof( advertData ), advertData );

  

    GAPRole_SetParameter( GAPROLE_PARAM_UPDATE_ENABLE, sizeof( uint8 ), &enable_update_request );

    GAPRole_SetParameter( GAPROLE_MIN_CONN_INTERVAL, sizeof( uint16 ), &desired_min_interval );

    GAPRole_SetParameter( GAPROLE_MAX_CONN_INTERVAL, sizeof( uint16 ), &desired_max_interval );

    GAPRole_SetParameter( GAPROLE_SLAVE_LATENCY, sizeof( uint16 ), &desired_slave_latency );

    GAPRole_SetParameter( GAPROLE_TIMEOUT_MULTIPLIER, sizeof( uint16 ), &desired_conn_timeout );

  }

  

  // Set the GAP Attributes

  GGS_SetParameter( GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, attDeviceName );

  // Setup the GAP Bond Manager

  {

    uint32 passkey = DEFAULT_PASSCODE;

    uint8 pairMode = DEFAULT_PAIRING_MODE;

    uint8 mitm = DEFAULT_MITM_MODE;

    uint8 ioCap = DEFAULT_IO_CAPABILITIES;

    uint8 bonding = DEFAULT_BONDING_MODE;

    GAPBondMgr_SetParameter( GAPBOND_DEFAULT_PASSCODE, sizeof( uint32 ), &passkey );

    GAPBondMgr_SetParameter( GAPBOND_PAIRING_MODE, sizeof( uint8 ), &pairMode );

    GAPBondMgr_SetParameter( GAPBOND_MITM_PROTECTION, sizeof( uint8 ), &mitm );

    GAPBondMgr_SetParameter( GAPBOND_IO_CAPABILITIES, sizeof( uint8 ), &ioCap );

    GAPBondMgr_SetParameter( GAPBOND_BONDING_ENABLED, sizeof( uint8 ), &bonding );

  }

  

  // Initialize GATT Client

  VOID GATT_InitClient();

  // Initialize GATT attributes

  GGS_AddService( GATT_ALL_SERVICES ); // GAP

  GATTServApp_AddService( GATT_ALL_SERVICES ); // GATT attributes

  DevInfo_AddService(); // Device Information Service

  ProxReporter_AddService( GATT_ALL_SERVICES ); // Proximity Reporter Profile

  Batt_AddService( ); // Battery Service

  Accel_AddService( GATT_ALL_SERVICES ); // Accelerometer Profile

  SK_AddService( GATT_ALL_SERVICES ); // Simple Keys Profile

  keyfobProximityState = KEYFOB_PROXSTATE_INITIALIZED;

  // Initialize Tx Power Level characteristic in Proximity Reporter

  {

    int8 initialTxPowerLevel = 0;

    

    ProxReporter_SetParameter( PP_TX_POWER_LEVEL, sizeof ( int8 ), &initialTxPowerLevel );

  }

  keyfobAlertState = ALERT_STATE_OFF;

  // make sure buzzer is off

  buzzerStop();

  // makes sure LEDs are off

  HalLedSet( (HAL_LED_1 | HAL_LED_2), HAL_LED_MODE_OFF );

  // For keyfob board set GPIO pins into a power-optimized state

  // Note that there is still some leakage current from the buzzer,

  // accelerometer, LEDs, and buttons on the PCB.

  P0SEL = 0; // Configure Port 0 as GPIO

  P1SEL = 0x40; // Configure Port 1 as GPIO, except P1.6 for peripheral function for buzzer

  P2SEL = 0; // Configure Port 2 as GPIO

  P0DIR = 0xFC; // Port 0 pins P0.0 and P0.1 as input (buttons),

                // all others (P0.2-P0.7) as output

  P1DIR = 0xFF; // All port 1 pins (P1.0-P1.7) as output

  P2DIR = 0x1F; // All port 1 pins (P2.0-P2.4) as output

  P0 = 0x03; // All pins on port 0 to low except for P0.0 and P0.1 (buttons)

  P1 = 0; // All pins on port 1 to low

  P2 = 0; // All pins on port 2 to low

  // initialize the ADC for battery reads

  HalAdcInit();

  // Register for all key events - This app will handle all key events

  RegisterForKeys( keyfobapp_TaskID );

#if defined ( DC_DC_P0_7 )

  // Enable stack to toggle bypass control on TPS62730 (DC/DC converter)

  HCI_EXT_MapPmIoPortCmd( HCI_EXT_PM_IO_PORT_P0, HCI_EXT_PM_IO_PORT_PIN7 );

#endif // defined ( DC_DC_P0_7 )

  

  // Setup a delayed profile startup

  osal_start_timerEx( keyfobapp_TaskID, KFD_START_DEVICE_EVT, STARTDELAY );

}

只有设备与手机的连接断开了才会回调到应用层吗?那我这种情况应该怎么处理。。。现在我是用keyfob做防丢器,然后在keyfob里集成了ANCS,防丢器与APP连接后,再把APP杀掉,然后再打开APP却搜索不到设备了,那设备端要怎么才能知道APP被杀掉的动作?只有知道这个动作我才能判断是否要广播。

什么情况。。

你好,

你把APP杀掉你确认BLE还是保持连接的还是已经断开了?

Kefob软件中你可以看到,ble 断开连接之后他是会自动重新开始广播的。

所以,请你确认一下,如果不是杀掉app,而是直接关掉蓝牙,你看下重新打开是CC2541有没有在广播。

你好,

杀掉APP后,应该还是连接着的,在iOS的蓝牙设置界面显示已连接。

关掉蓝牙CC2540会重新广播。

你好,

对吧,这个应该是APP并没有正常disconnect。

蓝牙应该没有关掉。

所以你需要在APP上找原因。

那我APP重新打开的时候 可以直接跟设备通信吗?不需要重新连接了?

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top