[Tinyos-help] payloadLength

Klaas Thoelen klaas.thoelen at cs.kuleuven.be
Thu Jan 4 02:30:32 PST 2007


Hi *,

I was reading TEP111 on message_t, and thought I'd try something...

The code below is sending a broadcast message when a timer fires. I'm just sending a packet with some payload and then I try to get the size of 
this payload using payloadLength(). This should be 3 bytes.

This seems to be ok, except for the first packet that each node sends out. For some reason, it's payload is 0 bytes at TX, but 3 bytes at RX. 
All following packets have a payload of 3 bytes at both TX and RX.

Can someone explain me what's happening here?

Best regards,
Klaas

event void Timer.fired() {
	if (!busy) {	 	
		RadioStrengthMsg *pkt = (RadioStrengthMsg*)(call Packet.getPayload(&packet, NULL));
		dbg("RadioStrength", "Timer fired -> Send Message.\n");
		pkt->nodeid = TOS_NODE_ID;
		pkt->rssi = recv_strength;
		dbg("RadioStrength", "TX Payloadlength = %d\n", call Packet.payloadLength(&packet));
		if (call AMSend.send(AM_BROADCAST_ADDR, &packet, sizeof(RadioStrengthMsg)) == SUCCESS) {
			busy = TRUE;
		}
	}		
}

event message_t* Receive.receive(message_t* msg, void* payload, uint8_t len) {
	if (len == sizeof(RadioStrengthMsg)) {
		RadioStrengthMsg *pkt = (RadioStrengthMsg*)(call Packet.getPayload(msg, NULL));
		dbg("RadioStrength", "RX Payloadlength = %d\n", call Packet.payloadLength(msg));
		dbg("RadioStrength", "RX rssi = %d\n", pkt->rssi);
		...
	}
}

With a one shot timer, so only 1 packet per node
$ python test.py
   1   2   -54.0
   2   1   -55.0
DEBUG (1): Timer fired -> Send Message.
DEBUG (1): TX PayloadLength = 0
DEBUG (2): Timer fired -> Send Message.
DEBUG (2): TX PayloadLength = 0
DEBUG (1): RX PayloadLength = 3
DEBUG (1): RX rssi = 0
DEBUG (2): sendDone
DEBUG (2): RX PayloadLength = 3
DEBUG (2): RX rssi = 0
DEBUG (1): sendDone

With a periodic timer and thus multiple packets:
$ python test.py
   1   2   -54.0
   2   1   -55.0
DEBUG (1): Timer fired -> Send Message.
DEBUG (1): TX PayloadLength = 0
DEBUG (2): Timer fired -> Send Message.
DEBUG (2): TX PayloadLength = 0
DEBUG (2): RX PayloadLength = 3
DEBUG (2): RX rssi = 0
DEBUG (1): sendDone
DEBUG (1): RX PayloadLength = 3
DEBUG (1): RX rssi = 0
DEBUG (2): sendDone
DEBUG (1): Timer fired -> Send Message.
DEBUG (1): TX PayloadLength = 3
DEBUG (2): Timer fired -> Send Message.
DEBUG (2): TX PayloadLength = 3
DEBUG (2): RX PayloadLength = 3
DEBUG (2): RX rssi = 0
DEBUG (1): sendDone
DEBUG (1): RX PayloadLength = 3
DEBUG (1): RX rssi = 0
DEBUG (2): sendDone
DEBUG (1): Timer fired -> Send Message.
DEBUG (1): TX PayloadLength = 3
DEBUG (2): Timer fired -> Send Message.
DEBUG (2): TX PayloadLength = 3
DEBUG (1): sendDone
DEBUG (2): sendDone
DEBUG (1): Timer fired -> Send Message.
DEBUG (1): TX PayloadLength = 3
DEBUG (2): Timer fired -> Send Message.
DEBUG (2): TX PayloadLength = 3
DEBUG (1): sendDone
DEBUG (2): sendDone

Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm


More information about the Tinyos-help mailing list