forked from thrandre/ZSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.cs
More file actions
80 lines (73 loc) · 2.08 KB
/
Copy pathUtils.cs
File metadata and controls
80 lines (73 loc) · 2.08 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ZSharp
{
public static class Utils
{
// Methods
internal static byte[] ByteSubstring(byte[] buffer, int startIndex, int length)
{
byte[] buffer2 = new byte[length];
for (int i = 0; i < length; i++)
{
buffer2[i] = buffer[i + startIndex];
}
return buffer2;
}
internal static string ByteArrayToString(byte[] message)
{
string s = string.Empty;
for (int i = 0; i < message.Length; i++)
{
s += message[i].ToString("X2") + " ";
}
return s;
}
internal enum VersionType
{
API,
SDK
}
internal static string VersionToString(byte[] p, VersionType versionType)
{
string s = string.Empty;
foreach (var b in p)
{
s += b;
}
return s;
}
internal static string GenericTypeToString(byte genericType)
{
switch (genericType)
{
case 0x01:
return "GENERIC_CONTROLLER";
case 0x02:
return "STATIC_CONTROLLER";
case 0x10:
return "SWITCH_BINARY";
case 0x11:
return "SWITCH_MULTILEVEL";
case 0x20:
return "SENSOR_BINARY";
case 0x21:
return "SENSOR_MULTILEVEL";
case 0x31:
return "METER";
default:
return "Unknown";
}
}
public static void SafeEventFire(object sender, EventArgs e, EventHandler evt)
{
var tmpEvt = Interlocked.CompareExchange(ref evt, null, null);
if (tmpEvt != null)
tmpEvt(sender, e);
}
}
}