Compare commits
No commits in common. "44e056b5fe62dc504f370008ab7ab469f06573c9" and "df1fefef5f8ecd1d7a76414515b741b9a092d0b0" have entirely different histories.
44e056b5fe
...
df1fefef5f
@ -24,10 +24,6 @@
|
|||||||
android:required="true"
|
android:required="true"
|
||||||
android:name="android.permission.INTERNET"/>
|
android:name="android.permission.INTERNET"/>
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||||
|
@ -20,12 +20,12 @@ import android.widget.ToggleButton;
|
|||||||
import com.example.ueberwachungssystem.Detection.DetectionReport;
|
import com.example.ueberwachungssystem.Detection.DetectionReport;
|
||||||
import com.example.ueberwachungssystem.Detection.Detector;
|
import com.example.ueberwachungssystem.Detection.Detector;
|
||||||
import com.example.ueberwachungssystem.Detection.VideoDetector;
|
import com.example.ueberwachungssystem.Detection.VideoDetector;
|
||||||
|
|
||||||
import org.w3c.dom.Text;
|
import org.w3c.dom.Text;
|
||||||
|
|
||||||
@ExperimentalGetImage
|
@ExperimentalGetImage
|
||||||
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
|
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
|
||||||
private Fragment aktuellesFragment;
|
private Fragment aktuellesFragment;
|
||||||
WifiCommunication communication;
|
|
||||||
private TextView alarm;
|
private TextView alarm;
|
||||||
private String text = "Das ist ein Alarm des Sensors";
|
private String text = "Das ist ein Alarm des Sensors";
|
||||||
//Buttons
|
//Buttons
|
||||||
@ -37,7 +37,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|||||||
private void log(String nachricht) {
|
private void log(String nachricht) {
|
||||||
Log.d(this.getClass().getSimpleName(), nachricht);
|
Log.d(this.getClass().getSimpleName(), nachricht);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -57,6 +56,9 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|||||||
|
|
||||||
//boolean isRunning = vd.isRunning();
|
//boolean isRunning = vd.isRunning();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
@ -68,19 +70,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPause() {
|
|
||||||
super.onPause();
|
|
||||||
communication.stopCommunication();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
communication = new WifiCommunication(MainActivity.this, 1234);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onClickZeigeFragment1(View view) {
|
public void onClickZeigeFragment1(View view) {
|
||||||
Button button = (Button) view;
|
Button button = (Button) view;
|
||||||
log(button.getText() + " ausgewählt");
|
log(button.getText() + " ausgewählt");
|
||||||
|
@ -1,131 +0,0 @@
|
|||||||
package com.example.ueberwachungssystem;
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.DatagramPacket;
|
|
||||||
import java.net.DatagramSocket;
|
|
||||||
import java.net.Inet4Address;
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.NetworkInterface;
|
|
||||||
import java.net.SocketException;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Enumeration;
|
|
||||||
|
|
||||||
public class WifiCommunication {
|
|
||||||
private final MainActivity mainActivity;
|
|
||||||
private final InetAddress address;
|
|
||||||
private final int port;
|
|
||||||
|
|
||||||
private String messageToSend;
|
|
||||||
volatile private boolean send;
|
|
||||||
private final DatagramSocket socket;
|
|
||||||
volatile private boolean running;
|
|
||||||
@SuppressLint("SetTextI18n")
|
|
||||||
public WifiCommunication(MainActivity mainActivity, int port) {
|
|
||||||
this.mainActivity = mainActivity;
|
|
||||||
this.port = port;
|
|
||||||
try {
|
|
||||||
socket = new DatagramSocket(this.port);
|
|
||||||
socket.setBroadcast(true);
|
|
||||||
address = InetAddress.getByName("255.255.255.255"); //100.82.255.255
|
|
||||||
running = true;
|
|
||||||
send = false;
|
|
||||||
new ReceiveThread().start();
|
|
||||||
new SendThread().start();
|
|
||||||
} catch (SocketException | UnknownHostException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
//mainActivity.runOnUiThread(() -> mainActivity.tvMessages.setText("Communication running"));
|
|
||||||
}
|
|
||||||
private class ReceiveThread extends Thread {
|
|
||||||
private StringBuffer rxStringBuffer = new StringBuffer();
|
|
||||||
private String rxString="";
|
|
||||||
private String previousRxString = "";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
do {
|
|
||||||
byte[] receiveData = new byte[512];
|
|
||||||
InetAddress fromAdress;
|
|
||||||
int fromPort;
|
|
||||||
DatagramPacket rxPacket = new DatagramPacket(receiveData, receiveData.length);
|
|
||||||
socket.receive(rxPacket);
|
|
||||||
fromAdress = rxPacket.getAddress();
|
|
||||||
fromPort = rxPacket.getPort();
|
|
||||||
rxString = new String(rxPacket.getData());
|
|
||||||
if(!previousRxString.equals(rxString)) {
|
|
||||||
rxStringBuffer.append(rxString).append("\n");
|
|
||||||
//mainActivity.runOnUiThread(() -> mainActivity.tvMessages.setText(rxStringBuffer));
|
|
||||||
previousRxString = rxString;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} while (running);
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private class SendThread extends Thread {
|
|
||||||
private int tmpCnt = 0;
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
do {
|
|
||||||
if(send)
|
|
||||||
{
|
|
||||||
send = false;
|
|
||||||
SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
|
|
||||||
Date curDate = new Date(System.currentTimeMillis());
|
|
||||||
String str = formatter.format(curDate);
|
|
||||||
byte[] send_Data = new byte[512];
|
|
||||||
String txString = (str+ ",Gruppe2," + getLocalIpAddress() + ",An,Video," +messageToSend);
|
|
||||||
send_Data = txString.getBytes();
|
|
||||||
|
|
||||||
DatagramPacket txPacket = new DatagramPacket(send_Data, txString.length(), address, port);
|
|
||||||
|
|
||||||
for(int i = 0; i < 500; i++) {
|
|
||||||
socket.send(txPacket);
|
|
||||||
/*try{
|
|
||||||
sleep(10);
|
|
||||||
}catch (InterruptedException e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} while (running);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static String getLocalIpAddress() {
|
|
||||||
try {
|
|
||||||
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
|
|
||||||
NetworkInterface networkInterface = (NetworkInterface) ((Enumeration<?>) en).nextElement();
|
|
||||||
for (Enumeration<InetAddress> addresses = networkInterface.getInetAddresses(); addresses.hasMoreElements();) {
|
|
||||||
InetAddress inetAddress = addresses.nextElement();
|
|
||||||
if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) {
|
|
||||||
return inetAddress.getHostAddress();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (SocketException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendTrue(String message){
|
|
||||||
send = true;
|
|
||||||
messageToSend = message;
|
|
||||||
}
|
|
||||||
public void stopCommunication() {
|
|
||||||
running = false;
|
|
||||||
socket.close();
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user