Exemplo n.º 1
0
        private void RestClient_GotUserPacket(object sender, PacketEventArgs e)
        {
            if (e.packet.ID.Equals(this.myID))
            {
                //Ignore my own packets...
                return;
            }
            UserPacket upkt = (UserPacket)e.packet;
            RadioID    to   = upkt.Destination;

            if (activeCalls.ContainsKey(to))
            {
                //Console.WriteLine("Appending to active call...");
                activeCalls[to].AppendPkt(upkt);
            }
            else
            {
                //Console.WriteLine("Creating new call...");
                if (upkt.PacketType == PacketType.GroupDataCall || upkt.PacketType == PacketType.PrivateDataCall)
                {
                    activeCalls[to] = new DataCall(upkt);
                }
                else
                {
                    activeCalls[to] = new AudioCall(upkt);
                }
            }
            if (activeCalls[to].IsEnded)
            {
                this.GotRestCall?.Invoke(this, new CallEventArgs(activeCalls[to]));
                activeCalls.Remove(to);
            }
        }
Exemplo n.º 2
0
        protected void FireUserPacket(Packet pkt, System.Net.IPEndPoint ep)
        {
            if (this.GotUserPacket != null)
            {
                PacketEventArgs e = new PacketEventArgs(pkt, ep);
                this.GotUserPacket(this, e);
            }
            UserPacket upkt = (UserPacket)pkt;
            RadioID    to   = upkt.Destination;

            if (activeCalls.ContainsKey(to))
            {
                //Console.WriteLine("Appending to active call...");
                activeCalls[to].AppendPkt(upkt);
            }
            else
            {
                //Console.WriteLine("Creating new call...");
                if (upkt.PacketType == PacketType.GroupDataCall || upkt.PacketType == PacketType.PrivateDataCall)
                {
                    activeCalls[to] = new DataCall(upkt);
                }
                else
                {
                    activeCalls[to] = new AudioCall(upkt);
                }
            }
            if (activeCalls[to].IsEnded)
            {
                this.GotUserCall?.Invoke(this, new CallEventArgs(activeCalls[to]));
                activeCalls.Remove(to);
            }
        }
Exemplo n.º 3
0
        public bool RadioCheck(RadioID toCheck, ref float rssi)
        {
            CSBKBurst     burst   = new RadioCheck(this.ID, toCheck);
            RadioCall     call    = DataCall.CSBKRadioCall(6, false, this.ID, toCheck, burst);
            float         myRSSI  = 0.0F;
            SemaphoreSlim signal  = new SemaphoreSlim(0, 1);
            CallHander    handler = new CallHander((sender, e) => {
                if (e.Call.IsAudio)
                {
                    return;
                }
                DataCall intcall = (DataCall)e.Call;
                if (intcall.From.Equals(toCheck) && intcall.To.Equals(this.myID) && intcall.DataType == CallDataType.RadioCheckAck)
                {
                    myRSSI    = intcall.RSSI;
                    e.Handled = true;
                    signal.Release();
                }
            });

            this.InternalCallHandler += handler;
            this.SendCall(call);
            if (signal.Wait(5000) == false)
            {
                this.InternalCallHandler -= handler;
                return(false);
            }
            this.InternalCallHandler -= handler;
            rssi = myRSSI;
            return(true);
        }
Exemplo n.º 4
0
 public DataCall(bool group, bool encrypted, RadioID from, RadioID to) : this()
 {
     this.isGroupCall = group;
     this.isEncrypted = encrypted;
     this.from        = from;
     this.to          = to;
     this.groupTag    = (UInt32) new Random().Next(0);
 }
Exemplo n.º 5
0
        public override bool Equals(object obj)
        {
            if ((obj == null) || !this.GetType().Equals(obj.GetType()))
            {
                return(false);
            }
            RadioID r = (RadioID)obj;

            return(this.id == r.id);
        }
Exemplo n.º 6
0
 public RadioSystem(uint radioid, RadioSystemType type, UInt16 port)
 {
     this.peers       = new List <Radio>();
     this.activeCalls = new Dictionary <RadioID, RadioCall>();
     this.myID        = new RadioID(radioid);
     this.type        = type;
     this.client      = new UDPClient(port);
     this.client.GotPeerRegisterRequest  += new PacketHandler(this.HandlePeerRegisterRequest);
     this.client.GetPeerKeepAliveRequest += new PacketHandler(this.HandlePeerKeepAliveRequest);
     this.client.GotPeerListReply        += new PacketHandler(this.NullHandler);
     this.client.GotUserPacket           += RestClient_GotUserPacket;
 }
Exemplo n.º 7
0
        public static DataCall CSBKRadioCall(int numberOfPreambles, bool group, RadioID from, RadioID to, CSBKBurst burst)
        {
            DataCall call = new DataCall(group, false, from, to);

            for (int i = 0; i < numberOfPreambles; i++)
            {
                Preamble pre = new Preamble((byte)(numberOfPreambles - i), to, from);
                call.bursts.Add(pre);
            }
            call.bursts.Add(burst);
            return(call);
        }
Exemplo n.º 8
0
        public IPAddress GetIPForRadio(RadioID id)
        {
            Radio r = FindRadioByID(id);

            if (r != null && r is IPRadio)
            {
                IPRadio ir = (IPRadio)r;
                return(ir.Endpoint.Address);
            }
            byte[] tmp = new byte[4];
            id.AddToArray(tmp, 0, 4);
            tmp[0] = 12;
            return(new IPAddress(tmp));
        }
Exemplo n.º 9
0
 protected RadioCall(UserPacket upkt)
 {
     this.startTime = DateTime.Now;
     this.bursts    = new List <Burst>()
     {
         upkt.Burst
     };
     this.isGroupCall = (upkt.PacketType == PacketType.GroupDataCall || upkt.PacketType == PacketType.GroupVoiceCall);
     this.isAudio     = (upkt.PacketType == PacketType.PrivateVoiceCall || upkt.PacketType == PacketType.GroupVoiceCall);
     this.from        = upkt.Source;
     this.to          = upkt.Destination;
     this.isEncrypted = upkt.Encrypted;
     this.isEnded     = upkt.End;
     this.isPhoneCall = upkt.PhoneCall;
     this.groupTag    = upkt.GroupTag;
 }
Exemplo n.º 10
0
 public UserPacket[] ToPackets(RadioID initiator)
 {
     UserPacket[] ret = new UserPacket[this.bursts.Count];
     for (int i = 0; i < ret.Length; i++)
     {
         if (i > 0)
         {
             //Make sure we get different timestamps...
             Thread.Sleep(1);
         }
         UserPacket pkt = new UserPacket(initiator, !this.isAudio, this.isGroupCall, this.from, this.to, this.isEncrypted, this.isPhoneCall, this.groupTag, this.bursts[i]);
         ret[i] = pkt;
     }
     ret[ret.Length - 1].End = true;
     return(ret);
 }
Exemplo n.º 11
0
 public Radio FindRadioByID(RadioID id)
 {
     if (this.master != null && this.master.ID == id)
     {
         return(master);
     }
     foreach (Radio r in this.peers)
     {
         if (r.ID != null && r.ID.Equals(id))
         {
             return(r);
         }
     }
     //TODO handle remote radios
     return(null);
 }