I am facing problem of retaining values in an array, while running a NESC program.
I am trying to store the nodeid and the timestamp of receving the message in an array of strucutre
Below is the code for the same
+++++++++++++++++++++++++++++++
//nodeInfo nodeEntry[3];
module SimpleMessageM {
provides {
interface StdControl;
}
uses {
interface ReceiveMsg as RcvSimpleMsg;
interface SendMsg as SndSimpleMsg;
interface Timer as SendTimer;
interface Time as checktime;
interface Random;
}
}
implementation {
enum {RADIO_BUSY=0, RADIO_FREE=1};
uint8_t txState;
TOS_Msg out;
uint8_t sequenceNo;
uint8_t fired;
uint32_t localtime ;
uint32_t s;
uint32_t p;
TOS_Msg processedMsgBuffer;
TOS_MsgPtr processedMsg;
nodeInfo nodeEntry[3];
uint32_t s2;
uint32_t s0;
enum {
STATE_IDLE = 0x00,
STATE_PROCESSING = 0x01,
STATE_SENDING = 0x02,
STATE_INIT = 0x04,
};
uint8_t last_id;
command result_t StdControl.init() {
int i = 0;
txState = RADIO_FREE;
sequenceNo = 0;
//processedMsg = &processedMsgBuffer;
for (i=0;i<3;i++)
nodeEntry[i].nodeId=0xFFFF;
dbg(DBG_USR1,"Init. SimpleMessage initialized\n");
return SUCCESS;
}
command result_t StdControl.start() {
//call SendTimer.start(TIMER_REPEAT,512 + TOS_LOCAL_ADDRESS * 1024);
call SendTimer.start(TIMER_ONE_SHOT,512 + TOS_LOCAL_ADDRESS * 1024);
dbg(DBG_USR1,"SimpleMessage started\n");
return SUCCESS;
}
command result_t StdControl.stop() {
int i,j;
call SendTimer.stop();
return SUCCESS;
}
task void sendSimpleMsg() {
SimpleMsgPtr simpleMsgPtr;
result_t retval;
simpleMsgPtr = (SimpleMsgPtr)(out.data);
simpleMsgPtr->sourceId = TOS_LOCAL_ADDRESS;
simpleMsgPtr->sequenceNo = sequenceNo++;
simpleMsgPtr->levelNo = 0;
retval = call SndSimpleMsg.send(TOS_BCAST_ADDR,sizeof(struct SimpleMsg),&out);
if (retval != SUCCESS) {
atomic {
sequenceNo--;
txState = RADIO_FREE;
}
dbg(DBG_USR1,"Failed to queue message for send\n");
}
}
event result_t SndSimpleMsg.sendDone( TOS_MsgPtr pmsg, result_t success ) {
uint8_t sn;
atomic {
txState = RADIO_FREE;
sn = sequenceNo - 1;
}
dbg(DBG_USR1,"Sent message \%x \n",sn);
return SUCCESS;
}
void processMsg()
{
SimpleMsgPtr mptr,simpleMsgPtr ;
result_t retval;
int i;
mptr = (SimpleMsgPtr)(processedMsg ->data);
for (i=0;i<3;i++)
{
if (nodeEntry[i].nodeId == 0xffff)
{
if(i == TOS_LOCAL_ADDRESS)
{
atomic{
nodeEntry[i].nodeId=i;
nodeEntry[i].broadAT = s;
}
dbg(DBG_USR1,"putting inside processmsg %x %i\n",nodeEntry[TOS_LOCAL_ADDRESS].nodeId,s);
break;
}
}
}
simpleMsgPtr = (SimpleMsgPtr)(out.data);
simpleMsgPtr->sourceId = TOS_LOCAL_ADDRESS;
simpleMsgPtr->sequenceNo = sequenceNo++;
simpleMsgPtr->levelNo = 0;
retval = call SndSimpleMsg.send(mptr->sourceId,sizeof(struct SimpleMsg),&out);
dbg(DBG_USR1,"Inside ProcessMsg source: %x sending to %x\n",TOS_LOCAL_ADDRESS,mptr->sourceId);
}
void processMsgonly()
{
SimpleMsgPtr mptr,simpleMsgPtr ;
result_t retval;
atomic{
int i,j;
mptr = (SimpleMsgPtr)(processedMsg ->data);
if (nodeEntry[TOS_LOCAL_ADDRESS].nodeId == 0xffff || TOS_LOCAL_ADDRESS == 1)
{
nodeEntry[TOS_LOCAL_ADDRESS].nodeId=TOS_LOCAL_ADDRESS;
nodeEntry[TOS_LOCAL_ADDRESS].neigh[mptr->sourceId] = s;
} }
}
event TOS_MsgPtr RcvSimpleMsg.receive(TOS_MsgPtr pmsg ) {
TOS_MsgPtr old = processedMsg;
//int i=0,j=0;
SimpleMsgPtr mptr = (SimpleMsgPtr)(pmsg->data);
SimpleMsgPtr oldptr=(SimpleMsgPtr)(old->data);
processedMsg = pmsg;
//dbg(DBG_USR1,"Old-Node \%x : Received messsage \%x from source \%x \n",TOS_LOCAL_ADDRESS,oldptr->sequenceNo,oldptr->sourceId);
dbg(DBG_USR1,"Node \%x : Received messsage \%x from source \%x \n",TOS_LOCAL_ADDRESS,mptr->sequenceNo,mptr->sourceId);
last_id=fired;
dbg(DBG_USR1,"last id %x\n",last_id);
s= call checktime.getLow32();
p= call checktime.getHigh32();
dbg(DBG_USR1,"time %i %i\n",s,p);
if (mptr->sourceId == 1 )
{
processMsg();
}
else
processMsgonly();
//if (TOS_LOCAL_ADDRESS== 1 && mptr->sourceId == 2)
//{
atomic{
int i=0,j=0;
for (i=0;i<3;i++)
{
dbg(DBG_USR1,"\nNODEID for i=%d: %x \n ",i,nodeEntry[i].nodeId);
dbg(DBG_USR1,":BROADCAST ARRIVAL %i\n",nodeEntry[i].broadAT);
//if (i==1)
//{
//for (j=0;j<3;j++)
//dbg(DBG_USR1,":UNICAST ARRIVAL %i\n", nodeEntry[i].neigh[j]);
// }
}
}
//}
return pmsg;
//return old;
}
event result_t SendTimer.fired() {
if(txState == RADIO_FREE) {
atomic {
txState = RADIO_BUSY;
}
dbg(DBG_USR1,"Posting task to send message\n");
++fired;
post sendSimpleMsg();
}
return SUCCESS;
}
}
+++++++++++++++++++++++++++++++++++++
why are values not getting stored in nodeEntry array of strucutre, it only reflects the value for TOS_LOCAL_ADDRESS as index.
Thanks & Regards,
Neeta
_______________________________________________ Tinyos-help mailing list [email protected] https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
