2013-12-13 09:19:49 -04:30
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2013 Miguel Angel Astor Romero
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
2013-11-05 11:44:26 -04:30
|
|
|
package ve.ucv.ciens.ccg.nxtcam.network;
|
|
|
|
|
|
2014-01-20 12:59:51 -04:30
|
|
|
import ve.ucv.ciens.ccg.nxtcam.utils.Logger;
|
|
|
|
|
|
2013-11-05 11:44:26 -04:30
|
|
|
public class LCPThread extends Thread{
|
2014-01-20 12:59:51 -04:30
|
|
|
private static final String TAG = "LCP_THREAD";
|
|
|
|
|
private static final String CLASS_NAME = LCPThread.class.getSimpleName();
|
2013-11-05 11:44:26 -04:30
|
|
|
|
2014-01-20 12:59:51 -04:30
|
|
|
private boolean done;
|
|
|
|
|
private boolean reportSensors;
|
|
|
|
|
private BTCommunicator btComm;
|
|
|
|
|
private MotorControlThread motorControl;
|
|
|
|
|
private SensorReportThread sensorReport;
|
|
|
|
|
|
|
|
|
|
public LCPThread(String serverIp){
|
|
|
|
|
super("Robot Control Main Thread");
|
|
|
|
|
btComm = BTCommunicator.getInstance();
|
|
|
|
|
done = false;
|
|
|
|
|
motorControl = new MotorControlThread(serverIp);
|
|
|
|
|
sensorReport = new SensorReportThread(serverIp);
|
2013-11-05 11:44:26 -04:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void run(){
|
2014-01-20 12:59:51 -04:30
|
|
|
if(!motorControl.connectToServer()){
|
|
|
|
|
Logger.log_e(TAG, CLASS_NAME + ".run() :: Thread motorControl could not connect to the server.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(!(reportSensors = sensorReport.connectToServer())){
|
|
|
|
|
Logger.log_e(TAG, CLASS_NAME + ".run() :: Thread sensorReport could not connect to the server.");
|
|
|
|
|
Logger.log_e(TAG, CLASS_NAME + ".run() :: Sensor data will not be reported to server app.");
|
|
|
|
|
}
|
2013-11-05 11:44:26 -04:30
|
|
|
|
2014-01-20 12:59:51 -04:30
|
|
|
while(!done){
|
|
|
|
|
if(btComm.isBTEnabled() && btComm.isConnected()){
|
|
|
|
|
Logger.log_d(TAG, CLASS_NAME + ".run() :: Connected.");
|
|
|
|
|
if(reportSensors)
|
|
|
|
|
Logger.log_d(TAG, CLASS_NAME + ".run() :: Sensor data can be reported.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void finish(){
|
|
|
|
|
done = true;
|
2013-11-05 11:44:26 -04:30
|
|
|
}
|
|
|
|
|
}
|