Browse Source

Error handling

master
Vanessa Bock 1 year ago
parent
commit
a34657dc1a

+ 1
- 1
MobileApp/.idea/misc.xml View File

</map> </map>
</option> </option>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="11" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">

+ 1
- 1
MobileApp/app/src/main/java/com/example/lfrmobileapp/MainActivity.java View File

private ActivityMainBinding binding; private ActivityMainBinding binding;
private ExtendedSocket socket; private ExtendedSocket socket;
private DataTransferAsyncTask dataTransferAsyncTask; private DataTransferAsyncTask dataTransferAsyncTask;
Boolean connected = false;
public Boolean connected = false;


@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {

+ 15
- 6
MobileApp/app/src/main/java/com/example/lfrmobileapp/ui/dashboard/DashboardFragment.java View File



import com.example.lfrmobileapp.Communication; import com.example.lfrmobileapp.Communication;
import com.example.lfrmobileapp.DataTransferAsyncTask; import com.example.lfrmobileapp.DataTransferAsyncTask;
import com.example.lfrmobileapp.MainActivity;
import com.example.lfrmobileapp.R; import com.example.lfrmobileapp.R;
import com.example.lfrmobileapp.databinding.FragmentAutomatikBinding; import com.example.lfrmobileapp.databinding.FragmentAutomatikBinding;




import kotlin.collections.UArraySortingKt; import kotlin.collections.UArraySortingKt;


// Autonomous Mode
public class DashboardFragment extends Fragment { public class DashboardFragment extends Fragment {
Communication com = new Communication(); Communication com = new Communication();
private FragmentAutomatikBinding binding; private FragmentAutomatikBinding binding;


MainActivity mainActivity;

//Keys for Shared Preferences //Keys for Shared Preferences
String listKey = "listkey"; String listKey = "listkey";


DataTransferAsyncTask dataTransferAsyncTask;
@Override
public void onAttach(Context context) {
super.onAttach(context);
mainActivity = (MainActivity) context;
}


public View onCreateView(@NonNull LayoutInflater inflater, public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) { ViewGroup container, Bundle savedInstanceState) {


@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
dataTransferAsyncTask.writeTelegram(com.telegram(true, autoList));
}else{
dataTransferAsyncTask.writeTelegram(com.telegram(false, autoList));
if (mainActivity.connected){
if(isChecked){
mainActivity.sendTelegram(com.telegram(true, autoList));
}else{
mainActivity.sendTelegram(com.telegram(false, autoList));
}
} }
} }
}); });
@Override @Override
public void onDestroyView() { public void onDestroyView() {
super.onDestroyView(); super.onDestroyView();
dataTransferAsyncTask.cancel(false);
binding = null; binding = null;
} }



+ 27
- 13
MobileApp/app/src/main/java/com/example/lfrmobileapp/ui/home/HomeFragment.java View File

import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility")
@Override @Override
public boolean onTouch(View v, MotionEvent event) { public boolean onTouch(View v, MotionEvent event) {

if(event.getAction() == MotionEvent.ACTION_UP){
boolean send = false;
if (System.currentTimeMillis() - lastOnMoveCall > 250){
send = true;
lastOnMoveCall = System.currentTimeMillis();
}
if (send && mainActivity.connected) {
if (event.getAction() == MotionEvent.ACTION_UP) {
binding.rotateLeft.performClick(); binding.rotateLeft.performClick();
mainActivity.sendTelegram(com.telegram(new int[]{0, 0, 0, 0}, 0)); mainActivity.sendTelegram(com.telegram(new int[]{0, 0, 0, 0}, 0));
return true; return true;
}else{
} else {
mainActivity.sendTelegram(com.telegram(new int[]{-1, 1, -1, 1}, 100)); mainActivity.sendTelegram(com.telegram(new int[]{-1, 1, -1, 1}, 100));
} }
return false;
} }
});
return false;
}
});


binding.rotateRight.setOnTouchListener(new View.OnTouchListener(){ binding.rotateRight.setOnTouchListener(new View.OnTouchListener(){
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility")
@Override @Override
public boolean onTouch(View v, MotionEvent event) { public boolean onTouch(View v, MotionEvent event) {

if(event.getAction() == MotionEvent.ACTION_UP){
binding.rotateRight.performClick();
mainActivity.sendTelegram(com.telegram(new int[]{0, 0, 0, 0}, 0));
return true;
}else{
mainActivity.sendTelegram(com.telegram(new int[]{1, -1, 1, -1}, 100));
boolean send = false;
if (System.currentTimeMillis() - lastOnMoveCall > 250){
send = true;
lastOnMoveCall = System.currentTimeMillis();
}
if (send && mainActivity.connected){
if(event.getAction() == MotionEvent.ACTION_UP){
binding.rotateRight.performClick();
mainActivity.sendTelegram(com.telegram(new int[]{0, 0, 0, 0}, 0));
return true;
}else{
mainActivity.sendTelegram(com.telegram(new int[]{1, -1, 1, -1}, 100));
}
} }
return false; return false;
} }
joystick.setBackgroundResource(R.mipmap.blank); joystick.setBackgroundResource(R.mipmap.blank);
telegram = com.telegram(new int[]{0, 0, 0, 0}, strength); telegram = com.telegram(new int[]{0, 0, 0, 0}, strength);
} }
if (send)
if (send && mainActivity.connected)
{ {
mainActivity.sendTelegram(telegram); mainActivity.sendTelegram(telegram);
// Log.v("TAG", telegram + "\n");
} }
} }
}); });

+ 8
- 4
MobileApp/app/src/main/java/com/example/lfrmobileapp/ui/notifications/NotificationsFragment.java View File

String connectionFailed = "Verbindung fehlgeschlagen."; String connectionFailed = "Verbindung fehlgeschlagen.";
String connectionSuccessful = "Verbindung erfolgreich."; String connectionSuccessful = "Verbindung erfolgreich.";


String ipAddress = "192.168.0.1";
int port = 8000;
String ipAddress = "192.168.4.1";
int port = 8080;


int duration = Toast.LENGTH_LONG; int duration = Toast.LENGTH_LONG;
DataTransferAsyncTask dataTransferAsyncTask; DataTransferAsyncTask dataTransferAsyncTask;
final Button button = binding.connect; final Button button = binding.connect;
button.setOnClickListener(new View.OnClickListener() { button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
ipAddress = String.valueOf(binding.ipAdress.getText());
port = Integer.parseInt(String.valueOf(binding.port.getText()));
try {
ipAddress = String.valueOf(binding.ipAdress.getText());
port = Integer.parseInt(String.valueOf(binding.port.getText()));
} catch (Exception e){
System.err.println("Parse Exception: " + e.getMessage());
}


connected = mainActivity.connectToWifi(ipAddress, port); connected = mainActivity.connectToWifi(ipAddress, port);



Loading…
Cancel
Save