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); } }
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); } }
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); }
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); }
private void HandleUserCall(object sender, CallEventArgs e) { if (!e.Call.IsAudio) { DataCall dc = (DataCall)e.Call; switch (dc.DataType) { case CallDataType.LRRP: if (this.lrrp != null) { if (lrrp.RecentlySent(dc.LRRPPacket, this.GetIPForRadio(e.Call.To))) { //Drop this... return; } else if (lrrp.DebouncePacket(dc.LRRPPacket, this.GetIPForRadio(e.Call.From), dc)) { //Sent through LRRP processing, drop it... return; } } break; case CallDataType.TMS: if (this.tms != null) { if (tms.RecentlySent(dc.TextMessage, this.GetIPForRadio(e.Call.To))) { //Drop this... return; } else if (tms.DebouncePacket(dc.TextMessage, this.GetIPForRadio(e.Call.From), dc)) { //Sent through TMS processing, drop it... return; } } break; } } this.InternalCallHandler?.Invoke(sender, e); if (!e.Handled) { this.GotRadioCall?.Invoke(sender, e); } }