如何在低功耗蓝牙中向服务添加特征

如何解决如何在低功耗蓝牙中向服务添加特征

似乎我无法为Bluetooth Low Energy中的服务添加新特性。我基于简单外围设备示例进行编程,该示例具有5个特征。我想根据在simple_gatt_profile.c和.h中如何初始化其他5个特征来添加第6个和第7个特征。当我这样做时,代码不再起作用,在main中调用bios_start()之后,它似乎挂在了某个地方。任务不被调用。因此,我创建特征的方式一定存在问题。这是一些代码: 从simple_gatt_profile.h:

// Profile Parameters
#define SIMPLEPROFILE_CHAR1                    0  // RW uint8 - Profile Characteristic 1 value

#define SIMPLEPROFILE_CHAR2                    1  // RW uint8 - Profile Characteristic 2 value

#define SIMPLEPROFILE_CHAR3                    2  // RW uint8 - Profile Characteristic 3 value

#define SIMPLEPROFILE_CHAR4                    3  // RW uint8 - Profile Characteristic 4 value

#define SIMPLEPROFILE_CHAR5                    4  // RW uint8 - Profile Characteristic 5 value

#define SIMPLEPROFILE_CHAR6                    5  // RW uint8 - Profile Characteristic 6 value

#define SIMPLEPROFILE_CHAR7                    6  // RW uint8 - Profile Characteristic 7 value

// Simple Profile Service UUID
#define SIMPLEPROFILE_SERV_UUID               0xFFF0

// Key Pressed UUID
#define SIMPLEPROFILE_CHAR1_UUID            0xFFF1
#define SIMPLEPROFILE_CHAR2_UUID            0xFFF2
#define SIMPLEPROFILE_CHAR3_UUID            0xFFF3
#define SIMPLEPROFILE_CHAR4_UUID            0xFFF4
#define SIMPLEPROFILE_CHAR5_UUID            0xFFF5
#define SIMPLEPROFILE_CHAR6_UUID            0xFFF6
#define SIMPLEPROFILE_CHAR7_UUID            0xFFF7

// Simple Keys Profile Services bit fields
#define SIMPLEPROFILE_SERVICE               0x00000001

// Length of Characteristics in bytes
#define SIMPLEPROFILE_CHAR1_LEN           20
#define SIMPLEPROFILE_CHAR2_LEN           20
#define SIMPLEPROFILE_CHAR3_LEN           20
#define SIMPLEPROFILE_CHAR4_LEN           20
#define SIMPLEPROFILE_CHAR5_LEN           20
#define SIMPLEPROFILE_CHAR6_LEN           20
#define SIMPLEPROFILE_CHAR7_LEN           14

从simple_gatt_profile.c中获取:

// Simple GATT Profile Service UUID: 0xFFF0
CONST uint8 simpleProfileServUUID[ATT_BT_UUID_SIZE] =
{
  LO_UINT16(SIMPLEPROFILE_SERV_UUID),HI_UINT16(SIMPLEPROFILE_SERV_UUID)
};

// Characteristic 1 UUID: 0xFFF1
CONST uint8 simpleProfilechar1UUID[ATT_BT_UUID_SIZE] =
{
  LO_UINT16(SIMPLEPROFILE_CHAR1_UUID),HI_UINT16(SIMPLEPROFILE_CHAR1_UUID)
};

// Characteristic 2 UUID: 0xFFF2
CONST uint8 simpleProfilechar2UUID[ATT_BT_UUID_SIZE] =
{
  LO_UINT16(SIMPLEPROFILE_CHAR2_UUID),HI_UINT16(SIMPLEPROFILE_CHAR2_UUID)
};

// Characteristic 3 UUID: 0xFFF3
CONST uint8 simpleProfilechar3UUID[ATT_BT_UUID_SIZE] =
{
  LO_UINT16(SIMPLEPROFILE_CHAR3_UUID),HI_UINT16(SIMPLEPROFILE_CHAR3_UUID)
};

// Characteristic 4 UUID: 0xFFF4
CONST uint8 simpleProfilechar4UUID[ATT_BT_UUID_SIZE] =
{
  LO_UINT16(SIMPLEPROFILE_CHAR4_UUID),HI_UINT16(SIMPLEPROFILE_CHAR4_UUID)
};

// Characteristic 5 UUID: 0xFFF5
CONST uint8 simpleProfilechar5UUID[ATT_BT_UUID_SIZE] =
{
  LO_UINT16(SIMPLEPROFILE_CHAR5_UUID),HI_UINT16(SIMPLEPROFILE_CHAR5_UUID)
};

// Characteristic 6 UUID: 0xFFF6
CONST uint8 simpleProfilechar6UUID[ATT_BT_UUID_SIZE] =
{
  LO_UINT16(SIMPLEPROFILE_CHAR6_UUID),HI_UINT16(SIMPLEPROFILE_CHAR6_UUID)
};

// Characteristic 7 UUID: 0xFFF7
CONST uint8 simpleProfilechar7UUID[ATT_BT_UUID_SIZE] =
{
  LO_UINT16(SIMPLEPROFILE_CHAR7_UUID),HI_UINT16(SIMPLEPROFILE_CHAR7_UUID)
};
/*********************************************************************
 * EXTERNAL VARIABLES
 */

/*********************************************************************
 * EXTERNAL FUNCTIONS
 */

/*********************************************************************
 * LOCAL VARIABLES
 */

static simpleProfileCBs_t *simpleProfile_AppCBs = NULL;

/*********************************************************************
 * Profile Attributes - variables
 */

// Simple Profile Service attribute
static CONST gattAttrType_t simpleProfileService = { ATT_BT_UUID_SIZE,simpleProfileServUUID };


// Simple Profile Characteristic 1 Properties
static uint8 simpleProfileChar1Props = GATT_PROP_READ | GATT_PROP_WRITE| GATT_PROP_NOTIFY;

// Characteristic 1 Value
static uint8 simpleProfileChar1[SIMPLEPROFILE_CHAR1_LEN] = { 0,0 };

// Simple Profile Characteristic 1 User Description
static uint8 simpleProfileChar1UserDesp[8] = "Amsel 1";


// Simple Profile Characteristic 2 Properties
static uint8 simpleProfileChar2Props = GATT_PROP_READ | GATT_PROP_WRITE| GATT_PROP_NOTIFY;

// Characteristic 2 Value
static uint8 simpleProfileChar2[SIMPLEPROFILE_CHAR2_LEN] = { 0,0 };

// Simple Profile Characteristic 2 User Description
static uint8 simpleProfileChar2UserDesp[8] = "Amsel 2";


// Simple Profile Characteristic 3 Properties
static uint8 simpleProfileChar3Props = GATT_PROP_READ | GATT_PROP_WRITE| GATT_PROP_NOTIFY;

// Characteristic 3 Value
static uint8 simpleProfileChar3[SIMPLEPROFILE_CHAR3_LEN] = { 0,0 };

// Simple Profile Characteristic 3 User Description
static uint8 simpleProfileChar3UserDesp[8] = "Amsel 3";


// Simple Profile Characteristic 4 Properties
static uint8 simpleProfileChar4Props = GATT_PROP_READ | GATT_PROP_WRITE | GATT_PROP_NOTIFY;

// Characteristic 4 Value
static uint8 simpleProfileChar4[SIMPLEPROFILE_CHAR4_LEN] = { 0,0 };

// Simple Profile Characteristic 4 User Description
static uint8 simpleProfileChar4UserDesp[16] = "Amsel 4,Notify";

// Simple Profile Characteristic 5 Properties
static uint8 simpleProfileChar5Props = GATT_PROP_READ | GATT_PROP_WRITE | GATT_PROP_NOTIFY;

// Characteristic 5 Value
static uint8 simpleProfileChar5[SIMPLEPROFILE_CHAR5_LEN] = { 0,0 };

// Simple Profile Characteristic 5 User Description
static uint8 simpleProfileChar5UserDesp[8] = "Dialog1";

// Simple Profile Characteristic 6 Properties
static uint8 simpleProfileChar6Props = GATT_PROP_READ | GATT_PROP_WRITE | GATT_PROP_NOTIFY;

// Characteristic 6 Value
static uint8 simpleProfileChar6[SIMPLEPROFILE_CHAR6_LEN] = { 0,0 };

// Simple Profile Characteristic 6 User Description
static uint8 simpleProfileChar6UserDesp[8] = "Dialog2";

// Simple Profile Characteristic 7 Properties
static uint8 simpleProfileChar7Props = GATT_PROP_READ | GATT_PROP_WRITE | GATT_PROP_NOTIFY;

// Characteristic 7 Value
static uint8 simpleProfileChar7[SIMPLEPROFILE_CHAR7_LEN] = { 0,0 };

// Simple Profile Characteristic 7 User Description
static uint8 simpleProfileChar7UserDesp[8] = "Dialog3";

// Simple Profile Characteristic 4 Configuration Each client has its own
// instantiation of the Client Characteristic Configuration. Reads of the
// Client Characteristic Configuration only shows the configuration for
// that client and writes only affect the configuration of that client.
static gattCharCfg_t *simpleProfileChar1Config;
static gattCharCfg_t *simpleProfileChar2Config;
static gattCharCfg_t *simpleProfileChar3Config;
static gattCharCfg_t *simpleProfileChar4Config;
static gattCharCfg_t *simpleProfileChar5Config;
static gattCharCfg_t *simpleProfileChar6Config;
static gattCharCfg_t *simpleProfileChar7Config;

/*********************************************************************
 * Profile Attributes - Table
 */

static gattAttribute_t simpleProfileAttrTbl[SERVAPP_NUM_ATTR_SUPPORTED] =
{
  // Simple Profile Service
  {
    { ATT_BT_UUID_SIZE,primaryServiceUUID },/* type */
    GATT_PERMIT_READ,/* permissions */
    0,/* handle */
    (uint8 *)&simpleProfileService            /* pValue */
  },// Characteristic 1 Declaration
  {
    { ATT_BT_UUID_SIZE,characterUUID },GATT_PERMIT_READ,&simpleProfileChar1Props
  },// Characteristic Value 1
    {
      { ATT_BT_UUID_SIZE,simpleProfilechar1UUID },GATT_PERMIT_READ | GATT_PERMIT_WRITE,(uint8 *)&simpleProfileChar1
    },// Characteristic 1 configuration
    {
      { ATT_BT_UUID_SIZE,clientCharCfgUUID },(uint8 *)&simpleProfileChar1Config
    },// Characteristic 1 User Description
    {
      { ATT_BT_UUID_SIZE,charUserDescUUID },simpleProfileChar1UserDesp
    },// Characteristic 2 Declaration
    {
      { ATT_BT_UUID_SIZE,&simpleProfileChar2Props
    },// Characteristic Value 2
      {
        { ATT_BT_UUID_SIZE,simpleProfilechar2UUID },(uint8 *)&simpleProfileChar2
      },// Characteristic 2 configuration
      {
        { ATT_BT_UUID_SIZE,(uint8 *)&simpleProfileChar2Config
      },// Characteristic 2 User Description
      {
        { ATT_BT_UUID_SIZE,simpleProfileChar2UserDesp
      },// Characteristic 3 Declaration
    {
      { ATT_BT_UUID_SIZE,&simpleProfileChar3Props
    },// Characteristic Value 3
      {
        { ATT_BT_UUID_SIZE,simpleProfilechar3UUID },(uint8 *)&simpleProfileChar3
      },// Characteristic 3 configuration
      {
        { ATT_BT_UUID_SIZE,(uint8 *)&simpleProfileChar3Config
      },// Characteristic 3 User Description
      {
        { ATT_BT_UUID_SIZE,simpleProfileChar3UserDesp
      },// Characteristic 4 Declaration
    {
      { ATT_BT_UUID_SIZE,GATT_PERMIT_READ| GATT_PERMIT_WRITE,&simpleProfileChar4Props
    },// Characteristic Value 4
      {
        { ATT_BT_UUID_SIZE,simpleProfilechar4UUID },(uint8 *)&simpleProfileChar4
      },// Characteristic 4 configuration
      {
        { ATT_BT_UUID_SIZE,(uint8 *)&simpleProfileChar4Config
      },// Characteristic 4 User Description
      {
        { ATT_BT_UUID_SIZE,simpleProfileChar4UserDesp
      },// Characteristic 5 Declaration
      {
        { ATT_BT_UUID_SIZE,&simpleProfileChar5Props
      },// Characteristic Value 5
        {
          { ATT_BT_UUID_SIZE,simpleProfilechar5UUID },(uint8 *)&simpleProfileChar5
        },// Characteristic 5 configuration
        {
          { ATT_BT_UUID_SIZE,(uint8 *)&simpleProfileChar5Config
        },// Characteristic 5 User Description
        {
          { ATT_BT_UUID_SIZE,simpleProfileChar5UserDesp
        },// Characteristic 6 Declaration
        {
          { ATT_BT_UUID_SIZE,&simpleProfileChar6Props
        },// Characteristic Value 6
          {
            { ATT_BT_UUID_SIZE,(uint8 *)&simpleProfileChar6
          },// Characteristic 5 configuration
          {
            { ATT_BT_UUID_SIZE,(uint8 *)&simpleProfileChar6Config
          },// Characteristic 6 User Description
          {
            { ATT_BT_UUID_SIZE,simpleProfileChar6UserDesp
          },// Characteristic 7 Declaration
          {
            { ATT_BT_UUID_SIZE,&simpleProfileChar7Props
          },// Characteristic Value 7
            {
              { ATT_BT_UUID_SIZE,simpleProfilechar7UUID },(uint8 *)&simpleProfileChar7
            },// Characteristic 7 configuration
            {
              { ATT_BT_UUID_SIZE,(uint8 *)&simpleProfileChar7Config
            },// Characteristic 7 User Description
            {
              { ATT_BT_UUID_SIZE,simpleProfileChar7UserDesp
            },};
bStatus_t SimpleProfile_AddService( uint32 services )
{
  uint8 status;

  // Allocate Client Characteristic Configuration table
  simpleProfileChar1Config = (gattCharCfg_t *)ICall_malloc( sizeof(gattCharCfg_t) *
                                                              linkDBNumConns );
    if ( simpleProfileChar1Config == NULL )
    {
      return ( bleMemAllocError );
    }

    // Initialize Client Characteristic Configuration attributes
    GATTServApp_InitCharCfg( INVALID_CONNHANDLE,simpleProfileChar1Config );

    simpleProfileChar2Config = (gattCharCfg_t *)ICall_malloc( sizeof(gattCharCfg_t) *
                                                                 linkDBNumConns );
       if ( simpleProfileChar2Config == NULL )
       {
         return ( bleMemAllocError );
       }

       // Initialize Client Characteristic Configuration attributes
       GATTServApp_InitCharCfg( INVALID_CONNHANDLE,simpleProfileChar2Config );

   simpleProfileChar3Config = (gattCharCfg_t *)ICall_malloc( sizeof(gattCharCfg_t) *
                                                                linkDBNumConns );
      if ( simpleProfileChar3Config == NULL )
      {
        return ( bleMemAllocError );
      }

      // Initialize Client Characteristic Configuration attributes
      GATTServApp_InitCharCfg( INVALID_CONNHANDLE,simpleProfileChar3Config );

  simpleProfileChar4Config = (gattCharCfg_t *)ICall_malloc( sizeof(gattCharCfg_t) *
                                                            linkDBNumConns );
  if ( simpleProfileChar4Config == NULL )
  {
    return ( bleMemAllocError );
  }

  // Initialize Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE,simpleProfileChar4Config );

  simpleProfileChar5Config = (gattCharCfg_t *)ICall_malloc( sizeof(gattCharCfg_t) *
                                                            linkDBNumConns );
  if ( simpleProfileChar5Config == NULL )
  {
    return ( bleMemAllocError );
  }

  // Initialize Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE,simpleProfileChar5Config );

  simpleProfileChar6Config = (gattCharCfg_t *)ICall_malloc( sizeof(gattCharCfg_t) *
                                                            linkDBNumConns );
  if ( simpleProfileChar6Config == NULL )
  {
    return ( bleMemAllocError );
  }
  // Initialize Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE,simpleProfileChar6Config );

  // Initialize Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE,simpleProfileChar7Config );

  simpleProfileChar7Config = (gattCharCfg_t *)ICall_malloc( sizeof(gattCharCfg_t) *
                                                            linkDBNumConns );
  if ( simpleProfileChar7Config == NULL )
  {
    return ( bleMemAllocError );
  }

  // Initialize Client Characteristic Configuration attributes
  GATTServApp_InitCharCfg( INVALID_CONNHANDLE,simpleProfileChar7Config );
  if ( services & SIMPLEPROFILE_SERVICE )
  {
    // Register GATT attribute list and CBs with GATT Server App
    status = GATTServApp_RegisterService( simpleProfileAttrTbl,GATT_NUM_ATTRS( simpleProfileAttrTbl ),GATT_MAX_ENCRYPT_KEY_SIZE,&simpleProfileCBs );
  }
  else
  {
    status = SUCCESS;
  }

  return ( status );
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 <select id="xxx"> SELECT di.id, di.name, di.work_type, di.updated... <where> <if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 <property name="dynamic.classpath" value="tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-