- ble基本组成 att是原始数据键值对,gatt是给原始数据加以修饰device service characteristic
gap 管理设备名字 是否可见 是否可链接 广播管理
|
CH592 Device -gatt
│
├── 温湿度 Service -gatt
│ │
│ ├── 温度 Characteristic Temp_Read/NotifyCallback()
│ │ ├── Read
│ │ └── Notify
│ │
│ └── 湿度 Characteristic -gatt
│ ├── Read -gatt
│ └── Notify -gatt
│
└── OTA Service
│
└── OTA Characteristic
├── Write
└── Notify
实际对应
↓
ATT Table
Handle1
Handle2
Handle3
Handle4
...
- 代码解析
cpp
// Simple GATT Profile Callbacks
static OTAProfileCBs_t Peripheral_OTA_IAPProfileCBs = {
OTA_IAPReadDataComplete, // Charactersitic value change callback
OTA_IAPWriteData
};
OTAProfile_AddService(GATT_ALL_SERVICES);
// Register callback with OTAGATTprofile
OTAProfile_RegisterAppCBs(&Peripheral_OTA_IAPProfileCBs);
- 理解
开机
↓
OTAProfile_AddService()
创建
BLE Device
│
└── OTA Service
│
└── OTA Characteristic
↓
OTAProfile_RegisterAppCBs()
给Characteristic绑定事件回调处理
Write
↓
OTA_IAPWriteData()
Notify完成
↓
OTA_IAPReadDataComplete()
- 实际运行
手机发送数据
↓
Write
↓
OTA Characteristic
↓
OTA_IAPWriteData()
↓
Rec_OTA_IAP_DataDeal()
↓
CMD_IAP_INFO
CMD_IAP_ERASE
CMD_IAP_PROM
...
设备回数据
OTA_IAP_SendData()
↓
Notify
↓
OTA Characteristic
↓
手机
发送结束
↓
OTA_IAPReadDataComplete()