Beispiel #1
0
        private async Task <ILoraWanGateway> CreateGateway()
        {
            try
            {
                // Create the transceiver:
                TransceiverPinSettings pinSettings = GetTransceiverPinSettings();
                ITransceiver           transceiver = await TransceiverFactory.Create(_gatewaySettings, pinSettings).ConfigureAwait(false);

                transceiver.OnMessageReceived += TransceiverOnMessageReceived;


                // Create the GPS manager (if existing):
                IPositionProvider positionProvider;
                if (UseGpsManager())
                {
                    // Create the GPS manager:
                    IGpsManager gpsManager = await GpsManagerFactory.Create(GpsManagerSettings.Default).ConfigureAwait(false);

                    // Hook up the event fired when a new position is recorded:
                    gpsManager.OnPositionData += GpsManagerPositionDataAsync;

                    // Start the GPS:
                    await gpsManager.WakeUp().ConfigureAwait(false);

                    // Make the Gateway use the GpsManager as position provider
                    // (sending the actual coordinates in its status messages):
                    positionProvider = gpsManager;
                }
                else
                {
                    // Make the Gateway use "no position" as its coordinate:
                    positionProvider = FixedPositionProvider.NoPositionProvider;

                    // ...or give it a fixed coordinate:
                    //positionProvider = new FixedPositionProvider(new SimplePosition(55.597382, 12.95889, 18.4));
                }


                // Get the gateway EUI:
                GatewayEui gatewayEui = await GetGatewayEui().ConfigureAwait(false);

                WriteLog("The gateway EUI: " + gatewayEui);


                // Create the LoRa WAN gateway handler:
                return(LoraWanGatewayFactory.Create(
                           transceiver,
                           _gatewaySettings,
                           gatewayEui,
                           positionProvider));
            }
            catch (Exception exception)
            {
                WriteLog("Failed creating the LoRaWAN gateway:\r\n" + exception.Message);
                Debugger.Break();
                return(null);
            }
        }
        private async Task <bool> InitLoraTransceiver()
        {
            try
            {
                _transceiver = await TransceiverFactory.Create(GetRadioSettings(), GetPinSettings()).ConfigureAwait(false);

                _transceiver.OnMessageReceived += TransceiverOnMessageReceived;

                return(true);
            }
            catch (Exception exception)
            {
                WriteLog("Failed initiating the LoRa transceiver:\r\n" + exception.Message);
                return(false);
            }
        }