[Tinyos-help] typos or defined elsewhere?

Chad Metcalf metcalfc at gmail.com
Thu Jan 4 16:17:21 PST 2007


On 1/4/07, Mohamed Ahmed <mohamed7ahmed at yahoo.com> wrote:
> Hi,
>
> Could someone tell me the following code is complete/correct?
> Where is pkt defined?

According the version in my
$TOSROOT/apps/tutorials/BlinkToRadio/BlinkToRadioC.nc pkt is defined
on line 55. Just search for it.

----
implementation {

  uint16_t counter;
  message_t pkt;
  bool busy = FALSE;
----

> Also btrpkt is not used after initializing its fields "nodeid" and
> "counter".

You are correct. The btrpkt pointer is used to used access to the
nodeid and counter fields. Once they are updated you don't need to use
the pointer anymore. That's what this:

BlinkToRadioMsg* btrpkt = (BlinkToRadioMsg*)(call Packet.getPayload(&pkt, NULL))

is doing for you. The pkt is the packet you are sending. The payload
is where the BlinkToRadioMsg structure lives (for this message type).
By getting a pointer to the payload and casting it to a pointer to the
BlinkToRadioMsg struct you get a nice convenient way of modifying the
values of nodeid and counter.

Now in this line:

if (call AMSend.send(AM_BROADCAST_ADDR, &pkt, sizeof(BlinkToRadioMsg))
== SUCCESS) {

you send the pkt. The nodeid and counter values have been changed. So
you don't need the btrptk because it isn't the whole packet, just the
payload.

Generally, the tutorials are correct.

Cheers,
Chad


-- 
Chad @ Home


More information about the Tinyos-help mailing list