Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Hardik Garg committed May 2, 2024
2 parents 894ee3f + 14ad32c commit 4652879
Show file tree
Hide file tree
Showing 117 changed files with 4,049 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object ConnectionSelector {
}

fun getConnection(): ILocalConnection {
val connected = isConnectedViaWifi(context)
val connected = isConnectedViaWifi(context) || isWifiApEnabled(context)
return if (connected) NetworkServiceConnection else NearbyConnection
}

Expand All @@ -30,4 +30,14 @@ object ConnectionSelector {

return networkId > 0
}

private fun isWifiApEnabled(context: Context): Boolean {
val wifiManager = context.getSystemService(WIFI_SERVICE) as WifiManager
return try {
val method = wifiManager.javaClass.getDeclaredMethod("isWifiApEnabled")
method.invoke(wifiManager) as? Boolean == true
} catch (ignored: Throwable) {
false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,15 @@ class VideoViewWebRTC @JvmOverloads constructor(
val initializationOptions = PeerConnectionFactory.InitializationOptions.builder(context)
.createInitializationOptions()
PeerConnectionFactory.initialize(initializationOptions)

val options = PeerConnectionFactory.Options().apply {
networkIgnoreMask = 16
disableEncryption = false
disableNetworkMonitor = true
}
factory = PeerConnectionFactory.builder().setVideoEncoderFactory(encoderFactory)
.setVideoDecoderFactory(decoderFactory).createPeerConnectionFactory()
.setVideoDecoderFactory(decoderFactory)
.setOptions(options).createPeerConnectionFactory()
}

private fun initializePeerConnections() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,14 @@ private void handlePhoneControllerEvents() {
commandType = event.getString("command");
} else if (event.has("driveCmd")) {
commandType = Constants.CMD_DRIVE;
} else if (event.has("server")) {
for (int i = 0; i < serverSpinner.getAdapter().getCount(); i++) {
if(event.getString("server").equals("noServerFound")){
serverSpinner.setSelection(0);
} else if(event.getString("server").equals(serverSpinner.getAdapter().getItem(i))){
serverSpinner.setSelection(i);
}
}
}

switch (commandType) {
Expand Down Expand Up @@ -287,7 +295,7 @@ private void handlePhoneControllerEvents() {
error -> {
Log.d(null, "Error occurred in ControllerToBotEventBus: " + error);
},
event -> event.has("command") || event.has("driveCmd") // filter out everything else
event -> event.has("command") || event.has("driveCmd") || event.has("server") // filter out everything else
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;

import java.lang.reflect.Method;

public class ConnectionSelector {
private static final String TAG = "ConnectionManager";
Expand Down Expand Up @@ -37,7 +40,7 @@ ILocalConnection getConnection() {
return connection;
}

if (isConnectedViaWifi()) {
if (isConnectedViaWifi() || isWifiApEnabled()) {
connection = networkConnection;
} else {
connection = nearbyConnection;
Expand All @@ -52,4 +55,17 @@ private boolean isConnectedViaWifi() {
NetworkInfo mWifi = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
return mWifi.isConnected();
}

private boolean isWifiApEnabled() {
WifiManager wifiManager =
(WifiManager) _context.getSystemService(Context.WIFI_SERVICE);
try {
final Method method =
wifiManager.getClass().getDeclaredMethod("isWifiApEnabled");
Boolean result = (Boolean) method.invoke(wifiManager);
return Boolean.TRUE.equals(result);
} catch (final Throwable ignored) {}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public void onServiceFound(NsdServiceInfo service) {
try {
if (service.getServiceType().equals(SERVICE_TYPE)
&& service.getServiceName().equals(SERVICE_NAME_CONTROLLER)) {
Timber.e("found service");
mNsdManager.resolveService(service, mResolveListener);
} else if (service.getServiceName().equals(MY_SERVICE_NAME)) {
Log.d(TAG, "Same machine: " + MY_SERVICE_NAME);
Expand Down Expand Up @@ -289,7 +290,6 @@ void runReceiver(Scanner reader) {
try {
while (true) {
String msg = reader.nextLine().trim();

if (!stopped) {
((Activity) context).runOnUiThread(() -> dataReceivedCallback.dataReceived(msg));
}
Expand Down
6 changes: 6 additions & 0 deletions android/robot/src/main/java/org/openbot/env/WebRtcServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,16 @@ private void initializePeerConnectionFactory() {
PeerConnectionFactory.InitializationOptions.builder(context).createInitializationOptions();
PeerConnectionFactory.initialize(initializationOptions);

PeerConnectionFactory.Options options = new PeerConnectionFactory.Options();
options.networkIgnoreMask = 16;
options.disableEncryption = false;
options.disableNetworkMonitor = true;

factory =
PeerConnectionFactory.builder()
.setVideoEncoderFactory(encoderFactory)
.setVideoDecoderFactory(decoderFactory)
.setOptions(options)
.createPeerConnectionFactory();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class ObjectNavFragment extends CameraFragment {

private Detector detector;

private boolean mirrorControl;
private Matrix frameToCropTransform;
private Bitmap croppedBitmap;
private int sensorOrientation;
Expand Down Expand Up @@ -146,6 +147,8 @@ public void onNothingSelected(AdapterView<?> parent) {}

binding.cameraToggle.setOnClickListener(v -> toggleCamera());

binding.mirrorControl.setOnClickListener(v -> mirrorControl());

List<String> models =
getModelNames(f -> f.type.equals(Model.TYPE.DETECTOR) && f.pathType != Model.PATH_TYPE.URL);
initModelSpinner(binding.modelSpinner, models, preferencesManager.getObjectNavModel());
Expand Down Expand Up @@ -228,6 +231,10 @@ public void onNothingSelected(AdapterView<?> parent) {}
});
}

private void mirrorControl() {
mirrorControl = !mirrorControl;
}

private void updateCropImageInfo() {
// Timber.i("%s x %s",getPreviewSize().getWidth(), getPreviewSize().getHeight());
// Timber.i("%s x %s",getMaxAnalyseImageSize().getWidth(),
Expand Down Expand Up @@ -477,7 +484,12 @@ protected void processFrame(Bitmap bitmap, ImageProxy image) {
}

tracker.trackResults(mappedRecognitions, frameNum);
handleDriveCommand(tracker.updateTarget());
Control target = tracker.updateTarget();
if (mirrorControl) {
handleDriveCommand(target.mirror());
} else {
handleDriveCommand(target);
}
binding.trackingOverlay.postInvalidate();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode) {

@Override
public void onServiceResolved(NsdServiceInfo serviceInfo) {
Timber.e("serviceInfo %s", serviceInfo.getServiceName());
servers.put(serviceInfo.getServiceName(), serviceInfo);
try {
serverListener.onServerListChange(servers.keySet());
Expand Down
4 changes: 4 additions & 0 deletions android/robot/src/main/java/org/openbot/vehicle/Control.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ public float getLeft() {
public float getRight() {
return right;
}

public Control mirror() {
return new Control(this.right, this.left);
}
}
19 changes: 19 additions & 0 deletions android/robot/src/main/res/drawable/ic_mirror_control.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="@color/openBotBlue">
<group
android:scaleX="-1"
android:translateX="12"
android:translateY="12">
<group
android:translateX="-12"
android:translateY="-12">
<path
android:pathData="M15 21h2v-2h-2v2zM19 9h2L21 7h-2v2zM3 5v14c0 1.1 0.9 2 2 2h4v-2L5 19L5 5h4L9 3L5 3c-1.1 0 -2 0.9 -2 2zM19 3v2h2c0 -1.1 -0.9 -2 -2 -2zM11 23h2L13 1h-2v22zM19 17h2v-2h-2v2zM15 5h2L17 3h-2v2zM19 13h2v-2h-2v2zM19 21c1.1 0 2 -0.9 2 -2h-2v2z"
android:fillColor="#FF000000" />
</group>
</group>
</vector>
10 changes: 10 additions & 0 deletions android/robot/src/main/res/drawable/ic_mirror_control_off.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:pathData="M15,21h2v-2h-2v2zM19,9h2L21,7h-2v2zM3,5v14c0,1.1 0.9,2 2,2h4v-2L5,19L5,5h4L9,3L5,3c-1.1,0 -2,0.9 -2,2zM19,3v2h2c0,-1.1 -0.9,-2 -2,-2zM11,23h2L13,1h-2v22zM19,17h2v-2h-2v2zM15,5h2L17,3h-2v2zM19,13h2v-2h-2v2zM19,21c1.1,0 2,-0.9 2,-2h-2v2z"
android:fillColor="#FF000000"/>
</vector>
6 changes: 6 additions & 0 deletions android/robot/src/main/res/drawable/mirror_control.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:drawable="@drawable/ic_mirror_control_off" android:state_checked="false" />
<item android:drawable="@drawable/ic_mirror_control" android:state_checked="true" />
<item android:drawable="@drawable/ic_mirror_control_off" />
</selector>
18 changes: 14 additions & 4 deletions android/robot/src/main/res/layout/fragment_object_nav.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
android:id="@+id/usbToggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginEnd="8dp"
android:button="@drawable/usb_toggle"
app:layout_constraintBottom_toBottomOf="@+id/camera_toggle"
app:layout_constraintEnd_toStartOf="@+id/camera_toggle"
Expand All @@ -75,7 +75,7 @@
android:id="@+id/bleToggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginEnd="8dp"
android:button="@drawable/ble_toggle"
app:layout_constraintBottom_toBottomOf="@+id/camera_toggle"
app:layout_constraintEnd_toStartOf="@+id/camera_toggle"
Expand All @@ -85,15 +85,25 @@
android:id="@+id/camera_toggle"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginRight="16dp"
android:layout_marginEnd="8dp"
android:background="@android:color/transparent"
android:scaleType="center"
android:src="@drawable/ic_cameraswitch"
android:text="@string/camera_facing_back"
app:layout_constraintTop_toTopOf="@+id/autoLinearLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintEnd_toStartOf="@+id/mirrorControl"
app:tint="@color/openBotBlue" />

<CheckBox
android:id="@+id/mirrorControl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:button="@drawable/mirror_control"
android:layout_marginTop="8dp"
app:layout_constraintTop_toTopOf="@+id/autoLinearLayout"
app:layout_constraintEnd_toEndOf="parent" />

<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
Expand Down
1 change: 1 addition & 0 deletions controller/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
__pycache__
.run
44 changes: 44 additions & 0 deletions controller/flutter/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
/build/

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release
33 changes: 33 additions & 0 deletions controller/flutter/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled.

version:
revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849
channel: stable

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849
base_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849
- platform: android
create_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849
base_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849
- platform: ios
create_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849
base_revision: b8f7f1f9869bb2d116aa6a70dbeac61000b52849

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
Loading

0 comments on commit 4652879

Please sign in to comment.