tiger-gz 发表于 2014-5-28 11:14:39

如何获得远端设备名称?

请问大神,如果想要获取远端蓝牙设备的名称应该如何做?

LXQ 发表于 2014-5-28 14:40:21

:):):):):)

legendflying 发表于 2014-5-28 14:54:10

profile support
找相应profile里参数

tiger-gz 发表于 2014-5-29 08:37:49

legendflying 发表于 2014-5-28 14:54
profile support
找相应profile里参数

可以具体点吗?是远端名称,不是本地名称哦。谢谢。

legendflying 发表于 2014-5-29 13:50:54

bluelab4.1里面的EIR a,可以把附近搜索到的设备名称打印出来
我把main。c文件贴给看看
/* Copyright (C) Cambridge Silicon Radio Limited 2008-2009 */
/* Part of BlueLab 4.1-Release */

#include <stdio.h>
#include <stdlib.h>
#include <connection.h>
#include <panic.h>

#ifdef DEBUG_ENABLED
#   define DEBUG(x) x
#else
#   define DEBUG(x)
#endif

static TaskData task;         /* application task */

/* application local messages */
enum
{
    APP_INQUIRE = 0,            /* Inquire devices */

    APP_MESSAGE_TOP
};

/* EIR data types as defined in Bluetooth Assigned Numbers */
#define EIR_UUID16_PART         0x02    /* More 16-bit UUIDs available */
#define EIR_UUID16            0x03    /* Complete list of 16-bit UUIDs */
#define EIR_UUID32_PART         0x04    /* More 32-bit UUIDs available */
#define EIR_UUID32            0x05    /* Complete list of 32-bit UUIDs */
#define EIR_UUID128_PART      0x06    /* More 128-bit UUIDs available */
#define EIR_UUID128             0x07    /* Complete list of 128-bit UUIDs */
#define EIR_NAME_PART         0x08    /* Shortened local name */
#define EIR_NAME                0x09    /* Complete local name */
#define EIR_TXPOWER             0x0a    /* TX Power level */
#define EIR_OOB_COD             0x0d    /* SSP OOB Class of Device */
#define EIR_OOB_C               0x0e    /* SSP OOB Hash C */
#define EIR_OOB_R               0x0f    /* SSP OOB Randomizer R */
#define EIR_ID                  0x10    /* Device ID */
#define EIR_MANUFACTURER      0xff    /* Manufacturer Specific Data */

static const char *hex = "0123456789abcdef";
static uint8 *bd_format(const bdaddr *addr)
{
    /* this uses 18 bytes globals but is OK for this example */
    static uint8 rc;

    /* return Bluetooth address in human readable format */
    rc[ 0] = hex[(addr->nap >> 12) & 0xf];
    rc[ 1] = hex[(addr->nap >>8) & 0xf];
    rc[ 3] = hex[(addr->nap >>4) & 0xf];
    rc[ 4] = hex[(addr->nap >>0) & 0xf];
   
    rc[ 6] = hex[(addr->uap >>4) & 0xf];
    rc[ 7] = hex[(addr->uap >>0) & 0xf];

    rc[ 9] = hex[(addr->lap >> 24) & 0xf];
    rc = hex[(addr->lap >> 16) & 0xf];
    rc = hex[(addr->lap >> 12) & 0xf];
    rc = hex[(addr->lap >>8) & 0xf];
    rc = hex[(addr->lap >>4) & 0xf];
    rc = hex[(addr->lap >>0) & 0xf];

    rc = rc = rc = rc = rc = ':';
    rc = 0;

    return rc;
}

static void parse_eir(const uint8 *eir_data, uint8 *endp)
{
    const char *footer[] = { "...", "" };
    const uint8 *p;
    uint16 i;

    for (p = eir_data; p < endp && p; p += 1 + p)
    {
      switch (p)
      {
      case EIR_NAME_PART:
      case EIR_NAME:
            printf("    EIR name       ");
            for (i = 1; i < p; i++)
                printf("%c", p);
            printf("%s\n", footer - EIR_NAME_PART]);
            break;
            
      case EIR_TXPOWER:
            printf("    EIR TX power   %d\n", p);
            break;
            
      default:
            printf("    Unhandled EIR data type %x\n", p);
            break;
      }
    }
}

static void app_handler(Task task, MessageId id, Message message)
{
    switch (id)
    {
    case APP_INQUIRE:
      ConnectionInquire(task, 0x9e8b33, 10, 8, 0);
      break;
   
    case CL_INIT_CFM:
      if (((CL_INIT_CFM_T*)message)->status != success)
            Panic();
      /* set inquiry mode to Inquiry with EIR */
      ConnectionWriteInquiryMode(task, inquiry_mode_eir);
      break;

    case CL_DM_INQUIRE_RESULT:
    {
      CL_DM_INQUIRE_RESULT_T *inq = (CL_DM_INQUIRE_RESULT_T*)message;

      switch (inq->status)
      {
      case inquiry_status_ready:
            /* inquiry completed, start new round after 1 second */
            MessageSendLater(task, APP_INQUIRE, NULL, 1000);
            break;

      case inquiry_status_result:
            printf("%s, RSSI %d\n", bd_format(&inq->bd_addr), inq->rssi);
            /* Extended Inquiry Response data available, print it */
            if (inq->size_eir_data)
                parse_eir(inq->eir_data, inq->eir_data + inq->size_eir_data);
            break;
      } /* switch (inq->status) */
      break;
    }
   
    case CL_DM_WRITE_INQUIRY_MODE_CFM:
      if (((CL_DM_WRITE_INQUIRY_MODE_CFM_T*)message)->status != success)
            Panic();
      /* Send internal message to start an inquiry */
      MessageSend(task, APP_INQUIRE, NULL);
      break;
      
    default:
      DEBUG(printf("Unhandled message 0x%x\n", id));
    }
}

int main(void)
{
    /* Setup application task */
    task.handler = app_handler;

    /* Initialise Connection handler */
    ConnectionInit(&task);
   
    MessageLoop();

    return 0;
}

/* End-of-File */

legendflying 发表于 2014-5-29 13:51:16

供参考
:):):):)

tiger-gz 发表于 2014-5-29 14:35:42

OK,谢谢。:)

lefish 发表于 2015-1-12 11:50:58

非常感谢五楼

lefish 发表于 2015-1-14 11:51:36

(ADK3.0 CSR8670)但是我跟踪得到 size_eir_data 为 0,eir_data【】也为空,为什么?

lefish 发表于 2015-1-16 15:45:49

问高手得到了答案
调用函数: ConnectionReadRemoteName
页: [1]
查看完整版本: 如何获得远端设备名称?