Hi Folks, I am trying to write a piece of code in which I need a "remote control" to broadcast several commands to a bunch of nodes and each of them has to handle this message to figure out if there is any action for it.
Assuming the remote control send the command "START_EMISSION" asking to
the node with id "x" to send "SAMPLES" times of an hello msg. This is the
portion of code I wrote for the node "x". It is supposed to be a
dispatcher to decide which is the proper action associated to a given
command.
/* When a msg is received its payload is copied in a local global
structure and
the dispatcher is called */
event message_t* AMProtoReceive.receive(message_t* msg, void* payload,
uint8_t len) {
Protocol_Msg *btrpkt = (Protocol_Msg*)(call
AMProtoPacket.getPayload(msg, NULL));
atomic {
P_payload.protocol_id = btrpkt->protocol_id;
P_payload.parameter_1 = btrpkt->parameter_1;
P_payload.parameter_2 = btrpkt->parameter_2;
}
post protocol_msg_handler();
return SUCCESS;
}
/* The Dispacher realizes the command START_EMISSION has been received
and the startEmission task is posted */
task void protocol_msg_handler(){
switch(P_payload.protocol_id) {
case START_EMISSION: {
if (P_payload.parameter_1 == TOS_NODE_ID) {
train = P_payload.parameter_2;
sample=SAMPLES;
call Leds.led1On();
post startEmission();
}
break;
}
case SEND_DATA: {
if (P_payload.parameter_1 == TOS_NODE_ID)
post sendData();
break;
}
}
}
/* This task simply start a periodic time where TIMER_PERIOD_EMISSION is the
the period at which the hello msg has to be sent */
task void startEmission() {
call Timer0.startPeriodic(TIMER_PERIOD_EMISSION);
}
/* Each step the period is expired the emissionRadio is posted */
event void Timer0.fired() {
call Leds.led0Toggle();
post emissionRadio();
}
/* The hello msg is built and then it is sent */
task void emissionRadio(){
if (sample>0) {
DTOA_Msg *btrpkt = (DTOA_Msg*)(call
AMDTOAPacket.getPayload(&pktDTOA, NULL));
btrpkt->node_id=sample;
call AMDTOASend.send(AM_BROADCAST_ADDR, &pktDTOA, sizeof(DTOA_Msg));
}
else{
call Timer0.stop();
}
}
/* After the confermation of the send of the msg the number of samples is
decreased */
event void AMProtoSend.sendDone(message_t* msg, error_t error) {
atomic sample--;
}
The problem is that after the first hello msg is sent the node "stucks"
and I don't understand why. Can anybody help me?
Thank you,
Andrea
P.S.: In attachment the full source code if you are interested.
-----------------------------------------
This email was sent using SquirrelMail.
https://email.dia.uniroma3.it
Web Site: http://www.squirrelmail.org/
NodeAppC.nc
Description: Cdf file
NodeC.nc
Description: Cdf file
#ifndef PARAMETERS_H
#define PARAMETERS_H
/* ID nodes */
enum {
BASE_STATION=0,
REMOTE_CONTROL=254
};
/* Timers */
enum {
TIMER_START=1000, /* Microsecond */
TIMER_SOUND=100, /* Milli */
TIMER_PERIOD_EMISSION=2000 /* Milli */
};
/* Port for Packets */
enum {
AM_PROTOCOL= 5, /* Port used for both commands and notification msgs*/
AM_DTOA = 6, /* Port used for dtoa msgs*/
AM_DATA= 7 /* Port used for notification msgs*/
};
/* Protocol Ids */
enum {
START_EMISSION = 1, /* To notify to start of an emission */
END_EMISSION = 2, /* To notify to end of an emission */
SEND_DATA = 3, /* To notify to send data */
DATA_SENT=4 /* To notify data has been sent */
};
/* Configuration Parameters */
enum {
UNKNOWNS = 3,
ANCHORS = 0,
SAMPLES = 6,
TRAINS = 1,
ITERATIONS = 2
};
/* To define the structure of a msg*/
typedef nx_struct DTOA_Msg {
/*
Note that the type nx_uint16_t is introduced.
This type differs from the C type int16_t as
the byte ordering is handled internally.
*/
nx_uint16_t node_id;
} DTOA_Msg;
typedef nx_struct Data_Msg {
/*
Note that the type nx_uint16_t is introduced.
This type differs from the C type int16_t as
the byte ordering is handled internally.
*/
nx_uint16_t receiver;
nx_uint32_t samples[SAMPLES];
nx_uint32_t emitter;
nx_uint32_t iter;
} Data_Msg;
typedef nx_struct Protocol_Msg {
/*
Note that the type nx_uint16_t is introduced.
This type differs from the C type int16_t as
the byte ordering is handled internally.
*/
nx_uint8_t protocol_id;
nx_uint8_t parameter_1;
nx_uint8_t parameter_2;
} Protocol_Msg;
#endif_______________________________________________ Tinyos-help mailing list [email protected] https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
