Commit b285fca9 authored by David Johnson's avatar David Johnson

New default mote src code, plus listener. Came straight from

RobTransparentBase, just modified things to blink leds differently (i.e.,
toggle the yellow led on packet receive), and to
dump original sender id, rssi, and AM type for any packet the mote hears.
There's an sflisten.c program that will decode and display these values.
It requires several of the tinyos C sf header files and code.
parent e1d0181e
// $Id: TOSBase.nc,v 1.1 2005-04-20 20:47:23 ricci Exp $
// $Id: ElabRadioDump.nc,v 1.1 2005-05-27 21:42:23 johnsond Exp $
/* tab:4
* "Copyright (c) 2000-2003 The Regents of the University of California.
......@@ -29,38 +29,41 @@
* 94704. Attention: Intel License Inquiry.
*/
/* Author: Phil Buonadonna
* Revision: $Id: TOSBase.nc,v 1.1 2005-04-20 20:47:23 ricci Exp $
* Revision: $Id: ElabRadioDump.nc,v 1.1 2005-05-27 21:42:23 johnsond Exp $
*/
/**
* @author Phil Buonadonna
*/
configuration TOSBase {
configuration ElabRadioDump {
}
implementation {
components Main, TOSBaseM, RadioCRCPacket as Comm,
components Main, ElabRadioDumpM, RadioCRCPacket as Comm,
//UARTNoCRCPacket as UART,
GenericComm as UART,
LedsC;
LedsC,
TimerC;
//FramerM, UART
Main.StdControl -> TOSBaseM;
Main.StdControl -> ElabRadioDumpM;
//TOSBaseM.UARTControl -> FramerM;
//TOSBaseM.UARTSend -> FramerM;
//TOSBaseM.UARTReceive -> FramerM;
//TOSBaseM.UARTTokenReceive -> FramerM;
TOSBaseM.UARTControl -> UART;
//TOSBaseM.UARTSend -> UART;
//TOSBaseM.UARTReceive -> UART;
TOSBaseM.UARTSend -> UART.SendMsg[42];
TOSBaseM.UARTReceive -> UART.ReceiveMsg[42];
TOSBaseM.RadioControl -> Comm;
TOSBaseM.RadioSend -> Comm;
TOSBaseM.RadioReceive -> Comm;
ElabRadioDumpM.Timer -> TimerC.Timer[unique("Timer")];
TOSBaseM.Leds -> LedsC;
//ElabRadioDumpM.UARTControl -> FramerM;
//ElabRadioDumpM.UARTSend -> FramerM;
//ElabRadioDumpM.UARTReceive -> FramerM;
//ElabRadioDumpM.UARTTokenReceive -> FramerM;
ElabRadioDumpM.UARTControl -> UART;
//ElabRadioDumpM.UARTSend -> UART;
//ElabRadioDumpM.UARTReceive -> UART;
ElabRadioDumpM.UARTSend -> UART.SendMsg[4];
ElabRadioDumpM.UARTReceive -> UART.ReceiveMsg[4];
ElabRadioDumpM.RadioControl -> Comm;
ElabRadioDumpM.RadioSend -> Comm;
ElabRadioDumpM.RadioReceive -> Comm;
ElabRadioDumpM.Leds -> LedsC;
//FramerM.ByteControl -> UART;
//FramerM.ByteComm -> UART;
......
// $Id: TOSBaseM.nc,v 1.1 2005-04-20 20:47:23 ricci Exp $
// $Id: ElabRadioDumpM.nc,v 1.1 2005-05-27 21:42:23 johnsond Exp $
/* tab:4
* "Copyright (c) 2000-2003 The Regents of the University of California.
......@@ -30,7 +30,7 @@
*/
/*
* Author: Phil Buonadonna
* Revision: $Id: TOSBaseM.nc,v 1.1 2005-04-20 20:47:23 ricci Exp $
* Revision: $Id: ElabRadioDumpM.nc,v 1.1 2005-05-27 21:42:23 johnsond Exp $
*
*
*/
......@@ -45,7 +45,7 @@
*/
module TOSBaseM {
module ElabRadioDumpM {
provides interface StdControl;
uses {
interface StdControl as UARTControl;
......@@ -58,6 +58,8 @@ module TOSBaseM {
interface BareSendMsg as RadioSend;
interface ReceiveMsg as RadioReceive;
interface Timer;
interface Leds;
}
}
......@@ -82,11 +84,30 @@ implementation
uint8_t gTxPendingToken;
uint8_t gfTxFlags;
// uint8_t timer_going = 0;
task void RadioRcvdTask() {
TOS_MsgPtr pMsg;
result_t Result;
dbg (DBG_USR1, "TOSBase forwarding Radio packet to UART\n");
// int st = 0;
/* blink yellow leds */
// atomic {
// if (!timer_going) {
// timer_going = 1;
// st = 1;
// }
// }
// if (st) {
// call Timer.start(TIMER_ONE_SHOT,128);
// call Leds.yellowOn();
// }
// we just use a toggle, in hopes that this will better illustrate speed:
call Leds.yellowToggle();
dbg (DBG_USR1, "ElabRadioDump forwarding Radio packet to UART\n");
atomic {
pMsg = gRxBufPoolTbl[gRxTailIndex];
gRxTailIndex++; gRxTailIndex %= QUEUE_SIZE;
......@@ -94,27 +115,32 @@ implementation
//*(pMsg->data) = 1;
pMsg->data[1] = pMsg->strength;
pMsg->data[2] = pMsg->strength >> 8;
pMsg->length = 3;
pMsg->data[3] = pMsg->type;
pMsg->data[4] = pMsg->addr;
pMsg->data[5] = pMsg->addr >> 8;
pMsg->length = (pMsg->length > 5)?pMsg->length:5;
Result = call UARTSend.send(TOS_UART_ADDR,pMsg->length,pMsg);
if (Result != SUCCESS) {
pMsg->length = 0;
}
else {
call Leds.redToggle();
//call Leds.redToggle();
}
}
task void UARTRcvdTask() {
result_t Result;
dbg (DBG_USR1, "TOSBase forwarding UART packet to Radio\n");
dbg (DBG_USR1, "ElabRadioDump forwarding UART packet to Radio\n");
Result = call RadioSend.send(gpTxMsg);
if (Result != SUCCESS) {
atomic gfTxFlags = 0;
}
else {
call Leds.greenToggle();
//call Leds.greenToggle();
}
}
......@@ -148,7 +174,7 @@ implementation
ok2 = call RadioControl.init();
ok3 = call Leds.init();
dbg(DBG_BOOT, "TOSBase initialized\n");
dbg(DBG_BOOT, "ElabRadioDump initialized\n");
return rcombine3(ok1, ok2, ok3);
}
......@@ -159,6 +185,10 @@ implementation
ok1 = call UARTControl.start();
ok2 = call RadioControl.start();
call Leds.greenOn();
call Timer.start(TIMER_REPEAT,1024);
return rcombine(ok1, ok2);
}
......@@ -174,7 +204,7 @@ implementation
event TOS_MsgPtr RadioReceive.receive(TOS_MsgPtr Msg) {
TOS_MsgPtr pBuf;
dbg(DBG_USR1, "TOSBase received radio packet.\n");
dbg(DBG_USR1, "ElabRadioDump received radio packet.\n");
if (Msg->crc) {
atomic {
......@@ -205,7 +235,7 @@ implementation
event TOS_MsgPtr UARTReceive.receive(TOS_MsgPtr Msg) {
TOS_MsgPtr pBuf;
dbg(DBG_USR1, "TOSBase received UART packet.\n");
dbg(DBG_USR1, "ElabRadioDump received UART packet.\n");
atomic {
if (gfTxFlags & TXFLAG_BUSY) {
......@@ -233,7 +263,7 @@ implementation
event TOS_MsgPtr UARTTokenReceive.receive(TOS_MsgPtr Msg, uint8_t Token) {
TOS_MsgPtr pBuf;
dbg(DBG_USR1, "TOSBase received UART token packet.\n");
dbg(DBG_USR1, "ElabRadioDump received UART token packet.\n");
atomic {
if (gfTxFlags & TXFLAG_BUSY) {
......@@ -281,4 +311,10 @@ implementation
}
return SUCCESS;
}
event result_t Timer.fired() {
call Leds.redToggle();
return SUCCESS;
}
}
COMPONENT=TOSBase
COMPONENT=ElabRadioDump
PFLAGS=-I%T/lib/HDLC
include ../Makerules
#include <stdio.h>
#include <stdlib.h>
#include "serialsource.h"
static char *msgs[] = {
"unknown_packet_type",
"ack_timeout" ,
"sync" ,
"too_long" ,
"too_short" ,
"bad_sync" ,
"bad_crc" ,
"closed" ,
"no_memory" ,
"unix_error"
};
void stderr_msg(serial_source_msg problem)
{
fprintf(stderr, "Note: %s\n", msgs[problem]);
}
int main(int argc, char **argv)
{
serial_source src;
if (argc != 3)
{
fprintf(stderr, "Usage: %s <device> <rate> - dump packets from a serial port\n", argv[0]);
exit(2);
}
src = open_serial_source(argv[1], atoi(argv[2]), 0, stderr_msg);
if (!src)
{
fprintf(stderr, "Couldn't open serial port at %s:%s\n",
argv[1], argv[2]);
exit(1);
}
for (;;)
{
int len, i;
const unsigned char *packet = read_serial_packet(src, &len);
int rssi_val;
int am_type;
int orig_sender;
float real_rssi;
float vdc = 3.0f;
if (!packet)
exit(0);
//for (i = 0; i < len; i++)
// printf("%02x ", packet[i]);
//printf("counter: %d RSSI: %d\n",packet[5],((packet[6] & 0xff) << 8) | (packet[7] & 0xff));
rssi_val = ((packet[7] & 0xff) << 8) | (packet[6] & 0xff);
am_type = packet[8];
orig_sender = ((packet[10] & 0xff) << 8) | (packet[9] & 0xff);
/* for mica 2, ALSO depends on the value of vdc; which for wall plugin
* is 3 VDC; for 1.5V batts it's something else
*/
real_rssi = -50.0f * (vdc * (rssi_val/1024.0f)) - 45.5f;
printf("original sender: %d; AM type: %d; RSSI: %f dBm\n",
orig_sender,
am_type,
real_rssi);
fflush(stdout);
//putchar('\n');
free((void *)packet);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment