##// END OF EJS Templates
update before compilation on pc-alison
leroy -
r48:bcdc8ffba490 default
parent child
Show More
@@ -0,0 +1,60
1 #include "tcpackettosend.h"
2
3 TCPacketToSend::TCPacketToSend(QObject *parent) :
4 QObject(parent)
5 {
6 initLookUpTableForCRC();
7 }
8
9 void TCPacketToSend::initLookUpTableForCRC( void )
10 {
11 unsigned int i;
12 unsigned int tmp;
13
14 for (i=0; i<256; i++)
15 {
16 tmp = 0;
17 if((i & 1) != 0) {
18 tmp = tmp ^ 0x1021;
19 }
20 if((i & 2) != 0) {
21 tmp = tmp ^ 0x2042;
22 }
23 if((i & 4) != 0) {
24 tmp = tmp ^ 0x4084;
25 }
26 if((i & 8) != 0) {
27 tmp = tmp ^ 0x8108;
28 }
29 if((i & 16) != 0) {
30 tmp = tmp ^ 0x1231;
31 }
32 if((i & 32) != 0) {
33 tmp = tmp ^ 0x2462;
34 }
35 if((i & 64) != 0) {
36 tmp = tmp ^ 0x48c4;
37 }
38 if((i & 128) != 0) {
39 tmp = tmp ^ 0x9188;
40 }
41 lookUpTableForCRC[i] = tmp;
42 }
43 }
44
45 void TCPacketToSend::GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData)
46 {
47 unsigned int Chk;
48 unsigned int j;
49 Chk = 0xffff; // reset the syndrom to all ones
50 for (j=0; j<sizeOfData; j++) {
51 Chk = Crc_opt(data[j], Chk);
52 }
53 crcAsTwoBytes[0] = (unsigned char) (Chk >> 8);
54 crcAsTwoBytes[1] = (unsigned char) (Chk & 0x00ff);
55 }
56
57 unsigned int TCPacketToSend::Crc_opt( unsigned char D, unsigned int Chk)
58 {
59 return(((Chk << 8) & 0xff00)^lookUpTableForCRC [(((Chk >> 8)^D) & 0x00ff)]);
60 }
@@ -0,0 +1,27
1 #ifndef TCPACKETTOSEND_H
2 #define TCPACKETTOSEND_H
3
4 #include <QObject>
5
6 #include <TC_types.h>
7
8 class TCPacketToSend : public QObject
9 {
10 Q_OBJECT
11 public:
12 explicit TCPacketToSend(QObject *parent = 0);
13
14 unsigned char calculateDataCRC(char *data, int nbBytes);
15 void initLookUpTableForCRC( void );
16
17 void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData);
18 unsigned int Crc_opt( unsigned char D, unsigned int Chk);
19 unsigned int lookUpTableForCRC[256];
20
21 signals:
22
23 public slots:
24
25 };
26
27 #endif // TCPACKETTOSEND_H
General Comments 0
You need to be logged in to leave comments. Login now