[Tinyos-help] Crc Interface in BlinkToRadio application
Razvan Musaloiu-E.
razvanm at cs.jhu.edu
Thu Aug 28 06:24:37 PDT 2008
Hi!
On Thu, 28 Aug 2008, Dinesh Koya wrote:
> Hi Razvan
>
> Thanks for your answer. As you specified, the second parameter for the Packet.getPayload should the length of the packet, but if it is so then the command returns the length of the payload and not the payload . This I found in Packet.nc (you can see that below), I am not sure whether I got it right or not, I m sorry if not
> /**
> * Return a pointer to a protocol's payload region in a packet. If
> * len is not NULL, getPayload will return the length of the payload
> * in it, which is the same as the return value from
> * payloadLength(). If a protocol does not support variable length
> * packets, then *len is equal to maxPayloadLength().
> *
> * @param msg the packet
> * @param len pointer to where the current payload length should be stored.
> * @return a pointer to the packet's data payload for this layer
> */
> command void* getPayload(message_t* msg, uint8_t* len);
You are looking at an older version of TinyOS. The current Packet.nc looks
like this:
http://tinyos.cvs.sourceforge.net/*checkout*/tinyos/tinyos-2.x/tos/interfaces/Packet.nc?revision=1.8&content-type=text%2Fplain
> I have another question regarding appending the calculated CRC to the
> packet. How can this be done? I tried to do it many in ways like
> assigning the crc to the particular region of the packet, etc but I did
> not succeed. Hope I would get some clue.
I attached an archive with the way I did in one of our projects. The Crc
is added at the end.
All the best!
Razvan ME
> --- On Wed, 27/8/08, Razvan Musaloiu-E. <razvanm at cs.jhu.edu> wrote:
> From: Razvan Musaloiu-E. <razvanm at cs.jhu.edu>
> Subject: Re: [Tinyos-help] Crc Interface in BlinkToRadio application
> To: "Dinesh Koya" <dinesh_eric03 at yahoo.co.in>
> Cc: "TinyOS - Help" <tinyos-help at millennium.berkeley.edu>
> Date: Wednesday, 27 August, 2008, 4:39 PM
>
> Hi!
>
> On Wed, 27 Aug 2008, Dinesh Koya wrote:
>
>> Hi all
>>
>> I tried to use the Crc interface in the BlinkToRadio application
>> to calculate the crc for the packets.
>> For this I modified the BlinkToRadio.h as below
>>
>> #ifndef BLINKTORADIO_H
>> #define BLINKTORADIO_H
>>
>> enum
>> {
>> TIMER_PERIOD_MILLI = 250,
>>
>> AM_BLINKTORADIOMSG = 6
>> };
>>
>> typedef nx_struct BlinkToRadioMsg
>> {
>> nx_uint16_t nodeid;
>> nx_uint16_t counter;
>> nx_uint16_t crc; // this was included
>> }
>> BlinkToRadioMsg;
>>
>> #endif
>>
>> Then I modified the event void Timer0.fired(); block of
>> BlinkToRadioC file as below
>>
>> #include <crc.h> // this was included
>> uses interface Crc; // this was included
>> event void Timer0.fired()
>> {
>> counter++;
>> //call Leds.set(counter);
>>
>> if (!busy)
>> {
>> BlinkToRadioMsg* btrpkt =
>> (BlinkToRadioMsg*)(call Packet.getPayload(&pkt, NULL));
>> btrpkt -> nodeid = TOS_NODE_ID;
>> btrpkt -> counter = counter;
>> btrpkt -> crc = crc; // this was included
>> /* command uint16_t crc16(void* buf, uint8_t len); */
>> crc = call Crc.crc16(&pkt,4); // this was included
>>
>> if (call AMSend.send(AM_BROADCAST_ADDR, &pkt, sizeof(BlinkToRadioMsg)) == SUCCESS)
>> {
>> busy = TRUE;
>> }
>> }
>> }
>>
>> Here I did not get rightly what to pass as the 2nd parameter
>> which is uint8_t len for crc16 command, so I just tried out with 4
>> and then I got the following result when two tmotes were running
>> BlinkToRadio with node id's 1 and 2 and one tmote with
>> BaseStation running with node id as 0.
>>
>
> (nodeid)(counter)(crc16)
>> 00 FF FF FF FF 06 00 06 00 01 00 01 00 00
>> 00 FF FF FF FF 06 00 06 00 02 00 01 00 00
>> 00 FF FF FF FF 06 00 06 00 01 00 02 00 00
>> 00 FF FF FF FF 06 00 06 00 02 00 02 00 00
>> 00 FF FF FF FF 06 00 06 00 01 00 03 4E 63
>> 00 FF FF FF FF 06 00 06 00 02 00 03 4E 63
>> 00 FF FF FF FF 06 00 06 00 01 00 04 5E 42
>> 00 FF FF FF FF 06 00 06 00 02 00 04 5E 42
>> 00 FF FF FF FF 06 00 06 00 01 00 05 6E 21
>> 00 FF FF FF FF 06 00 06 00 02 00 05 6E 21
>> 00 FF FF FF FF 06 00 06 00 01 00 06 7E 00
>> 00 FF FF FF FF 06 00 06 00 02 00 06 7E 00
>> 00 FF FF FF FF 06 00 06 00 01 00 07 0E E7
>> 00 FF FF FF FF 06 00 06 00 02 00 07 0E E7
>> 00 FF FF FF FF 06 00 06 00 01 00 08 1E C6
>> 00 FF FF FF FF 06 00 06 00 02 00 08 1E C6
>> 00 FF FF FF FF 06 00 06 00 01 00 09 2E A5
>> 00 FF FF FF FF 06 00 06 00 02 00 09 2E A5
>> 00 FF FF FF FF 06 00 06 00 01 00 0A 3E 84
>> 00 FF FF FF FF 06 00 06 00 02 00 0A 3E 84
>>
>> I would like to know what exactly is to be passed to 2nd
>> parameter of crc16 command and also based on the parameter
>> how is the crc calculated, i.e for what lenght of the packet?
>
> Here is what it says in tos/interfaces/Crc.h:
>
> /**
> * Compute the CRC-16 value of a byte array.
> *
> * @param 'void* COUNT(len) buf' A pointer to the buffer over which to compute CRC.
> * @param len The length of the buffer over which to compute CRC.
> * @return The CRC-16 value.
> */
> async command uint16_t crc16(void* buf, uint8_t len);
>
> Note: in you case pkt is a message_t and &pkt will not point to the
> payload. If you want to compute the crc on the payload then you'll have to
> use the result from Packet.getPayload.
>
> And another note: the second parameter for the Packet.getPayload should
> the length of the packet. You can use the size returned by
> Packet.payloadLength(...) if the packet is already filled with data or
> Packet.maxPayloadLength(...). All these is documented in
> tos/interfaces/Packet.nc.
>
> --
> Razvan ME
>
>> I also included the wiring in BlinkToRadioAppC as
>>
>> components CrcC; //this was included
>> App.Crc -> CrcC; //this was included
>>
>> Could some one help me with this
>>
>> Thanks for any help
>>
>> Regads
>> Dinesh
>>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CrcAM.tar.cz
Type: application/octet-stream
Size: 1203 bytes
Desc:
Url : https://www.millennium.berkeley.edu/pipermail/tinyos-help/attachments/20080828/591fbcbe/attachment.obj
More information about the Tinyos-help
mailing list