Examples of RemoteNode


Examples of org.ugate.service.entity.jpa.RemoteNode

   *
   * @param rxResponse
   *            the {@linkplain RxResponse16}
   */
  protected void handleRxResponse16(final RxResponse16 rxResponse) {
    final RemoteNode rn = findRemoteNode(rxResponse);
    if (rn == null) {
      return;
    }
    final Command command = extractCommand(rxResponse);
    if (command == null) {
      log.error(String.format("An unrecognized %1$s command was received from %2$s",
          rxResponse.getData()[0], rn.getAddress()));
      return;
    }
    final int failures = rxResponse.getData()[1]; // TODO : Handle cases where failures exist
    final RxData.Status status = failures == 0 ? RxData.Status.NORMAL : RxData.Status.GENERAL_FAILURE;
    log.info(String.format("======= Recieved %1$s command from wireless address %2$s (signal strength: %3$s) with (%4$s) failures =======",
        command, rn.getAddress(), rxResponse.getRssi(), failures));
    if (command == Command.CAM_TAKE_PIC) {
      ImageCapture ic;
      RxTxImage rxTxImage = imgMap.containsKey(rn.getAddress()) ? imgMap.get(rn.getAddress()) : null;
      if (rxTxImage == null || rxTxImage.hasTimedOut()) {
        if (rxTxImage != null) {
          rxTxImage.resetRxTxAttempts();
          ic = rxTxImage.createImageSegmentsSnapshot();
          processData(rn, UGateEvent.Type.WIRELESS_DATA_RX_FAILED, command, ic,
              RS.rbLabel(KEY.SERVICE_RX_IMAGE_TIMEOUT, ic));
        }
        // TODO : add check for what sensor tripped the image and image format detection (instead of using just JPEG)
        rxTxImage = new RxTxJPEG(rn, status, rxResponse.getRssi(), null);
        imgMap.put(rn.getAddress(), rxTxImage);
        ic = rxTxImage.createImageSegmentsSnapshot();
        log.info(String.format("======= Receiving chunked image data (%1$s) =======", rxTxImage));
        processData(rn, UGateEvent.Type.WIRELESS_DATA_RX_MULTIPART, command, ic,
            RS.rbLabel(KEY.SERVICE_RX_IMAGE_MULTPART, ic));
      }
      int[] imageChunk = rxTxImage.addImageSegment(rxResponse.getData(), IMAGE_START_INDEX);
      if (log.isDebugEnabled()) {
        log.debug(String.format("Sensor Tripped (%1$s, LENGTH: %2$s, RAW LENGTH: %3$s) DATA: %4$s",
            rxTxImage, imageChunk.length, rxResponse.getLength().getLength(), ByteUtils.toBase16(imageChunk)));
      }
      if (rxTxImage.isEof()) {
        if (rxTxImage.getStatus() != RxData.Status.NORMAL) {
          final int retries = rn.getCamImgCaptureRetryCnt();
          ic = rxTxImage.createImageSegmentsSnapshot();
          if (retries != 0 && rxTxImage.getRxTxAttempts() <= retries) {
            rxTxImage.incRxTxAttempts();
            processData(rn, UGateEvent.Type.WIRELESS_DATA_RX_FAILED_RETRYING, command, ic,
                RS.rbLabel(KEY.SERVICE_RX_IMAGE_LOST_PACKETS_RETRY, ic, rxTxImage.getRxTxAttempts(), retries));
            ServiceProvider.IMPL.getWirelessService().sendData(rn, command, 0, false);
          } else {
            try {
              processData(rn, UGateEvent.Type.WIRELESS_DATA_RX_FAILED, command, ic,
                  RS.rbLabel(KEY.SERVICE_RX_IMAGE_LOST_PACKETS, ic, rxTxImage.getRxTxAttempts()));
            } finally {
              imgMap.remove(rn.getAddress());
            }
          }
        } else {
          try {
            ic = rxTxImage.writeImageSegments();
            processData(rn, UGateEvent.Type.WIRELESS_DATA_RX_SUCCESS, command, ic,
                RS.rbLabel(KEY.SERVICE_RX_IMAGE_SUCCESS, ic));
          } catch (IOException e) {
            log.info("Cannot save image ID: " + UGateUtil.calFormat(rxTxImage.getCreatedTime()), e);
          } finally {
            imgMap.remove(rn.getAddress());
          }
        }
      }
    } else if (command == Command.ACCESS_PIN_CHANGE) {
      //final int hasFailures = rxResponse.getData()[1];
      final KeyCodes kc = new KeyCodes(rn, status, rxResponse.getRssi(), rxResponse.getData()[1],
          rxResponse.getData()[2], rxResponse.getData()[3]);
      processData(rn, UGateEvent.Type.WIRELESS_DATA_RX_SUCCESS, command, kc,
          RS.rbLabel(KEY.SERVICE_RX_KEYCODES, kc));
    } else if (command == Command.SERVO_LASER_CALIBRATE) {
      processData(rn, UGateEvent.Type.WIRELESS_DATA_RX_SUCCESS, command, 
          new RxRawData<Void>(rn, status, rxResponse.getRssi(), null),
          failures > 0 ? RS.rbLabel(KEY.LASER_CALIBRATION_FAILED) : RS.rbLabel(KEY.LASER_CALIBRATION_SUCCESS));
    } else if (command == Command.SENSOR_GET_READINGS || command == Command.GATE_TOGGLE_OPEN_CLOSE) {
      int i = 1;
      final RemoteNodeReading rnr = new RemoteNodeReading();
      rnr.setRemoteNode(rn);
      rnr.setReadDate(new Date());
      rnr.setSignalStrength(rxResponse.getRssi());
      rnr.setSonarFeet(rxResponse.getData()[++i]);
      rnr.setSonarInches(rxResponse.getData()[++i]);
      rnr.setMicrowaveCycleCount(rxResponse.getData()[++i]);
      rnr.setPirIntensity(rxResponse.getData()[++i]);
      rnr.setLaserFeet(rxResponse.getData()[++i]);
      rnr.setLaserInches(rxResponse.getData()[++i]);
      rnr.setGateState(rxResponse.getData()[++i]);
      final RxTxRemoteNodeReadingDTO sr = new RxTxRemoteNodeReadingDTO(rnr, status);
      processData(rn, UGateEvent.Type.WIRELESS_DATA_RX_SUCCESS, command, sr,
          RS.rbLabel(KEY.SERVICE_RX_READINGS, sr));
    } else if (command == Command.SENSOR_GET_SETTINGS) {
      // the number of response data and their order is important!!!
      int i = 1;
      final int[] sd = new int[RemoteNodeType.canRemoteCount()];
      for (int j = 0; j<RemoteNodeType.canRemoteCount(); j++) {
        sd[j] = rxResponse.getData()[++i];
      }
      // create a detached state remote node w/o modifying the existing local instance
      final RemoteNode rnFromRemote = RemoteNodeType.newDefaultRemoteNode(rn.getHost());
      final RxTxRemoteNodeDTO dto = new RxTxRemoteNodeDTO(rnFromRemote, status,
          rxResponse.getRssi(), sd);
      processData(rn, UGateEvent.Type.WIRELESS_DATA_RX_SUCCESS, command, dto,
          RS.rbLabel(KEY.SERVICE_RX_SETTINGS, dto));
    } else {
View Full Code Here

Examples of org.ugate.service.entity.jpa.RemoteNode

      @Override
      public void handle(final UGateEvent<?, ?> event) {
        final boolean isRemoteCommand = event.isFromRemote() && event.getCommand() != null;
        if (event.getType() == UGateEvent.Type.WIRELESS_REMOTE_NODE_COMMITTED) {
          // notify the user that the remote node has successfully been committed locally
          final RemoteNode rn = (RemoteNode) event.getSource();
          final NodeStatusView nsv = getNodeStatusView(rn.getAddress());
          if (isRemoteCommand && nsv != null) {
            // blink status to indicate the a remote command has been received
            nsv.updateLastCommand(event.getCommand(), false);
          }
          if (event.getNewValue() == null) {
            // remove from display
            NodeStatusView.remove(rn.getAddress());
            selectFromChange(null, true);
            log.info("Removed remote node at address: " + rn.getAddress());
          }
        } else if (event.getType() == UGateEvent.Type.WIRELESS_DATA_RX_SUCCESS) {
          final RemoteNode rn = (RemoteNode) event.getSource();
          if (event.getNewValue() instanceof RxTxRemoteNodeDTO) {
            final RxTxRemoteNodeDTO ndto = (RxTxRemoteNodeDTO) event.getNewValue();
            if (!RemoteNodeType.remoteEquivalent(rn, ndto.getRemoteNode())) {
              // remote device values do not match the local device values
              rn.setDeviceSynchronized(false);
              ndto.getRemoteNode().setDeviceSynchronized(false);
              final NodeStatusView nsv = getNodeStatusView(rn.getAddress());
              if (nsv != null) {
                // blink status to indicate the a remote device is out of sync
                nsv.updateLastCommand(event.getCommand(), true);
                controlBar.setHelpText(RS.rbLabel(
                    KEY.WIRELESS_NODE_REMOTE_SAVED_LOCAL,
View Full Code Here

Examples of org.ugate.service.entity.jpa.RemoteNode

    if (address == null || address.isEmpty()) {
      return;
    }
    log.info("Attempting to add remote node at address: " + address);
    // node may have been added, but the save failed
    RemoteNode rnm = null;
    for (final RemoteNode rn : controlBar.getActor().getHost().getRemoteNodes()) {
      if (rn.getAddress().equalsIgnoreCase(address)) {
        rnm = rn;
        break;
      }
    }
    if (rnm == null) {
      final RemoteNode rn = RemoteNodeType.newDefaultRemoteNode(controlBar
          .getActor().getHost(), controlBar.getRemoteNode());
      rn.setAddress(address);
      controlBar.getActor().getHost().getRemoteNodes().add(rn);
      ServiceProvider.IMPL.getCredentialService().mergeHost(
          controlBar.getActor().getHost());
    }
  }
View Full Code Here

Examples of org.ugate.service.entity.jpa.RemoteNode

            // if the dialog shouldn't be closed call super.cancel()
            try {
              log.info("Attempting to remove remote node at address: "
                  + address);
              if (controlBar.getActor().getHost().getRemoteNodes().size() > 1) {
                RemoteNode rnr = null;
                for (final RemoteNode rn : controlBar.getActor().getHost().getRemoteNodes()) {
                  if (address.equalsIgnoreCase(rn.getAddress())) {
                    rnr = rn;
                    break;
                  }
View Full Code Here

Examples of org.ugate.service.entity.jpa.RemoteNode

      public void handle(final UGateEvent<?, ?> event) {
        if (members.size() <= 0) {
          return;
        }
        if (event.getType() == UGateEvent.Type.WIRELESS_REMOTE_NODE_COMMITTED) {
          final RemoteNode rn = (RemoteNode) event.getSource();
          final String jsonData = jsonRemoteNode.toJSON(rn);
          if (log.isInfoEnabled()) {
            log.info(String
                .format("Sending %1$s (address: %2$s) notification to %3$s web member(s): %4$s",
                    RemoteNode.class.getSimpleName(),
                    rn.getAddress(), members.size(),
                    jsonData));
          }
          notifyMembers(jsonData);
        } else if (event.getType() == UGateEvent.Type.WIRELESS_DATA_RX_SUCCESS
            && event.getNewValue() instanceof RxTxRemoteNodeReadingDTO) {
View Full Code Here

Examples of org.ugate.service.entity.jpa.RemoteNode

      IOException {
    int id;
    final String idStr = request.getParameter(RemoteNodeType.ID.getKey());
    if (idStr != null && !idStr.isEmpty()
        && (id = Integer.valueOf(idStr)) >= 0) {
      final RemoteNode rn = ServiceProvider.IMPL.getRemoteNodeService()
          .findById(id);
      if (rn == null) {
        log.warn(String.format("Unable to find %1$s with %2$s = %3$s",
            RemoteNode.class.getSimpleName(),
            RemoteNodeType.WIRELESS_ADDRESS, idStr));
View Full Code Here

Examples of org.ugate.service.entity.jpa.RemoteNode

  protected void doPost(final HttpServletRequest request,
      final HttpServletResponse response) throws ServletException,
      IOException {
    try {
      if (validate(request, response)) {
        final RemoteNode rn = getRemoteNode(request, response);
        executeCommands(request, response, rn);
        final String p = request.getParameter(VAR_ACTION_NAME);
        if (p != null && p.equals(VAR_ACTION_CONNECT_NAME)) {
          final boolean connected = ServiceProvider.IMPL
              .getWirelessService().testRemoteConnection(rn, 0);
          if (!connected) {
            response.sendError(
                HttpServletResponse.SC_CONFLICT,
                RS.rbLabel(KEY.WIRELESS_NODE_CONNECT_FAILED,
                    rn.getAddress()));
            return;
          }
        }
        response.setStatus(HttpServletResponse.SC_OK);
      }
View Full Code Here

Examples of org.ugate.service.entity.jpa.RemoteNode

  @Override
  protected void doPut(final HttpServletRequest request,
      final HttpServletResponse response) throws ServletException,
      IOException {
    try {
      RemoteNode rn;
      if (validate(request, response)
          && (rn = getRemoteNode(request, response)) != null) {
        boolean hasParams = false;
        String p;
        Object v;
        for (final RemoteNodeType rnt : RemoteNodeType.values()) {
          p = request.getParameter(rnt.getKey());
          if (p == null || p.isEmpty()) {
            continue;
          }
          v = rnt.getValue(rn);
          if (v != null && v.toString().equals(p)) {
            continue;
          }
          if (log.isInfoEnabled()) {
            log.info(String
                .format("Setting request parameter %1$s to %2$s for %3$s at address %4$s)",
                    rnt.getKey(), p,
                    RemoteNode.class.getSimpleName(),
                    rn.getAddress()));
          }
          rnt.setValue(rn, p);
          hasParams = true;
        }
        if (hasParams) {
View Full Code Here

Examples of org.ugate.service.entity.jpa.RemoteNode

    // show a visual indication that the settings need updated
    UGateKeeper.DEFAULT.addListener(new UGateListener() {
      @Override
      public void handle(final UGateEvent<?, ?> event) {
        if (event.getType() == UGateEvent.Type.WIRELESS_DATA_RX_SUCCESS) {
          final RemoteNode rn = (RemoteNode) event.getSource();
          if (event.getNewValue() instanceof RxTxRemoteNodeReadingDTO &&
              rn.getAddress().equalsIgnoreCase(cb.getRemoteNode().getAddress())) {
            final RxTxRemoteNodeReadingDTO sr = (RxTxRemoteNodeReadingDTO) event.getNewValue();
            remoteNodeReadingShow(sr.getRemoteNodeReading());
          }
        } else if (event.getType() == UGateEvent.Type.APP_DATA_LOADED ||
            event.getType() == UGateEvent.Type.WIRELESS_REMOTE_NODE_CHANGED) {
View Full Code Here

Examples of org.ugate.service.entity.jpa.RemoteNode

    final Actor actor = findActor(req);
    if (actor == null) {
      req.authenticate(res);
    }
    final Integer rnId = getParameter(req, RemoteNodeType.ID.getKey(), Integer.class);
    RemoteNode rn = null;
    if (rnId != null) {
      rn = getRemoteNode(actor, rnId);
      if (rn != null) {
        ctx.setVariable(VAR_REMOTE_NODE_NAME, rn);
        addRemoteNodeReadingVars(rn, ctx);
        addRemoteNodeVars(rn, ctx);
      }
    }
    if (rn == null) {
      rn = new RemoteNode();
      rn.setAddress("");
      ctx.setVariable(VAR_REMOTE_NODE_NAME, rn);
    }
    ctx.setVariable(VAR_REMOTE_NODES_NAME, actor.getHost().getRemoteNodes());
    return null;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.