pebble/libpebble — pull request #3 by aleksandyr (2013-04-14 08:28:34+00:00)
Title: Fix for response fragmentation caused by lightblue

This addresses the issue some people were seeing where attempting to work with more than 4 installed watch apps caused warnings/errors.

Essentially, LightBluePebble was relying on the serial buffer to be complete (and to contain exactly one response from the watch) as soon as any data was available. This is generally true for smaller responses - but for larger responses, such as the app bank, the response becomes arbitrarily fragmented.

This fix blocks on read until a complete response (according to the size sent over from the Pebble) is returned.

For comparison, LightBlue vs RFComm:

#### LightBlue
```
$ ./p.py --lightblue list
[DEBUG ] LightBlue process has started on pid 90885
[DEBUG ] Connection established to 00:18:33:5A:F8:74
[DEBUG ] Initializing reader thread
[DEBUG ] Reader thread loaded on tid Thread-1
[DEBUG ] >>> 0001177001
[DEBUG ] Got message for endpoint 17 of length 1
[DEBUG ] <<< 0001001100
[DEBUG ] >>> 000d001101ffffffff8000000000000032
[DEBUG ] Got message for endpoint 6000 of length 325
[DEBUG ] <<< 022b17700100000008000000070000002500000000576f726473717561726500000000000000000000000000000000000000000000687564736f6e00000000000000000000000000000000000000000000000000000000000100180000002600000001536e616b652046696e6e000000000000000000000000000000000000000000007768696c652874727565293b000000000000000000000000000000000000000000000000000000000027000000023931204475620000000000000000000000000000000000000000000000000000506562626c6520546563686e6f6c6f67792026206f72766977616e0000000000000000010dd800000022000000034f545000000000000000000000000000000000000000000000000000000000005075626c696320446f6d61696e0000000000000000000000000000000000000000000000000000000028
[WARNING ] Couldn't load bank 4; remaining data = '\x00\x00\x00(' (325)
[WARNING ] Couldn't load bank 5; remaining data = '' (325)
[WARNING ] Couldn't load bank 6; remaining data = '' (325)
[DEBUG ] Got message for endpoint 4 of length 0
[DEBUG ] <<< 00000004
[DEBUG ] Got message for endpoint 28016 of length 222
[DEBUG ] <<< 53696d706c696369747900000000000000000000000000000000000000000000506562626c6520546563686e6f6c6f6779000000000000000000000000000000000000010000000000290000000554696d657320537175617265000000000000000000000000000000000000000047617a6c657200000000000000000000000000000000000000000000000000000000000100000000002a000000065365676d656e7420536978000000000000000000000000000000000000000000506562626c6520546563686e6f6c6f6779000000000000000000000000000000000000010000
[0] Wordsquare
[1] Snake Finn
[2] 91 Dub
[3] OTP
```

#### RFComm
```
$ ./p.py --pebble_id F874 list
[DEBUG ] Attempting to open /dev/tty.PebbleF874-SerialPortSe as Pebble device F874
[DEBUG ] Initializing reader thread
[DEBUG ] Reader thread loaded on tid Thread-1
[DEBUG ] >>> 0001177001
[DEBUG ] Got message for endpoint 17 of length 1
[DEBUG ] <<< 0001001100
[DEBUG ] >>> 000d001101ffffffff8000000000000032
[DEBUG ] Got message for endpoint 6000 of length 555
[DEBUG ] <<< 022b17700100000008000000070000002500000000576f726473717561726500000000000000000000000000000000000000000000687564736f6e00000000000000000000000000000000000000000000000000000000000100180000002600000001536e616b652046696e6e000000000000000000000000000000000000000000007768696c652874727565293b000000000000000000000000000000000000000000000000000000000027000000023931204475620000000000000000000000000000000000000000000000000000506562626c6520546563686e6f6c6f67792026206f72766977616e0000000000000000010dd800000022000000034f545000000000000000000000000000000000000000000000000000000000005075626c696320446f6d61696e00000000000000000000000000000000000000000000000000000000280000000453696d706c696369747900000000000000000000000000000000000000000000506562626c6520546563686e6f6c6f6779000000000000000000000000000000000000010000000000290000000554696d657320537175617265000000000000000000000000000000000000000047617a6c657200000000000000000000000000000000000000000000000000000000000100000000002a000000065365676d656e7420536978000000000000000000000000000000000000000000506562626c6520546563686e6f6c6f6779000000000000000000000000000000000000010000
[0] Wordsquare
[1] Snake Finn
[2] 91 Dub
[3] OTP
[4] Simplicity
[5] Times Square
[6] Segment Six
```