Browse Source

Version 2.1 working

ms_service_copie
Miguel Siebenhaar 1 year ago
parent
commit
edcf555b5b

+ 4
- 1
app/src/main/java/com/example/ueberwachungssystem/Detection/DetectorService.java View File



public void stringToStringbuffer(String string){ public void stringToStringbuffer(String string){
if(string != null) { if(string != null) {
stringBufferWifi.append(string).append("\n");
stringBufferWifi.insert(0,string + "\n");
} }
} }




} }





public boolean checkState(String string){ public boolean checkState(String string){
Log.d("state", String.valueOf(splitString(string)[4].equals("An"))); Log.d("state", String.valueOf(splitString(string)[4].equals("An")));
return splitString(string)[4].equals("An"); return splitString(string)[4].equals("An");

+ 1
- 1
app/src/main/java/com/example/ueberwachungssystem/MainActivity.java View File

detectorService.setOnDetectionListener(new DetectorService.OnDetectionListener() { detectorService.setOnDetectionListener(new DetectorService.OnDetectionListener() {
@Override @Override
public void onDetection(@NonNull StringBuffer stringBuffer) { public void onDetection(@NonNull StringBuffer stringBuffer) {
Log.d("onDetection", stringBuffer.toString());
Log.d("onDetection", stringBuffer.toString()); //Für oli hier Textview einbauen
} }
}); });
} }

+ 28
- 6
app/src/main/java/com/example/ueberwachungssystem/WifiCommunication.java View File

volatile private boolean running; volatile private boolean running;


private boolean Gruppe =true; private boolean Gruppe =true;
private boolean showMessage = true;

StringBuffer rxStringBuffer = new StringBuffer();


private OnConnectionListener listener; private OnConnectionListener listener;
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
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);
for(String elem: splitrxStringBuffer){
if(elem.equals(rxString)){
showMessage = false;
}else{
showMessage = true;
}
}
if(Gruppe){ if(Gruppe){
if(!previousRxString.equals(rxString) && splitrxString[0].equals("1") && splitrxString.length==7) {
//rxStringBuffer.append(rxString).append("\n");
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); Log.d("empfangen", rxString);
sendWifiData(rxString); sendWifiData(rxString);
//mainActivity.runOnUiThread(() -> mainActivity.tvMessages.setText(rxStringBuffer)); //mainActivity.runOnUiThread(() -> mainActivity.tvMessages.setText(rxStringBuffer));
previousRxString = rxString; previousRxString = rxString;
} }
} }

} while (running); } while (running);
} }
catch (IOException e) { catch (IOException e) {
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 = (messageToSend); //"1," +str+ ",Gruppe2," + getLocalIpAddress() + ",An,Video,"
Log.d("send", txString); Log.d("send", txString);


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 < 300; i++) {
for(int i = 0; i < 500; i++) {
socket.send(txPacket); socket.send(txPacket);
} }
} }
running = false; running = false;
socket.close(); socket.close();
} }
public String[] splitBufferIntoStrings(StringBuffer string){
String[] splitrxString2 = string.toString().split("\n");
return splitrxString2;
}
} }

Loading…
Cancel
Save