summaryrefslogtreecommitdiff
path: root/lib/fst4/get_crc24.f90
blob: cb7f3a05f558ea5d2cb95c79cb79d1a7245a1aad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
subroutine get_crc24(mc,len,ncrc)
!
! 1. To calculate 24-bit CRC, mc(1:len-24) is the message and mc(len-23:len) are zero.
! 2. To check a received CRC, mc(1:len) is the received message plus CRC. 
!    ncrc will be zero if the received message/CRC are consistent.
!
   character c24*24
   integer*1 mc(len)
   integer*1 r(25),p(25)
   integer ncrc
! polynomial for 24-bit CRC 0x100065b
   data p/1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,0,1,1,0,1,1/

! divide by polynomial
   r=mc(1:25)
   do i=0,len-25 
      r(25)=mc(i+25)
      r=mod(r+r(1)*p,2)
      r=cshift(r,1)
   enddo

   write(c24,'(24b1)') r(1:24)
   read(c24,'(b24.24)') ncrc

end subroutine get_crc24