-
Notifications
You must be signed in to change notification settings - Fork 0
/
PdSop.cs
136 lines (126 loc) · 2.77 KB
/
PdSop.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
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace USB_PD_Analyzer
{
internal class PdSop
{
public enum SopType
{
Sop,
SopPrime,
SopDoublePrime,
SopPrimeDebug,
SopDoublePrimeDebug,
HardReset,
CableReset,
Error
}
public enum K_code
{
Sync_1 = 0x03,
Sync_2 = 0x11,
Sync_3 = 0x0c,
RST_1 = 0x1c,
RST_2 = 0x13
}
public readonly K_code[] value = new K_code[4];
public PdSop(byte[] d)
{
if (d.Count() != 4)
throw new ArgumentException();
for (int i = 0; i < 4; i++)
{
value[i] = (K_code)d[i];
}
}
public SopType Sop
{
get
{
if (value.SequenceEqual(new K_code[] { K_code.Sync_1, K_code.Sync_1, K_code.Sync_1, K_code.Sync_2 }))
{
return SopType.Sop;
}
else if (value.SequenceEqual(new K_code[] { K_code.Sync_1, K_code.Sync_1, K_code.Sync_3, K_code.Sync_3 }))
{
return SopType.SopPrime;
}
else if (value.SequenceEqual(new K_code[] { K_code.Sync_1, K_code.Sync_3, K_code.Sync_1, K_code.Sync_3 }))
{
return SopType.SopDoublePrime;
}
else if (value.SequenceEqual(new K_code[] { K_code.Sync_1, K_code.RST_2, K_code.RST_2, K_code.Sync_3 }))
{
return SopType.SopPrimeDebug;
}
else if (value.SequenceEqual(new K_code[] { K_code.Sync_1, K_code.RST_2, K_code.Sync_3, K_code.Sync_2 }))
{
return SopType.SopDoublePrimeDebug;
}
else if (value.SequenceEqual(new K_code[] { K_code.RST_1, K_code.RST_1, K_code.RST_1, K_code.RST_2 }))
{
return SopType.CableReset;
}
else if (value.SequenceEqual(new K_code[] { K_code.Sync_1, K_code.Sync_1, K_code.RST_1, K_code.Sync_3 }))
{
return SopType.HardReset;
}
return SopType.Error;
}
}
public string GetSopTypeString()
{
switch (this.Sop)
{
case SopType.Sop:
return "SOP";
case SopType.SopPrime:
return "SOP'";
case SopType.SopDoublePrime:
return "SOP''";
case SopType.SopPrimeDebug:
return "SOP'_Debug";
case SopType.SopDoublePrimeDebug:
return "SOP''_Debug";
case SopType.CableReset:
return "Cable Reset";
case SopType.HardReset:
return "Hard Reset";
default:
return "Error";
}
}
public IEnumerable<string> GetSopString()
{
List<string> ss = new List<string>();
for (int i = 0; i < 4; i++)
{
switch (this.value[i])
{
case K_code.Sync_1:
ss.Add("Sync-1");
break;
case K_code.Sync_2:
ss.Add("Sync-2");
break;
case K_code.Sync_3:
ss.Add("Sync-3");
break;
case K_code.RST_1:
ss.Add("RST-1");
break;
case K_code.RST_2:
ss.Add("RST-2");
break;
default:
ss.Add("Error");
break;
}
}
return ss;
}
}
}