-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathIcom.CIV.Core.Helpers.cs
More file actions
41 lines (38 loc) · 1.29 KB
/
Copy pathIcom.CIV.Core.Helpers.cs
File metadata and controls
41 lines (38 loc) · 1.29 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
using System;
using System.Reflection;
using System.ComponentModel;
namespace Icom.CIV
{
public partial class Core : IDisposable
{
// Helper to extract description attribute
private static string GetEnumDescription(Enum value)
{
FieldInfo fi = value.GetType().GetField(value.ToString());
System.ComponentModel.
DescriptionAttribute[] attributes =
(DescriptionAttribute[])fi.GetCustomAttributes(
typeof(DescriptionAttribute),
false);
if (attributes != null &&
attributes.Length > 0)
return attributes[0].Description;
else
return value.ToString();
}
// Convert an unsigned integer into 5 bytes of
private byte[] IntToBCD5(uint numericvalue, int bytesize = 5)
{
byte[] bcd = new byte[bytesize];
for (int byteNo = 0; byteNo < bytesize; ++byteNo)
bcd[byteNo] = 0;
for (int digit = 0; digit < bytesize * 2; ++digit)
{
uint hexpart = numericvalue % 10;
bcd[digit / 2] |= (byte)(hexpart << ((digit % 2) * 4));
numericvalue /= 10;
}
return bcd;
}
}
}