turned on and off.
#include <sim_gain.h>
#include <sim_tossim.h>
+#include <AM.h>
module CC2420ActiveMessageC {
provides interface CC2420Packet as Packet;
}
implementation {
+ typedef struct cc2420_header {
+
+ } cc2420_header_t;
/**
* Get transmission power setting for current packet.
*
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;
- }
}
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)
increase the message_t size. */
NREADINGS = 5,
/* Default sampling period. */
- DEFAULT_INTERVAL = 200,
+ DEFAULT_INTERVAL = 1024,
AM_OSCILLOSCOPE = 0x93
};
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;
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.
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;
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;
DebugSender.MessagePool -> DebugMessagePool;
DebugSender.SendQueue -> DebugSendQueue;
Collector.CollectionDebug -> DebugSender;
+
+ components CC2420ActiveMessageC;
+ CC2420ActiveMessageC.SubPacket -> ActiveMessageC;
+
}
// Miscalleny:
interface Timer<TMilli>;
+ interface Timer<TMilli> as OnOffTimer;
interface Read<uint16_t>;
interface Leds;
+ interface Random;
}
}
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.
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();
if (call SerialControl.start() != SUCCESS)
fatal_problem();
+
+ running = TRUE;
+ call OnOffTimer.startOneShot(19 + (call Random.rand32() % 173));
}
event void SerialControl.startDone(error_t error) {
// 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) { }
//
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 {
//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));
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;
}
event void Send.sendDone(message_t* msg, error_t error) {
+ dbg("App", "App-level send done.\n");
if (error == SUCCESS)
report_sent();
else
#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)
#for i in range(0, 196607):
# print m1.generateNoise(i)
-for i in range(0, 2000):
+while ((t.time() / t.ticksPerSecond()) < 3000):
t.runNextEvent();