예제 #1
0
  public boolean setConfigXML(
      Simulation simulation, Collection<Element> configXML, boolean visAvailable) {
    for (Element element : configXML) {
      String name = element.getName();

      if (name.equals("motetype_identifier")) {

        setSimulation(simulation);
        myMoteType = (MspMoteType) simulation.getMoteType(element.getText());
        getType().setIdentifier(element.getText());

        initEmulator(myMoteType.getContikiFirmwareFile());
        myMoteInterfaceHandler = createMoteInterfaceHandler();

      } else if (name.equals("interface_config")) {
        String intfClass = element.getText().trim();
        if (intfClass.equals("se.sics.cooja.mspmote.interfaces.MspIPAddress")) {
          intfClass = IPAddress.class.getName();
        }
        Class<? extends MoteInterface> moteInterfaceClass =
            simulation.getGUI().tryLoadClass(this, MoteInterface.class, intfClass);

        if (moteInterfaceClass == null) {
          logger.fatal("Could not load mote interface class: " + intfClass);
          return false;
        }

        MoteInterface moteInterface = getInterfaces().getInterfaceOfType(moteInterfaceClass);
        moteInterface.setConfigXML(element.getChildren(), visAvailable);
      }
    }

    return true;
  }
예제 #2
0
 public void setInactive() {
   simulation.deleteObserver(simObserver);
   for (Mote mote : simulation.getMotes()) {
     IPAddress ipAddr = mote.getInterfaces().getIPAddress();
     if (ipAddr != null) {
       ipAddr.deleteObserver(addrObserver);
     }
     RimeAddress rimeAddr = mote.getInterfaces().getRimeAddress();
     if (rimeAddr != null) {
       rimeAddr.deleteObserver(addrObserver);
     }
   }
 }
 public void actionPerformed(ActionEvent e) {
   Runnable r =
       new Runnable() {
         public void run() {
           reset();
         }
       };
   if (simulation.isRunning()) {
     simulation.invokeSimulationThread(r);
   } else {
     r.run();
   }
 }
예제 #4
0
  public void setActive(Simulation simulation, Visualizer vis) {
    this.simulation = simulation;
    this.visualizer = vis;

    simulation.addObserver(simObserver);
    simObserver.update(null, null);
  }
예제 #5
0
  public void paintAfterMotes(Graphics g) {
    FontMetrics fm = g.getFontMetrics();
    g.setColor(Color.BLACK);

    /* Paint last output below motes */
    Mote[] allMotes = simulation.getMotes();
    for (Mote mote : allMotes) {
      String msg = null;
      {
        IPAddress ipAddr = mote.getInterfaces().getIPAddress();
        if (ipAddr != null) {
          msg = ipAddr.getIPString();
        }
      }

      if (msg == null) {
        RimeAddress rimeAddr = mote.getInterfaces().getRimeAddress();
        if (rimeAddr != null) {
          msg = rimeAddr.getAddressString();
        }
      }

      if (msg == null) {
        continue;
      }

      Position pos = mote.getInterfaces().getPosition();
      Point pixel = visualizer.transformPositionToPixel(pos);

      int msgWidth = fm.stringWidth(msg);
      g.drawString(msg, pixel.x - msgWidth / 2, pixel.y + 2 * Visualizer.MOTE_RADIUS + 3);
    }
  }
    public void update() {
      long now = simulation.getSimulationTime();

      accumulateDuration(now - lastUpdateTime);

      /* Radio on/off */
      if (radioWasOn) {
        accumulateRadioOn(now - lastUpdateTime);
      }

      /* Radio tx/rx */
      if (lastRadioState == RadioState.TRANSMITTING) {
        accumulateRadioTx(now - lastUpdateTime);
      } else if (lastRadioState == RadioState.RECEIVING) {
        accumulateRadioRx(now - lastUpdateTime);
      } else if (lastRadioState == RadioState.INTERFERED) {
        accumulateRadioIntefered(now - lastUpdateTime);
      }

      /* Await next radio event */
      if (radio.isTransmitting()) {
        lastRadioState = RadioState.TRANSMITTING;
      } else if (!radio.isRadioOn()) {
        lastRadioState = RadioState.IDLE;
      } else if (radio.isInterfered()) {
        lastRadioState = RadioState.INTERFERED;
      } else if (radio.isReceiving()) {
        lastRadioState = RadioState.RECEIVING;
      } else {
        lastRadioState = RadioState.IDLE;
      }
      radioWasOn = radio.isRadioOn();
      lastUpdateTime = now;
    }
  public void closePlugin() {
    /* Remove repaint timer */
    repaintTimer.stop();

    simulation.getEventCentral().removeMoteCountListener(moteCountListener);

    /* Remove mote trackers */
    for (Mote m : simulation.getMotes()) {
      removeMote(m);
    }
    if (!moteTrackers.isEmpty()) {
      logger.fatal("Mote observers not cleaned up correctly");
      for (MoteTracker t : moteTrackers.toArray(new MoteTracker[0])) {
        t.dispose();
      }
    }
  }
 public void reset() {
   while (moteTrackers.size() > 0) {
     removeMote(moteTrackers.get(0).mote);
   }
   for (Mote m : simulation.getMotes()) {
     addMote(m);
   }
 }
예제 #9
0
  private static void generate(File config, File jar) {
    if (!config.exists()) {
      throw new RuntimeException("Simulation config not found: " + config.getAbsolutePath());
    }

    /* Load simulation */
    logger.info("Loading " + config);
    GUI.externalToolsUserSettingsFile =
        new File(System.getProperty("user.home"), GUI.EXTERNAL_TOOLS_USER_SETTINGS_FILENAME);
    Simulation s = GUI.quickStartSimulationConfig(config, false, null);
    if (s == null) {
      throw new RuntimeException("Error when creating simulation");
    }
    s.stopSimulation();

    try {
      buildExecutableJAR(s.getGUI(), jar);
    } catch (RuntimeException e) {
      logger.fatal(e.getMessage(), e);
      System.exit(1);
    }
    System.exit(0);
  }
예제 #10
0
        public void update(Observable obs, Object obj) {

          /* Observe Rime and IP addresses */
          for (Mote mote : simulation.getMotes()) {
            IPAddress ipAddr = mote.getInterfaces().getIPAddress();
            if (ipAddr != null) {
              ipAddr.addObserver(addrObserver);
            }
            RimeAddress rimeAddr = mote.getInterfaces().getRimeAddress();
            if (rimeAddr != null) {
              rimeAddr.addObserver(addrObserver);
            }
          }
          visualizer.repaint();
        }
예제 #11
0
  public boolean setConfigXML(
      Simulation simulation, Collection<Element> configXML, boolean visAvailable) {
    setSimulation(simulation);
    myMoteInterfaceHandler = createMoteInterfaceHandler();

    /* Create watchpoint container */
    try {
      breakpointsContainer =
          new MspBreakpointContainer(this, ((MspMoteType) getType()).getFirmwareDebugInfo());
    } catch (IOException e) {
      throw (RuntimeException) new RuntimeException("Error: " + e.getMessage()).initCause(e);
    }

    for (Element element : configXML) {
      String name = element.getName();

      if (name.equals("motetype_identifier")) {
        /* Ignored: handled by simulation */
      } else if ("breakpoints".equals(element.getName())) {
        breakpointsContainer.setConfigXML(element.getChildren(), visAvailable);
      } else if (name.equals("interface_config")) {
        String intfClass = element.getText().trim();
        if (intfClass.equals("se.sics.cooja.mspmote.interfaces.MspIPAddress")) {
          intfClass = IPAddress.class.getName();
        }
        if (intfClass.equals("se.sics.cooja.mspmote.interfaces.ESBLog")) {
          intfClass = MspSerial.class.getName();
        }
        if (intfClass.equals("se.sics.cooja.mspmote.interfaces.SkySerial")) {
          intfClass = MspSerial.class.getName();
        }
        Class<? extends MoteInterface> moteInterfaceClass =
            simulation.getGUI().tryLoadClass(this, MoteInterface.class, intfClass);

        if (moteInterfaceClass == null) {
          logger.fatal("Could not load mote interface class: " + intfClass);
          return false;
        }

        MoteInterface moteInterface = getInterfaces().getInterfaceOfType(moteInterfaceClass);
        moteInterface.setConfigXML(element.getChildren(), visAvailable);
      }
    }

    /* Schedule us immediately */
    requestImmediateWakeup();
    return true;
  }
    public MoteTracker(Mote mote) {
      this.simulation = mote.getSimulation();
      this.mote = mote;
      this.radio = mote.getInterfaces().getRadio();

      radioWasOn = radio.isRadioOn();
      if (radio.isTransmitting()) {
        lastRadioState = RadioState.TRANSMITTING;
      } else if (radio.isReceiving()) {
        lastRadioState = RadioState.RECEIVING;
      } else if (radio.isInterfered()) {
        lastRadioState = RadioState.INTERFERED;
      } else {
        lastRadioState = RadioState.IDLE;
      }
      lastUpdateTime = simulation.getSimulationTime();

      radio.addObserver(this);
    }
예제 #13
0
  /**
   * Builds executable JAR from current simulation
   *
   * @param gui GUI. Must contain simulation
   * @param outputFile Output file
   */
  public static boolean buildExecutableJAR(GUI gui, File outputFile) {
    String executeDir = null;
    executeDir = outputFile.getName();
    if (!executeDir.endsWith(".jar")) {
      throw new RuntimeException("Not a proper JAR archive: " + executeDir);
    }
    executeDir = executeDir.substring(0, executeDir.length() - ".jar".length());

    Simulation simulation = gui.getSimulation();
    if (simulation == null) {
      throw new RuntimeException("No simulation active");
    }

    /* Check dependencies: mote type */
    for (MoteType t : simulation.getMoteTypes()) {
      if (!t.getClass().getName().contains("SkyMoteType")) {
        throw new RuntimeException(
            "You simulation contains the mote type: "
                + GUI.getDescriptionOf(t.getClass())
                + "\n"
                + "Only the Sky Mote Type is currently supported.\n");
      }
      logger.info("Checking mote types: '" + GUI.getDescriptionOf(t.getClass()) + "'");
    }

    /* Check dependencies: Contiki Test Editor */
    boolean hasTestEditor = false;
    for (Plugin startedPlugin : gui.getStartedPlugins()) {
      if (startedPlugin instanceof ScriptRunner) {
        hasTestEditor = true;
        break;
      }
    }
    logger.info("Checking that Contiki Test Editor exists: " + hasTestEditor);
    if (!hasTestEditor) {
      throw new RuntimeException(
          "The simulation needs at least one active Contiki Test Editor plugin.\n"
              + "The plugin is needed to control the non-visualized simulation.");
    }

    /* Create temporary directory */
    File workingDir;
    try {
      workingDir = File.createTempFile("cooja", ".tmp");
      workingDir.delete();
      workingDir.mkdir();
      logger.info("Creating temporary directory: " + workingDir.getAbsolutePath());
    } catch (IOException e1) {
      throw (RuntimeException)
          new RuntimeException("Error when creating temporary directory: " + e1.getMessage())
              .initCause(e1);
    }

    /* Unpacking project JARs */
    ProjectConfig config = gui.getProjectConfig();
    String[] projectJARs = config.getStringArrayValue(GUI.class.getName() + ".JARFILES");
    for (String jar : projectJARs) {
      /* Locate project */
      File project = config.getUserProjectDefining(GUI.class, "JARFILES", jar);
      File jarFile = new File(project, jar);
      if (!jarFile.exists()) {
        jarFile = new File(project, "lib/" + jar);
      }
      if (!jarFile.exists()) {
        throw new RuntimeException("Project JAR could not be found: " + jarFile.getAbsolutePath());
      }

      logger.info("Unpacking project JAR " + jar + " (" + project + ")");
      try {
        Process unjarProcess =
            Runtime.getRuntime()
                .exec(new String[] {"jar", "xf", jarFile.getAbsolutePath()}, null, workingDir);
        unjarProcess.waitFor();
      } catch (Exception e1) {
        throw (RuntimeException)
            new RuntimeException("Error unpacking JAR file: " + e1.getMessage()).initCause(e1);
      }
    }

    /* Unpacking COOJA core JARs */
    String[] coreJARs =
        new String[] {
          "tools/cooja/lib/jdom.jar", "tools/cooja/lib/log4j.jar", "tools/cooja/dist/cooja.jar"
        };
    for (String jar : coreJARs) {
      File jarFile = new File(GUI.getExternalToolsSetting("PATH_CONTIKI"), jar);
      if (!jarFile.exists()) {
        throw new RuntimeException("Project JAR could not be found: " + jarFile.getAbsolutePath());
      }
      logger.info("Unpacking core JAR " + jar);
      try {
        Process unjarProcess =
            Runtime.getRuntime()
                .exec(new String[] {"jar", "xf", jarFile.getAbsolutePath()}, null, workingDir);
        unjarProcess.waitFor();
      } catch (Exception e1) {
        throw (RuntimeException)
            new RuntimeException("Error unpacking JAR file: " + e1.getMessage()).initCause(e1);
      }
    }

    /* Prepare simulation config */
    Element rootElement = gui.extractSimulationConfig();
    logger.info("Extracting simulation configuration");
    handleExportAttributesToJAR(rootElement, gui, workingDir);

    /* Save simulation config */
    File configFile = new File(workingDir, SIMCONFIG_FILENAME);
    try {
      Document doc = new Document(rootElement);
      FileOutputStream out = new FileOutputStream(configFile);
      XMLOutputter outputter = new XMLOutputter();
      outputter.setFormat(Format.getPrettyFormat());
      outputter.output(doc, out);
      out.close();
    } catch (Exception e1) {
      throw (RuntimeException)
          new RuntimeException("Error when writing simulation configuration: " + configFile)
              .initCause(e1);
    }
    logger.info("Wrote simulation configuration: " + configFile.getName());

    /* Export external tools config (without projects) */
    try {
      File externalToolsConfig = new File(workingDir, EXTERNALTOOLS_FILENAME);
      FileOutputStream out = new FileOutputStream(externalToolsConfig);
      Properties differingSettings = new Properties();
      Enumeration<Object> keyEnum = GUI.currentExternalToolsSettings.keys();
      while (keyEnum.hasMoreElements()) {
        String key = (String) keyEnum.nextElement();
        String defaultSetting = GUI.getExternalToolsDefaultSetting(key, "");
        String currentSetting = GUI.currentExternalToolsSettings.getProperty(key, "");

        if (key.equals("DEFAULT_PROJECTDIRS")) {
          differingSettings.setProperty(key, "");
        } else if (!defaultSetting.equals(currentSetting)) {
          differingSettings.setProperty(key, currentSetting);
        }
      }

      differingSettings.store(out, "Cooja External Tools (User specific)");
      out.close();
      logger.info("Wrote external tools config: " + externalToolsConfig.getName());
    } catch (Exception e2) {
      throw (RuntimeException)
          new RuntimeException(
                  "Error when writing external tools configuration: " + e2.getMessage())
              .initCause(e2);
    }

    /* Export current project configuration */
    try {
      ProjectConfig pConfig = gui.getProjectConfig().clone();
      Enumeration<String> pValues = pConfig.getPropertyNames();
      File newConfigFile = new File(workingDir, PROJECT_DEFAULT_CONFIG_FILENAME);
      Properties newConfig = new Properties();
      while (pValues.hasMoreElements()) {
        String name = pValues.nextElement();
        newConfig.setProperty(name, pConfig.getStringValue(name));
      }
      FileOutputStream out = new FileOutputStream(newConfigFile);
      newConfig.store(out, "Cooja Project Config");
      logger.info("Wrote project config: " + newConfigFile.getName());
    } catch (Exception e1) {
      e1.printStackTrace();
      throw (RuntimeException)
          new RuntimeException("Error when writing project config: " + e1.getMessage())
              .initCause(e1);
    }

    /* Delete existing META-INF dir */
    File metaInfDir = new File(workingDir, "META-INF");
    if (metaInfDir.exists() && metaInfDir.isDirectory()) {
      if (!deleteDirectory(metaInfDir)) {
        if (!deleteDirectory(metaInfDir)) {
          deleteDirectory(metaInfDir);
        }
      }
    }

    /* Prepare JAR manifest */
    File manifestFile = new File(workingDir, "manifest.tmp");
    if (manifestFile.exists()) {
      manifestFile.delete();
    }
    StringBuilder sb = new StringBuilder();
    sb.append("Manifest-Version: 1.0\r\n");
    sb.append("Main-Class: " + ExecuteJAR.class.getName() + "\r\n");
    sb.append("Class-path: .\r\n");
    StringUtils.saveToFile(manifestFile, sb.toString());
    logger.info("Wrote manifest file: " + manifestFile.getName());

    /* Build executable JAR */
    if (outputFile.exists()) {
      outputFile.delete();
    }

    logger.info("Building executable JAR: " + outputFile);
    MessageList errors = new MessageList();
    try {
      CompileContiki.compile(
          "jar cfm " + outputFile.getAbsolutePath() + " manifest.tmp .",
          null,
          outputFile,
          workingDir,
          null,
          null,
          errors,
          true);
    } catch (Exception e) {
      logger.warn("Building executable JAR error: " + e.getMessage());
      MessageContainer[] err = errors.getMessages();
      for (int i = 0; i < err.length; i++) {
        logger.fatal(">> " + err[i]);
      }

      /* Forward exception */
      throw (RuntimeException)
          new RuntimeException("Error when building executable JAR: " + e.getMessage())
              .initCause(e);
    }

    /* Delete temporary working directory */
    logger.info("Deleting temporary files in: " + workingDir.getAbsolutePath());
    if (!deleteDirectory(workingDir)) {
      if (!deleteDirectory(workingDir)) {
        deleteDirectory(workingDir);
      }
    }

    /* We are done! */
    logger.info("Done! To run simulation: > java -jar " + outputFile.getName());
    return true;
  }
  public PowerTracker(final Simulation simulation, final GUI gui) {
    super("PowerTracker", gui, false);
    this.simulation = simulation;

    /* Automatically add/delete motes */
    simulation
        .getEventCentral()
        .addMoteCountListener(
            moteCountListener =
                new MoteCountListener() {
                  public void moteWasAdded(Mote mote) {
                    addMote(mote);
                    table.invalidate();
                    table.repaint();
                  }

                  public void moteWasRemoved(Mote mote) {
                    removeMote(mote);
                    table.invalidate();
                    table.repaint();
                  }
                });
    for (Mote m : simulation.getMotes()) {
      addMote(m);
    }

    if (!GUI.isVisualized()) {
      return;
    }

    AbstractTableModel model =
        new AbstractTableModel() {
          public int getRowCount() {
            return moteTrackers.size() + 1;
          }

          public int getColumnCount() {
            return 4;
          }

          public String getColumnName(int col) {
            if (col == COLUMN_MOTE) {
              return "Mote";
            }
            if (col == COLUMN_RADIOON) {
              return "Radio on (%)";
            }
            if (col == COLUMN_RADIOTX) {
              return "Radio TX (%)";
            }
            if (col == COLUMN_RADIORX) {
              return "Radio RX (%)";
            }
            return null;
          }

          public Object getValueAt(int rowIndex, int col) {
            if (rowIndex < 0 || rowIndex >= moteTrackers.size() + 1) {
              return null;
            }

            if (rowIndex == moteTrackers.size()) {
              /* Average */
              long radioOn = 0;
              long radioTx = 0;
              long radioRx = 0;
              long duration = 0;
              for (MoteTracker mt : moteTrackers) {
                radioOn += mt.radioOn;
                radioTx += mt.radioTx;
                radioRx += mt.radioRx;

                duration += mt.duration;
              }

              if (col == COLUMN_MOTE) {
                return "AVERAGE";
              }
              if (col == COLUMN_RADIOON) {
                return String.format("%2.2f%%", 100.0 * radioOn / duration);
              }
              if (col == COLUMN_RADIOTX) {
                return String.format("%2.2f%%", 100.0 * radioTx / duration);
              }
              if (col == COLUMN_RADIORX) {
                return String.format("%2.2f%%", 100.0 * radioRx / duration);
              }
              return null;
            }

            MoteTracker rule = moteTrackers.get(rowIndex);
            if (col == COLUMN_MOTE) {
              return rule.mote.toString();
            }
            if (col == COLUMN_RADIOON) {
              return String.format("%2.2f%%", 100.0 * rule.getRadioOnRatio());
            }
            if (col == COLUMN_RADIOTX) {
              return String.format("%2.2f%%", 100.0 * rule.getRadioTxRatio());
            }
            if (col == COLUMN_RADIORX) {
              return String.format("%2.2f%%", 100.0 * rule.getRadioRxRatio());
            }
            return null;
          }
        };
    table =
        new JTable(model) {
          public String getToolTipText(MouseEvent e) {
            java.awt.Point p = e.getPoint();
            int rowIndex = table.rowAtPoint(p);
            if (rowIndex < 0 || rowIndex >= moteTrackers.size()) {
              return null;
            }
            MoteTracker mt = moteTrackers.get(rowIndex);
            return "<html><pre>" + mt.toString() + "</html>";
          }
        };
    table.setDefaultRenderer(
        Object.class,
        new DefaultTableCellRenderer() {
          public Component getTableCellRendererComponent(
              JTable table,
              Object value,
              boolean isSelected,
              boolean hasFocus,
              int row,
              int column) {
            Component c =
                super.getTableCellRendererComponent(
                    table, value, isSelected, hasFocus, row, column);
            if (row == tableMaxRadioOnIndex) {
              setBackground(isSelected ? table.getSelectionBackground() : Color.RED);
              setForeground(isSelected ? table.getSelectionForeground() : Color.WHITE);
            } else {
              setBackground(isSelected ? table.getSelectionBackground() : table.getBackground());
              setForeground(isSelected ? table.getSelectionForeground() : table.getForeground());
            }
            return c;
          }
        });

    Box control = Box.createHorizontalBox();
    control.add(Box.createHorizontalGlue());
    control.add(new JButton(printAction));
    control.add(new JButton(resetAction));

    this.getContentPane().add(BorderLayout.CENTER, new JScrollPane(table));
    this.getContentPane().add(BorderLayout.SOUTH, control);
    setSize(400, 400);

    repaintTimer.start();
  }
  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

  }
  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
  }