Ejemplo n.º 1
0
  private static void handleMotionSensorControllerMessage(Message Msg) {

    if (Msg.GetMessage().equalsIgnoreCase(MOTION_SENSOR_ON)) // window break Sensor on
    {
      messageWindow.WriteMessage("Motion Sensor on");
      MotionSensorState = true;
    }

    if (Msg.GetMessage().equalsIgnoreCase(MOTION_SENSOR_OFF)) // window break Sensor off
    {
      messageWindow.WriteMessage("Motion Sensor off");
      MotionSensorState = false;
    }
  }
Ejemplo n.º 2
0
  private static void performSensorprocess() {
    /**
     * ************************************************ Here we start the main simulation loop that
     * will continuously look for control messages *************************************************
     */
    messageWindow.WriteMessage("Motion Sensor off");

    while (!Done) {
      // postArmStatus

      try {
        queue = messageManager.GetMessageQueue(); // get messages from message manager
        sendHeartBeat(messageManager, "22", "MotionSensor", "This device detectes motion");
      } catch (Exception e) {
        messageWindow.WriteMessage("Error getting message queue::" + e);
      }

      int qlen = queue.GetSize();

      for (int i = 0; i < qlen; i++) {
        Msg = queue.GetMessage();

        if (Msg.GetMessageId() == MOTION_SENSOR_ID) {
          handleMotionSensorControllerMessage(Msg);
        }

        if (Msg.GetMessageId() == HALT_SECURITY_ID) {
          handleExitMessage();
        }
        if (MotionSensorState) {
          if (Msg.GetMessageId() == MOTION_SIMULATE_ID) {
            if (SIMULATE_ON.equals(Msg.GetMessage())) {
              simulate = true;
              messageWindow.WriteMessage("Send MOTION_DETECTED");
              sendMessageToMessageManager(MOTION_DETECTED, MOTION_SENSE_MSG_ID);
            } else {
              simulate = false;
              messageWindow.WriteMessage("Send STOP_ALARM");
              sendMessageToMessageManager(STOP_ALARM, MOTION_SENSE_MSG_ID);
            }
          }
        }
      }
      if (MotionSensorState) {
        if (simulate) {
          messageWindow.WriteMessage("Send MOTION_DETECTED");
          sendMessageToMessageManager(MOTION_DETECTED, MOTION_SENSE_MSG_ID);
        } else {
          messageWindow.WriteMessage("Send OK");
          sendMessageToMessageManager(OK, MOTION_SENSE_MSG_ID);
        }
      }

      try {
        Thread.sleep(Delay);
      } catch (Exception e) {
        System.out.println("Sleep error:: " + e);
      }
    }
  }