You could probably do something like that...
But why?
+ Being able to update one application independent of the other
- You would need to make some creative changes in Deluge (normally a tool on 
workstation decides when to switch)
- Every time you switch application it would require a rewrite of CPU program 
flash and a restart
  (there is often a limited number of rewrites specified for each chip - OK for 
manual use, but this kind...)

With the attached patch for Oscilloscope it can measure several channels 
(interleaved in message).
It will also give you an Idea about how to rewrite the application.
And as a bonus it supports Deluge too...
[I am not sure that this is the latest version, but it should be close...]

/RogerL

--
Roger Larsson, Research Engineer
Division of Mobile Networking and Computing
Luleå University of Technology
SE-931 87 Skellefteå
________________________________________
Från: tinyos-help-boun...@millennium.berkeley.edu 
[tinyos-help-boun...@millennium.berkeley.edu] för Puya Ghazizadeh 
[ghp...@gmail.com]
Skickat: den 1 december 2010 16:55
Till: tinyos-help@millennium.berkeley.edu
Ämne: [Tinyos-help] Using deluge for oscilloscope

Hi,

I am using iris mote with mts300 sensor in ubuntu 10.04. I want to use the 
Deluge for running two version of Oscilloscope. First detecting Accelerometer 
then change it to the Temperature sensing (automatically by defining threshold 
for accelerometer) .
Should I inject both Oscilloscope image and Sense image to Basestation?

Thanks

Puya
Index: Oscilloscope/OscilloscopeC.nc
===================================================================
--- Oscilloscope/OscilloscopeC.nc	(revision 5187)
+++ Oscilloscope/OscilloscopeC.nc	(working copy)
@@ -12,30 +12,42 @@
  * Oscilloscope demo application. See README.txt file in this directory.
  *
  * @author David Gay
+ * @author Roger Larsson, ltu.se
  */
 #include "Timer.h"
 #include "Oscilloscope.h"
 
+#ifdef WITH_DIGITAL_ACCEL
+#include "ADXL345.h"
+#endif
+
 module OscilloscopeC @safe()
 {
   uses {
     interface Boot;
-    interface SplitControl as RadioControl;
+    interface SplitControl as CommunicationControl;
     interface AMSend;
     interface Receive;
     interface Timer<TMilli>;
-    interface Read<uint16_t>;
+    interface Read<uint16_t> as ChannelRead[uint8_t];
     interface Leds;
+    interface GeneralIO as AnalogAccelEnable;
+    interface SplitControl as DigitalAccelControl;
+    interface ADXL345Control as DigitalAccelConfig;
+    interface StdControl as MultiMeterControl;
+    interface HplDS2782  as MultiMeterConfig;
   }
 }
 implementation
 {
   message_t sendBuf;
   bool sendBusy;
+  bool sendQueue;
 
   /* Current local state - interval, version and accumulated readings */
   oscilloscope_t local;
 
+  uint8_t oversample; /* local.oversample downto 0 */
   uint8_t reading; /* 0 to NREADINGS */
 
   /* When we head an Oscilloscope message, we check it's sample count. If
@@ -50,23 +62,102 @@
   void report_sent() { call Leds.led1Toggle(); }
   void report_received() { call Leds.led2Toggle(); }
 
+  void startTimer();
+  void startDone(int channels_started)
+  {
+	static int waiting = uniqueCount("Channel") + 1; /* + communication */
+	waiting -= channels_started;
+	if (waiting == 0)
+	   startTimer();
+  }
+
   event void Boot.booted() {
     local.interval = DEFAULT_INTERVAL;
     local.id = TOS_NODE_ID;
-    if (call RadioControl.start() != SUCCESS)
+    local.oversample = 1;
+    local.channels = uniqueCount("Channel");
+    if (call CommunicationControl.start() != SUCCESS)
       report_problem();
+
+#ifndef WITHOUT_DEMOSENSOR
+    startDone(1); /* DemoSensor is autostarted */
+#endif
+
+#ifdef WITH_ANALOG_ACCEL
+    call AnalogAccelEnable.set(); // TODO: SplitControl?
+    startDone(3);
+#endif
+#ifdef WITH_DIGITAL_ACCEL
+    {
+	error_t e = call DigitalAccelControl.start();
+    	if (e != SUCCESS)
+       	   startDone(3); // Fake started...
+    }
+#endif
+#ifdef WITH_DIGITAL_TEMPERATURE
+       call MultiMeterControl.start(); // TODO: SplitControl?
+       call MultiMeterConfig.setConfig(0);
+       startDone(1);
+#endif
   }
 
+  event void DigitalAccelControl.startDone(error_t err) {
+  	if (err != SUCCESS) {
+	   report_problem();
+	   if (err == FAIL) call Leds.led1Toggle();
+	   // TODO: some sleep?
+	   call DigitalAccelControl.start(); // Retry...
+	   return; // Do not start timer...
+	}
+  	startDone(3);
+  }
+  
+  event void DigitalAccelControl.stopDone(error_t err) {
+        
+  }
+
+  /*
+   * prepareReadings: prepare reading buffer (and associated state) for receiving new data
+   */
+  void prepareReadings()
+  {
+	uint8_t cc;
+	for (cc=0; cc < NREADINGS; cc++)
+	    local.readings[cc] = 0;
+
+	reading = 0;
+	oversample = local.oversample;
+
+	/* Part 2 of cheap "time sync": increment our count if we didn't
+	   jump ahead. */
+	if (!suppressCountChange)
+	  local.count++;
+	suppressCountChange = FALSE;
+  }
+
   void startTimer() {
+#ifdef WITH_DIGITAL_ACCEL
+       /* Feature: ADXL345 has internal antialiazing filter - use it */
+       static float bw_table[] = {
+       	      0.05, 0.10, 0.20, 0.39, 0.78, 1.56, 3.13, 6.25, 12.5,
+	      25, 50, 100, 200, 400, 800, 1600}; 
+       uint8_t rate_ix;
+       float s_freq = 1000.0f/local.interval;
+       float req_bw = s_freq/2;
+       for (rate_ix = sizeof(bw_table)/sizeof(bw_table[0])-1; rate_ix>0; rate_ix--)
+       	   if (bw_table[rate_ix] <= req_bw)
+	      break;
+       call DigitalAccelConfig.setRegister(ADXL345_BW_RATE, rate_ix);
+#endif
     call Timer.startPeriodic(local.interval);
-    reading = 0;
+    prepareReadings();
   }
 
-  event void RadioControl.startDone(error_t error) {
-    startTimer();
+  event void CommunicationControl.startDone(error_t error) {
+     startDone(1);
   }
 
-  event void RadioControl.stopDone(error_t error) {
+  event void CommunicationControl.stopDone(error_t error) {
   }
 
   event message_t* Receive.receive(message_t* msg, void* payload, uint8_t len) {
@@ -81,9 +172,11 @@
       {
 	local.version = omsg->version;
 	local.interval = omsg->interval;
+	local.oversample = omsg->oversample;
+	/* Feature: sending an update starts timer */
 	startTimer();
       }
-    if (omsg->count > local.count)
+    if (omsg->count > local.count) /* TODO: review wrap handling... */
       {
 	local.count = omsg->count;
 	suppressCountChange = TRUE;
@@ -93,34 +186,52 @@
   }
 
   /* At each sample period:
-     - if local sample buffer is full, send accumulated samples
+     - if local sample buffer is full, copy accumulated samples
      - read next sample
+     - send samples
   */
   event void Timer.fired() {
-    if (reading == NREADINGS)
+    const int readings_fit = NREADINGS/uniqueCount("Channel");
+
+    /* Copy (minimal work before conversation start) */
+    if (reading == readings_fit) {
+        // Last chance to update local fields here!
+ 	if (sizeof local > call AMSend.maxPayloadLength()) {
+	   report_problem();
+	} else {
+	     memcpy(call AMSend.getPayload(&sendBuf, sizeof(local)), &local, sizeof local);
+	     sendQueue = TRUE;
+        }
+    }
+
+    /* Start conversation (before sending to minimize jitter) */
+    /* TODO: Start conversation for all channels when fired */
+    if (call ChannelRead.read[0U]() != SUCCESS)
+       report_problem();
+
+    if (reading == readings_fit) {
+	prepareReadings(); /* will reset readings too */
+    }
+
+    /* Send */
+    if (sendQueue)
       {
-	if (!sendBusy && sizeof local <= call AMSend.maxPayloadLength())
+	if (!sendBusy)
 	  {
-	    // Don't need to check for null because we've already checked length
-	    // above
-	    memcpy(call AMSend.getPayload(&sendBuf, sizeof(local)), &local, sizeof local);
-	    if (call AMSend.send(AM_BROADCAST_ADDR, &sendBuf, sizeof local) == SUCCESS)
+	    if (call AMSend.send(AM_BROADCAST_ADDR, &sendBuf, sizeof local) == SUCCESS) {
+	      sendQueue = FALSE;
 	      sendBusy = TRUE;
+	    }
 	  }
 	if (!sendBusy)
 	  report_problem();
 
-	reading = 0;
-	/* Part 2 of cheap "time sync": increment our count if we didn't
-	   jump ahead. */
-	if (!suppressCountChange)
-	  local.count++;
-	suppressCountChange = FALSE;
       }
-    if (call Read.read() != SUCCESS)
-      report_problem();
+
   }
 
+
+
   event void AMSend.sendDone(message_t* msg, error_t error) {
     if (error == SUCCESS)
       report_sent();
@@ -130,13 +241,60 @@
     sendBusy = FALSE;
   }
 
-  event void Read.readDone(error_t result, uint16_t data) {
+  default command error_t ChannelRead.read[uint8_t]() {}
+
+  void chain_done()
+  {
+       if (--oversample == 0) {
+       	  reading++;
+	  oversample = local.oversample;
+       }
+  }
+
+  event void ChannelRead.readDone[uint8_t channel](error_t result, uint16_t data) {
     if (result != SUCCESS)
       {
 	data = 0xffff;
-	report_problem();
+//	report_problem();
       }
-    if (reading < NREADINGS) 
-      local.readings[reading++] = data;
+
+    if (channel < uniqueCount("Channel")) {
+       if (data == 0xffff) {
+              local.readings[reading*uniqueCount("Channel") + channel] = data;
+       } else {
+       	      local.readings[reading*uniqueCount("Channel") + channel] += data;
+       }
+    }
+
+    /* NEXT CHANNEL */
+    channel++;
+    if (channel == uniqueCount("Channel")) {
+       chain_done();
+       return;
+    }
+    {
+    error_t err=call ChannelRead.read[channel]();
+    if (err != SUCCESS) {
+       // Chain will stop here...
+       chain_done();
+       if (err == EBUSY)
+       	  report_problem();
+    }
+    }
   }
+
+  async event void MultiMeterConfig.setConfigDone( error_t error ) {};
+  async event void MultiMeterConfig.allowSleepDone( error_t error ) {};
+  async event void MultiMeterConfig.setOffsetBiasDone( error_t error ) {};
+  async event void MultiMeterConfig.setAccOffsetBiasDone( error_t error ) {};
+
+  event void DigitalAccelConfig.setInterruptsDone( error_t error ) {};
+  event void DigitalAccelConfig.setIntMapDone( error_t error ) {};
+  event void DigitalAccelConfig.setReadAddressDone( error_t error ) {};
+  event void DigitalAccelConfig.setRangeDone( error_t error ) {};
+  event void DigitalAccelConfig.setRegisterDone( error_t error ) {}; /* used */
+  event void DigitalAccelConfig.setDurationDone( error_t error ) {};
+  event void DigitalAccelConfig.setWindowDone( error_t error ) {};
+  event void DigitalAccelConfig.setLatentDone( error_t error ) {};
 }
+
Index: Oscilloscope/java/Graph.java
===================================================================
--- Oscilloscope/java/Graph.java	(revision 5187)
+++ Oscilloscope/java/Graph.java	(working copy)
@@ -164,34 +164,42 @@
     /* Inner class to simplify drawing a graph. Simplify initialise it, then
        feed it the X screen and graph coordinates, from left to right. */
     private class SingleGraph {
-    int lastsx, lastsy, nodeId;
+    int lastsx, lastsy[], nodeId;
 
     /* Start drawing the graph mote id */
     SingleGraph(Graphics g, int id) {
         nodeId = id;
         lastsx = -1;
-        lastsy = -1;
+        lastsy = null;
     }
 
     /* Next point in mote's graph is at x value gx, screen coordinate sx */
     void nextPoint(Graphics g, int gx, int sx) {
-        int gy = parent.parent.data.getData(nodeId, gx);
-        int sy = -1;
+        int gy[] = parent.parent.data.getData(nodeId, gx);
+	for (int ch=0; gy != null && ch<gy.length; ch++) {
+	    int sy = -1;
 
-        if (gy >= 0) { // Ignore missing values
-        double rsy = height - yscale * (gy - gy0);
+	    if (gy != null && gy[ch] >= 0) { // Ignore missing values
+		double rsy = height - yscale * (gy[ch] - gy0);
 
-        // Ignore problem values
-        if (rsy >= -1e6 && rsy <= 1e6) {
-            sy = (int)(rsy + 0.5);
-        }
+		// Ignore problem values
+		if (rsy >= -1e6 && rsy <= 1e6) {
+		    sy = (int)(rsy + 0.5);
+		}
 
-        if (lastsy >= 0 && sy >= 0) {
-            g.drawLine(lastsx, lastsy, sx, sy);
-        }
-        }
-        lastsx = sx;
-        lastsy = sy;
+		// Got OK value, length should be OK too
+		if (lastsy == null) {
+		    lastsy = new int[gy.length];
+		}
+		else if (lastsy[ch] >= 0 && sy >= 0) {
+		    g.drawLine(lastsx, lastsy[ch], sx, sy);
+		}
+	    }
+	    // Wait for OK value
+	    if (lastsy != null)
+		lastsy[ch] = sy;
+	}
+	lastsx = sx;
     }
     }
 
Index: Oscilloscope/java/run
===================================================================
--- Oscilloscope/java/run	(revision 5187)
+++ Oscilloscope/java/run	(working copy)
@@ -1,4 +1,5 @@
 #!/bin/sh
+cd `dirname $0`
 if cygpath -w / >/dev/null 2>/dev/null; then
   CLASSPATH="oscilloscope.jar;$CLASSPATH"
 else
Index: Oscilloscope/java/Node.java
===================================================================
--- Oscilloscope/java/Node.java	(revision 5187)
+++ Oscilloscope/java/Node.java	(working copy)
@@ -8,6 +8,8 @@
  * 94704.  Attention:  Intel License Inquiry.
  */
 
+import java.util.*;
+
 /**
  * Class holding all data received from a mote.
  */
@@ -16,7 +18,8 @@
        INCREMENT itself must be a multiple of Constant.NREADINGS. This
        simplifies handling the extension and clipping of old data
        (see setEnd) */
-    final static int INCREMENT = 100 * Constants.NREADINGS;
+    final static int WINDOW = 1;
+    final static int INCREMENT = 100 * Constants.NREADINGS/WINDOW;
     final static int MAX_SIZE = 100 * INCREMENT; // Must be multiple of INCREMENT
 
     /* The mote's identifier */
@@ -25,54 +28,41 @@
     /* Data received from the mote. data[0] is the dataStart'th sample
        Indexes 0 through dataEnd - dataStart - 1 hold data.
        Samples are 16-bit unsigned numbers, -1 indicates missing data. */
-    int[] data;
+    Vector data;
+    int prevMessageId;
     int dataStart, dataEnd;
 
+    float[] window_func;
+
     Node(int _id) {
     id = _id;
+    window_func = new float[WINDOW];
+    for (int i=0; i<WINDOW; i++) {
+	window_func[i] = 1.0f; // rectangular
     }
+    }
 
     /* Update data to hold received samples newDataIndex .. newEnd.
        If we receive data with a lower index, we discard newer data
        (we assume the mote rebooted). */
-    private void setEnd(int newDataIndex, int newEnd) {
-    if (newDataIndex < dataStart || data == null) {
-        /* New data is before the start of what we have. Just throw it
-           all away and start again */
+    private void setEnd(boolean wrap, int newDataIndex, int newEnd) {
+	
+    if (wrap || newDataIndex < dataStart || data == null) {
+        // New data is before the start of what we have. Just throw it
+        //   all away and start again
+	System.out.println("DEBUG: data is before our start " + wrap);
+
         dataStart = newDataIndex;
-        data = new int[INCREMENT];
+	dataEnd = newDataIndex;
+        data = new Vector();
     }
-    if (newEnd > dataStart + data.length) {
-        /* Try extending first */
-        if (data.length < MAX_SIZE) {
-        int newLength = (newEnd - dataStart + INCREMENT - 1) / INCREMENT * INCREMENT;
-        if (newLength >= MAX_SIZE) {
-            newLength = MAX_SIZE;
-        }
+    data.ensureCapacity(newEnd - dataStart + 1);
+    // System.out.println("DEBUG: setend(" + newDataIndex + ", " + newEnd + ") with dataStart=" + dataStart + " dataEnd=" + dataEnd);
 
-        int[] newData = new int[newLength];
-        System.arraycopy(data, 0, newData, 0, data.length);
-        data = newData;
-
-        }
-        if (newEnd > dataStart + data.length) {
-        /* Still doesn't fit. Squish.
-           We assume INCREMENT >= (newEnd - newDataIndex), and ensure
-           that dataStart + data.length - INCREMENT = newDataIndex */
-        int newStart = newDataIndex + INCREMENT - data.length;
-
-        if (dataStart + data.length > newStart) {
-            System.arraycopy(data, newStart - dataStart, data, 0,
-                     data.length - (newStart - dataStart));
-        }
-        dataStart = newStart;
-        }
-    }
     /* Mark any missing data as invalid */
-    for (int i = dataEnd < dataStart ? dataStart : dataEnd;
-         i < newDataIndex; i++) {
-        data[i - dataStart] = -1;
-    }
+    /* Fill to start position, from old end to new start */
+    for (int i = dataEnd; i < newDataIndex; i++)
+	data.add(null);
 
     /* If we receive a count less than the old count, we assume the old
        data is invalid */
@@ -82,20 +72,26 @@
 
     /* Data received containing NREADINGS samples from messageId * NREADINGS 
        onwards */
-    void update(int messageId, int[] readings) {
-    int start = messageId * Constants.NREADINGS;
-    setEnd(start, start + Constants.NREADINGS);
-    for (int i = 0; i < readings.length; i++) {
-        data[start - dataStart + i] = readings[i];
+    void update(int messageId, int[][] readings) {
+	int len = readings.length;
+	int start = messageId * len; // assume all messages of same length...
+	boolean wrap = (short)(messageId - prevMessageId) > 0 &&
+	    messageId < prevMessageId;
+	prevMessageId = messageId;
+
+	setEnd(wrap, start, start + len);
+
+	for (int i = 0; i < len; i++) {
+	    data.add(readings[i]);
+	}
     }
-    }
 
     /* Return value of sample x, or -1 for missing data */
-    int getData(int x) {
+    int[] getData(int x) {
     if (x < dataStart || x >= dataEnd) {
-        return -1;
+        return null;
     } else {
-        return data[x - dataStart];
+        return (int[])data.get(x - dataStart);
     }
     }
 
Index: Oscilloscope/java/Data.java
===================================================================
--- Oscilloscope/java/Data.java	(revision 5187)
+++ Oscilloscope/java/Data.java	(working copy)
@@ -23,7 +23,8 @@
 
     /* Data received from mote nodeId containing NREADINGS samples from
        messageId * NREADINGS onwards. Tell parent if this is a new node. */
-    void update(int nodeId, int messageId, int readings[]) {
+    void update(int nodeId, int messageId, int readings[][]) {
+	/* TODO: rewrite to use Vector */
     if (nodeId >= nodes.length) {
         int newLength = nodes.length * 2;
         if (nodeId >= newLength) {
@@ -43,9 +44,9 @@
     }
 
     /* Return value of sample x for mote nodeId, or -1 for missing data */
-    int getData(int nodeId, int x) {
+    int[] getData(int nodeId, int x) {
     if (nodeId >= nodes.length || nodes[nodeId] == null)
-        return -1;
+        return new int[0];
     return nodes[nodeId].getData(x);
     }
 
Index: Oscilloscope/java/Oscilloscope.java
===================================================================
--- Oscilloscope/java/Oscilloscope.java	(revision 5187)
+++ Oscilloscope/java/Oscilloscope.java	(working copy)
@@ -69,8 +69,18 @@
 
         /* Update interval and mote data */
         periodUpdate(omsg.get_version(), omsg.get_interval());
-        data.update(omsg.get_id(), omsg.get_count(), omsg.get_readings());
+	int rreadings[] = omsg.get_readings();
+	final int channels = omsg.get_channels();
+	final int readings = rreadings.length / channels;
+	int sreadings[][] = new int[readings][channels];
 
+	int ix = 0;
+	for (int rix = 0; rix < readings; rix++)
+	    for (int cix = 0; cix < channels; cix++)
+		sreadings[rix][cix] = rreadings[ix++];
+
+        data.update(omsg.get_id(), omsg.get_count(), sreadings);
+
         /* Inform the GUI that new data showed up */
         window.newData();
     }
Index: Oscilloscope/OscilloscopeAppC.nc
===================================================================
--- Oscilloscope/OscilloscopeAppC.nc	(revision 5187)
+++ Oscilloscope/OscilloscopeAppC.nc	(working copy)
@@ -19,17 +19,77 @@
 configuration OscilloscopeAppC { }
 implementation
 {
-  components OscilloscopeC, MainC, ActiveMessageC, LedsC,
-    new TimerMilliC(), new DemoSensorC() as Sensor, 
-    new AMSenderC(AM_OSCILLOSCOPE), new AMReceiverC(AM_OSCILLOSCOPE);
+  components LedsC;
 
+#ifdef WITH_DELUGE
+  components DelugeC;
+  DelugeC.Leds -> LedsC;
+#endif
+
+  components OscilloscopeC, MainC, new TimerMilliC();
+
+#ifndef WITHOUT_DEMOSENSOR
+  components new DemoSensorC() as Sensor;
+#endif
+
+#ifdef WITH_ANALOG_ACCEL
+  components HplMMA7261QTC as AnalogAccel;
+#endif
+
+#ifdef WITH_DIGITAL_ACCEL
+  components new ADXL345C() as DigitalAccel;
+#endif
+
+#ifdef WITH_DIGITAL_TEMPERATURE
+  components DS2782InternalC as MultiMeter;
+#endif
+
+#if defined(DELUGE_BASESTATION) || defined(BASESTATION)
+  components SerialActiveMessageC as ActiveMessageC_,
+    new SerialAMSenderC(AM_OSCILLOSCOPE) as AMSenderC_,
+    new SerialAMReceiverC(AM_OSCILLOSCOPE) as AMReceiverC_;
+#else
+  components ActiveMessageC as ActiveMessageC_,
+    new AMSenderC(AM_OSCILLOSCOPE) as AMSenderC_,
+    new AMReceiverC(AM_OSCILLOSCOPE) as AMReceiverC_;
+#endif
+
+
   OscilloscopeC.Boot -> MainC;
-  OscilloscopeC.RadioControl -> ActiveMessageC;
-  OscilloscopeC.AMSend -> AMSenderC;
-  OscilloscopeC.Receive -> AMReceiverC;
+  OscilloscopeC.CommunicationControl -> ActiveMessageC_;
+  OscilloscopeC.AMSend -> AMSenderC_;
+  OscilloscopeC.Receive -> AMReceiverC_;
   OscilloscopeC.Timer -> TimerMilliC;
-  OscilloscopeC.Read -> Sensor;
+#ifdef WITH_DIGITAL_ACCEL
+  OscilloscopeC.DigitalAccelControl -> DigitalAccel;
+  OscilloscopeC.DigitalAccelConfig  -> DigitalAccel;
+#endif
+
+#ifndef WITHOUT_DEMOSENSOR
+  OscilloscopeC.ChannelRead[unique("Channel")] -> Sensor;
+#endif
+
+#ifdef WITH_ANALOG_ACCEL
+  OscilloscopeC.ChannelRead[unique("Channel")] -> AnalogAccel.AccelX;
+  OscilloscopeC.ChannelRead[unique("Channel")] -> AnalogAccel.AccelY;
+  OscilloscopeC.ChannelRead[unique("Channel")] -> AnalogAccel.AccelZ;
+#endif
+
+#ifdef WITH_DIGITAL_ACCEL
+  OscilloscopeC.ChannelRead[unique("Channel")] -> DigitalAccel.X;
+  OscilloscopeC.ChannelRead[unique("Channel")] -> DigitalAccel.Y;
+  OscilloscopeC.ChannelRead[unique("Channel")] -> DigitalAccel.Z;
+#endif
+
+#ifdef WITH_DIGITAL_TEMPERATURE
+  OscilloscopeC.ChannelRead[unique("Channel")] -> MultiMeter.Temperature;
+  OscilloscopeC.MultiMeterControl -> MultiMeter;
+  OscilloscopeC.MultiMeterConfig -> MultiMeter;
+#endif
+
   OscilloscopeC.Leds -> LedsC;
 
-  
+#ifdef WITH_ANALOG_ACCEL
+  OscilloscopeC.AnalogAccelEnable -> AnalogAccel.Sleep; /* Sleep is active low (TODO: split control?) */ 
+#endif
 }
Index: Oscilloscope/volumes-stm25p.xml
===================================================================
--- Oscilloscope/volumes-stm25p.xml	(revision 0)
+++ Oscilloscope/volumes-stm25p.xml	(revision 0)
@@ -0,0 +1,6 @@
+<volume_table>
+  <volume name="GOLDENIMAGE" size="65536" base="983040" />
+  <volume name="DELUGE1" size="65536"/>
+  <volume name="DELUGE2" size="65536"/>
+  <volume name="DELUGE3" size="65536"/>
+</volume_table>
\ No newline at end of file
Index: Oscilloscope/Oscilloscope.h
===================================================================
--- Oscilloscope/Oscilloscope.h	(revision 5187)
+++ Oscilloscope/Oscilloscope.h	(working copy)
@@ -16,7 +16,7 @@
 enum {
   /* Number of readings per message. If you increase this, you may have to
      increase the message_t size. */
-  NREADINGS = 10,
+  NREADINGS = 9,
 
   /* Default sampling period. */
   DEFAULT_INTERVAL = 256,
@@ -29,6 +29,8 @@
   nx_uint16_t interval; /* Samping period. */
   nx_uint16_t id; /* Mote id of sending mote. */
   nx_uint16_t count; /* The readings are samples count * NREADINGS onwards */
+  nx_uint8_t  oversample; /* readings are accumulated, rectangle window - simple addition */
+  nx_uint8_t  channels; /* no of interleaved channels in readings */
   nx_uint16_t readings[NREADINGS];
 } oscilloscope_t;
 
Index: Oscilloscope/oscilloscope.py
===================================================================
--- Oscilloscope/oscilloscope.py	(revision 5187)
+++ Oscilloscope/oscilloscope.py	(working copy)
@@ -5,6 +5,27 @@
 
 AM_OSCILLOSCOPE = 0x93
 
+_decode=False
+if '-d' in sys.argv:
+    _decode=True
+
+_interval = None
+if '-i' in sys.argv:
+    _interval = int(sys.argv[sys.argv.index('-i')+1])
+    print '% interval', _interval
+
+_oversample = None
+if '-o' in sys.argv:
+    _oversample = int(sys.argv[sys.argv.index('-o')+1])
+    print '% oversample', _oversample
+
+_calibrated = '-c' in sys.argv
+
+ck = {'Xa': 2./-487.25, 'Ya': 2./-512, 'Za':2./499.5,
+      'Xd': 2./524.95,  'Yd': 2./-528, 'Zd':2./498.67}
+cd = {'Xa': -509.38,    'Ya':-506,     'Za':-516.68,
+      'Xd': -0.28,      'Yd':-3.4,     'Zd': -7.67}
+
 class OscilloscopeMsg(tos.Packet):
     def __init__(self, packet = None):
         tos.Packet.__init__(self,
@@ -12,10 +33,20 @@
                              ('interval', 'int', 2),
                              ('id',       'int', 2),
                              ('count',    'int', 2),
+                             ('oversample','int', 1),
+                             ('channels', 'int', 1),
+                             # readings
+                             ('acca_X',  'int', 2),
+                             ('acca_Y',  'int', 2),
+                             ('acca_Z',  'int', 2),
+                             ('accd_X', 'sint', 2),
+                             ('accd_Y', 'sint', 2),
+                             ('accd_Z', 'sint', 2),
+                             ('temp',   'sint', 2),
                              ('readings', 'blob', None)],
                             packet)
 if '-h' in sys.argv:
-    print "Usage:", sys.argv[0], "serial@/dev/ttyUSB0:57600"
+    print >>sys.stderr, "Usage:", sys.argv[0], "serial@/dev/ttyUSB0:57600 [-i interval] [-o oversample] [-d [-c]]"
     sys.exit()
 
 am = tos.AM()
@@ -24,6 +55,43 @@
     p = am.read()
     if p and p.type == AM_OSCILLOSCOPE:
         msg = OscilloscopeMsg(p.data)
-        print msg.id, msg.count, [i<<8 | j for (i,j) in zip(msg.readings[::2], msg.readings[1::2])]
-        #print msg
+        if _decode:
+            temp = msg.temp/256.0/msg.oversample
+            aax = msg.acca_X/msg.oversample
+            aay = msg.acca_Y/msg.oversample
+            aaz = msg.acca_Z/msg.oversample
+            adx = msg.accd_X/msg.oversample
+            ady = msg.accd_Y/msg.oversample
+            adz = msg.accd_Z/msg.oversample
+            if _calibrated:
+                aax = ck['Xa']*(aax+cd['Xa'])
+                aay = ck['Ya']*(aay+cd['Ya'])
+                aaz = ck['Za']*(aaz+cd['Za'])
+                adx = ck['Xd']*(adx+cd['Xd'])
+                ady = ck['Yd']*(ady+cd['Yd'])
+                adz = ck['Zd']*(adz+cd['Zd'])
+            print msg.id, msg.count, aax, aay, aaz, adx, ady, adz, temp
+        else:
+            readings = [i<<8 | j for (i,j) in zip(msg.readings[::2], msg.readings[1::2])]
+            print msg.id, msg.count, readings
 
+        sys.stdout.flush()
+        _send = False
+
+        if _interval:
+            msg.interval = _interval
+            _interval = None
+            _send = True
+
+        if _oversample:
+            msg.oversample = _oversample
+            _oversample = None
+            _send = True
+
+        if _send:
+            msg.version += 1
+            am.write(msg, p.type)
+            
+    else:
+        print p
+
Index: Oscilloscope/volumes-at45db.xml
===================================================================
--- Oscilloscope/volumes-at45db.xml	(revision 0)
+++ Oscilloscope/volumes-at45db.xml	(revision 0)
@@ -0,0 +1,6 @@
+<volume_table>
+  <volume name="GOLDENIMAGE" size="65536" base="0" />
+  <volume name="DELUGE1" size="65536"/>
+  <volume name="DELUGE2" size="65536"/>
+  <volume name="DELUGE3" size="65536"/>
+</volume_table>
\ No newline at end of file
Index: Oscilloscope/Makefile
===================================================================
--- Oscilloscope/Makefile	(revision 5187)
+++ Oscilloscope/Makefile	(working copy)
@@ -1,3 +1,6 @@
 COMPONENT=OscilloscopeAppC
+BOOTLOADER=tosboot
 
+#CFLAGS += -DDELUGE_LIGHT_BASESTATION
+
 include $(MAKERULES)
_______________________________________________
Tinyos-help mailing list
Tinyos-help@millennium.berkeley.edu
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to