- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArduinoFunction.cs
More file actions
Latest commit
78 lines (73 loc) · 3.32 KB
/
Copy pathArduinoFunction.cs
File metadata and controls
78 lines (73 loc) · 3.32 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
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Text;
namespaceArduinoDynamicDriver
{
publicclassArduinoFunction
{
publicreadonlybyteFunctionId;
publicreadonlyIList<SupportedType>ArgumentTypes;
publicreadonlySupportedTypeReturnType;
object[]Arguments;
publicArduinoFunction(bytefunctionId,IList<SupportedType>argumentTypes,SupportedTypereturnType,paramsobject[]arguments)
{
FunctionId=functionId;
ArgumentTypes=argumentTypes??thrownewArgumentNullException(nameof(argumentTypes));
ReturnType=returnType;
Arguments=arguments;
}
publicIList<Byte>GetDataBytes()
{
varresult=newList<byte>();
for(inti=0;i<Arguments.Length;i++)
{
varargument=Arguments[i];
varargumentType=ArgumentTypes[i];
switch(argumentType)
{
caseSupportedType.BOOLEANT:
varboolean=(bool)argument;
result.Add(boolean?(byte)1:(byte)0);
break;
caseSupportedType.CHART:
result.Add(BitConverter.GetBytes(Convert.ToSByte(argument))[0]);
break;
caseSupportedType.UCHART:
result.Add(Convert.ToByte(argument));
break;
caseSupportedType.BYTET:
result.Add(Convert.ToByte(argument));
break;
caseSupportedType.INTT:
varinteger=Convert.ToInt16(argument);
varintegerReperesentation=BitConverter.GetBytes(integer);
result.AddRange(integerReperesentation);
break;
caseSupportedType.UINTT:
varuinteger=Convert.ToUInt16(argument);
varuintegerReperesentation=BitConverter.GetBytes(uinteger);
result.AddRange(uintegerReperesentation);
break;
caseSupportedType.LONG:
varlon=Convert.ToInt32(argument);
varlonRepresentation=BitConverter.GetBytes(lon);
result.AddRange(lonRepresentation);
break;
caseSupportedType.ULONG:
varulon=Convert.ToUInt32(argument);
varulonRepresentation=BitConverter.GetBytes(ulon);
result.AddRange(ulonRepresentation);
break;
caseSupportedType.SHORT:
varshor=Convert.ToInt16(argument);
varshorReprestation=BitConverter.GetBytes(shor);
result.AddRange(shorReprestation);
break;
caseSupportedType.VOIDT:
thrownewArgumentException("An argument cant be VOIDT");
}
}
returnresult;
}
}
}