From b85b5fa257ff631bce3fabf0c0608742334aab11 Mon Sep 17 00:00:00 2001 From: prabal Date: Sat, 7 Apr 2007 21:53:25 +0000 Subject: [PATCH] Initial checkin for Logging tuturial --- apps/tutorials/PacketParrot/Makefile | 2 + apps/tutorials/PacketParrot/PacketParrotC.nc | 64 ++++++++ apps/tutorials/PacketParrot/PacketParrotP.nc | 153 ++++++++++++++++++ apps/tutorials/PacketParrot/README.txt | 58 +++++++ .../tutorials/PacketParrot/volumes-at45db.xml | 4 + .../tutorials/PacketParrot/volumes-stm25p.xml | 4 + 6 files changed, 285 insertions(+) create mode 100644 apps/tutorials/PacketParrot/Makefile create mode 100644 apps/tutorials/PacketParrot/PacketParrotC.nc create mode 100644 apps/tutorials/PacketParrot/PacketParrotP.nc create mode 100644 apps/tutorials/PacketParrot/README.txt create mode 100644 apps/tutorials/PacketParrot/volumes-at45db.xml create mode 100644 apps/tutorials/PacketParrot/volumes-stm25p.xml diff --git a/apps/tutorials/PacketParrot/Makefile b/apps/tutorials/PacketParrot/Makefile new file mode 100644 index 00000000..3ae6049c --- /dev/null +++ b/apps/tutorials/PacketParrot/Makefile @@ -0,0 +1,2 @@ +COMPONENT=PacketParrotC +include $(MAKERULES) diff --git a/apps/tutorials/PacketParrot/PacketParrotC.nc b/apps/tutorials/PacketParrot/PacketParrotC.nc new file mode 100644 index 00000000..839f2042 --- /dev/null +++ b/apps/tutorials/PacketParrot/PacketParrotC.nc @@ -0,0 +1,64 @@ +/* tab:2 + * + * "Copyright (c) 2000-2007 The Regents of the University of + * California. All rights reserved. + * + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose, without fee, and without written + * agreement is hereby granted, provided that the above copyright + * notice, the following two paragraphs and the author appear in all + * copies of this software. + * + * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY + * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL + * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS + * DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE + * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF + * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, + * UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + * + */ + +/** + * Demonstrates the LogRead and LogWrite + * abstractions. The application logs packets it receives from the + * radio to flash. On a subsequent power cycle, the application + * transmits logged packets, erases the log, and then continues to log + * packets again. The red LED is on when the log is being erased. + * The blue (yellow) LED blinks when packets are being received and + * logged, and remains on when packets are being received but are not + * logged (because the log is being erased). The green LED blinks + * rapidly after a power cycle when logged packets are transmitted. + * + * @author Prabal Dutta + * @date Apr 6, 2007 + */ +#include +#include "StorageVolumes.h" + +configuration PacketParrotC { +} +implementation { + components MainC; + components LedsC; + components PacketParrotP as App; + components ActiveMessageC; + components CC2420CsmaC; + components new LogStorageC(VOLUME_LOGTEST, TRUE); + components new TimerMilliC() as Timer0; + + App.Boot -> MainC; + App.Leds -> LedsC; + App.Packet -> ActiveMessageC; + App.AMControl -> ActiveMessageC; + App.Send -> CC2420CsmaC; + App.Receive -> CC2420CsmaC; + App.LogRead -> LogStorageC; + App.LogWrite -> LogStorageC; + App.Timer0 -> Timer0; +} diff --git a/apps/tutorials/PacketParrot/PacketParrotP.nc b/apps/tutorials/PacketParrot/PacketParrotP.nc new file mode 100644 index 00000000..7281643f --- /dev/null +++ b/apps/tutorials/PacketParrot/PacketParrotP.nc @@ -0,0 +1,153 @@ +/* tab:2 + * + * "Copyright (c) 2000-2007 The Regents of the University of + * California. All rights reserved. + * + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose, without fee, and without written + * agreement is hereby granted, provided that the above copyright + * notice, the following two paragraphs and the author appear in all + * copies of this software. + * + * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY + * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL + * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS + * DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE + * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF + * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, + * UPDATES, ENHANCEMENTS, OR MODIFICATIONS." + * + */ + +/** + * Implementation of the PacketParrot application. + * + * @author Prabal Dutta + * @date Apr 6, 2007 + */ +module PacketParrotP { + uses { + interface Boot; + interface Leds; + interface Packet; + interface Send; + interface Receive; + interface SplitControl as AMControl; + interface LogRead; + interface LogWrite; + interface Timer as Timer0; + } +} +implementation { + + enum { + INTER_PACKET_INTERVAL = 25 + }; + + typedef nx_struct logentry_t { + nx_uint8_t len; + message_t msg; + } logentry_t; + + bool m_busy = TRUE; + logentry_t m_entry; + + event void Boot.booted() { + call AMControl.start(); + } + + + event void AMControl.startDone(error_t err) { + if (err == SUCCESS) { + error_t e; + do { + e = call LogRead.read(&m_entry, sizeof(logentry_t)); + } while (e != SUCCESS); + } + else { + call AMControl.start(); + } + } + + + event void AMControl.stopDone(error_t err) { + } + + + event void LogRead.readDone(void* buf, storage_len_t len, error_t err) { + if ( (len == sizeof(logentry_t)) && (buf == &m_entry) ) { + call Send.send(&m_entry.msg, m_entry.len); + call Leds.led1On(); + } + else { + error_t e; + do { + e = call LogWrite.erase(); + } while (e != SUCCESS); + call Leds.led0On(); + } + } + + + event void Send.sendDone(message_t* msg, error_t err) { + call Leds.led1Off(); + if ( (err == SUCCESS) && (msg == &m_entry.msg) ) { + error_t e; + call Packet.clear(&m_entry.msg); + do { + e = call LogRead.read(&m_entry, sizeof(logentry_t)); + } while (e != SUCCESS); + } + else { + call Timer0.startOneShot(INTER_PACKET_INTERVAL); + } + } + + + event void Timer0.fired() { + call Send.send(&m_entry.msg, m_entry.len); + } + + + event void LogWrite.eraseDone(error_t err) { + if (err == SUCCESS) { + m_busy = FALSE; + } + else { + // Handle error. + } + call Leds.led0Off(); + } + + + event message_t* Receive.receive(message_t* msg, void* payload, uint8_t len){ + call Leds.led2On(); + if (!m_busy) { + m_busy = TRUE; + m_entry.len = len; + m_entry.msg = *msg; + if (call LogWrite.append(&m_entry, sizeof(message_t)) != SUCCESS) { + m_busy = FALSE; + } + } + return msg; + } + + event void LogWrite.appendDone(void* buf, storage_len_t len, + bool recordsLost, error_t err) { + m_busy = FALSE; + call Leds.led2Off(); + } + + event void LogRead.seekDone(error_t err) { + } + + event void LogWrite.syncDone(error_t err) { + } + +} diff --git a/apps/tutorials/PacketParrot/README.txt b/apps/tutorials/PacketParrot/README.txt new file mode 100644 index 00000000..ca228f16 --- /dev/null +++ b/apps/tutorials/PacketParrot/README.txt @@ -0,0 +1,58 @@ +$Id$ + +README for PacketParrot + +Author/Contact: + + tinyos-help@millennium.berkeley.edu + +Description: + + PacketParrot demonstrates use of LogWrite and LogRead abstractions. + A node writes received packets to a circular log and retransmits the + logged packets (or at least the part of the packets above the AM + layer) when power cycled. + + The application logs packets it receives from the radio to flash. + On a subsequent power cycle, the application transmits logged + packets, erases the log, and then continues to log packets again. + The red LED is on when the log is being erased. The blue (yellow) + LED turns on when a packets is received and turns off when a packet + has been logged. The blue (yellow) LED remains on when packets are + being received but are not logged (because the log is being erased). + The green LED flickers rapidly after a power cycle when logged + packets are transmitted. + + To use this application: + + (i) Program one node (the "parrot") with this application using + the typical command (e.g. make telosb install) + (ii) Program a second node with the BlinkToRadio application. + (iii) Turn the parrot node on. The red LED will turn on briefly, + indicating that the flash volume is being erased. + (iv) Turn the second node on. Nothing should happen on the second + node but the blue (yellow) LED on the parrot node should start + to blink, indicating it is receiving packets and logging them + to flash. + (v) After a few tens of seconds, focus you attention on the second + node's LEDs and then power cycle the parrot node. The LEDs on + the second node should rapidly flash as if they were displaying + the three low-order bits of a counter. At the same time, the + green LED on the parrot node should flicker rapidly, in unison + with the LEDs on the second node, indicating that packets are + being transmitted. + (vi) Repeat step (v) a few times and notice that the parrot's blue + (yellow) LED turns on and doesn't turn off until just a bit + after the red LED, indicating that one or more packets were + received (the LED turned on) but these packets were not logged + (since the LED does not turn off) because the log is being + erased. + +Tools: + + None + +Known bugs/limitations: + + Only works on motes with the CC2420 radio. Known to work with + TelosB and Tmote nodes but currently flaky on the MicaZ nodes. diff --git a/apps/tutorials/PacketParrot/volumes-at45db.xml b/apps/tutorials/PacketParrot/volumes-at45db.xml new file mode 100644 index 00000000..7cc59802 --- /dev/null +++ b/apps/tutorials/PacketParrot/volumes-at45db.xml @@ -0,0 +1,4 @@ + + + + diff --git a/apps/tutorials/PacketParrot/volumes-stm25p.xml b/apps/tutorials/PacketParrot/volumes-stm25p.xml new file mode 100644 index 00000000..adce9924 --- /dev/null +++ b/apps/tutorials/PacketParrot/volumes-stm25p.xml @@ -0,0 +1,4 @@ + + + + -- 2.39.2