-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathErrorDetect.c
76 lines (70 loc) · 1.82 KB
/
ErrorDetect.c
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "ErrorDetect.h"
/*---------------------------------------------------------------
-- SOURCE FILE: ErrorDetect.c
--
-- PROGRAM: RFID Reader - Enterprise Edition
--
-- FUNCTIONS:
-- BOOL DetectLRCError(CHAR* pcPacket, DWORD dwLength)
--
--
-- DATE: Nov 2, 2010
--
-- REVISIONS: (Date and Description)
--
-- DESIGNER: Dean Morin, Marcel Vangrootheest
--
-- PROGRAMMER: Ian Lee
--
-- NOTES:
--
-- Handles the LRC error checking on frames passed into the program
--
----------------------------------------------------------------*/
/*---------------------------------------------------------------
--FUNCTION: DetectLRCError
--
--DATE: Nov 2, 2010
--
--REVISIONS: (Date and Description)
--
--DESIGNER: Dean Morin, Marcel Vangrootheest
--
--Programer: Ian Lee
--
--INTERFACE: BOOL DetectLRCError(CHAR* pcPacket, DWORD dwLength)
-- pcPacket - Frame to be processed
-- dwLength - number of Bytes in frame
--
--
--RETURNS: BOOL true if an error is detected
--
--NOTES:
--
-- Performs LRC Error checking on the frame.
1. XOR the first byte with the second byte, then the result of
that with the third byte, and so on until all bytes except
for the final two have been XOR’d.
2. If the result of this is not the same as the second to last
byte:
A. return true
3. XOR the second to last byte with ‘FF’
4. If the result of this is not the same as the last byte:
A. return true
5. return false
----------------------------------------------------------------*/
BOOL DetectLRCError(CHAR* pcPacket, DWORD dwLength){
DWORD i;
char sum = 0x0;
char ff = (char)0xFF;
for(i = 0;i<dwLength - 2; i++){
sum = sum ^ pcPacket[i];
}
if(sum != pcPacket[i++])
return TRUE;
sum = sum^ff;
if(sum!= pcPacket[i++]){
return TRUE;
}
return FALSE;
}