Esempio n. 1
0
        public LoraMessage CreateFromPayload(LoraAntennaPacket packet)
        {
            if (random.Next() % 2 == 0)
            {
                return(new LoraJoinMessage(packet.Payload));
            }

            return(new LoraTelemetryMessage(packet.Payload));
        }
Esempio n. 2
0
        private async Task OnLoraPacketReceived(LoraAntennaPacket packet)
        {
            this.logger.LogInformation("Message from antenna received");

            // 1. Find out the message type
            var loraMessage = this.messageFactory.CreateFromPayload(packet);

            // 2. Execute handler
            var response = await this.mediator.Send(loraMessage);

            // 3. Send response if needed
            if (response.Payload.Length > 0)
            {
                await this.loraAntenna.SendMessage(response.Payload);
            }
        }
Esempio n. 3
0
        public async Task Start()
        {
            const int  PORT     = 1000;
            IPEndPoint endPoint = new IPEndPoint(IPAddress.Any, PORT);

            udpClient = new UdpClient(endPoint);


            while (true)
            {
                UdpReceiveResult receivedResults = await udpClient.ReceiveAsync();

                var packet = new LoraAntennaPacket(receivedResults.Buffer);

                // do not wait for it to finish
                Task.Run(() => this.receiver(packet));
            }
        }
Esempio n. 4
0
        private async Task CreateFakePayloads()
        {
            while (true)
            {
                var payload = new LoraAntennaPacket(new byte[10]);

                Task.Run(() => this.receiver(payload));

                if (System.Diagnostics.Debugger.IsAttached)
                {
                    await Task.Delay(1000 * 15);
                }
                else
                {
                    await Task.Delay(1000 * 3);
                }
            }
        }