PI蓝牙协议栈增加过滤

go的代码 一直都是直接scan 还有很多细节 比如主动扫描 被动烧苗等过滤

结论是

func (a *Adapter) Scan(callback func(*Adapter, ScanResult)) error {
    if a.cancelChan != nil {
        return errScanning
    }

    // Channel that will be closed when the scan is stopped.
    // Detecting whether the scan is stopped can be done by doing a non-blocking
    // read from it. If it succeeds, the scan is stopped.
    cancelChan := make(chan struct{})
    a.cancelChan = cancelChan

    // This appears to be necessary to receive any BLE discovery results at all.
    defer a.adapter.SetDiscoveryFilter(nil)
    err := a.adapter.SetDiscoveryFilter(map[string]interface{}{
        "Transport": "le",
        "RSSI":      int16(-60),
        "UUIDs":     []string{ServiceUUIDNordicUART.String()},
        //"Pathloss":      30,
        "DuplicateData": false,
        "Discoverable":  true,
    })

具体分析如下

D:\m_izar_rpi_gw\bluetooth_mcube\gap_linux.go过滤 和 简化
主动扫描https://stackoverflow.com/questions/50675797/bluez-d-bus-c-application-ble
最下面有2个连接 不合适我们defer a.adapter.SetDiscoveryFilter(nil)err := a.adapter.SetDiscoveryFilter(map[string]interface{}{"Transport": "le",})本地同步拉代码
git clone https://github.com/muka/go-bluetooth.git查找函数
SetDiscoveryFilterC:\Users\Koson.Gong\Pictures\go-bluetooth\bluez\profile\adapter\gen_Adapter1.go
func (a *Adapter1) SetDiscoveryFilter(filter map[string]interface{}) error {return a.client.Call("SetDiscoveryFilter", 0, filter).Store()
}https://www.linumiz.com/bluetooth-setdiscoveryfilter-for-filtered-scanning/
这里是源码只需要我们的代码+MUKA的代码就可以了
全部是GO基础知识 数据结构的做法func (a *Adapter) Scan(callback func(*Adapter, ScanResult)) error {if a.cancelChan != nil {return errScanning}// Channel that will be closed when the scan is stopped.// Detecting whether the scan is stopped can be done by doing a non-blocking// read from it. If it succeeds, the scan is stopped.cancelChan := make(chan struct{})a.cancelChan = cancelChan// This appears to be necessary to receive any BLE discovery results at all.defer a.adapter.SetDiscoveryFilter(nil)err := a.adapter.SetDiscoveryFilter(map[string]interface{}{"Transport": "le","RSSI":      int16(-60),"UUIDs":     []string{ServiceUUIDNordicUART.String()},//"Pathloss":      30,"DuplicateData": false,"Discoverable":  true,})必须体现RSSI的数据类型 必须写数组测试OK


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部