コード例 #1
0
  void fileWriter(int motePinId, byte[] message) {

    // Writing the Simulation time and Sensor value in a file
    int pinId = 0;
    pinId = motePinId % 100;
    String content = "";

    if (pinId == 18) {
      try {
        //                String content = "";
        content =
            (String.valueOf(motePinId)
                + '\t'
                + '\t'
                + String.valueOf(sim.getSimulationTimeMillis())
                + '\t'
                + '\t'
                + String.valueOf(message[0])
                + '\t'
                + '\t'
                + String.valueOf(message[1])
                + '\t'
                + '\t'
                + String.valueOf(message[2])
                + '\t'
                + '\t'
                + String.valueOf(message[3])
                + '\t'
                + '\t'
                + String.valueOf(message[4])
                + '\t'
                + '\t'
                + String.valueOf(message[5])
                + '\t'
                + '\t'
                + String.valueOf(message[6])
                + '\t'
                + '\t'
                + String.valueOf(message[7])
                + '\t'
                + '\t'
                + String.valueOf(message[8])
                + '\t'
                + '\t'
                + String.valueOf(message[9])
                + '\t'
                + '\t'
                + String.valueOf(message[10])
                + '\t'
                + '\t'
                + String.valueOf(message[11])
                + '\t'
                + '\t'
                + String.valueOf(message[12])
                + '\t'
                + '\t'
                + String.valueOf(message[13])
                + '\t'
                + '\t'
                + String.valueOf(message[14])
                + '\t'
                + '\t'
                + String.valueOf(message[15]));

        lastTimeForFile = sim.getSimulationTimeMillis();

        // if file doesn't exists, then create it
        if (!serialFileSend.exists()) {
          serialFileSend.createNewFile();
        } else if (SerialSendWrittenForFirst) {
          serialFileSend.delete();
          serialFileSend.createNewFile();
          SerialSendWrittenForFirst = false;
        }

        FileWriter fw = new FileWriter(serialFileSend.getAbsoluteFile(), true);

        BufferedWriter bw = new BufferedWriter(fw);
        PrintWriter pn = new PrintWriter(fw);
        pn.println(content);
        pn.close();

        logger.info("Done");
      } catch (Exception e) { // Catch exception if any
        logger.info("Error in print dacFile");
      }
    } else if (pinId == 19) {
      try {
        //                String content = "";
        content =
            (String.valueOf(motePinId)
                + '\t'
                + '\t'
                + String.valueOf(sim.getSimulationTimeMillis())
                + '\t'
                + '\t'
                + String.valueOf(message[0])
                + '\t'
                + '\t'
                + String.valueOf(message[1])
                + '\t'
                + '\t'
                + String.valueOf(message[2])
                + '\t'
                + '\t'
                + String.valueOf(message[3])
                + '\t'
                + '\t'
                + String.valueOf(message[4])
                + '\t'
                + '\t'
                + String.valueOf(message[5])
                + '\t'
                + '\t'
                + String.valueOf(message[6])
                + '\t'
                + '\t'
                + String.valueOf(message[7])
                + '\t'
                + '\t'
                + String.valueOf(message[8])
                + '\t'
                + '\t'
                + String.valueOf(message[9])
                + '\t'
                + '\t'
                + String.valueOf(message[10])
                + '\t'
                + '\t'
                + String.valueOf(message[11])
                + '\t'
                + '\t'
                + String.valueOf(message[12])
                + '\t'
                + '\t'
                + String.valueOf(message[13])
                + '\t'
                + '\t'
                + String.valueOf(message[14])
                + '\t'
                + '\t'
                + String.valueOf(message[15]));

        lastTimeForFile = sim.getSimulationTimeMillis();

        // if file doesn't exists, then create it
        if (!serialFileRCV.exists()) {
          serialFileRCV.createNewFile();
        } else if (SerialRCVWrittenForFirst) {
          serialFileRCV.delete();
          serialFileRCV.createNewFile();
          SerialRCVWrittenForFirst = false;
        }

        FileWriter fw = new FileWriter(serialFileRCV.getAbsoluteFile(), true);
        BufferedWriter bw = new BufferedWriter(fw);
        PrintWriter pn = new PrintWriter(fw);
        pn.println(content);
        pn.close();
        logger.info("Done");
      } catch (Exception e) { // Catch exception if any
        logger.info("Error in print dacFile");
      }
    }
    // End of writing

  }
コード例 #2
0
  void fileWriter(int motePinId, int value) {

    // Writing the Simulation time and Sensor value in a file
    int pinId = 0;
    pinId = motePinId % 100;
    String content = "";
    String content1 = ("motePinId" + '\t' + '\t' + "SimulationTime" + '\t' + '\t' + "value");

    if (pinId == 0 || pinId == 1) {
      try {
        //                String content = "";
        content =
            (String.valueOf(motePinId)
                + '\t'
                + '\t'
                + String.valueOf(sim.getSimulationTimeMillis())
                + '\t'
                + '\t'
                + String.valueOf(value));

        lastTimeForFile = sim.getSimulationTimeMillis();

        // if file doesn't exists, then create it
        if (!adcFile.exists()) {
          adcFile.createNewFile();
        } else if (ADCWrittenForFirst) {
          adcFile.delete();
          adcFile.createNewFile();

          FileWriter fw1 = new FileWriter(adcFile.getAbsoluteFile(), true);
          BufferedWriter bw1 = new BufferedWriter(fw1);
          PrintWriter pn1 = new PrintWriter(fw1);
          pn1.println(content1);
          pn1.close();

          ADCWrittenForFirst = false;
        }

        FileWriter fw = new FileWriter(adcFile.getAbsoluteFile(), true);
        BufferedWriter bw = new BufferedWriter(fw);
        PrintWriter pn = new PrintWriter(fw);
        pn.println(content);
        pn.close();
        //               logger.info("Done");
      } catch (Exception e) { // Catch exception if any
        logger.info("Error in print dacFile");
      }
    } else if (pinId == 16 || pinId == 17) {
      try {
        content =
            (String.valueOf(motePinId)
                + '\t'
                + '\t'
                + String.valueOf(sim.getSimulationTimeMillis())
                + '\t'
                + '\t'
                + String.valueOf(value));
        if (!dacFile.exists()) {
          dacFile.createNewFile();
        } else if (DACWrittenForFirst) {
          dacFile.delete();
          dacFile.createNewFile();

          FileWriter fw1 = new FileWriter(dacFile.getAbsoluteFile(), true);
          BufferedWriter bw1 = new BufferedWriter(fw1);
          PrintWriter pn1 = new PrintWriter(fw1);
          pn1.println(content1);
          pn1.close();

          DACWrittenForFirst = false;
        }

        FileWriter fw = new FileWriter(dacFile.getAbsoluteFile(), true);

        BufferedWriter bw = new BufferedWriter(fw);
        PrintWriter pn = new PrintWriter(fw);
        pn.println(content);
        pn.close();
        //                        logger.info("Done");
      } catch (Exception e) { // Catch exception if any
        logger.info("Error in print dacFile");
      }
    }
    // End of writing
  }