araepm: basic skeleton. initial port from araplox project
-Basic DME class for doing local/peer [GET/SET]REQ.
-Adds a button to do a local GETREQ on 0xd020 for testing
Testing Done:
None whatsoever.
diff --git a/res/layout/activity_main.xml b/res/layout/activity_main.xml
index 0befe60..92f43a4 100644
--- a/res/layout/activity_main.xml
+++ b/res/layout/activity_main.xml
@@ -13,4 +13,9 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
+
+ <Button
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:onClick="getReq" />
</RelativeLayout>
diff --git a/src/com/projectara/araepm/DME.java b/src/com/projectara/araepm/DME.java
new file mode 100644
index 0000000..b25b026
--- /dev/null
+++ b/src/com/projectara/araepm/DME.java
@@ -0,0 +1,241 @@
+package com.projectara.araepm;
+
+import android.hardware.I2cManager;
+import android.hardware.I2cTransaction;
+import android.util.Log;
+import java.io.IOException;
+
+public class DME {
+ private static final int slaveAddress = 0x44;
+ private static final String TAG = "DME";
+ private static String i2cBus;
+ private I2cManager i2c;
+
+ public static enum AttributeId {
+ T_PEERDEVICEID (0x4021),
+ T_PEERCPORTID (0x4022),
+ T_CONNECTIONSTATE (0x4020),
+ T_TRAFFICCLASS (0x4023),
+ T_PROTOCOLID (0x4024),
+ T_CPORTFLAGS (0x4025),
+ T_TXTOKENVALUE (0x4026),
+ T_RXTOKENVALUE (0x4027),
+ T_LOCALBUFFERSPACE(0x4028),
+ T_PEERBUFFERSPACE (0x4029),
+ T_CREDITSTOSEND (0x402A),
+ T_CPORTMODE (0x402B),
+ DME_LINKSTARTUP (0xD020);
+
+ private int id;
+ private AttributeId(int id) {
+ this.id = id;
+ }
+ }
+
+ public static enum FunctionId {
+ C0_SETREQ (0x00),
+ C0_SETCNF (0x01),
+ C0_PEERSETREQ (0x02),
+ C0_PEERSETCNF (0x03),
+ C0_GETREQ (0x04),
+ C0_GETCNF (0x05),
+ C0_PEERGETREQ (0x06),
+ C0_PEERGETCNF (0x07),
+ C0_LUTSETREQ (0x08),
+ C0_LUTSETCNF (0x09),
+ C0_LUTGETREQ (0x0a),
+ C0_LUTGETCNF (0x0b),
+ C0_SWITCHATTRSETREQ (0x0c),
+ C0_SWITCHATTRSETCNF (0x0d),
+ C0_SWITCHATTRGETREQ (0x0e),
+ C0_SWITCHATTERGETCNF(0x0f);
+
+ private int id;
+ private FunctionId(int id) {
+ this.id = id;
+ }
+ }
+
+ private class SetRequest {
+ int portId;
+ FunctionId functionId;
+ AttributeId attrId;
+ int selectorIndex;
+ int attrVal;
+
+ public byte[] getBytes() {
+ byte[] rawBytes = new byte[10];
+ rawBytes[0] = (byte)(portId & 0xFF);
+
+ rawBytes[1] = (byte)(functionId.id & 0xFF);
+
+ rawBytes[2] = (byte)((attrId.id >> 8) & 0xFF); // msb
+ rawBytes[3] = (byte)(attrId.id & 0xFF); // lsb
+
+ rawBytes[4] = (byte)((selectorIndex >> 8) & 0xFF);
+ rawBytes[5] = (byte)((selectorIndex) & 0xFF);
+
+ rawBytes[6] = (byte)((attrVal >> 24) & 0xFF);
+ rawBytes[7] = (byte)((attrVal >> 16) & 0xFF);
+ rawBytes[8] = (byte)((attrVal >> 8) & 0xFF);
+ rawBytes[9] = (byte)((attrVal) & 0xFF);
+ return rawBytes;
+ }
+ }
+
+ private class SetCnf {
+ public static final int MSG_SIZE = 4;
+ int portId;
+ FunctionId functionId;
+ int resultCode;
+
+ public SetCnf(byte[] setCnfBytes) {
+ portId = setCnfBytes[0] & 0xFF;
+ functionId = FunctionId.values()[setCnfBytes[1] & 0xFF];
+ resultCode = (((int)setCnfBytes[2] & 0xFF) << 8) |
+ (((int)setCnfBytes[3] & 0xFF));
+ }
+ }
+
+
+ private class GetRequest {
+ int portId;
+ FunctionId functionId;
+ AttributeId attrId;
+ int selectorIndex;
+
+ public byte[] getBytes() {
+ byte[] rawBytes = new byte[6];
+ rawBytes[0] = (byte)(portId & 0xFF);
+
+ rawBytes[1] = (byte)(functionId.id & 0xFF);
+
+ rawBytes[2] = (byte)((attrId.id >> 8) & 0xFF);
+ rawBytes[3] = (byte)(attrId.id & 0xFF);
+
+ rawBytes[4] = (byte)((selectorIndex >> 8) & 0xFF);
+ rawBytes[5] = (byte)((selectorIndex) & 0xFF);
+ return rawBytes;
+ }
+ }
+
+ private class GetCnf {
+ public static final int MSG_SIZE = 8;
+ int portId;
+ FunctionId functionId;
+ int resultCode;
+ int attrVal;
+
+ public GetCnf(byte[] getCnfBytes) {
+ portId = getCnfBytes[0] & 0xFF;
+ functionId = FunctionId.values()[getCnfBytes[1] & 0xFF];
+ resultCode = (((int)getCnfBytes[2] & 0xFF) << 8) |
+ (((int)getCnfBytes[3] & 0xFF));
+
+ attrVal = (((int)getCnfBytes[4] & 0xFF) << 24) |
+ (((int)getCnfBytes[5] & 0xFF) << 16) |
+ (((int)getCnfBytes[6] & 0xFF) << 8) |
+ (((int)getCnfBytes[7] & 0xFF));
+ }
+ }
+
+ public DME(I2cManager i2c) {
+ this.i2c = i2c;
+ this.i2cBus = i2c.getI2cBuses()[0];
+ }
+
+ // api_write_switch_config
+ public void writeDMEConfig(int port, boolean peer, AttributeId attrId,
+ int selectorIndex, int attrVal,
+ int expectedResultCode) throws IOException {
+ I2cTransaction txn = null;
+ SetRequest setReq = new SetRequest();
+
+ setReq.portId = port;
+ setReq.functionId = peer ? FunctionId.C0_PEERSETREQ : FunctionId.C0_SETREQ;
+ setReq.attrId = attrId;
+ setReq.selectorIndex = selectorIndex;
+ setReq.attrVal = attrVal;
+
+ Log.d(TAG, "writeDMEConfig: setReq(): portID: " + setReq.portId);
+ Log.d(TAG, "writeDMEConfig: setReq(): functionId: " + setReq.functionId);
+ Log.d(TAG, "writeDMEConfig: setReq(): attrId: " + setReq.attrId);
+ Log.d(TAG, "writeDMEConfig: setReq(): selectorIndex: " + setReq.selectorIndex);
+ Log.d(TAG, "writeDMEConfig: setReq(): attrVal: " + setReq.attrVal);
+
+
+ txn = I2cTransaction.newWrite(setReq.getBytes());
+ I2cTransaction[] results;
+ try {
+ results = i2c.performTransactions(i2cBus, slaveAddress, txn);
+ } catch (IOException e) {
+ return;
+ }
+
+ txn = I2cTransaction.newRead(SetCnf.MSG_SIZE);
+ try {
+ results = i2c.performTransactions(i2cBus, slaveAddress, txn);
+ } catch (IOException e) {
+ Log.e(TAG, "SetCnf: " + e.toString());
+ throw e;
+ }
+ SetCnf setCnf = new SetCnf(results[0].data);
+
+ if (setCnf.resultCode != 0) {
+ Log.e(TAG, "Unexpected resultCode: " + setCnf.resultCode);
+ }
+
+ Log.d(TAG, "setCnf portId: " + setCnf.portId);
+ Log.d(TAG, "setCnf functionId: " + setCnf.functionId);
+ Log.d(TAG, "setCnf resultCode: " + setCnf.resultCode);
+ }
+
+ public int readDMEConfig(int port,
+ boolean peer,
+ AttributeId attrId,
+ int selectorIndex,
+ int expectedResultCode) throws IOException {
+ I2cTransaction txn = null;
+ GetRequest getReq = new GetRequest();
+
+ getReq.portId = port;
+ getReq.functionId = peer ? FunctionId.C0_PEERGETREQ : FunctionId.C0_GETREQ;
+ getReq.attrId = attrId;
+ getReq.selectorIndex = selectorIndex;
+
+ Log.d(TAG, "readDMEConfig: getReq(): portID: " + getReq.portId);
+ Log.d(TAG, "readDMEConfig: getReq(): functionId: " + getReq.functionId);
+ Log.d(TAG, "readDMEConfig: getReq(): attrId: " + getReq.attrId);
+ Log.d(TAG, "readDMEConfig: getReq(): selectorIndex: " + getReq.selectorIndex);
+
+ txn = I2cTransaction.newWrite(getReq.getBytes());
+
+ I2cTransaction[] results;
+ try {
+ results = i2c.performTransactions(i2cBus, slaveAddress, txn);
+ } catch (IOException e) {
+ Log.e(TAG, "GetReq: " + e.toString());
+ throw e;
+ }
+
+ txn = I2cTransaction.newRead(GetCnf.MSG_SIZE);
+ try {
+ results = i2c.performTransactions(i2cBus, slaveAddress, txn);
+ } catch (IOException e) {
+ Log.e(TAG, "GetCnf: " + e.toString());
+ throw e;
+ }
+ GetCnf getCnf = new GetCnf(results[0].data);
+
+ if (getCnf.resultCode != 0) {
+ Log.e(TAG, "Unexpected resultCode: " + getCnf.resultCode);
+ }
+
+ Log.d(TAG, "getCnf portId: " + getCnf.portId);
+ Log.d(TAG, "getCnf functionId: " + getCnf.functionId);
+ Log.d(TAG, "getCnf resultCode: " + getCnf.resultCode);
+ Log.d(TAG, "getCnf attrVal: " + getCnf.attrVal);
+
+ return getCnf.attrVal;
+ }
+}
diff --git a/src/com/projectara/araepm/L3Switch.java b/src/com/projectara/araepm/L3Switch.java
deleted file mode 100644
index c0fbf28..0000000
--- a/src/com/projectara/araepm/L3Switch.java
+++ /dev/null
@@ -1,160 +0,0 @@
-package com.projectara.araepm;
-
-import android.hardware.I2cManager;
-import android.hardware.I2cTransaction;
-import java.io.IOException;
-
-public class L3Switch {
- private static final int slaveAddress = 0x44;
- private static String i2cBus;
- private I2cManager i2c;
-
- private static enum AttributeId {
- T_PEERDEVICEID (0x4021),
- T_PEERCPORTID (0x4022),
- T_CONNECTIONSTATE (0x4020),
- T_TRAFFICCLASS (0x4023),
- T_PROTOCOLID (0x4024),
- T_CPORTFLAGS (0x4025),
- T_TXTOKENVALUE (0x4026),
- T_RXTOKENVALUE (0x4027),
- T_LOCALBUFFERSPACE(0x4028),
- T_PEERBUFFERSPACE (0x4029),
- T_CREDITSTOSEND (0x402A),
- T_CPORTMODE (0x402B);
-
- private int id;
- private AttributeId(int id) {
- this.id = id;
- }
- }
-
- private static enum FunctionId {
- C0_SETREQ (0x00),
- C0_SETCNF (0x01),
- C0_PEERSETREQ (0x02),
- C0_PEERSETCNF (0x03),
- C0_GETREQ (0x04),
- C0_GETCNF (0x05),
- C0_PEERGETREQ (0x06),
- C0_PEERGETCNF (0x07),
- C0_LUTSETREQ (0x08),
- C0_LUTSETCNF (0x09),
- C0_LUTGETREQ (0x0a),
- C0_LUTGETCNF (0x0b),
- C0_SWITCHATTRSETREQ (0x0c),
- C0_SWITCHATTRSETCNF (0x0d),
- C0_SWITCHATTRGETREQ (0x0e),
- C0_SWITCHATTERGETCNF(0x0f);
-
- private int id;
- private FunctionId(int id) {
- this.id = id;
- }
- }
-
- private class SetRequest {
- int portId;
- FunctionId functionId;
- AttributeId attrId;
- int selectorIndex;
- int attrVal;
-
- public byte[] getBytes() {
- byte[] rawBytes = new byte[10];
- rawBytes[0] = (byte)(portId & 0xFF);
-
- rawBytes[1] = (byte)(functionId.id & 0xFF);
-
- rawBytes[2] = (byte)((attrId.id >> 8) & 0xFF); // msb
- rawBytes[3] = (byte)(attrId.id & 0xFF); // lsb
-
- rawBytes[4] = (byte)((selectorIndex >> 8) & 0xFF);
- rawBytes[5] = (byte)((selectorIndex) & 0xFF);
-
- rawBytes[6] = (byte)((attrVal >> 24) & 0xFF);
- rawBytes[7] = (byte)((attrVal >> 16) & 0xFF);
- rawBytes[8] = (byte)((attrVal >> 8) & 0xFF);
- rawBytes[9] = (byte)((attrVal) & 0xFF);
- return rawBytes;
- }
- }
-
- public L3Switch(I2cManager i2c) {
- this.i2c = i2c;
- this.i2cBus = i2c.getI2cBuses()[0];
- }
-
- // api_write_switch_config
- public void writeSwitchConfig(int port, boolean peer, AttributeId attrId,
- int selectorIndex, int attrVal,
- int expectedResultCode) {
- I2cTransaction txn = null;
- SetRequest setReq = new SetRequest();
-
- setReq.portId = port;
- setReq.functionId = peer ? FunctionId.C0_PEERSETREQ : FunctionId.C0_SETREQ;
- setReq.attrId = attrId;
- setReq.selectorIndex = selectorIndex;
- setReq.attrVal = attrVal;
-
- txn = I2cTransaction.newWrite(setReq.getBytes());
- I2cTransaction[] results;
- try {
- results = i2c.performTransactions(i2cBus, slaveAddress, txn);
- } catch (IOException e) {
- return;
- }
- }
-
- // api_write_switch_config, peer = 0 (false)
- public void writeSwitchConfigLocal(int port, AttributeId attrId,
- int selectorIndex, int attrVal,
- int expectedResultCode) {
- writeSwitchConfig(port, false, attrId, selectorIndex, attrVal,
- expectedResultCode);
- }
-
- // api_write_switch_config, peer = 1 (true)
- public void writeSwitchConfigPeer(int port, AttributeId attrId,
- int selectorIndex, int attrVal,
- int expectedResultCode) {
- writeSwitchConfig(port, true, attrId, selectorIndex, attrVal,
- expectedResultCode);
- }
-
-// // api_read_switch_config
-// int readSwitchConfig(int port, boolean peer, AttributeId attrId,
-// int selectorIndex,
-// int expectedResultCode) {
-// return 0;
-// }
-//
-// // api_read_switch_config, peer = 0 (false)
-// int readSwitchConfigLocal(int port, int attrId,
-// int selectorIndex,
-// int expectedResultCode) {
-// return readSwitchConfig(port, false, attrId, selectorIndex,
-// expectedResultCode);
-// }
-//
-// // api_read_switch_config, peer = 1 (true)
-// int readSwitchConfigPeer(int port, int attrId,
-// int selectorIndex,
-// int expectedResultCode) {
-// return readSwitchConfig(port, true, attrId, selectorIndex,
-// expectedResultCode);
-// }
-
- // api_write_switch_lut_config
- public void writeSwitchLutConfig(int port, int lutAddr, int destPortId,
- int destCPortId, int expectedResultCode) {
-
- }
-
- public void configureL3Device(int portA, int cPortA,
- int cPortB, int deviceIdB) {
-
- }
-
-}
diff --git a/src/com/projectara/araepm/MainActivity.java b/src/com/projectara/araepm/MainActivity.java
index c8594e2..0cf3113 100644
--- a/src/com/projectara/araepm/MainActivity.java
+++ b/src/com/projectara/araepm/MainActivity.java
@@ -3,6 +3,7 @@
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
+import android.view.View;
import android.hardware.I2cManager;
import android.hardware.I2cTransaction;
import android.widget.TextView;
@@ -10,19 +11,17 @@
import android.os.Handler;
import android.util.Log;
-public class MainActivity extends Activity implements Mlx90620Listener{
+public class MainActivity extends Activity {
TextView textView;
- AFE4400Thread thread;
- Handler handler;
private static final String TAG = "araepm";
+ private DME dme = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView)findViewById(R.id.textView);
- handler = new Handler();
}
@Override
@@ -34,30 +33,26 @@
@Override
protected void onStart(){
+ Log.d(TAG, "onstart");
super.onStart();
I2cManager i2c = (I2cManager) getSystemService(I2C_SERVICE);
- thread = new AFE4400Thread(this, i2c);
- thread.start();
- Log.d(TAG, "onstart");
+ dme = new DME(i2c);
}
@Override
protected void onStop() {
- super.onStop();
- thread.requestStop();
Log.d(TAG, "onstop");
+ super.onStop();
}
- // -- AFE4400 API --------------------------------------------------------
-
- @Override
- public void updateAFE4400Status(String text) {
- final String t = text;
- handler.post(new Runnable() {
- @Override
- public void run() {
- textView.setText(t);
- }
- });
+ public void getReq(View view) {
+ int rc;
+ Log.d(TAG, "button pressed");
+ try {
+ rc = dme.readDMEConfig(0, false, DME.AttributeId.DME_LINKSTARTUP, 0, 0);
+ } catch (IOException e) {
+ return;
+ }
+ Log.d(TAG, "DME rc: " + rc);
}
}