提交 | 用户 | age
|
0ed438
|
1 |
#include "pch.h"
|
65f713
|
2 |
#include "DataParser1.h"
|
0ed438
|
3 |
|
Q |
4 |
CDataParser1::CDataParser1()
|
|
5 |
{
|
|
6 |
|
|
7 |
}
|
|
8 |
|
|
9 |
int CDataParser1::PutIn(unsigned char * str, int len1)
|
|
10 |
{
|
|
11 |
if (len1 <= 0) return 0;
|
|
12 |
memcpy(InBuf + nBufDataLen, str, len1);
|
|
13 |
nBufDataLen += len1;
|
|
14 |
int handx, handy;
|
|
15 |
int j;
|
|
16 |
for (j = 0; j < nBufDataLen; j++)
|
|
17 |
{
|
|
18 |
if (nBufDataLen - j < 20) { break; } //等待数据
|
|
19 |
if (InBuf[j] == 'v'&&nBufDataLen - j < 12) { break;}
|
|
20 |
if (InBuf[j] == 'v'&&InBuf[j - 1] == ' '&&InBuf[j + 1] == ' ')
|
|
21 |
{
|
|
22 |
char hex1, hex2;
|
|
23 |
hex1 = InBuf[j + 8]; hex2 = InBuf[j + 9];
|
|
24 |
if (hex1 <= '9'&&hex1 >= '0') { handx = (hex1 - '0') * 16; }
|
|
25 |
else { handx = (hex1 - 'A' + 10) * 16; }
|
|
26 |
if (hex2 <= '9'&&hex2 >= '0') { handx += hex2 - '0'; }
|
|
27 |
else { handx += hex2 - 'A' + 10; }
|
|
28 |
|
|
29 |
hex1 = InBuf[j + 11]; hex2 = InBuf[j + 12];
|
|
30 |
if (hex1 <= '9'&&hex1 >= '0') { handy = (hex1 - '0') * 16; }
|
|
31 |
else { handy = (hex1 - 'A' + 10) * 16; }
|
|
32 |
if (hex2 <= '9'&&hex2 >= '0') { handy += hex2 - '0'; }
|
|
33 |
else { handy += hex2 - 'A' + 10; }
|
|
34 |
m_bHasData = 1;
|
|
35 |
m_Value1 = handx;
|
|
36 |
m_Value2 = handy;
|
|
37 |
}
|
|
38 |
}
|
|
39 |
//将recv2移位到最左端
|
|
40 |
if (j == nBufDataLen) { nBufDataLen = 0; }
|
|
41 |
else
|
|
42 |
{
|
|
43 |
nBufDataLen = nBufDataLen - j;
|
|
44 |
memmove(InBuf, InBuf + j, nBufDataLen);
|
|
45 |
}
|
|
46 |
return m_bHasData;
|
|
47 |
}
|
|
48 |
|
|
49 |
int CDataParser1::GetOutput(int * value1, int * value2)
|
|
50 |
{
|
|
51 |
if (m_bHasData)
|
|
52 |
{
|
|
53 |
*value1 = m_Value1;
|
|
54 |
*value2 = m_Value2;
|
|
55 |
m_bHasData = 0;
|
|
56 |
return 1;
|
|
57 |
}
|
|
58 |
return 0;
|
|
59 |
}
|
|
60 |
|
|
61 |
int GetOutputStr(char * buf, int & len1)
|
|
62 |
{
|
|
63 |
len1 = 0;
|
|
64 |
return 0;
|
|
65 |
}
|