sandeepmistry/noble — pull request #26 by holmesal (2013-10-08 22:50:23+00:00)
Title: Bugfix: scan exits and RangeErrors

Problem: Scans would exit at seemingly random times.
---
Scans were exiting because a subevent was received that was not an advertising packet (e.g. not 0x02). It's not clear where this event comes from and I can't find good documentation on it's value (integer 42). I changed hci-ble.c to simply log any non-advertising events - the original behavior was to break out of the scan loop.

A side effect of this is that scans don't automatically stop when a connection is created. I'm okay with this, as my use case is to frequently connect to devices while continuing to scan for new ones in the background. If this isn't what most people are after, we could call stopScanning from `connect` in bindings.js, or add a keepScanning=false default to the connect function.

Problem: Corrupt data would cause a RangeError when parsing the buffer
---
Your buffer length check works well most of the time. However, when the data is corrupted, I still get Range Errors. I wrapped each line of buffer parsing in a try/catch, so that at least noble won't crash.

I still get strange "pauses" in my scans, usually coinciding with a positive rssi value. Nothing seems to be crashing anymore, though, which is good enough for now.

Also, I'm not sure why the diff below is so messed up - it's much cleaner when you diff these files side-by-side