This repository was archived by the owner on Dec 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathLoRaArduinoSerial.Helper.cs
More file actions
89 lines (79 loc) · 3.04 KB
/
LoRaArduinoSerial.Helper.cs
File metadata and controls
89 lines (79 loc) · 3.04 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
81
82
83
84
85
86
87
88
89
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace LoRaWan.Tests.E2E
{
using System;
using System.IO.Ports;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using LoRaWan.Tests.Shared;
/// <summary>
/// Lora Arduino Serial Class.
/// </summary>
public sealed partial class LoRaArduinoSerial
{
public static LoRaArduinoSerial CreateFromPort(string port)
{
var isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
LoRaArduinoSerial result = null;
TestLogger.Log($"** Starting serial port '{port}' **");
var serialPort = new SerialPort(port)
{
BaudRate = 115200,
Parity = Parity.None,
StopBits = StopBits.One,
DataBits = 8,
DtrEnable = true,
Handshake = Handshake.None
};
result = new LoRaArduinoSerial(serialPort);
try
{
serialPort.Open();
}
catch (Exception ex)
{
TestLogger.Log($"Error opening serial port '{port}': {ex.ToString()}");
throw;
}
return result;
}
// Setup lora for a given region
public async Task SetupLora(
LoraRegion region,
LoRaArduinoSerial._data_rate_t dataRate = LoRaArduinoSerial._data_rate_t.DR6,
short power = 14,
bool adr = false)
{
try
{
await this.setAdaptiveDataRateAsync(adr);
if (region == LoraRegion.EU)
{
await this.setDataRateAsync(dataRate, LoRaArduinoSerial._physical_type_t.EU868);
await this.setChannelAsync(0, 868.1F);
await this.setChannelAsync(1, 868.3F);
await this.setChannelAsync(2, 868.5F);
await this.setChannelAsync(3, 867.1F);
await this.setChannelAsync(4, 867.3F);
await this.setChannelAsync(5, 867.5F);
await this.setChannelAsync(6, 867.7F);
await this.setReceiceWindowFirstAsync(0, 868.1F);
await this.setReceiceWindowSecondAsync(869.5F, LoRaArduinoSerial._data_rate_t.DR0);
}
else
{
await this.setDataRateAsync(LoRaArduinoSerial._data_rate_t.DR0, LoRaArduinoSerial._physical_type_t.US915HYBRID);
}
await this.setConfirmedMessageRetryTimeAsync(10);
await this.setDutyCycleAsync(false);
await this.setJoinDutyCycleAsync(false);
await this.setPowerAsync(power);
}
catch (Exception ex)
{
TestLogger.Log($"Error during {nameof(this.SetupLora)}. {ex.ToString()}");
}
}
}
}