aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/dsi/ant/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/dsi/ant/core')
-rw-r--r--src/com/dsi/ant/core/IJAntEnum.java23
-rw-r--r--src/com/dsi/ant/core/JAntJava.java293
-rw-r--r--src/com/dsi/ant/core/JAntStatus.java61
-rw-r--r--src/com/dsi/ant/core/JAntUtils.java44
4 files changed, 421 insertions, 0 deletions
diff --git a/src/com/dsi/ant/core/IJAntEnum.java b/src/com/dsi/ant/core/IJAntEnum.java
new file mode 100644
index 0000000..3a1a825
--- /dev/null
+++ b/src/com/dsi/ant/core/IJAntEnum.java
@@ -0,0 +1,23 @@
+/*
+ * ANT Stack
+ *
+ * Copyright 2009 Dynastream Innovations
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.dsi.ant.core;
+
+public interface IJAntEnum<V> {
+ V getValue();
+}
+
diff --git a/src/com/dsi/ant/core/JAntJava.java b/src/com/dsi/ant/core/JAntJava.java
new file mode 100644
index 0000000..836f320
--- /dev/null
+++ b/src/com/dsi/ant/core/JAntJava.java
@@ -0,0 +1,293 @@
+/*
+ * ANT Stack
+ *
+ * Copyright 2009 Dynastream Innovations
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.dsi.ant.core;
+
+import android.util.Log;
+
+import com.dsi.ant.server.AntHalDefine;
+
+
+/** Class for providing connection with JANTNative.cpp module */
+
+public class JAntJava
+{
+ private static final boolean debug = false;
+ private static final String TAG = "JAntJava";
+ private static ICallback mCallback = null;
+
+
+ /** Static constructor */
+ static
+ {
+ try
+ {
+ System.load("libantradio.so");
+ }
+ catch (Exception e)
+ {
+ Log.e("JANT", "Exception during nativeJANT_ClassInitNative (" + e.toString() + ")");
+ }
+ }
+
+ public interface ICallback
+ {
+ void ANTRxMessage(byte[] RxMessage);
+ void ANTStateChange(int NewState);
+ }
+ /*******************************************************************************
+ *
+ * Class Methods
+ *
+ *******************************************************************************/
+
+ public JAntStatus create(ICallback callback)
+ {
+ JAntStatus jAntStatus;
+
+ try
+ {
+ if (debug)
+ Log.d(TAG, "Calling nativeJAnt_Create");
+ int AntStatus = nativeJAnt_Create();
+ jAntStatus = JAntUtils.getEnumConst(JAntStatus.class, AntStatus);
+
+ // Record the caller's callback if create was successful
+ if (JAntStatus.SUCCESS == jAntStatus)
+ {
+ if (debug)
+ Log.d(TAG, "create: nativeJAnt_Create returned success");
+ mCallback = callback;
+ }
+ else
+ {
+ Log.e(TAG, "create: nativeJAnt_Create failed " + jAntStatus);
+ }
+ }
+ catch(Exception e)
+ {
+ Log.e(TAG, "create: exception during nativeJAnt_Create (" + e.toString() + ")");
+ jAntStatus = JAntStatus.FAILED;
+ }
+
+ return jAntStatus;
+ }
+
+ public JAntStatus destroy()
+ {
+ if (debug)
+ Log.d(TAG, "destroy: entered");
+ JAntStatus jAntStatus;
+
+ try
+ {
+ int AntStatus = nativeJAnt_Destroy();
+ jAntStatus = JAntUtils.getEnumConst(JAntStatus.class, AntStatus);
+ if (JAntStatus.SUCCESS == jAntStatus)
+ {
+ if (debug)
+ Log.d(TAG, "destroy: nativeJAnt_Destroy returned success");
+ mCallback = null;
+ }
+ else
+ {
+ Log.e(TAG, "destroy: nativeJAnt_Destroy failed " + jAntStatus);
+ }
+ }
+ catch (Exception e)
+ {
+ Log.e(TAG, "destroy: exception during nativeJAnt_Destroy (" + e.toString() + ")");
+ jAntStatus = JAntStatus.FAILED;
+ }
+
+ if (debug)
+ Log.d(TAG, "destroy: exiting");
+
+ return jAntStatus;
+ }
+
+ public JAntStatus enable()
+ {
+ if (debug)
+ Log.d(TAG, "enable: entered");
+
+ JAntStatus jAntStatus;
+
+ try
+ {
+ int AntStatus = nativeJAnt_Enable();
+ jAntStatus = JAntUtils.getEnumConst(JAntStatus.class, AntStatus);
+ if (debug)
+ Log.d(TAG, "After nativeJAnt_Enable, status = " + jAntStatus.toString());
+ }
+ catch (Exception e)
+ {
+ Log.e(TAG, "enable: exception during nativeJAnt_enable (" + e.toString() + ")");
+ jAntStatus = JAntStatus.FAILED;
+ }
+
+ if (debug)
+ Log.d(TAG, "enable: exiting");
+
+ return jAntStatus;
+ }
+
+
+ public JAntStatus disable()
+ {
+ if (debug)
+ Log.d(TAG, "disable: entered");
+
+ JAntStatus jAntStatus;
+
+ try
+ {
+ int status = nativeJAnt_Disable();
+ jAntStatus = JAntUtils.getEnumConst(JAntStatus.class, status);
+ if (debug)
+ Log.d(TAG, "After nativeJAnt_Disable, status = " + jAntStatus.toString());
+ }
+ catch (Exception e)
+ {
+ Log.e(TAG, "disable: exception during nativeJAnt_Disable (" + e.toString() + ")");
+ jAntStatus = JAntStatus.FAILED;
+ }
+
+ if (debug)
+ Log.d(TAG, "disable: exiting");
+
+ return jAntStatus;
+ }
+
+ public int getRadioEnabledStatus()
+ {
+ if (debug) Log.d(TAG, "getRadioEnabledStatus: entered");
+ int retStatus;
+ try
+ {
+ retStatus = nativeJAnt_GetRadioEnabledStatus();
+ if (debug) Log.i(TAG, "Got ANT status as " + retStatus);
+ }
+ catch (Exception e)
+ {
+ Log.e(TAG, "getRadioEnabledStatus: exception during call (" + e.toString() + ")");
+ retStatus = AntHalDefine.ANT_HAL_STATE_UNKNOWN;
+ }
+ if (debug) Log.d(TAG, "getRadioEnabledStatus: exiting");
+ return retStatus;
+ }
+
+ public JAntStatus ANTTxMessage(byte[] message)
+ {
+ if (debug)
+ Log.d(TAG, "ANTTxMessage: entered");
+ JAntStatus jAntStatus;
+
+ try
+ {
+ int AntStatus = nativeJAnt_TxMessage(message);
+ jAntStatus = JAntUtils.getEnumConst(JAntStatus.class, AntStatus);
+ if (debug)
+ Log.d(TAG, "After nativeJAnt_ANTTxMessage, status = " + jAntStatus.toString());
+ }
+ catch (Exception e)
+ {
+ Log.e(TAG, "ANTTxMessage: exception during nativeJAnt_ANTTxMessage (" + e.toString() + ")");
+ jAntStatus = JAntStatus.FAILED;
+ }
+
+ if (debug)
+ Log.d(TAG, "ANTTxMessage: exiting");
+ return jAntStatus;
+ }
+
+ public JAntStatus hardReset()
+ {
+ if (debug)
+ Log.d(TAG, "hardReset: entered");
+
+ JAntStatus jAntStatus;
+
+ try
+ {
+ int status = nativeJAnt_HardReset();
+ jAntStatus = JAntUtils.getEnumConst(JAntStatus.class, status);
+ if (debug)
+ Log.d(TAG, "After nativeJAnt_HardReset, status = " + jAntStatus.toString());
+ }
+ catch (Exception e)
+ {
+ Log.e(TAG, "hardReset: exception during nativeJAnt_HardReset, (" + e.toString() + ")");
+ jAntStatus = JAntStatus.FAILED;
+ }
+
+ if (debug)
+ Log.d(TAG, "hardReset:: exiting");
+
+ return jAntStatus;
+ }
+
+ /* --------------------------------
+ * NATIVE PART
+ * --------------------------------
+ */
+ /* RBTL Calls */
+ private static native int nativeJAnt_Create();
+ private static native int nativeJAnt_Destroy();
+ private static native int nativeJAnt_Enable();
+ private static native int nativeJAnt_Disable();
+ private static native int nativeJAnt_GetRadioEnabledStatus();
+ private static native int nativeJAnt_TxMessage(byte[] message);
+ private static native int nativeJAnt_HardReset();
+
+
+ /* ----------------------------------------------
+ * Callbacks from the JAntNative.cpp module
+ * ----------------------------------------------
+ */
+ public static void nativeCb_AntRxMessage(byte[] RxMessage)
+ {
+ if (debug)
+ Log.d(TAG, "nativeCb_AntRxMessage: calling callback");
+
+ if (mCallback != null)
+ {
+ mCallback.ANTRxMessage(RxMessage);
+ }
+ else
+ {
+ Log.e(TAG, "nativeCb_AntRxMessage: callback is null");
+ }
+ }
+
+ public static void nativeCb_AntStateChange(int NewState)
+ {
+ if (debug)
+ Log.d(TAG, "nativeCb_AntStateChange: calling callback");
+
+ if (mCallback != null)
+ {
+ mCallback.ANTStateChange(NewState);
+ }
+ else
+ {
+ Log.e(TAG, "nativeCb_AntStateChange: callback is null");
+ }
+ }
+
+} /* End class */
+
diff --git a/src/com/dsi/ant/core/JAntStatus.java b/src/com/dsi/ant/core/JAntStatus.java
new file mode 100644
index 0000000..7ee6c43
--- /dev/null
+++ b/src/com/dsi/ant/core/JAntStatus.java
@@ -0,0 +1,61 @@
+/*
+ * ANT Stack
+ *
+ * Copyright 2009 Dynastream Innovations
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.dsi.ant.core;
+
+public enum JAntStatus implements IJAntEnum<Integer> {
+
+SUCCESS (0),
+FAILED (1),
+PENDING (2),
+INVALID_PARM (3),
+IN_PROGRESS (4),
+NOT_APPLICABLE (5),
+NOT_SUPPORTED (6),
+INTERNAL_ERROR (7),
+TRANSPORT_INIT_ERR (8),
+HARDWARE_ERR (9),
+NO_VALUE_AVAILABLE (10),
+CONTEXT_DOESNT_EXIST (11),
+CONTEXT_NOT_DESTROYED (12),
+CONTEXT_NOT_ENABLED (13),
+CONTEXT_NOT_DISABLED (14),
+NOT_DE_INITIALIZED (15),
+NOT_INITIALIZED (16),
+TOO_MANY_PENDING_CMDS (17),
+DISABLING_IN_PROGRESS (18),
+COMMAND_WRITE_FAILED (20),
+SCRIPT_EXEC_FAILED (21),
+
+FAILED_BT_NOT_INITIALIZED (23),
+AUDIO_OPERATION_UNAVAILIBLE_RESOURCES (24),
+
+NO_VALUE (100);
+
+ private final int value;
+
+ private JAntStatus(int value)
+ {
+ this.value = value;
+ }
+
+ public Integer getValue()
+ {
+ return value;
+ }
+}
+
diff --git a/src/com/dsi/ant/core/JAntUtils.java b/src/com/dsi/ant/core/JAntUtils.java
new file mode 100644
index 0000000..a9ff0ac
--- /dev/null
+++ b/src/com/dsi/ant/core/JAntUtils.java
@@ -0,0 +1,44 @@
+/*
+ * ANT Stack
+ *
+ * Copyright 2009 Dynastream Innovations
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.dsi.ant.core;
+
+import java.lang.Enum;
+import java.util.EnumSet;
+
+public final class JAntUtils {
+
+ public static <V, E extends Enum<E> & IJAntEnum<V>> E getEnumConst(Class<E> enumType, V constValue) {
+ EnumSet<E> es = EnumSet.allOf(enumType);
+
+ E matchingConst = null;
+
+ for (E enumConst: es) {
+ if (enumConst.getValue().equals(constValue))
+ {
+ matchingConst = enumConst;
+ break;
+ }
+ }
+
+ if (matchingConst == null) {
+ //Log.e(TAG, "getEnumConst: Invalid const (" + constValue + ") for " + enumType.toString());
+ }
+ return matchingConst;
+ }
+}
+