Commit b2afc580 authored by Timothy Stack's avatar Timothy Stack

Restore some files that were removed accidentally

parent 392a66a6
// $Id: TOSBase.nc,v 1.3 2005-06-22 15:30:33 stack Exp $
/* tab:4
* "Copyright (c) 2000-2003 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."
*
* Copyright (c) 2002-2003 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: Phil Buonadonna
* Revision: $Id: TOSBase.nc,v 1.3 2005-06-22 15:30:33 stack Exp $
*/
/**
* @author Phil Buonadonna
*/
configuration TOSBase {
}
implementation {
components Main, TOSBaseM, RadioCRCPacket as Comm,
//UARTNoCRCPacket as UART,
GenericComm as UART,
LedsC;
//FramerM, UART
Main.StdControl -> TOSBaseM;
//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;
TOSBaseM.Leds -> LedsC;
//FramerM.ByteControl -> UART;
//FramerM.ByteComm -> UART;
}
// $Id: TOSBaseM.nc,v 1.3 2005-06-22 15:30:33 stack Exp $
/* tab:4
* "Copyright (c) 2000-2003 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."
*
* Copyright (c) 2002-2003 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: Phil Buonadonna
* Revision: $Id: TOSBaseM.nc,v 1.3 2005-06-22 15:30:33 stack Exp $
*
*
*/
/* TOSBaseM
- captures all the packets that it can hear and report it back to the UART
- forward all incoming UART messages out to the radio
*/
/**
* @author Phil Buonadonna
*/
module TOSBaseM {
provides interface StdControl;
uses {
interface StdControl as UARTControl;
//interface BareSendMsg as UARTSend;
interface SendMsg as UARTSend;
interface ReceiveMsg as UARTReceive;
//interface TokenReceiveMsg as UARTTokenReceive;
interface StdControl as RadioControl;
interface BareSendMsg as RadioSend;
interface ReceiveMsg as RadioReceive;
interface Leds;
}
}
implementation
{
enum {
QUEUE_SIZE = 5
};
enum {
TXFLAG_BUSY = 0x1,
TXFLAG_TOKEN = 0x2
};
TOS_Msg gRxBufPool[QUEUE_SIZE];
TOS_MsgPtr gRxBufPoolTbl[QUEUE_SIZE];
uint8_t gRxHeadIndex,gRxTailIndex;
TOS_Msg gTxBuf;
TOS_MsgPtr gpTxMsg;
uint8_t gTxPendingToken;
uint8_t gfTxFlags;
task void RadioRcvdTask() {
TOS_MsgPtr pMsg;
result_t Result;
dbg (DBG_USR1, "TOSBase forwarding Radio packet to UART\n");
atomic {
pMsg = gRxBufPoolTbl[gRxTailIndex];
gRxTailIndex++; gRxTailIndex %= QUEUE_SIZE;
}
//*(pMsg->data) = 1;
pMsg->data[1] = pMsg->strength;
pMsg->data[2] = pMsg->strength >> 8;
pMsg->length = 3;
Result = call UARTSend.send(TOS_UART_ADDR,pMsg->length,pMsg);
if (Result != SUCCESS) {
pMsg->length = 0;
}
else {
call Leds.redToggle();
}
}
task void UARTRcvdTask() {
result_t Result;
dbg (DBG_USR1, "TOSBase forwarding UART packet to Radio\n");
Result = call RadioSend.send(gpTxMsg);
if (Result != SUCCESS) {
atomic gfTxFlags = 0;
}
else {
call Leds.greenToggle();
}
}
#if 0
task void SendAckTask() {
call UARTTokenReceive.ReflectToken(gTxPendingToken);
call Leds.yellowToggle();
atomic {
gpTxMsg->length = 0;
gfTxFlags = 0;
}
}
#endif
command result_t StdControl.init() {
result_t ok1, ok2, ok3;
uint8_t i;
for (i = 0; i < QUEUE_SIZE; i++) {
gRxBufPool[i].length = 0;
gRxBufPoolTbl[i] = &gRxBufPool[i];
}
gRxHeadIndex = 0;
gRxTailIndex = 0;
gTxBuf.length = 0;
gpTxMsg = &gTxBuf;
gfTxFlags = 0;
ok1 = call UARTControl.init();
ok2 = call RadioControl.init();
ok3 = call Leds.init();
dbg(DBG_BOOT, "TOSBase initialized\n");
return rcombine3(ok1, ok2, ok3);
}
command result_t StdControl.start() {
result_t ok1, ok2;
ok1 = call UARTControl.start();
ok2 = call RadioControl.start();
return rcombine(ok1, ok2);
}
command result_t StdControl.stop() {
result_t ok1, ok2;
ok1 = call UARTControl.stop();
ok2 = call RadioControl.stop();
return rcombine(ok1, ok2);
}
event TOS_MsgPtr RadioReceive.receive(TOS_MsgPtr Msg) {
TOS_MsgPtr pBuf;
dbg(DBG_USR1, "TOSBase received radio packet.\n");
if (Msg->crc) {
atomic {
pBuf = gRxBufPoolTbl[gRxHeadIndex];
if (pBuf->length == 0) {
gRxBufPoolTbl[gRxHeadIndex] = Msg;
gRxHeadIndex++; gRxHeadIndex %= QUEUE_SIZE;
}
else {
pBuf = NULL;
}
}
if (pBuf) {
post RadioRcvdTask();
}
else {
pBuf = Msg;
}
}
else {
pBuf = Msg;
}
return pBuf;
}
event TOS_MsgPtr UARTReceive.receive(TOS_MsgPtr Msg) {
TOS_MsgPtr pBuf;
dbg(DBG_USR1, "TOSBase received UART packet.\n");
atomic {
if (gfTxFlags & TXFLAG_BUSY) {
pBuf = NULL;
}
else {
pBuf = gpTxMsg;
gfTxFlags |= (TXFLAG_BUSY);
gpTxMsg = Msg;
}
}
if (pBuf == NULL) {
pBuf = Msg;
}
else {
post UARTRcvdTask();
}
return pBuf;
}
#if 0
event TOS_MsgPtr UARTTokenReceive.receive(TOS_MsgPtr Msg, uint8_t Token) {
TOS_MsgPtr pBuf;
dbg(DBG_USR1, "TOSBase received UART token packet.\n");
atomic {
if (gfTxFlags & TXFLAG_BUSY) {
pBuf = NULL;
}
else {
pBuf = gpTxMsg;
gfTxFlags |= (TXFLAG_BUSY | TXFLAG_TOKEN);
gpTxMsg = Msg;
gTxPendingToken = Token;
}
}
if (pBuf == NULL) {
pBuf = Msg;
}
else {
post UARTRcvdTask();
}
return pBuf;
}
#endif
event result_t UARTSend.sendDone(TOS_MsgPtr Msg, result_t success) {
Msg->length = 0;
return SUCCESS;
}
event result_t RadioSend.sendDone(TOS_MsgPtr Msg, result_t success) {
if ((gfTxFlags & TXFLAG_TOKEN)) {
if (success == SUCCESS) {
//post SendAckTask();
}
}
else {
atomic {
gpTxMsg->length = 0;
gfTxFlags = 0;
}
}
return SUCCESS;
}
}
#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