⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 contikimotetypedialog.java

📁 传感器网络操作系统contiki。 被广泛应用于环境检测、结构健康监测等等。包括路由协议
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
      mapFile.delete();    }    compilationThread = new Thread(new Runnable() {      public void run() {        // Add all project directories        compilationFiles = (Vector<File>) myGUI            .getProjectDirs().clone();        compilationFiles.addAll(moteTypeProjectDirs);        // Add source files from project configs        String[] projectSourceFiles = newMoteTypeConfig.getStringArrayValue(            ContikiMoteType.class, "C_SOURCES");        for (String projectSourceFile : projectSourceFiles) {          if (!projectSourceFile.equals("")) {            File file = new File(projectSourceFile);            if (file.getParent() != null) {              // Find which project directory added this file              File projectDir = newMoteTypeConfig.getUserProjectDefining(                  ContikiMoteType.class, "C_SOURCES", projectSourceFile);              if (projectDir != null) {                // We found a project directory; add it to path                compilationFiles.add(new File(projectDir.getPath(), file                    .getParent()));              }            }            compilationFiles.add(new File(file.getName()));          }        }        // Add selected process source files        for (Component checkBox : processPanel.getComponents()) {          if (((JCheckBox) checkBox).isSelected()) {            String processName = ((JCheckBox) checkBox).getToolTipText();            if (processName != null) {              compilationFiles.add(new File(processName));            }          }        }        compilationSucceded = ContikiMoteTypeDialog.compileLibrary(identifier,            contikiDir, compilationFiles, symbolsCheckBox.isSelected(),            (ContikiMoteType.CommunicationStack) commStackComboBox.getSelectedItem(),            taskOutput.getInputStream(MessageList.NORMAL),            taskOutput.getInputStream(MessageList.ERROR));      }    }, "compilation thread");    compilationThread.start();    while (compilationThread.isAlive()) {      try {        Thread.sleep(100);      } catch (InterruptedException e) {        // NOP      }    }    if (!compilationSucceded) {      if (libFile.exists()) {        libFile.delete();      }      if (depFile.exists()) {        depFile.delete();      }      if (mapFile.exists()) {        mapFile.delete();      }      libraryCreatedOK = false;    } else {      libraryCreatedOK = true;      if (!libFile.exists() || !depFile.exists()) {        /* TODO Check if map file is really needed */        logger.fatal("Not all needed files could be located");        libraryCreatedOK = false;      }    }    if (libraryCreatedOK) {      progressBar.setBackground(Color.GREEN);      progressBar.setString("compilation succeded");      button.grabFocus();      myDialog.getRootPane().setDefaultButton(createButton);    } else {      progressBar.setBackground(Color.ORANGE);      progressBar.setString("compilation failed");      myDialog.getRootPane().setDefaultButton(testButton);    }    progressBar.setIndeterminate(false);    progressBar.setValue(0);    createButton.setEnabled(libraryCreatedOK);  }  /**   * Generates new source file by reading default source template and replacing   * fields with sensors, core interfaces and processes. Also includes default   * processes from GUI external configuration.   *   * @param id   *          Mote type ID (decides name of new source file)   * @param sensors   *          Names of sensors   * @param coreInterfaces   *          Names of core interfaces   * @param userProcesses   *          Names of user processes   * @return New filename   * @throws Exception   *           If any error occurs   */  public static String generateSourceFile(String id, Vector<String> sensors,      Vector<String> coreInterfaces, Vector<String> userProcesses)      throws Exception {    // SENSORS    String sensorString = "";    String externSensorDefs = "";    for (String sensor : sensors) {      if (!sensorString.equals("")) {        sensorString += ", ";      }      sensorString += "&" + sensor;      externSensorDefs += "extern const struct sensors_sensor " + sensor          + ";\n";    }    if (!sensorString.equals("")) {      sensorString = "SENSORS(" + sensorString + ");";    } else {      sensorString = "SENSORS(NULL);";    }    // CORE INTERFACES    String interfaceString = "";    String externInterfaceDefs = "";    for (String coreInterface : coreInterfaces) {      if (!interfaceString.equals("")) {        interfaceString += ", ";      }      interfaceString += "&" + coreInterface;      externInterfaceDefs += "SIM_INTERFACE_NAME(" + coreInterface + ");\n";    }    if (!interfaceString.equals("")) {      interfaceString = "SIM_INTERFACES(" + interfaceString + ");";    } else {      interfaceString = "SIM_INTERFACES(NULL);";    }    // PROCESSES (including any default processes)    String userProcessString = "";    String externProcessDefs = "";    for (String process : userProcesses) {      if (!userProcessString.equals("")) {        userProcessString += ", ";      }      userProcessString += "&" + process;      externProcessDefs += "PROCESS_NAME(" + process + ");\n";    }    String defaultProcessString = "";    String defaultProcesses[] = GUI.getExternalToolsSetting(        "CONTIKI_STANDARD_PROCESSES").split(";");    for (String process : defaultProcesses) {      if (!defaultProcessString.equals("")) {        defaultProcessString += ", ";      }      defaultProcessString += "&" + process;    }    if (userProcessString.equals("")) {      logger          .warn("No application processes specified! Sure you don't want any?");    }    String processString;    if (!defaultProcessString.equals("")) {      processString = "PROCINIT(" + defaultProcessString + ");";    } else {      processString = "PROCINIT(NULL);";    }    if (!userProcessString.equals("")) {      processString += "\nAUTOSTART_PROCESSES(" + userProcessString + ");";    } else {      processString += "\nAUTOSTART_PROCESSES(NULL);";    }    // CHECK JNI CLASS AVAILABILITY    String libString = CoreComm.getAvailableClassName();    if (libString == null) {      logger.fatal("No more libraries can be loaded!");      throw new MoteTypeCreationException("Maximum number of mote types already exist");    }    // GENERATE NEW FILE    BufferedWriter destFile = null;    BufferedReader sourceFile = null;    String destFilename = null;    try {      Reader reader;      String mainTemplate = GUI          .getExternalToolsSetting("CONTIKI_MAIN_TEMPLATE_FILENAME");      if ((new File(mainTemplate)).exists()) {        reader = new FileReader(mainTemplate);      } else {        InputStream input = ContikiMoteTypeDialog.class            .getResourceAsStream('/' + mainTemplate);        if (input == null) {          throw new FileNotFoundException(mainTemplate + " not found");        }        reader = new InputStreamReader(input);      }      sourceFile = new BufferedReader(reader);      destFilename = ContikiMoteType.tempOutputDirectory.getPath()          + File.separatorChar + id + ".c";      destFile = new BufferedWriter(new OutputStreamWriter(          new FileOutputStream(destFilename)));      // Replace special fields in template      String line;      while ((line = sourceFile.readLine()) != null) {        line = line            .replaceFirst("\\[PROCESS_DEFINITIONS\\]", externProcessDefs);        line = line.replaceFirst("\\[PROCESS_ARRAY\\]", processString);        line = line.replaceFirst("\\[SENSOR_DEFINITIONS\\]", externSensorDefs);        line = line.replaceFirst("\\[SENSOR_ARRAY\\]", sensorString);        line = line.replaceFirst("\\[INTERFACE_DEFINITIONS\\]",            externInterfaceDefs);        line = line.replaceFirst("\\[INTERFACE_ARRAY\\]", interfaceString);        line = line.replaceFirst("\\[CLASS_NAME\\]", libString);        destFile.write(line + "\n");      }      destFile.close();      sourceFile.close();    } catch (Exception e) {      try {        if (destFile != null) {          destFile.close();        }        if (sourceFile != null) {          sourceFile.close();        }      } catch (Exception e2) {      }      // Forward exception      throw e;    }    return destFilename;  }  /**   * Compiles a mote type shared library using the standard Contiki makefile.   *   * @param identifier   *          Mote type identifier   * @param contikiDir   *          Contiki base directory   * @param sourceFiles   *          Source files and directories to include in compilation   * @param includeSymbols   *          Generate and include symbols in library file   * @param outputStream   *          Output stream from compilation (optional)   * @param errorStream   *          Error stream from compilation (optional)   * @return True if compilation succeded, false otherwise   */  public static boolean compileLibrary(String identifier, File contikiDir,      Vector<File> sourceFiles, boolean includeSymbols,      ContikiMoteType.CommunicationStack commStack,      final PrintStream outputStream, final PrintStream errorStream) {    File libFile = new File(ContikiMoteType.tempOutputDirectory,        identifier + ContikiMoteType.librarySuffix);    File mapFile = new File(ContikiMoteType.tempOutputDirectory,        identifier + ContikiMoteType.mapSuffix);    File arFile = new File(ContikiMoteType.tempOutputDirectory,        identifier + ContikiMoteType.dependSuffix);    // Recheck that contiki path exists    if (!contikiDir.exists()) {      if (errorStream != null) {        errorStream.println("Bad Contiki OS path");      }      logger.fatal("Contiki path does not exist: " + contikiDir.getAbsolutePath());      return false;    }    if (!contikiDir.isDirectory()) {      if (errorStream != null) {        errorStream.println("Bad Contiki OS path");      }      logger.fatal("Contiki path is not a directory");      return false;    }    if (libFile.exists()) {      if (errorStream != null) {        errorStream.println("Bad output filenames");      }      logger.fatal("Could not overwrite already existing library");      return false;    }    if (CoreComm.hasLibraryFileBeenLoaded(libFile)) {      if (errorStream != null) {        errorStream.println("Bad output filenames");      }      logger.fatal("A library has already been loaded with the same name before");      return false;    }    if (arFile.exists()) {      if (errorStream != null) {        errorStream.println("Bad output filenames");      }      logger.fatal("Could not overwrite already existing dependency file");      return false;    }    if (mapFile.exists()) {      if (errorStream != null) {        errorStream.println("Bad output filenames");      }      logger.fatal("Could not overwrite already existing map file");      return false;    }    try {      // Let Contiki 2.x regular make file compile      String[] cmd = new String[]{          GUI.getExternalToolsSetting("PATH_MAKE"),          libFile.getPath().replace(File.separatorChar, '/'),          "-f",          contikiDir.getPath().replace(File.separatorChar, '/')              + "/Makefile.include"};      String sourceDirs = System.getProperty("PROJECTDIRS", "");      String sourceFileNames = "";      // Prepare compilation command      String ccFlags = GUI.getExternalToolsSetting("COMPILER_ARGS", "");      String link1 = GUI.getExternalToolsSetting("LINK_COMMAND_1", "");      String link2 = GUI.getExternalToolsSetting("LINK_COMMAND_2", "");      String ar1 = GUI.getExternalToolsSetting("AR_COMMAND_1", "");      String ar2 = GUI.getExternalToolsSetting("AR_COMMAND_2", "");      link1 = link1.replace("$(MAPFILE)", mapFile.getPath().replace(File.separatorChar, '/'));      link2 = link2.replace("$(MAPFILE)", mapFile.getPath().replace(File.separatorChar, '/'));      ar1 = ar1.replace("$(MAPFILE)", mapFile.getPath().replace(File.separatorChar, '/'));      ar2 = ar2.replace("$(MAPFILE)", mapFile.getPath().replace(File.separatorChar, '/'));      ccFlags = ccFlags.replace("$(MAPFILE)", mapFile.getPath().replace(File.separatorChar, '/'));      link1 = link1.replace("$(LIBFILE)", libFile.getPath().replace(File.separatorChar, '/'));      link2 = link2.replace("$(LIBFILE)", libFile.getPath().replace(File.separatorChar, '/'));      ar1 = ar1.replace("$(LIBFILE)", libFile.getPath().replace(File.separatorChar, '/'));      ar2 = ar2.replace("$(LIBFILE)", libFile.getPath().replace(File.separatorChar, '/'));      ccFlags = ccFlags.replace("$(LIBFILE)", libFile.getPath().replace(File.separatorChar, '/'));      link1 = link1.replace("$(ARFILE)", arFile.getPath().replace(File.separatorChar, '/'));      link2 = link2.replace("$(ARFILE)", arFile.getPath().replace(File.separatorChar, '/'));      ar1 = ar1.replace("$(ARFILE)", arFile.getPath().replace(File.separatorChar, '/'));      ar2 = ar2.replace("$(ARFILE)", arFile.getPath().replace(File.separatorChar, '/'));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -