-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLawicel.cs
69 lines (61 loc) · 2.09 KB
/
Lawicel.cs
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
using System;
public class Lawicel
{
public string sId = "";
public string sDlc = "";
public string sMsg = "";
public int iPeriod = 0;
public int tsimbolRx (char[] data, int rx_ptr_in)
{
rx_ptr_in++;
//ID
sId = data[rx_ptr_in++] + "" + data[rx_ptr_in++] + "" + data[rx_ptr_in++];
//DLC
sDlc = data[rx_ptr_in] + "";
int iDlc = ((data[rx_ptr_in++] & 0x0F) * 2);
if (iDlc > 16) iDlc = 16;
//MSG
for (int i = 0; i < iDlc; i += 2)
{
sMsg += data[rx_ptr_in++] + "" + data[rx_ptr_in++] + " ";
}
//Period
iPeriod = ((AsciiToHex(data[rx_ptr_in++]) << 12) |
(AsciiToHex(data[rx_ptr_in++]) << 8) |
(AsciiToHex(data[rx_ptr_in++]) << 4) |
(AsciiToHex(data[rx_ptr_in]) << 0));//
return rx_ptr_in;
}
public int TsimbolRx (char[] data, int rx_ptr_in)
{
rx_ptr_in++;
//ID
sId = data[rx_ptr_in++] + "" + data[rx_ptr_in++] + "" + data[rx_ptr_in++] + "" + data[rx_ptr_in++] + "" +
data[rx_ptr_in++] + "" + data[rx_ptr_in++] + "" + data[rx_ptr_in++] + "" + data[rx_ptr_in++];
//DLC
sDlc = data[rx_ptr_in] + "";
int iDlc = (data[rx_ptr_in++] & 0x0F) * 2;
if (iDlc > 16) iDlc = 16;
//MSG
for (int i = 0; i < iDlc; i += 2)
{
sMsg += data[rx_ptr_in++] + "" + data[rx_ptr_in++] + " ";
}
//Period
iPeriod = ((AsciiToHex(data[rx_ptr_in++]) << 12) |
(AsciiToHex(data[rx_ptr_in++]) << 8) |
(AsciiToHex(data[rx_ptr_in++]) << 4) |
(AsciiToHex(data[rx_ptr_in++]) << 0));//
return rx_ptr_in;
}
public int AsciiToHex(int ascii)
{
if ((ascii >= '0') && (ascii <= '9')) return (ascii - '0');
if ((ascii >= 'A') && (ascii <= 'F')) return (ascii - 'A' + 10);
if ((ascii >= 'a') && (ascii <= 'f')) return (ascii - 'a' + 10);
return (0xFF);
}
public Lawicel()
{
}
}