Skip to content

Commit

Permalink
Merge pull request benjymous#6 from garthy/master
Browse files Browse the repository at this point in the history
This is really important. Stops corrupt read messages and half read messages!
  • Loading branch information
benjymous committed Mar 9, 2012
2 parents 1a0aa4d + 40e60c5 commit 1e450af
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/org/metawatch/manager/MetaWatchService.java
Expand Up @@ -654,7 +654,17 @@ void readFromDevice() {
try { try {
byte[] bytes = new byte[256]; byte[] bytes = new byte[256];
if (Preferences.logging) Log.d(MetaWatch.TAG, "before blocking read"); if (Preferences.logging) Log.d(MetaWatch.TAG, "before blocking read");
inputStream.read(bytes); // Do a proper read loop
int haveread = 0;
int lengthtoread = 4;
while((lengthtoread-haveread) != 0)
{
haveread += inputStream.read(bytes, haveread, lengthtoread-haveread);
if(haveread > 1)
{
lengthtoread = bytes[1];
}
}
wakeLock.acquire(5000); wakeLock.acquire(5000);


// print received // print received
Expand Down Expand Up @@ -682,12 +692,15 @@ void readFromDevice() {
* success if (bytes[4] == 0x00) // set to 12 hour format * success if (bytes[4] == 0x00) // set to 12 hour format
* Protocol.setNvalTime(true); } * Protocol.setNvalTime(true); }
*/ */

if (bytes[2] == eMessageType.NvalOperationResponseMsg.msg) {
if (bytes[2] == eMessageType.StatusChangeEvent.msg) { // status if (Preferences.logging) Log.d(MetaWatch.TAG,
"MetaWatchService.readFromDevice(): NvalOperationResponseMsg");
// Do something here?
} else if (bytes[2] == eMessageType.StatusChangeEvent.msg) { // status
// change // change
// event // event
if (Preferences.logging) Log.d(MetaWatch.TAG, if (Preferences.logging) Log.d(MetaWatch.TAG,
"MetaWatchService.readFromDevice(): status change"); "MetaWatchService.readFromDevice(): status change");
if (bytes[4] == 0x11) { if (bytes[4] == 0x11) {
if (Preferences.logging) Log.d(MetaWatch.TAG, if (Preferences.logging) Log.d(MetaWatch.TAG,
"MetaWatchService.readFromDevice(): scroll request notification"); "MetaWatchService.readFromDevice(): scroll request notification");
Expand Down

0 comments on commit 1e450af

Please sign in to comment.