示例#1
0
        //We prefer the packet recieved by the repeater because it has RSSI
        public bool DebouncePacket(TMSMessage 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);
            TMSMessageEventArgs myE = new TMSMessageEventArgs(pkt, new IPEndPoint(ipAddress, 4001), call);

            foreach (KeyValuePair <TMSMessageEventArgs, 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.SequenceNumber == pkt.SequenceNumber)
                    {
                        pair.Value.Stop();
                        this.recentlyRecieved.Remove(pair.Key);
                        return(ReallySendEvent(myE));
                    }
                }
            }
            if (this.ReallySendEvent(myE))
            {
                this.recentlyHandled.Add(myE);
                return(true);
            }
            return(false);
        }
示例#2
0
        private bool ReallySendEvent(TMSMessageEventArgs e)
        {
            switch (e.Packet.Type)
            {
            case MessageType.SimpleText:
                if (this.GotText != null)
                {
                    this.GotText.Invoke(this, e);
                    return(true);
                }
                return(false);

            case MessageType.Ack:
                if (this.GotAck != null)
                {
                    this.GotAck.Invoke(this, e);
                    return(true);
                }
                return(false);

            default:
                Console.WriteLine("Got an unknown TMS packet {0}", e.Packet);
                return(false);
            }
        }
示例#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);
         TMSMessage          m = new TMSMessage(receiveBytes);
         TMSMessageEventArgs e = new TMSMessageEventArgs(m, RemoteIpEndPoint);
         foreach (TMSMessageEventArgs x in this.recentlyHandled)
         {
             if (e.Endpoint.Address.Equals(x.Endpoint.Address))
             {
                 if (e.Packet.Type == x.Packet.Type && e.Packet.SequenceNumber == x.Packet.SequenceNumber)
                 {
                     //Drop this it was already handled from the repeater...
                     continue;
                 }
             }
         }
         if (this.deboune)
         {
             if (this.GotText == null && this.GotAck == 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);
         }
     }
 }