CRC16CCiTT Problem

Just starting out? Need help? Post your questions and find answers here.
swhite
Enthusiast
Enthusiast
Posts: 785
Joined: Thu May 21, 2009 6:56 pm

CRC16CCiTT Problem

Post by swhite »

Code: Select all

Procedure.s CRC16CCITTBad(tcTxt.s,tnASCII.i=1)
   
   Protected *table.Unicode, *mem.Ascii = @tcTxt, *mem_end = *mem + StringByteLength(tcTxt,#PB_Ascii)
   Protected crc16.u = $ffff
   While *mem < *mem_end
      *table = ?CRC16CCITT_table + crc16 >> 8 ! *mem\a << 1
      crc16 = crc16 << 8 ! *table\u 
      *mem + 1
   Wend
   If tnASCII = 1
      ProcedureReturn Chr(crc16 >> 8)+Chr(crc16 & $00FF)
   Else
      ProcedureReturn Hex(crc16,#PB_Unicode)
   EndIf
   
   DataSection
      CRC16CCITT_table:
      Data.u $0000, $1021, $2042, $3063, $4084, $50A5, $60C6, $70E7
      Data.u $8108, $9129, $A14A, $B16B, $C18C, $D1AD, $E1CE, $F1EF
      Data.u $1231, $0210, $3273, $2252, $52B5, $4294, $72F7, $62D6
      Data.u $9339, $8318, $B37B, $A35A, $D3BD, $C39C, $F3FF, $E3DE
      Data.u $2462, $3443, $0420, $1401, $64E6, $74C7, $44A4, $5485
      Data.u $A56A, $B54B, $8528, $9509, $E5EE, $F5CF, $C5AC, $D58D
      Data.u $3653, $2672, $1611, $0630, $76D7, $66F6, $5695, $46B4
      Data.u $B75B, $A77A, $9719, $8738, $F7DF, $E7FE, $D79D, $C7BC
      Data.u $48C4, $58E5, $6886, $78A7, $0840, $1861, $2802, $3823
      Data.u $C9CC, $D9ED, $E98E, $F9AF, $8948, $9969, $A90A, $B92B
      Data.u $5AF5, $4AD4, $7AB7, $6A96, $1A71, $0A50, $3A33, $2A12
      Data.u $DBFD, $CBDC, $FBBF, $EB9E, $9B79, $8B58, $BB3B, $AB1A
      Data.u $6CA6, $7C87, $4CE4, $5CC5, $2C22, $3C03, $0C60, $1C41
      Data.u $EDAE, $FD8F, $CDEC, $DDCD, $AD2A, $BD0B, $8D68, $9D49
      Data.u $7E97, $6EB6, $5ED5, $4EF4, $3E13, $2E32, $1E51, $0E70
      Data.u $FF9F, $EFBE, $DFDD, $CFFC, $BF1B, $AF3A, $9F59, $8F78
      Data.u $9188, $81A9, $B1CA, $A1EB, $D10C, $C12D, $F14E, $E16F
      Data.u $1080, $00A1, $30C2, $20E3, $5004, $4025, $7046, $6067
      Data.u $83B9, $9398, $A3FB, $B3DA, $C33D, $D31C, $E37F, $F35E
      Data.u $02B1, $1290, $22F3, $32D2, $4235, $5214, $6277, $7256
      Data.u $B5EA, $A5CB, $95A8, $8589, $F56E, $E54F, $D52C, $C50D
      Data.u $34E2, $24C3, $14A0, $0481, $7466, $6447, $5424, $4405
      Data.u $A7DB, $B7FA, $8799, $97B8, $E75F, $F77E, $C71D, $D73C
      Data.u $26D3, $36F2, $0691, $16B0, $6657, $7676, $4615, $5634
      Data.u $D94C, $C96D, $F90E, $E92F, $99C8, $89E9, $B98A, $A9AB
      Data.u $5844, $4865, $7806, $6827, $18C0, $08E1, $3882, $28A3
      Data.u $CB7D, $DB5C, $EB3F, $FB1E, $8BF9, $9BD8, $ABBB, $BB9A
      Data.u $4A75, $5A54, $6A37, $7A16, $0AF1, $1AD0, $2AB3, $3A92
      Data.u $FD2E, $ED0F, $DD6C, $CD4D, $BDAA, $AD8B, $9DE8, $8DC9
      Data.u $7C26, $6C07, $5C64, $4C45, $3CA2, $2C83, $1CE0, $0CC1
      Data.u $EF1F, $FF3E, $CF5D, $DF7C, $AF9B, $BFBA, $8FD9, $9FF8
      Data.u $6E17, $7E36, $4E55, $5E74, $2E93, $3EB2, $0ED1, $1EF0
   EndDataSection
   
EndProcedure

Debug CRC16CCITTBad(Chr($2)+"11009030000020A180040000000400000000000000005000000024150416075241061227920000000107CONCORD003004USD02133000100100000005000007CONCORD"+Chr($3),1)
Debug CRC16CCITTBad(Chr($2)+"11009030000020A180040000000400000000000000005000000024150416075241061227920000000107CONCORD003004USD02133000100100000005000007CONCORD"+Chr($3),0)
Debug CRC16CCITTBad(Chr($2)+"11009030000020A180040000000400000000000000005000000031150416090556061227920000000107CONCORD003004USD02133000100100000005000007CONCORD"+Chr($3),1)
Debug CRC16CCITTBad(Chr($2)+"11009030000020A180040000000400000000000000005000000031150416090556061227920000000107CONCORD003004USD02133000100100000005000007CONCORD"+Chr($3),0)
Debug CRC16CCITTBad(Chr($2)+"11009030000020A180040000000400000000000000005000000034150416092436061227920000000107CONCORD003004USD02133000100100000005000007CONCORD"+Chr($3),1)
Debug CRC16CCITTBad(Chr($2)+"11009030000020A180040000000400000000000000005000000034150416092436061227920000000107CONCORD003004USD02133000100100000005000007CONCORD"+Chr($3),0)
When I run the above code in the debugger using compile with ASCII mode I get all the expected results. When I include the CRC16CCITTBad procedure in my application the crc16 variable is always zero. I compiled the application in ASCII mode just as I did in the above example but do not understand why the results are different.

Thanks,
Simon
Simon White
dCipher Computing
User avatar
NicknameFJ
User
User
Posts: 90
Joined: Tue Mar 17, 2009 6:36 pm
Location: Germany

Re: CRC16CCiTT Problem

Post by NicknameFJ »

*** Answer deleted ***

Answer was not helpful
Last edited by NicknameFJ on Thu Apr 16, 2015 7:05 pm, edited 1 time in total.
PS: Sorry for my weird english, but english is not my native language.



Image
swhite
Enthusiast
Enthusiast
Posts: 785
Joined: Thu May 21, 2009 6:56 pm

Solved: CRC16CCiTT Problem

Post by swhite »

I resolved the problem. I found that the application was including the received CRC16 value in the text passed to CRC16CCITTBad. Once I corrected this everything worked just fine.

Simon
Simon White
dCipher Computing
Post Reply