This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

我可以把ANCS做到keyfob里吗?

Other Parts Discussed in Thread: TPS62730

ANCS是从TimeApp的基础上改的,看TimeApp里调用了:

// Initialize GATT Client
VOID GATT_InitClient();

// Register to receive incoming ATT Indications/Notifications
GATT_RegisterForInd( timeAppTaskId );

1. ANCS是不是一定要做client?

2. 那和keyfob会不会冲突?

3. 上面这两个函数的详细功能是什么呢?谢谢!

  • ouc qzy,

    当然可以。

    1. 是的。ANCS必须是client。但对于一个设备来说,可以是Client和Server共存。

    2. 不会冲突。

    3. 这是初始化GATT和注册indication 指定接收的task。

  • 你好,是不是调用GATT_RegisterForInd后会回调对应task中的下面这个回调函数?

    // GAP Role Callbacks

    static gapRolesCBs_t timeAppPeripheralCB =

    {

      timeAppGapStateCB, // Profile State Change Callbacks

      NULL // When a valid RSSI is read from controller

    };

    我把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 );

    }

  • 你好,是不是调用GATT_RegisterForInd后会回调对应task中的下面这个回调函数?

    // GAP Role Callbacks

    static gapRolesCBs_t timeAppPeripheralCB =

    {

      timeAppGapStateCB, // Profile State Change Callbacks

      NULL // When a valid RSSI is read from controller

    };

    我把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被杀掉的动作?只有知道这个动作我才能判断是否要广播。

  • 怎么没人了。。。