Added more logging for debugging functionality

This commit is contained in:
Luca Warmenhoven
2024-05-29 15:13:04 +02:00
parent 4983162ac9
commit 447a021b10
4 changed files with 25 additions and 2 deletions

View File

@@ -70,9 +70,9 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
@Override @Override
public void onRobotFocusGained(QiContext qiContext) { public void onRobotFocusGained(QiContext qiContext) {
// Find the VideoView by its ID
CompletableFuture.runAsync(() -> FitnessCycle.executeMovement("bicepcurl", 10, qiContext));
personalMotionPreviewElement.provideQiContext(qiContext); personalMotionPreviewElement.provideQiContext(qiContext);
// Find the VideoView by its ID
//CompletableFuture.runAsync(() -> FitnessCycle.executeMovement("bicepcurl", 10, qiContext));
// FitnessCycle.playVideo(qiContext, videoView, this); // FitnessCycle.playVideo(qiContext, videoView, this);
} }
@@ -89,5 +89,7 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
QiSDK.unregister(this, this);
this.personalMotionPreviewElement.onDestroy();
} }
} }

View File

@@ -94,6 +94,14 @@ public class PersonalMotionPreviewElement extends View {
this.paths = exercise.getPath(); this.paths = exercise.getPath();
} }
public void onDestroy()
{
if ( this.motionProcessor != null )
this.motionProcessor.stopListening();
this.motionProcessor = null;
}
/** /**
* Function for providing a QiContext to the PersonalMotionPreviewElement. * Function for providing a QiContext to the PersonalMotionPreviewElement.
* This function will be called by the parent activity when the QiContext is available. * This function will be called by the parent activity when the QiContext is available.

View File

@@ -71,6 +71,9 @@ public class MotionProcessor {
public void parsePacket(@NotNull String data) { public void parsePacket(@NotNull String data) {
try { try {
Log.i("MotionProcessor", "Received packet data: " + data);
JsonElement json = JsonParser.parseString(data); JsonElement json = JsonParser.parseString(data);
if (!json.isJsonObject()) if (!json.isJsonObject())
@@ -106,6 +109,7 @@ public class MotionProcessor {
addMotionData(motionData); addMotionData(motionData);
} catch (Exception e) { } catch (Exception e) {
// Don't do anything ... just ignore the exception // Don't do anything ... just ignore the exception
Log.i("MotionProcessor", "Failed to parse packet data.");
} }
} }

View File

@@ -6,6 +6,7 @@ import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
@@ -63,6 +64,7 @@ public class WebServer implements Runnable {
// Find a new connection // Find a new connection
Socket newSocket = this.serverSocket.accept(); Socket newSocket = this.serverSocket.accept();
InputStream streamIn = newSocket.getInputStream(); InputStream streamIn = newSocket.getInputStream();
OutputStream streamOut = newSocket.getOutputStream();
// Read the incoming data // Read the incoming data
BufferedReader reader = new BufferedReader(new InputStreamReader(streamIn)); BufferedReader reader = new BufferedReader(new InputStreamReader(streamIn));
@@ -71,7 +73,14 @@ public class WebServer implements Runnable {
while ((line = reader.readLine()) != null) while ((line = reader.readLine()) != null)
builder.append(line).append("\n"); builder.append(line).append("\n");
// Send generic message back
streamOut.write("HTTP/1.1 200 OK\n".getBytes());
streamOut.write("Content-Type: text/html\n".getBytes());
streamOut.write("Connection: close\n".getBytes());
streamIn.close(); // Closes the reader, stream and socket connection. streamIn.close(); // Closes the reader, stream and socket connection.
streamOut.close();
newSocket.close();
String[] data = builder.toString().split("\n\n"); String[] data = builder.toString().split("\n\n");