bcsphere / bluetooth

Please support! Kindly "Star" this standard Bluetooth Smart API / SDK :) The "bcsphere/bluetooth" is a phonegap/cordova plugin. It's a Bluetooth JavaScript API from JUMA, a Bluetooth expert team. It supports both Bluetooth 4.0 GATT/Bluetooth Low Energy (BLE) interface in iOS/Android and Bluetooth 2.1 Classic Rfcomm / L2cap socket interface as Bluetooth Serial Port/SPP, as well as iBeacon!
Apache License 2.0
299 stars 12 forks source link

fixed readValue error after setNotification #25

Closed mrichie closed 10 years ago

mrichie commented 10 years ago

错误发生过程: 1、执行service1 下 char1 的 setNotifcation enable: true操作,这时ISON 为 TRUE 2、执行service2 下 char1 的 readValue 操作,didUpdateValueForCharacteristic 方法会优先走ISON为true的判断逻辑,返回setNotification的callback,此时系统就会报错 解决方法:在执行readValue的时候,强制将ISON关闭,读完数据之后再打开

TO: @lizhijumacc, @wenze0410 很早以前邮件沟通过,ios 不能同时对多个 characteristic 执行subscribe 操作,那时回调里面只会返回一个characteristic的值,现在这个问题由于urlAndCallback的加入已经解决,根本原因是cordova 执行的时候需要记住command.callbackId ,这样在发送回调结果时(commandDelegate sendPluginResult)才能将对应的结果返回给指定的函数 但是最近几次调查出来的bug,问题都出在urlAndCallback的使用上,建议这块再系统测试下,read, write, ison的控制也能够像setNotification 那样根据serviceIndex、characteristicIndex进行区分开 (lldb) po self.urlAndCallback { 10setNotification = BCBluetooth1632634; 20setNotification = BCBluetooth1632628; "connectD71A2C8D-C9E0-2517-6F26-81E8121AB2A8" = BCBluetooth1632624; disconnect = BCBluetooth1632593; getBluetoothState = BCBluetooth1632602; "getRssiD71A2C8D-C9E0-2517-6F26-81E8121AB2A8" = BCBluetooth1632911; newadvpacket = BCBluetooth1632600; oncharacteristicread = BCBluetooth1632596; oncharacteristicwrite = BCBluetooth1632597; ondescriptorread = BCBluetooth1632598; ondescriptorwrite = BCBluetooth1632599; onsubscribe = BCBluetooth1632594; onunsubscribe = BCBluetooth1632595; "perInfoCommandD71A2C8D-C9E0-2517-6F26-81E8121AB2A8" = BCBluetooth1632626; readCharacteristor = BCBluetooth1632922; write = BCBluetooth1632630;

superMushRoom commented 10 years ago

sorry 我这边按你的描述执行了但是我并没有重现到你描述的问题,你是不是可以发错误截图给我看看?

mrichie commented 10 years ago

@wenze0410 app链接硬件后,假设对service1下的char1执行subscribe操作,这个时候urlAndCallback中的ISON 就会为true,如果这个时候再对另外一个service2下的char1进行read操作,此时就会报错,错误行数 https://github.com/bcsphere/bluetooth/blob/master/src/ios/BCBluetooth.m#L1154

superMushRoom commented 10 years ago

哦 崩溃是因为 我传了空的callback给上层 之前我实在上层做了对空的过滤 只要判断callback不为空再传给上层就好 不需要用ISON去判断的

superMushRoom commented 10 years ago

已经提交更改的代码,没有merge你的代码是因为崩溃原因是传了空的callback给上层。感谢发现问题,关于urlAndCallback 我们会测试一下。感谢反馈!

mrichie commented 10 years ago

@wenze0410 我这边也测试了 https://github.com/bcsphere/bluetooth/blob/master/src/ios/BCBluetooth.m#L1152 这里加上不为空的验证,不会报错,返回结果值貌似也没错,但是有个疑问,按道理,readValue 操作之后,didUpdateValueForCharacteristic 这个delegate 里面,不是应该走 if ([self.urlAndCallback valueForKey:READCHARACTERISTIC]){ 这里面的逻辑么,为什么还是走上面ISON的逻辑

superMushRoom commented 10 years ago

因为注册过通知 并且没有停止通知 不然不会走的

------------------ 原始邮件 ------------------ 发件人: "Richie Min"notifications@github.com; 发送时间: 2014年7月21日(星期一) 上午10:03 收件人: "bcsphere/bluetooth"bluetooth@noreply.github.com; 抄送: "幽谷绮罗"1187762647@qq.com; 主题: Re: [bluetooth] fixed readValue error after setNotification (#25)

@wenze0410 我这边也测试了 https://github.com/bcsphere/bluetooth/blob/master/src/ios/BCBluetooth.m#L1152 这里加上不为空的验证,不会报错,返回结果值貌似也没错,但是有个疑问,按道理,readValue 操作之后,didUpdateValueForCharacteristic 这个delegate 里面,不是应该走 if ([self.urlAndCallback valueForKey:READCHARACTERISTIC]){ 这里面的逻辑么,为什么还是走上面ISON的逻辑

— Reply to this email directly or view it on GitHub.

superMushRoom commented 10 years ago

不应该啊 你测一下 希望能提供错误信息

------------------ 原始邮件 ------------------ 发件人: "Richie Min"notifications@github.com; 发送时间: 2014年7月18日(星期五) 下午3:38 收件人: "bcsphere/bluetooth"bluetooth@noreply.github.com; 抄送: "幽谷绮罗"1187762647@qq.com; 主题: Re: [bluetooth] fixed readValue error after setNotification (#25)

@wenze0410 app链接硬件后,假设对service1下的char1执行subscribe操作,这个时候urlAndCallback中的ISON 就会为true,如果这个时候再对另外一个service2下的char1进行read操作,此时就会报错,错误行数 https://github.com/bcsphere/bluetooth/blob/master/src/ios/BCBluetooth.m#L1154

— Reply to this email directly or view it on GitHub.