Package org.ugate.service.entity.jpa

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


        @Override
        public void handle(final EmailEvent event) {
          String msg;
          if (event.type == EmailEvent.Type.EXECUTE_COMMAND) {
            if (ServiceProvider.IMPL.getWirelessService().isConnected()) {
              RemoteNode rn;
              final List<String> commandMsgs = new ArrayList<String>();
              // send command to all the nodes defined in the email
              for (final String toAddress : event.toAddresses) {
                commandMsgs.clear();
                rn = ServiceProvider.IMPL.getRemoteNodeService().findByAddress(toAddress);
View Full Code Here


          // need to update the existing dirty host
          getActor().setHost((Host) event.getSource());
          getActorPA().setBean(getActor());
        } else if (event.getType() == UGateEvent.Type.WIRELESS_REMOTE_NODE_COMMITTED) {
          // need to update the existing dirty remote node
          final RemoteNode rn = (RemoteNode) event.getSource();
          final boolean isViewNode = rn.getAddress()
              .equalsIgnoreCase(getRemoteNode().getAddress());
          final LinkedHashSet<RemoteNode> rns = new LinkedHashSet<>(
              ServiceProvider.IMPL.getRemoteNodeService()
                  .findForHost(getActor().getHost().getId()));
          getActor().getHost().setRemoteNodes(rns);
          RemoteNode prn = null;
          if (isViewNode && event.getNewValue() == null) {
            // node removed- show another node
            prn = getActor().getHost().getRemoteNodes().iterator()
                .next();
          } else if (isViewNode) {
            // update performed- refresh node
            for (final RemoteNode nrn : getActor().getHost().getRemoteNodes()) {
              if (nrn.getAddress().equalsIgnoreCase(rn.getAddress())) {
                prn = nrn;
                break;
              }
            }
          }
          setHelpText(RS.rbLabel(KEY.WIRELESS_NODE_REMOTE_SAVED_LOCAL, rn.getAddress()));
          // synchronize the remote node with the remote device
          if (prn != null) {
            getRemoteNodePA().setBean(prn);
            if (!prn.isDeviceSynchronized() && prn.getDeviceAutoSynchronize() == 1) {
              // automatically send the changes to the remote node device
              createCommandService(Command.SENSOR_SEND_SETTINGS, true);
            } else if (!prn.isDeviceSynchronized() && isViewNode) {
              validateRemoteNodeSynchronization();
            }
          }
        } else if (event.getType() == UGateEvent.Type.WIRELESS_DATA_TX_SUCCESS) {
          final RemoteNode rn = (RemoteNode) event.getSource();
          if (rn.getAddress().equalsIgnoreCase(getRemoteNode().getAddress())) {
            settingsSetTimeline.stop();
          }
        } else if (event.getType() == UGateEvent.Type.WIRELESS_DATA_RX_SUCCESS) {
          final RemoteNode rn = (RemoteNode) event.getSource();
          if (event.getNewValue() instanceof RxTxRemoteNodeReadingDTO) {
            final RxTxRemoteNodeReadingDTO sr = (RxTxRemoteNodeReadingDTO) event.getNewValue();
            ServiceProvider.IMPL.getRemoteNodeService().saveReading(sr.getRemoteNodeReading());
          } else 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);
              if (rn.getDeviceAutoSynchronize() == 1) {
                // automatically send the changes to the remote node
                // (consume event so no other notifications for the
                // event will be processed)
                event.setConsumed(true);
                createCommandService(Command.SENSOR_SEND_SETTINGS, true);
              } else if (rn.getAddress().equalsIgnoreCase(getRemoteNode().getAddress())) {
                validateRemoteNodeSynchronization();
              }
            }
          }
        } else if (event.getType() == UGateEvent.Type.WIRELESS_REMOTE_NODE_CHANGED) {
View Full Code Here

      log.error(String .format("Received data from an unknown address %1$s... Discarding response...",
          "NONE"));
      return null;
    }
    // TODO : RemoteNode should not be queried every time a response is received when multi-chunking data (like image)
    final RemoteNode rn = ServiceProvider.IMPL.getRemoteNodeService().findByAddress(remoteAddress);
    if (rn == null) {
      log.error(String .format("Received data from an unknown address %1$s... Discarding response...",
          remoteAddress));
      return null;
    }
View Full Code Here

   */
  public void handleSound(final UGateEvent<?, ?> event) {
    if (!(event.getSource() instanceof RemoteNode)) {
      return;
    }
    final RemoteNode rn = (RemoteNode) event.getSource();
    if (rn == null || rn.getDeviceSoundsOn() != 1) {
      return;
    }
    if (event.getType() == UGateEvent.Type.WIRELESS_DATA_TX_STATUS_RESPONSE_UNRECOGNIZED) {
      RS.mediaPlayerConfirm.play();
    } else if (event.getType() == UGateEvent.Type.WIRELESS_DATA_TX_STATUS_RESPONSE_SUCCESS) {
View Full Code Here

   *
   * @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

      @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

    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

            // 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

      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

      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

TOP

Related Classes of org.ugate.service.entity.jpa.RemoteNode

Copyright © 2018 www.massapicom. 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.