Assuming that this line in RadioReceive.receive()
is the only change you made:
gRxBufPoolTbl[gRxHeadIndex] ->data[20] = Msg->strength;
It oughta work...but I wonder if the CRC needs to be recalculated?
Look through the UART send code and see if it thinks it can just
leave it alone. If so you'll have to figure out how to recalculate it.
The data[20] thing may walk on some byte of data in the
message payloads being sent, so it's not a transparent solution...
MS
vinayak elangovan wrote:
Hi Every1,
I am trying to get the signal strength reading from the motes and so i
modified the TOSBase program with reference to the available source
codes in the net. the program is getting compiled but i am not getting
any result when i run the OscilloscopeRF program. Its getting struck,
[EMAIL PROTECTED]:57600 <mailto:[EMAIL PROTECTED]:57600> resynchronising..... and
its not printing anything.
Can any1 please verify the code and let me know what the mistake is.
Since i am very new to tinyOS, i need lot of help from you all.
Thanks All in advance.
#ifndef TOSBASE_BLINK_ON_DROP
#define TOSBASE_BLINK_ON_DROP
#endif
module TOSBaseM {
provides interface StdControl;
uses {
interface StdControl as UARTControl;
interface BareSendMsg 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 {
UART_QUEUE_LEN = 12,
RADIO_QUEUE_LEN = 12,
QUEUE_SIZE = 5,
};
TOS_Msg uartQueueBufs[UART_QUEUE_LEN];
TOS_MsgPtr uartQueue[UART_QUEUE_LEN];
TOS_MsgPtr gRxBufPoolTbl[QUEUE_SIZE];
uint16_t gRxHeadIndex;
uint8_t uartIn, uartOut;
bool uartBusy, uartFull;
TOS_Msg radioQueueBufs[RADIO_QUEUE_LEN];
TOS_MsgPtr radioQueue[RADIO_QUEUE_LEN];
uint8_t radioIn, radioOut;
bool radioBusy, radioFull;
uint16_t strength;
task void UARTSendTask();
task void RadioSendTask();
task void RadioRcvdTask();
void failBlink();
void dropBlink();
command result_t StdControl.init() {
result_t ok1, ok2, ok3;
uint8_t i;
for (i = 0; i < UART_QUEUE_LEN; i++) {
uartQueue[i] = &uartQueueBufs[i];
}
uartIn = uartOut = 0;
uartBusy = FALSE;
uartFull = FALSE;
for (i = 0; i < RADIO_QUEUE_LEN; i++) {
radioQueue[i] = &radioQueueBufs[i];
}
radioIn = radioOut = 0;
radioBusy = FALSE;
radioFull = FALSE;
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) {
if(Msg->group != TOS_AM_GROUP)
return Msg;
atomic {
pBuf = gRxBufPoolTbl[gRxHeadIndex];
if (pBuf->length == 0) {
gRxBufPoolTbl[gRxHeadIndex] = Msg;
gRxBufPoolTbl[gRxHeadIndex] ->data[20] = Msg->strength;
gRxHeadIndex++; gRxHeadIndex %= QUEUE_SIZE;
}
else{
pBuf = NULL;
}
}
if (pBuf){
post RadioRcvdTask();
}
else {
pBuf = Msg;
}
}
else {
pBuf = Msg;
}
return pBuf;
}
task void UARTSendTask() {
bool noWork = FALSE;
dbg (DBG_USR1, "TOSBase forwarding Radio packet to UART\n");
atomic {
if (uartIn == uartOut && uartFull == FALSE) {
uartBusy = FALSE;
noWork = TRUE;
}
}
if (noWork) {
return;
}
if (call UARTSend.send(uartQueue[uartOut]) == SUCCESS) {
call Leds.greenToggle();
} else {
failBlink();
post UARTSendTask();
}
}
event result_t UARTSend.sendDone(TOS_MsgPtr msg, result_t success) {
if (!success) {
failBlink();
} else {
atomic {
if (msg == uartQueue[uartOut]) {
if( ++uartOut >= UART_QUEUE_LEN ) uartOut = 0;
if (uartFull) {
uartFull = FALSE;
}
}
}
}
post UARTSendTask();
return SUCCESS;
}
event TOS_MsgPtr UARTReceive.receive(TOS_MsgPtr Msg) {
return Msg;
}
event TOS_MsgPtr UARTTokenReceive.receive(TOS_MsgPtr Msg, uint8_t Token) {
TOS_MsgPtr pBuf = Msg;
bool reflectToken = FALSE;
dbg(DBG_USR1, "TOSBase received UART token packet.\n");
atomic {
if (!radioFull) {
reflectToken = TRUE;
pBuf = radioQueue[radioIn];
radioQueue[radioIn] = Msg;
if( ++radioIn >= RADIO_QUEUE_LEN ) radioIn = 0;
if (radioIn == radioOut)
radioFull = TRUE;
if (!radioBusy) {
if (post RadioRcvdTask()) {
radioBusy = TRUE;
}
}
} else {
dropBlink();
}
}
if (reflectToken) {
call UARTTokenReceive.ReflectToken(Token);
}
return pBuf;
}
task void RadioRcvdTask() {
bool noWork = FALSE;
dbg (DBG_USR1, "TOSBase forwarding UART packet to Radio\n");
atomic {
if (radioIn == radioOut && radioFull == FALSE) {
radioBusy = FALSE;
noWork = TRUE;
}
}
if (noWork)
return;
radioQueue[radioOut]->group = TOS_AM_GROUP;
if (call RadioSend.send(radioQueue[radioOut]) == SUCCESS) {
call Leds.redToggle();
} else {
failBlink();
post RadioRcvdTask();
}
}
event result_t RadioSend.sendDone(TOS_MsgPtr msg, result_t success) {
if (!success) {
failBlink();
} else {
atomic {
if (msg == radioQueue[radioOut]) {
if( ++radioOut >= RADIO_QUEUE_LEN ) radioOut = 0;
if (radioFull)
radioFull = FALSE;
}
}
}
post RadioRcvdTask();
return SUCCESS;
}
void dropBlink() {
#ifdef TOSBASE_BLINK_ON_DROP
call Leds.yellowToggle();
#endif
}
void failBlink() {
#ifdef TOSBASE_BLINK_ON_FAIL
call Leds.yellowToggle();
#endif
}
}
------------------------------------------------------------------------
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help