[Tinyos-help] problem with sendone

Noor n.alnakhala at gmail.com
Tue Dec 17 13:05:45 PST 2013


I'm implementing a tinyos code to handle clustering algorithm.

first, the normal nodes in each cluster will send their data to ch and they
request acknowledgment from ch, if the ack is received then normal nodes go
to sleep, else they will resend again.
after that the communication will be between the cluster heads only to
exchange data. as follows
assume there are 3 CHs
**CH1 broadcasts its data to nearby CHs.
**CH2 hears the broadcast first will reply back with its data to CH1 ONLY
and request ack from CH1
**CH1 sends ack with its data to CH2.
and then they compute their new results and start to broadcast again.
they do this correctly, but I  have a problem with the *stop condition* of
the code. sometimes it works and sometimes it does not.
I believe the problem is that the packet is mixed between the normal packets
sent to CH and the packets that the CH exchange between them, but I can't
figure out the bug.
I tried to use two different message_t and also I tried to use two different
AMSend but it did not solve the problem.

This is the code for senddone.

event void AMSend.sendDone(message_t * bufPtr, error_t error) {

	   datamsg_t *checkpacket = NULL;

checkpacket =
	    (datamsg_t *) (call
			   AMSend.getPayload(bufPtr, sizeof(datamsg_t)));

	//check if ack recieved from CH
    if(ctype != 0 && checkpacket->cluster_type == ctype &&

	if (call PacketAcknowledgements.wasAcked(bufPtr))
	    {// means that it recieves ack from ch
		//normal node will go to sleep 
		//call Leds.led1Toggle();
	  //  call Timer2.startOneShot((call Random.rand16() % 100) +
				//	 100);	

	 else {
	    dbg("Net", "Resend my data to ch...\n");
	   post send();	


//if im cluster head	
if(ctype == 0 && checkpacket->cluster_type == 0)


if (call PacketAcknowledgements.wasAcked(bufPtr)
	    || checkpacket->packet_type == PKT1) {

	    if (checkpacket->packet_type == PKT2) {
		//I recieved the acknolwedgmnet that the other cluster recieved PKT2 from
		call Timer0.startOneShot(100);
	    } else if (checkpacket->packet_type == PKT1) {
		call Timer0.startOneShot(100);

	    call Leds.led1Toggle();
	} else {
	    dbg("Net", "Resend2...\n");

	    post send();

	    call Leds.led2Toggle();


and this is the code for Receive

event message_t *Receive.receive(message_t *msg, void *payload,
				     uint8_t len) {

	datamsg_t *rpack = NULL;

	if (len == sizeof(datamsg_t)) {
	    rpack = (datamsg_t *) payload;
	    src = call AMPacket.source(msg);
	    dst = call AMPacket.destination(msg);

	   	//if packet from normal node recieved
	    if (ctype==0 && rpack->cluster_type != 0  ) {
	   dbg("Net", "R [P%d] from %d\n", rpack->packet_type, src);
		dbg("Net", "\treceived from normal node\n");

		return msg;

//if the recieved packt if from another cluster head
else if (rpack->cluster_type == 0) {

 /* If the packet is from the wrong person, discard it. */

	if (ss != 0 && src != ss) {
		dbg("Net", "\tDiscarded\n");
		return msg;
                             /* If the packet is one I expect, process it */

		if ((mstate == 2 && rpack->packet_type == PKT3)
		|| (mstate == 0 && rpack->packet_type == PKT1)
		|| (mstate == 1 && rpack->packet_type == PKT2)) {
		call Timer0.stop();
		 dbg("Net", "R [P%d] from %d\n", rpack->packet_type, src);
		return msg;


/* otherwise, discard it. */
	   dbg("Net", "\tDiscarded\n");
	    return msg;
 return msg;

hope I was clear explaining the idea briefly. I wish anyone can help.


View this message in context: http://tinyos-help.10906.n7.nabble.com/problem-with-sendone-tp23958.html
Sent from the TinyOS - Help mailing list archive at Nabble.com.

More information about the Tinyos-help mailing list