mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-04-10 02:02:21 +02:00
Initial import of my androidgcs framework
This commit is contained in:
parent
c1a0f176eb
commit
9d707cef5b
18
androidgcs/AndroidManifest.xml
Normal file
18
androidgcs/AndroidManifest.xml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="org.openpilot.androidgcs"
|
||||||
|
android:versionCode="1"
|
||||||
|
android:versionName="1.0">
|
||||||
|
|
||||||
|
|
||||||
|
<application android:icon="@drawable/icon" android:label="@string/app_name">
|
||||||
|
<activity android:name="ObjectBrowser"
|
||||||
|
android:label="@string/app_name">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
|
</application>
|
||||||
|
</manifest>
|
BIN
androidgcs/bin/OpieMobi.apk
Normal file
BIN
androidgcs/bin/OpieMobi.apk
Normal file
Binary file not shown.
BIN
androidgcs/bin/classes.dex
Normal file
BIN
androidgcs/bin/classes.dex
Normal file
Binary file not shown.
Binary file not shown.
BIN
androidgcs/bin/org/openpilot/androidgcs/ObjectBrowser.class
Normal file
BIN
androidgcs/bin/org/openpilot/androidgcs/ObjectBrowser.class
Normal file
Binary file not shown.
BIN
androidgcs/bin/org/openpilot/androidgcs/R$attr.class
Normal file
BIN
androidgcs/bin/org/openpilot/androidgcs/R$attr.class
Normal file
Binary file not shown.
BIN
androidgcs/bin/org/openpilot/androidgcs/R$color.class
Normal file
BIN
androidgcs/bin/org/openpilot/androidgcs/R$color.class
Normal file
Binary file not shown.
BIN
androidgcs/bin/org/openpilot/androidgcs/R$drawable.class
Normal file
BIN
androidgcs/bin/org/openpilot/androidgcs/R$drawable.class
Normal file
Binary file not shown.
BIN
androidgcs/bin/org/openpilot/androidgcs/R$id.class
Normal file
BIN
androidgcs/bin/org/openpilot/androidgcs/R$id.class
Normal file
Binary file not shown.
BIN
androidgcs/bin/org/openpilot/androidgcs/R$layout.class
Normal file
BIN
androidgcs/bin/org/openpilot/androidgcs/R$layout.class
Normal file
Binary file not shown.
BIN
androidgcs/bin/org/openpilot/androidgcs/R$string.class
Normal file
BIN
androidgcs/bin/org/openpilot/androidgcs/R$string.class
Normal file
Binary file not shown.
BIN
androidgcs/bin/org/openpilot/androidgcs/R.class
Normal file
BIN
androidgcs/bin/org/openpilot/androidgcs/R.class
Normal file
Binary file not shown.
BIN
androidgcs/bin/org/openpilot/uavtalk/UAVDataObject.class
Normal file
BIN
androidgcs/bin/org/openpilot/uavtalk/UAVDataObject.class
Normal file
Binary file not shown.
BIN
androidgcs/bin/org/openpilot/uavtalk/UAVMetaObject.class
Normal file
BIN
androidgcs/bin/org/openpilot/uavtalk/UAVMetaObject.class
Normal file
Binary file not shown.
BIN
androidgcs/bin/org/openpilot/uavtalk/UAVObject$AccessMode.class
Normal file
BIN
androidgcs/bin/org/openpilot/uavtalk/UAVObject$AccessMode.class
Normal file
Binary file not shown.
BIN
androidgcs/bin/org/openpilot/uavtalk/UAVObject$UpdateMode.class
Normal file
BIN
androidgcs/bin/org/openpilot/uavtalk/UAVObject$UpdateMode.class
Normal file
Binary file not shown.
BIN
androidgcs/bin/org/openpilot/uavtalk/UAVObject.class
Normal file
BIN
androidgcs/bin/org/openpilot/uavtalk/UAVObject.class
Normal file
Binary file not shown.
BIN
androidgcs/bin/org/openpilot/uavtalk/UAVObjectManager.class
Normal file
BIN
androidgcs/bin/org/openpilot/uavtalk/UAVObjectManager.class
Normal file
Binary file not shown.
BIN
androidgcs/bin/resources.ap_
Normal file
BIN
androidgcs/bin/resources.ap_
Normal file
Binary file not shown.
11
androidgcs/default.properties
Normal file
11
androidgcs/default.properties
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# This file is automatically generated by Android Tools.
|
||||||
|
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||||
|
#
|
||||||
|
# This file must be checked in Version Control Systems.
|
||||||
|
#
|
||||||
|
# To customize properties used by the Ant build system use,
|
||||||
|
# "build.properties", and override values to adapt the script to your
|
||||||
|
# project structure.
|
||||||
|
|
||||||
|
# Project target.
|
||||||
|
target=android-8
|
31
androidgcs/gen/org/openpilot/androidgcs/R.java
Normal file
31
androidgcs/gen/org/openpilot/androidgcs/R.java
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/* AUTO-GENERATED FILE. DO NOT MODIFY.
|
||||||
|
*
|
||||||
|
* This class was automatically generated by the
|
||||||
|
* aapt tool from the resource data it found. It
|
||||||
|
* should not be modified by hand.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.openpilot.androidgcs;
|
||||||
|
|
||||||
|
public final class R {
|
||||||
|
public static final class attr {
|
||||||
|
}
|
||||||
|
public static final class color {
|
||||||
|
public static final int all_black=0x7f050001;
|
||||||
|
public static final int all_white=0x7f050000;
|
||||||
|
}
|
||||||
|
public static final class drawable {
|
||||||
|
public static final int icon=0x7f020000;
|
||||||
|
}
|
||||||
|
public static final class id {
|
||||||
|
public static final int objects=0x7f060000;
|
||||||
|
}
|
||||||
|
public static final class layout {
|
||||||
|
public static final int main=0x7f030000;
|
||||||
|
public static final int objectbrowser=0x7f030001;
|
||||||
|
}
|
||||||
|
public static final class string {
|
||||||
|
public static final int app_name=0x7f040001;
|
||||||
|
public static final int hello=0x7f040000;
|
||||||
|
}
|
||||||
|
}
|
36
androidgcs/proguard.cfg
Normal file
36
androidgcs/proguard.cfg
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
-optimizationpasses 5
|
||||||
|
-dontusemixedcaseclassnames
|
||||||
|
-dontskipnonpubliclibraryclasses
|
||||||
|
-dontpreverify
|
||||||
|
-verbose
|
||||||
|
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
|
||||||
|
|
||||||
|
-keep public class * extends android.app.Activity
|
||||||
|
-keep public class * extends android.app.Application
|
||||||
|
-keep public class * extends android.app.Service
|
||||||
|
-keep public class * extends android.content.BroadcastReceiver
|
||||||
|
-keep public class * extends android.content.ContentProvider
|
||||||
|
-keep public class * extends android.app.backup.BackupAgentHelper
|
||||||
|
-keep public class * extends android.preference.Preference
|
||||||
|
-keep public class com.android.vending.licensing.ILicensingService
|
||||||
|
|
||||||
|
-keepclasseswithmembernames class * {
|
||||||
|
native <methods>;
|
||||||
|
}
|
||||||
|
|
||||||
|
-keepclasseswithmembernames class * {
|
||||||
|
public <init>(android.content.Context, android.util.AttributeSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
-keepclasseswithmembernames class * {
|
||||||
|
public <init>(android.content.Context, android.util.AttributeSet, int);
|
||||||
|
}
|
||||||
|
|
||||||
|
-keepclassmembers enum * {
|
||||||
|
public static **[] values();
|
||||||
|
public static ** valueOf(java.lang.String);
|
||||||
|
}
|
||||||
|
|
||||||
|
-keep class * implements android.os.Parcelable {
|
||||||
|
public static final android.os.Parcelable$Creator *;
|
||||||
|
}
|
BIN
androidgcs/res/drawable-hdpi/icon.png
Normal file
BIN
androidgcs/res/drawable-hdpi/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 47 KiB |
BIN
androidgcs/res/drawable-ldpi/icon.png
Normal file
BIN
androidgcs/res/drawable-ldpi/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 47 KiB |
BIN
androidgcs/res/drawable-mdpi/icon.png
Normal file
BIN
androidgcs/res/drawable-mdpi/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 47 KiB |
12
androidgcs/res/layout/main.xml
Normal file
12
androidgcs/res/layout/main.xml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
>
|
||||||
|
<TextView
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/hello"
|
||||||
|
/>
|
||||||
|
</LinearLayout>
|
8
androidgcs/res/layout/objectbrowser.xml
Normal file
8
androidgcs/res/layout/objectbrowser.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:background="@color/all_white">
|
||||||
|
<ExpandableListView android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/objects"></ExpandableListView>
|
||||||
|
</LinearLayout>
|
7
androidgcs/res/values/strings.xml
Normal file
7
androidgcs/res/values/strings.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="hello">OpenPilot Android GCS</string>
|
||||||
|
<string name="app_name">OpieMobi</string>
|
||||||
|
<color name="all_white">#FFFFFF</color>
|
||||||
|
<color name="all_black">#000000</color>
|
||||||
|
</resources>
|
@ -0,0 +1,99 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.openpilot.androidgcs;
|
||||||
|
|
||||||
|
import android.widget.AbsListView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.view.Gravity;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.BaseExpandableListAdapter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author jcotton81
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ObjBrowserExpandableListAdapter extends BaseExpandableListAdapter {
|
||||||
|
|
||||||
|
// Sample data set. children[i] contains the children (String[]) for
|
||||||
|
// groups[i].
|
||||||
|
private String[] groups = { "Parent1", "Parent2", "Parent3" };
|
||||||
|
private String[][] children = { { "Child1" },{ "Child2" }, { "Child3" },{ "Child4" }, { "Child5" } };
|
||||||
|
|
||||||
|
private Context context;
|
||||||
|
|
||||||
|
public ObjBrowserExpandableListAdapter(Context context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getChild(int groupPosition, int childPosition) {
|
||||||
|
return children[groupPosition][childPosition];
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getChildId(int groupPosition, int childPosition) {
|
||||||
|
return childPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getChildrenCount(int groupPosition) {
|
||||||
|
int i = 0;
|
||||||
|
try {
|
||||||
|
i = children[groupPosition].length;
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextView getGenericView() {
|
||||||
|
// Layout parameters for the ExpandableListView
|
||||||
|
AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.FILL_PARENT, 64);
|
||||||
|
|
||||||
|
TextView textView = new TextView(context);
|
||||||
|
textView.setLayoutParams(lp);
|
||||||
|
// Center the text vertically
|
||||||
|
textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
|
||||||
|
// Set the text starting position
|
||||||
|
textView.setPadding(36, 0, 0, 0);
|
||||||
|
return textView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public View getChildView(int groupPosition, int childPosition,
|
||||||
|
boolean isLastChild, View convertView, ViewGroup parent) {
|
||||||
|
TextView textView = getGenericView();
|
||||||
|
textView.setText(getChild(groupPosition, childPosition).toString());
|
||||||
|
return textView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getGroup(int groupPosition) {
|
||||||
|
return groups[groupPosition];
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getGroupCount() {
|
||||||
|
return groups.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getGroupId(int groupPosition) {
|
||||||
|
return groupPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
public View getGroupView(int groupPosition, boolean isExpanded,
|
||||||
|
View convertView, ViewGroup parent) {
|
||||||
|
TextView textView = getGenericView();
|
||||||
|
textView.setText(getGroup(groupPosition).toString());
|
||||||
|
return textView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isChildSelectable(int groupPosition, int childPosition) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasStableIds() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
21
androidgcs/src/org/openpilot/androidgcs/ObjectBrowser.java
Normal file
21
androidgcs/src/org/openpilot/androidgcs/ObjectBrowser.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package org.openpilot.androidgcs;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import android.widget.*;
|
||||||
|
|
||||||
|
public class ObjectBrowser extends Activity {
|
||||||
|
/** Called when the activity is first created. */
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
setContentView(R.layout.objectbrowser);
|
||||||
|
ExpandableListAdapter mAdapter;
|
||||||
|
ExpandableListView epView = (ExpandableListView) findViewById(R.id.objects);
|
||||||
|
mAdapter = new ObjBrowserExpandableListAdapter(this);
|
||||||
|
epView.setAdapter(mAdapter);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
27
androidgcs/src/org/openpilot/uavtalk/UAVDataObject.java
Normal file
27
androidgcs/src/org/openpilot/uavtalk/UAVDataObject.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
package org.openpilot.uavtalk;
|
||||||
|
|
||||||
|
public abstract class UAVDataObject extends UAVObject {
|
||||||
|
|
||||||
|
public UAVDataObject(int objID, Boolean isSingleInst, Boolean isSet, String name) {
|
||||||
|
super(objID, isSingleInst, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initialize(int instID, UAVMetaObject mobj) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initialize(UAVMetaObject mobj) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Boolean isSettings() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
UAVMetaObject getMetaObject() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract UAVDataObject clone(int instID);
|
||||||
|
|
||||||
|
}
|
50
androidgcs/src/org/openpilot/uavtalk/UAVMetaObject.java
Normal file
50
androidgcs/src/org/openpilot/uavtalk/UAVMetaObject.java
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
package org.openpilot.uavtalk;
|
||||||
|
|
||||||
|
public class UAVMetaObject extends UAVObject {
|
||||||
|
|
||||||
|
public UAVMetaObject(int objID, Boolean isSingleInst, String name) {
|
||||||
|
super(objID, isSingleInst, name);
|
||||||
|
// TODO Auto-generated constructor stub
|
||||||
|
}
|
||||||
|
|
||||||
|
public UAVMetaObject(int objID, String mname, UAVDataObject obj) {
|
||||||
|
// TODO Auto-generated constructor stub
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deserialize(byte[] arr, int offset) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UAVMetaObject getDefaultMetadata() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getObjID() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getObjName() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] serialize() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
117
androidgcs/src/org/openpilot/uavtalk/UAVObject.java
Normal file
117
androidgcs/src/org/openpilot/uavtalk/UAVObject.java
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
package org.openpilot.uavtalk;
|
||||||
|
|
||||||
|
public abstract class UAVObject {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Object update mode
|
||||||
|
*/
|
||||||
|
public enum UpdateMode {
|
||||||
|
UPDATEMODE_PERIODIC, /** Automatically update object at periodic intervals */
|
||||||
|
UPDATEMODE_ONCHANGE, /** Only update object when its data changes */
|
||||||
|
UPDATEMODE_MANUAL, /** Manually update object, by calling the updated() function */
|
||||||
|
UPDATEMODE_NEVER /** Object is never updated */
|
||||||
|
} ;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Access mode
|
||||||
|
*/
|
||||||
|
public enum AccessMode{
|
||||||
|
ACCESS_READWRITE,
|
||||||
|
ACCESS_READONLY
|
||||||
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
private Boolean isSingleInst;
|
||||||
|
private int instID;
|
||||||
|
private UAVMetaObject meta;
|
||||||
|
|
||||||
|
public UAVObject(int objID, Boolean isSingleInst, String name) {
|
||||||
|
assert(objID == getObjID()); // ID is in implementation code, make sure it matches object
|
||||||
|
assert(name.equals(getName()));
|
||||||
|
this.isSingleInst = isSingleInst;
|
||||||
|
meta = getDefaultMetadata();
|
||||||
|
};
|
||||||
|
|
||||||
|
public void initialize(int instID) {
|
||||||
|
this.instID = instID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getInstID() { return instID; }
|
||||||
|
public Boolean isSingleInstance() { return isSingleInst; }
|
||||||
|
public String getName() { return getObjName(); } // matching QT API to the current autogen code
|
||||||
|
|
||||||
|
public abstract int getObjID();
|
||||||
|
public abstract String getDescription();
|
||||||
|
public abstract String getObjName();
|
||||||
|
|
||||||
|
int getNumBytes() {
|
||||||
|
return serialize().length;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The name of the serializer and deserialize from the autogenerated code
|
||||||
|
public abstract byte[] serialize();
|
||||||
|
public abstract void deserialize(byte[] arr,int offset);
|
||||||
|
|
||||||
|
byte [] pack() {
|
||||||
|
return serialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
Boolean unpack(byte [] data) {
|
||||||
|
deserialize(data, 0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMetadata(UAVMetaObject obj) { meta = obj; }
|
||||||
|
public UAVMetaObject getMetadata() { return meta; }
|
||||||
|
public abstract UAVMetaObject getDefaultMetadata();
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Unported code from QT
|
||||||
|
bool save();
|
||||||
|
bool save(QFile& file);
|
||||||
|
bool load();
|
||||||
|
bool load(QFile& file);
|
||||||
|
virtual void setMetadata(const Metadata& mdata) = 0;
|
||||||
|
virtual Metadata getMetadata() = 0;
|
||||||
|
virtual Metadata getDefaultMetadata() = 0;
|
||||||
|
void requestUpdate();
|
||||||
|
void updated();
|
||||||
|
void lock();
|
||||||
|
void lock(int timeoutMs);
|
||||||
|
void unlock();
|
||||||
|
QMutex* getMutex();
|
||||||
|
qint32 getNumFields();
|
||||||
|
QList<UAVObjectField*> getFields();
|
||||||
|
UAVObjectField* getField(const QString& name);
|
||||||
|
QString toString();
|
||||||
|
QString toStringBrief();
|
||||||
|
QString toStringData();
|
||||||
|
void emitTransactionCompleted(bool success);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void objectUpdated(UAVObject* obj);
|
||||||
|
void objectUpdatedAuto(UAVObject* obj);
|
||||||
|
void objectUpdatedManual(UAVObject* obj);
|
||||||
|
void objectUnpacked(UAVObject* obj);
|
||||||
|
void updateRequested(UAVObject* obj);
|
||||||
|
void transactionCompleted(UAVObject* obj, bool success);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void fieldUpdated(UAVObjectField* field);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
quint32 objID;
|
||||||
|
quint32 instID;
|
||||||
|
bool isSingleInst;
|
||||||
|
QString name;
|
||||||
|
QString description;
|
||||||
|
quint32 numBytes;
|
||||||
|
QMutex* mutex;
|
||||||
|
quint8* data;
|
||||||
|
QList<UAVObjectField*> fields;
|
||||||
|
|
||||||
|
void initializeFields(QList<UAVObjectField*>& fields, quint8* data, quint32 numBytes);
|
||||||
|
void setDescription(const QString& description);
|
||||||
|
*/
|
||||||
|
}
|
332
androidgcs/src/org/openpilot/uavtalk/UAVObjectManager.java
Normal file
332
androidgcs/src/org/openpilot/uavtalk/UAVObjectManager.java
Normal file
@ -0,0 +1,332 @@
|
|||||||
|
package org.openpilot.uavtalk;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ListIterator;
|
||||||
|
|
||||||
|
public class UAVObjectManager {
|
||||||
|
|
||||||
|
private final int MAX_INSTANCES = 10;
|
||||||
|
|
||||||
|
// Use array list to store objects since rarely added or deleted
|
||||||
|
private List<List<UAVObject>> objects = new ArrayList<List<UAVObject>>();
|
||||||
|
|
||||||
|
public UAVObjectManager()
|
||||||
|
{
|
||||||
|
//mutex = new QMutex(QMutex::Recursive);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register an object with the manager. This function must be called for all newly created instances.
|
||||||
|
* A new instance can be created directly by instantiating a new object or by calling clone() of
|
||||||
|
* an existing object. The object will be registered and will be properly initialized so that it can accept
|
||||||
|
* updates.
|
||||||
|
*/
|
||||||
|
Boolean registerObject(UAVDataObject obj)
|
||||||
|
{
|
||||||
|
// QMutexLocker locker(mutex);
|
||||||
|
|
||||||
|
ListIterator<List<UAVObject>> objIt = objects.listIterator(0);
|
||||||
|
|
||||||
|
// Check if this object type is already in the list
|
||||||
|
while(objIt.hasNext()) {
|
||||||
|
List<UAVObject> instList = objIt.next();
|
||||||
|
|
||||||
|
// Check if the object ID is in the list
|
||||||
|
if( (instList.size() > 0) && (instList.get(0).getObjID() == obj.getObjID() )) {
|
||||||
|
// Check if this is a single instance object, if yes we can not add a new instance
|
||||||
|
if(obj.isSingleInstance()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// The object type has alredy been added, so now we need to initialize the new instance with the appropriate id
|
||||||
|
// There is a single metaobject for all object instances of this type, so no need to create a new one
|
||||||
|
// Get object type metaobject from existing instance
|
||||||
|
UAVDataObject refObj = (UAVDataObject) instList.get(0);
|
||||||
|
if (refObj == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
UAVMetaObject mobj = refObj.getMetaObject();
|
||||||
|
|
||||||
|
// Make sure we aren't requesting to create too many instances
|
||||||
|
if(obj.getInstID() >= MAX_INSTANCES || instList.size() >= MAX_INSTANCES || obj.getInstID() < 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If InstID is zero then we find the next open instId and create it
|
||||||
|
if (obj.getInstID() == 0)
|
||||||
|
{
|
||||||
|
// Assign the next available ID and initialize the object instance the nadd
|
||||||
|
obj.initialize(instList.size(), mobj);
|
||||||
|
instList.add(obj);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if that inst ID already exists
|
||||||
|
ListIterator<UAVObject> instIter = instList.listIterator();
|
||||||
|
while(instIter.hasNext()) {
|
||||||
|
UAVObject testObj = instIter.next();
|
||||||
|
if(testObj.getInstID() == obj.getInstID()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the instance ID is specified and not at the default value (0) then we need to make sure
|
||||||
|
// that there are no gaps in the instance list. If gaps are found then then additional instances
|
||||||
|
// will be created.
|
||||||
|
for(int instID = instList.size(); instID < obj.getInstID(); instID++) {
|
||||||
|
UAVDataObject newObj = obj.clone(instID);
|
||||||
|
newObj.initialize(mobj);
|
||||||
|
instList.add(newObj);
|
||||||
|
// emit new instance signal
|
||||||
|
}
|
||||||
|
obj.initialize(mobj);
|
||||||
|
//emit new instance signal
|
||||||
|
instList.add(obj);
|
||||||
|
|
||||||
|
instIter = instList.listIterator();
|
||||||
|
while(instIter.hasNext()) {
|
||||||
|
UAVObject testObj = instIter.next();
|
||||||
|
if(testObj.getInstID() == obj.getInstID()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Check if there are any gaps between the requested instance ID and the ones in the list,
|
||||||
|
// if any then create the missing instances.
|
||||||
|
for (int instId = instList.size(); instId < obj.getInstID(); ++instId)
|
||||||
|
{
|
||||||
|
UAVDataObject cobj = obj.clone(instId);
|
||||||
|
cobj.initialize(mobj);
|
||||||
|
instList.add(cobj);
|
||||||
|
// emit newInstance(cobj);
|
||||||
|
}
|
||||||
|
// Finally, initialize the actual object instance
|
||||||
|
obj.initialize(mobj);
|
||||||
|
// Add the actual object instance in the list
|
||||||
|
instList.add(obj);
|
||||||
|
//emit newInstance(obj);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// If this point is reached then this is the first time this object type (ID) is added in the list
|
||||||
|
// create a new list of the instances, add in the object collection and create the object's metaobject
|
||||||
|
// Create metaobject
|
||||||
|
String mname = obj.getName();
|
||||||
|
mname += "Meta";
|
||||||
|
UAVMetaObject mobj = new UAVMetaObject(obj.getObjID()+1, mname, obj);
|
||||||
|
// Initialize object
|
||||||
|
obj.initialize(0, mobj);
|
||||||
|
// Add to list
|
||||||
|
addObject(obj);
|
||||||
|
addObject(mobj);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void addObject(UAVObject obj)
|
||||||
|
{
|
||||||
|
// Add to list
|
||||||
|
List<UAVObject> ls = new ArrayList<UAVObject>();
|
||||||
|
ls.add(obj);
|
||||||
|
objects.add(ls);
|
||||||
|
//emit newObject(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all objects. A two dimentional QList is returned. Objects are grouped by
|
||||||
|
* instances of the same object type.
|
||||||
|
*/
|
||||||
|
List<List<UAVObject>> getObjects()
|
||||||
|
{
|
||||||
|
//QMutexLocker locker(mutex);
|
||||||
|
return objects;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Same as getObjects() but will only return DataObjects.
|
||||||
|
*/
|
||||||
|
List< List<UAVDataObject> > getDataObjects()
|
||||||
|
{
|
||||||
|
return new ArrayList<List<UAVDataObject>>();
|
||||||
|
|
||||||
|
/* QMutexLocker locker(mutex);
|
||||||
|
QList< QList<UAVDataObject*> > dObjects;
|
||||||
|
|
||||||
|
// Go through objects and copy to new list when types match
|
||||||
|
for (int objidx = 0; objidx < objects.length(); ++objidx)
|
||||||
|
{
|
||||||
|
if (objects[objidx].length() > 0)
|
||||||
|
{
|
||||||
|
// Check type
|
||||||
|
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(objects[objidx][0]);
|
||||||
|
if (obj != NULL)
|
||||||
|
{
|
||||||
|
// Create instance list
|
||||||
|
QList<UAVDataObject*> list;
|
||||||
|
// Go through instances and cast them to UAVDataObject, then add to list
|
||||||
|
for (int instidx = 0; instidx < objects[objidx].length(); ++instidx)
|
||||||
|
{
|
||||||
|
obj = dynamic_cast<UAVDataObject*>(objects[objidx][instidx]);
|
||||||
|
if (obj != NULL)
|
||||||
|
{
|
||||||
|
list.append(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Append to object list
|
||||||
|
dObjects.append(list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
// Done
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Same as getObjects() but will only return MetaObjects.
|
||||||
|
*/
|
||||||
|
List <List<UAVMetaObject> > getMetaObjects()
|
||||||
|
{
|
||||||
|
return new ArrayList< List<UAVMetaObject> >();
|
||||||
|
/*
|
||||||
|
QMutexLocker locker(mutex);
|
||||||
|
QList< QList<UAVMetaObject*> > mObjects;
|
||||||
|
|
||||||
|
// Go through objects and copy to new list when types match
|
||||||
|
for (int objidx = 0; objidx < objects.length(); ++objidx)
|
||||||
|
{
|
||||||
|
if (objects[objidx].length() > 0)
|
||||||
|
{
|
||||||
|
// Check type
|
||||||
|
UAVMetaObject* obj = dynamic_cast<UAVMetaObject*>(objects[objidx][0]);
|
||||||
|
if (obj != NULL)
|
||||||
|
{
|
||||||
|
// Create instance list
|
||||||
|
QList<UAVMetaObject*> list;
|
||||||
|
// Go through instances and cast them to UAVMetaObject, then add to list
|
||||||
|
for (int instidx = 0; instidx < objects[objidx].length(); ++instidx)
|
||||||
|
{
|
||||||
|
obj = dynamic_cast<UAVMetaObject*>(objects[objidx][instidx]);
|
||||||
|
if (obj != NULL)
|
||||||
|
{
|
||||||
|
list.append(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Append to object list
|
||||||
|
mObjects.append(list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Done
|
||||||
|
return mObjects;
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a specific object given its name and instance ID
|
||||||
|
* @returns The object is found or NULL if not
|
||||||
|
*/
|
||||||
|
UAVObject getObject(String name, int instId)
|
||||||
|
{
|
||||||
|
return getObject(name, 0, instId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a specific object given its object and instance ID
|
||||||
|
* @returns The object is found or NULL if not
|
||||||
|
*/
|
||||||
|
UAVObject getObject(int objId, int instId)
|
||||||
|
{
|
||||||
|
return getObject(null, objId, instId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function for the public getObject() functions.
|
||||||
|
*/
|
||||||
|
UAVObject getObject(String name, int objId, int instId)
|
||||||
|
{
|
||||||
|
//QMutexLocker locker(mutex);
|
||||||
|
// Check if this object type is already in the list
|
||||||
|
ListIterator<List<UAVObject>> objIter = objects.listIterator();
|
||||||
|
while(objIter.hasNext()) {
|
||||||
|
List<UAVObject> instList = objIter.next();
|
||||||
|
if (instList.size() > 0) {
|
||||||
|
if ( (name != null && instList.get(0).getName().compareTo(name) == 0) || (name == null && instList.get(0).getObjID() == objId) ) {
|
||||||
|
// Look for the requested instance ID
|
||||||
|
ListIterator<UAVObject> iter = instList.listIterator();
|
||||||
|
while(iter.hasNext()) {
|
||||||
|
UAVObject obj = iter.next();
|
||||||
|
if(obj.getInstID() == instId) {
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all the instances of the object specified by name
|
||||||
|
*/
|
||||||
|
List<UAVObject> getObjectInstances(String name)
|
||||||
|
{
|
||||||
|
return getObjectInstances(name, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all the instances of the object specified by its ID
|
||||||
|
*/
|
||||||
|
List<UAVObject> getObjectInstances(int objId)
|
||||||
|
{
|
||||||
|
return getObjectInstances(null, objId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function for the public getObjectInstances()
|
||||||
|
*/
|
||||||
|
List<UAVObject> getObjectInstances(String name, int objId)
|
||||||
|
{
|
||||||
|
//QMutexLocker locker(mutex);
|
||||||
|
// Check if this object type is already in the list
|
||||||
|
ListIterator<List<UAVObject>> objIter = objects.listIterator();
|
||||||
|
while(objIter.hasNext()) {
|
||||||
|
List<UAVObject> instList = objIter.next();
|
||||||
|
if (instList.size() > 0) {
|
||||||
|
if ( (name != null && instList.get(0).getName().compareTo(name) == 0) || (name == null && instList.get(0).getObjID() == objId) ) {
|
||||||
|
return instList;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the number of instances for an object given its name
|
||||||
|
*/
|
||||||
|
int getNumInstances(String name)
|
||||||
|
{
|
||||||
|
return getNumInstances(name, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the number of instances for an object given its ID
|
||||||
|
*/
|
||||||
|
int getNumInstances(int objId)
|
||||||
|
{
|
||||||
|
return getNumInstances(null, objId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper function for public getNumInstances
|
||||||
|
*/
|
||||||
|
int getNumInstances(String name, int objId)
|
||||||
|
{
|
||||||
|
return getObjectInstances(name,objId).size();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user