Hello Everyone,
I'm using a nesC application to send some messages between two Tmote Sky
nodes. My application consists of the following message structure.
typedef struct{
uint8_t source;
uint8_t destination;
uint8_t sequence_no;
uint8_t payload[PAYLOAD];
} Msgbody_t;
where PAYLOAD value is 24...
One node starts generating these messages upon the expiration of a timer and
transmits them over the radio, when the other node receives this messages it
forwards the messages to the UART...
But the at the serial forwarder of the receiving node, i have the following
problems.
1. TOS_Msg length is invalid : header length = 10, real_length = 37..
modifying message to fit.
2. Received message 00 01 08 F3 FF FF 7E 00 01 7D 64 63 EC 61 62 63 64 65 66
67 68 69 6A 6B 6D 6E 6F 70 71 72 73 74 75 76 77 78
Below is the nesC code of my application.
#include<AM.h>
#include <stdio.h>
module TestM{
provides interface StdControl;
uses interface Leds;
uses interface Timer;
uses interface SendMsg;
uses interface ReceiveMsg;
uses interface SendMsg as SendUART;
uses interface ReceiveMsg as ReceiveUART;
}
implementation{
// C:\cygwin\opt\moteiv\tos\lib\CC2420Radio - Modify the payload size here
//#define PAYLOAD (TOSH_DATA_LENGTH - 3) //number of payload bytes is 113
per packet
#define SOURCE_ID 1 //this node listens to the UART for packets
#define PAYLOAD 24 //number of payload bytes per packet, maximum 24
#define TARGET_ID 99 //this node forwards received packets to the UART
#define TEST_ID 100 //this node generates packets using a timer
*// structure of the data packet*
typedef struct{
uint8_t source;
uint8_t destination;
uint8_t sequence_no;
uint8_t payload[PAYLOAD];
} Msgbody_t;
TOS_Msg message;
uint8_t sequenceCounter;
*command result_t StdControl.init() *{
call Leds.init();
sequenceCounter = 0;
return SUCCESS;
}
*command result_t StdControl.start()* {
//test node sends a packet every 50msec when the timer expires
if (TOS_LOCAL_ADDRESS == TEST_ID)
call Timer.start(TIMER_REPEAT,50);
return SUCCESS;
}
*command result_t StdControl.stop()* {
return call Timer.stop();
}
*//when timer is fired we send packets over the radio*
*event result_t Timer.fired()*
{
int i;
static TOS_Msg packet;// TOS msg
Msgbody_t* data = (Msgbody_t*)packet.data;
packet.length = sizeof(Msgbody_t)+10;
sequenceCounter+=2;
data->source = TOS_LOCAL_ADDRESS;
data->destination = TARGET_ID;
data->sequence_no = sequenceCounter;
* //create some dummy payload*
//fill
for (i=0; i<PAYLOAD ; i++)
data->payload[i] = 'a'+ (i % 26);
//add some data
//sprintf((char *)data->payload,"p:%i from %i to
%i\n",data->sequence_no,data->source,data->destination);
if (call SendMsg.send(TOS_BCAST_ADDR, sizeof(Msgbody_t), &packet) ==
SUCCESS)
call Leds.yellowToggle();
else
call Leds.yellowToggle();
return SUCCESS;
}
*//when a packet is sent this event takes place*
*event result_t SendMsg.sendDone(TOS_MsgPtr msg, result_t success )*
{
call Leds.yellowToggle();
return SUCCESS;
}
*//receiving the packets over the radio and sending to the UART*
*event TOS_MsgPtr ReceiveMsg.receive(TOS_MsgPtr packet ){*
Msgbody_t* data = (Msgbody_t*)packet->data;
call Leds.redOn();
//have we processed this packet already?
if ((uint8_t)((data->sequence_no) - sequenceCounter) >= 128)
return packet;
//update sequence counter
sequenceCounter = data->sequence_no;
//are we the final destination?
if ((TOS_LOCAL_ADDRESS == TARGET_ID) && (data->destination ==
TOS_LOCAL_ADDRESS)) {
if (call SendUART.send(TOS_UART_ADDR, sizeof(Msgbody_t), packet) ==
SUCCESS)
call Leds.greenOn();
else
call Leds.greenOff();
return packet;
}
//otherwise route forward
//simple flooding
data->destination = TARGET_ID;
if (call SendMsg.send(TOS_BCAST_ADDR, sizeof(Msgbody_t), packet) ==
SUCCESS)
call Leds.yellowOn(); //yellow is a blue led on Tmote
else
call Leds.yellowOff();
return packet;
}
*//Sending packets through the UART*
* event result_t SendUART.sendDone( TOS_MsgPtr msg, result_t success )*
{
call Leds.yellowToggle();
return SUCCESS;
}
*// Receiving packets through the UART*
*event TOS_MsgPtr ReceiveUART.receive( TOS_MsgPtr packet )*
{
int j;
Msgbody_t* data = (Msgbody_t*)message.data;
call Leds.greenOn();
return packet;
for(j =0;j<24;j++){
data->payload[j] = packet->data[j];}
sequenceCounter++;
data->source = TOS_LOCAL_ADDRESS;
data->destination = TARGET_ID;
data->sequence_no = sequenceCounter;
if (call SendMsg.send(TOS_BCAST_ADDR, sizeof(Msgbody_t), &message) ==
SUCCESS)
call Leds.redOn();
else
call Leds.yellowOn();
}
} //end of the module
Hope you can understand the code and reply....
with regards
--
Siva Sankar Gupta Guggilum
Schubertstraße 19
Klagenfurt,9020
Austria
Ph:- 0043 6606871071
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help