Commit 5f927c00 authored by Harshith Goka's avatar Harshith Goka

Continuous Thread Execution

parent 127ff063
...@@ -24,7 +24,6 @@ public class ConnectThread extends Thread { ...@@ -24,7 +24,6 @@ public class ConnectThread extends Thread {
GlobalClass globalClass; GlobalClass globalClass;
public int isConnected; public int isConnected;
Handler handler; Handler handler;
ReceiveDataThread receiveDataThread = null;
public ConnectThread(String address,UUID uuid,Handler handler,GlobalClass globalClass){ public ConnectThread(String address,UUID uuid,Handler handler,GlobalClass globalClass){
this.address = address; this.address = address;
...@@ -41,15 +40,13 @@ public class ConnectThread extends Thread { ...@@ -41,15 +40,13 @@ public class ConnectThread extends Thread {
bluetoothSocket = bluetoothDevice.createInsecureRfcommSocketToServiceRecord(uuid); bluetoothSocket = bluetoothDevice.createInsecureRfcommSocketToServiceRecord(uuid);
bluetoothSocket.connect(); bluetoothSocket.connect();
isConnected = Constants.CONNECTION_STATUS_OK; isConnected = Constants.CONNECTION_STATUS_OK;
receiveDataThread = new ReceiveDataThread(bluetoothSocket,handler,globalClass);
receiveDataThread.start();
} }
catch (IOException e) { catch (IOException e) {
isConnected = Constants.CONNECTION_STATUS_NOT_CONNECTED; isConnected = Constants.CONNECTION_STATUS_NOT_CONNECTED;
} }
Looper.prepare(); Looper.prepare();
Message message = handler.obtainMessage(Constants.CONNECTION_STATUS,isConnected); Message message = handler.obtainMessage(Constants.CONNECTION_STATUS,isConnected,0,bluetoothSocket);
handler.handleMessage(message); handler.handleMessage(message);
Looper.loop(); Looper.loop();
} }
......
...@@ -17,7 +17,7 @@ public class ProcessThread extends Thread{ ...@@ -17,7 +17,7 @@ public class ProcessThread extends Thread{
public ProcessThread(GlobalClass globalClass) { public ProcessThread(GlobalClass globalClass) {
liveReadings = null; liveReadings = null;
this.globalClass = globalClass; this.globalClass = globalClass;
globalClass.setProcessHandler(handler);
} }
@Override @Override
public void run() { public void run() {
...@@ -29,6 +29,12 @@ public class ProcessThread extends Thread{ ...@@ -29,6 +29,12 @@ public class ProcessThread extends Thread{
L.m(liveReadings.toString()); L.m(liveReadings.toString());
} }
}; };
globalClass.setProcessHandler(handler);
Looper.loop(); Looper.loop();
while (true){
if(liveReadings != null){
}
}
} }
} }
...@@ -48,27 +48,21 @@ public class ReceiveDataThread extends Thread { ...@@ -48,27 +48,21 @@ public class ReceiveDataThread extends Thread {
String readMessage = new String(buffer,0,bytes); String readMessage = new String(buffer,0,bytes);
stringBuilder.append(readMessage); stringBuilder.append(readMessage);
convert(); convert();
ProcessThread processThread = new ProcessThread(globalClass); // ProcessThread processThread = new ProcessThread(globalClass);
try { // processThread.start();
Thread.sleep(1000); //
} catch (InterruptedException e) { // processHandler = globalClass.getProcessHandler();
}
processThread.start();
processHandler = globalClass.getProcessHandler();
while(true) { while(true) {
bytes = inputStream.read(buffer); bytes = inputStream.read(buffer);
readMessage = new String(buffer,0,bytes); readMessage = new String(buffer,0,bytes);
stringBuilder.append(readMessage); stringBuilder.append(readMessage);
convert(); convert();
Looper.prepare(); // if(processHandler != null) {
if(processHandler != null) { // processHandler.obtainMessage(1, readings).sendToTarget();
processHandler.obtainMessage(1, readings).sendToTarget(); // }
} // else {
else { // processHandler = globalClass.getProcessHandler();
processHandler = globalClass.getProcessHandler(); // }
}
Looper.loop();
} }
......
package com.example.harshith.ddc; package com.example.harshith.ddc;
import android.app.Service; import android.app.Service;
import android.bluetooth.BluetoothSocket;
import android.content.Intent; import android.content.Intent;
import android.os.Handler; import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
...@@ -16,6 +17,7 @@ import java.util.UUID; ...@@ -16,6 +17,7 @@ import java.util.UUID;
public class ReceiveService extends Service { public class ReceiveService extends Service {
ConnectThread connectThread; ConnectThread connectThread;
ReceiveDataThread receiveDataThread;
private static final UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); private static final UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
public Handler handler; public Handler handler;
GlobalClass globalClass; GlobalClass globalClass;
...@@ -26,8 +28,10 @@ public class ReceiveService extends Service { ...@@ -26,8 +28,10 @@ public class ReceiveService extends Service {
@Override @Override
public void handleMessage(Message message) { public void handleMessage(Message message) {
if(message.what == Constants.CONNECTION_STATUS) { if(message.what == Constants.CONNECTION_STATUS) {
if((int)message.obj == Constants.CONNECTION_STATUS_OK){ if(message.arg1 == Constants.CONNECTION_STATUS_OK){
Toast.makeText(getApplicationContext(),"Connected",Toast.LENGTH_LONG).show(); Toast.makeText(getApplicationContext(),"Connected",Toast.LENGTH_LONG).show();
receiveDataThread = new ReceiveDataThread((BluetoothSocket) message.obj,handler,globalClass);
receiveDataThread.start();
} }
else if((int) message.obj == Constants.CONNECTION_STATUS_NOT_CONNECTED){ else if((int) message.obj == Constants.CONNECTION_STATUS_NOT_CONNECTED){
Toast.makeText(getApplicationContext(),"Couldn't Connect to Dextera Domini, Check whether it is switched on",Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(),"Couldn't Connect to Dextera Domini, Check whether it is switched on",Toast.LENGTH_SHORT).show();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment