Esempio n. 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);
        }
Esempio n. 2
0
        private bool ReallySendEvent(LRRPPacketEventArgs e)
        {
            switch (e.Packet.Type)
            {
            case LRRPPacketType.ImmediateLocationResponse:
            case LRRPPacketType.TriggeredLocationData:
                if (this.GotLocationData != null)
                {
                    this.GotLocationData.Invoke(this, e);
                    return(true);
                }
                return(false);

            case LRRPPacketType.ProtocolVersionResponse:
            case LRRPPacketType.TriggeredLocationStartResponse:
            case LRRPPacketType.TriggeredLocationStopResponse:
                if (this.GotLRRPControl != null)
                {
                    this.GotLRRPControl.Invoke(this, e);
                    return(true);
                }
                return(false);

            default:
                Console.WriteLine("Got an unknown LRRP packet {0}", e.Packet);
                return(false);
            }
        }
Esempio n. 3
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);
         }
     }
 }