CH579-BLE
Posted kingboy100
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CH579-BLE相关的知识,希望对你有一定的参考价值。
Peripheral
EVTEXAMBLEPeripheralProfileincludegattprofile.h
1 gattprofile.h //重要 因为只读 需要重新生成一次 2 3 #define SIMPLEPROFILE_CHAR1_LEN 10 4 #define SIMPLEPROFILE_CHAR2_LEN 10 5 #define SIMPLEPROFILE_CHAR3_LEN 10 6 #define SIMPLEPROFILE_CHAR4_LEN 10
EVTEXAMBLEPeripheralProfilegattprofile.c
1 // Simple Profile Characteristic 1 Properties 2 static uint8 simpleProfileChar1Props = GATT_PROP_READ | GATT_PROP_WRITE; //支持读写 3 4 // Characteristic 1 Value 5 static uint8 simpleProfileChar1[SIMPLEPROFILE_CHAR1_LEN] = { 0 }; //初始化 6 7 // Simple Profile Characteristic 1 User Description 8 static uint8 simpleProfileChar1UserDesp[] = "Characteristic 1 "; //描述 9 10 11 12 // Simple Profile Characteristic 4 Properties 13 static uint8 simpleProfileChar4Props = GATT_PROP_NOTIFY; 14 15 //安卓点击接收 16 static bStatus_t simpleProfile_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr, 17 uint8 *pValue, uint16 *pLen, uint16 offset, uint16 maxLen,uint8 method ) 18 ... 19 if ( pAttr->type.len == ATT_BT_UUID_SIZE ) 20 { 21 // 16-bit UUID 22 uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]); 23 switch ( uuid ) 24 { 25 case SIMPLEPROFILE_CHAR1_UUID: //根据UUID 26 *pLen = SIMPLEPROFILE_CHAR1_LEN; 27 PRINT("simpleProfile_ReadAttrCB 1 len=%d "); 28 pAttr->pValue[0]=‘A‘; //填入要发送的数据 29 pAttr->pValue[1]=‘B‘; 30 pAttr->pValue[2]=‘C‘; 31 pAttr->pValue[3]=‘D‘; 32 tmos_memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR1_LEN ); //发送函数 33 break; 34 35 //安卓写入函数 36 static bStatus_t simpleProfile_WriteAttrCB( uint16 connHandle, gattAttribute_t *pAttr, 37 uint8 *pValue, uint16 len, uint16 offset,uint8 method ) 38 39 if ( pAttr->type.len == ATT_BT_UUID_SIZE ) 40 { 41 // 16-bit UUID 42 uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]); 43 switch ( uuid ) 44 { 45 case SIMPLEPROFILE_CHAR1_UUID: 46 //Validate the value 47 // Make sure it‘s not a blob oper 48 if ( offset == 0 ) 49 { 50 if ( len > SIMPLEPROFILE_CHAR1_LEN ) 51 { 52 status = ATT_ERR_INVALID_VALUE_SIZE; 53 } 54 } 55 else 56 { 57 status = ATT_ERR_ATTR_NOT_LONG; 58 } 59 60 //Write the value 61 if ( status == SUCCESS ) 62 { 63 64 PRINT("simpleProfile_WriteAttrCB 1=%c,%c,%c,%c,%c,%c ",pValue[0],pValue[1],pValue[2],pValue[3],pValue[4],pValue[5]);//显示安卓发来的数据 65 tmos_memcpy( pAttr->pValue, pValue, SIMPLEPROFILE_CHAR1_LEN ); 66 notifyApp = SIMPLEPROFILE_CHAR1; 67 } 68 break; 69
以上是关于CH579-BLE的主要内容,如果未能解决你的问题,请参考以下文章