]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
DIP Test Code
authorkaisenl <kaisenl>
Thu, 24 Jan 2008 07:28:27 +0000 (07:28 +0000)
committerkaisenl <kaisenl>
Thu, 24 Jan 2008 07:28:27 +0000 (07:28 +0000)
apps/tests/TestDIP/Makefile [new file with mode: 0644]
apps/tests/TestDIP/README [new file with mode: 0644]
apps/tests/TestDIP/TestDIPC-Master.nc [new file with mode: 0644]
apps/tests/TestDIP/TestDIPP-Master.nc [new file with mode: 0644]
apps/tests/TestDIP/gentest.py [new file with mode: 0644]

diff --git a/apps/tests/TestDIP/Makefile b/apps/tests/TestDIP/Makefile
new file mode 100644 (file)
index 0000000..de7eb1d
--- /dev/null
@@ -0,0 +1,8 @@
+COMPONENT=TestDIPC
+CFLAGS += -I$(TOSDIR)/lib/net
+CFLAGS += -I$(TOSDIR)/lib/net/dip -I$(TOSDIR)/lib/net/dip/interfaces
+#CFLAGS += -I$(TOSDIR)/lib/net/drip
+
+CONSTANTS += -DTOSH_DATA_LENGTH=32
+CFLAGS += $(CONSTANTS)
+include $(MAKERULES)
diff --git a/apps/tests/TestDIP/README b/apps/tests/TestDIP/README
new file mode 100644 (file)
index 0000000..2d81083
--- /dev/null
@@ -0,0 +1,47 @@
+
+Title: TestDIP Application
+Author: Kaisen Lin
+
+1. SETTING UP THE TEST
+
+You need to first generate the code for compilation. The gentest.py
+script reads in the Master files and creates TestDIPC.nc (the
+configuration) and TESTDIPP.nc (the module). It takes two parameters,
+the total number of items and the number of new items. The items that
+are random are chosen randomly.
+
+If you want 128 total items and 96 new items, you would type:
+
+python gentest.py 128 96
+
+After the configuration and module have been generated, you can use
+the normal compilation method (e.g. make telosb).
+
+2, READING THE LEDS
+
+When an node receives a new item, it toggles LED0. When a node
+completes all items, it turns all LEDs on.
+
+3. SERIAL MESSAGES
+
+typedef nx_struct dip_test_msg_t {
+  nx_am_addr_t id;
+  nx_uint8_t count;
+  nx_uint8_t isOk;
+} dip_test_msg_t;
+
+Every time a node a receives a new item, it sends a dip_test_msg_t
+through the serial interface.
+
+id is the node id
+count is how many new items it has received so far
+isOk will be true if the data value was as expected
+
+4. TIMING
+
+With a single sender and single receiver on a table, it takes
+approximately:
+
+3.5 minutes for a node to receive 128 out of 128 items. 
+4.0 minutes for a node to receive 240 out of 240 items.
+
diff --git a/apps/tests/TestDIP/TestDIPC-Master.nc b/apps/tests/TestDIP/TestDIPC-Master.nc
new file mode 100644 (file)
index 0000000..b61094d
--- /dev/null
@@ -0,0 +1,28 @@
+
+configuration TestDIPC {
+
+}
+
+implementation {
+  components TestDIPP;
+  components LedsC as LedsC;
+  TestDIPP.Leds -> LedsC;
+
+  components DisseminationC;
+  TestDIPP.StdControl -> DisseminationC;
+  /*
+  components new DisseminatorC(uint32_t, 0x1) as Dissem1;
+  TestDIPP.DisseminationValue1 -> Dissem1;
+  TestDIPP.DisseminationUpdate1 -> Dissem1;
+  */
+
+  // ... DISSEMINATORS
+
+  components MainC;
+  TestDIPP.Boot -> MainC;
+
+  components SerialActiveMessageC;
+  components new SerialAMSenderC(0xAB);
+  TestDIPP.SerialSend -> SerialAMSenderC;
+  TestDIPP.SerialControl -> SerialActiveMessageC;
+}
diff --git a/apps/tests/TestDIP/TestDIPP-Master.nc b/apps/tests/TestDIP/TestDIPP-Master.nc
new file mode 100644 (file)
index 0000000..696743d
--- /dev/null
@@ -0,0 +1,90 @@
+
+module TestDIPP {
+  uses interface Leds;
+  uses interface StdControl;
+
+  /*
+  uses interface DisseminationUpdate<uint16_t> as DisseminationUpdate1;
+  uses interface DisseminationValue<uint16_t> as DisseminationValue1;
+  */
+
+  // ... INTERFACES
+
+  uses interface Boot;
+  uses interface AMSend as SerialSend;
+  uses interface SplitControl as SerialControl;
+}
+
+implementation {
+  typedef nx_struct dip_test_msg_t {
+    nx_am_addr_t id;
+    nx_uint8_t count;
+    nx_uint8_t isOk;
+  } dip_test_msg_t;
+
+  message_t m_test;
+
+  uint8_t okbit = 1;
+  uint16_t data;
+  uint8_t count = 0;
+  /*
+  uint8_t newcount = N;
+  */
+  // ... NEWCOUNT
+
+  void bookkeep();
+
+  event void SerialControl.startDone(error_t err) {
+    call StdControl.start();
+    if(TOS_NODE_ID == 0) {
+      data = 0xBEEF;
+      dbg("TestDIPP","Updating data items\n");
+      /*
+      call DisseminationUpdate1.change(&data);
+      */
+      // ... CHANGES
+    }
+  }
+  
+  event void SerialControl.stopDone(error_t err) {
+    
+  }
+
+  event void Boot.booted() {
+    call SerialControl.start();
+    dbg("TestDIPP", "Booted at %s\n", sim_time_string());
+  }
+  /*
+  event void DisseminationValue1.changed() {
+    uint16_t val = *(uint16_t*) call DisseminationValue1.get();
+    if(val != 0xBEEF) { return; }
+    bookkeep();
+  }
+  */
+
+  // ... EVENTS
+
+  void bookkeep() {
+    dip_test_msg_t* testmsg;
+
+    if(count < newcount) {
+      count++;
+    }
+    dbg("TestDIPP", "Got an update, %u complete now at %s\n", count, sim_time_string());
+    call Leds.led0Toggle();
+    
+    if(newcount == count) {
+      call Leds.set(7);
+      testmsg = (dip_test_msg_t*) call SerialSend.getPayload(&m_test, 0);
+      testmsg->id = TOS_NODE_ID;
+      testmsg->count = count;
+      testmsg->isOk = okbit;
+      call SerialSend.send(0, &m_test, sizeof(dip_test_msg_t));
+    }
+    
+  }
+
+  event void SerialSend.sendDone(message_t* message, error_t err) {
+
+  }
+}
diff --git a/apps/tests/TestDIP/gentest.py b/apps/tests/TestDIP/gentest.py
new file mode 100644 (file)
index 0000000..5e5084e
--- /dev/null
@@ -0,0 +1,61 @@
+#!/usr/bin/python
+
+import sys
+import re
+import os
+import random
+
+print "Usage: python gentest.py [numitems] [newitems]"
+
+items = sys.argv[1]
+newitems = sys.argv[2]
+
+print "Generating Configurations"
+
+fin = open("TestDIPC-Master.nc", "r")
+fout = open("TestDIPC.nc", "w")
+lines = fin.readlines()
+for line in lines:
+    if(line.find("... DISSEMINATORS") != -1):
+        for i in range(1, int(items)+1):
+            fout.write("  components new DisseminatorC(uint16_t, ")
+            fout.write(str(i))
+            fout.write(") as Dissem" + str(i) + ";\n")
+            fout.write("  TestDIPP.DisseminationUpdate" + str(i))
+            fout.write(" -> Dissem" + str(i) + ";\n")
+            fout.write("  TestDIPP.DisseminationValue" + str(i))
+            fout.write(" -> Dissem" + str(i) + ";\n\n")
+    else:
+        fout.write(line)
+
+fin.close()
+fout.close()
+
+print "Generating Modules"
+
+fin = open("TestDIPP-Master.nc", "r")
+fout = open("TestDIPP.nc", "w")
+lines = fin.readlines()
+for line in lines:
+    if(line.find("... INTERFACES") != -1):
+        for i in range(1, int(items)+1):
+            fout.write("  uses interface DisseminationUpdate<uint16_t> as DisseminationUpdate")
+            fout.write(str(i) + ";\n")
+            fout.write("  uses interface DisseminationValue<uint16_t> as DisseminationValue")
+            fout.write(str(i) + ";\n\n")
+    elif(line.find("... NEWCOUNT") != -1):
+        fout.write("  uint8_t newcount = " + str(newitems) + ";\n")
+    elif(line.find("... CHANGES") != -1):
+        for i in random.sample(range(1, int(items)+1), int(newitems)):
+            fout.write("      call DisseminationUpdate" + str(i) + ".change(&data);\n")
+    elif(line.find("... EVENTS") != -1):
+        for i in range(1, int(items)+1):
+            fout.write("  event void DisseminationValue" + str(i))
+            fout.write(".changed() {\n")
+            fout.write("    uint16_t val = *(uint16_t*) call DisseminationValue" + str(i) + ".get();\n")
+            fout.write("    if(val != 0xBEEF) { return; }\n")
+            fout.write("    bookkeep();\n")
+            fout.write("  }\n\n")
+    else:
+        fout.write(line)
+