Example #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);
            }
        }
Example #2
0
        private async Task InitGpsManager()
        {
            try
            {
                // Create the GPS manager
                _gpsManager = await GpsManagerFactory.Create(GpsManagerSettings.Default).ConfigureAwait(false);

                // Hook up the events
                _gpsManager.OnStandardMessage += GpsManagerStandardMessage;
                _gpsManager.OnCustomMessage   += GpsManagerCustomMessage;
                _gpsManager.OnPositionData    += GpsManagerPositionDataAsync;
                _gpsManager.OnMovementData    += GpsManagerMovementData;

                // Wake up!
                await _gpsManager.WakeUp().ConfigureAwait(false);
            }
            catch (Exception exception)
            {
                WriteLog("The demo crashed:\r\n" + exception.Message);
                Debugger.Break();
            }
        }