public void run() {
   started = System.currentTimeMillis();
   while (keepWaiting && !currentStatus.equals(ProcessStatus.ALL_OK)) {
     delay(10); // in seconds
     if (!currentStatus.equals(ProcessStatus.ALL_OK)
         && (System.currentTimeMillis() - started) > (cleaningDelay * 1000)) // Expired
     {
       // Next status level.
       log("Your cleaning delay (" + cleaningDelay + ") has expired. Going to the next level");
       log(" >>>>>>>>>> Level is " + currentStatus + ", GOING TO THE NEXT LEVEL >>>>>> ");
       switch (currentStatus.level()) {
         case SENT_TO_CAPTAIN:
           {
             log(">>>>>>>>>>>>> SENDING MESSAGE TO OWNER >>>>>");
             started = System.currentTimeMillis(); // Re-initialize the loop
             currentStatus = ProcessStatus.MESSAGE_SENT_TO_OWNER;
             String[] mess = {
               "Your boat, " + boatName + ", has oil in its bilge",
               "The power supply of the bilge pump has been shut off",
               "This oil should be cleaned.",
               "Reply to this message by sending CLEAN when done"
             };
             //  String mess = "Your boat, " + boatName + ", has oil in its bilge.";
             sendSMS(phoneNumber_2, mess);
           }
           break;
         case SENT_TO_OWNER:
           {
             log(">>>>>>>>>>>>> SENDING MESSAGE TO AUTHORITIES >>>>>");
             started = System.currentTimeMillis(); // Re-initialize the loop
             currentStatus = ProcessStatus.MESSAGE_SENT_TO_AUTHORITIES;
             String[] mess = {
               "The vessel " + boatName + " has oil in its bilge",
               "The power supply of the bilge pump has been shut off",
               "This oil should be cleaned.",
               "Reply to this message by sending CLEAN when the bilge has been cleaned."
             };
             //  String mess = "The vessel " + boatName + " has oil in its bilge."};
             sendSMS(phoneNumber_3, mess);
           }
           break;
         default:
           log(">>>>>>>>>>>>> FULL RESET NEEDED >>>>>");
           keepWaiting = false; // Full reset needed.
           break;
       }
     }
   }
   log("  >>> " + this.getClass().getName() + " completed.");
 }
Exemplo n.º 2
0
  /**
   * @param testTask the testTask to be executed
   * @param testSuite the TestSuite wrapper for the testTask
   * @param environment the environment configuration
   */
  public void runTestTask(TestTask testTask, TestSuite testSuite, Environment environment) {

    /*
     * check if all mandatory fields are set
     */
    ProcessStatus notNullCheck =
        NullCheckWrapperUtil.checkIfNotNull(testTask, "id", "method", "resource");
    if (notNullCheck.isPassed()) {
      /*
       Run the http calls
      */ try {

        resourceInvocationHandler.executeResourceCalls(testTask, testSuite);

        /*
        Run the status check assertions if set
        */
        if (testTask.getStatusCheck() != null) {
          assertionExecutor.executeStatusAssertion(testTask, testSuite);
        }
        /*
        Run the value assertions if set
         */
        if (testTask.getAssertions() != null && testTask.getAssertions().size() > 0) {
          for (ValueAssertion assertion : testTask.getAssertions()) {
            assertionExecutor.executeAssertion(assertion, testSuite.getTestContext());
            if (!assertion.isPassed()) {
              testSuite.setFailureCount(testSuite.getFailureCount() + 1);
              testTask.setPassed(false);
            }
          }
        }
      } catch (IOException e) {
        LOGGER.error("IO Exception when executing testSuiteId " + testSuite.getId(), e);
        testTask.setError(e.getMessage());
      } catch (JsonPathException e) {
        LOGGER.error("Json path Exception when executing testSuiteId " + testSuite.getId(), e);
        testTask.setError(e.getMessage());

      } catch (InvalidExpressionException e) {
        LOGGER.error("InvalidExpression  when executing testSuiteId" + testSuite.getId(), e);
        testTask.setError(e.getMessage());
      }
    } else {
      testTask.setError(notNullCheck.getMessage());
    }
  }
  /**
   * -----+-oo- ^ | ^ | | | Dist To Surface | | v | -+---------------- RSH | Oil Thickness |
   * -+---------------- | | ^ | | | Water Thickness v | v =====+================ RSH: RangeSensor
   * Height
   */
  private static void businessLogic(double waterThickness, double oilThickness) {
    //  log(">>> In BusinessLogic (" + waterLevel + ", " + oilLevel + ")");

    //  currentWaterLevel   = Math.round(waterLevel);
    oilThicknessValues.add(oilThickness);

    //  double smoothedOilValue = -1D;

    //  System.out.println("Business Logic - Water:" + waterLevel + ", oil:" + oilLevel);
    if (oilThicknessValues.size() >= windowWidth) {
      while (oilThicknessValues.size() > windowWidth) oilThicknessValues.remove(0);
      currentOilThickness = smoothOilThickness();
    }
    if (oilThicknessValues.size() >= windowWidth && currentOilThickness > 0) {
      //    log("Oil thick:" + oilThickness + ", Water:" + waterLevel);
      if (waterThickness <= 0.1 && currentOilThickness > 0.25) {
        log(
            "       >>>>>>>>>>>>>>>>>>>>>>>>>> Shutting OFF !!!! <<<<<<<<<<<<<<<<<<<<< W:"
                + waterThickness
                + ", O:"
                + currentOilThickness);
        // Switch the relay off?
        RelayManager.RelayState status = rm.getStatus("00");
        // log("Relay is:" + status);
        if (RelayManager.RelayState.ON.equals(status)) {
          log("Turning relay off!");
          try {
            rm.set("00", RelayManager.RelayState.OFF);
          } catch (Exception ex) {
            System.err.println(ex.toString());
          }
        }
        if (currentStatus.equals(ProcessStatus.ALL_OK)) {
          log("Oil thick:" + currentOilThickness + ", Water:" + waterThickness + " ");
          // Make a call
          String[] mess = {
            "Oil in the bilge of " + boatName + ": " + DF23.format(currentOilThickness) + " cm.",
            "Please reply CLEAN to this message when done with it."
          };
          //  String mess = "First warning to " + boatName;

          displayAppMess(
              " >>>>>>>>>> CALLING "
                  + phoneNumber_1); // + "Mess is a " + mess.getClass().getName() + "\n" + mess);
          sendSMS(phoneNumber_1, mess);
          currentStatus = ProcessStatus.MESSAGE_SENT_TO_CAPTAIN;
          WaitForCleanThread wfct = new WaitForCleanThread();
          wfct.start();
        }
      } else {
        System.out.println("                            ");
        System.out.println("                            ");
      }
    }
  }