mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-04-11 03:02:20 +02:00
AndroidGCS: Dynamic loading works. Currently won't work out of the box though.
From the build/uavobjects-synth/java: 1. mkdir -p src/org/openpilot/uavtalk/uavobjects 2. javac *.java ../../../androidgcs/src/org/openpilot/uavtalk/UAVDataObject.java \ ../../../androidgcs/src/org/openpilot/uavtalk/UAVObject*.java \ ../../../androidgcs/src/org/openpilot/uavtalk/UAVMetaObject.java \ -d . 3. rm org/openpilot/uavtalk/*.class 4. jar cf tmp_org.openpilot.uavtalk.uavobjects.jar org 5. dx --dex --output org.openpilot.uavtalk.uavobjects.jar tmp_org.openpilot.uavtalk.uavobjects.jar 6. adb push org.openpilot.uavtalk.uavobjects.jar /data/org.openpilot.uavtalk.uavobjects.jar
This commit is contained in:
parent
c6341139c2
commit
76785cad57
@ -276,6 +276,24 @@ public class OPTelemetryService extends Service {
|
|||||||
public UAVObjectManager getObjectManager();
|
public UAVObjectManager getObjectManager();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete the files in a directories
|
||||||
|
* @param directory
|
||||||
|
*/
|
||||||
|
private static void deleteDirectoryContents(File directory)
|
||||||
|
{
|
||||||
|
File contents[] = directory.listFiles();
|
||||||
|
if (contents != null)
|
||||||
|
{
|
||||||
|
for (File file : contents)
|
||||||
|
{
|
||||||
|
if (file.isDirectory())
|
||||||
|
deleteDirectoryContents(file);
|
||||||
|
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Load the UAVObjects from a JAR file. This method must be called in the
|
* Load the UAVObjects from a JAR file. This method must be called in the
|
||||||
* service context.
|
* service context.
|
||||||
@ -289,25 +307,24 @@ public class OPTelemetryService extends Service {
|
|||||||
File dexDir = getDir(DEX_DIR, Context.MODE_WORLD_READABLE);
|
File dexDir = getDir(DEX_DIR, Context.MODE_WORLD_READABLE);
|
||||||
|
|
||||||
// Necessary to get dexOpt to run
|
// Necessary to get dexOpt to run
|
||||||
//if (dexDir.exists())
|
if (dexDir.exists())
|
||||||
// deleteDirectoryContents(dexDir);
|
deleteDirectoryContents(dexDir);
|
||||||
|
|
||||||
File jarsDir = getDir(JAR_DIR, MODE_WORLD_READABLE);
|
//File jarsDir = getDir(JAR_DIR, MODE_WORLD_READABLE);
|
||||||
String classpath = new File(jarsDir, jar).getAbsolutePath();
|
//String classpath = new File(jarsDir, jar).getAbsolutePath();
|
||||||
|
String classpath = "/data/org.openpilot.uavtalk.uavobjects.jar";
|
||||||
DexClassLoader loader = new DexClassLoader(classpath, dexDir.getAbsolutePath(), null, getClassLoader());
|
DexClassLoader loader = new DexClassLoader(classpath, dexDir.getAbsolutePath(), null, getClassLoader());
|
||||||
|
|
||||||
Object initInstance = null;
|
|
||||||
try {
|
try {
|
||||||
Class<?> initClass = loader.loadClass("org.openpilot.uavtalk.uavobjects.UAVObjectsInitialize");
|
Class<?> initClass = loader.loadClass("org.openpilot.uavtalk.uavobjects.UAVObjectsInitialize");
|
||||||
initInstance = initClass.newInstance();
|
Log.d(TAG, "Got the initClass: " + initClass);
|
||||||
Method initMethod = initClass.getMethod("register", UAVObjectManager.class);
|
Method initMethod = initClass.getMethod("register", UAVObjectManager.class);
|
||||||
initMethod.invoke(initInstance, objMngr);
|
Log.d(TAG, "Got the method: " + initMethod);
|
||||||
|
initMethod.invoke(null, objMngr);
|
||||||
|
Log.d(TAG, "Invoked");
|
||||||
} catch (ClassNotFoundException e1) {
|
} catch (ClassNotFoundException e1) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
} catch (InstantiationException e1) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e1.printStackTrace();
|
|
||||||
} catch (IllegalAccessException e1) {
|
} catch (IllegalAccessException e1) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
|
@ -11,7 +11,7 @@ import org.openpilot.uavtalk.TelemetryMonitor;
|
|||||||
import org.openpilot.uavtalk.UAVObject;
|
import org.openpilot.uavtalk.UAVObject;
|
||||||
import org.openpilot.uavtalk.UAVObjectManager;
|
import org.openpilot.uavtalk.UAVObjectManager;
|
||||||
import org.openpilot.uavtalk.UAVTalk;
|
import org.openpilot.uavtalk.UAVTalk;
|
||||||
import org.openpilot.uavtalk.uavobjects.UAVObjectsInitialize;
|
import org.openpilot.uavtalk.uavobjects.TelemObjectsInitialize;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@ -115,7 +115,7 @@ public abstract class TelemetryTask implements Runnable {
|
|||||||
// be dependent on what is connected (e.g. board and
|
// be dependent on what is connected (e.g. board and
|
||||||
// version number).
|
// version number).
|
||||||
objMngr = new UAVObjectManager();
|
objMngr = new UAVObjectManager();
|
||||||
UAVObjectsInitialize.register(objMngr);
|
TelemObjectsInitialize.register(objMngr);
|
||||||
|
|
||||||
// Register to get an update from FirmwareIAP in order to register
|
// Register to get an update from FirmwareIAP in order to register
|
||||||
// the appropriate objects
|
// the appropriate objects
|
||||||
|
@ -70,7 +70,6 @@ public class UAVObjectManager {
|
|||||||
*/
|
*/
|
||||||
public synchronized boolean registerObject(UAVDataObject obj) throws Exception
|
public synchronized boolean registerObject(UAVDataObject obj) throws Exception
|
||||||
{
|
{
|
||||||
// QMutexLocker locker(mutex);
|
|
||||||
|
|
||||||
ListIterator<List<UAVObject>> objIt = objects.listIterator(0);
|
ListIterator<List<UAVObject>> objIt = objects.listIterator(0);
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ package org.openpilot.uavtalk.uavobjects;
|
|||||||
|
|
||||||
import org.openpilot.uavtalk.UAVObjectManager;
|
import org.openpilot.uavtalk.UAVObjectManager;
|
||||||
|
|
||||||
public class UAVObjectsInitialize {
|
public class TelemObjectsInitialize {
|
||||||
|
|
||||||
public static void register(UAVObjectManager objMngr) {
|
public static void register(UAVObjectManager objMngr) {
|
||||||
try {
|
try {
|
Loading…
x
Reference in New Issue
Block a user