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

@@ -141,7 +141,7 @@ public class DetectorService extends LifecycleService {

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

@@ -151,6 +151,9 @@ public class DetectorService extends LifecycleService {

}




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

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

@@ -104,7 +104,7 @@ public class MainActivity extends AppCompatActivity {
detectorService.setOnDetectionListener(new DetectorService.OnDetectionListener() {
@Override
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

@@ -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;
}
}

Loading…
Cancel
Save