Ejemplo n.º 1
0
        public async Task Error_Callback_Should_Be_Executed_When_Serializer_Throws_An_Exception()
        {
            var serverErrorEvent = new AutoResetEvent(false);

            var server = new UdpBinding(new IPEndPoint(IPAddress.Any, 1701), new ExceptionSerializer());

            server.IoCompleted += (sender, e) => Debug.WriteLine(e.LastOperation);
            server.Error       += (sender, e) =>
            {
                serverErrorEvent.Set();
            };

            var result = server.ListenAsync();

            Assert.IsTrue(result);

            var client = new UdpBinding(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1701), new TestSerializer());

            client.IoCompleted += (sender, e) => Debug.WriteLine(e.LastOperation);

            await client.ConnectAsync();

            await client.SendAsync(new TestPacket());

            Assert.IsTrue(serverErrorEvent.WaitOne(TimeSpan.FromSeconds(3)));
        }
Ejemplo n.º 2
0
        public async Task Client_Should_Receive_Package_When_Server_Responds()
        {
            var serverReceivedEvent = new AutoResetEvent(false);
            var clientReceivedEvent = new AutoResetEvent(false);

            var server = new UdpBinding(new IPEndPoint(IPAddress.Any, 1700), new TestSerializer());

            server.IoCompleted    += (sender, e) => Debug.WriteLine(e.LastOperation);
            server.PacketReceived += async(sender, e) =>
            {
                serverReceivedEvent.Set();

                await e.Binding.SendAsync(e.Packet);
            };

            var result = server.ListenAsync();

            Assert.IsTrue(result);

            var client = new UdpBinding(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1700), new TestSerializer());

            client.IoCompleted    += (sender, e) => Debug.WriteLine(e.LastOperation);
            client.PacketReceived += (sender, e) => clientReceivedEvent.Set();

            await client.ConnectAsync();

            await client.SendAsync(new TestPacket());

            Assert.IsTrue(serverReceivedEvent.WaitOne(TimeSpan.FromSeconds(3)));

            Assert.IsTrue(clientReceivedEvent.WaitOne(TimeSpan.FromSeconds(3)));
        }
        public async Task Meter_Should_Respond_With_Ack_When_Sending_SND_NKE()
        {
            var resetEvent = new AutoResetEvent(false);

            var binding = new UdpBinding(new IPEndPoint(IPAddress.Parse(COLLECTOR_IP_ADDRESS), COLLECTOR_PORT), new MeterbusFrameSerializer());

            binding.PacketReceived += (sender, e) => resetEvent.Set();

            await binding.ConnectAsync();

            await binding.SendAsync(new ShortFrame((byte)ControlMask.SND_NKE, 0x0a));

            Assert.IsTrue(resetEvent.WaitOne(TimeSpan.FromSeconds(TIMEOUT_IN_SECONDS)));
        }
        public async Task Test1()
        {
            var packet = new PushDataPacket
            {
                ProtocolVersion = 1,
                Token           = 1,
                Eui             = "0000000000000001",
                Payload         = new PushDataPacketPayload
                {
                    Rxpk = new List <Rxpk>()
                    {
                        new RxpkV2
                        {
                            Time                = DateTime.UtcNow,
                            Timestamp           = GpsTime.Time,
                            RadioFrequencyChain = 1,
                            Frequency           = 868.500000,
                            CrcStatus           = CrcStatus.OK,
                            Modulation          = Modulation.LORA,
                            DataRate            = DatarateIdentifier.SF7BW125,
                            CodingRate          = CodeRate.CR_LORA_4_8,
                            Size                = 14,
                            Data                = "Wg3qoMwpJ5T372B9pxLIs0kbvUs=",
                            RadioSignals        = new List <Rsig>()
                            {
                                new Rsig
                                {
                                    Antenna                       = 0,
                                    Channel                       = 7,
                                    FineTimestamp                 = 50000,
                                    EncryptedTimestamp            = "asd",
                                    ReceivedSignalStrengthChannel = -75,
                                    LoraSignalToNoiseRatio        = 30,
                                }
                            }
                        },
                        new RxpkV2
                        {
                            Time                = DateTime.UtcNow,
                            Timestamp           = GpsTime.Time,
                            RadioFrequencyChain = 1,
                            Frequency           = 868.500000,
                            CrcStatus           = CrcStatus.OK,
                            Modulation          = Modulation.LORA,
                            DataRate            = DatarateIdentifier.SF7BW125,
                            CodingRate          = CodeRate.CR_LORA_4_8,
                            Size                = 14,
                            Data                = "Wg3qoMwpJ5T372B9pxLIs0kbvUs=",
                            RadioSignals        = new List <Rsig>()
                            {
                                new Rsig
                                {
                                    Antenna                       = 1,
                                    Channel                       = 7,
                                    FineTimestamp                 = 50000,
                                    EncryptedTimestamp            = "asd",
                                    ReceivedSignalStrengthChannel = -75,
                                    LoraSignalToNoiseRatio        = 30,
                                }
                            }
                        }
                    },
                    Stat = new StatV2
                    {
                        Lati = 46.24,
                        Long = 3.2523,
                        Alti = 100,
                        Time = DateTime.UtcNow,
                    },
                }
            };

            var resetEvent = new AutoResetEvent(false);

            var binding = new UdpBinding(new PicocellPacketSerializer());

            binding.PacketReceived += (sender, e) => resetEvent.Set();

            await binding.ConnectAsync(new IPEndPoint(IPAddress.Parse(COLLECTOR_IP_ADDRESS), COLLECTOR_PORT));

            await binding.SendAsync(packet);

            Assert.True(resetEvent.WaitOne(TimeSpan.FromSeconds(TIMEOUT_IN_SECONDS)));
        }