一 前言
这里的代码是在原厂基础上修改了不少。虽然代码复杂了不少,但是逻辑也清晰了不少。
二 广播协议
想要熟悉并修改ble的广播协议和内容,请查阅结构体:
static const attribute_t my_Attributes[]
比如,假如要上报电压值,可以在里面添加
{0,ATT_PERMISSIONS_READ,2,sizeof(my_batCharVal),(u8*)(&my_characterUUID), (u8*)(my_batCharVal), 0}, //prop
该广播信息的填写如下所示:
//// Battery attribute values static const u8 my_batCharVal[5] = { CHAR_PROP_READ | CHAR_PROP_NOTIFY, U16_LO(BATT_LEVEL_INPUT_DP_H), U16_HI(BATT_LEVEL_INPUT_DP_H), U16_LO(CHARACTERISTIC_UUID_BATTERY_LEVEL), U16_HI(CHARACTERISTIC_UUID_BATTERY_LEVEL) };
三 连接和断开
连接成功的接口如下所示:
case APP_BLE_EVENT_CONNECTED: b_ble_connected = ON; LOG_INFO("Connected!!! ble_state:%d ",b_ble_connected); LOG_INFO("e: %d p:%d n: %d", param->e, param->p, param->n);
断开的接口如下所示:
case APP_BLE_EVENT_DISCONNECTED: b_ble_connected = OFF; b_rx_notify_enable = OFF; LOG_INFO("DisConnected Reason: 0x%02x ble_state:%d ", param->p,b_ble_connected); att_mtu_size = DEFAULT_ATT_MTU_SIZE;
四 数据收发
数据接收的接口函数:
static int parse_xp_message(XpMessage* message, uint8_t* data, uint16_t len) { uint8_t* p = NULL; p = data; set_xp_header(message, data, &p); LOG_DEBUG("%s Info: ble received data:", __func__);
数据发送的接口函数:
app_ble_send_data_by_notification(buff, length);
五 软硬件链接:
作者:虚生 出处:https://www.cnblogs.com/dylancao/ 以音频和传感器算法为核心的智能可穿戴产品解决方案提供商 ,提供可穿戴智能软硬件解决方案的设计,开发和咨询服务。 勾搭热线:邮箱:1173496664@qq.com weixin:18019245820 市场技术对接群:347609188 |