Kopie Master Version 1.3 UDP Socket merged with sensor, mit Fehler

This commit is contained in:
Miguel Siebenhaar 2023-06-21 14:27:53 +02:00
parent 5b042611a5
commit be1e52a9b0
3 changed files with 25 additions and 3 deletions

View File

@ -58,7 +58,9 @@ public class DetectorService extends LifecycleService {
@Override @Override
public void onDetection(@NonNull DetectionReport detectionReport) { public void onDetection(@NonNull DetectionReport detectionReport) {
//passToServiceListener(detectionReport); //passToServiceListener(detectionReport);
Log.d("Video", detectionReport.toMessage());
wifiCommunication.sendTrue(detectionReport.toMessage()); wifiCommunication.sendTrue(detectionReport.toMessage());
} }
}); });
/** Motion Detection**/ /** Motion Detection**/
@ -68,6 +70,7 @@ public class DetectorService extends LifecycleService {
@Override @Override
public void onDetection(@NonNull DetectionReport detectionReport) { public void onDetection(@NonNull DetectionReport detectionReport) {
//passToServiceListener(detectionReport); //passToServiceListener(detectionReport);
Log.d("Motion", detectionReport.toMessage());
wifiCommunication.sendTrue(detectionReport.toMessage()); wifiCommunication.sendTrue(detectionReport.toMessage());
} }
}); });
@ -77,6 +80,7 @@ public class DetectorService extends LifecycleService {
@Override @Override
public void onDetection(@NonNull DetectionReport detectionReport) { public void onDetection(@NonNull DetectionReport detectionReport) {
//passToServiceListener(detectionReport); //passToServiceListener(detectionReport);
Log.d("Audio", detectionReport.toMessage());
wifiCommunication.sendTrue(detectionReport.toMessage()); wifiCommunication.sendTrue(detectionReport.toMessage());
} }
}); });

View File

@ -22,6 +22,7 @@ import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import android.widget.ToggleButton;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
@ -38,7 +39,7 @@ import java.nio.ByteOrder;
@ExperimentalGetImage @ExperimentalGetImage
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
WifiCommunication communication; //WifiCommunication communication;
PermissionRequest permission; PermissionRequest permission;
boolean communicationRunning = true; boolean communicationRunning = true;
TextView textview1; TextView textview1;
@ -53,6 +54,19 @@ public class MainActivity extends AppCompatActivity {
Intent serviceIntent = new Intent(this, DetectorService.class); Intent serviceIntent = new Intent(this, DetectorService.class);
bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE); bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE);
startService(serviceIntent); 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); //textview1 = findViewById(R.id.textView1);
//Button button1 = findViewById(R.id.buttonSend); //Button button1 = findViewById(R.id.buttonSend);
@ -87,7 +101,7 @@ public class MainActivity extends AppCompatActivity {
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
if (communicationRunning){ /*if (communicationRunning){
communication = new WifiCommunication(1234); communication = new WifiCommunication(1234);
communication.setOnConnectionListener(new WifiCommunication.OnConnectionListener() { communication.setOnConnectionListener(new WifiCommunication.OnConnectionListener() {
@Override @Override
@ -102,7 +116,7 @@ public class MainActivity extends AppCompatActivity {
} }
}); });
communicationRunning = false; communicationRunning = false;
} }*/
permission = new PermissionRequest(MainActivity.this); permission = new PermissionRequest(MainActivity.this);
permission.rechtePruefen(); permission.rechtePruefen();
} }

View File

@ -1,5 +1,6 @@
package com.example.ueberwachungssystem; package com.example.ueberwachungssystem;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -77,9 +78,11 @@ public class WifiCommunication {
socket.receive(rxPacket); socket.receive(rxPacket);
rxString = new String(receiveData, 0, rxPacket.getLength()); rxString = new String(receiveData, 0, rxPacket.getLength());
String[] splitrxString = rxString.split(","); String[] splitrxString = rxString.split(",");
Log.d("empfangen", rxString);
if(!previousRxString.equals(rxString) && splitrxString[0].equals("1") && splitrxString.length==7) { if(!previousRxString.equals(rxString) && splitrxString[0].equals("1") && splitrxString.length==7) {
//rxStringBuffer.append(rxString).append("\n"); //rxStringBuffer.append(rxString).append("\n");
sendWifiData(rxString); sendWifiData(rxString);
//mainActivity.runOnUiThread(() -> mainActivity.tvMessages.setText(rxStringBuffer)); //mainActivity.runOnUiThread(() -> mainActivity.tvMessages.setText(rxStringBuffer));
previousRxString = rxString; previousRxString = rxString;
} }
@ -107,6 +110,7 @@ public class WifiCommunication {
for(int i = 0; i < 500; i++) { for(int i = 0; i < 500; i++) {
socket.send(txPacket); socket.send(txPacket);
Log.d("senden", txPacket.getData().toString());
} }
} }
} while (running); } while (running);