-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoRaWANConfig.cs
164 lines (141 loc) · 5.29 KB
/
LoRaWANConfig.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
using hio_dotnet.Common.Enums.LoRaWAN;
using hio_dotnet.Common.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using System.Reflection;
namespace hio_dotnet.Common.Config
{
public class LoRaWANConfig : ConfigCommon
{
#region ConnectionParams
[ConfigSerializationAttribute(true, false, "lrw", "devaddr")]
public string DevAddr { get; set; } = "00000000";
[ConfigSerializationAttribute(true, false, "lrw", "deveui")]
public string DevEui { get; set; } = "0000000000000000";
[ConfigSerializationAttribute(true, false, "lrw", "joineui")]
public string JoinEui { get; set; } = "0000000000000000";
[ConfigSerializationAttribute(true, false, "lrw", "appkey")]
public string AppKey { get; set; } = "00000000000000000000000000000000";
[ConfigSerializationAttribute(true, false, "lrw", "appskey")]
public string AppSKey { get; set; } = "00000000000000000000000000000000";
[ConfigSerializationAttribute(true, false, "lrw", "nwkskey")]
public string NwkSKey { get; set; } = "00000000000000000000000000000000";
#endregion
#region LoRaWANParams
[ConfigSerializationAttribute(true, false, "lrw", "antenna")]
public AntennaType Antenna { get; set; } = AntennaType.Internal;
[ConfigSerializationAttribute(true, false, "lrw", "band")]
public LoRaWANBand Band { get; set; } = LoRaWANBand.EU868;
[ConfigSerializationAttribute(true, false, "lrw", "mode")]
public LoRaWANMode Mode { get; set; } = LoRaWANMode.OTAA;
[ConfigSerializationAttribute(true, false, "lrw", "nwk")]
public LoRaWANNetwork Network { get; set; } = LoRaWANNetwork.Private;
[ConfigSerializationAttribute(true, false, "lrw", "class")]
public LoRaWANClass Class { get; set; } = LoRaWANClass.A;
#endregion
[ConfigSerializationAttribute(true, false, "lrw", "adr")]
public bool Adr { get; set; } = true;
[ConfigSerializationAttribute(true, false, "lrw", "test")]
public bool Test { get; set; } = false;
[ConfigSerializationAttribute(true, false, "lrw", "dutycycle")]
public bool DutyCycle { get; set; } = false;
[ConfigSerializationAttribute(true, false, "lrw", "datarate")]
public int DataRate { get; set; } = 0;
#region FluentInterface
// Metody pro fluent interface
public LoRaWANConfig WithDevAddr(string devAddr)
{
DevAddr = devAddr;
return this;
}
public LoRaWANConfig WithDevEui(string devEui)
{
DevEui = devEui;
return this;
}
public LoRaWANConfig WithJoinEui(string joinEui)
{
JoinEui = joinEui;
return this;
}
public LoRaWANConfig WithAppKey(string appKey)
{
AppKey = appKey;
return this;
}
public LoRaWANConfig WithAppSKey(string appSKey)
{
AppSKey = appSKey;
return this;
}
public LoRaWANConfig WithNwkSKey(string nwkSKey)
{
NwkSKey = nwkSKey;
return this;
}
public LoRaWANConfig WithAntenna(AntennaType antenna)
{
Antenna = antenna;
return this;
}
public LoRaWANConfig WithBand(LoRaWANBand band)
{
Band = band;
return this;
}
public LoRaWANConfig WithMode(LoRaWANMode mode)
{
Mode = mode;
return this;
}
public LoRaWANConfig WithNetwork(LoRaWANNetwork network)
{
Network = network;
return this;
}
public LoRaWANConfig WithClass(LoRaWANClass @class)
{
Class = @class;
return this;
}
public LoRaWANConfig WithAdr(bool adr)
{
Adr = adr;
return this;
}
public LoRaWANConfig WithTest(bool test)
{
Test = test;
return this;
}
public LoRaWANConfig WithDutyCycle(bool dutyCycle)
{
DutyCycle = dutyCycle;
return this;
}
public LoRaWANConfig WithDataRate(int dataRate)
{
DataRate = dataRate;
return this;
}
#endregion
public void ParseLine(string line)
{
if (string.IsNullOrEmpty(line))
throw new ArgumentNullException("LoRaWAN Parsing>> Cannot parse null or empty line");
if (line.Contains("lte "))
throw new ArgumentException("LoRaWAN Parsing>> The config line is not for LoRa. It belongs to LTE parsing.");
if (line.Contains("ble "))
throw new ArgumentException("LoRaWAN Parsing>> The config line is not for LoRa. It belongs to BLE parsing.");
if (line.Contains("app "))
throw new ArgumentException("LoRaWAN Parsing>> The config line is not for LoRa. It belongs to APP parsing.");
if (line.Contains("lrw config "))
line = line.Replace("lrw config ", string.Empty).ReplaceLineEndings();
ParseLineToProp(line);
}
}
}