Browse Source

Version 2. working

ms_service_copie
Miguel Siebenhaar 1 year ago
parent
commit
e571373fbb

+ 23
- 0
app/src/main/java/com/example/ueberwachungssystem/Detection/DetectorService.java View File

@@ -32,6 +32,8 @@ public class DetectorService extends LifecycleService {
String wifiData;
StringBuffer stringBufferWifi = new StringBuffer();

String typOfAlarm;


@Override
public int onStartCommand(Intent intent, int flags, int startId) {
@@ -50,6 +52,8 @@ public class DetectorService extends LifecycleService {
stringToStringbuffer(data);
Log.d("buffer",stringBufferWifi.toString());
passToServiceListener(stringBufferWifi);
checkState(data);
checkTyp(data);

}
});
@@ -140,4 +144,23 @@ public class DetectorService extends LifecycleService {
stringBufferWifi.append(string).append("\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;
}
}

+ 11
- 7
app/src/main/java/com/example/ueberwachungssystem/WifiCommunication.java View File

@@ -31,6 +31,8 @@ public class WifiCommunication {
private final DatagramSocket socket;
volatile private boolean running;

private boolean Gruppe =true;

private OnConnectionListener listener;
@SuppressLint("SetTextI18n")
public WifiCommunication(int port) {
@@ -66,7 +68,6 @@ public class WifiCommunication {
}

private class ReceiveThread extends Thread {
private StringBuffer rxStringBuffer = new StringBuffer();
private String rxString="";
private String previousRxString = "";

@@ -79,13 +80,16 @@ public class WifiCommunication {
socket.receive(rxPacket);
rxString = new String(receiveData, 0, rxPacket.getLength());
String[] splitrxString = rxString.split(",");
if(!previousRxString.equals(rxString) && splitrxString[0].equals("1") && splitrxString.length==7) {
//rxStringBuffer.append(rxString).append("\n");
Log.d("empfangen", rxString);
sendWifiData(rxString);
//mainActivity.runOnUiThread(() -> mainActivity.tvMessages.setText(rxStringBuffer));
previousRxString = rxString;
if(Gruppe){
if(!previousRxString.equals(rxString) && splitrxString[0].equals("1") && splitrxString.length==7) {
//rxStringBuffer.append(rxString).append("\n");
Log.d("empfangen", rxString);
sendWifiData(rxString);
//mainActivity.runOnUiThread(() -> mainActivity.tvMessages.setText(rxStringBuffer));
previousRxString = rxString;
}
}

} while (running);
}
catch (IOException e) {

Loading…
Cancel
Save