Specifications

55
Figure 5.7.1. Listing of c-code for CRC-4 checksum computation.
5.7.2.3 Compressed heave spectrum (MsgID = 0)
Table 5.7.11 explains the "Compressed heave spectrum" message. Here, T
z
and m
0
are the
zero-upcross period and the rms of the heave calculated from the zeroth moment of the
spectrum, respectively. The significant wave height follows from H
m0
= 4*m
0
. Integer values
in the message may be transformed to real numbers as described in subsubsection 5.7.2.8. The
next entry, k
max
, is the index of the frequency bin for which S(f) is maximal, i.e. S(f
kmax
) = S
max
.
The 27 values of the spectral density S
k
= S(f
k
)/S
max
are normalized values. To scale back
multiply by
Δ=
k
kk
fSmS
0max
(5.7.8)
The frequency values f
k
are selected through smart decimation, which method is described later.
Table 5.7.11. Compressed heave spectrum message (MsgID = 0).
Byte HiNibble LoNibble
0 MsgID = 0 = 0000 CRC-4 checksum
1 T
z
2 m
0
3 k
max
4 S
0
5 S
1
… …
30 S
26
/*This is the key table for CRC generator X^4+X+1*/
const unsigned char
keytable[16]={0,3,6,5,12,15,10,9,11,8,13,14,7,4,1,2};
/*This routine checks the crc of a message
The routine uses a precalculated table
<data> must point to the message to be checked
<n> is the number of bytes in the message
If returned crc=0, message is OK*/
unsigned char ChkCrcCode (unsigned char *data, unsigned char n)
{
unsigned char i,crc;
crc=0;
for(i=0;i<n;i++)/*do for all bytes*/
{
crc=keytable[(crc^(data[i]>>4))&0x0f];
/*first nibble in byte*/
if(i>0) crc=keytable[(crc^data[i])&0x0f];
/*second nibble in byte*/
}
crc=keytable[(crc^data[0])&0x0f];
/*do second nibble of first byte last*/
return(crc);
}