|
|
@@ -32,6 +32,9 @@ public class WifiCommunication { |
|
|
|
volatile private boolean running; |
|
|
|
|
|
|
|
private boolean Gruppe =true; |
|
|
|
private boolean showMessage = true; |
|
|
|
|
|
|
|
StringBuffer rxStringBuffer = new StringBuffer(); |
|
|
|
|
|
|
|
private OnConnectionListener listener; |
|
|
|
@SuppressLint("SetTextI18n") |
|
|
@@ -80,16 +83,31 @@ public class WifiCommunication { |
|
|
|
socket.receive(rxPacket); |
|
|
|
rxString = new String(receiveData, 0, rxPacket.getLength()); |
|
|
|
String[] splitrxString = rxString.split(","); |
|
|
|
String[] splitrxStringBuffer = splitBufferIntoStrings(rxStringBuffer); |
|
|
|
for(String elem: splitrxStringBuffer){ |
|
|
|
if(elem.equals(rxString)){ |
|
|
|
showMessage = false; |
|
|
|
}else{ |
|
|
|
showMessage = true; |
|
|
|
} |
|
|
|
} |
|
|
|
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); |
|
|
|
sendWifiData(rxString); |
|
|
|
//mainActivity.runOnUiThread(() -> mainActivity.tvMessages.setText(rxStringBuffer)); |
|
|
|
previousRxString = rxString; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} while (running); |
|
|
|
} |
|
|
|
catch (IOException e) { |
|
|
@@ -106,9 +124,9 @@ public class WifiCommunication { |
|
|
|
if(send) |
|
|
|
{ |
|
|
|
send = false; |
|
|
|
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss"); |
|
|
|
/*SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss"); |
|
|
|
Date curDate = new Date(System.currentTimeMillis()); |
|
|
|
String str = formatter.format(curDate); |
|
|
|
String str = formatter.format(curDate);*/ |
|
|
|
byte[] send_Data = new byte[512]; |
|
|
|
String txString = (messageToSend); //"1," +str+ ",Gruppe2," + getLocalIpAddress() + ",An,Video," |
|
|
|
Log.d("send", txString); |
|
|
@@ -116,7 +134,7 @@ public class WifiCommunication { |
|
|
|
|
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
@@ -151,4 +169,8 @@ public class WifiCommunication { |
|
|
|
running = false; |
|
|
|
socket.close(); |
|
|
|
} |
|
|
|
public String[] splitBufferIntoStrings(StringBuffer string){ |
|
|
|
String[] splitrxString2 = string.toString().split("\n"); |
|
|
|
return splitrxString2; |
|
|
|
} |
|
|
|
} |