Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #6 from garthy/master

This is really important. Stops corrupt read messages and half read messages!
  • Loading branch information...
commit 1e450af42ce39d0e258b360801cd3ddeea485eb8 2 parents 1a0aa4d + 40e60c5
@benjymous benjymous authored
Showing with 18 additions and 5 deletions.
  1. +18 −5 src/org/metawatch/manager/MetaWatchService.java
View
23 src/org/metawatch/manager/MetaWatchService.java
@@ -654,7 +654,17 @@ void readFromDevice() {
try {
byte[] bytes = new byte[256];
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);
// print received
@@ -682,12 +692,15 @@ void readFromDevice() {
* success if (bytes[4] == 0x00) // set to 12 hour format
* Protocol.setNvalTime(true); }
*/
-
- if (bytes[2] == eMessageType.StatusChangeEvent.msg) { // status
+ if (bytes[2] == eMessageType.NvalOperationResponseMsg.msg) {
+ if (Preferences.logging) Log.d(MetaWatch.TAG,
+ "MetaWatchService.readFromDevice(): NvalOperationResponseMsg");
+ // Do something here?
+ } else if (bytes[2] == eMessageType.StatusChangeEvent.msg) { // status
// change
// event
- if (Preferences.logging) Log.d(MetaWatch.TAG,
- "MetaWatchService.readFromDevice(): status change");
+ if (Preferences.logging) Log.d(MetaWatch.TAG,
+ "MetaWatchService.readFromDevice(): status change");
if (bytes[4] == 0x11) {
if (Preferences.logging) Log.d(MetaWatch.TAG,
"MetaWatchService.readFromDevice(): scroll request notification");

0 comments on commit 1e450af

Please sign in to comment.
Something went wrong with that request. Please try again.