示例#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
        public bool SendText(string message, string ipAddress, bool confirmReciept)
        {
            TMSMessage msg = new TMSMessage(message, confirmReciept);
            IPEndPoint ep  = new IPEndPoint(IPAddress.Parse(ipAddress), 4007);

            if (confirmReciept == false)
            {
                return(this.Send(msg, ep));
            }
            SemaphoreSlim     signal  = new SemaphoreSlim(0, 1);
            TMSMessageHandler handler = new TMSMessageHandler((sender, e) => {
                if (e.Packet.Type == MessageType.Ack && e.Endpoint.Equals(ep))
                {
                    signal.Release();
                }
            });

            this.GotAck += handler;
            this.Send(msg, ep);
            if (signal.Wait(5000) == false)
            {
                this.GotAck -= handler;
                return(false);
            }
            this.GotAck -= handler;
            return(true);
        }
示例#3
0
        public bool Send(TMSMessage msg, IPEndPoint ep)
        {
            byte[] tmp = msg.Encode();
            int    ret = client.Send(tmp, tmp.Length, ep);

            this.recentlySent?.Add(new TMSMessageEventArgs(msg, ep));
            return(ret == tmp.Length);
        }
示例#4
0
 public TMSMessageEventArgs(TMSMessage p, IPEndPoint ep, DataCall call)
 {
     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;
     this.Call      = call;
 }
示例#5
0
 public bool RecentlySent(TMSMessage pkt, IPAddress ipAddress)
 {
     //Remove any packets older than 5 seconds...
     this.recentlySent.RemoveAll(x => x.Timestamp.AddSeconds(5) < DateTime.Now);
     foreach (TMSMessageEventArgs p in this.recentlySent)
     {
         if (p.Endpoint.Address.Equals(ipAddress))
         {
             if (p.Packet.Type == pkt.Type && p.Packet.SequenceNumber == pkt.SequenceNumber)
             {
                 this.recentlySent.Remove(p);
                 return(true);
             }
         }
     }
     return(false);
 }
示例#6
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);
         }
     }
 }
示例#7
0
 public TMSMessageEventArgs(TMSMessage p, IPEndPoint ep) : this(p, ep, null)
 {
 }