[Tinyos-2-commits] CVS: tinyos-2.x/apps/MViz .cvsignore, NONE,
1.1.2.1 DemoSensorC.nc, NONE, 1.1.2.1 MViz.h, NONE,
1.1.2.1 MVizAppC.nc, NONE, 1.1.2.1 MVizC.nc, NONE,
1.1.2.1 Makefile, NONE, 1.1.2.1 README.txt, NONE, 1.1.2.1
Phil Levis
scipio at users.sourceforge.net
Tue Oct 24 18:54:46 PDT 2006
Update of /cvsroot/tinyos/tinyos-2.x/apps/MViz
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv23136/MViz
Added Files:
Tag: tinyos-2_0_devel-BRANCH
.cvsignore DemoSensorC.nc MViz.h MVizAppC.nc MVizC.nc Makefile
README.txt
Log Message:
MViz app.
--- NEW FILE: .cvsignore ---
build .*.swp
--- NEW FILE: DemoSensorC.nc ---
/* $Id: DemoSensorC.nc,v 1.1.2.1 2006/10/25 01:54:44 scipio Exp $
* Copyright (c) 2006 Intel Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached INTEL-LICENSE
* file. If you do not find these files, copies can be found by writing to
* Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
* 94704. Attention: Intel License Inquiry.
*/
/**
* The micaZ doesn't have any built-in sensors - the DemoSensor returns
* a constant value of 0xbeef, or just reads the ground value for the
* stream sensor.
*
* @author Philip Levis
* @authod David Gay
*/
generic module DemoSensorC()
{
provides interface Init;
provides interface Read<uint16_t>;
}
implementation {
uint32_t counter;
command error_t Init.init() {
counter = TOS_NODE_ID * 40;
return SUCCESS;
}
task void readTask() {
float val = (float)counter;
val = val / 100.0;
val = sin(val) * 4096.0;
val += 8192.0;
counter++;
signal Read.readDone(SUCCESS, (uint16_t)val);
}
command error_t Read.read() {
post readTask();
return SUCCESS;
}
}
--- NEW FILE: MViz.h ---
/*
* Copyright (c) 2006 Intel Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached INTEL-LICENSE
* file. If you do not find these files, copies can be found by writing to
* Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
* 94704. Attention: Intel License Inquiry.
*/
/**
* @author David Gay
* @author Kyle Jamieson
* @author Phil Levis
*/
#ifndef MVIZ_H
#define MVIZ_H
enum {
/* Default sampling period. */
DEFAULT_INTERVAL = 256,
AM_MVIZ = 0x93
};
typedef nx_struct oscilloscope {
nx_uint16_t version; /* Version of the interval. */
nx_uint16_t interval; /* Samping period. */
nx_uint16_t origin; /* Mote id of sending mote. */
nx_uint16_t count; /* The readings are samples count * NREADINGS onwards */
nx_uint16_t reading;
} oscilloscope_t;
#endif
--- NEW FILE: MVizAppC.nc ---
/*
* Copyright (c) 2006 Intel Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached INTEL-LICENSE
* file. If you do not find these files, copies can be found by writing to
* Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
* 94704. Attention: Intel License Inquiry.
*/
/**
* MViz demo application using the collection layer.
* See README.txt file in this directory and TEP 119: Collection.
*
* @author David Gay
* @author Kyle Jamieson
* @author Philip Levis
*/
configuration MVizC { }
implementation {
components MainC, MVizC, LedsC, new TimerMilliC(),
new DemoSensorC() as Sensor;
//MainC.SoftwareInit -> Sensor;
MVizC.Boot -> MainC;
MVizC.Timer -> TimerMilliC;
MVizC.Read -> Sensor;
MVizC.Leds -> LedsC;
//
// Communication components. These are documented in TEP 113:
// Serial Communication, and TEP 119: Collection.
//
components CollectionC as Collector, // Collection layer
ActiveMessageC, // AM layer
new CollectionSenderC(AM_MVIZ), // Sends multihop RF
SerialActiveMessageC, // Serial messaging
new SerialAMSenderC(AM_MVIZ); // Sends to the serial port
MVizC.RadioControl -> ActiveMessageC;
MVizC.SerialControl -> SerialActiveMessageC;
MVizC.RoutingControl -> Collector;
MVizC.Send -> CollectionSenderC;
MVizC.SerialSend -> SerialAMSenderC.AMSend;
MVizC.Snoop -> Collector.Snoop[AM_MVIZ];
MVizC.Receive -> Collector.Receive[AM_MVIZ];
MVizC.RootControl -> Collector;
//
// Components for debugging collection.
//
components new PoolC(message_t, 10) as DebugMessagePool,
new QueueC(message_t*, 10) as DebugSendQueue,
new SerialAMSenderC(AM_CTP_DEBUG) as DebugSerialSender,
UARTDebugSenderP as DebugSender;
DebugSender.Boot -> MainC;
DebugSender.UARTSend -> DebugSerialSender;
DebugSender.MessagePool -> DebugMessagePool;
DebugSender.SendQueue -> DebugSendQueue;
Collector.CollectionDebug -> DebugSender;
}
--- NEW FILE: MVizC.nc ---
/*
* Copyright (c) 2006 Intel Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached INTEL-LICENSE
* file. If you do not find these files, copies can be found by writing to
* Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
* 94704. Attention: Intel License Inquiry.
*/
/**
* MViz demo application using the collection layer.
* See README.txt file in this directory and TEP 119: Collection.
*
* @author David Gay
* @author Kyle Jamieson
* @author Philip Levis
*/
#include "MViz.h"
module MVizC {
uses {
// Interfaces for initialization:
interface Boot;
interface SplitControl as RadioControl;
interface SplitControl as SerialControl;
interface StdControl as RoutingControl;
// Interfaces for communication, multihop and serial:
interface Send;
interface Receive as Snoop;
interface Receive;
interface AMSend as SerialSend;
interface CollectionPacket;
interface RootControl;
// Miscalleny:
interface Timer<TMilli>;
interface Read<uint16_t>;
interface Leds;
}
}
implementation {
task void uartSendTask();
static void startTimer();
static void fatal_problem();
static void report_problem();
static void report_sent();
static void report_received();
uint8_t uartlen;
message_t sendbuf;
message_t uartbuf;
bool sendbusy=FALSE, uartbusy=FALSE;
/* Current local state - interval, version and accumulated readings */
oscilloscope_t local;
uint8_t reading; /* 0 to NREADINGS */
/* When we head an Oscilloscope message, we check it's sample count. If
it's ahead of ours, we "jump" forwards (set our count to the received
count). However, we must then suppress our next count increment. This
is a very simple form of "time" synchronization (for an abstract
notion of time). */
bool suppress_count_change;
//
// On bootup, initialize radio and serial communications, and our
// own state variables.
//
event void Boot.booted() {
local.interval = DEFAULT_INTERVAL;
local.origin = TOS_NODE_ID;
// Beginning our initialization phases:
if (call RadioControl.start() != SUCCESS)
fatal_problem();
if (call RoutingControl.start() != SUCCESS)
fatal_problem();
}
event void RadioControl.startDone(error_t error) {
if (error != SUCCESS)
fatal_problem();
if (sizeof(local) > call Send.maxPayloadLength())
fatal_problem();
if (call SerialControl.start() != SUCCESS)
fatal_problem();
}
event void SerialControl.startDone(error_t error) {
if (error != SUCCESS)
fatal_problem();
// This is how to set yourself as a root to the collection layer:
if (local.id % 500 == 0)
call RootControl.setRoot();
startTimer();
}
static void startTimer() {
call Timer.startPeriodic(local.interval);
reading = 0;
}
event void RadioControl.stopDone(error_t error) { }
event void SerialControl.stopDone(error_t error) { }
//
// Only the root will receive messages from this interface; its job
// is to forward them to the serial uart for processing on the pc
// connected to the sensor network.
//
event message_t*
Receive.receive(message_t* msg, void *payload, uint8_t len) {
if (uartbusy == FALSE) {
oscilloscope_t* in = (oscilloscope_t*)payload;
oscilloscope_t* out = (oscilloscope_t*)call SerialSend.getPayload(&uartbuf);
if (len != sizeof(oscilloscope_t)) {
return msg;
}
else {
memcpy(out, in, sizeof(oscilloscope_t));
}
uartbusy = TRUE;
uartlen = sizeof(oscilloscope_t);
post uartSendTask();
}
return msg;
}
task void uartSendTask() {
if (call SerialSend.send(0xffff, &uartbuf, uartlen) != SUCCESS) {
uartbusy = FALSE;
}
}
//
// Overhearing other traffic in the network.
//
event message_t*
Snoop.receive(message_t* msg, void* payload, uint8_t len) {
oscilloscope_t *omsg = payload;
report_received();
// If we receive a newer version, update our interval.
if (omsg->version > local.version) {
local.version = omsg->version;
local.interval = omsg->interval;
startTimer();
}
// If we hear from a future count, jump ahead but suppress our own
// change.
if (omsg->count > local.count) {
local.count = omsg->count;
suppress_count_change = TRUE;
}
return msg;
}
/* At each sample period:
- if local sample buffer is full, send accumulated samples
- read next sample
*/
event void Timer.fired() {
if (!sendbusy) {
oscilloscope_t *o = (oscilloscope_t *)call Send.getPayload(&sendbuf);
memcpy(o, &local, sizeof(local));
if (call Send.send(&sendbuf, sizeof(local)) == SUCCESS)
sendbusy = TRUE;
else
report_problem();
}
reading = 0;
/* Part 2 of cheap "time sync": increment our count if we didn't
jump ahead. */
if (!suppress_count_change)
local.count++;
suppress_count_change = FALSE;
if (call Read.read() != SUCCESS)
fatal_problem();
}
event void Send.sendDone(message_t* msg, error_t error) {
if (error == SUCCESS)
report_sent();
else
report_problem();
sendbusy = FALSE;
}
event void Read.readDone(error_t result, uint16_t data) {
if (result != SUCCESS) {
data = 0xffff;
report_problem();
}
local.reading = data;
}
event void SerialSend.sendDone(message_t *msg, error_t error) {
uartbusy = FALSE;
}
// Use LEDs to report various status issues.
static void fatal_problem() {
call Leds.led0On();
call Leds.led1On();
call Leds.led2On();
call Timer.stop();
}
static void report_problem() { call Leds.led0Toggle(); }
static void report_sent() { call Leds.led1Toggle(); }
static void report_received() { call Leds.led2Toggle(); }
}
--- NEW FILE: Makefile ---
COMPONENT=MultihopOscilloscopeAppC
CFLAGS += -I$(TOSDIR)/lib/net/ -I$(TOSDIR)/lib/net/ctp -I$(TOSDIR)/lib/net/le -I.
include $(MAKERULES)
--- NEW FILE: README.txt ---
README for MultihopOscilloscope
Author/Contact: tinyos-help at millennium.berkeley.edu
Description:
MultihopOscilloscope is a simple data-collection demo. It periodically samples
the default sensor and broadcasts a message every few readings. These readings
can be displayed by the Java "Oscilloscope" application found in the
TOSROOT/apps/Oscilloscope/java subdirectory. The sampling rate starts at 4Hz,
but can be changed from the Java application.
You can compile MultihopOscilloscope with a sensor board's default sensor by
compiling as follows:
SENSORBOARD=<sensorboard name> make <mote>
You can change the sensor used by editing MultihopOscilloscopeAppC.nc.
Tools:
The Java application displays readings it receives from motes running the
MultihopOscilloscope demo via a serial forwarder. To run it, change to the
TOSROOT/apps/Oscilloscope/java subdirectory and type:
make
java net.tinyos.sf.SerialForwarder -comm serial@<serial port>:<mote>
# e.g., java net.tinyps.sf.SerialForwarder -comm serial@/dev/ttyUSB0:mica2
# or java net.tinyps.sf.SerialForwarder -comm serial at COM2:telosb
./run
The controls at the bootom of the screen allow yoy to zoom in or out the X
axis, change the range of the Y axis, and clear all received data. You can
change the color used to display a mote by clicking on its color in the
mote table.
Known bugs/limitations:
None.
See also:
TEP 113: Serial Communications, TEP 119: Collection.
Notes:
MultihopOscilloscope configures a mote whose TOS_NODE_ID modulo 500 is zero
to be a collection root.
More information about the Tinyos-2-commits
mailing list