📄 powerprofileplugin.java
字号:
/* * For PowerTOSSIM project, Harvard University * Authors: Bor-rong Chen * Date: Mar 23 2004 * Desc: Power Profiling Plugin for PowerTOSSIM * *//** * @author Bor-rong Chen *///TODO: the simulation time shown on the top bar is actually wrong after//we switched to 7.37Mhz clock, fix this?package net.tinyos.sim.plugins;import java.util.*;import java.text.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;import net.tinyos.message.*;import net.tinyos.sim.*;import net.tinyos.sim.event.*;/* All plugins must extend the 'Plugin' class. 'SimConst' provides * some useful constants. */public class PowerProfilePlugin extends GuiPlugin implements SimConst {/* * power states to track: * * ADC: * LED: * RADIO_STATE: TX, RX, ON, OFF, SetRFPower FF * CPU_STATE: IDLE, ADC_NOISE_REDUCTION, POWER_DOWN, POWER_SAVE, RESERVED, STANDBY, EXTENDED_STANDBY * EEPROM: */ JTable table; JScrollPane scrollpane; String[][] tableData; // Begin Energy Model final double VOLTAGE= 3.0; // CPU numbers: // Idle mode is what the CPU is in when not actively executing, but // no special action is taken. The per-active-cycle numbers are added // on top of that final double CPU_ACTIVE= 8.0; //final double CPU_IDLE= 3.2; final double CPU_IDLE= 4.13; final double CPU_ADC_NOISE_REDUCTION= 1.0; final double CPU_POWER_DOWN= 0.103; final double CPU_POWER_SAVE= 0.110; final double CPU_STANDBY= 0.216; final double CPU_EXTENDED_STANDBY= 0.223; // The startup mode for the cpu final double CPU_INIT= 3.2; final double CPU_FREQ= 7370000; // Radio numbers final double RADIO_RX= 7.96; final double RADIO_TX_00= 4.65; final double RADIO_TX_01= 6.14; final double RADIO_TX_03= 6.3; final double RADIO_TX_06= 7.4; final double RADIO_TX_09= 7.98; final double RADIO_TX_0F= 9.4; final double RADIO_TX_60= 12.5; final double RADIO_TX_80= 14.7; final double RADIO_TX_C0= 18.3; final double RADIO_TX_FF= 22.41; final double RADIO_OFF= 0; // The default power mode final double RADIO_DEFAULT_POWER= 0x0F; // LED final double LED= 2.2; final double LED_INIT= 0; // EEPROM - FIXME final double EEPROM_READ= 6.241; final double EEPROM_WRITE= 18.401; final double EEPROM_INIT= 0; //ADC final double ADC= 0.9; final double ADC_INIT= 0; // If the sensor board is plugged in, it draws this much current at all times //final double SENSOR_BOARD= 1.6; final double SENSOR_BOARD= 0.69; // Sensors final double SENSOR_PHOTO= 0; //FIXME....... final double SENSOR_TEMP= 0; //end Energy Model //max number of motes allowed final int MAX_MOTE = 1000; //column assignment for different component final int COL_MOTEID = 0; final int COL_RADIO = 1; final int COL_CPU = 2; final int COL_LED = 3; //final int COL_ADC = 4; final int COL_EEPROM = 4; final int COL_TOTAL = 5; //this tells us how many nodes in the simulation int max_moteid_seen = 0; double e_radio[] = new double[MAX_MOTE]; double e_cpu[] = new double[MAX_MOTE]; double e_led[] = new double[MAX_MOTE]; double e_adc[] = new double[MAX_MOTE]; double e_eeprom[] = new double[MAX_MOTE]; double e_total[] = new double[MAX_MOTE]; double radio_tx = RADIO_TX_0F; //default radio tx power level //current draw for each component at certain state double current_radio[] = new double[MAX_MOTE]; double current_cpu[] = new double[MAX_MOTE]; double current_led_r[] = new double[MAX_MOTE]; double current_led_g[] = new double[MAX_MOTE]; double current_led_y[] = new double[MAX_MOTE]; double current_adc[] = new double[MAX_MOTE]; double current_eeprom[] = new double[MAX_MOTE]; final double INVALID_POWER = -1.0; //variables for setting next state //must set back to INVALID_POWER after state switching is done double next_radio = INVALID_POWER; double next_cpu = INVALID_POWER; double next_led_r = INVALID_POWER; double next_led_g = INVALID_POWER; double next_led_y = INVALID_POWER; double next_adc = INVALID_POWER; double next_eeprom = INVALID_POWER; //last time update this mote int last_time[] = new int[MAX_MOTE]; int current_time; private void update_table(int moteid) { int duration; //for the first time if(last_time[moteid]==0) { last_time[moteid] = current_time; //set the default states here current_radio[moteid] = RADIO_OFF; current_cpu[moteid] = CPU_INIT; current_led_r[moteid] = LED_INIT; current_led_g[moteid] = LED_INIT; current_led_y[moteid] = LED_INIT; current_adc[moteid] = ADC_INIT; current_eeprom[moteid] = EEPROM_INIT; //end default states return; } duration = current_time - last_time[moteid]; e_radio[moteid] += current_radio[moteid] * VOLTAGE * duration / CPU_FREQ; e_cpu[moteid] += current_cpu[moteid] * VOLTAGE * duration / CPU_FREQ; e_led[moteid] += current_led_r[moteid] * VOLTAGE * duration / CPU_FREQ; e_led[moteid] += current_led_g[moteid] * VOLTAGE * duration / CPU_FREQ; e_led[moteid] += current_led_y[moteid] * VOLTAGE * duration / CPU_FREQ; //e_adc[moteid] += current_adc[moteid] * VOLTAGE * duration / CPU_FREQ; e_eeprom[moteid] += current_eeprom[moteid] * VOLTAGE * duration / CPU_FREQ; //e_total[moteid] = e_radio[moteid] + e_cpu[moteid] + e_led[moteid] + e_adc[moteid] + e_eeprom[moteid]; e_total[moteid] = e_radio[moteid] + e_cpu[moteid] + e_led[moteid] + e_eeprom[moteid]; //change update time last_time[moteid] = current_time; //switching states if(next_radio != INVALID_POWER) { current_radio[moteid] = next_radio; next_radio = INVALID_POWER; } if(next_cpu != INVALID_POWER) { current_radio[moteid] = next_cpu; next_cpu = INVALID_POWER; } if(next_led_r != INVALID_POWER) { current_led_r[moteid] = next_led_r; next_led_r = INVALID_POWER; } if(next_led_g != INVALID_POWER) { current_led_g[moteid] = next_led_g; next_led_g = INVALID_POWER; } if(next_led_y != INVALID_POWER) { current_led_y[moteid] = next_led_y; next_led_y = INVALID_POWER; } if(next_adc != INVALID_POWER) { current_adc[moteid] = next_adc; next_adc = INVALID_POWER; } if(next_eeprom != INVALID_POWER) { current_eeprom[moteid] = next_eeprom; next_eeprom = INVALID_POWER; } //update the energy number DecimalFormat format = new DecimalFormat("0.00"); FieldPosition f = new FieldPosition(0); StringBuffer s; s = new StringBuffer(); table.setValueAt(String.valueOf(moteid), moteid, COL_MOTEID); format.format(e_radio[moteid], s, f); table.setValueAt(s.toString(), moteid, COL_RADIO);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -