diff options
author | Keith Packard <keithp@keithp.com> | 2012-01-01 14:19:16 -0800 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2012-01-01 14:19:16 -0800 |
commit | 365b40503f72a84b1c921b322df717089bff8014 (patch) | |
tree | 4952601585e26e41f37c4642413ffd145f99bfcf | |
parent | 54ffb14fc6867c69e6d867171d2c83ccc7cc6688 (diff) |
Add newline to messages sent to TBT. Log incoming messages
Newline required to send commands.
Log incoming message to verify reliable data transfer.
Signed-off-by: Keith Packard <keithp@keithp.com>
-rw-r--r-- | src/org/altusmetrum/AltosDroid/AltosDroid.java | 2 | ||||
-rw-r--r-- | src/org/altusmetrum/AltosDroid/BluetoothChatService.java | 19 |
2 files changed, 15 insertions, 6 deletions
diff --git a/src/org/altusmetrum/AltosDroid/AltosDroid.java b/src/org/altusmetrum/AltosDroid/AltosDroid.java index 844ca39..43a8574 100644 --- a/src/org/altusmetrum/AltosDroid/AltosDroid.java +++ b/src/org/altusmetrum/AltosDroid/AltosDroid.java @@ -217,6 +217,8 @@ public class AltosDroid extends Activity { // Get the message bytes and tell the BluetoothChatService to write byte[] send = message.getBytes(); mChatService.write(send); + byte[] newline = { '\n' }; + mChatService.write(newline); // Reset out string buffer to zero and clear the edit text field mOutStringBuffer.setLength(0); diff --git a/src/org/altusmetrum/AltosDroid/BluetoothChatService.java b/src/org/altusmetrum/AltosDroid/BluetoothChatService.java index 93cb75d..03edeb9 100644 --- a/src/org/altusmetrum/AltosDroid/BluetoothChatService.java +++ b/src/org/altusmetrum/AltosDroid/BluetoothChatService.java @@ -236,15 +236,17 @@ public class BluetoothChatService { // Get a BluetoothSocket for a connection with the // given BluetoothDevice try { + Log.i(TAG, "Connect starting"); if (secure) { Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class}); - tmp = (BluetoothSocket) m.invoke(device, 2); + tmp = (BluetoothSocket) m.invoke(device, 1); // tmp = device.createRfcommSocket(1); } else { Method m = device.getClass().getMethod("createInsecureRfcommSocket", new Class[] {int.class}); - tmp = (BluetoothSocket) m.invoke(device, 2); + tmp = (BluetoothSocket) m.invoke(device, 1); // tmp = device.createInsecureRfcommSocket(1); } + Log.i(TAG, "Connect succeeded"); } catch (Exception e) { Log.e(TAG, "Socket Type: " + mSocketType + "create() failed", e); e.printStackTrace(); @@ -253,19 +255,21 @@ public class BluetoothChatService { } public void run() { - Log.i(TAG, "BEGIN mConnectThread SocketType:" + mSocketType); + Log.i(TAG, "BEGIN ya y a mConnectThread SocketType:" + mSocketType); setName("ConnectThread" + mSocketType); // Always cancel discovery because it will slow down a connection - mAdapter.cancelDiscovery(); +// mAdapter.cancelDiscovery(); // Make a connection to the BluetoothSocket try { // This is a blocking call and will only return on a // successful connection or an exception + Log.i(TAG, "CONNECT SocketType:" + mSocketType); mmSocket.connect(); } catch (IOException e) { // Close the socket + Log.e(TAG, "Connect failed", e); try { mmSocket.close(); } catch (IOException e2) { @@ -332,9 +336,12 @@ public class BluetoothChatService { // Read from the InputStream bytes = mmInStream.read(buffer); - // Send the obtained bytes to the UI Activity - mHandler.obtainMessage(AltosDroid.MESSAGE_READ, bytes, -1, buffer) + if (bytes > 0) { + Log.i(TAG, "Recv: " + new String(buffer, 0, bytes)); + // Send the obtained bytes to the UI Activity + mHandler.obtainMessage(AltosDroid.MESSAGE_READ, bytes, -1, buffer) .sendToTarget(); + } } catch (IOException e) { Log.e(TAG, "disconnected", e); connectionLost(); |