[Tinyos-help] Crc Interface in BlinkToRadio application
Razvan Musaloiu-E.
razvanm at cs.jhu.edu
Wed Aug 27 04:09:23 PDT 2008
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
>
>
>
>
>
>
More information about the Tinyos-help
mailing list