From 9488153e3b2b01e9b9c4a889bebc8466217e63a0 Mon Sep 17 00:00:00 2001 From: scipio Date: Tue, 19 Feb 2008 19:49:30 +0000 Subject: [PATCH] Update the testing code so it tests for radios being turned on and off. --- .../TestMultihopLqi/CC2420ActiveMessageC.nc | 10 ++-- apps/tests/TestMultihopLqi/Makefile | 2 +- .../TestMultihopLqi/MultihopOscilloscope.h | 2 +- .../MultihopOscilloscopeAppC.nc | 21 ++++--- .../TestMultihopLqi/MultihopOscilloscopeC.nc | 56 +++++++++++++------ apps/tests/TestMultihopLqi/script.py | 8 +-- 6 files changed, 61 insertions(+), 38 deletions(-) diff --git a/apps/tests/TestMultihopLqi/CC2420ActiveMessageC.nc b/apps/tests/TestMultihopLqi/CC2420ActiveMessageC.nc index ad1228af..6758006d 100644 --- a/apps/tests/TestMultihopLqi/CC2420ActiveMessageC.nc +++ b/apps/tests/TestMultihopLqi/CC2420ActiveMessageC.nc @@ -1,5 +1,6 @@ #include #include +#include module CC2420ActiveMessageC { provides interface CC2420Packet as Packet; @@ -7,6 +8,9 @@ module CC2420ActiveMessageC { } implementation { + typedef struct cc2420_header { + + } cc2420_header_t; /** * Get transmission power setting for current packet. * @@ -59,10 +63,4 @@ implementation { return (uint8_t)sig; } - async command cc2420_header_t* Packet.getHeader(message_t* msg) { - return NULL; - } - async command cc2420_metadata_t* Packet.getMetadata(message_t* msg) { - return NULL; - } } diff --git a/apps/tests/TestMultihopLqi/Makefile b/apps/tests/TestMultihopLqi/Makefile index 027077c6..5b6ef2b1 100644 --- a/apps/tests/TestMultihopLqi/Makefile +++ b/apps/tests/TestMultihopLqi/Makefile @@ -1,4 +1,4 @@ COMPONENT=MultihopOscilloscopeAppC -CFLAGS += -I$(TOSDIR)/lib/net/ -I$(TOSDIR)/lib/net/lqi +CFLAGS += -I$(TOSDIR)/lib/net/ -I$(TOSDIR)/lib/net/lqi -I$(TOSDIR)/chips/cc2420/interfaces include $(MAKERULES) diff --git a/apps/tests/TestMultihopLqi/MultihopOscilloscope.h b/apps/tests/TestMultihopLqi/MultihopOscilloscope.h index 29ebb8b7..5f040539 100644 --- a/apps/tests/TestMultihopLqi/MultihopOscilloscope.h +++ b/apps/tests/TestMultihopLqi/MultihopOscilloscope.h @@ -21,7 +21,7 @@ enum { increase the message_t size. */ NREADINGS = 5, /* Default sampling period. */ - DEFAULT_INTERVAL = 200, + DEFAULT_INTERVAL = 1024, AM_OSCILLOSCOPE = 0x93 }; diff --git a/apps/tests/TestMultihopLqi/MultihopOscilloscopeAppC.nc b/apps/tests/TestMultihopLqi/MultihopOscilloscopeAppC.nc index d2f0e482..1f591c9e 100644 --- a/apps/tests/TestMultihopLqi/MultihopOscilloscopeAppC.nc +++ b/apps/tests/TestMultihopLqi/MultihopOscilloscopeAppC.nc @@ -18,8 +18,8 @@ configuration MultihopOscilloscopeAppC { } implementation { - components MainC, MultihopOscilloscopeC, LedsC, new TimerMilliC(), - new DemoSensorC() as Sensor; + components MainC, MultihopOscilloscopeC, LedsC, new TimerMilliC(), + new TimerMilliC() as OnOffTimer, new DemoSensorC() as Sensor; //MainC.SoftwareInit -> Sensor; @@ -27,7 +27,7 @@ implementation { MultihopOscilloscopeC.Timer -> TimerMilliC; MultihopOscilloscopeC.Read -> Sensor; MultihopOscilloscopeC.Leds -> LedsC; - + MultihopOscilloscopeC.OnOffTimer -> OnOffTimer; // // Communication components. These are documented in TEP 113: // Serial Communication, and TEP 119: Collection. @@ -37,6 +37,7 @@ implementation { new CollectionSenderC(AM_OSCILLOSCOPE), // Sends multihop RF SerialActiveMessageC, // Serial messaging new SerialAMSenderC(AM_OSCILLOSCOPE); // Sends to the serial port + components RandomC; MultihopOscilloscopeC.RadioControl -> ActiveMessageC; MultihopOscilloscopeC.SerialControl -> SerialActiveMessageC; @@ -47,17 +48,15 @@ implementation { MultihopOscilloscopeC.Snoop -> Collector.Snoop[AM_OSCILLOSCOPE]; MultihopOscilloscopeC.Receive -> Collector.Receive[AM_OSCILLOSCOPE]; MultihopOscilloscopeC.RootControl -> Collector; - + MultihopOscilloscopeC.Random -> RandomC; + components new PoolC(message_t, 10) as UARTMessagePoolP, new QueueC(message_t*, 10) as UARTQueueP; MultihopOscilloscopeC.UARTMessagePool -> UARTMessagePoolP; MultihopOscilloscopeC.UARTQueue -> UARTQueueP; - - // - // Components for debugging collection. - // - components new PoolC(message_t, 20) as DebugMessagePool, + + components new PoolC(message_t, 20) as DebugMessagePool, new QueueC(message_t*, 20) as DebugSendQueue, new SerialAMSenderC(AM_LQI_DEBUG) as DebugSerialSender, UARTDebugSenderP as DebugSender; @@ -67,4 +66,8 @@ implementation { DebugSender.MessagePool -> DebugMessagePool; DebugSender.SendQueue -> DebugSendQueue; Collector.CollectionDebug -> DebugSender; + + components CC2420ActiveMessageC; + CC2420ActiveMessageC.SubPacket -> ActiveMessageC; + } diff --git a/apps/tests/TestMultihopLqi/MultihopOscilloscopeC.nc b/apps/tests/TestMultihopLqi/MultihopOscilloscopeC.nc index aed5a437..a13236e3 100644 --- a/apps/tests/TestMultihopLqi/MultihopOscilloscopeC.nc +++ b/apps/tests/TestMultihopLqi/MultihopOscilloscopeC.nc @@ -40,8 +40,10 @@ module MultihopOscilloscopeC { // Miscalleny: interface Timer; + interface Timer as OnOffTimer; interface Read; interface Leds; + interface Random; } } @@ -69,7 +71,7 @@ implementation { is a very simple form of "time" synchronization (for an abstract notion of time). */ bool suppress_count_change; - + bool running = FALSE; // // On bootup, initialize radio and serial communications, and our // own state variables. @@ -78,16 +80,19 @@ implementation { local.interval = DEFAULT_INTERVAL; local.id = TOS_NODE_ID; local.version = 0; - dbg("App", "Booted."); + // Beginning our initialization phases: if (call RadioControl.start() != SUCCESS) fatal_problem(); if (call RoutingControl.start() != SUCCESS) fatal_problem(); + + startTimer(); } event void RadioControl.startDone(error_t error) { + //dbg("App", "Radio control start done.\n"); if (error != SUCCESS) fatal_problem(); @@ -96,6 +101,9 @@ implementation { if (call SerialControl.start() != SUCCESS) fatal_problem(); + + running = TRUE; + call OnOffTimer.startOneShot(19 + (call Random.rand32() % 173)); } event void SerialControl.startDone(error_t error) { @@ -105,17 +113,33 @@ implementation { // This is how to set yourself as a root to the collection layer: if (local.id % 500 == 0) call RootControl.setRoot(); + - startTimer(); } + + event void OnOffTimer.fired() { + if (running) { + call RadioControl.stop(); + } + else { + call RadioControl.start(); + } + + } + static void startTimer() { + dbg("App", "Starting timer.\n"); if (call Timer.isRunning()) call Timer.stop(); call Timer.startPeriodic(local.interval); reading = 0; } - event void RadioControl.stopDone(error_t error) { } + event void RadioControl.stopDone(error_t error) { + //dbg("App", "Radio control stop done.\n"); + running = FALSE; + call OnOffTimer.startOneShot(3); + } event void SerialControl.stopDone(error_t error) { } // @@ -127,17 +151,10 @@ implementation { Receive.receive(message_t* msg, void *payload, uint8_t len) { oscilloscope_t* in = (oscilloscope_t*)payload; oscilloscope_t* out; - dbg("App", "Received a packet.\n\t"); - { - int i; - for (i = 0; i < len; i++) { - dbg_clear("App", "[%hhx] ", ((uint8_t*)payload)[i]); - } - dbg_clear("App", "\n"); - } if (uartbusy == FALSE) { out = (oscilloscope_t*)call SerialSend.getPayload(&uartbuf, sizeof(oscilloscope_t)); - if (out == NULL || call Packet.payloadLength(&uartbuf) != sizeof(oscilloscope_t)) { + if (out == NULL) { + fatal_problem(); return msg; } else { @@ -158,7 +175,8 @@ implementation { //Prepare message to be sent over the uart out = (oscilloscope_t*)call SerialSend.getPayload(newmsg, sizeof(oscilloscope_t)); if (out == NULL) { - return; + fatal_problem(); + return msg; } memcpy(out, in, sizeof(oscilloscope_t)); @@ -237,15 +255,18 @@ implementation { if (!sendbusy) { oscilloscope_t *o = (oscilloscope_t *)call Send.getPayload(&sendbuf, sizeof(oscilloscope_t)); if (o == NULL) { + fatal_problem(); return; } memcpy(o, &local, sizeof(local)); if (call Send.send(&sendbuf, sizeof(local)) == SUCCESS) { - dbg("App", "Sending a packet.\n"); sendbusy = TRUE; - } - else + dbg("App", "Sending data packet.\n"); + } + else { + dbg("App", "Data packet send failed.\n"); report_problem(); + } } reading = 0; @@ -261,6 +282,7 @@ implementation { } event void Send.sendDone(message_t* msg, error_t error) { + dbg("App", "App-level send done.\n"); if (error == SUCCESS) report_sent(); else diff --git a/apps/tests/TestMultihopLqi/script.py b/apps/tests/TestMultihopLqi/script.py index 15d2e342..aa72201c 100644 --- a/apps/tests/TestMultihopLqi/script.py +++ b/apps/tests/TestMultihopLqi/script.py @@ -11,11 +11,11 @@ r = t.radio() #t.addChannel("RadioCountToLedsC", sys.stdout) #t.addChannel("CpmModelC", sys.stdout) #t.addChannel("Gain", sys.stdout) -t.addChannel("AM", sys.stdout) +#t.addChannel("AM", sys.stdout) t.addChannel("App", sys.stdout) -#t.addChannel("LQI", sys.stdout) +t.addChannel("LQI", sys.stdout) #t.addChannel("LQIRoute", sys.stdout) -#t.addChannel("LQIDeliver", sys.stdout) +t.addChannel("LQIDeliver", sys.stdout) #t.addChannel("LQIRoute", sys.stdout) #t.addChannel("PointerBug", sys.stdout) @@ -54,5 +54,5 @@ print "time: ", duration; #for i in range(0, 196607): # print m1.generateNoise(i) -for i in range(0, 2000): +while ((t.time() / t.ticksPerSecond()) < 3000): t.runNextEvent(); -- 2.39.2