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

Continuous Thread Execution

parent 127ff063
......@@ -24,7 +24,6 @@ public class ConnectThread extends Thread {
GlobalClass globalClass;
public int isConnected;
Handler handler;
ReceiveDataThread receiveDataThread = null;
public ConnectThread(String address,UUID uuid,Handler handler,GlobalClass globalClass){
this.address = address;
......@@ -41,15 +40,13 @@ public class ConnectThread extends Thread {
bluetoothSocket = bluetoothDevice.createInsecureRfcommSocketToServiceRecord(uuid);
bluetoothSocket.connect();
isConnected = Constants.CONNECTION_STATUS_OK;
receiveDataThread = new ReceiveDataThread(bluetoothSocket,handler,globalClass);
receiveDataThread.start();
}
catch (IOException e) {
isConnected = Constants.CONNECTION_STATUS_NOT_CONNECTED;
}
Looper.prepare();
Message message = handler.obtainMessage(Constants.CONNECTION_STATUS,isConnected);
Message message = handler.obtainMessage(Constants.CONNECTION_STATUS,isConnected,0,bluetoothSocket);
handler.handleMessage(message);
Looper.loop();
}
......
......@@ -17,7 +17,7 @@ public class ProcessThread extends Thread{
public ProcessThread(GlobalClass globalClass) {
liveReadings = null;
this.globalClass = globalClass;
globalClass.setProcessHandler(handler);
}
@Override
public void run() {
......@@ -29,6 +29,12 @@ public class ProcessThread extends Thread{
L.m(liveReadings.toString());
}
};
globalClass.setProcessHandler(handler);
Looper.loop();
while (true){
if(liveReadings != null){
}
}
}
}
......@@ -48,27 +48,21 @@ public class ReceiveDataThread extends Thread {
String readMessage = new String(buffer,0,bytes);
stringBuilder.append(readMessage);
convert();
ProcessThread processThread = new ProcessThread(globalClass);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
processThread.start();
processHandler = globalClass.getProcessHandler();
// ProcessThread processThread = new ProcessThread(globalClass);
// processThread.start();
//
// processHandler = globalClass.getProcessHandler();
while(true) {
bytes = inputStream.read(buffer);
readMessage = new String(buffer,0,bytes);
stringBuilder.append(readMessage);
convert();
Looper.prepare();
if(processHandler != null) {
processHandler.obtainMessage(1, readings).sendToTarget();
}
else {
processHandler = globalClass.getProcessHandler();
}
Looper.loop();
// if(processHandler != null) {
// processHandler.obtainMessage(1, readings).sendToTarget();
// }
// else {
// processHandler = globalClass.getProcessHandler();
// }
}
......
package com.example.harshith.ddc;
import android.app.Service;
import android.bluetooth.BluetoothSocket;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
......@@ -16,6 +17,7 @@ import java.util.UUID;
public class ReceiveService extends Service {
ConnectThread connectThread;
ReceiveDataThread receiveDataThread;
private static final UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
public Handler handler;
GlobalClass globalClass;
......@@ -26,8 +28,10 @@ public class ReceiveService extends Service {
@Override
public void handleMessage(Message message) {
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();
receiveDataThread = new ReceiveDataThread((BluetoothSocket) message.obj,handler,globalClass);
receiveDataThread.start();
}
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();
......
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