diff --git a/pom.xml b/pom.xml
index fbf488dd89..b5ac081ea6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1655,6 +1655,14 @@
io.netty
*
+
+ logback-classic
+ *
+
+
+ logback-core
+ *
+
diff --git a/src/main/java/org/myrobotlab/service/Arduino.java b/src/main/java/org/myrobotlab/service/Arduino.java
index f06216e55f..38135bad41 100644
--- a/src/main/java/org/myrobotlab/service/Arduino.java
+++ b/src/main/java/org/myrobotlab/service/Arduino.java
@@ -288,6 +288,17 @@ public void attach(String listener, int address) {
@Override
public void attach(UltrasonicSensorControl sensor, Integer triggerPin, Integer echoPin) throws Exception {
+
+ if (triggerPin == null) {
+ error("%s please set trigger pin");
+ return;
+ }
+
+ if (echoPin == null) {
+ error("%s please set echo pin");
+ return;
+ }
+
// refer to
// http://myrobotlab.org/content/control-controller-manifesto
if (isAttached(sensor)) {
diff --git a/src/main/java/org/myrobotlab/service/MockGateway.java b/src/main/java/org/myrobotlab/service/MockGateway.java
index 6d85e05d01..0e532f28cc 100644
--- a/src/main/java/org/myrobotlab/service/MockGateway.java
+++ b/src/main/java/org/myrobotlab/service/MockGateway.java
@@ -333,4 +333,14 @@ public Message getMsg(String name, String callback) {
}
return null;
}
+
+ public Integer size(String name, String callback) {
+ String fullName = getFullRemoteName(name);
+
+ String key = String.format("%s.%s", fullName, callback);
+ if (!sendQueues.containsKey(key)) {
+ return null;
+ }
+ return sendQueues.get(key).size();
+ }
}
\ No newline at end of file
diff --git a/src/main/java/org/myrobotlab/service/Runtime.java b/src/main/java/org/myrobotlab/service/Runtime.java
index 7cf25153ef..5a86472a6b 100644
--- a/src/main/java/org/myrobotlab/service/Runtime.java
+++ b/src/main/java/org/myrobotlab/service/Runtime.java
@@ -5165,7 +5165,7 @@ static public void savePlan(String configName) {
private void savePlanInternal(String configName) {
if (configName == null) {
- error("cannot save plan config name is null");
+ info("cannot save plan config name is null");
return;
}
diff --git a/src/main/java/org/myrobotlab/service/UltrasonicSensor.java b/src/main/java/org/myrobotlab/service/UltrasonicSensor.java
index c5df12d252..02eede97e2 100644
--- a/src/main/java/org/myrobotlab/service/UltrasonicSensor.java
+++ b/src/main/java/org/myrobotlab/service/UltrasonicSensor.java
@@ -35,20 +35,13 @@ public class UltrasonicSensor extends Service implements
private static final long serialVersionUID = 1L;
- // probably should do this in a util class
- public static int byteArrayToInt(int[] b) {
- return b[3] & 0xFF | (b[2] & 0xFF) << 8 | (b[1] & 0xFF) << 16 | (b[0] & 0xFF) << 24;
- }
-
- // currently not variable in NewPing.h
- // Integer maxDistanceCm = 500;
-
transient protected UltrasonicSensorController controller;
protected String controllerName;
transient protected BlockingQueue data = new LinkedBlockingQueue();
+ @Deprecated /* use directly from config - should be String */
protected Integer echoPin = null;
protected boolean isAttached = false;
@@ -74,6 +67,7 @@ public static int byteArrayToInt(int[] b) {
protected long timeout = 500;
+ @Deprecated /* use directly from config - should be String */
protected Integer trigPin = null;
protected final Set types = new HashSet(Arrays.asList("SR04", "SR05"));
@@ -222,6 +216,10 @@ public long getPingCount() {
public int getTriggerPin() {
return trigPin;
}
+
+ public boolean isAttached() {
+ return isAttached;
+ }
@Override
public boolean isAttached(String name) {
diff --git a/src/main/java/org/myrobotlab/service/meta/WebGuiMeta.java b/src/main/java/org/myrobotlab/service/meta/WebGuiMeta.java
index 7ab982a206..55ac6f3e00 100644
--- a/src/main/java/org/myrobotlab/service/meta/WebGuiMeta.java
+++ b/src/main/java/org/myrobotlab/service/meta/WebGuiMeta.java
@@ -22,6 +22,8 @@ public WebGuiMeta() {
addDependency("org.jmdns", "jmdns", "3.5.5");
addDependency("org.atmosphere", "nettosphere", "3.2.2");
exclude("io.netty", "*"); // it brings in an old version of netty
+ exclude("logback-classic", "*");
+ exclude("logback-core", "*");
addDependency("javax.annotation", "javax.annotation-api", "1.3.2");
// force correct version of netty
diff --git a/src/test/java/org/myrobotlab/service/UltrasonicSensorTest.java b/src/test/java/org/myrobotlab/service/UltrasonicSensorTest.java
index 5e2875f509..9dfe3b0dce 100644
--- a/src/test/java/org/myrobotlab/service/UltrasonicSensorTest.java
+++ b/src/test/java/org/myrobotlab/service/UltrasonicSensorTest.java
@@ -1,130 +1,75 @@
package org.myrobotlab.service;
-import org.junit.After;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Test;
-import org.junit.runner.JUnitCore;
-import org.junit.runner.Result;
-import org.myrobotlab.logging.LoggerFactory;
-import org.myrobotlab.logging.Logging;
-import org.myrobotlab.service.interfaces.PinArrayControl;
-import org.myrobotlab.service.interfaces.SerialDevice;
+import org.myrobotlab.framework.Message;
+import org.myrobotlab.framework.Service;
+import org.myrobotlab.framework.TimeoutException;
import org.myrobotlab.test.AbstractTest;
-import org.slf4j.Logger;
-
-//TODO: re-enable this test when we figure out why it fails from the
-// command line ant build...
-@Ignore
public class UltrasonicSensorTest extends AbstractTest {
- static PinArrayControl arduino = null;
- static TestCatcher catcher = null;
-
- // VirtualArduino setup
- static int echoPin = 7;
- public final static Logger log = LoggerFactory.getLogger(UltrasonicSensor.class);
- static String port = "COM4";
-
- static UltrasonicSensor sensor = null;
- static SerialDevice serial = null;
- static int trigPin = 8;
- static Serial uart = null;
- static boolean useVirtualHardware = true; // base class for this and
-
- static VirtualArduino virtual = null;
-
- // FIXME - test for re-entrant !!!!
- // FIXME - single switch for virtual versus "real" hardware
-
- static public void main(String[] args) {
-
- try {
- // // LoggingFactory.init();
- // FIXME - base class static method .webGui() & .gui()
- // Runtime.start("webgui", "WebGui");
- // Runtime.start("gui", "SwingGui");
-
- // test a "real" arduino
- useVirtualHardware = true;
-
- UltrasonicSensorTest test = new UltrasonicSensorTest();
- UltrasonicSensorTest.setUpBeforeClass();
-
- // arduino.record();
-
- if (virtual != null) {
- virtual.connect(port);
- }
-
- test.test();
-
- // run junit as java app
- JUnitCore junit = new JUnitCore();
- Result result = junit.run(UltrasonicSensorTest.class);
- log.info("Result was: {}", result);
-
- } catch (Exception e) {
- Logging.logError(e);
- }
- }
+ static MockGateway gateway = null;
+ static UltrasonicSensor ultra = null;
+ static Arduino uno = null;
@BeforeClass
- public static void setUpBeforeClass() throws Exception {
- // // LoggingFactory.init(Level.INFO);
-
- log.info("setUpBeforeClass");
- sensor = (UltrasonicSensor) Runtime.start("arduino", "UltrasonicSensor");
- virtual = (VirtualArduino) Runtime.start("virtual", "VirtualArduino");
- if (useVirtualHardware) {
- virtual.connect(port);
- }
-
- catcher = (TestCatcher) Runtime.start("catcher", "TestCatcher");
- uart = (Serial) virtual.getSerial();
- // uart.setTimeout(100); // don't want to hang when decoding results...
- }
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
+ public static void setupBeforeClass() throws Exception {
+ ultra = (UltrasonicSensor) Runtime.start("ultra", "UltrasonicSensor");
+ gateway = (MockGateway) Runtime.start("gateway", "MockGateway");
+ gateway.clear();
+ uno = (Arduino) Runtime.start("uno", "Arduino");
+ uno.setVirtual(true);
+ uno.connect("COMX");
+ ultra.setTriggerPin(11);
+ ultra.setEchoPin(10);
+ ultra.attach("uno");
+
+ //Runtime.start("webgui", "WebGui");
}
@Before
- public void setUp() throws Exception {
- }
-
- @After
- public void tearDown() throws Exception {
+ public void setup() {
+ gateway.clear();
}
- // TODO - Virtual Serial test - do a record of tx & rx on a real sensor
- // then send the data - IT MUST BE INTERLEAVED
@Test
- public final void test() throws Exception {
-
- TestCatcher catcher = (TestCatcher) Runtime.start("catcher", "TestCatcher");
- Arduino mega = (Arduino) Runtime.start("ultrasonic_arduino", "TestCatcher");
- sensor.addRangeListener(catcher);
- sensor.attach(mega, trigPin, echoPin);
- sensor.startRanging();
- log.info("here");
- sensor.stopRanging();
-
- uart.stopRecording();
-
- sensor.startRanging();
- log.info("here");
-
- sensor.stopRanging();
-
- sensor.startRanging();
+ public void testUltrasonicSensor() throws TimeoutException {
+ assertTrue(ultra.isAttached());
+ Double range = ultra.ping();
+ assertNotNull(range);
+ ultra.addListener("publishRange", "mocker@mockId");
+ ultra.startRanging();
+ gateway.waitForMsg("mocker@mockId", "onRange", 100);
+ ultra.stopRanging();
+ Service.sleep(10);
+ gateway.clear();
+ assertNull(gateway.getMsg("mocker@mockId", "onRange"));
+
+ // 1 hz
+ ultra.setRate(1);
+ ultra.startRanging();
+ Message msg = gateway.waitForMsg("mocker@mockId", "onRange", 1000);
+ Double r = (Double)msg.data[0];
+ assertNotNull(r);
+ ultra.stopRanging();
+ Integer count = gateway.size("mocker@mockId", "onRange");
+ assertTrue(count == 0);
+ }
- sensor.startRanging();
- sensor.stopRanging();
+ @AfterClass
+ public static void tearDownAfterClass() {
+ Runtime.release("ultra");
+ Runtime.release("gateway");
+ Runtime.release("uno");
}
}