mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-21 11:54:15 +01:00
Make the UAVTalk object process one byte per call so it can be embedded in
another loop. Also clean up some warnings.
This commit is contained in:
parent
8dc6b09b96
commit
cdac9d7f9e
@ -1,7 +1,5 @@
|
||||
package org.openpilot.uavtalk;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
@ -30,7 +28,10 @@ public class UAVTalk extends Observable {
|
||||
|
||||
inputProcessingThread = new Thread() {
|
||||
public void run() {
|
||||
processInputStream();
|
||||
while(true) {
|
||||
if( !processInputStream() )
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
return inputProcessingThread;
|
||||
@ -173,12 +174,11 @@ public class UAVTalk extends Observable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called each time there are data in the input buffer
|
||||
* Process any data in the queue
|
||||
*/
|
||||
public void processInputStream() {
|
||||
public boolean processInputStream() {
|
||||
int val;
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
// inStream.wait();
|
||||
val = inStream.read();
|
||||
@ -190,19 +190,19 @@ public class UAVTalk extends Observable {
|
||||
// TODO Auto-generated catch block
|
||||
System.out.println("Error reading from stream\n");
|
||||
e.printStackTrace();
|
||||
break;
|
||||
return false;
|
||||
}
|
||||
if (val == -1) {
|
||||
System.out
|
||||
.println("End of stream, terminating processInputStream thread");
|
||||
break;
|
||||
System.out.println("End of stream, terminating processInputStream thread");
|
||||
return false;
|
||||
}
|
||||
|
||||
// System.out.println("Received byte " + val + " in state + " +
|
||||
// rxState);
|
||||
processInputByte(val);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Request an update for the specified object, on success the object data
|
||||
@ -665,9 +665,6 @@ public class UAVTalk extends Observable {
|
||||
public synchronized boolean transmitSingleObject(UAVObject obj, int type,
|
||||
boolean allInstances) {
|
||||
int length;
|
||||
int dataOffset;
|
||||
int objId;
|
||||
int instId;
|
||||
int allInstId = ALL_INSTANCES;
|
||||
|
||||
assert (objMngr != null && outStream != null);
|
||||
|
Loading…
x
Reference in New Issue
Block a user