Exemple #1
0
        //We prefer the packet recieved by the repeater because it has RSSI
        public bool DebouncePacket(LRRPPacket pkt, IPAddress ipAddress, DataCall call)
        {
            //Remove expired timers...
            this.recentlyRecieved = this.recentlyRecieved.Where(pair => pair.Value.Enabled == false).ToDictionary(pair => pair.Key, pair => pair.Value);
            LRRPPacketEventArgs myE = new LRRPPacketEventArgs(pkt, new IPEndPoint(ipAddress, 4001), call);

            foreach (KeyValuePair <LRRPPacketEventArgs, System.Timers.Timer> pair in this.recentlyRecieved)
            {
                Console.WriteLine("Does {0} == {1}", pair.Key.Endpoint.Address, ipAddress);
                if (pair.Key.Endpoint.Address.Equals(ipAddress))
                {
                    if (pair.Key.Packet.Type == pkt.Type && pair.Key.Packet.RequestID == pkt.RequestID)
                    {
                        pair.Value.Stop();
                        this.recentlyRecieved.Remove(pair.Key);
                        return(ReallySendEvent(myE));
                    }
                }
            }
            if (this.ReallySendEvent(myE))
            {
                this.recentlyHandled.Add(myE);
                return(true);
            }
            return(false);
        }
Exemple #2
0
        public bool Send(LRRPPacket packet, IPEndPoint ep)
        {
            byte[] tmp = packet.Encode();
            int    ret = client.Send(tmp, tmp.Length, ep);

            this.recentlySent?.Add(new LRRPPacketEventArgs(packet, ep));
            return(ret == tmp.Length);
        }
Exemple #3
0
 public LRRPPacketEventArgs(LRRPPacket p, IPEndPoint ep)
 {
     this.Packet   = p;
     this.Endpoint = ep;
     byte[] tmp = ep.Address.GetAddressBytes();
     this.CAI       = tmp[0];
     this.ID        = new RadioID(tmp, 1, 3);
     this.Timestamp = DateTime.Now;
 }
Exemple #4
0
 public bool RecentlySent(LRRPPacket pkt, IPAddress ipAddress)
 {
     //Remove any packets older than 5 seconds...
     this.recentlySent.RemoveAll(x => x.Timestamp.AddSeconds(5) < DateTime.Now);
     foreach (LRRPPacketEventArgs p in this.recentlySent)
     {
         if (p.Endpoint.Address.Equals(ipAddress))
         {
             if (p.Packet.Type == pkt.Type && p.Packet.RequestID == pkt.RequestID)
             {
                 this.recentlySent.Remove(p);
                 return(true);
             }
         }
     }
     return(false);
 }
Exemple #5
0
 public void ListenThread()
 {
     while (running)
     {
         this.recentlyHandled.RemoveAll(x => x.Timestamp.AddSeconds(5) < DateTime.Now);
         IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
         Byte[]     receiveBytes     = this.client.Receive(ref RemoteIpEndPoint);
         LRRPPacket p = LRRPPacket.Decode(receiveBytes);
         //Console.WriteLine("Got LRRP Packet {0}", p);
         LRRPPacketEventArgs e = new LRRPPacketEventArgs(p, RemoteIpEndPoint);
         foreach (LRRPPacketEventArgs x in this.recentlyHandled)
         {
             if (e.Endpoint.Address.Equals(x.Endpoint.Address))
             {
                 if (e.Packet.Type == x.Packet.Type && e.Packet.RequestID == x.Packet.RequestID)
                 {
                     //Drop this it was already handled from the repeater...
                     continue;
                 }
             }
         }
         if (this.deboune)
         {
             if (this.GotLocationData == null && this.GotLRRPControl == null)
             {
                 //No event handlers this is the easy case...
                 continue;
             }
             System.Timers.Timer t = new System.Timers.Timer(1000);
             t.Elapsed += new System.Timers.ElapsedEventHandler((sender, evt) => {
                 ReallySendEvent(e);
             });
             t.Start();
         }
         else
         {
             ReallySendEvent(e);
         }
     }
 }
Exemple #6
0
 public LRRPPacketEventArgs(LRRPPacket p, IPEndPoint ep, DataCall call) : this(p, ep)
 {
     this.Call = call;
 }