*
*    Hy!
  I have some problems in understanding the CRC algorithm within Iris mote.
So I'm using a Matlab code to calculate the CRC but when I compare with the
received CRC I don't see any match beetwen the signals.
My packet format is  synch byte || Packet Type ||* ** *Sequence number
||* *Message
address ||* *Message address ||* *Message Type* ||** *Group ID ||* *Packet
size* *||* *Data* || *Data *|| *CRC *|| *CRC * || *synch byte* *.

So, for example I receive at a time instance the following packet:

ans =Val= 126

ans =Val= 66

ans =Val= 125

ans =Val= 94

ans =Val= 0

ans =Val= 4

ans =Val= 125

ans =Val= 93

ans =Val= 4

ans =Val= 94

ans =Val= 28

ans =Val= 11

ans =Val= 0

ans =Val= 186

ans =Val= 10

ans =Val= 126

The red spot is the payload and the next 2 bytes are the CRC! The next code
I use to compare the CRC data received with the one calculated in
matlab(with r value)

 File CRC16.m
%**************************************************************************
% This script calculates the 16-bit ITU-T CRC, as described in 7.2.1.9
% IEEE 802.15.4-2006 std. (ZigBee).
%
% Author: Everton Leandro Alves
% Date: 06/19/2008
%
% The generator polynomial is G(x)=x^16+x^12+x^5+1. From the given
% explanation the steps are:
% 1 - Remainder register 'r' is initialized to 0;
% 2 - The message is shifted into the divider (b0 first);
% 3 - Operations are done in the order: a) XORs, b) left shift of r
% register and c) r3 and r10 update.
% 4 - The r register is appended to the message.
%
%**************************************************************************

clear all
clc

msg = [66;125;94;0;4;125;93;4;94;28;11;0];
msg = de2bi(msg,8);

msg = reshape(msg,1,8*length(msg));

r=zeros(1,16);      % Remainder register initialization

for c3=1:length(msg)

    s1=bitxor(msg(c3),r(1));    % XOR between r0 and the message bit
    s2=bitxor(s1,r(12));        % XOR r11
    s3=bitxor(s1,r(5));         % XOR r4

    r=[r(2:16) s1];             % Left shift of r, and r15 update

    r(11)=s2;                   % r10 update
    r(4)=s3;                    % r3 update
end

msg_FCS=[msg r];                % Message + FCS field
display('Message + FCS field:')
msg_FCS

When I calculate the CRC, I use everything except  the two frame synch
bytes, and the two CRC bytes. Does anyone have any clue  where I'm going
wrong?
*

*
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to