Skip to content
Snippets Groups Projects
Commit 36ef5ee8 authored by Xavier Gibert's avatar Xavier Gibert
Browse files

Simulation debugging

parent 9d817d1a
No related branches found
No related tags found
No related merge requests found
package cs.si.satatt;
public class Parameters {
public static class Simulator {
public static final long min_hud_panel_refreshing_interval_ns = 500000000;//2Hz max
public static final long min_hud_model_refreshing_interval_ns = 40000000;//25Hz max
}
public static class Web {
public static final String STARTING_PAGE = "file:///android_asset/www/index.html";
public static final String TEST_PAGE_1 = "http://get.webgl.org/";
......
......@@ -14,6 +14,7 @@ import android.preference.PreferenceManager;
import android.app.Fragment;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
......@@ -112,7 +113,9 @@ public final class SimulatorFragment extends Fragment {
}else{
//Set mission
}
Log.d("Sim",System.currentTimeMillis()+": "+"button connect pressed");
simulator.connect();
Log.d("Sim",System.currentTimeMillis()+": "+"button connect onlick ends");
}
}
});
......
......@@ -81,12 +81,15 @@ public class ModelSimulation {
* @param st
*/
private synchronized void updateState(ModelState st){
Log.d("Sim",System.currentTimeMillis()+": "+"pre update 2");
state = st;
Log.d("Sim",System.currentTimeMillis()+": "+"post update 2");
}
private synchronized void updateInfo(ModelInfo inf){
info = inf;
updateHUD();
Log.d("Sim",System.currentTimeMillis()+": "+"pre update 3");
info = inf;
Log.d("Sim",System.currentTimeMillis()+": "+"post update 3");
}
private AbsoluteDate tmp_time;
......@@ -94,6 +97,7 @@ public class ModelSimulation {
private TimeScale utc;
private Frame sunFrame;
public void updateSimulation(SpacecraftState scs, int sim_progress){
Log.d("Sim",System.currentTimeMillis()+": "+"pre update 1");
ModelState new_state = new ModelState();
ModelInfo new_info = new ModelInfo();
......@@ -160,9 +164,11 @@ public class ModelSimulation {
updateState(new_state);
updateInfo(new_info);
Log.d("Sim",System.currentTimeMillis()+": "+"post update 1");
}
private void updateHUD(){
public synchronized void updateHUD(){
Log.d("Sim",System.currentTimeMillis()+": "+"pre update gui 1");
activity.runOnUiThread( new Runnable() {
@SuppressLint("ResourceAsColor")
public void run() {
......@@ -207,5 +213,6 @@ public class ModelSimulation {
}
}
});
Log.d("Sim",System.currentTimeMillis()+": "+"post update gui 1");
}
}
......@@ -9,6 +9,7 @@ import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
......@@ -60,7 +61,9 @@ public class Simulator {
public SimulatorStatus connect(){
if(simulatorStatus.equals(SimulatorStatus.Disconnected)){
Log.d("Sim",System.currentTimeMillis()+": "+"simulator connecting thread");
connectThread();
Log.d("Sim",System.currentTimeMillis()+": "+"simulator has connected thread");
}
return simulatorStatus;
}
......@@ -107,6 +110,7 @@ public class Simulator {
}
private void connectThread() {
Log.d("Sim",System.currentTimeMillis()+": "+"simulator connecting thread interior");
activity.setProgress(10 * 100);
boolean remote = sharedPref.getBoolean(context.getString(R.string.pref_key_sim_global_remote), false);
if(remote){
......@@ -118,14 +122,18 @@ public class Simulator {
activity.setProgress(30 * 100);
simulation = new ModelSimulation(activity);
activity.setProgress(40 * 100);
Log.d("Sim",System.currentTimeMillis()+": "+"simulator pre preinitialize");
simulation.preInitialize();
Log.d("Sim",System.currentTimeMillis()+": "+"simulator post preinitialize");
thread = (SocketsThread) new SocketsThread(this,host,port).execute(simulation);
Log.d("Sim",System.currentTimeMillis()+": "+"end executing thread ");
}catch(NumberFormatException nfe){
}
}else{
// Local
}
activity.setProgress(100 * 100);
Log.d("Sim",System.currentTimeMillis()+": "+"simulator interior thread connected");
}
private void disconnectThread() {
......
......@@ -12,6 +12,7 @@ import java.net.UnknownHostException;
import org.orekit.propagation.SpacecraftState;
import cs.si.satatt.Parameters;
import cs.si.satatt.R;
import cs.si.satatt.SerializationUtil;
import model.ModelSimulation;
......@@ -19,7 +20,7 @@ import android.os.AsyncTask;
import android.util.Log;
import android.widget.Toast;
public class SocketsThread extends AsyncTask<ModelSimulation, SimResults, Boolean>{
public class SocketsThread extends AsyncTask<ModelSimulation, Void, Boolean>{
private String dstAddress;
private int dstPort;
......@@ -49,10 +50,12 @@ public class SocketsThread extends AsyncTask<ModelSimulation, SimResults, Boolea
}
}
private long time_tmp_data = 0;
@Override
protected Boolean doInBackground(ModelSimulation... params) {
if(simulator.getSimulatorStatus().equals(SimulatorStatus.Disconnected)){
Log.d("Sim",System.currentTimeMillis()+": "+"simulator connecting socket");
try {
socket = new Socket(dstAddress, dstPort);
socket.setTcpNoDelay(true);
......@@ -63,6 +66,7 @@ public class SocketsThread extends AsyncTask<ModelSimulation, SimResults, Boolea
setConnected();
simulator.goToHud();
simulator.showMessage(simulator.getContext().getString(R.string.sim_remote_simulator_connected));
Log.d("Sim",System.currentTimeMillis()+": "+"socket openend");
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
......@@ -77,14 +81,21 @@ public class SocketsThread extends AsyncTask<ModelSimulation, SimResults, Boolea
}
if(simulator.getSimulatorStatus().equals(SimulatorStatus.Connected)){
try {
Log.d("Sim",System.currentTimeMillis()+": "+"enter infinite loop");
while (true){
long procTime = System.currentTimeMillis();
Log.d("Sim",System.currentTimeMillis()+": "+"before readObject");
SpacecraftState sstate = (SpacecraftState) inputOStream.readObject();
Log.d("Sim",System.currentTimeMillis()+": "+"after readObject");
if(sstate!=null){
SimResults results = new SimResults(sstate, 0);
publishProgress(results);
if(time_tmp_data==0 || (System.nanoTime()-time_tmp_data)>Parameters.Simulator.min_hud_model_refreshing_interval_ns){
Log.d("Sim",System.currentTimeMillis()+": "+"update data");
time_tmp_data = System.nanoTime();
SimResults results = new SimResults(sstate, 0);
simulator.getSimulationResults().updateSimulation(results.spacecraftState, results.sim_progress);
Log.d("Sim",System.currentTimeMillis()+": "+"end update data");
}
publishProgress();
}
Log.d("Simulator", "Receive time: "+(System.currentTimeMillis()-procTime));
if(isCancelled())
break;
}
......@@ -105,13 +116,15 @@ public class SocketsThread extends AsyncTask<ModelSimulation, SimResults, Boolea
return true;
}
private long time_tmp_gui = 0;
@Override
protected void onProgressUpdate(SimResults... values) {
long procTime = System.currentTimeMillis();
simulator.getSimulationResults().updateSimulation(values[0].spacecraftState, values[0].sim_progress);
Log.d("Simulator", "Update time: "+(System.currentTimeMillis()-procTime));
protected void onProgressUpdate(Void... values) {
if(time_tmp_gui==0 || (System.nanoTime()-time_tmp_gui)>Parameters.Simulator.min_hud_panel_refreshing_interval_ns){
Log.d("Sim",System.currentTimeMillis()+": "+"update gui");
time_tmp_gui = System.nanoTime();
simulator.getSimulationResults().updateHUD();
Log.d("Sim",System.currentTimeMillis()+": "+"end update gui");
}
}
@Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment