示例#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 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;
 }
示例#3
0
        static void HandleUserCall(object sender, CallEventArgs e)
        {
            RadioCall call    = e.Call;
            string    rssiStr = "";

            if (!double.IsNaN(call.RSSI))
            {
                rssiStr = " RSSI " + call.RSSI;
                DBRadio r = db.ReadRadio(call.From);
                if (r == null)
                {
                    r = new DBRadio(call.From.Int, call.RSSI);
                }
                else
                {
                    r.AddReading(call.RSSI);
                }
                db.UpdateRadio(r);
            }
            if (call.IsAudio)
            {
                Console.WriteLine("Audio Call : {0} => {1} " + rssiStr, call.From, call.To);
                AudioCall ac       = (AudioCall)call;
                string    filename = String.Format(@"E:\RadioCalls\{0} - {1} to {2}.mp3", call.Start.ToString("yyyy-MM-ddTHH-mm-ss"), call.From.Int, call.To.Int);
                try
                {
                    ac.SaveToMP3(filename);
                }
                catch (Exception)
                {
                    Console.WriteLine("Unable to decode audio!");
                }
                db.WriteVoiceCall(call.From, call.To, call.Start, call.End, call.RSSI, call.Slot, filename);
                srv.PublishVoiceCall(call);
            }
            else
            {
                DataCall dc = (DataCall)call;
                switch (dc.DataType)
                {
                case CallDataType.TMS:
                    if (dc.TextMessage.Type == MessageType.Ack)
                    {
                        Console.WriteLine("Text Message Ack : {0} => {1}" + rssiStr, call.From, call.To);
                    }
                    else if (dc.TextMessage != null)
                    {
                        Console.WriteLine("Text Message : {0} => {1} \"{2}\"" + rssiStr, call.From, call.To, dc.TextMessage.Message);
                    }
                    else
                    {
                        Console.WriteLine("Text Message : {0} => {1} unable to parse!" + rssiStr, call.From, call.To);
                    }
                    break;

                case CallDataType.LRRP:
                    LRRPPacket pkt = dc.LRRPPacket;
                    if (pkt.Type == LRRPPacketType.ImmediateLocationResponse || pkt.Type == LRRPPacketType.TriggeredLocationData)
                    {
                        Console.WriteLine("Got LRRP Packet from {0} {1} {2}", call.From, pkt, rssiStr);
                    }
                    else
                    {
                        Console.WriteLine("Got LRRP Control Message: {0} => {1}" + rssiStr, call.From, call.To);
                    }
                    break;

                case CallDataType.ICMP:
                    Console.WriteLine("Got ICMP Ping: {0} => {1}" + rssiStr, call.From, call.To);
                    break;

                case CallDataType.RadioCheck:
                    Console.WriteLine("Got Radio Check: {0} => {1}" + rssiStr, call.From, call.To);
                    break;

                case CallDataType.RadioCheckAck:
                    Console.WriteLine("Got Radio Check Ack: {0} => {1}" + rssiStr, call.From, call.To);
                    break;

                case CallDataType.UnknownSmall:
                case CallDataType.IPAck:
                    //Just ignore this
                    break;

                default:
                    Console.WriteLine("Data Call Type is {0}", dc.DataType);
                    Console.WriteLine("Got Unknown radio call: {0} => {1}" + rssiStr, call.From, call.To);
                    Console.WriteLine("    " + BitConverter.ToString(call.Data));
                    break;
                }
            }
        }
示例#4
0
 public LRRPPacketEventArgs(LRRPPacket p, IPEndPoint ep, DataCall call) : this(p, ep)
 {
     this.Call = call;
 }