forked from rigexpert/AntScope2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencodinghelpers.cpp
More file actions
169 lines (141 loc) · 4.89 KB
/
Copy pathencodinghelpers.cpp
File metadata and controls
169 lines (141 loc) · 4.89 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#include "encodinghelpers.h"
EncodingHelpers::EncodingHelpers() {}
QString EncodingHelpers::encodeString(QString strIn) { // A02_EnCode_strToBase16_v0
int ifor1, srtIn_len;
QString str_Hi, str_Lo;
quint8 tmpBt1, tmpBt_hi, tmpBt_lo;
QString str1x_Hi, str1x_L0;
quint8 CRC8;
//-------Ord( "A ") / Chr($64)---------
// v--0
str_Hi = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // 37
str_Lo = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // 37
QString Result;
srtIn_len = strIn.length();
CRC8 = 0x01;
for (ifor1 = 0; ifor1 < srtIn_len; ifor1++) { // 900 = 1800 div 2
tmpBt1 = strIn[ifor1].toLatin1();
CRC8 = CRC8 ^ tmpBt1;
tmpBt_hi = ((tmpBt1 >> 4) & 0x0F);
tmpBt_lo = (tmpBt1 & 0x0F);
str1x_Hi = str_Hi[tmpBt_hi];
str1x_L0 = str_Lo[tmpBt_lo];
Result = Result + str1x_Hi + str1x_L0;
}
// add crc byte ---------------------------------------
tmpBt_hi = ((CRC8 >> 4) & 0x0F);
tmpBt_lo = (CRC8 & 0x0F);
//--------------------------
str1x_Hi = str_Hi[tmpBt_hi];
str1x_L0 = str_Lo[tmpBt_lo];
Result = Result + str1x_Hi + str1x_L0;
return Result;
}
QByteArray EncodingHelpers::decodeString(QString inRaw) { // B02_www_Decode_rawMSG
quint8 tmpBt1;
quint8 CRC_CALK;
int inLen;
int poz1, poz2, poz3;
QString str1, str2, str3;
QString chHi, chLo, str_Hi, str_Lo;
quint8 pozHi, pozLo;
quint8 SendBuff[65];
QString Result = "X1 ";
inLen = inRaw.length();
poz1 = inRaw.indexOf("&nGet=");
poz2 = inRaw.indexOf("&nRaw=");
poz3 = inRaw.indexOf("&raw=");
if (!((poz1 > 0) and (poz2 > poz1) and (poz3 > poz2)))
return Result.toLatin1(); //-----------> ret X1
str1 = inRaw.mid((poz1 + QString("&nGet=").length()),
poz2 - (poz1 + QString("&nGet= ").length()));
str2 = inRaw.mid((poz2 + QString("&nRaw=").length()),
poz3 - (poz2 + QString("&nRaw= ").length()));
str3 = inRaw.mid((poz3 + QString("&raw=").length()),
inLen - (poz3 + QString("&raw= ").length()) + 1);
int len = str3.length();
str_Hi = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ "; // 37
str_Lo = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ "; // 37
CRC_CALK = 0x02;
for (int ifor1 = 0; ifor1 < 65; ifor1++) {
if (ifor1 * 2 >= len)
break;
chHi = str3[(ifor1 * 2)];
chLo = str3[(ifor1 * 2) + 1];
pozHi = str_Hi.indexOf(chHi); //-1;
pozLo = str_Lo.indexOf(chLo); //-1;
tmpBt1 = ((pozHi << 4) | pozLo) & 0x00FF;
SendBuff[ifor1] = tmpBt1;
CRC_CALK = CRC_CALK ^ tmpBt1;
}
SendBuff[64] = 0;
return QByteArray((char *)SendBuff, 64); // ret 65bytes?
}
QByteArray EncodingHelpers::decodeString_nRaw1(QString inRaw) {
quint8 tmpBt1;
quint8 CRC_CALK;
int inLen;
int poz1, poz2, poz3;
QString str1, str2, str3;
QString chHi, chLo, str_Hi, str_Lo;
quint8 pozHi, pozLo;
quint8 SendBuff[2000];
QString Result = "X1 ";
inLen = inRaw.length();
poz1 = inRaw.indexOf("&nGet=");
poz2 = inRaw.indexOf("&nRaw=");
poz3 = inRaw.indexOf("&raw=");
if (!((poz1 > 0) and (poz2 > poz1) and (poz3 > poz2)))
return Result.toLatin1(); //-----------> ret X1
str1 = inRaw.mid((poz1 + QString("&nGet=").length()),
poz2 - (poz1 + QString("&nGet= ").length()));
str2 = inRaw.mid((poz2 + QString("&nRaw=").length()),
poz3 - (poz2 + QString("&nRaw= ").length()));
str3 = inRaw.mid((poz3 + QString("&raw=").length()),
inLen - (poz3 + QString("&raw= ").length()) + 1);
int len = (str3.length())/2;
str_Hi = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ "; // 37
str_Lo = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ "; // 37
CRC_CALK = 0x02;
for (int ifor1 = 0; ifor1 < len; ifor1++) {
if (ifor1 * 2 >= 2000)
break;
chHi = str3[(ifor1 * 2)];
chLo = str3[(ifor1 * 2) + 1];
pozHi = str_Hi.indexOf(chHi); //-1;
pozLo = str_Lo.indexOf(chLo); //-1;
tmpBt1 = ((pozHi << 4) | pozLo) & 0x00FF;
SendBuff[ifor1] = tmpBt1;
CRC_CALK = CRC_CALK ^ tmpBt1;
}
return QByteArray((char *)SendBuff, len); //
}
QByteArray EncodingHelpers::sendToMatch(QString serialNumber) {// B01_E1_Send_to_Match2
quint8 CRC_CALK;
quint8 SendBuff[64];
quint8 byteChar, byteTmp;
quint8 rdx, rdy;
for (int ifor1 = 4; ifor1 < 64; ifor1++)
SendBuff[ifor1] = abs(rand() % 255); // Random(255);
SendBuff[0] = 0x07;
SendBuff[1] = 0x3E;
SendBuff[2] = 0xBD;
SendBuff[3] = 0xE1;
//----------
SendBuff[4] = 0x01;
rdx = (SendBuff[15] & 0x0F);
rdy = 16 + (SendBuff[9] & 0x07);
for (int ifor1 = 0; ifor1 < 5; ifor1++) {
byteChar = serialNumber[4 + ifor1].toLatin1();
byteTmp = (SendBuff[10 + ifor1] & 0x3F);
byteTmp = byteTmp + (ifor1 + 1) * rdx;
byteTmp = byteTmp + byteChar;
SendBuff[rdy + ifor1] = byteTmp;
}
CRC_CALK = 1; /// for blok 64 =1 //http=2 //data=0
for (int ifor1 = 3; ifor1 < 63; ifor1++) {
CRC_CALK = CRC_CALK ^ SendBuff[ifor1];
}
SendBuff[63] = CRC_CALK;
return QByteArray((char *)SendBuff, sizeof(SendBuff));
}