Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • monica/lora-gateway/lora
1 result
Show changes
Commits on Source (1)
...@@ -105,12 +105,17 @@ namespace Fraunhofer.Fit.Iot.Lora { ...@@ -105,12 +105,17 @@ namespace Fraunhofer.Fit.Iot.Lora {
} }
}); });
private void PanicUpdates(Object sender, PanicUpdateEvent e) => this.PanicUpdate?.Invoke(sender, e); private async void PanicUpdates(Object sender, PanicUpdateEvent e) => await Task.Run(() => {
this.PanicUpdate?.Invoke(sender, e);
private void StatusUpdates(Object sender, StatusUpdateEvent e) => this.StatusUpdate?.Invoke(sender, e); });
private void DataUpdates(Object sender, DataUpdateEvent e) => this.DataUpdate?.Invoke(sender, e); private async void StatusUpdates(Object sender, StatusUpdateEvent e) => await Task.Run(() => {
this.StatusUpdate?.Invoke(sender, e);
});
private async void DataUpdates(Object sender, DataUpdateEvent e) => await Task.Run(() => {
this.DataUpdate?.Invoke(sender, e);
});
#region IDisposable Support #region IDisposable Support
private Boolean disposedValue = false; private Boolean disposedValue = false;
...@@ -130,7 +135,7 @@ namespace Fraunhofer.Fit.Iot.Lora { ...@@ -130,7 +135,7 @@ namespace Fraunhofer.Fit.Iot.Lora {
} }
public void Dispose() { public void Dispose() {
Dispose(true); this.Dispose(true);
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
} }
#endregion #endregion
......
using System.Reflection; using System.Reflection;
using System.Resources;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// Allgemeine Informationen über eine Assembly werden über die folgenden // Allgemeine Informationen über eine Assembly werden über die folgenden
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, // Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
// die einer Assembly zugeordnet sind. // die einer Assembly zugeordnet sind.
[assembly: AssemblyTitle("Lora")] [assembly: AssemblyTitle("Lora")]
[assembly: AssemblyDescription("")] [assembly: AssemblyDescription("Library that connects to a radio device and recieves lora traffic")]
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")] [assembly: AssemblyCompany("Fraunhofer FIT")]
[assembly: AssemblyProduct("Lora")] [assembly: AssemblyProduct("Lora")]
[assembly: AssemblyCopyright("Copyright © 2018 - 22.04.2019")] [assembly: AssemblyCopyright("Copyright © 2018 - 31.05.2019")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("Fraunhofer FIT, BlubbFish")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("de-DE")]
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly // Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von // für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
...@@ -31,8 +33,8 @@ using System.Runtime.InteropServices; ...@@ -31,8 +33,8 @@ using System.Runtime.InteropServices;
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, // Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben: // indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.8.2")] [assembly: AssemblyVersion("1.8.3")]
[assembly: AssemblyFileVersion("1.8.2")] [assembly: AssemblyFileVersion("1.8.3")]
/* /*
* 1.1.0 Now awaiing Battery as Double and fix the sending twise issue * 1.1.0 Now awaiing Battery as Double and fix the sending twise issue
...@@ -48,4 +50,5 @@ using System.Runtime.InteropServices; ...@@ -48,4 +50,5 @@ using System.Runtime.InteropServices;
* 1.8.0 Add field that indicates when the last gps position was recieved, change all times to UTC * 1.8.0 Add field that indicates when the last gps position was recieved, change all times to UTC
* 1.8.1 Add Hostname to MQTT, so you can see from witch device the data is recieved * 1.8.1 Add Hostname to MQTT, so you can see from witch device the data is recieved
* 1.8.2 Bugfix, create also an event for sending normal loradata when update panic * 1.8.2 Bugfix, create also an event for sending normal loradata when update panic
* 1.8.3 Refactoring and make using threads on event occours
*/ */
...@@ -135,9 +135,7 @@ namespace Fraunhofer.Fit.Iot.Lora.lib ...@@ -135,9 +135,7 @@ namespace Fraunhofer.Fit.Iot.Lora.lib
} }
} }
public override Boolean StartRadio() { public override Boolean StartRadio() => true;
return true;
}
public override void ParseConfig() { public override void ParseConfig() {
if (!this.config.ContainsKey("frequency") || if (!this.config.ContainsKey("frequency") ||
...@@ -221,9 +219,7 @@ namespace Fraunhofer.Fit.Iot.Lora.lib ...@@ -221,9 +219,7 @@ namespace Fraunhofer.Fit.Iot.Lora.lib
return size; return size;
} }
public Byte Available() { public Byte Available() => (Byte)(this.ReadRegister(Registers.RX_NB_BYTES) - this._packetIndex);
return (Byte)(this.ReadRegister(Registers.RX_NB_BYTES) - this._packetIndex);
}
public Int16 Read() { public Int16 Read() {
if (this.Available() == 0) { if (this.Available() == 0) {
...@@ -258,31 +254,19 @@ namespace Fraunhofer.Fit.Iot.Lora.lib ...@@ -258,31 +254,19 @@ namespace Fraunhofer.Fit.Iot.Lora.lib
this.WriteRegister(Registers.PREAMBLE_LSB, (Byte)(length >> 0)); this.WriteRegister(Registers.PREAMBLE_LSB, (Byte)(length >> 0));
} }
public void SetSyncWord(Byte sw) { public void SetSyncWord(Byte sw) => this.WriteRegister(Registers.SYNC_WORD, sw);
this.WriteRegister(Registers.SYNC_WORD, sw);
}
public void EnableCrc() { public void EnableCrc() => this.WriteRegister(Registers.MODEM_CONFIG_2, (Byte)(this.ReadRegister(Registers.MODEM_CONFIG_2) | 0x04));
this.WriteRegister(Registers.MODEM_CONFIG_2, (Byte)(this.ReadRegister(Registers.MODEM_CONFIG_2) | 0x04));
}
public void DisableCrc() { public void DisableCrc() => this.WriteRegister(Registers.MODEM_CONFIG_2, (Byte)(this.ReadRegister(Registers.MODEM_CONFIG_2) & 0xfb));
this.WriteRegister(Registers.MODEM_CONFIG_2, (Byte)(this.ReadRegister(Registers.MODEM_CONFIG_2) & 0xfb));
}
#endregion #endregion
#region RadioSettings #region RadioSettings
public Byte Rssi() { public Byte Rssi() => (Byte)(this.ReadRegister(Registers.RSSI_VALUE) - (this._frequency < 868E6 ? 164 : 157));
return (Byte)(this.ReadRegister(Registers.RSSI_VALUE) - (this._frequency < 868E6 ? 164 : 157));
}
public Byte PacketRssi() { public Byte PacketRssi() => (Byte)(this.ReadRegister(Registers.PKT_RSSI_VALUE) - (this._frequency < 868E6 ? 164 : 157));
return (Byte)(this.ReadRegister(Registers.PKT_RSSI_VALUE) - (this._frequency < 868E6 ? 164 : 157));
}
public Double PacketSnr() { public Double PacketSnr() => ((SByte)this.ReadRegister(Registers.PKT_SNR_VALUE)) * 0.25;
return ((SByte)this.ReadRegister(Registers.PKT_SNR_VALUE)) * 0.25;
}
public Int64 PacketFrequencyError() { public Int64 PacketFrequencyError() {
Int32 freqError = 0; Int32 freqError = 0;
...@@ -307,10 +291,8 @@ namespace Fraunhofer.Fit.Iot.Lora.lib ...@@ -307,10 +291,8 @@ namespace Fraunhofer.Fit.Iot.Lora.lib
this.WriteRegister(Registers.FRF_LSB, (Byte)(frf >> 0)); this.WriteRegister(Registers.FRF_LSB, (Byte)(frf >> 0));
} }
public Byte GetSpreadingFactor() { public Byte GetSpreadingFactor() => (Byte)(this.ReadRegister(Registers.MODEM_CONFIG_2) >> 4);
return (Byte)(this.ReadRegister(Registers.MODEM_CONFIG_2) >> 4);
}
public void SetSpreadingFactor(Byte sf) { public void SetSpreadingFactor(Byte sf) {
if(sf < 6) { if(sf < 6) {
sf = 6; sf = 6;
...@@ -382,9 +364,7 @@ namespace Fraunhofer.Fit.Iot.Lora.lib ...@@ -382,9 +364,7 @@ namespace Fraunhofer.Fit.Iot.Lora.lib
this.WriteRegister(Registers.MODEM_CONFIG_1, (Byte)((this.ReadRegister(Registers.MODEM_CONFIG_1) & 0xF1) | (cr << 1))); this.WriteRegister(Registers.MODEM_CONFIG_1, (Byte)((this.ReadRegister(Registers.MODEM_CONFIG_1) & 0xF1) | (cr << 1)));
} }
public void SetPrePaRamp() { public void SetPrePaRamp() => this.WriteRegister(Registers.PRE_PA_RAMP, (Byte)((this.ReadRegister(Registers.PRE_PA_RAMP) & 0xF0) | 0x08));
this.WriteRegister(Registers.PRE_PA_RAMP, (Byte)((this.ReadRegister(Registers.PRE_PA_RAMP) & 0xF0) | 0x08));
}
public void EnableInvertIQ() { public void EnableInvertIQ() {
this.WriteRegister(Registers.INVERTIQ, 0x66); this.WriteRegister(Registers.INVERTIQ, 0x66);
...@@ -408,9 +388,7 @@ namespace Fraunhofer.Fit.Iot.Lora.lib ...@@ -408,9 +388,7 @@ namespace Fraunhofer.Fit.Iot.Lora.lib
#endregion #endregion
#region Debug #region Debug
public Byte Random() { public Byte Random() => this.ReadRegister(Registers.RSSI_WIDEBAND);
return this.ReadRegister(Registers.RSSI_WIDEBAND);
}
public String DumpRegisters() { public String DumpRegisters() {
String t = ""; String t = "";
...@@ -496,13 +474,9 @@ namespace Fraunhofer.Fit.Iot.Lora.lib ...@@ -496,13 +474,9 @@ namespace Fraunhofer.Fit.Iot.Lora.lib
#endregion #endregion
#region Powserusage #region Powserusage
public void Ilde() { public void Ilde() => this.WriteRegister(Registers.OP_MODE, (Byte)Modes.LONG_RANGE_MODE | (Byte)Modes.STDBY);
this.WriteRegister(Registers.OP_MODE, (Byte)Modes.LONG_RANGE_MODE | (Byte)Modes.STDBY);
}
public void Sleep() { public void Sleep() => this.WriteRegister(Registers.OP_MODE, (Byte)Modes.LONG_RANGE_MODE | (Byte)Modes.SLEEP);
this.WriteRegister(Registers.OP_MODE, (Byte)Modes.LONG_RANGE_MODE | (Byte)Modes.SLEEP);
}
public override void SetTxPower(Int32 level) { public override void SetTxPower(Int32 level) {
if (level > 17) { if (level > 17) {
...@@ -525,21 +499,13 @@ namespace Fraunhofer.Fit.Iot.Lora.lib ...@@ -525,21 +499,13 @@ namespace Fraunhofer.Fit.Iot.Lora.lib
#endregion #endregion
#region Communication #region Communication
private Byte ReadRegister(Byte address) { private Byte ReadRegister(Byte address) => this.SingleTransfer((Byte)(address & 0x7F), 0x00);
return this.SingleTransfer((Byte)(address & 0x7F), 0x00);
}
private Byte ReadRegister(Registers reg) { private Byte ReadRegister(Registers reg) => this.ReadRegister((Byte)reg);
return this.ReadRegister((Byte)reg);
}
private void WriteRegister(Byte address, Byte value) { private void WriteRegister(Byte address, Byte value) => this.SingleTransfer((Byte)(address | 0x80), value);
this.SingleTransfer((Byte)(address | 0x80), value);
}
private void WriteRegister(Registers reg, Byte value) { private void WriteRegister(Registers reg, Byte value) => this.WriteRegister((Byte)reg, value);
this.WriteRegister((Byte)reg, value);
}
private Byte SingleTransfer(Byte address, Byte value) { private Byte SingleTransfer(Byte address, Byte value) {
this.Selectreceiver(); this.Selectreceiver();
...@@ -564,13 +530,9 @@ namespace Fraunhofer.Fit.Iot.Lora.lib ...@@ -564,13 +530,9 @@ namespace Fraunhofer.Fit.Iot.Lora.lib
this.PinReset.PinMode = GpioPinDriveMode.Output; this.PinReset.PinMode = GpioPinDriveMode.Output;
} }
private void Selectreceiver() { private void Selectreceiver() => this.PinSlaveSelect.Write(false);
this.PinSlaveSelect.Write(false);
}
private void Unselectreceiver() { private void Unselectreceiver() => this.PinSlaveSelect.Write(true);
this.PinSlaveSelect.Write(true);
}
public override void AttachUpdateEvent() { public override void AttachUpdateEvent() {
if (this.HasAttachedUpdateEvent()) { if (this.HasAttachedUpdateEvent()) {
......
using System; /*
* Copyright (c) 2013, SEMTECH S.A.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Semtech corporation nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL SEMTECH S.A. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text;
using System.Threading; using System.Threading;
using BlubbFish.Utils; using BlubbFish.Utils;
using Fraunhofer.Fit.Iot.Lora.Events; using Fraunhofer.Fit.Iot.Lora.Events;
...@@ -493,9 +519,7 @@ namespace Fraunhofer.Fit.Iot.Lora.lib { ...@@ -493,9 +519,7 @@ namespace Fraunhofer.Fit.Iot.Lora.lib {
this.ReadonlyRegister = readonlyRegister; this.ReadonlyRegister = readonlyRegister;
this.DefaultValue = defaultValue; this.DefaultValue = defaultValue;
} }
public override String ToString() { public override String ToString() => "Reg: [P:" + this.RegisterPage + ",A:" + this.Address + ",O:" + this.BitOffset + "]";
return "Reg: [P:" + this.RegisterPage + ",A:"+ this.Address +",O:"+ this.BitOffset +"]";
}
}; };
public static class SX125X { public static class SX125X {
...@@ -2423,15 +2447,9 @@ namespace Fraunhofer.Fit.Iot.Lora.lib { ...@@ -2423,15 +2447,9 @@ namespace Fraunhofer.Fit.Iot.Lora.lib {
#endregion #endregion
#region Packets, Read, Write #region Packets, Read, Write
public override Boolean BeginPacket(Boolean implictHeader = false) { public override Boolean BeginPacket(Boolean implictHeader = false) => throw new NotImplementedException();
throw new NotImplementedException(); public override Boolean EndPacket(Boolean async = false) => throw new NotImplementedException();
} public override Byte Write(Byte[] buffer) => throw new NotImplementedException();
public override Boolean EndPacket(Boolean async = false) {
throw new NotImplementedException();
}
public override Byte Write(Byte[] buffer) {
throw new NotImplementedException();
}
public override void Receive(Byte size) { public override void Receive(Byte size) {
Byte[] recieveregister = this.RegisterReadArray(Registers.RX_PACKET_DATA_FIFO_NUM_STORED, 5); Byte[] recieveregister = this.RegisterReadArray(Registers.RX_PACKET_DATA_FIFO_NUM_STORED, 5);
...@@ -2708,9 +2726,7 @@ namespace Fraunhofer.Fit.Iot.Lora.lib { ...@@ -2708,9 +2726,7 @@ namespace Fraunhofer.Fit.Iot.Lora.lib {
} }
} }
public void SetDatarate(UInt32 dr) { public void SetDatarate(UInt32 dr) => this.fskDatarate = dr;
this.fskDatarate = dr;
}
public void SetSignalBandwith(Int64 sbw, RadioDataType @interface) { public void SetSignalBandwith(Int64 sbw, RadioDataType @interface) {
BW bw; BW bw;
...@@ -2736,19 +2752,13 @@ namespace Fraunhofer.Fit.Iot.Lora.lib { ...@@ -2736,19 +2752,13 @@ namespace Fraunhofer.Fit.Iot.Lora.lib {
} }
} }
public void EnableCrc() { public void EnableCrc() => this.CrcEnabled = true;
this.CrcEnabled = true;
}
public void DisableCrc() { public void DisableCrc() => this.CrcEnabled = false;
this.CrcEnabled = false;
}
#endregion #endregion
#region Powserusage #region Powserusage
public override void SetTxPower(Int32 level) { public override void SetTxPower(Int32 level) => throw new NotImplementedException();
throw new NotImplementedException();
}
#endregion #endregion
#region Register Communication #region Register Communication
...@@ -3188,13 +3198,9 @@ namespace Fraunhofer.Fit.Iot.Lora.lib { ...@@ -3188,13 +3198,9 @@ namespace Fraunhofer.Fit.Iot.Lora.lib {
this.PinReset.PinMode = GpioPinDriveMode.Output; this.PinReset.PinMode = GpioPinDriveMode.Output;
} }
private void Selectreceiver() { private void Selectreceiver() => this.PinSlaveSelect.Write(false);
this.PinSlaveSelect.Write(false);
}
private void Unselectreceiver() { private void Unselectreceiver() => this.PinSlaveSelect.Write(true);
this.PinSlaveSelect.Write(true);
}
private Byte SingleSPI(Byte address, Byte value = 0) { private Byte SingleSPI(Byte address, Byte value = 0) {
this.Selectreceiver(); this.Selectreceiver();
......
...@@ -10,9 +10,7 @@ namespace Fraunhofer.Fit.Iot.Lora.lib { ...@@ -10,9 +10,7 @@ namespace Fraunhofer.Fit.Iot.Lora.lib {
public delegate void DataUpdate(Object sender, LoraClientEvent e); public delegate void DataUpdate(Object sender, LoraClientEvent e);
public event DataUpdate Update; public event DataUpdate Update;
protected LoraConnector(Dictionary<String, String> settings) { protected LoraConnector(Dictionary<String, String> settings) => this.config = settings;
this.config = settings;
}
public static LoraConnector GetInstance(Dictionary<String, String> settings) { public static LoraConnector GetInstance(Dictionary<String, String> settings) {
if (settings.Count == 0) { if (settings.Count == 0) {
...@@ -32,9 +30,7 @@ namespace Fraunhofer.Fit.Iot.Lora.lib { ...@@ -32,9 +30,7 @@ namespace Fraunhofer.Fit.Iot.Lora.lib {
return (LoraConnector)t.GetConstructor(new Type[] { typeof(Dictionary<String, String>) }).Invoke(new Object[] { settings }); return (LoraConnector)t.GetConstructor(new Type[] { typeof(Dictionary<String, String>) }).Invoke(new Object[] { settings });
} }
protected void RaiseUpdateEvent(LoraClientEvent data) { protected void RaiseUpdateEvent(LoraClientEvent data) => this.Update?.Invoke(this, data);
this.Update?.Invoke(this, data);
}
protected Boolean HasAttachedUpdateEvent() { protected Boolean HasAttachedUpdateEvent() {
if(this.Update != null) { if(this.Update != null) {
......