objective c - NSData Splits into chunks -
i'm nslogging stream of nsdata receive outside source, reason, keeps breaking 40 character chunks, , going new line once hits 40 characters. i'm trying parse through stream , pick out values in specific places, it's huge hassle keeps jumping down line. know how behavior can prevented? here example of nslog:
2013-07-17 14:44:32.638 test app [4041:907] data equals <3e2c042c 31333037 31373032 34302d30 372c0100> 2013-07-17 14:44:32.698 test app [4041:907] data equals <00000000 2c020000 0000002c 03000000 00002cff> 2013-07-17 14:44:32.758 test app [4041:907] data equals <00000000 00>
edit: relevant code, i'm using third party ble library, figured wouldn't of use. line of relevant code:
nsdata *data = [bledevice readreceivedbytes]; nslog(@"data equals %@", data);
i gave rob's suggestion shot, , result:
2013-07-17 15:21:35.399 test app[4060:907] data equals <3e2c012c 31333037 31373033 32312d30 372cff00> 2013-07-17 15:21:35.401 test app[4060:907] data length equals =20 2013-07-17 15:21:35.458 test app[4060:907] data equals <00000000> 2013-07-17 15:21:35.460 test app[4060:907] data length equals =4
it should streaming in 1 line, rather having 40 character max. maybe ble thing.
if ble sends small packets there nothing can it. , should not expect packets of size returned.
you should collect received chunks in nsmutabledata
object instead:
// init once: nsmutabledata *collecteddata = [nsmutabledata data]; // append received data in read loop: nsdata *data = [bledevice readreceivedbytes]; [collecteddata appenddata:data];
now can search specific bytes in collecteddata
.
Comments
Post a Comment