コード例 #1
0
  @Override
  public void message(ReadWriteFONA.SMS sms) {
    log("\nReceived messsage:");
    log("From:" + sms.getFrom());
    log(sms.getContent());
    if (sms.getContent().trim().equalsIgnoreCase("CLEAN")
        && (SIMULATOR.equals(sms.getFrom())
            || sms.getFrom().contains(phoneNumber_1)
            || sms.getFrom().contains(phoneNumber_2)
            || sms.getFrom().contains(phoneNumber_3))) {
      // Check, and Resume if OK
      if (currentOilThickness <= 0) {
        // Tell whoever has been warned so far
        boolean[] messLevel = {false, false, false};
        messLevel[SENT_TO_CAPTAIN] =
            (currentStatus == ProcessStatus.MESSAGE_SENT_TO_CAPTAIN
                || currentStatus == ProcessStatus.MESSAGE_SENT_TO_OWNER
                || currentStatus == ProcessStatus.MESSAGE_SENT_TO_AUTHORITIES);
        messLevel[SENT_TO_OWNER] =
            (currentStatus == ProcessStatus.MESSAGE_SENT_TO_OWNER
                || currentStatus == ProcessStatus.MESSAGE_SENT_TO_AUTHORITIES);
        messLevel[SENT_TO_AUTHORITIES] =
            (currentStatus == ProcessStatus.MESSAGE_SENT_TO_AUTHORITIES);
        String[] mess = {
          "Oil in the bilge of " + boatName + " has been cleaned",
          "Bilge pump can be used as before."
        };
        //  String mess =  "Oil in the bilge of " + boatName + " has been cleaned.";
        if (messLevel[SENT_TO_AUTHORITIES]) sendSMS(phoneNumber_3, mess);
        if (messLevel[SENT_TO_OWNER]) sendSMS(phoneNumber_2, mess);
        if (messLevel[SENT_TO_CAPTAIN]) sendSMS(phoneNumber_1, mess);

        currentStatus = ProcessStatus.ALL_OK;
        RelayManager.RelayState status = rm.getStatus("00");
        // log("Relay is:" + status);
        if (RelayManager.RelayState.OFF.equals(status)) {
          log("Turning relay back on as needed.");
          try {
            rm.set("00", RelayManager.RelayState.ON);
          } catch (Exception ex) {
            System.err.println(ex.toString());
          }
        }
      } else {
        // Reply, not clean enough.
        String[] mess = {
          "Sorry, the bilge is not clean enough.",
          "Try again to send a CLEAN message when this has been taken care of"
        };
        // String mess = "Not clean enough";
        sendSMS(phoneNumber_1, mess);
      }
    }
  }
コード例 #2
0
 @Override
 public void message(ReadWriteFONA.SMS sms) {
   System.out.println(
       "Message # "
           + sms.getNum()
           + ", from "
           + sms.getFrom()
           + ", "
           + sms.getLen()
           + " char(s), "
           + sms.getContent());
 }