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

📄 simdriver.java

📁 无线通信的主要编程软件,是无线通信工作人员的必备工具,关天相关教程我会在后续传上.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    /*     * If the scriptPath wasn't specified, cons up a relatively useful     * default and add on the builtin scripts and libraries.     */    if (scriptPath == null) {      scriptPath = ".";    }    String pathsep = System.getProperty("path.separator");    if (pathsep == null) pathsep = ":";        String filesep = System.getProperty("file.separator");    if (filesep == null) filesep = "/'";        /*     * Ugh -- go through pains to make sure this doesn't crash if it     * can't find the directory. But if it can, try to add on the     * pyscripts directory and the     */    URL builtinURL = getClass().getResource("pyscripts");    if (builtinURL != null && builtinURL.getProtocol().equals("file")) {      String builtinPath = builtinURL.getPath();      String libPath = builtinPath + filesep + "Lib.jar";      scriptPath += pathsep + builtinPath + pathsep + libPath;    }    /*     * Always run the event bus.     */    simEventBus.start();        /*     * Try to connect to the simulator     */    simComm.start();    if (gui) {      tv.refreshPauseState();    }    /*     * If there's a script, implicitly tack its directory onto the     * scriptPath and create an interpreter for it.     */    if (script != null) {      System.out.println("DRIVER: creating interpreter for script: "                         + script + "...");            int lastSlash = script.lastIndexOf(filesep);      if (lastSlash != -1) {        String scriptDir = script.substring(0, lastSlash);        scriptPath = scriptPath + pathsep + scriptDir;      }            interp = new ScriptInterpreter(this, script);    }    /*     * Create a console and/or a listen socket for interactive script     * sessions.     */    if (console || listen_port > 0) {      interactor = new ScriptInteractor(this);      if (listen_port > 0) {        interactor.startListenSocket(listen_port);      }      if (console) {        interactor.startConsole(System.in, System.out);      }    }    /*     * Finally, run the simulator if we're using -run.     */    if (autoRun != null) {      if (! simComm.isStopped()) {        System.err.println("DRIVER: Can't use AutoRun when SimComm already connected");        System.err.println("(check for stale main.exe processes)");        System.exit(1);      }      autoRun.run();      exit(0);    }  }  public final AutoRun getAutoRun() {    return autoRun;  }    public final SimComm getSimComm() {    return simComm;  }  public final SimCommands getSimCommands() {    return simCommands;  }  public final SimRandom getSimRandom() {    return simRandom;  }  public final SimExec getSimExec() {    return simExec;  }  public final SimState getSimState() {    return simState;  }  public final SimEventBus getEventBus() {    return simEventBus;  }  public final MoteVariables getVariables() {    return moteVariables;  }  public final PluginManager getPluginManager() {    return pluginManager;  }  public final RadioModelPlugin getRadioModel() {    return radioModel;  }  public final MoteLayoutPlugin getMoteLayout() {    return moteLayout;  }  public final PacketLoggerPlugin getPacketLogger() {    return packets;  }  public final String getScriptPath() {    return scriptPath;  }    public final String getScriptArgs() {    return scriptArgs;  }  public final long getTossimTime() {    return tossimTime;  }    public final synchronized void pause() {    pauseCount++;    debug.err.println("PAUSE: "+pauseCount);    if (pauseCount == 1) {      simComm.pause();      refreshPauseState();      this.notifyAll();    }  }  public final synchronized void resume() {    pauseCount--;    debug.err.println("RESUME: "+pauseCount);    if (pauseCount <= 0) {      pauseCount = 0;      simComm.resume();      refreshPauseState();      this.notifyAll();    }  }  public synchronized void reset() {    simComm.stop();    refreshPauseState();    simEventBus.pause();    simEventBus.clear();    simState.removeAllObjects();    refreshAndWait();    pluginManager.reset();    simComm.start();    refreshPauseState();    simEventBus.resume();    this.notifyAll();  }  public synchronized void stop() {    if (autoRun != null) autoRun.stop();    if (simExec != null) simExec.stop();  }  public final synchronized boolean isPaused() {    return simComm.isPaused();  }    public final void setSimDelay(long delay_ms) {    simComm.setSimDelay(delay_ms);  }  public final void connect() {    while (simComm.isStopped() && simExec.processRunning()) {      try {        if (simComm.isStopped()) simComm.start();        simComm.waitUntilInit();        Thread.currentThread().sleep(500);      } catch (InterruptedException ie) {        continue;      }    }  }  public final void exit(int errcode) {    System.err.println("Goodbye!");    if (simComm != null) simComm.stop();    if (autoRun != null) autoRun.stop();    if (simExec != null) simExec.stop();    System.exit(errcode);  }  public final String getOption(String optionName) {    return (String)options.get(optionName);  }    public final void setOption(String optionName, String optionVal) {    options.put(optionName, optionVal);    if (simEventBus != null)       simEventBus.addEvent(        new net.tinyos.sim.event.OptionSetEvent(optionName, optionVal));  }  public final Enumeration getOptions() {    return options.keys();  }  // Callbacks to update to status changes  public void refreshAndWait() {    if (tv != null) tv.refreshAndWait();  }      public void refreshPauseState() {    if (tv != null) tv.refreshPauseState();  }    public void setStatus(String s) {    if (tv != null) tv.setStatus(s);    else System.out.println("status: "+s);  }    public void refreshPluginRegistrations() {    if (tv != null) tv.refreshPluginRegistrations();  }  public void refreshMotePanel() {    if (tv != null) tv.getMotePanel().refresh();  }    public static void main(String[] args) throws IOException {    System.err.println("Starting SimDriver... ");    new SimDriver(args);  }  class EchoDebugPlugin extends Plugin {    public void handleEvent(SimEvent event) {      if (event instanceof DebugMsgEvent) {        System.out.println(((DebugMsgEvent)event).getMessage());      }    }  }  class TimeUpdatePlugin extends Plugin {    public void handleEvent(SimEvent event) {      if (event instanceof TossimEvent) {        TossimEvent te = (TossimEvent)event;        tossimTime = te.getTime();                if (tv != null) {          String time= Double.toString(Math.round(tossimTime/4000.0)/1000.0);          if(time.length()<2) time=time.concat(".");          while (time.length()-time.indexOf(".")<4) time=time.concat("0");          tv.timeUpdate(time);        }      }    };  }}

⌨️ 快捷键说明

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