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

String wifiData; String wifiData;
StringBuffer stringBufferWifi = new StringBuffer(); 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) {
stringToStringbuffer(data); stringToStringbuffer(data);
Log.d("buffer",stringBufferWifi.toString()); Log.d("buffer",stringBufferWifi.toString());
passToServiceListener(stringBufferWifi); passToServiceListener(stringBufferWifi);
checkState(data);
checkTyp(data);


} }
}); });
stringBufferWifi.append(string).append("\n"); 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

private final DatagramSocket socket; private final DatagramSocket socket;
volatile private boolean running; volatile private boolean running;


private boolean Gruppe =true;

private OnConnectionListener listener; private OnConnectionListener listener;
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
public WifiCommunication(int port) { public WifiCommunication(int port) {
} }


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 = "";


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(",");
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); } while (running);
} }
catch (IOException e) { catch (IOException e) {

Loading…
Cancel
Save