Ejemplo n.º 1
0
  private void createSensorNetwork() {
    String sn_name = null;
    String create_date = null;
    int sn_id = 0;
    String input_sn_id = null;
    Set<String> sn_uris = new HashSet<String>();
    System.out.println("Create Sensor Network Mode");
    System.out.print("Sensor Network Name: ");
    sn_name = sc.nextLine();

    Calendar calendar = Calendar.getInstance();
    java.util.Date date = calendar.getTime();
    create_date = (new SimpleDateFormat("yyyyMMddHHmmss").format(date));

    try {
      sensorNetworkMetaDAO.addSensorNetwork(sn_name, create_date);
      System.out.println("Finish Insert Sensor Network in DB");
      System.out.println("Add Sensors");

      for (; ; ) {
        System.out.print("Input Sensor(for quit to type 'x'): ");
        input_sn_id = sc.nextLine();
        if (input_sn_id.compareTo("x") == 0) break;
        else {
          String sn_uri = sensorMetaDAO.getSensorURI(input_sn_id);
          sn_uris.add(sn_uri);
        }
      }
      sn_id = sensorNetworkMetaDAO.getSensorNetworkID(sn_name);
      sensorNetworkMetaDAO.addSensorNetworkMembers(sn_id, sn_uris);
      snConnector.setSensorNetworkData(sn_name, sn_id, sn_uris, false);
      snConnector.transferSensorNetworkMeta();

    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 2
0
  private void deleteSensorNetwork() {
    String name = null;
    String delete_date = null;
    System.out.println("Delete Sensor Network Mode");

    System.out.print("Sensor Network Name: ");
    name = sc.nextLine();

    Calendar calendar = Calendar.getInstance();
    java.util.Date date = calendar.getTime();
    delete_date = (new SimpleDateFormat("yyyyMMddHHmmss").format(date));

    try {
      sensorNetworkMetaDAO.deleteSensorNetwork(name, delete_date);
      snConnector.setSensorNetworkData(name, 0, null, true);
      snConnector.transferSensorNetworkMeta();
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } catch (SQLException e) {
      e.printStackTrace();
    }
    System.out.println("Finish Delet Sensor Network in DB");
  }
Ejemplo n.º 3
0
  private void startCLIInterface() {
    int commandType = 0;
    boolean continue_flag = true;

    try {
      snConnector.createSocketandStream();
    } catch (IOException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }

    do {
      System.out.println("----Command Choose----");
      System.out.println("0. Log out");
      System.out.println("1. Create Sensor Meta");
      System.out.println("2. Update Sensor Meta");
      System.out.println("3. Delete Sensor Meta");
      System.out.println("4. Create Sensor Tags");
      System.out.println("5. Update Sensor Tags");
      System.out.println("6. Delete Sensor Tags");
      System.out.println("7. Create Sensor Network");
      System.out.println("8. Update Sensor Network");
      System.out.println("9. Delete Sensor Network");
      System.out.print("Choose Command: ");
      commandType = sc.nextInt();
      sc.nextLine();

      switch (commandType) {
        case 0:
          continue_flag = false;
          break;
        case 1:
          this.createSensorMeta();
          break;
        case 2:
          this.updateSensorMeta();
          break;
        case 3:
          this.deleteSensorMeta();
          break;
        case 4:
          this.createSensorTag();
          break;
        case 5:
          this.updateSensorTag();
          break;
        case 6:
          this.deleteSensorTag();
          break;
        case 7:
          this.createSensorNetwork();
          break;
        case 8:
          this.updateSensorNetwork();
          break;
        case 9:
          this.deleteSensorNetwork();
          break;
        default:
          System.out.println("Wrong Command");
          break;
      }
    } while (continue_flag);
    try {
      // Temporary Close Message sn_id == 999
      snConnector.setSensorNetworkData(null, 999, null, false);
      snConnector.transferSensorNetworkMeta();
      snConnector.closeSocketandStream();
    } catch (IOException e) {
      e.printStackTrace();
    }
    System.out.println("Bye");
  }