FileName |
Description |
|---|---|
driver_adapt.h |
南向发现连接适配接口。 |
Method |
|---|
int (*Init)(void* ctx, const char* ifName) Ble适配:用于Ble初始化,开启蓝牙,保证扫描和广播接口能顺利调用;需要启动GATT服务。Wi-Fi适配:用于Wi-Fi初始化,保证Wi-Fi打开;Driver的初始化动作可以放在该函数中,确保该函数执行完成后,其他驱动接口可用。 |
Parameters
Name |
Description |
|---|---|
ctx |
通配各设备参数差异——预留。 |
ifName |
Ble适配:不需要使用该参数——预留。Wi-Fi适配:不需要使用该参数——预留。 |
Return
Type |
Description |
|---|---|
int32_t |
0:成功,<0失败。 |
Method |
|---|
int (*Deinit)(void* priv) BLE适配:去底层初始化,没有其他进程使用蓝牙时可以关闭蓝牙等操作;关闭GATT服务。Wi-Fi适配:去底层初始化,完成资源释放,移除GO,若无其他进程使用Wi-Fi可以关闭Wi-Fi。 |
Parameters
Name |
Description |
|---|---|
priv |
通配各设备参数差异——预留。 |
Return
Type |
Description |
|---|---|
int32_t |
0:成功,<0失败。 |
Method |
|---|
int (*SetParam)(SetParamsType paramType, void* priv) BLE适配:暂未使用——预留。Wi-Fi适配:驱动参数设置函数,在Init 执行完成之后,将配置参数进行一次性传递。将配置参数如 ip等传入南向接口,南向接口获取到参数后完成参数配置。 |
Parameters
Name |
Description |
|---|---|
paramType |
BLE适配:参数类型——预留Wi-Fi适配:参数类型,为枚举类型,详见SetParamsType结构体。 |
priv |
设置数据的结构体指针, 采用void *通配不同设备,设置的数据结构体差异。 |
Return
Type |
Description |
|---|---|
int32_t |
0:成功,<0失败。 |
Method |
|---|
int (*GetParam)(GetParamsType paramType, void* result) BLE适配:Ble参数获取函数,通过该接口获取Ble设备名称。Wi-Fi适配:WiFi参数获取函数,通过该接口获取本地网卡MAC地址和Wi-Fi能力。 |
Parameters
Name |
Description |
|---|---|
paramType |
参数类型,为枚举类型,详见GetParamsType结构体。 |
result |
获取数据结果的结构体指针, 采用void通配不同设备数据结构体差异。 |
Return
Type |
Description |
|---|---|
int32_t |
0:成功,<0失败。 |
Method |
|---|
int (*Connect)(void* channelInfo) BLE适配:由手机侧发起连接,当前场景不需要适配。Wi-Fi适配:由手机侧发起连接,当前场景不需要适配。 |
Parameters
Name |
Description |
|---|---|
channelInfo |
通道相关参数, 采用void通配各设备参数差异。 |
Return
Type |
Description |
|---|---|
int32_t |
0:成功,<0失败。 |
Method |
|---|
int (*Disconnect)( const void* channelInfo) BLE适配:断开GATT服务。Wi-Fi适配:用于断开建立P2P连接。 |
Parameters
Name |
Description |
|---|---|
channelInfo |
通道相关参数, 通配各设备参数差异。 |
Return
Type |
Description |
|---|---|
int32_t |
0:成功,<0失败。 |
Method |
|---|
int (*StartAdv)(void *priv) BLE适配:开启Ble广播,设置广播minInterval、maxInterval、和广播通道。Wi-Fi适配:不需要适配。 |
Parameters
Name |
Description |
|---|---|
priv |
BLE适配:参考BleAdvParams结构体,包括:minInterval、maxInterval、advChannel。当前minInterval、maxInterval,设定默认值0x0040是为了保证发现效率,可根据南向接口调试情况修改,自行保证发现效率。advChannel默认为37、38、39广播通道。 |
Return
Type |
Description |
|---|---|
int32_t |
0:成功,<0失败。 |
Method |
|---|
int (*StopAdv )(void *priv) BLE适配:停止Ble广播。Wi-Fi适配:不需要适配。 |
Parameters
Name |
Description |
|---|---|
priv |
通配各设备参数差异——预留。 |
Return
Type |
Description |
|---|---|
int32_t |
0:成功,<0失败。 |
Method |
|---|
int (*SetAdvData) (void *priv) BLE适配:设置广播内容。Wi-Fi适配:不需要适配。 |
Parameters
Name |
Description |
|---|---|
priv |
BLE适配:广播数据结构,适配参考BleAdvData结构体。 |
Return
Type |
Description |
|---|---|
int32_t |
0:成功,<0失败。 |
Method |
|---|
int (*StartScan)(void *priv) BLE适配:启动扫描。Wi-Fi适配:不需要适配。 |
Parameters
Name |
Description |
|---|---|
priv |
BLE适配:通配各设备参数差异——预留。 |
Return
Type |
Description |
|---|---|
int32_t |
0:成功,<0失败。 |
Method |
|---|
int (*StopScan) (void *priv) BLE适配:停止扫描。Wi-Fi适配:不需要适配。 |
Parameters
Name |
Description |
|---|---|
priv |
BLE适配:通配各设备参数差异——预留。 |
Return
Type |
Description |
|---|---|
int32_t |
0:成功,<0失败。 |
Method |
|---|
int (*NotifyData)(void *priv) BLE适配:服务端向客户端发送数据。Wi-Fi适配:不需要适配。 |
Parameters
Name |
Description |
|---|---|
priv |
通配各设备参数差异——预留。 |
Return
Type |
Description |
|---|---|
int32_t |
0:成功,<0失败。 |
Method |
|---|
int (*SendData) (void *priv) BLE适配:客户端向服务端发送数据,此场景设备为服务端,不需要适配。Wi-Fi适配:不需要适配。 |
Parameters
Name |
Description |
|---|---|
priv |
通配各设备参数差异——预留。 |
Return
Type |
Description |
|---|---|
int32_t |
0:成功,<0失败。 |
Method |
|---|
int (*CreateWifiChannel)(void* context, void* wifiData) BLE适配:不需要适配。Wi-Fi适配:根据本地化IP创建GO。 |
Parameters
Name |
Description |
|---|---|
priv |
通配各设备参数差异——预留。 |
wifiData |
Wi-Fi适配:这里传入是信道频率frequency的指针(int *)。GO的名称(ssid)、密码(key)、mac地址由设备侧生成上报。ssid字符串长度不超过19;key长度不超过19。 |
Return
Type |
Description |
|---|---|
int32_t |
0:成功,<0失败。 |
Method |
|---|
int (*RegisterChannelCallback)(ChannelCallback* channelCallback) BLE适配:注册回调函数,包括Ble扫描结果回调,数据接收回调,状态上报回调。 Wi-Fi适配:注册回调函数,不需要注册扫描结果回调。 |
Parameters
Name |
Description |
|---|---|
channelCallback |
回调函数包括:ScanCallback、ReceiveData、ChannelStateChange,详见ChannelCallback结构体。 |
Return
Type |
Description |
|---|---|
int32_t |
0:成功,<0失败。 |
Public Structres
通道类型的结构体。
Name |
Description |
|---|---|
int channelNum |
设备支持信道的个数。 |
int channelList[100] |
设备支持的信道列表。 |
设备Wi-Fi能力结构体。
Name |
Description |
|---|---|
int isSupportGO |
设备是否支持做GO (1支持 0 不支持)。 |
int isSupportGC |
设备是否支持做GC (1支持 0 不支持)。 |
int isSupportAband |
设备是否支持做5G (1支持 0 不支持)。 |
int isSupportGband |
设备是否支持做2.4G (1支持 0 不支持)。 |
int isSupportRSDB |
设备是否支持做RSDB (1支持 0 不支持)。 |
int currentFreq |
设备当前的频率。 |
char selfGcMac[18] |
设备MAC地址,格式为xx:xx:xx:xx:xx:xx字符串。 |
char selfBssid[18] |
设备BSSID,格式为xx:xx:xx:xx:xx:xx字符串。 |
Channel channelData |
设备支持的5G信道。 |
char countryCode[16] |
设备国家码。 |
int isSupportGO |
设备是否支持做GO (1支持 0 不支持)。 |
int isSupportGC |
设备是否支持做GC (1支持 0 不支持)。 |
int isSupportAband |
设备是否支持做5G (1支持 0 不支持)。 |
通道类型的结构体。
Name |
Description |
|---|---|
unsigned char evtType |
广播上报事件。 |
unsigned char addrType |
设备地址类型,public或random。 |
unsigned char addr [MAC_ADDR_LEN] |
设备MAC地址,格式为:unsigned char型数组unsigned char bdAddr[6] = {0x34, 0xF3, 0x9A, 0xF5, 0x1F, 0xC1}。 |
unsigned char len |
数据的长度,最大31。 |
unsigned char data [BLE_ADV_MAX_LEN] |
广播或扫描回复数据。 |
char rssi |
信号强度:-127 ≤ N ≤ +20 dBm。 |
RegisterChannelCallback注册设备回调方法,Ble、Wi-Fi与南向的事件消息都是通过回调的方式实现的。
Name |
Description |
|---|---|
void (*ChannelStateChange)(ChannelType channelType, EventType eventType, const void data, int dataLen) |
状态改变,上报事件,见枚举EventType。 |
void (*ScanCallback)(ChannelType channelType, const BleScanResult result) |
BLE扫描结果上报,详见BleScanResult。 |
void (*ReceiveData)(ChannelType channelType, const void channelParam, const unsigned char* data, int dataLen) |
通道收到数据上报。 |