Browse Source

adapted datahandling and communication strings

Benutzeroberflaeche
Christian Tinz 1 year ago
parent
commit
cca1311b74

+ 2
- 2
app/src/main/java/com/example/greenwatch/AudiodetectionActivity.java View File

@@ -87,10 +87,10 @@ public class AudiodetectionActivity extends AppCompatActivity {
@Override
public void onChanged(Boolean aBoolean) {
if (aBoolean) {
mMicrofonViewModel.updateDevice(mMicrofonViewModel.getLocalDeviceUUID(), mMicrofonViewModel.getSystemTimeStamp(), true, "Microfon", mMicrofonViewModel.getAmplitudeInDB());
mMicrofonViewModel.updateDevice(mMicrofonViewModel.getLocalDeviceUUID(), mMicrofonViewModel.getSystemTimeStamp(), true, "Audio", mMicrofonViewModel.getAmplitudeInDB());
}
else {
mMicrofonViewModel.updateDevice(mMicrofonViewModel.getLocalDeviceUUID(), mMicrofonViewModel.getSystemTimeStamp(), false, "Microfon", mMicrofonViewModel.getAmplitudeInDB());
mMicrofonViewModel.updateDevice(mMicrofonViewModel.getLocalDeviceUUID(), mMicrofonViewModel.getSystemTimeStamp(), false, "Audio", 0.0f);
}

}

+ 1
- 1
app/src/main/java/com/example/greenwatch/AudiodetectionAndAccelerometerActivity.java View File

@@ -105,7 +105,7 @@ public class AudiodetectionAndAccelerometerActivity extends AppCompatActivity im
}
else {
Toast.makeText(AudiodetectionAndAccelerometerActivity.this, "onChangedFalse", Toast.LENGTH_LONG).show();
mAudiodetectionAndAccelerometerViewModel.updateDevice(mAudiodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mAudiodetectionAndAccelerometerViewModel.getSystemTimeStamp(), false, "AudioAndAccelerometer", 0);
mAudiodetectionAndAccelerometerViewModel.updateDevice(mAudiodetectionAndAccelerometerViewModel.getLocalDeviceUUID(), mAudiodetectionAndAccelerometerViewModel.getSystemTimeStamp(), false, "AudioAndAccelerometer", 0.0f);
}

}

+ 19
- 6
app/src/main/java/com/example/greenwatch/MainActivity.java View File

@@ -7,6 +7,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
@@ -138,30 +139,42 @@ public class MainActivity extends AppCompatActivity {
}
});
}
public void openAudiodetectionActivity(){

@Override
protected void onResume() {
super.onResume();
mMainActivityViewModel.updateDevice(mMainActivityViewModel.getLocalDeviceUUID(), mMainActivityViewModel.getSystemTimeStamp(), false, "No Sensor selected", 0.0f);
}

public void openAudiodetectionActivity() {
mMainActivityViewModel.updateDevice(mMainActivityViewModel.getLocalDeviceUUID(), mMainActivityViewModel.getSystemTimeStamp(), false, "Audio", 0.0f);
Intent intent = new Intent(this, AudiodetectionActivity.class);
startActivity(intent);
}
public void openVideodetectionActivity(){
public void openVideodetectionActivity() {
mMainActivityViewModel.updateDevice(mMainActivityViewModel.getLocalDeviceUUID(), mMainActivityViewModel.getSystemTimeStamp(), false, "Video", 0.0f);
Intent intent = new Intent(this, VideodetectionActivity.class);
startActivity(intent);
}
public void openAccelerometerActivity(){
public void openAccelerometerActivity() {
mMainActivityViewModel.updateDevice(mMainActivityViewModel.getLocalDeviceUUID(), mMainActivityViewModel.getSystemTimeStamp(), false, "Accelerometer", 0.0f);
Intent intent = new Intent(this, AccelerometerActivity.class);
startActivity(intent);
}
public void openAudiodetectionAndAccelerometerActivity(){
public void openAudiodetectionAndAccelerometerActivity() {
mMainActivityViewModel.updateDevice(mMainActivityViewModel.getLocalDeviceUUID(), mMainActivityViewModel.getSystemTimeStamp(), false, "AudioAndAccelerometer", 0.0f);
Intent intent = new Intent(this, AudiodetectionAndAccelerometerActivity.class);
startActivity(intent);
}
public void openVideodetectionAndAccelerometerActivity(){
public void openVideodetectionAndAccelerometerActivity() {
mMainActivityViewModel.updateDevice(mMainActivityViewModel.getLocalDeviceUUID(), mMainActivityViewModel.getSystemTimeStamp(), false, "VideoAndAccelerometer", 0.0f);
Intent intent = new Intent(this, VideodetectionAndAccelerometerActivity.class);
startActivity(intent);
}
public void openConnectionActivity(){
//Intent intent = new Intent(this, ConnectionActivity.class);
//startActivity(intent);
mMainActivityViewModel.updateDevice(mMainActivityViewModel.getLocalDeviceUUID(), "10:51", true, "Audio", 10);
mMainActivityViewModel.updateDevice(mMainActivityViewModel.getLocalDeviceUUID(), "10:51", false, "Audio", 10);
}

}

+ 2
- 2
app/src/main/java/com/example/greenwatch/VideodetectionActivity.java View File

@@ -88,10 +88,10 @@ public class VideodetectionActivity extends AppCompatActivity {
@Override
public void onChanged(Boolean aBoolean) {
if (aBoolean) {
mVideoDetectionViewModel.updateDevice(mVideoDetectionViewModel.getLocalDeviceUUID(), mVideoDetectionViewModel.getSystemTimeStamp(), true, "Video", 10);
mVideoDetectionViewModel.updateDevice(mVideoDetectionViewModel.getLocalDeviceUUID(), mVideoDetectionViewModel.getSystemTimeStamp(), true, "Video", 1.0f);
}
else {
mVideoDetectionViewModel.updateDevice(mVideoDetectionViewModel.getLocalDeviceUUID(), mVideoDetectionViewModel.getSystemTimeStamp(), false, "Video", 0);
mVideoDetectionViewModel.updateDevice(mVideoDetectionViewModel.getLocalDeviceUUID(), mVideoDetectionViewModel.getSystemTimeStamp(), false, "Video", 0.0f);
}

}

+ 1
- 2
app/src/main/java/com/example/greenwatch/communication/WiFiCommunication.java View File

@@ -88,8 +88,7 @@ public class WiFiCommunication {
if(isNewMessage)
{
isNewMessage = false;
//todo: adapt send String
String txString = getLocalIpAddress() + " sends. #" + tmpCnt++ + sendMessage;
String txString = sendMessage;
byte[] txBuffer = txString.getBytes();

DatagramPacket txPacket = new DatagramPacket(txBuffer, txBuffer.length, address, port);

+ 25
- 16
app/src/main/java/com/example/greenwatch/repositories/DeviceRepository.java View File

@@ -76,21 +76,22 @@ public class DeviceRepository {

public void getNewReceivedMessage(String newMessage) {
String[] messageString = messageStringSplitter(newMessage);
String timeStamp = messageString[0];
String deviceID = messageString[1];
boolean sensorStatus = convertSensorStatus(messageString[2]);
String sensorType = messageString[3];
float sensorMassage = Float.valueOf(messageString[4]);

if (deviceID.equals(checkDeviceID(localDeviceUUID))) {
return;
}
if(messageString[0]=="1" && messageString.length == 7) {
String timeStamp = messageString[1];
String deviceID = messageString[3];
boolean sensorStatus = convertSensorStatus(messageString[4]);
String sensorType = messageString[5];
float sensorMassage = Float.valueOf(messageString[6]);

if (deviceID.equals(checkDeviceID(localDeviceUUID))) {
return;
}

if(!connectedDevicesList.containsKey(deviceID)) {
createNewDevice(timeStamp, deviceID, sensorStatus, sensorType, sensorMassage);
}
else {
updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage);
if (!connectedDevicesList.containsKey(deviceID)) {
createNewDevice(timeStamp, deviceID, sensorStatus, sensorType, sensorMassage);
} else {
updateDevice(deviceID, timeStamp, sensorStatus, sensorType, sensorMassage);
}
}
}

@@ -98,7 +99,11 @@ public class DeviceRepository {
StringBuilder message = new StringBuilder();
Device device = connectedDevicesList.get(deviceID);
if(device != null) {
message.append(device.getTimeStamp())
message.append("1")
.append(delimiter)
.append(device.getTimeStamp())
.append(delimiter)
.append("Gruppe3")
.append(delimiter)
.append(device.getDeviceID())
.append(delimiter)
@@ -109,7 +114,11 @@ public class DeviceRepository {
.append(device.getSensorMassage());
}
else {
message.append("")
message.append("1")
.append(delimiter)
.append("")
.append(delimiter)
.append("Gruppe3")
.append(delimiter)
.append("")
.append(delimiter)

+ 3
- 3
app/src/main/java/com/example/greenwatch/viewmodels/MainActivityViewModel.java View File

@@ -32,12 +32,12 @@ public class MainActivityViewModel extends ViewModel implements ViewModelInterfa
if(mDeviceList != null) {
return;
}
//todo: check if WiFi instanz can be hold only by the repository
mDeviceRepository = DeviceRepository.getInstance();
mWiFiCommunication = WiFiCommunication.getInstance();
mDeviceRepository.setWiFiCommunication(mWiFiCommunication);
mWiFiCommunication.setDeviceRepository(mDeviceRepository);
mDeviceRepository.createNewDevice(mDeviceRepository.getSystemTimeStamp(), mDeviceRepository.getLocalDeviceUUID(), false, "No Sensor selected", 0);
mDeviceRepository.createNewDevice(mDeviceRepository.getSystemTimeStamp(), mDeviceRepository.getLocalDeviceUUID(), false, "No Sensor selected", 0.0f);
mDeviceRepository.setDeviceID(mDeviceRepository.getLocalDeviceUUID(), WiFiCommunication.getLocalIpAddress());
mDeviceList = mDeviceRepository.getConnectedDeviceList();
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList();
mStartAlarmRecording = mDeviceRepository.getStartAlarmRecording();
@@ -136,6 +136,6 @@ public class MainActivityViewModel extends ViewModel implements ViewModelInterfa

@Override
public String getSystemTimeStamp() {
return null;
return mDeviceRepository.getSystemTimeStamp();
}
}

Loading…
Cancel
Save