加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

BLE4.0 Client发送数据给Server

(2014-06-11 23:11:49)
标签:

it

技术文档

蓝牙4.0

教育

分类: 技术文档

Client 发送数据给Server

使用的器件:USBdongle+MiniDK + usb转串口

功能:通过串口发送数据给USBDongle,触发USBDongle发送数据给MiniDK

使用例程:SimpleBLEPeripheral与,SimpleBLECentral

SimpleBLEPeripheral中添加自定义特性值6

修改simpleGATTprofile.csimpleGATTprofile.h

添加可读写的20个字节的SIMPLEPROFILE_CHAR6

 

center中,一旦与simplePeripheral建立连接,就可获取到所有ServerUUID,并能得到相应

特性值的Handle

获取特性值Handle

bStatus_t GATT_WriteCharValue               uint16         connHandle,

attWriteReq_t *         pReq,

uint8         taskId        

                       

只有当Client端(USBDongle)知道Server端(MiniDK)相应characteristic value Handle.

并且已经连接上才能写入成功

Parameters:

connHandle         - connection to use

pReq         - pointer to request to be sent

taskId         - task to be notified of response

Returns:

SUCCESS: Request was sent successfully.

INVALIDPARAMETER: Invalid connection handle or request field.

MSG_BUFFER_NOT_AVAIL: No HCI buffer is available.

bleNotConnected: Connection is down.

blePending: A response is pending with this server.

bleMemAllocError: Memory allocation error occurred.

bleTimeout: Previous transaction timed out.

typedef struct

{

  uint16 handle;               //!< 要写入的characteristic value Handle

  uint8 len;                   //!< 写入数据的长度

  uint8 value[ATT_MTU_SIZE-3]; //!<</span>数据内容

  uint8 sig;                   //!< Authentication Signature status (not included (0), valid (1), invalid (2))

  uint8 cmd;                   //!< Command Flag(暂不知这两个参数用途)

} attWriteReq_t;

 

-----------------------------------------------------------------------------------------------------------------

     uint8 state = 0;

     uint8 ch[] = "123456789abcdef1234";   //最大20个字节。

     attWriteReq_t req;

     req.handle = 0x0035;            //特性值6handle

     req.len = 19;

     osal_memcpy(req.value,ch,19);

     req.sig = 0;

     req.cmd = 0;

     state = GATT_WriteCharValue(simpleBLEConnHandle,&req,simpleBLETaskId) ;

     if( state == SUCCESS) 

--------------------------------------------------------------------------------------------------------------------

center中通过串口控制来向从机发送数据,

由于simpleperipheral中的characteristic中的内容改变了,会触发相应的CallBack函数

simpleperipheral

static void simpleProfileChangeCB( uint8 paramID )charasteristic值改变的回调函数paramID

charasteristicuuid

通过switchparamID)查找到对应的characteristic通过

SimpleProfile_GetParameter( SIMPLEPROFILE_CHAR6, newChar );                  

就能得到所接收到的数据。不过数据最大长度只有20个字节。

  case SIMPLEPROFILE_CHAR6:

    {

      SimpleProfile_GetParameter( SIMPLEPROFILE_CHAR6, newChar );

    }

SimpleProfile_GetParameter直接将char6的内容复制给了newChar,这样就得到了center发送过来的数据了。

  case SIMPLEPROFILE_CHAR6:

      VOID osal_memcpy( value, simpleProfileChar6, SIMPLEPROFILE_CHAR6_LEN );

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有