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

📄 powerprofileplugin.java

📁 无线通信的主要编程软件,是无线通信工作人员的必备工具,关天相关教程我会在后续传上.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
  	   s = new StringBuffer();  	     	   format.format(e_cpu[moteid], s, f);  	   table.setValueAt(s.toString(), moteid, COL_CPU);  	   s = new StringBuffer();  	   format.format(e_eeprom[moteid], s, f);  	   table.setValueAt(s.toString(), moteid, COL_EEPROM);  	   s = new StringBuffer();  	   format.format(e_led[moteid], s, f);  	   table.setValueAt(s.toString(), moteid, COL_LED);  	   s = new StringBuffer();  	   format.format(e_total[moteid], s, f);  	   table.setValueAt(s.toString(), moteid, COL_TOTAL);  	   /* taken out after we added number formatting above  	   table.setValueAt(String.valueOf(moteid), moteid, COL_MOTEID);  	   table.setValueAt(String.valueOf(e_radio[moteid]), moteid, COL_RADIO);  	   table.setValueAt(String.valueOf(e_cpu[moteid]), moteid, COL_CPU);  	   table.setValueAt(String.valueOf(e_led[moteid]), moteid, COL_LED);  	   //table.setValueAt(String.valueOf(e_adc[moteid]), moteid, COL_ADC);  	   table.setValueAt(String.valueOf(e_eeprom[moteid]), moteid, COL_EEPROM);  	   table.setValueAt(String.valueOf(e_total[moteid]), moteid, COL_TOTAL);  	   */  }  /* The main event-handling function. Every event handled by TinyViz   * will be delivered to each plugin through this method. There are   * a few types of events that can be received - see the 'event'    * subdirectory.    */  public void handleEvent(SimEvent event) {        String match;      int index_match, index_2;        if (event instanceof DebugMsgEvent) {         DebugMsgEvent dmEvent = (DebugMsgEvent)event;         Integer mote = new Integer(dmEvent.getMoteID());         //Integer time = new Integer();         String msg = dmEvent.getMessage();                  //Currently we only support up to MAX_MOTE moteid power profiling                  if(mote.intValue() < MAX_MOTE) {                      if(mote.intValue() > max_moteid_seen)               max_moteid_seen = mote.intValue();         	           //table.setValueAt(mote.toString(), mote.intValue(), COL_MOTEID);         //Check if it is a RADIO_STATE message         	   match = new String("POWER:");	   	   if ((index_match = msg.indexOf(match)) != -1) {             //get current time	     match = new String(" at");	     if ((index_match = msg.indexOf(match)) != -1) {               String strLen = msg.substring(index_match);               String strParsed[] = strLen.split(" ");               //table.setValueAt(strParsed[2], mote.intValue(), COL_TOTAL);               //set current time               current_time = Integer.valueOf(strParsed[2]).intValue();               update_table(mote.intValue());             }	 	             match = new String("RADIO_STATE");             if ((index_match = msg.indexOf(match)) != -1) {               String strLen = msg.substring(index_match);               String strParsed[] = strLen.split(" ");                              //find state               if((index_2 = strParsed[1].indexOf(new String("TX"))) != -1)  { next_radio = radio_tx; }               if((index_2 = strParsed[1].indexOf(new String("RX"))) != -1)  { next_radio = RADIO_RX; }               if((index_2 = strParsed[1].indexOf(new String("ON"))) != -1)  { next_radio = RADIO_RX; }               if((index_2 = strParsed[1].indexOf(new String("OFF"))) != -1)  { next_radio = RADIO_OFF; }               if((index_2 = strParsed[1].indexOf(new String("SetRFPower"))) != -1)  { radio_tx = RADIO_TX_0F; } //FIXME: implement SetRFPower               update_table(mote.intValue());             }                          match = new String("CPU_STATE");             if ((index_match = msg.indexOf(match)) != -1) {               String strLen = msg.substring(index_match);               String strParsed[] = strLen.split(" ");               //table.setValueAt(strParsed[1], mote.intValue(), COL_CPU);               //find state               if((index_2 = strParsed[1].indexOf(new String("IDLE"))) != -1)  { next_cpu = CPU_IDLE; }               if((index_2 = strParsed[1].indexOf(new String("ADC_NOISE_REDUCTION"))) != -1)  { next_cpu = CPU_ADC_NOISE_REDUCTION; }               if((index_2 = strParsed[1].indexOf(new String("POWER_DOWN"))) != -1)  { next_cpu = CPU_POWER_DOWN; }               if((index_2 = strParsed[1].indexOf(new String("POWER_SAVE"))) != -1)  { next_cpu = CPU_POWER_SAVE; }               if((index_2 = strParsed[1].indexOf(new String("STANDBY"))) != -1)  { next_cpu = CPU_STANDBY; }               if((index_2 = strParsed[1].indexOf(new String("EXTENDED_STANDBY"))) != -1)  { next_cpu = CPU_EXTENDED_STANDBY; }               update_table(mote.intValue());             }             match = new String("LED_STATE");             if ((index_match = msg.indexOf(match)) != -1) {               String strLen = msg.substring(index_match);               String strParsed[] = strLen.split(" ");               //find state               if((index_2 = strParsed[1].indexOf(new String("RED_ON"))) != -1)  { next_led_r = LED; }               if((index_2 = strParsed[1].indexOf(new String("RED_OFF"))) != -1)  { next_led_r = LED_INIT; }               if((index_2 = strParsed[1].indexOf(new String("GREEN_ON"))) != -1)  { next_led_g = LED; }               if((index_2 = strParsed[1].indexOf(new String("GREEN_OFF"))) != -1)  { next_led_g = LED_INIT; }               if((index_2 = strParsed[1].indexOf(new String("YELLOW_ON"))) != -1)  { next_led_y = LED; }               if((index_2 = strParsed[1].indexOf(new String("YELLOW_OFF"))) != -1)  { next_led_y = LED_INIT; }               //table.setValueAt(strParsed[1], mote.intValue(), COL_LED);               update_table(mote.intValue());             }             match = new String("ADC");             if ((index_match = msg.indexOf(match)) != -1) {               String strLen = msg.substring(index_match);               String strParsed[] = strLen.split(" ");               //find state               if((index_2 = strParsed[1].indexOf(new String("SAMPLE"))) != -1)  { next_adc = ADC; }               if((index_2 = strParsed[1].indexOf(new String("DATA_READY"))) != -1)  { next_adc = ADC_INIT; }               //table.setValueAt(strParsed[1], mote.intValue(), COL_ADC);               //table.setValueAt(String.valueOf(current_adc[mote.intValue()]), mote.intValue(), COL_TOTAL);               update_table(mote.intValue());             }             match = new String("EEPROM");             if ((index_match = msg.indexOf(match)) != -1) {               String strLen = msg.substring(index_match);               String strParsed[] = strLen.split(" ");               //find state               if((index_2 = strParsed[2].indexOf(new String("START"))) != -1) {                  if((index_2 = strParsed[1].indexOf(new String("WRITE"))) != -1)  { next_eeprom = EEPROM_WRITE; }                  if((index_2 = strParsed[1].indexOf(new String("READ"))) != -1)  { next_eeprom = EEPROM_READ; }               }                                 if((index_2 = strParsed[2].indexOf(new String("STOP"))) != -1)  { next_eeprom = EEPROM_INIT; }               //table.setValueAt(strParsed[1]+strParsed[2], mote.intValue(), COL_EEPROM);               update_table(mote.intValue());             }                        }         }     }     motePanel.refresh();  }  /* This method is called when a plugin is "registered", ie., enabled   * by the user from the plugins menu. Here we create the widgets to appear    * in the plugin control panel.   */  public void register() {       String columnNames[] = { "moteid", "radio", "cpu", "led", "eeprom", "total"};    tableData = new String[MAX_MOTE][6];    table = new JTable(tableData, columnNames);    scrollpane = new JScrollPane(table);    pluginPanel.add(scrollpane);  }  /* This method is called when a plugin is disabled by the user - here   * we do nothing.   */  public void deregister() {}  /* This method is called when the simulation state is reset, which    * may happen when the simulation stops running, or in between    * simulations when using AutoRun files. Here we want to clear out our   * internal state.   */  public void reset() {    motePanel.refresh();  }//modified from ADCPlugin.java  /* Called when it's time to redraw the mote panel. Here we just redraw   * the arrows representing radio links.   */  public void draw(Graphics graphics) {        //these values are just for fancy coloring of mote energy numbers    //in motepanel    double TOTAL_BATTERY_ENERGY = 200; //assume each mote has such amount of battery energy    double LEVEL_3 = 0.5 * TOTAL_BATTERY_ENERGY;  // anything above it is good, green    double LEVEL_2 = 0.2 * TOTAL_BATTERY_ENERGY;  //     double LEVEL_1 = 0.05 * TOTAL_BATTERY_ENERGY; // critical    double LEVEL_0 = 0.01 * TOTAL_BATTERY_ENERGY; // mote with lower than this energy is dead        double e_remaining;    String strEnergy;  	    Iterator it = state.getMoteSimObjects().iterator();    graphics.setFont(tv.smallFont);    graphics.setColor(Color.green);    while (it.hasNext()) {      MoteSimObject mote = (MoteSimObject)it.next();      if (!mote.isVisible()) {	continue;      }            e_remaining = TOTAL_BATTERY_ENERGY - e_total[mote.getID()];                //set the color according to energy spent        if(e_remaining < LEVEL_0) {graphics.setColor(Color.black);}  //should turn off mote here, future work :)        else if(e_remaining < LEVEL_1) {graphics.setColor(Color.red);}        else if(e_remaining < LEVEL_2) {graphics.setColor(Color.orange);}        else if(e_remaining < LEVEL_3) {graphics.setColor(Color.blue);}        else {graphics.setColor(Color.green);}        //                DecimalFormat eFormat = new DecimalFormat("###.##");        strEnergy = new String("E:" + eFormat.format(e_total[mote.getID()]));      	CoordinateAttribute coordinate = mote.getCoordinate();	int x = (int)cT.simXToGUIX(coordinate.getX());       	int y = (int)cT.simYToGUIY(coordinate.getY());	graphics.drawString(strEnergy, x+10, y);      }   }    /* The toString() method is important - it gives the plugin a name in   * the plugins menu and panel. Use a *short* but descriptive name here.   */  public String toString() {    return "Power Profiling";  }}

⌨️ 快捷键说明

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