protected boolean sendRefCommand(boolean takeoff, boolean emergency) {

		int ref = REF_BASE;
		if (takeoff) {
			ref = ref | MASK_TAKEOFF;
		}
		if (emergency) {
			ref = ref | MASK_EMERGENCY;
		}

		try {
			final String payload = String.format(REF, DUMMY_SN, ref);
			if (emergency) {
				commandQueue.offer(payload);
				return true;
			}

			final WaitForState task = new WaitForState();
			task.setMaxWaitMs(10000);
			if (takeoff) {
				task.setStateMask(Navdata.MASK_FLY);
				task.setTransitionState(E_MajorControlState.CTRL_TRANS_TAKEOFF);
				task.setEndState(E_MajorControlState.CTRL_HOVERING);
			} else {
				task.setInversionMask(Navdata.MASK_FLY);
				task.setTransitionState(E_MajorControlState.CTRL_TRANS_LANDING);
				task.setEndState(E_MajorControlState.CTRL_LANDED);
			}
			final Future<Boolean> f = exec.submit(task);
			long start = System.currentTimeMillis();
			int nSent = 0;
			while (!f.isDone()) {
				if (nSent < 3) {
					commandQueue.offer(payload);
					nSent++;
				}
				try {
					Thread.sleep(100);
				} catch (InterruptedException e) {
					// ignore
				}
			}
			if (Util.DEBUG_ENABLED) {
				long end = System.currentTimeMillis();
				long dt = end - start;
				Util.printDebug("Takeoff/landing completed with result "
						+ f.get() + " after " + dt + "ms");
			}
			return Boolean.TRUE.equals(f.get());
		} catch (Exception e) {
			Util.printError("Exception occurred while sending REF (" + takeoff
					+ ") command : ", e, false);
			return false;
		}
	}