|
|
|
|
@ -148,16 +148,15 @@ public class VisualiserInput implements Runnable
|
|
|
|
|
* @throws IOException made by the inputstream reading
|
|
|
|
|
*/
|
|
|
|
|
private static byte[] getBytes(InputStream inStream) throws IOException {
|
|
|
|
|
while (inStream.available() < 15){
|
|
|
|
|
//WE NEED THIS!!!!
|
|
|
|
|
}
|
|
|
|
|
if (inStream.available() < 15) return null;//if there is not enough bytes foer the headerr
|
|
|
|
|
byte[] headerBytes = new byte[15];
|
|
|
|
|
inStream.read(headerBytes);
|
|
|
|
|
byte[] messageLenBytes = Arrays.copyOfRange(headerBytes, 13, 15);
|
|
|
|
|
short messageLen = bytesToShort(messageLenBytes);
|
|
|
|
|
byte[] messageBytesWithCRC = new byte[messageLen+4];
|
|
|
|
|
while (inStream.available() < messageLen + 4){
|
|
|
|
|
//WE NEED THIS!!!!
|
|
|
|
|
if (inStream.available() < messageLen + 4){//if the message is not long enough
|
|
|
|
|
inStream.reset();//reset pointer.
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
inStream.read(messageBytesWithCRC, 0, messageLen + 4);
|
|
|
|
|
ByteBuffer binaryMessageBytes = ByteBuffer.allocate(headerBytes.length+messageBytesWithCRC.length);
|
|
|
|
|
@ -176,6 +175,10 @@ public class VisualiserInput implements Runnable
|
|
|
|
|
|
|
|
|
|
//converts the input into a byte array that can be read by the decoder
|
|
|
|
|
byte[] binaryMessage = getBytes(inFromClient);
|
|
|
|
|
//if there is no bytes read.
|
|
|
|
|
if (binaryMessage == null){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//decode the binary message into readable date
|
|
|
|
|
BinaryMessageDecoder testDecoder = new BinaryMessageDecoder(binaryMessage);
|
|
|
|
|
|