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

@Override @Override
public void onChanged(Boolean aBoolean) { public void onChanged(Boolean aBoolean) {
if (aBoolean) { if (aBoolean) {
mMicrofonViewModel.updateDevice(mMicrofonViewModel.getLocalDeviceUUID(), mMicrofonViewModel.getSystemTimeStamp(), true, "Microfon", mMicrofonViewModel.getAmplitudeInDB());
mMicrofonViewModel.updateDevice(mMicrofonViewModel.getLocalDeviceUUID(), mMicrofonViewModel.getSystemTimeStamp(), true, "Audio", mMicrofonViewModel.getAmplitudeInDB());
} }
else { 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

} }
else { else {
Toast.makeText(AudiodetectionAndAccelerometerActivity.this, "onChangedFalse", Toast.LENGTH_LONG).show(); 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

import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;


import android.content.Intent; import android.content.Intent;
import android.hardware.SensorManager;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
} }
}); });
} }
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); Intent intent = new Intent(this, AudiodetectionActivity.class);
startActivity(intent); 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); Intent intent = new Intent(this, VideodetectionActivity.class);
startActivity(intent); 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); Intent intent = new Intent(this, AccelerometerActivity.class);
startActivity(intent); 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); Intent intent = new Intent(this, AudiodetectionAndAccelerometerActivity.class);
startActivity(intent); 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); Intent intent = new Intent(this, VideodetectionAndAccelerometerActivity.class);
startActivity(intent); startActivity(intent);
} }
public void openConnectionActivity(){ public void openConnectionActivity(){
//Intent intent = new Intent(this, ConnectionActivity.class); //Intent intent = new Intent(this, ConnectionActivity.class);
//startActivity(intent); //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

@Override @Override
public void onChanged(Boolean aBoolean) { public void onChanged(Boolean aBoolean) {
if (aBoolean) { if (aBoolean) {
mVideoDetectionViewModel.updateDevice(mVideoDetectionViewModel.getLocalDeviceUUID(), mVideoDetectionViewModel.getSystemTimeStamp(), true, "Video", 10);
mVideoDetectionViewModel.updateDevice(mVideoDetectionViewModel.getLocalDeviceUUID(), mVideoDetectionViewModel.getSystemTimeStamp(), true, "Video", 1.0f);
} }
else { 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

if(isNewMessage) if(isNewMessage)
{ {
isNewMessage = false; isNewMessage = false;
//todo: adapt send String
String txString = getLocalIpAddress() + " sends. #" + tmpCnt++ + sendMessage;
String txString = sendMessage;
byte[] txBuffer = txString.getBytes(); byte[] txBuffer = txString.getBytes();


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

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



public void getNewReceivedMessage(String newMessage) { public void getNewReceivedMessage(String newMessage) {
String[] messageString = messageStringSplitter(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);
}
} }
} }


StringBuilder message = new StringBuilder(); StringBuilder message = new StringBuilder();
Device device = connectedDevicesList.get(deviceID); Device device = connectedDevicesList.get(deviceID);
if(device != null) { if(device != null) {
message.append(device.getTimeStamp())
message.append("1")
.append(delimiter)
.append(device.getTimeStamp())
.append(delimiter)
.append("Gruppe3")
.append(delimiter) .append(delimiter)
.append(device.getDeviceID()) .append(device.getDeviceID())
.append(delimiter) .append(delimiter)
.append(device.getSensorMassage()); .append(device.getSensorMassage());
} }
else { else {
message.append("")
message.append("1")
.append(delimiter)
.append("")
.append(delimiter)
.append("Gruppe3")
.append(delimiter) .append(delimiter)
.append("") .append("")
.append(delimiter) .append(delimiter)

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

if(mDeviceList != null) { if(mDeviceList != null) {
return; return;
} }
//todo: check if WiFi instanz can be hold only by the repository
mDeviceRepository = DeviceRepository.getInstance(); mDeviceRepository = DeviceRepository.getInstance();
mWiFiCommunication = WiFiCommunication.getInstance(); mWiFiCommunication = WiFiCommunication.getInstance();
mDeviceRepository.setWiFiCommunication(mWiFiCommunication); mDeviceRepository.setWiFiCommunication(mWiFiCommunication);
mWiFiCommunication.setDeviceRepository(mDeviceRepository); 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(); mDeviceList = mDeviceRepository.getConnectedDeviceList();
mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList(); mAlarmHistoryList = mDeviceRepository.getAlarmHistoryDeviceList();
mStartAlarmRecording = mDeviceRepository.getStartAlarmRecording(); mStartAlarmRecording = mDeviceRepository.getStartAlarmRecording();


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

Loading…
Cancel
Save