/** Returns the active sensors. */ @SimpleProperty( category = PropertyCategory.BEHAVIOR, description = "The active sensor collections, as a list of two-element sublists. The first element " + "of each sublist represents the sensor name. The second element of each " + "sublist represents the schedule period of that sensor") public YailList CurrentActiveSensors() { YailList list = new YailList(); List<Object> arrlist = new ArrayList<Object>(); for (Entry<String, Integer> entry : mPipeline.getActiveSensor().entrySet()) { // list.clear(); // list.add(YailList.makeList(new String[] { "First Name", "Barack" })); // list.add(YailList.makeList(new String[] { "Last Name", "Obama" })); // list.add(YailList.makeList(new String[] { "Title", "President of the United States" // })); // list.add(YailList.makeList(new String[] { "This list has too few items" })); // try { // web.buildPostData(YailList.makeList(list)); arrlist.add(YailList.makeList(new Object[] {entry.getKey(), entry.getValue()})); // YailList entryList = new YailList(); // entryList.add(entry.getKey()); // entryList.add(entry.getValue()); // list.add(entryList); } return YailList.makeList(arrlist); }
public void testSendAndReceiveBytes() { List<Object> list = new ArrayList<Object>(); list.add((byte) 0); list.add((short) 1); list.add(-1); list.add((long) 127); list.add((byte) -128); list.add((short) 255); list.add("0x0"); list.add("0x1"); list.add("0xFF"); list.add("0xab"); connection.SendBytes(YailList.makeList(list)); assertEquals(0, recordedErrorNumber); assertEquals(10, connection.BytesAvailableToReceive()); List<Integer> signedBytes = connection.ReceiveSignedBytes(5); assertEquals(0, signedBytes.get(0).intValue()); assertEquals(1, signedBytes.get(1).intValue()); assertEquals(-1, signedBytes.get(2).intValue()); assertEquals(127, signedBytes.get(3).intValue()); assertEquals(-128, signedBytes.get(4).intValue()); List<Integer> unsignedBytes = connection.ReceiveUnsignedBytes(5); assertEquals(255, unsignedBytes.get(0).intValue()); assertEquals(0x0, unsignedBytes.get(1).intValue()); assertEquals(0x1, unsignedBytes.get(2).intValue()); assertEquals(0xFF, unsignedBytes.get(3).intValue()); assertEquals(0xab, unsignedBytes.get(4).intValue()); assertEquals(0, recordedErrorNumber); list = new ArrayList<Object>(); list.add("abc"); connection.SendBytes(YailList.makeList(list)); assertEquals(ErrorMessages.ERROR_BLUETOOTH_COULD_NOT_DECODE_ELEMENT, recordedErrorNumber); recordedErrorNumber = 0; list = new ArrayList<Object>(); list.add("256"); connection.SendBytes(YailList.makeList(list)); assertEquals(ErrorMessages.ERROR_BLUETOOTH_COULD_NOT_FIT_ELEMENT_IN_BYTE, recordedErrorNumber); byte[] bytes = outputStream.toByteArray(); assertEquals(10, bytes.length); int i = 0; assertEquals((byte) 0x00, bytes[i++]); // 0 assertEquals((byte) 0x01, bytes[i++]); // 1 assertEquals((byte) 0xFF, bytes[i++]); // -1 assertEquals((byte) 0x7F, bytes[i++]); // 127 assertEquals((byte) 0x80, bytes[i++]); // -128 assertEquals((byte) 0xFF, bytes[i++]); // 255 assertEquals((byte) 0x00, bytes[i++]); // 0x00 assertEquals((byte) 0x01, bytes[i++]); // 0x01 assertEquals((byte) 0xFF, bytes[i++]); // 0xFF assertEquals((byte) 0xAB, bytes[i++]); // 0xab }
/* * Return available sensors */ @SimpleFunction( description = "Return available names of the avaiable sesnors for data collection") public YailList getAvailableSensors() { Log.i(TAG, sensorMapping.keySet().toString()); YailList sensorList = YailList.makeList(sensorMapping.keySet()); return sensorList; }
/** * ElementsFromString property setter method * * @param itemstring - a string containing a comma-separated list of the strings to be picked from */ @DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_STRING, defaultValue = "") // TODO(sharon): it might be nice to have a list editorType where the developer // could directly enter a list of strings (e.g. one per row) and we could // avoid the comma-separated business. @SimpleProperty(category = PropertyCategory.BEHAVIOR) public void ElementsFromString(String itemstring) { if (itemstring.length() == 0) { items = new YailList(); } else { items = YailList.makeList((Object[]) itemstring.split(" *, *")); } }