summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Grover <joeygrover@gmail.com>2017-03-22 15:59:45 -0400
committerJoey Grover <joeygrover@gmail.com>2017-03-22 15:59:45 -0400
commit874191b33d313cc44137a5dd782fa11364d3c26a (patch)
tree2876f6ac7dabd316ba574c7135f9c1f3df79313e
parent2944eee107990c6860800d3828b32749759e5a9f (diff)
parent3141b194aa616418bcbbe06365396720b92caeaf (diff)
downloadsdl_android-874191b33d313cc44137a5dd782fa11364d3c26a.tar.gz
Merge branch 'hotfix/transport_performance' of git://github.com/jacobkeeler/sdl_android into develop
# Conflicts: # sdl_android_lib/src/com/smartdevicelink/transport/MultiplexBluetoothTransport.java
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/transport/BTTransport.java75
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/transport/MultiplexBluetoothTransport.java38
-rw-r--r--sdl_android_lib/src/com/smartdevicelink/transport/TCPTransport.java41
3 files changed, 86 insertions, 68 deletions
diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/BTTransport.java b/sdl_android_lib/src/com/smartdevicelink/transport/BTTransport.java
index f64ff3668..526d2226d 100644
--- a/sdl_android_lib/src/com/smartdevicelink/transport/BTTransport.java
+++ b/sdl_android_lib/src/com/smartdevicelink/transport/BTTransport.java
@@ -30,7 +30,9 @@ public class BTTransport extends SdlTransport {
private final static UUID SDL_V4_MOBILE_APPLICATION_SVC_CLASS = new UUID(0x936DA01F9ABD4D9DL, 0x80C702AF85C822A8L);
private static final String SDL_LIB_TRACE_KEY = "42baba60-eb57-11df-98cf-0800200c9a66";
-
+
+ private static final int READ_BUFFER_SIZE = 4096;
+
private BluetoothAdapter _adapter = null;
private BluetoothSocket _activeSocket = null;
private UUID _listeningServiceUUID = SDL_V4_MOBILE_APPLICATION_SVC_CLASS;
@@ -324,16 +326,18 @@ public class BTTransport extends SdlTransport {
private class TransportReaderThread extends Thread {
private Boolean isHalted = false;
- SdlPsm psm;
- byte byteRead = -1;
- boolean stateProgress = false;
-
- private InputStream _input = null;
+ SdlPsm psm;
+ int bytesRead = 0;
+ byte[] buffer = new byte[READ_BUFFER_SIZE];
+ byte currentByte = -1;
+ boolean stateProgress = false;
-
- public TransportReaderThread(){
- psm = new SdlPsm();
- }
+ private InputStream _input = null;
+
+
+ public TransportReaderThread(){
+ psm = new SdlPsm();
+ }
public void halt() {
isHalted = true;
}
@@ -387,7 +391,7 @@ public class BTTransport extends SdlTransport {
private void readFromTransport() {
try {
try {
- byteRead = (byte)_input.read();
+ bytesRead = _input.read(buffer);
} catch (Exception e) {
if (!isHalted) {
// Only call disconnect if the thread has not been halted
@@ -402,34 +406,37 @@ public class BTTransport extends SdlTransport {
return;
} // end-catch
- stateProgress = psm.handleByte(byteRead);
- if(!stateProgress){//We are trying to weed through the bad packet info until we get something
- //Log.w(TAG, "Packet State Machine did not move forward from state - "+ psm.getState()+". PSM being Reset.");
- psm.reset();
- if(byteRead == -1){ //If we read a -1 and the psm didn't move forward, then there is a problem
- if (!isHalted) {
- // Only call disconnect if the thread has not been halted
- DebugTool.logError("End of stream reached!");
- disconnect("End of stream reached.", null);
+ for (int i = 0; i < bytesRead; i++) {
+ currentByte = buffer[i];
+ stateProgress = psm.handleByte(currentByte);
+ if(!stateProgress){//We are trying to weed through the bad packet info until we get something
+ //Log.w(TAG, "Packet State Machine did not move forward from state - "+ psm.getState()+". PSM being Reset.");
+ psm.reset();
+ if(currentByte == -1){ //If we read a -1 and the psm didn't move forward, then there is a problem
+ if (!isHalted) {
+ // Only call disconnect if the thread has not been halted
+ DebugTool.logError("End of stream reached!");
+ disconnect("End of stream reached.", null);
+ }
}
}
- }
- if(psm.getState() == SdlPsm.FINISHED_STATE){
- //Log.d(TAG, "Packet formed, sending off");
- handleReceivedPacket((SdlPacket)psm.getFormedPacket());
- //We put a trace statement in the message read so we can avoid all the extra bytes
- psm.reset();
+ if(psm.getState() == SdlPsm.FINISHED_STATE){
+ //Log.d(TAG, "Packet formed, sending off");
+ handleReceivedPacket((SdlPacket)psm.getFormedPacket());
+ //We put a trace statement in the message read so we can avoid all the extra bytes
+ psm.reset();
+ }
}
} catch (Exception excp) {
- if (!isHalted) {
- // Only call disconnect if the thread has not been halted
- clearInputStream();
- String errString = "Failure in BTTransport reader thread: " + excp.toString();
- DebugTool.logError(errString, excp);
- disconnect(errString, excp);
- }
- return;
+ if (!isHalted) {
+ // Only call disconnect if the thread has not been halted
+ clearInputStream();
+ String errString = "Failure in BTTransport reader thread: " + excp.toString();
+ DebugTool.logError(errString, excp);
+ disconnect(errString, excp);
+ }
+ return;
} // end-catch
} // end-method
diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/MultiplexBluetoothTransport.java b/sdl_android_lib/src/com/smartdevicelink/transport/MultiplexBluetoothTransport.java
index fc8415b1e..b4fea0e71 100644
--- a/sdl_android_lib/src/com/smartdevicelink/transport/MultiplexBluetoothTransport.java
+++ b/sdl_android_lib/src/com/smartdevicelink/transport/MultiplexBluetoothTransport.java
@@ -83,7 +83,9 @@ public class MultiplexBluetoothTransport {
Handler timeOutHandler;
Runnable socketRunable;
private static final long msTillTimeout = 2500;
-
+
+ private static final int READ_BUFFER_SIZE = 4096;
+
public static String currentlyConnectedDevice = null;
public static String currentlyConnectedDeviceAddress = null;
private static MultiplexBluetoothTransport serverInstance = null;
@@ -771,8 +773,10 @@ public class MultiplexBluetoothTransport {
@SuppressLint("NewApi")
public void run() {
- Log.d(TAG, "Running the Connected Thread");
+ Log.d(TAG, "Running the Connected Thread");
byte input = 0;
+ int bytesRead = 0;
+ byte[] buffer = new byte[READ_BUFFER_SIZE];
MultiplexBluetoothTransport.currentlyConnectedDevice = mmSocket.getRemoteDevice().getName();
MultiplexBluetoothTransport.currentlyConnectedDeviceAddress = mmSocket.getRemoteDevice().getAddress();
// Keep listening to the InputStream while connected
@@ -782,20 +786,24 @@ public class MultiplexBluetoothTransport {
while (true) {
try {
- input = (byte)mmInStream.read();
- // Send the response of what we received
- stateProgress = psm.handleByte(input);
- if(!stateProgress){//We are trying to weed through the bad packet info until we get something
- //Log.w(TAG, "Packet State Machine did not move forward from state - "+ psm.getState()+". PSM being Reset.");
- psm.reset();
- continue;
- }
-
- if(psm.getState() == SdlPsm.FINISHED_STATE){
- //Log.d(TAG, "Packet formed, sending off");
- mHandler.obtainMessage(SdlRouterService.MESSAGE_READ, psm.getFormedPacket()).sendToTarget();
- psm.reset();
+ bytesRead = mmInStream.read(buffer);
+ Log.i(getClass().getName(), "Received " + bytesRead + " bytes from Bluetooth");
+ for (int i = 0; i < bytesRead; i++) {
+ input = buffer[i];
+
+ // Send the response of what we received
+ stateProgress = psm.handleByte(input);
+ if (!stateProgress) { //We are trying to weed through the bad packet info until we get something
+ //Log.w(TAG, "Packet State Machine did not move forward from state - "+ psm.getState()+". PSM being Reset.");
+ psm.reset();
+ continue;
+ }
+ if (psm.getState() == SdlPsm.FINISHED_STATE) {
+ //Log.d(TAG, "Packet formed, sending off");
+ mHandler.obtainMessage(SdlRouterService.MESSAGE_READ, psm.getFormedPacket()).sendToTarget();
+ psm.reset();
+ }
}
} catch (IOException|NullPointerException e) { // NPE is ONLY to catch error on mmInStream
Log.e(TAG, "Lost connection in the Connected Thread");
diff --git a/sdl_android_lib/src/com/smartdevicelink/transport/TCPTransport.java b/sdl_android_lib/src/com/smartdevicelink/transport/TCPTransport.java
index 9ba789ef8..e9fb0efcf 100644
--- a/sdl_android_lib/src/com/smartdevicelink/transport/TCPTransport.java
+++ b/sdl_android_lib/src/com/smartdevicelink/transport/TCPTransport.java
@@ -383,12 +383,14 @@ public class TCPTransport extends SdlTransport {
}
byte input;
+ byte[] buffer = new byte[READ_BUFFER_SIZE];
+ int bytesRead;
boolean stateProgress = false;
while (!isHalted) {
- logInfo("TCPTransport.run: Waiting for data...");
+ //logInfo("TCPTransport.run: Waiting for data...");
try {
- input = (byte) mInputStream.read();
- //bytesRead = mInputStream.read(buffer);
+ //input = (byte) mInputStream.read();
+ bytesRead = mInputStream.read(buffer);
} catch (IOException e) {
internalHandleStreamReadError();
break;
@@ -400,27 +402,28 @@ public class TCPTransport extends SdlTransport {
break;
}
}
-
- logInfo("TCPTransport.run: Got new data");
+ for (int i = 0; i < bytesRead; i++) {
+ //logInfo("TCPTransport.run: Got new data");
// Send the response of what we received
- stateProgress = psm.handleByte(input);
- if(!stateProgress){//We are trying to weed through the bad packet info until we get something
-
- //Log.w(TAG, "Packet State Machine did not move forward from state - "+ psm.getState()+". PSM being Reset.");
- psm.reset();
+ input = buffer[i];
+ stateProgress = psm.handleByte(input);
+ if (!stateProgress) {//We are trying to weed through the bad packet info until we get something
+
+ //Log.w(TAG, "Packet State Machine did not move forward from state - "+ psm.getState()+". PSM being Reset.");
+ psm.reset();
}
-
- if(psm.getState() == SdlPsm.FINISHED_STATE)
+
+ if (psm.getState() == SdlPsm.FINISHED_STATE)
{
- synchronized (TCPTransport.this) {
- //Log.d(TAG, "Packet formed, sending off");
- handleReceivedPacket((SdlPacket)psm.getFormedPacket());
- }
- //We put a trace statement in the message read so we can avoid all the extra bytes
- psm.reset();
+ synchronized (TCPTransport.this) {
+ //Log.d(TAG, "Packet formed, sending off");
+ handleReceivedPacket((SdlPacket) psm.getFormedPacket());
+ }
+ //We put a trace statement in the message read so we can avoid all the extra bytes
+ psm.reset();
}
//FIXME logInfo(String.format("TCPTransport.run: Received %d bytes", bytesRead));
-
+ }
}
}