Compare commits

..

No commits in common. "3d9e6b7a3e57f8624a1a5d1441df67b875bbd62f" and "1eba8e0f7c6f4edd841fb6f57650170e0877e5a5" have entirely different histories.

6 changed files with 33 additions and 162 deletions

View File

@ -3,7 +3,6 @@ package com.example.ueberwachungssystem.Detection;
import android.content.Intent; import android.content.Intent;
import android.os.Binder; import android.os.Binder;
import android.os.IBinder; import android.os.IBinder;
import android.util.Log;
import android.widget.ImageView; import android.widget.ImageView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -11,8 +10,6 @@ import androidx.annotation.Nullable;
import androidx.camera.core.ExperimentalGetImage; import androidx.camera.core.ExperimentalGetImage;
import androidx.lifecycle.LifecycleService; import androidx.lifecycle.LifecycleService;
import com.example.ueberwachungssystem.WifiCommunication;
import java.io.File; import java.io.File;
@ExperimentalGetImage @ExperimentalGetImage
@ -27,38 +24,12 @@ public class DetectorService extends LifecycleService {
public Accelerometer motionDetector = null; public Accelerometer motionDetector = null;
public MicrophoneDetector audioDetector = null; public MicrophoneDetector audioDetector = null;
public WifiCommunication wifiCommunication;
String wifiData;
StringBuffer stringBufferWifi = new StringBuffer();
String typOfAlarm;
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
if (isServiceRunning) if (isServiceRunning)
return START_NOT_STICKY; return START_NOT_STICKY;
/** Wifi Instanz **/
wifiCommunication = new WifiCommunication(1234);
wifiCommunication.sendTrue("TEst");
wifiCommunication.setOnConnectionListener(new WifiCommunication.OnConnectionListener() {
@Override
public void onConnection(String data) {
Log.d("Listener", data);
wifiData = data;
stringToStringbuffer(data);
Log.d("buffer",stringBufferWifi.toString());
passToServiceListener(stringBufferWifi);
checkState(data);
checkTyp(data);
}
});
@ -67,8 +38,7 @@ public class DetectorService extends LifecycleService {
videoDetector.setOnDetectionListener(new Detector.OnDetectionListener() { videoDetector.setOnDetectionListener(new Detector.OnDetectionListener() {
@Override @Override
public void onDetection(@NonNull DetectionReport detectionReport) { public void onDetection(@NonNull DetectionReport detectionReport) {
//passToServiceListener(detectionReport); passToServiceListener(detectionReport);
wifiCommunication.sendTrue(detectionReport.toMessage());
} }
}); });
/** Motion Detection**/ /** Motion Detection**/
@ -77,8 +47,7 @@ public class DetectorService extends LifecycleService {
motionDetector.setOnDetectionListener(new Detector.OnDetectionListener() { motionDetector.setOnDetectionListener(new Detector.OnDetectionListener() {
@Override @Override
public void onDetection(@NonNull DetectionReport detectionReport) { public void onDetection(@NonNull DetectionReport detectionReport) {
//passToServiceListener(detectionReport); passToServiceListener(detectionReport);
wifiCommunication.sendTrue(detectionReport.toMessage());
} }
}); });
/** Audio Detection **/ /** Audio Detection **/
@ -86,8 +55,7 @@ public class DetectorService extends LifecycleService {
audioDetector.setOnDetectionListener(new Detector.OnDetectionListener() { audioDetector.setOnDetectionListener(new Detector.OnDetectionListener() {
@Override @Override
public void onDetection(@NonNull DetectionReport detectionReport) { public void onDetection(@NonNull DetectionReport detectionReport) {
//passToServiceListener(detectionReport); passToServiceListener(detectionReport);
wifiCommunication.sendTrue(detectionReport.toMessage());
} }
}); });
/** Audio Recorder**/ /** Audio Recorder**/
@ -124,44 +92,18 @@ public class DetectorService extends LifecycleService {
/** Pass Detection Report to Service Detection Listener and trigger it */ /** Pass Detection Report to Service Detection Listener and trigger it */
public void passToServiceListener(StringBuffer stringBuffer) { public void passToServiceListener(DetectionReport detectionReport) {
if (listener != null) { if (listener != null) {
listener.onDetection(stringBuffer); listener.onDetection(detectionReport);
} }
} }
/** On Detection Listener - runs when violation is reported */ /** On Detection Listener - runs when violation is reported */
public interface OnDetectionListener { public interface OnDetectionListener {
void onDetection(@NonNull StringBuffer stringBuffer); void onDetection(@NonNull DetectionReport detectionReport);
} }
public void setOnDetectionListener(@NonNull DetectorService.OnDetectionListener listener) { public void setOnDetectionListener(@NonNull DetectorService.OnDetectionListener listener) {
this.listener = listener; this.listener = listener;
} }
public void stringToStringbuffer(String string){
if(string != null) {
stringBufferWifi.insert(0,string + "\n");
}
}
public String[] splitString(String string){
String[] splitrxString = string.split(",");
return splitrxString; //splitrxString[0] = "1",splitrxString[1] = "HH:MM:SS", splitrxString[0].equals("1")
}
public boolean checkState(String string){
Log.d("state", String.valueOf(splitString(string)[4].equals("An")));
return splitString(string)[4].equals("An");
}
public String checkTyp(String string){
if (splitString(string)[5] != null) {
typOfAlarm = splitString(string)[5];
Log.d("Type", typOfAlarm);
}
return typOfAlarm;
}
} }

View File

@ -12,11 +12,8 @@ import android.content.ServiceConnection;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.util.Log; import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.Toast;
import android.widget.ToggleButton; import android.widget.ToggleButton;
import com.example.ueberwachungssystem.Detection.Accelerometer; import com.example.ueberwachungssystem.Detection.Accelerometer;
@ -34,31 +31,28 @@ public class MainActivity extends AppCompatActivity {
ImageView inputImageView; ImageView inputImageView;
ImageView outputImageView; ImageView outputImageView;
ToggleButton toggleButton; ToggleButton toggleButton;
int num=0;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
inputImageView = findViewById(R.id.inputImageView); inputImageView = findViewById(R.id.inputImageView);
outputImageView = findViewById(R.id.outputImageView); outputImageView = findViewById(R.id.outputImageView);
toggleButton = findViewById(R.id.toggleButton); toggleButton = findViewById(R.id.toggleButton);
}
@Override
protected void onResume() {
super.onResume();
PermissionHandler permissionHandler = new PermissionHandler(this); PermissionHandler permissionHandler = new PermissionHandler(this);
//permissionHandler.getPermissions(); permissionHandler.getPermissions();
if (permissionHandler.hasPermissions()) { if (permissionHandler.hasPermissions()) {
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.setOnClickListener(new View.OnClickListener() { toggleButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -66,6 +60,7 @@ public class MainActivity extends AppCompatActivity {
{ {
if (detectorService != null){ if (detectorService != null){
detectorService.videoDetector.debugProcessing(inputImageView, outputImageView);
detectorService.videoDetector.startDetection(); detectorService.videoDetector.startDetection();
detectorService.audioDetector.startDetection(); detectorService.audioDetector.startDetection();
@ -90,42 +85,13 @@ public class MainActivity extends AppCompatActivity {
} }
} }
}); });
}else{
Toast.makeText(this,"Bitte Rechte geben", Toast.LENGTH_SHORT).show();
}
}
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.options_menu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
Toast.makeText(this, "Selected Item: " + item.getTitle(), Toast.LENGTH_SHORT).show();
PopUpClass popUpClass;
switch (item.getItemId()) {
case R.id.Rechteverwaltung:
popUpClass = new PopUpClass(MainActivity.this);
popUpClass.showPopupWindow(inputImageView);
popUpClass.RechtePrüfen();
return true;
case R.id.Sensoren:
popUpClass = new PopUpClass(MainActivity.this);
popUpClass.showPopupWindow(inputImageView);
popUpClass.Sensoren();
return true;
case R.id.Impressum:
popUpClass = new PopUpClass(MainActivity.this);
popUpClass.showPopupWindow(inputImageView);
popUpClass.Impressum();
return true;
case R.id.Detection:
popUpClass = new PopUpClass(MainActivity.this);
popUpClass.showPopupWindow(inputImageView);
popUpClass.DetectionTotal(num);
return true;
default:
return super.onOptionsItemSelected(item);
} }
} }
@ -134,18 +100,15 @@ public class MainActivity extends AppCompatActivity {
public void onServiceConnected(ComponentName name, IBinder service) { public void onServiceConnected(ComponentName name, IBinder service) {
DetectorService.ServiceBinder binder = (DetectorService.ServiceBinder) service; DetectorService.ServiceBinder binder = (DetectorService.ServiceBinder) service;
detectorService = binder.getBoundService(); detectorService = binder.getBoundService();
detectorService.videoDetector.debugProcessing(null, outputImageView); //inputImageView
detectorService.setOnDetectionListener(new DetectorService.OnDetectionListener() { detectorService.setOnDetectionListener(new DetectorService.OnDetectionListener() {
@Override @Override
public void onDetection(@NonNull StringBuffer stringBuffer) { public void onDetection(@NonNull DetectionReport detectionReport) {
Log.d("onDetection", stringBuffer.toString()); //Für oli hier Textview einbauen Log.d("onDetection", detectionReport.toMessage());
num++;
} }
}); });
} }
@Override @Override
public void onServiceDisconnected(ComponentName name) { public void onServiceDisconnected(ComponentName name) {}
}
}; };
} }

View File

@ -35,7 +35,7 @@ public class PermissionRequest extends AppCompatActivity{
handler.post(new Runnable() { handler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
Toast.makeText(mainActivity.getApplicationContext(),"Es werden Rechte benötigt", Toast.LENGTH_SHORT).show(); Toast.makeText(mainActivity.getApplicationContext(),"Es werden Rechte benötigt", Toast.LENGTH_LONG).show();
} }
}); });
} }

View File

@ -82,7 +82,5 @@ public class PopUpClass {
public void Impressum(){ public void Impressum(){
PopUpText.setText("Die Ueberwachungsapp wurde im Rahmen eines Praktikums der TH-Nürnberg programmiert"); PopUpText.setText("Die Ueberwachungsapp wurde im Rahmen eines Praktikums der TH-Nürnberg programmiert");
} }
public void DetectionTotal(int num) {
PopUpText.setText("Total Detektions:" +num);
}
} }

View File

@ -1,6 +1,5 @@
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;
@ -31,11 +30,6 @@ public class WifiCommunication {
private final DatagramSocket socket; private final DatagramSocket socket;
volatile private boolean running; volatile private boolean running;
private boolean Gruppe =true;
private boolean showMessage = true;
StringBuffer rxStringBuffer = new StringBuffer();
private OnConnectionListener listener; private OnConnectionListener listener;
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
public WifiCommunication(int port) { public WifiCommunication(int port) {
@ -57,20 +51,20 @@ public class WifiCommunication {
} }
public interface OnConnectionListener { public interface OnConnectionListener {
void onConnection(String data); void onConnection(StringBuffer data);
} }
public void setOnConnectionListener(@NonNull OnConnectionListener listener) { public void setOnConnectionListener(@NonNull OnConnectionListener listener) {
this.listener = listener; this.listener = listener;
} }
public void sendWifiData(String wifiMessage) { public void sendWifiData(StringBuffer wifiMessage) {
if (listener != null) { if (listener != null) {
listener.onConnection(wifiMessage); listener.onConnection(wifiMessage);
} }
} }
private class ReceiveThread extends Thread { private class ReceiveThread extends Thread {
private StringBuffer rxStringBuffer = new StringBuffer();
private String rxString=""; private String rxString="";
private String previousRxString = ""; private String previousRxString = "";
@ -83,30 +77,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(",");
String[] splitrxStringBuffer = splitBufferIntoStrings(rxStringBuffer); if(!previousRxString.equals(rxString) && splitrxString[0].equals("1") && splitrxString.length==7) {
for(String elem: splitrxStringBuffer){ rxStringBuffer.append(rxString).append("\n");
if(elem.equals(rxString)){ sendWifiData(rxStringBuffer);
showMessage = false; //mainActivity.runOnUiThread(() -> mainActivity.tvMessages.setText(rxStringBuffer));
}else{ previousRxString = rxString;
showMessage = true;
}
}
if(Gruppe){
if(!previousRxString.equals(rxString) && splitrxString[0].equals("1") && splitrxString.length==7 && showMessage) {
rxStringBuffer.append(rxString).append("\n");
Log.d("empfangen", rxString);
sendWifiData(rxString);
//mainActivity.runOnUiThread(() -> mainActivity.tvMessages.setText(rxStringBuffer));
previousRxString = rxString;
}
}else{
if(!previousRxString.equals(rxString) && splitrxString[0].equals("1") && splitrxString.length==7 && showMessage) {
rxStringBuffer.append(rxString).append("\n");
Log.d("empfangen", rxString);
sendWifiData(rxString);
//mainActivity.runOnUiThread(() -> mainActivity.tvMessages.setText(rxStringBuffer));
previousRxString = rxString;
}
} }
} while (running); } while (running);
} }
@ -124,17 +99,16 @@ public class WifiCommunication {
if(send) if(send)
{ {
send = false; send = false;
/*SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss"); SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
Date curDate = new Date(System.currentTimeMillis()); Date curDate = new Date(System.currentTimeMillis());
String str = formatter.format(curDate);*/ String str = formatter.format(curDate);
byte[] send_Data = new byte[512]; byte[] send_Data = new byte[512];
String txString = (messageToSend); //"1," +str+ ",Gruppe2," + getLocalIpAddress() + ",An,Video," String txString = ("1," +str+ ",Gruppe2," + getLocalIpAddress() + ",An,Video," +messageToSend);
Log.d("send", txString);
send_Data = txString.getBytes(); send_Data = txString.getBytes();
DatagramPacket txPacket = new DatagramPacket(send_Data, txString.length(), address, port); DatagramPacket txPacket = new DatagramPacket(send_Data, txString.length(), address, port);
for(int i = 0; i < 500; i++) { for(int i = 0; i < 300; i++) {
socket.send(txPacket); socket.send(txPacket);
} }
} }
@ -169,8 +143,4 @@ public class WifiCommunication {
running = false; running = false;
socket.close(); socket.close();
} }
public String[] splitBufferIntoStrings(StringBuffer string){
String[] splitrxString2 = string.toString().split("\n");
return splitrxString2;
}
} }

View File

@ -4,8 +4,6 @@
android:title="Rechteverwaltung" /> android:title="Rechteverwaltung" />
<item android:id="@+id/Sensoren" <item android:id="@+id/Sensoren"
android:title="Sensoren" /> android:title="Sensoren" />
<item android:id="@+id/Detection"
android:title="Detektionen" />
<item android:id="@+id/Impressum" <item android:id="@+id/Impressum"
android:title="Impressum" /> android:title="Impressum" />
</menu> </menu>