Exemple #1
0
        public Tuple <float, float, float?> GetCurrentLocation(string ipAddress)
        {
            ImmediateLocationRequestPacket lrp = new ImmediateLocationRequestPacket(1);
            IPEndPoint ep = new IPEndPoint(IPAddress.Parse(ipAddress), 4001);
            Tuple <float, float, float?> ret = new Tuple <float, float, float?>(0.0f, 0.0f, null);
            SemaphoreSlim     signal         = new SemaphoreSlim(0, 1);
            LRRPPacketHandler handler        = new LRRPPacketHandler((sender, e) => {
                if (e.Packet.Type == LRRPPacketType.ImmediateLocationResponse && e.Endpoint.Equals(ep))
                {
                    ImmediateLocationResponsePacket rp = (ImmediateLocationResponsePacket)e.Packet;
                    float?rssi = null;
                    if (e.Call != null && !double.IsNaN(e.Call.RSSI))
                    {
                        rssi = e.Call.RSSI;
                    }
                    ret = new Tuple <float, float, float?>(rp.Latitude, rp.Longitude, rssi);
                    signal.Release();
                }
            });

            this.GotLocationData += handler;
            this.Send(lrp, ep);
            if (signal.Wait(5000) == false)
            {
                this.GotLocationData -= handler;
                return(ret);
            }
            this.GotLocationData -= handler;
            return(ret);
        }
Exemple #2
0
        public int GetRemoteRadioLRRPVersion(string ipAddress)
        {
            LRRPPacket        verReq  = new VersionRequestPacket(1);
            IPEndPoint        ep      = new IPEndPoint(IPAddress.Parse(ipAddress), 4001);
            int               ver     = -1;
            SemaphoreSlim     signal  = new SemaphoreSlim(0, 1);
            LRRPPacketHandler handler = new LRRPPacketHandler((sender, e) => {
                if (e.Packet.Type == LRRPPacketType.ProtocolVersionResponse && e.Endpoint.Equals(ep))
                {
                    ver = ((VersionResponsePacket)e.Packet).Version;
                    signal.Release();
                }
            });

            this.GotLRRPControl += handler;
            this.Send(verReq, ep);
            if (signal.Wait(5000) == false)
            {
                this.GotLRRPControl -= handler;
                return(-1);
            }
            this.GotLRRPControl -= handler;
            return(ver);
        }