[Tinyos-beta-commits] CVS: tinyos-1.x/beta/TOSSIM-CC2420/PowerTOSSIM compile.pl, 1.1, 1.2 postprocess.py, 1.1, 1.2 telosA_energy_model.txt, 1.1, 1.2

Yang overbored at users.sourceforge.net
Mon May 16 00:01:00 PDT 2005


Update of /cvsroot/tinyos/tinyos-1.x/beta/TOSSIM-CC2420/PowerTOSSIM
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv668/PowerTOSSIM

Modified Files:
	compile.pl postprocess.py telosA_energy_model.txt 
Log Message:
Lots of bug fixes/minor enhancements; used in SP; basic power measurement.


Index: compile.pl
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/TOSSIM-CC2420/PowerTOSSIM/compile.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** compile.pl	13 Mar 2005 07:23:07 -0000	1.1
--- compile.pl	16 May 2005 07:00:51 -0000	1.2
***************
*** 29,33 ****
  
  if($make) {
!     system("make pc sim,telosA") && die "Can't compile base app for pc!\n";
  
      system("make telos") && die "Can't compile base app for telos!\n";
--- 29,33 ----
  
  if($make) {
!     system("make pc sim,telosa") && die "Can't compile base app for pc!\n";
  
      system("make telos") && die "Can't compile base app for telos!\n";

Index: postprocess.py
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/TOSSIM-CC2420/PowerTOSSIM/postprocess.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** postprocess.py	13 Mar 2005 07:23:07 -0000	1.1
--- postprocess.py	16 May 2005 07:00:52 -0000	1.2
***************
*** 7,10 ****
--- 7,12 ----
  from sys import argv
  import sys
+ import re
+ import shutil
  
  usage = """USAGE: postprocess.py [--help] [--debug] [--nosummary]
***************
*** 47,50 ****
--- 49,54 ----
  prev_time = []
  
+ prev_time_true = []
+ 
  maxmotes = 1000
  maxseen = 0
***************
*** 150,154 ****
      
  def initstate():
!     global state, total, voltage, prev_current, prev_time, data_file
      read_em()
      # initialize the various lists...
--- 154,158 ----
      
  def initstate():
!     global state, total, voltage, prev_current, prev_time, data_file, pushed, prev_time_true
      read_em()
      # initialize the various lists...
***************
*** 157,160 ****
--- 161,166 ----
      prev_current = [None] * maxmotes
      prev_time = [0] * maxmotes
+     pushed = [0] * maxmotes
+     prev_time_true = [0] * maxmotes
      data_file = [None] * maxmotes
      voltage = em['VOLTAGE']
***************
*** 162,166 ****
      for mote in range(maxmotes):
          # Init each mote with base values
!         state[mote] = {'radio':{'on':0, 'tx':0,
                                  'txpower':em['RADIO_DEFAULT_POWER']}, 
                         'cpu': 'IDLE',
--- 168,172 ----
      for mote in range(maxmotes):
          # Init each mote with base values
!         state[mote] = {'radio':{'on':0, 'tx':0, 'rx':0, 'oscon':0,
                                  'txpower':em['RADIO_DEFAULT_POWER']}, 
                         'cpu': 'IDLE',
***************
*** 210,227 ****
  
  def get_radio_current(mote):
! 	# Note that this sets the total power of the radio, so we have to include
! 	# numbers like RADIO_ON.
! 	#the state is:  {'on':ON/OFF,'tx': TX/RX,'txpower':PowerLevel}
! 	mystate = state[mote]['radio']
! 	power = 0
! 	if mystate['on']:
! 		power += em['RADIO_ON']
! 		if mystate['oscon']:
! 			power += em['RADIO_OSCON']
! 			if mystate['tx']:
! 				power += tx_current(mystate['txpower'])
! 			elif mystate['rx']:
! 				power += em['RADIO_RX']
! 	return power;
  
  def get_leds_current(mote):
--- 216,235 ----
  
  def get_radio_current(mote):
!     # Note that this sets the total power of the radio, so we have to include
!     # numbers like RADIO_ON.
!     #the state is:  {'on':ON/OFF,'tx': TX/RX,'txpower':PowerLevel}
!     mystate = state[mote]['radio']
!     if debug:
!         print 'get_radio_current():', mystate
!     power = 0
!     if mystate['on']:
!         power += em['RADIO_ON']
!         if mystate['oscon']:
!             power += em['RADIO_OSCON']
!             if mystate['tx']:
!                 power += tx_current(mystate['txpower'])
!             elif mystate['rx']:
!                 power += em['RADIO_RX']
!     return power;
  
  def get_leds_current(mote):
***************
*** 329,338 ****
          # Parameters are set to defaults when turning on
          oldstate['on'] = 1
! 		oldstate['oscon'] = 0
!         oldstate['tx'] = 0 # Defaults to RX mode
          oldstate['txpower'] = em['RADIO_DEFAULT_POWER']
      elif op == "OFF": 
          oldstate['on'] = 0
! 		oldstate['oscon'] = 0
      elif op == "SetRFPower":
          oldstate['txpower'] = int(newstate[2],16)  # must be a hex number
--- 337,349 ----
          # Parameters are set to defaults when turning on
          oldstate['on'] = 1
!         oldstate['oscon'] = 0
!         oldstate['tx'] = 0
!         oldstate['rx'] = 0
          oldstate['txpower'] = em['RADIO_DEFAULT_POWER']
      elif op == "OFF": 
          oldstate['on'] = 0
!         oldstate['oscon'] = 0
!         oldstate['tx'] = 0
!         oldstate['rx'] = 0
      elif op == "SetRFPower":
          oldstate['txpower'] = int(newstate[2],16)  # must be a hex number
***************
*** 343,355 ****
          # probably qualifies as a bug
          oldstate['on'] = 1 
! 		oldstate['oscon'] = 1
          oldstate['tx'] = 1
      elif op == "RX":
          oldstate['on'] = 1
! 		oldstate['oscon'] = 1
          oldstate['tx'] = 0
- 	elif op == "OSC_ON":
- 		oldstate['on'] = 1
- 		oldstate['oscon'] = 1
      else:
          quit(0,"Line %d: Syntax error: radio state %s unknown" % (lineno,op))
--- 354,370 ----
          # probably qualifies as a bug
          oldstate['on'] = 1 
!         oldstate['oscon'] = 1
          oldstate['tx'] = 1
+         oldstate['rx'] = 0
      elif op == "RX":
          oldstate['on'] = 1
!         oldstate['oscon'] = 1
!         oldstate['tx'] = 0
!         oldstate['rx'] = 1
!     elif op == "OSC_ON":
!         oldstate['on'] = 1
!         oldstate['oscon'] = 1
!         oldstate['rx'] = 0
          oldstate['tx'] = 0
      else:
          quit(0,"Line %d: Syntax error: radio state %s unknown" % (lineno,op))
***************
*** 422,425 ****
--- 437,447 ----
      return (float(t_to) - float(t_from))/em['CPU_FREQ']
  
+ # "Totals" are the total amount of energy consumed since the very start.
+ # energy = time * (power = current * voltage)
+ # There are "totals" for each component (CPU, radio, ...).
+ 
+ # prev_current is the current from prev_time up till time (the current time).
+ # There is a prev_current['total']
+ 
  # Updates every total for every timestep.  This is inefficient,
  # because if the radio is on for 100 events, there's no need to do 100
***************
*** 429,446 ****
      global total
      for m in range(maxseen+1):
!         for t in totals:
              td = time_diff(prev_time[m], time)
!             total[m][t] += td * prev_current[m][t] * voltage
  
  def update_currents(time):
!     global prev_time, prev_current
      for m in range(maxseen+1):
!         prev_time[m]=time
!         for t in totals:
!             prev_current[m][t] = current_fn_map[t](m)
  
  
  def dump_currents(mote,time):
!     global data_file, debug
      m=mote
      if not data_file[m]:
--- 451,481 ----
      global total
      for m in range(maxseen+1):
!         for t in totals: # for each str in ["cpu", "radio", ...]
              td = time_diff(prev_time[m], time)
!             if td > 0:
!                 total[m][t] += td * prev_current[m][t] * voltage
  
  def update_currents(time):
!     global prev_time, prev_current, pushed, prev_time_true
      for m in range(maxseen+1):
! #        pt = int(prev_time[m])
! #        pt = int(prev_time_true[m])
! #        t = int(time)
! #        if pt >= t:
! #            print 'pushing t =', t, 'to pt + 1 =', pt + 1
! #            t = pt + 1000000
! #            pushed[m] += 1000000 # + (pt - t)
! #        else:
! #            print 't = ', t, ', pt =', pt
! #            pushed[m] = 0
! #        time = t
!         prev_time[m] = int(time)
! #        prev_time_true[m] = t + 1000000
!         for total in totals:
!             prev_current[m][total] = current_fn_map[total](m)
  
  
  def dump_currents(mote,time):
!     global data_file, debug, prev_time_true
      m=mote
      if not data_file[m]:
***************
*** 458,477 ****
          # To make a square wave, print the previous currents up to "just
          # before now", then print the new currents
!         tm = float(time) / em['CPU_FREQ'] - 0.000001
!         data_file[m].write("%12f" % tm)
          for t in ['total'] + totals:
              c = float(prev_current[m][t])
!             data_file[m].write("%12f" % c)
          data_file[m].write("\n");
!         
!         tm = float(time)/em['CPU_FREQ']
          c = get_current(m)
          prev_current[m]['total'] = c
!         data_file[m].write("%12f%12f" % (tm,c))
          for t in totals:
              c = current_fn_map[t](m)
!             data_file[m].write("%12f" % c);
          data_file[m].write("\n");
  
  
  dbg_unknown_event_types = {}
--- 493,523 ----
          # To make a square wave, print the previous currents up to "just
          # before now", then print the new currents
!         tm = float(time) / em['CPU_FREQ']
!         ptm = prev_time_true[m]
!         #print "tm %f ptm %f" % (tm, ptm)
!         if ptm >= tm:
!             tm = ptm + 0.000001
!             #print "BUMPED tm %f ptm %f" % (tm, ptm)
! 
!         data_file[m].write("%15.9f" % tm)
          for t in ['total'] + totals:
              c = float(prev_current[m][t])
!             data_file[m].write("%15.9f" % c)
          data_file[m].write("\n");
! 
!         tm = tm + 0.000000001
!         ptm = tm + 0.000000001
          c = get_current(m)
+         # Note: we are updating the 'total' field!
          prev_current[m]['total'] = c
!         data_file[m].write("%15.9f%15.9f" % (tm,c))
          for t in totals:
              c = current_fn_map[t](m)
!             data_file[m].write("%15.9f" % c);
          data_file[m].write("\n");
  
+         data_file[m].flush()
+ 
+         prev_time_true[m] = ptm
  
  dbg_unknown_event_types = {}
***************
*** 485,488 ****
--- 531,535 ----
      global maxseen, detail
  
+ 
      if debug: print lineno, l
      event = l.split()
***************
*** 515,518 ****
--- 562,614 ----
  
  
+ # Post-process the detailed output file.
+ # Basically, clean up the dual-timestamped events.
+ # Currently, we only keep the last one; this may or may not be correct!
+ def cleanup_details():
+     global data_file, maxseen
+     for mote_id in range(0, maxseen + 1):
+         waiting_line = None
+         prev_time = -1
+         time = -2
+ 
+         data_file_name = basename + str(mote_id) + '.dat'
+         data_file[mote_id].close()
+         data_file[mote_id] = open(data_file_name, "r")
+ 
+         tmp_file_name = basename + str(mote_id) + '.tmp'
+         tmp_file = open(tmp_file_name, 'w')
+ 
+         lines = data_file[mote_id].readlines()
+         line_numbers = range(len(lines))
+         for line, line_number in zip(lines, line_numbers):
+             # special lines
+             if line.startswith('#'):
+                 tmp_file.write(line)
+                 tmp_file.write('0 0 0 0 0 0 0 0\n')
+                 continue
+ 
+             line = ' ' + line # pad it with a space
+             fields = re.split('\s+', line)
+             time = float(fields[1])
+             line = line[1:] # remove the space we added
+             if time == prev_time:
+                 waiting_line = line
+             elif time > prev_time:
+                 if waiting_line != None:
+                     tmp_file.write(waiting_line)
+                 waiting_line = line
+                 prev_time = time
+             # We should never be going back in time.
+             # This assumes we removed the step-function code in dump_currents().
+             else:
+                 assert time <= prev_time
+                 quit(error = "we went back/stood still in time! line %d: %f < %f" % (line_number, time, prev_time))
+ 
+         assert waiting_line != None
+ #        if waiting_line != None:
+ #            tmp_file.write(waiting_line)
+ 
+         tmp_file.close()
+         #shutil.move(tmp_file_name, data_file_name)
  
  ########################  "Main" code ###################
***************
*** 556,559 ****
--- 652,659 ----
          lineno += 1
          l = trace.readline()
+ #        print "> ",
+ #        sys.stdin.readline()
+ 
+     cleanup_details()
  
      if summary:

Index: telosA_energy_model.txt
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/TOSSIM-CC2420/PowerTOSSIM/telosA_energy_model.txt,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** telosA_energy_model.txt	13 Mar 2005 07:23:07 -0000	1.1
--- telosA_energy_model.txt	16 May 2005 07:00:52 -0000	1.2
***************
*** 60,65 ****
  #RADIO_TX_E0   0
  #RADIO_TX_FF	0
! RADIO_ON	0
! RADIO_OSCON	0
  
  # The default power mode (0x0F, but python doesn't like hex numbers in floats)
--- 60,65 ----
  #RADIO_TX_E0   0
  #RADIO_TX_FF	0
! RADIO_ON	1.0
! RADIO_OSCON	0.5
  
  # The default power mode (0x0F, but python doesn't like hex numbers in floats)



More information about the Tinyos-beta-commits mailing list