public int getMaxDataLength() {
return 681 * ORTEConstant.SHORT_FIELD_SIZE;
}
-
- public String toString() {
- String data = new String();
- for(int i = 0; i < hokuyo.length; i++) {
- data += i + ": " + hokuyo[i] + ", ";
- }
- data = data.substring(0, data.length()-2);
- return data;
- }
}
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
+import android.widget.EditText;
public class MainActivity extends Activity {
private Dialog voltageDialog = null;
+ static EditText voltage33 = null;
+ static EditText voltage50 = null;
+ static EditText voltage80 = null;
+ static EditText voltageBAT = null;
+ static Handler dialogHandler = new Handler() {
+ @Override
+ public void handleMessage(Message msg) {
+ double[] values = msg.getData().getDoubleArray("voltages");
+ if (values != null) {
+ if (voltage33 != null) {
+ voltage33.setText(Double.toString(values[0]));
+ }
+ if (voltage50 != null) {
+ voltage50.setText(Double.toString(values[1]));
+ }
+ if (voltage80 != null) {
+ voltage80.setText(Double.toString(values[2]));
+ }
+ if (voltageBAT != null) {
+ voltageBAT.setText(Double.toString(values[3]));
+ }
+ }
+ }
+ };
private Manager manager = null;
private String[] mgrs = {"192.168.1.5","192.168.1.8","192.168.1.29","10.1.1.1"};
private MotionSpeedPublish motion_speed_publ = null;
private MotionSpeedSubscribe motion_speed_subs = null;
private HokuyoScanSubscribe hokuyo_scan = null;
+ private PwrVoltageSubscribe pwr_voltage = null;
private SensorManager mSensorManager = null;
private Sensor mGravity = null;
private SensorEventListener accel = null;
hokuyo_view.invalidate();
hokuyo_item.setTitle("Start LRF");
}
+
+ if (pwr_voltage != null && !pwr_voltage.isCancelled()) {
+ if (voltageDialog.isShowing())
+ voltageDialog.dismiss();
+ pwr_voltage.cancel();
+ }
mWakeLock.release();
}
voltageDialog = new Dialog(this,R.style.voltage_dialog);
voltageDialog.setCancelable(false);
+ voltageDialog.setContentView(R.layout.status_dialog);
+ Button okButton = (Button)voltageDialog.findViewById(R.id.button1);
+ okButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View arg0) {
+ voltageDialog.dismiss();
+ pwr_voltage.cancel();
+ }
+ });
+ voltage33 = (EditText)voltageDialog.findViewById(R.id.editText1);
+ voltage50 = (EditText)voltageDialog.findViewById(R.id.editText2);
+ voltage80 = (EditText)voltageDialog.findViewById(R.id.editText3);
+ voltageBAT = (EditText)voltageDialog.findViewById(R.id.editText4);
+
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
mGravity = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
}
else if (item.getTitle().equals("Voltage monitor")) {
- voltageDialog.setContentView(R.layout.status_dialog);
- Button okButton = (Button)voltageDialog.findViewById(R.id.button1);
- okButton.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View arg0) {
- voltageDialog.dismiss();
- }
- });
+ if (pwr_voltage == null)
+ pwr_voltage = new PwrVoltageSubscribe(appDomain, dialogHandler);
+ pwr_voltage.start();
voltageDialog.show();
}
else if (item.getTitle().equals("Exit")) {
package org.ocera.orte.demo;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
+
+import org.ocera.orte.DomainApp;
+import org.ocera.orte.Subscription;
import org.ocera.orte.SubscriptionCallback;
+import org.ocera.orte.types.MessageData;
+import org.ocera.orte.types.NtpTime;
+import org.ocera.orte.types.RecvInfo;
+import org.ocera.orte.types.SubsProp;
+
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+
+public class PwrVoltageSubscribe extends SubscriptionCallback{
-public class PwrVoltageSubscribe extends SubscriptionCallback {
+ public final static int IMMEDIATE = 0x02;
+ public final static int BEST_EFFORTS = 0x01;
-}
+ static Handler handler;
+
+ private Subscription sub;
+ private PwrVoltageType voltagemsg;
+ private DomainApp domainApp;
+ private SubsProp subProps;
+
+ private boolean isCancelled = true;
+ private final ReentrantReadWriteLock controlRrwl = new ReentrantReadWriteLock(true);
+ private final ReadLock rcLock = controlRrwl.readLock();
+ private final WriteLock wcLock = controlRrwl.writeLock();
+
+ public PwrVoltageSubscribe(DomainApp domainApp, Handler dialogHandler) {
+ handler = dialogHandler;
+ this.domainApp = domainApp;
+
+ NtpTime deadline = new NtpTime(0,1288490189);
+ NtpTime minSeparation = new NtpTime(1);
+
+ voltagemsg = new PwrVoltageType(domainApp, "pwr_voltage");
+
+ subProps = new SubsProp(voltagemsg.getTopic(),
+ "pwr_voltage",
+ minSeparation,
+ deadline,
+ IMMEDIATE,
+ BEST_EFFORTS,
+ 0);
+ }
+
+ public void start() {
+ wcLock.lock();
+ try {
+ isCancelled = false;
+ sub = domainApp.createSubscription(subProps, voltagemsg, this);
+ } finally {
+ wcLock.unlock();
+ }
+ }
+
+ public void cancel() {
+ wcLock.lock();
+ try {
+ isCancelled = true;
+ sub.destroy();
+ } finally {
+ wcLock.unlock();
+ }
+ }
+
+ public boolean isCancelled() {
+ rcLock.lock();
+ try {
+ return isCancelled;
+ } finally {
+ rcLock.unlock();
+ }
+ }
+
+ public void callback(RecvInfo info, MessageData msg) {
+ Message message = handler.obtainMessage();
+ Bundle bundle = new Bundle();
+
+ bundle.putDoubleArray("voltages", ((PwrVoltageType)msg).voltage.clone());
+ message.setData(bundle);
+ handler.sendMessage(message);
+ }
+}
\ No newline at end of file
package org.ocera.orte.demo;
-import org.ocera.orte.types.MessageData;
+import org.ocera.orte.*;
+import org.ocera.orte.types.*;
-public class PwrVoltageType extends MessageData {
- @Override
- public void read() {
- // TODO Auto-generated method stub
-
- }
+public class PwrVoltageType extends MessageData
+{
+ public double[] voltage = new double[4];
+
+ public PwrVoltageType(DomainApp domainApp, String newTopic) {
+ super();
+ this.setTopic(newTopic);
+ if (!domainApp.regNewDataType("pwr_voltage",getMaxDataLength())) {
+ System.out.println(":j!: cannot register data type \"pwr_voltage\"!");
+ }
+ }
+
+ @Override
+ public void write() {}
+
+ @Override
+ public void read() {
+ buffer.rewind();
+ for (int i = 0; i < 4; i++) {
+ voltage[i] = buffer.getDouble();
+ }
+ }
- @Override
- public void write() {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public int getMaxDataLength() {
- // TODO Auto-generated method stub
- return 0;
- }
-
-}
+ @Override
+ public int getMaxDataLength() {
+ return 4 * ORTEConstant.DOUBLE_FIELD_SIZE;
+ }
+}
{
return 2 * ORTEConstant.SHORT_FIELD_SIZE;
}
-
- public String toString()
- {
- String data = "";
-
- data += (" left = " + speed[0]);
- data += (" right = " + speed[1]);
- return data;
- }
-
}