From be1e52a9b0422e52b07d3fbe617a6ae7ca1b22d2 Mon Sep 17 00:00:00 2001 From: Miguel Siebenhaar Date: Wed, 21 Jun 2023 14:27:53 +0200 Subject: [PATCH] Kopie Master Version 1.3 UDP Socket merged with sensor, mit Fehler --- .../Detection/DetectorService.java | 4 ++++ .../ueberwachungssystem/MainActivity.java | 20 ++++++++++++++++--- .../WifiCommunication.java | 4 ++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/example/ueberwachungssystem/Detection/DetectorService.java b/app/src/main/java/com/example/ueberwachungssystem/Detection/DetectorService.java index dab5508..7a985c0 100644 --- a/app/src/main/java/com/example/ueberwachungssystem/Detection/DetectorService.java +++ b/app/src/main/java/com/example/ueberwachungssystem/Detection/DetectorService.java @@ -58,7 +58,9 @@ public class DetectorService extends LifecycleService { @Override public void onDetection(@NonNull DetectionReport detectionReport) { //passToServiceListener(detectionReport); + Log.d("Video", detectionReport.toMessage()); wifiCommunication.sendTrue(detectionReport.toMessage()); + } }); /** Motion Detection**/ @@ -68,6 +70,7 @@ public class DetectorService extends LifecycleService { @Override public void onDetection(@NonNull DetectionReport detectionReport) { //passToServiceListener(detectionReport); + Log.d("Motion", detectionReport.toMessage()); wifiCommunication.sendTrue(detectionReport.toMessage()); } }); @@ -77,6 +80,7 @@ public class DetectorService extends LifecycleService { @Override public void onDetection(@NonNull DetectionReport detectionReport) { //passToServiceListener(detectionReport); + Log.d("Audio", detectionReport.toMessage()); wifiCommunication.sendTrue(detectionReport.toMessage()); } }); diff --git a/app/src/main/java/com/example/ueberwachungssystem/MainActivity.java b/app/src/main/java/com/example/ueberwachungssystem/MainActivity.java index 528725f..ea4b3d6 100644 --- a/app/src/main/java/com/example/ueberwachungssystem/MainActivity.java +++ b/app/src/main/java/com/example/ueberwachungssystem/MainActivity.java @@ -22,6 +22,7 @@ import android.view.View; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; +import android.widget.ToggleButton; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; @@ -38,7 +39,7 @@ import java.nio.ByteOrder; @ExperimentalGetImage public class MainActivity extends AppCompatActivity { - WifiCommunication communication; + //WifiCommunication communication; PermissionRequest permission; boolean communicationRunning = true; TextView textview1; @@ -53,6 +54,19 @@ public class MainActivity extends AppCompatActivity { Intent serviceIntent = new Intent(this, DetectorService.class); bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE); startService(serviceIntent); + ToggleButton button1 = findViewById(R.id.toggleButton); + button1.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if(button1.isChecked()){ + if(detectorService != null){ + detectorService.videoDetector.startDetection(); + } + }else{ + detectorService.videoDetector.stopDetection(); + } + } + }); //textview1 = findViewById(R.id.textView1); //Button button1 = findViewById(R.id.buttonSend); @@ -87,7 +101,7 @@ public class MainActivity extends AppCompatActivity { @Override protected void onResume() { super.onResume(); - if (communicationRunning){ + /*if (communicationRunning){ communication = new WifiCommunication(1234); communication.setOnConnectionListener(new WifiCommunication.OnConnectionListener() { @Override @@ -102,7 +116,7 @@ public class MainActivity extends AppCompatActivity { } }); communicationRunning = false; - } + }*/ permission = new PermissionRequest(MainActivity.this); permission.rechtePruefen(); } diff --git a/app/src/main/java/com/example/ueberwachungssystem/WifiCommunication.java b/app/src/main/java/com/example/ueberwachungssystem/WifiCommunication.java index fc4c220..191cbcc 100644 --- a/app/src/main/java/com/example/ueberwachungssystem/WifiCommunication.java +++ b/app/src/main/java/com/example/ueberwachungssystem/WifiCommunication.java @@ -1,5 +1,6 @@ package com.example.ueberwachungssystem; import android.annotation.SuppressLint; +import android.util.Log; import android.widget.Toast; import androidx.annotation.NonNull; @@ -77,9 +78,11 @@ public class WifiCommunication { socket.receive(rxPacket); rxString = new String(receiveData, 0, rxPacket.getLength()); String[] splitrxString = rxString.split(","); + Log.d("empfangen", rxString); if(!previousRxString.equals(rxString) && splitrxString[0].equals("1") && splitrxString.length==7) { //rxStringBuffer.append(rxString).append("\n"); sendWifiData(rxString); + //mainActivity.runOnUiThread(() -> mainActivity.tvMessages.setText(rxStringBuffer)); previousRxString = rxString; } @@ -107,6 +110,7 @@ public class WifiCommunication { for(int i = 0; i < 500; i++) { socket.send(txPacket); + Log.d("senden", txPacket.getData().toString()); } } } while (running);