<?xml version="1.0" encoding="utf-8"?>
<resources>
- <string name="app_name">ORTE Demo</string>
+ <string name="app_name">Robomon</string>
</resources>
\ No newline at end of file
--- /dev/null
+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.Publication;
+import org.ocera.orte.types.NtpTime;
+import org.ocera.orte.types.PublProp;
+
+public class CraneCmdPublish {
+
+ private boolean isCancelled = true;
+ private CraneCmdType liftmsg;
+ private Publication pub;
+ private PublProp publProp;
+ private DomainApp appDomain;
+
+ private final ReentrantReadWriteLock controlRrwl = new ReentrantReadWriteLock(true);
+ private final ReadLock rcLock = controlRrwl.readLock();
+ private final WriteLock wcLock = controlRrwl.writeLock();
+
+ public CraneCmdPublish(DomainApp appDomain) {
+ this.appDomain = appDomain;
+
+ NtpTime persistence = new NtpTime(3);
+ int strength = 100;
+
+ liftmsg = new CraneCmdType(appDomain,"crane_cmd");
+
+ publProp = new PublProp(liftmsg.getTopic(),
+ "crane_cmd",
+ persistence,
+ strength);
+ }
+
+ public void start() {
+ wcLock.lock();
+ try {
+ isCancelled = false;
+ pub = appDomain.createPublication(publProp, liftmsg);
+ }
+ finally {
+ wcLock.unlock();
+ }
+ }
+
+ public void cancel() {
+ wcLock.lock();
+ try {
+ isCancelled = true;
+ pub.destroy();
+ } finally {
+ wcLock.unlock();
+ }
+ }
+
+ public boolean isCancelled() {
+ rcLock.lock();
+ try {
+ return isCancelled;
+ } finally {
+ rcLock.unlock();
+ }
+ }
+
+ public void send(short magnet) {
+ liftmsg.position = magnet;
+ pub.send(liftmsg);
+ }
+}
--- /dev/null
+package org.ocera.orte.demo;
+
+import org.ocera.orte.DomainApp;
+import org.ocera.orte.types.MessageData;
+import org.ocera.orte.types.ORTEConstant;
+
+public class CraneCmdType extends MessageData {
+
+ public int position = 0;
+
+ public CraneCmdType(DomainApp domainApp, String newTopic) {
+ super();
+ this.setTopic(newTopic);
+ if (!domainApp.regNewDataType("crane_cmd",getMaxDataLength())) {
+ System.out.println(":j!: cannot register data type \"lift_cmd\"!");
+ }
+ }
+
+ @Override
+ public void read() {
+ }
+
+ @Override
+ public void write() {
+ buffer.rewind();
+ buffer.putShort((short) position);
+ buffer.putShort((short) 0);
+ }
+
+ @Override
+ public int getMaxDataLength() {
+ return 2*ORTEConstant.SHORT_FIELD_SIZE;
+ }
+
+}
--- /dev/null
+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.Publication;
+import org.ocera.orte.types.NtpTime;
+import org.ocera.orte.types.PublProp;
+
+public class MagnetCmdPublish {
+
+ private boolean isCancelled = true;
+ private MagnetCmdType magnetmsg;
+ private Publication pub;
+ private PublProp publProp;
+ private DomainApp appDomain;
+
+ private final ReentrantReadWriteLock controlRrwl = new ReentrantReadWriteLock(true);
+ private final ReadLock rcLock = controlRrwl.readLock();
+ private final WriteLock wcLock = controlRrwl.writeLock();
+
+ public MagnetCmdPublish(DomainApp appDomain) {
+ this.appDomain = appDomain;
+
+ NtpTime persistence = new NtpTime(3);
+ int strength = 100;
+
+ magnetmsg = new MagnetCmdType(appDomain,"magnet_cmd");
+
+ publProp = new PublProp(magnetmsg.getTopic(),
+ "magnet_cmd",
+ persistence,
+ strength);
+ }
+
+ public void start() {
+ wcLock.lock();
+ try {
+ isCancelled = false;
+ pub = appDomain.createPublication(publProp, magnetmsg);
+ }
+ finally {
+ wcLock.unlock();
+ }
+ }
+
+ public void cancel() {
+ wcLock.lock();
+ try {
+ isCancelled = true;
+ pub.destroy();
+ } finally {
+ wcLock.unlock();
+ }
+ }
+
+ public boolean isCancelled() {
+ rcLock.lock();
+ try {
+ return isCancelled;
+ } finally {
+ rcLock.unlock();
+ }
+ }
+
+ public void send(short magnet) {
+ magnetmsg.magnet = magnet;
+ pub.send(magnetmsg);
+ }
+}
--- /dev/null
+package org.ocera.orte.demo;
+
+import org.ocera.orte.DomainApp;
+import org.ocera.orte.types.MessageData;
+import org.ocera.orte.types.ORTEConstant;
+
+public class MagnetCmdType extends MessageData {
+
+ public int magnet = 0;
+
+ public MagnetCmdType(DomainApp domainApp, String newTopic) {
+ super();
+ this.setTopic(newTopic);
+ if (!domainApp.regNewDataType("magnet_cmd",getMaxDataLength())) {
+ System.out.println(":j!: cannot register data type \"magnet_cmd\"!");
+ }
+ }
+
+ @Override
+ public void read() {
+ }
+
+ @Override
+ public void write() {
+ buffer.rewind();
+ buffer.putShort((short) magnet);
+ }
+
+ @Override
+ public int getMaxDataLength() {
+ return ORTEConstant.SHORT_FIELD_SIZE;
+ }
+
+}
private MotionSpeedSubscribe motion_speed_subs = null;
private HokuyoScanSubscribe hokuyo_scan = null;
private PwrVoltageSubscribe pwr_voltage = null;
+ private MagnetCmdPublish magnet_cmd = null;
+ private CraneCmdPublish crane_cmd = null;
private SensorManager mSensorManager = null;
private Sensor mGravity = null;
private SensorEventListener accel = null;
protected void onDestroy() {
super.onDestroy();
+ if (crane_cmd != null && !crane_cmd.isCancelled()) {
+ crane_cmd.cancel();
+ }
+
+ if (magnet_cmd != null && !crane_cmd.isCancelled()) {
+ magnet_cmd.cancel();
+ }
+
if (appDomain != null) {
appDomain.destroy();
appDomain = null;
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);
manager = new Manager(mgrs);
appDomain = new DomainApp();
+ magnet_cmd = new MagnetCmdPublish(appDomain);
+ magnet_cmd.start();
+ crane_cmd = new CraneCmdPublish(appDomain);
+ crane_cmd.start();
}
@Override
item.setTitle("Start LRF");
}
else if (item.getTitle().equals("Lift up")) {
-
+ crane_cmd.send((short)0x100);
+ item.setTitle("Lift down");
}
else if (item.getTitle().equals("Lift down")) {
-
+ crane_cmd.send((short)0x190);
+ item.setTitle("Lift up");
}
else if (item.getTitle().equals("Magnet on")) {
-
+ magnet_cmd.send((short)1);
+ item.setTitle("Magnet off");
}
else if (item.getTitle().equals("Magnet off")) {
-
+ magnet_cmd.send((short)0);
+ item.setTitle("Magnet on");
}
else if (item.getTitle().equals("Voltage monitor")) {
if (pwr_voltage == null)