Initial Commit
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package com.example.carcontroller.SLAM;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.SurfaceView;
|
||||
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import org.zeromq.SocketType;
|
||||
import org.zeromq.ZContext;
|
||||
import org.zeromq.ZMQ;
|
||||
|
||||
public class SlamView extends SurfaceView implements Runnable {
|
||||
|
||||
ZContext context;
|
||||
String host;
|
||||
String port;
|
||||
Thread mapThread;
|
||||
|
||||
public SlamView(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public SlamView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public SlamView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
context = new ZContext();
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
host = prefs.getString("host", "10.0.0.53");
|
||||
port = prefs.getString("port", "50051");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// Receive map from zmq and update appropriately.
|
||||
try (ZMQ.Socket socket = context.createSocket(SocketType.SUB)) {
|
||||
socket.connect("tcp://" + host + ":" + port);
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
byte[] map = socket.recv();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void stop(){
|
||||
// Use grpc to tell the loader to stop. Interrupt the loader thread as well.
|
||||
mapThread.interrupt();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user