Feature/fix cn (#1054)
* Add china fixes * fix cn again * Commit CN * Last fixes for china * Fix Arduino code * Fix tests * React to comments * Remove old comment * Remove using * Correct sample
This commit is contained in:
Родитель
3043ae1c90
Коммит
ca99c726a6
|
@ -84,8 +84,8 @@ void loop(void)
|
|||
short length;
|
||||
short rssi;
|
||||
|
||||
memset(buffer, 0, 256);
|
||||
length = lora.receivePacket(buffer, 256, &rssi);
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
length = lora.receivePacket(buffer, sizeof(buffer), &rssi);
|
||||
|
||||
if (length)
|
||||
{
|
||||
|
|
|
@ -83,8 +83,8 @@ void loop(void)
|
|||
short length;
|
||||
short rssi;
|
||||
|
||||
memset(buffer, 0, 256);
|
||||
length = lora.receivePacket(buffer, 256, &rssi);
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
length = lora.receivePacket(buffer, sizeof(buffer), &rssi);
|
||||
|
||||
if(length)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,113 @@
|
|||
|
||||
#include <LoRaWan.h>
|
||||
// THOSE ARDUINO SAMPLE REQUIRES CHANGES IN THE ARDUINO CODE TO RUN DESCRIBED IN THE MAIN REPO
|
||||
// THE CONCENTRATOR IS EXPECTED TO HAVE THE FOLLOWING FREQUENCIES ACTIVATED
|
||||
// 498.3, 498.7, 498.9, 499.1, 499.3, 499.5, 499.7, 499.9
|
||||
// please refer to the repo documentation for further information
|
||||
|
||||
//set to true to send confirmed data up messages
|
||||
bool confirmed = true;
|
||||
//application information, should be similar to what was provisiionned in the device twins
|
||||
char * deviceId = "46AAC86800430028";
|
||||
char * devAddr = "0228B1B1";
|
||||
char * appSKey = "2B7E151628AED2A6ABF7158809CF4F3C";
|
||||
char * nwkSKey = "3B7E151628AED2A6ABF7158809CF4F3C";
|
||||
|
||||
|
||||
/*
|
||||
iot hub ABP tags for deviceid: 46AAC86800430028
|
||||
"desired": {
|
||||
"AppSKey": "2B7E151628AED2A6ABF7158809CF4F3C",
|
||||
"NwkSKey": "3B7E151628AED2A6ABF7158809CF4F3C",
|
||||
"DevAddr": "0228B1B1",
|
||||
"GatewayID" :"",
|
||||
"SensorDecoder" :"DecoderValueSensor"
|
||||
},
|
||||
*/
|
||||
|
||||
//set initial datarate and physical information for the device
|
||||
_data_rate_t dr = DR6;
|
||||
_physical_type_t physicalType = CN470PREQUEL ;
|
||||
|
||||
//internal variables
|
||||
char data[10];
|
||||
char buffer[256];
|
||||
int i = 0;
|
||||
int lastCall = 0;
|
||||
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
SerialUSB.begin(115200);
|
||||
while (!SerialUSB);
|
||||
lora.init();
|
||||
lora.setDeviceDefault();
|
||||
|
||||
lora.setId(devAddr, deviceId, NULL);
|
||||
lora.setKey(nwkSKey, appSKey, NULL);
|
||||
|
||||
lora.setDeciveMode(LWABP);
|
||||
lora.setDataRate(dr, physicalType);
|
||||
lora.setChannel(0, 499.9);
|
||||
lora.setChannel(1, 499.7);
|
||||
lora.setChannel(2, 499.5);
|
||||
lora.setChannel(3, 499.3);
|
||||
lora.setChannel(4, 499.1);
|
||||
lora.setChannel(5, 498.9);
|
||||
lora.setChannel(6, 498.7);
|
||||
lora.setChannel(7, 498.3);
|
||||
|
||||
lora.setReceiceWindowFirst(0, 868.1);
|
||||
|
||||
lora.setReceiceWindowSecond(498.3, DR1);
|
||||
|
||||
lora.setDutyCycle(false);
|
||||
lora.setJoinDutyCycle(false);
|
||||
|
||||
|
||||
lora.setPower(6);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
if ((millis() - lastCall) > 5000) {
|
||||
lastCall = millis();
|
||||
bool result = false;
|
||||
String packetString = "";
|
||||
packetString = String(i);
|
||||
SerialUSB.println(packetString);
|
||||
packetString.toCharArray(data, 10);
|
||||
|
||||
if (confirmed)
|
||||
result = lora.transferPacketWithConfirmed(data, 10);
|
||||
else
|
||||
result = lora.transferPacket(data, 10);
|
||||
i++;
|
||||
|
||||
if (result)
|
||||
{
|
||||
short length;
|
||||
short rssi;
|
||||
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
length = lora.receivePacket(buffer, sizeof(buffer), &rssi);
|
||||
|
||||
if (length)
|
||||
{
|
||||
SerialUSB.print("Length is: ");
|
||||
SerialUSB.println(length);
|
||||
SerialUSB.print("RSSI is: ");
|
||||
SerialUSB.println(rssi);
|
||||
SerialUSB.print("Data is: ");
|
||||
for (unsigned char i = 0; i < length; i ++)
|
||||
{
|
||||
SerialUSB.print( char(buffer[i]));
|
||||
|
||||
}
|
||||
SerialUSB.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,123 @@
|
|||
|
||||
#include <LoRaWan.h>
|
||||
//set to true to send confirmed data up messages
|
||||
// THOSE ARDUINO SAMPLE REQUIRES CHANGES IN THE ARDUINO CODE TO RUN DESCRIBED IN THE MAIN REPO
|
||||
// THE CONCENTRATOR IS EXPECTED TO HAVE THE FOLLOWING FREQUENCIES ACTIVATED
|
||||
// 498.3, 498.7, 498.9, 499.1, 499.3, 499.5, 499.7, 499.9
|
||||
// please refer to the repo documentation for further information
|
||||
|
||||
bool confirmed=true;
|
||||
//application information, should be similar to what was provisiionned in the device twins
|
||||
char * deviceId ="47AAC86800430028";
|
||||
char * appKey="8AFE71A145B253E49C3031AD068277A1";
|
||||
char * appEui ="BE7A0000000014E2";
|
||||
|
||||
/*
|
||||
iot hub OTAA tags for deviceid: 47AAC86800430028
|
||||
"desired": {
|
||||
"AppEUI": "BE7A0000000014E2",
|
||||
"AppKey": "8AFE71A145B253E49C3031AD068277A1",
|
||||
"GatewayID" :"",
|
||||
"SensorDecoder" :"DecoderValueSensor"
|
||||
},
|
||||
*/
|
||||
|
||||
//set initial datarate and physical information for the device
|
||||
_data_rate_t dr=DR0;
|
||||
_data_rate_t drrx2=DR1;
|
||||
_physical_type_t physicalType=CN470PREQUEL ;
|
||||
|
||||
//internal variables
|
||||
char data[10];
|
||||
char buffer[256];
|
||||
int i=0;
|
||||
int lastCall=0;
|
||||
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
SerialUSB.begin(115200);
|
||||
while(!SerialUSB);
|
||||
lora.init();
|
||||
lora.setDeviceDefault();
|
||||
delay(1000);
|
||||
lora.setPower(6);
|
||||
lora.setId(NULL,deviceId , appEui);
|
||||
lora.setKey(NULL, NULL, appKey);
|
||||
|
||||
lora.setDeciveMode(LWOTAA);
|
||||
lora.setDataRate(dr, physicalType);
|
||||
lora.setChannel(0, 499.9);
|
||||
lora.setChannel(1, 499.9);
|
||||
lora.setChannel(2, 499.9);
|
||||
lora.setChannel(3, 499.9);
|
||||
lora.setChannel(4, 499.9);
|
||||
lora.setChannel(5, 499.9);
|
||||
lora.setChannel(6, 499.9);
|
||||
lora.setChannel(7, 499.9);
|
||||
|
||||
|
||||
lora.setReceiceWindowSecond(498.3, drrx2);
|
||||
|
||||
lora.setAdaptiveDataRate(false);
|
||||
|
||||
lora.setDutyCycle(false);
|
||||
lora.setJoinDutyCycle(false);
|
||||
|
||||
lora.setPower(2);
|
||||
|
||||
while(!lora.setOTAAJoin(JOIN,20000));
|
||||
|
||||
// reenable channels after OTAA
|
||||
lora.setChannel(1, 498.3);
|
||||
lora.setChannel(2, 499.7);
|
||||
lora.setChannel(3, 499.5);
|
||||
lora.setChannel(4, 499.3);
|
||||
lora.setChannel(5, 499.1);
|
||||
lora.setChannel(6, 498.9);
|
||||
lora.setChannel(7, 498.7);
|
||||
|
||||
}
|
||||
|
||||
void loop(void)
|
||||
{
|
||||
|
||||
if((millis()-lastCall)>5000){
|
||||
lastCall=millis();
|
||||
bool result = false;
|
||||
String packetString = "";
|
||||
packetString=String(i);
|
||||
SerialUSB.println(packetString);
|
||||
packetString.toCharArray(data, 10);
|
||||
|
||||
if(confirmed)
|
||||
result = lora.transferPacketWithConfirmed(data, 10);
|
||||
else
|
||||
result = lora.transferPacket(data, 10);
|
||||
i++;
|
||||
|
||||
if(result)
|
||||
{
|
||||
short length;
|
||||
short rssi;
|
||||
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
length = lora.receivePacket(buffer, sizeof(buffer), &rssi);
|
||||
|
||||
if(length)
|
||||
{
|
||||
SerialUSB.print("Length is: ");
|
||||
SerialUSB.println(length);
|
||||
SerialUSB.print("RSSI is: ");
|
||||
SerialUSB.println(rssi);
|
||||
SerialUSB.print("Data is: ");
|
||||
for(unsigned char i = 0; i < length; i ++)
|
||||
{
|
||||
SerialUSB.print( char(buffer[i]));
|
||||
|
||||
}
|
||||
SerialUSB.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -102,8 +102,8 @@ void loop(void)
|
|||
short length;
|
||||
short rssi;
|
||||
|
||||
memset(buffer, 0, 256);
|
||||
length = lora.receivePacket(buffer, 256, &rssi);
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
length = lora.receivePacket(buffer, sizeof(buffer), &rssi);
|
||||
|
||||
if (length)
|
||||
{
|
||||
|
|
|
@ -60,8 +60,8 @@ void sendPacketString(String packetString)
|
|||
short length;
|
||||
short rssi;
|
||||
|
||||
memset(buffer, 0, 256);
|
||||
length = lora.receivePacket(buffer, 256, &rssi);
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
length = lora.receivePacket(buffer, sizeof(buffer), &rssi);
|
||||
|
||||
if (length)
|
||||
{
|
||||
|
|
|
@ -197,8 +197,8 @@ void sendLoraMessage(void)
|
|||
short length;
|
||||
short rssi;
|
||||
|
||||
memset(buffer, 0, 256);
|
||||
length = lora.receivePacket(buffer, 256, &rssi);
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
length = lora.receivePacket(buffer, sizeof(buffer), &rssi);
|
||||
|
||||
if(length)
|
||||
{
|
||||
|
|
|
@ -72,8 +72,8 @@ void loop(void)
|
|||
short length;
|
||||
short rssi;
|
||||
SerialUSB.print("receiving ");
|
||||
memset(buffer, 0, 256);
|
||||
length = lora.receivePacket(buffer, 256, &rssi);
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
length = lora.receivePacket(buffer, sizeof(buffer), &rssi);
|
||||
|
||||
if (length)
|
||||
{
|
||||
|
|
|
@ -81,8 +81,8 @@ void loop(void)
|
|||
short length;
|
||||
short rssi;
|
||||
|
||||
memset(buffer, 0, 256);
|
||||
length = lora.receivePacket(buffer, 256, &rssi);
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
length = lora.receivePacket(buffer, sizeof(buffer), &rssi);
|
||||
|
||||
if (length)
|
||||
{
|
||||
|
|
|
@ -79,8 +79,8 @@ void loop(void)
|
|||
short length;
|
||||
short rssi;
|
||||
|
||||
memset(buffer, 0, 256);
|
||||
length = lora.receivePacket(buffer, 256, &rssi);
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
length = lora.receivePacket(buffer, sizeof(buffer), &rssi);
|
||||
|
||||
if(length)
|
||||
{
|
||||
|
|
|
@ -98,8 +98,8 @@ void loop(void)
|
|||
short length;
|
||||
short rssi;
|
||||
|
||||
memset(buffer, 0, 256);
|
||||
length = lora.receivePacket(buffer, 256, &rssi);
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
length = lora.receivePacket(buffer, sizeof(buffer), &rssi);
|
||||
|
||||
if (length)
|
||||
{
|
||||
|
|
|
@ -194,8 +194,8 @@ void sendLoraMessage(void)
|
|||
short length;
|
||||
short rssi;
|
||||
|
||||
memset(buffer, 0, 256);
|
||||
length = lora.receivePacket(buffer, 256, &rssi);
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
length = lora.receivePacket(buffer, sizeof(buffer), &rssi);
|
||||
|
||||
if(length)
|
||||
{
|
||||
|
|
|
@ -77,8 +77,8 @@ void loop(void)
|
|||
short length;
|
||||
short rssi;
|
||||
|
||||
memset(buffer, 0, 256);
|
||||
length = lora.receivePacket(buffer, 256, &rssi);
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
length = lora.receivePacket(buffer, sizeof(buffer), &rssi);
|
||||
|
||||
if(length)
|
||||
{
|
||||
|
|
|
@ -73,8 +73,8 @@ void loop(void)
|
|||
short length;
|
||||
short rssi;
|
||||
|
||||
memset(buffer, 0, 256);
|
||||
length = lora.receivePacket(buffer, 256, &rssi);
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
length = lora.receivePacket(buffer, sizeof(buffer), &rssi);
|
||||
|
||||
if(length)
|
||||
{
|
||||
|
|
|
@ -227,6 +227,7 @@ namespace LoRaWan.NetworkServer
|
|||
|
||||
if (logger.IsEnabled(LogLevel.Debug))
|
||||
logger.LogDebug($"{ackLoRaMessage.MessageType} {JsonConvert.SerializeObject(downlinkPktFwdMessage)}");
|
||||
downlinkPktFwdMessage.DeviceJoinInfo = deviceJoinInfo;
|
||||
|
||||
return new DownlinkMessageBuilderResponse(downlinkPktFwdMessage, isMessageTooLong, receiveWindow);
|
||||
}
|
||||
|
|
|
@ -173,6 +173,7 @@ namespace LoRaWan.NetworkServer
|
|||
updatedProperties.StationEui = request.StationEui;
|
||||
}
|
||||
|
||||
DeviceJoinInfo deviceJoinInfo = null;
|
||||
if (request.Region.LoRaRegion == LoRaRegionType.CN470RP2)
|
||||
{
|
||||
#pragma warning disable CS0618 // #655 - This Rxpk based implementation will go away as soon as the complete LNS implementation is done
|
||||
|
@ -180,6 +181,7 @@ namespace LoRaWan.NetworkServer
|
|||
#pragma warning restore CS0618 // #655 - This Rxpk based implementation will go away as soon as the complete LNS implementation is done
|
||||
{
|
||||
updatedProperties.CN470JoinChannel = channelIndex;
|
||||
deviceJoinInfo = new DeviceJoinInfo(channelIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -214,7 +216,7 @@ namespace LoRaWan.NetworkServer
|
|||
#pragma warning disable CS0618 // #655 - This Rxpk based implementation will go away as soon as the complete LNS implementation is done
|
||||
datr = loraRegion.GetDownstreamDataRate(request.Rxpk);
|
||||
#pragma warning restore CS0618 // #655 - This Rxpk based implementation will go away as soon as the complete LNS implementation is done
|
||||
if (!loraRegion.TryGetDownstreamChannelFrequency(request.Rxpk.FreqHertz, out freq) || datr == null)
|
||||
if (!loraRegion.TryGetDownstreamChannelFrequency(request.Rxpk.FreqHertz, out freq, deviceJoinInfo: deviceJoinInfo) || datr == null)
|
||||
{
|
||||
this.logger.LogError("could not resolve DR and/or frequency for downstream");
|
||||
request.NotifyFailed(loRaDevice, LoRaDeviceRequestFailedReason.InvalidRxpk);
|
||||
|
@ -231,9 +233,9 @@ namespace LoRaWan.NetworkServer
|
|||
tmst = request.Rxpk.Tmst + (loraRegion.JoinAcceptDelay2 * 1000000);
|
||||
lnsRxDelay = (ushort)loraRegion.JoinAcceptDelay2;
|
||||
|
||||
freq = loraRegion.GetDownstreamRX2Freq(this.configuration.Rx2Frequency, logger);
|
||||
freq = loraRegion.GetDownstreamRX2Freq(this.configuration.Rx2Frequency, logger, deviceJoinInfo);
|
||||
#pragma warning disable CS0618 // #655 - This Rxpk based implementation will go away as soon as the complete LNS implementation is done
|
||||
datr = loraRegion.GetDownstreamRX2DataRate(devEUI, this.configuration.Rx2DataRate, null, logger);
|
||||
datr = loraRegion.GetDownstreamRX2DataRate(devEUI, this.configuration.Rx2DataRate, null, logger, deviceJoinInfo);
|
||||
#pragma warning restore CS0618 // #655 - This Rxpk based implementation will go away as soon as the complete LNS implementation is done
|
||||
}
|
||||
|
||||
|
@ -290,7 +292,7 @@ namespace LoRaWan.NetworkServer
|
|||
loraSpecDesiredRxDelay,
|
||||
null);
|
||||
|
||||
var joinAccept = loRaPayloadJoinAccept.Serialize(loRaDevice.AppKey, datr, freq, devEUI, tmst, lnsRxDelay, request.Rxpk.Rfch, request.Rxpk.Time, request.StationEui);
|
||||
var joinAccept = loRaPayloadJoinAccept.Serialize(loRaDevice.AppKey, datr, freq, devEUI, tmst, lnsRxDelay, request.Rxpk.Rfch, request.Rxpk.Time, request.StationEui, deviceJoinInfo);
|
||||
if (joinAccept != null)
|
||||
{
|
||||
this.receiveWindowHits?.Add(1, KeyValuePair.Create(MetricRegistry.ReceiveWindowTagName, (object)windowToUse));
|
||||
|
|
|
@ -994,6 +994,7 @@ namespace LoRaWan.NetworkServer
|
|||
AppNonce = updateProperties.AppNonce;
|
||||
DevNonce = updateProperties.DevNonce;
|
||||
NetID = updateProperties.NetID;
|
||||
ReportedCN470JoinChannel = updateProperties.CN470JoinChannel;
|
||||
|
||||
if (currentRegion.IsValidRX1DROffset(DesiredRX1DROffset))
|
||||
{
|
||||
|
|
|
@ -6,7 +6,6 @@ namespace LoRaWan.NetworkServer
|
|||
using System;
|
||||
using System.Diagnostics.Metrics;
|
||||
using LoRaTools.LoRaMessage;
|
||||
using LoRaTools.Regions;
|
||||
using LoRaTools.Utils;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
@ -20,7 +19,6 @@ namespace LoRaWan.NetworkServer
|
|||
private readonly NetworkServerConfiguration configuration;
|
||||
private readonly ILoRaDeviceRegistry deviceRegistry;
|
||||
private readonly ILoRaDeviceFrameCounterUpdateStrategyProvider frameCounterUpdateStrategyProvider;
|
||||
private volatile Region loraRegion;
|
||||
private readonly IJoinRequestMessageHandler joinRequestHandler;
|
||||
private readonly ILoggerFactory loggerFactory;
|
||||
private readonly ILogger<MessageDispatcher> logger;
|
||||
|
@ -85,22 +83,12 @@ namespace LoRaWan.NetworkServer
|
|||
request.SetPayload(loRaPayload);
|
||||
}
|
||||
|
||||
if (this.loraRegion == null)
|
||||
if (request.Region is null)
|
||||
{
|
||||
#pragma warning disable CS0618 // #655 - This Rxpk based implementation will go away as soon as the complete LNS implementation is done
|
||||
if (!RegionManager.TryResolveRegion(request.Rxpk, out var currentRegion))
|
||||
#pragma warning restore CS0618 // #655 - This Rxpk based implementation will go away as soon as the complete LNS implementation is done
|
||||
{
|
||||
// log is generated in Region factory
|
||||
// move here once V2 goes GA
|
||||
request.NotifyFailed(LoRaDeviceRequestFailedReason.InvalidRegion);
|
||||
return;
|
||||
}
|
||||
|
||||
this.loraRegion = currentRegion;
|
||||
request.NotifyFailed(LoRaDeviceRequestFailedReason.InvalidRegion);
|
||||
return;
|
||||
}
|
||||
|
||||
request.SetRegion(this.loraRegion);
|
||||
|
||||
var loggingRequest = new LoggingLoRaRequest(request, this.loggerFactory.CreateLogger<LoggingLoRaRequest>(), this.d2cMessageDeliveryLatencyHistogram);
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ namespace LoRaTools.LoRaMessage
|
|||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using LoRaTools.LoRaPhysical;
|
||||
using LoRaTools.Regions;
|
||||
using LoRaTools.Utils;
|
||||
using LoRaWan;
|
||||
using Org.BouncyCastle.Crypto.Engines;
|
||||
|
@ -210,7 +211,7 @@ namespace LoRaTools.LoRaMessage
|
|||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public DownlinkPktFwdMessage Serialize(string appKey, string datr, Hertz freq, string devEui, long tmst, ushort lnsRxDelay = 0, uint? rfch = 0, string time = "", StationEui stationEui = default)
|
||||
public DownlinkPktFwdMessage Serialize(string appKey, string datr, Hertz freq, string devEui, long tmst, ushort lnsRxDelay = 0, uint? rfch = 0, string time = "", StationEui stationEui = default, DeviceJoinInfo deviceJoinInfo = null)
|
||||
{
|
||||
var algoinput = Mhdr.ToArray().Concat(AppNonce.ToArray()).Concat(NetID.ToArray()).Concat(DevAddr.ToArray()).Concat(DlSettings.ToArray()).Concat(RxDelay.ToArray()).ToArray();
|
||||
if (!CfList.Span.IsEmpty)
|
||||
|
@ -219,7 +220,7 @@ namespace LoRaTools.LoRaMessage
|
|||
_ = CalculateMic(appKey, algoinput);
|
||||
_ = PerformEncryption(appKey);
|
||||
|
||||
return new DownlinkPktFwdMessage(GetByteMessage(), datr, freq, devEui, tmst, lnsRxDelay, rfch, time, stationEui: stationEui);
|
||||
return new DownlinkPktFwdMessage(GetByteMessage(), datr, freq, devEui, tmst, lnsRxDelay, rfch, time, stationEui: stationEui, deviceJoinInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace LoRaTools.LoRaPhysical
|
|||
{
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using LoRaTools.Regions;
|
||||
using LoRaWan;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
|
@ -31,6 +32,9 @@ namespace LoRaTools.LoRaPhysical
|
|||
[JsonIgnore]
|
||||
public StationEui StationEui { get; }
|
||||
|
||||
[JsonIgnore]
|
||||
public DeviceJoinInfo DeviceJoinInfo { get; set; }
|
||||
|
||||
public DownlinkPktFwdMessage()
|
||||
{
|
||||
}
|
||||
|
@ -40,7 +44,7 @@ namespace LoRaTools.LoRaPhysical
|
|||
/// This method is used in case of a response to a upstream message.
|
||||
/// </summary>
|
||||
/// <returns>DownlinkPktFwdMessage object ready to be sent.</returns>
|
||||
public DownlinkPktFwdMessage(byte[] loRaData, string datr, Hertz freq, string devEui, long tmst = 0, ushort lnsRxDelay = 0, uint? rfch = null, string time = "", StationEui stationEui = default)
|
||||
public DownlinkPktFwdMessage(byte[] loRaData, string datr, Hertz freq, string devEui, long tmst = 0, ushort lnsRxDelay = 0, uint? rfch = null, string time = "", StationEui stationEui = default, DeviceJoinInfo deviceJoinInfo = null)
|
||||
{
|
||||
if (loRaData is null) throw new ArgumentNullException(nameof(loRaData));
|
||||
|
||||
|
@ -65,6 +69,7 @@ namespace LoRaTools.LoRaPhysical
|
|||
AntennaPreference = rfch;
|
||||
StationEui = stationEui;
|
||||
Xtime = string.IsNullOrEmpty(time) ? 0 : ulong.Parse(time, CultureInfo.InvariantCulture);
|
||||
DeviceJoinInfo = deviceJoinInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,6 +84,7 @@ namespace LoRaTools.Regions
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
private static Region eu868;
|
||||
|
||||
public static Region EU868
|
||||
|
|
|
@ -8,6 +8,7 @@ namespace LoRaWan.Tests.Common
|
|||
using System.Threading.Tasks;
|
||||
using LoRaTools.ADR;
|
||||
using LoRaTools.LoRaMessage;
|
||||
using LoRaTools.Regions;
|
||||
using LoRaWan.NetworkServer;
|
||||
using LoRaWan.NetworkServer.ADR;
|
||||
using LoRaWan.NetworkServer.BasicsStation;
|
||||
|
@ -28,6 +29,8 @@ namespace LoRaWan.Tests.Common
|
|||
|
||||
public TestPacketForwarder PacketForwarder { get; }
|
||||
|
||||
protected Region Region { get; }
|
||||
|
||||
protected Mock<LoRaDeviceAPIServiceBase> LoRaDeviceApi { get; }
|
||||
|
||||
protected ILoRaDeviceFrameCounterUpdateStrategyProvider FrameCounterUpdateStrategyProvider { get; }
|
||||
|
@ -82,6 +85,10 @@ namespace LoRaWan.Tests.Common
|
|||
var requestHandler = new DefaultLoRaDataRequestHandler(ServerConfiguration, FrameCounterUpdateStrategyProvider, ConcentratorDeduplication, new LoRaPayloadDecoder(NullLogger<LoRaPayloadDecoder>.Instance), deduplicationFactory, adrStrategyProvider, adrManagerFactory, functionBundlerProvider, NullLogger<DefaultLoRaDataRequestHandler>.Instance, meter: null);
|
||||
|
||||
LoRaDeviceFactory = new TestLoRaDeviceFactory(ServerConfiguration, LoRaDeviceClient.Object, ConnectionManager, DeviceCache, requestHandler);
|
||||
|
||||
// By default we pick EU868 region.
|
||||
Region = Enum.TryParse<LoRaRegionType>(Environment.GetEnvironmentVariable("REGION"), out var loraRegionType) ?
|
||||
(RegionManager.TryTranslateToRegion(loraRegionType, out var resolvedRegion) ? resolvedRegion : RegionManager.EU868) : RegionManager.EU868;
|
||||
}
|
||||
|
||||
public static MemoryCache NewMemoryCache() => new MemoryCache(new MemoryCacheOptions());
|
||||
|
@ -129,14 +136,19 @@ namespace LoRaWan.Tests.Common
|
|||
IPacketForwarder packetForwarder = null,
|
||||
TimeSpan? startTimeOffset = null,
|
||||
TimeSpan? constantElapsedTime = null,
|
||||
bool useRealTimer = false) =>
|
||||
WaitableLoRaRequest.Create(metadata,
|
||||
bool useRealTimer = false)
|
||||
{
|
||||
var request = WaitableLoRaRequest.Create(metadata,
|
||||
loRaPayload,
|
||||
packetForwarder ?? PacketForwarder,
|
||||
startTimeOffset,
|
||||
constantElapsedTime,
|
||||
useRealTimer);
|
||||
|
||||
request.SetRegion(Region);
|
||||
return request;
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!this.disposedValue)
|
||||
|
|
|
@ -985,6 +985,8 @@ namespace LoRaWan.Tests.Integration
|
|||
inTimeForAdditionalMessageCheck: false,
|
||||
inTimeForDownlinkDelivery: false,
|
||||
payload);
|
||||
request.SetRegion(this.Region);
|
||||
|
||||
messageProcessor.DispatchRequest(request);
|
||||
Assert.True(await request.WaitCompleteAsync());
|
||||
|
||||
|
|
|
@ -141,6 +141,7 @@ namespace LoRaWan.Tests.Unit.NetworkServer
|
|||
FrameCounterUpdateStrategyProvider);
|
||||
|
||||
using var request = CreateWaitableRequest(TestUtils.GenerateTestRadioMetadata(frequency: new Hertz(0)), payload, useRealTimer: true);
|
||||
request.SetRegion(null);
|
||||
messageProcessor.DispatchRequest(request);
|
||||
Assert.True(await request.WaitCompleteAsync());
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
"FFFFFFFFFFFFFFFF"
|
||||
]
|
||||
],
|
||||
"region": "CN470",
|
||||
"region": "CN470RP2",
|
||||
"hwspec": "sx1301/1",
|
||||
"freq_range": [
|
||||
470000000,
|
||||
|
|
Загрузка…
Ссылка в новой задаче