protected override CommNode UpdateShortestWhere(CommNode a, CommNode b, CommLink link, double bestCost, CommNode startNode, Func <CommNode, CommNode, bool> whereClause)
        {
            CommNode value;

            for (int i = 0; i < Sequence_UpdateShortestWhere.Early.Count; i++)
            {
                try { Sequence_UpdateShortestWhere.Early[i].Invoke(a, b, link, bestCost, startNode, whereClause); }
                catch (Exception ex) { Debug.LogError(ex); }
            }

            for (int i = 0; i < Sequence_UpdateShortestWhere.Late.Count; i++)
            {
                try { Sequence_UpdateShortestWhere.Late[i].Invoke(a, b, link, bestCost, startNode, whereClause); }
                catch (Exception ex) { Debug.LogError(ex); }
            }

            value = base.UpdateShortestWhere(a, b, link, bestCost, startNode, whereClause);

            for (int i = 0; i < Sequence_UpdateShortestWhere.Post.Count; i++)
            {
                try { Sequence_UpdateShortestWhere.Post[i].Invoke(a, b, link, bestCost, startNode, whereClause); }
                catch (Exception ex) { Debug.LogError(ex); }
            }

            return(value);
        }
Example #2
0
        public static string DumpLink(CommLink link)
        {
            return($"A/B/Both CanRelay: {link.aCanRelay}/{link.bCanRelay}/{link.bothRelay}\n" +
                   $"StrengthAR/BR/RR: {link.strengthAR}/{link.strengthBR}/{link.strengthRR}\n" +
                   $"Best signal: {link.GetBestSignal()}" +
                   $"Cost: {link.cost}\n" +
                   $"Start: {link.start}\n" +
                   $"End: {link.end}\n" +
                   $"GetSignalStrength(start) / (end) / (no relays) / (both relays): {link.GetSignalStrength(link.start)}/{link.GetSignalStrength(link.end)}/{link.GetSignalStrength(false, false)}/{link.GetSignalStrength(true, true)}\n" +
                   $"signalStrength: {link.signalStrength}");

            /* Some sample results:
             * [LOG 13:25:45.815] [RealAntennasCommNetwork] [Trace] Link: Kerbin: Mesa South -to- RA-1-CS16 : 150727254.72 (Green)
             * [LOG 13:25:45.815] [RealAntennasCommNetwork] [Trace] A/B/Both CanRelay: True/False/False
             * StrengthAR/BR/RR: 0.609718471365098/0/0
             * Best signal: 0.609718471365098  Cost: 150727254.721891
             * Start: Node: Kerbin: Mesa South Links=3 : Home  Control  MultiHop : RealAntennas Gain:40dBi TxP:60dBm BW:10000KHz Draw:60dBm Coding:12dB
             * End: Node: RA-1-CS16 Links=6 :   : RealAntennas Gain:6dBi TxP:30dBm BW:10000KHz Draw:33dBm Coding:1dB
             * GetSignalStrength(start): 0
             * GetSignalStrength(end): 0.609718471365098
             * GetSignalStrength(no relays): 0
             *
             * Note the different Strength fields based on A/B/Both Relay state.  So... there can be a notion of direction?
             */
        }
Example #3
0
 private void keepAliveTimer_Callback(object state)
 {
     if (IsConnected)
     {
         CommLink.KeepAlive();
     }
 }
    public void StartStreamADC()
    {
        GSPacket StreamRequestPacket = new GSPacket(GSPTypes.Stream);

        CommLink.SendViaGSWatchLink(StreamRequestPacket);

        for (int i = 0; i < 128; i++)
        {
            ADCSamples[i] = (uint)i / 10;               //steps for demonstration
        }

        muki += 100;
    }
Example #5
0
        /// <summary>
        /// <para>Lists files in the NXT brick according to the file mask.</para>
        /// </summary>
        /// <param name="fileMask">A fileMask</param>
        /// <returns>A list of file names</returns>
        private string[] FindFiles(string fileMask)
        {
            List <string> fileArr = new List <string>();

            NxtFindFileReply?reply = CommLink.FindFirst(fileMask);

            while (reply.HasValue && reply.Value.fileFound)
            {
                fileArr.Add(reply.Value.fileName);
                reply = CommLink.FindNext(reply.Value.handle);
            }

            return(fileArr.ToArray());
        }
 internal void logDump(CommLink link)
 {
     Debug.Log("CommNetManager: ++ CommLink dump ++");
     Debug.Log("id: " + link.pathingID);
     Debug.Log("a.name: " + link.a.name);
     Debug.Log("b.name: " + link.b.name);
     Debug.Log("cost: " + link.cost);
     Debug.Log("hopType: " + link.hopType);
     Debug.Log("signal: " + link.signal);
     Debug.Log("signalStrength: " + link.signalStrength);
     Debug.Log("aCanRelay: " + link.aCanRelay);
     Debug.Log("bCanRelay: " + link.bCanRelay);
     Debug.Log("bothRelay: " + link.bothRelay);
     Debug.Log("Sum: " + link.ToString());
     Debug.Log("++++++++++++++++++ End dump +++++++");
 }
        protected override void UpdateShortestPath(CommNode a, CommNode b, CommLink link, double bestCost, CommNode startNode, CommNode endNode)
        {
            for (int i = 0; i < Sequence_UpdateShortestPath.Early.Count; i++)
            {
                try { Sequence_UpdateShortestPath.Early[i].Invoke(a, b, link, bestCost, startNode, endNode); }
                catch (Exception ex) { Debug.LogError(ex); }
            }

            for (int i = 0; i < Sequence_UpdateShortestPath.Late.Count; i++)
            {
                try { Sequence_UpdateShortestPath.Late[i].Invoke(a, b, link, bestCost, startNode, endNode); }
                catch (Exception ex) { Debug.LogError(ex); }
            }

            base.UpdateShortestPath(a, b, link, bestCost, startNode, endNode);

            for (int i = 0; i < Sequence_UpdateShortestPath.Post.Count; i++)
            {
                try { Sequence_UpdateShortestPath.Post[i].Invoke(a, b, link, bestCost, startNode, endNode); }
                catch (Exception ex) { Debug.LogError(ex); }
            }
        }
Example #8
0
 /// <summary>
 /// <para>Plays a tone.</para>
 /// </summary>
 /// <param name="frequency">Frequency for the tone, Hz</param>
 /// <param name="duration">Duration of the tone, ms</param>
 public void PlayTone(UInt16 frequency, UInt16 duration)
 {
     CommLink.PlayTone(frequency, duration);
 }
Example #9
0
 /// <summary>
 /// <para>Stops all playing sound; sound files and tones.</para>
 /// </summary>
 public void StopSound()
 {
     CommLink.StopSoundPlayback();
 }
 CommNode IPublicCommNet.UpdateShortestWhere(CommNode a, CommNode b, CommLink link, double bestCost, CommNode startNode, Func <CommNode, CommNode, bool> whereClause)
 {
     return(this.UpdateShortestWhere(a, b, link, bestCost, startNode, whereClause));
 }
Example #11
0
        IEnumerator<ITask> ExceptionHandler(Exception exception)
        {
            Tracer.Trace("SickLRF::ExceptionHandler() exception=" + exception);

            LogError(exception);

            BadPacketException bpe = exception as BadPacketException;

            if (bpe != null && bpe.Count < 2)
            {
                yield break;
            }

            _subMgrPort.Post(new submgr.Submit(new ResetType(), DsspActions.SubmitRequest));

            LogInfo("Closing link to LRF");
            yield return
                Arbiter.Choice(
                    _link.Close(),
                    delegate(SuccessResult success)
                    {
                    },
                    delegate(Exception except)
                    {
                        LogError(except);
                    }
                );

            _state.LinkState = "LRF Link closed, waiting 5 seconds";
            LogInfo(_state.LinkState);
            _link = null;

            SpawnIterator(5000, _state.ComPort, StartLRF);

            yield break;
        }
Example #12
0
        /// <summary>
        /// Overrode UpdateDisplay() fully and add own customisations
        /// </summary>
        private void updateCustomisedView()
        {
            if (FlightGlobals.ActiveVessel == null)
            {
                this.useTSBehavior = true;
            }
            else
            {
                this.useTSBehavior = false;
                this.vessel        = FlightGlobals.ActiveVessel;
            }

            if (this.vessel == null || this.vessel.connection == null || this.vessel.connection.Comm.Net == null) //revert to default display mode if saved mode is inconsistent in current situation
            {
                this.useTSBehavior = true;
                if (CustomModeTrackingStation != CustomDisplayMode.None)
                {
                    if (CustomModeTrackingStation != CustomDisplayMode.Network && CustomModeTrackingStation != CustomDisplayMode.MultiPaths)
                    {
                        CustomModeTrackingStation = CustomDisplayMode.Network;
                        ScreenMessages.PostScreenMessage(Localizer.Format("#autoLOC_118264", new string[]
                        {
                            Localizer.Format(CustomModeTrackingStation.displayDescription())
                        }), 5f);
                    }
                }
            }

            if (this.useTSBehavior)
            {
                CNVCommNetUI.CustomMode = CNVCommNetUI.CustomModeTrackingStation;
            }
            else
            {
                CNVCommNetUI.CustomMode = CNVCommNetUI.CustomModeFlightMap;
            }

            CommNetwork   net      = CommNetNetwork.Instance.CommNet;
            CommNetVessel cnvessel = null;
            CommNode      node     = null;
            CommPath      path     = null;

            if (this.vessel != null && this.vessel.connection != null && this.vessel.connection.Comm.Net != null)
            {
                cnvessel = this.vessel.connection;
                node     = cnvessel.Comm;
                path     = cnvessel.ControlPath;
            }

            //work out which links to display
            int count    = this.points.Count;//save previous value
            int numLinks = 0;

            switch (CNVCommNetUI.CustomMode)
            {
            case CNVCommNetUI.CustomDisplayMode.None:
                numLinks = 0;
                break;

            case CNVCommNetUI.CustomDisplayMode.FirstHop:
            case CNVCommNetUI.CustomDisplayMode.Path:
                if (cnvessel.ControlState == VesselControlState.Probe || cnvessel.ControlState == VesselControlState.Kerbal ||
                    path.Count == 0)
                {
                    numLinks = 0;
                }
                else
                {
                    if (CNVCommNetUI.CustomMode == CNVCommNetUI.CustomDisplayMode.FirstHop)
                    {
                        path.First.GetPoints(this.points);
                        numLinks = 1;
                    }
                    else
                    {
                        path.GetPoints(this.points, true);
                        numLinks = path.Count;
                    }
                }
                break;

            case CNVCommNetUI.CustomDisplayMode.VesselLinks:
                numLinks = node.Count;
                node.GetLinkPoints(this.points);
                break;

            case CNVCommNetUI.CustomDisplayMode.Network:
                if (net.Links.Count == 0)
                {
                    numLinks = 0;
                }
                else
                {
                    numLinks = net.Links.Count;
                    net.GetLinkPoints(this.points);
                }
                break;

            case CNVCommNetUI.CustomDisplayMode.MultiPaths:
                if (net.Links.Count == 0)
                {
                    numLinks = 0;
                }
                else
                {
                    CommPath newPath = new CommPath();

                    var nodes   = net;
                    var vessels = FlightGlobals.fetch.vessels;
                    for (int i = 0; i < vessels.Count; i++)
                    {
                        var commnetvessel = vessels[i].connection;
                        if (commnetvessel == null)    // like flag
                        {
                            continue;
                        }

                        SetPrivatePropertyValue <CommNetVessel>(commnetvessel, "unloadedDoOnce", true);   //network update is done only once for unloaded vessels so need to manually re-trigger every time
                        //don't want to override CommNetVessel to just set the boolean flag

                        if (!(commnetvessel.ControlState == VesselControlState.Probe || commnetvessel.ControlState == VesselControlState.Kerbal ||
                              commnetvessel.ControlPath == null || commnetvessel.ControlPath.Count == 0))
                        {
                            for (int pathIndex = 0; pathIndex < commnetvessel.ControlPath.Count; pathIndex++)
                            {
                                var link = commnetvessel.ControlPath[pathIndex];
                                if (newPath.Find(x => x.a.precisePosition == link.a.precisePosition && x.b.precisePosition == link.b.precisePosition) == null) //not found in list of links to be displayed
                                {
                                    newPath.Add(link);                                                                                                         //laziness wins
                                    //KSP techincally does not care if path is consisted of non-continuous links or not
                                }
                            }
                        }
                    }

                    path = newPath;
                    path.GetPoints(this.points, true);
                    numLinks = path.Count;
                }
                break;
            }// end of switch

            //check if nothing to display
            if (numLinks == 0)
            {
                if (this.line != null)
                {
                    this.line.active = false;
                }

                this.points.Clear();
                return;
            }

            if (this.line != null)
            {
                this.line.active = true;
            }
            else
            {
                this.refreshLines = true;
            }

            ScaledSpace.LocalToScaledSpace(this.points); //seem very important

            if (this.refreshLines || MapView.Draw3DLines != this.draw3dLines || count != this.points.Count || this.line == null)
            {
                this.CreateLine(ref this.line, this.points);//seems it is multiple separate lines not single continuous line
                this.draw3dLines  = MapView.Draw3DLines;
                this.refreshLines = false;
            }

            //paint the links
            switch (CNVCommNetUI.CustomMode)
            {
            case CNVCommNetUI.CustomDisplayMode.FirstHop:
            {
                float lvl = Mathf.Pow((float)path.First.signalStrength, this.colorLerpPower);
                if (this.swapHighLow)
                {
                    this.line.SetColor(Color.Lerp(this.colorHigh, this.colorLow, lvl), 0);
                }
                else
                {
                    this.line.SetColor(Color.Lerp(this.colorLow, this.colorHigh, lvl), 0);
                }
                break;
            }

            case CNVCommNetUI.CustomDisplayMode.Path:
            case CNVCommNetUI.CustomDisplayMode.MultiPaths:
            {
                int linkIndex = numLinks;
                for (int i = linkIndex - 1; i >= 0; i--)
                {
                    float lvl = Mathf.Pow((float)path[i].signalStrength, this.colorLerpPower);
                    if (this.swapHighLow)
                    {
                        this.line.SetColor(Color.Lerp(this.colorHigh, this.colorLow, lvl), i);
                    }
                    else
                    {
                        this.line.SetColor(Color.Lerp(this.colorLow, this.colorHigh, lvl), i);
                    }
                }
                break;
            }

            case CNVCommNetUI.CustomDisplayMode.VesselLinks:
            {
                var itr       = node.Values.GetEnumerator();
                int linkIndex = 0;
                while (itr.MoveNext())
                {
                    CommLink link = itr.Current;
                    float    lvl  = Mathf.Pow((float)link.GetSignalStrength(link.a != node, link.b != node), this.colorLerpPower);
                    if (this.swapHighLow)
                    {
                        this.line.SetColor(Color.Lerp(this.colorHigh, this.colorLow, lvl), linkIndex++);
                    }
                    else
                    {
                        this.line.SetColor(Color.Lerp(this.colorLow, this.colorHigh, lvl), linkIndex++);
                    }
                }
                break;
            }

            case CNVCommNetUI.CustomDisplayMode.Network:
            {
                for (int i = numLinks - 1; i >= 0; i--)
                {
                    CommLink commLink = net.Links[i];
                    float    lvl      = Mathf.Pow((float)net.Links[i].GetBestSignal(), this.colorLerpPower);
                    if (this.swapHighLow)
                    {
                        this.line.SetColor(Color.Lerp(this.colorHigh, this.colorLow, lvl), i);
                    }
                    else
                    {
                        this.line.SetColor(Color.Lerp(this.colorLow, this.colorHigh, lvl), i);
                    }
                }
                break;
            }
            } // end of switch

            if (this.draw3dLines)
            {
                this.line.SetWidth(this.lineWidth3D);
                this.line.Draw3D();
            }
            else
            {
                this.line.SetWidth(this.lineWidth2D);
                this.line.Draw();
            }
        }
Example #13
0
        protected override void UpdateDisplay()
        {
            //base.UpdateDisplay();
            if (CommNetNetwork.Instance == null)
            {
                return;
            }
            DisableAllLinkRenderers();
            DisableAllConeRenderers();
            if (CommNetUI.Mode == CommNetUI.DisplayMode.None)
            {
                return;
            }
            if (this.draw3dLines != MapView.Draw3DLines)
            {
                this.draw3dLines = MapView.Draw3DLines;
                ResetRendererLayer(MapView.Draw3DLines);
            }
            colorToTarget.a = ConeOpacity;
            color3dB.a      = ConeOpacity;
            color10dB.a     = ConeOpacity;

            if ((CommNetScenario.Instance as RACommNetScenario).Network.CommNet is RACommNetwork commNet)
            {
                if (CommNetUI.Mode == CommNetUI.DisplayMode.Network)
                {
                    foreach (RACommNode node in commNet.Nodes)
                    {
                        GatherLinkLines(node.Values.ToList());
                        GatherAntennaCones(node);
                    }
                }
                if (vessel is Vessel && vessel.Connection is CommNetVessel cnv &&
                    cnv.Comm is RACommNode commNode && cnv.ControlPath is CommPath commPath)
                {
                    switch (CommNetUI.Mode)
                    {
                    case DisplayMode.FirstHop:
                        CommLink cl = commPath.FirstOrDefault();
                        if (cl != null)
                        {
                            GatherLinkLines(new List <CommLink>()
                            {
                                cl.start == commNode ? cl.start[cl.end] : cl.end[cl.start]
                            });
                        }
                        GatherAntennaCones(commNode);
                        break;

                    case CommNetUI.DisplayMode.VesselLinks:
                        GatherLinkLines(commNode.Values.ToList());
                        GatherAntennaCones(commNode);
                        break;

                    case CommNetUI.DisplayMode.Path:
                        if (commPath.Count == 0)
                        {
                            GatherLinkLines(commNode.Values.ToList());
                            GatherAntennaCones(commNode);
                        }
                        foreach (CommLink link in commPath)
                        {
                            GatherLinkLines(new List <CommLink>()
                            {
                                link.start[link.end]
                            });
                            GatherAntennaCones(link.start as RACommNode);
                        }
                        break;
                    }
                }
            }
        }
        // Render the CommNet presentation
        // This method has been created to modify line color
        private void UpdateView()
        {
            CommNetwork   net      = CommNetNetwork.Instance.CommNet;
            CommNetVessel cnvessel = null;
            CommNode      node     = null;
            CommPath      path     = null;

            if (vessel != null && vessel.connection != null && vessel.connection.Comm.Net != null)
            {
                cnvessel = vessel.connection;
                node     = cnvessel.Comm;
                path     = cnvessel.ControlPath;
            }

            // Work out how many connections to paint
            int numLinks = 0;
            int count    = points.Count;

            switch (Mode)
            {
            case DisplayMode.None:
            {
                numLinks = 0;
                break;
            }

            case DisplayMode.FirstHop:
            {
                if (cnvessel.ControlState == VesselControlState.Probe || cnvessel.ControlState == VesselControlState.Kerbal || path == null || path.Count == 0)
                {
                    numLinks = 0;
                }
                else
                {
                    path.First.GetPoints(points);
                    numLinks = 1;
                }
                break;
            }

            case DisplayMode.Path:
            {
                if (cnvessel.ControlState == VesselControlState.Probe || cnvessel.ControlState == VesselControlState.Kerbal || path == null || path.Count == 0)
                {
                    numLinks = 0;
                }
                else
                {
                    path.GetPoints(points, true);
                    numLinks = path.Count;
                }
                break;
            }

            case DisplayMode.VesselLinks:
            {
                numLinks = node.Count;
                node.GetLinkPoints(points);
                break;
            }

            case DisplayMode.Network:
            {
                if (net.Links.Count == 0)
                {
                    numLinks = 0;
                }
                else
                {
                    numLinks = net.Links.Count;
                    net.GetLinkPoints(points);
                }
                break;
            }
            }

            // Check if nothing to draw
            if (numLinks == 0)
            {
                if (line != null)
                {
                    line.active = false;
                }
                points.Clear();
                return;
            }
            else
            {
                // TODO: I'm not sure if I need the commented part below.
                //if (line != null) line.active = true;
                //else refreshLines = true;
                //ScaledSpace.LocalToScaledSpace(points);
                //if (refreshLines || MapView.Draw3DLines != draw3dLines || (count != points.Count || line == null))
                //{
                //  CreateLine(ref line, points);
                //  draw3dLines = MapView.Draw3DLines;
                //  refreshLines = false;
                //}

                //paint eligible connections

                // Sample to create a customHighColor :
                //    Color customHighColor = getConstellationColor(path.First.a, path.First.b);
                //      If want custom color, alter colorHigh for customHighColor
                switch (Mode)
                {
                case DisplayMode.FirstHop:
                {
                    float lvl = Mathf.Pow((float)path.First.signalStrength, colorLerpPower);
                    if (swapHighLow)
                    {
                        line.SetColor(Color.Lerp(colorHigh, colorLow, lvl), 0);
                    }
                    else
                    {
                        line.SetColor(Color.Lerp(colorLow, colorHigh, lvl), 0);
                    }
                    break;
                }

                case DisplayMode.Path:
                {
                    int linkIndex = numLinks;
                    for (int i = linkIndex - 1; i >= 0; i--)
                    {
                        float lvl = Mathf.Pow((float)path[i].signalStrength, colorLerpPower);
                        if (swapHighLow)
                        {
                            line.SetColor(Color.Lerp(colorHigh, colorLow, lvl), i);
                        }
                        else
                        {
                            line.SetColor(Color.Lerp(colorLow, colorHigh, lvl), i);
                        }
                    }
                    break;
                }

                case DisplayMode.VesselLinks:
                {
                    var itr       = node.Values.GetEnumerator();
                    int linkIndex = 0;
                    while (itr.MoveNext())
                    {
                        CommLink link = itr.Current;
                        float    lvl  = Mathf.Pow((float)link.GetSignalStrength(link.a != node, link.b != node), colorLerpPower);
                        if (swapHighLow)
                        {
                            line.SetColor(Color.Lerp(colorHigh, colorLow, lvl), linkIndex++);
                        }
                        else
                        {
                            line.SetColor(Color.Lerp(colorLow, colorHigh, lvl), linkIndex++);
                        }
                    }
                    break;
                }

                case DisplayMode.Network:
                {
                    int linkIndex = numLinks;
                    while (linkIndex-- > 0)
                    {
                        CommLink commLink = net.Links[linkIndex];
                        float    t2       = Mathf.Pow((float)net.Links[linkIndex].GetBestSignal(), colorLerpPower);
                        if (swapHighLow)
                        {
                            line.SetColor(Color.Lerp(colorHigh, colorLow, t2), linkIndex);
                        }
                        else
                        {
                            line.SetColor(Color.Lerp(colorLow, colorHigh, t2), linkIndex);
                        }
                    }
                    break;
                }
                }
            }
        }
Example #15
0
        /// <summary>
        /// Overrode UpdateDisplay() fully and add own customisations
        /// </summary>
        private void updateCustomisedView()
        {
            if (FlightGlobals.ActiveVessel == null)
            {
                this.useTSBehavior = true;
            }
            else
            {
                this.useTSBehavior = false;
                this.vessel        = FlightGlobals.ActiveVessel;
            }

            if (this.vessel == null || this.vessel.connection == null || this.vessel.connection.Comm.Net == null) //revert to default display mode if saved mode is inconsistent in current situation
            {
                this.useTSBehavior = true;
                if (CustomModeTrackingStation != CustomDisplayMode.None)
                {
                    if (CustomModeTrackingStation != CustomDisplayMode.Network && CustomModeTrackingStation != CustomDisplayMode.MultiPaths)
                    {
                        CustomModeTrackingStation = CustomDisplayMode.Network;
                        ScreenMessages.PostScreenMessage(Localizer.Format("#autoLOC_118264", new string[]
                        {
                            Localizer.Format(CustomModeTrackingStation.displayDescription())
                        }), CNCSettings.ScreenMessageDuration);
                    }
                }
            }

            if (this.useTSBehavior)
            {
                CNCCommNetUI.CustomMode = CNCCommNetUI.CustomModeTrackingStation;
            }
            else
            {
                CNCCommNetUI.CustomMode = CNCCommNetUI.CustomModeFlightMap;
            }

            CommNetwork   net      = CommNetNetwork.Instance.CommNet;
            CommNetVessel cnvessel = null;
            CommNode      node     = null;
            CommPath      path     = null;

            if (this.vessel != null && this.vessel.connection != null && this.vessel.connection.Comm.Net != null)
            {
                cnvessel = this.vessel.connection;
                node     = cnvessel.Comm;
                path     = cnvessel.ControlPath;
            }

            //work out which links to display
            int  count    = this.points.Count;//save previous value
            int  numLinks = 0;
            bool pathLinkExist;

            switch (CNCCommNetUI.CustomMode)
            {
            case CNCCommNetUI.CustomDisplayMode.None:
                numLinks = 0;
                break;

            case CNCCommNetUI.CustomDisplayMode.FirstHop:
            case CNCCommNetUI.CustomDisplayMode.Path:
                if (cnvessel.ControlState == VesselControlState.Probe || cnvessel.ControlState == VesselControlState.Kerbal ||
                    path.Count == 0)
                {
                    numLinks = 0;
                }
                else
                {
                    if (CNCCommNetUI.CustomMode == CNCCommNetUI.CustomDisplayMode.FirstHop)
                    {
                        path.First.GetPoints(this.points);
                        numLinks = 1;
                    }
                    else
                    {
                        path.GetPoints(this.points, true);
                        numLinks = path.Count;
                    }
                }
                break;

            case CNCCommNetUI.CustomDisplayMode.VesselLinks:
                numLinks = node.Count;
                node.GetLinkPoints(this.points);
                break;

            case CNCCommNetUI.CustomDisplayMode.Network:
                if (net.Links.Count == 0)
                {
                    numLinks = 0;
                }
                else
                {
                    numLinks = net.Links.Count;
                    net.GetLinkPoints(this.points);
                }
                break;

            case CNCCommNetUI.CustomDisplayMode.MultiPaths:
                if (net.Links.Count == 0)
                {
                    numLinks = 0;
                }
                else
                {
                    path          = new CommPath();
                    path.Capacity = net.Links.Count;

                    var vessels = CNCCommNetScenario.Instance.getCommNetVessels();    //TODO: replace it with CNM
                    for (int i = 0; i < vessels.Count; i++)
                    {
                        vessels[i].computeUnloadedUpdate();    //network update is done only once for unloaded vessels so need to manually re-trigger every time

                        //is vessel real/alive?
                        if (!(vessels[i].ControlState == VesselControlState.Probe || vessels[i].ControlState == VesselControlState.Kerbal ||
                              vessels[i].ControlPath == null || vessels[i].ControlPath.Count == 0))
                        {
                            //add each link in control path to overall path
                            for (int controlpathIndex = 0; controlpathIndex < vessels[i].ControlPath.Count; controlpathIndex++)
                            {
                                pathLinkExist = false;
                                for (int overallpathIndex = 0; overallpathIndex < path.Count; overallpathIndex++)    //check if overall path has this link already
                                {
                                    if (CNCCommNetwork.AreSame(path[overallpathIndex].a, vessels[i].ControlPath[controlpathIndex].a) &&
                                        CNCCommNetwork.AreSame(path[overallpathIndex].b, vessels[i].ControlPath[controlpathIndex].b))
                                    {
                                        pathLinkExist = true;
                                        break;
                                    }
                                }
                                if (!pathLinkExist)
                                {
                                    path.Add(vessels[i].ControlPath[controlpathIndex]);     //laziness wins
                                    //KSP techincally does not care if path is consisted of non-continuous links or not
                                }
                            }
                        }
                    }

                    path.GetPoints(this.points, true);
                    numLinks = path.Count;
                }
                break;
            }// end of switch

            //check if nothing to display
            if (numLinks == 0)
            {
                if (this.line != null)
                {
                    this.line.active = false;
                }

                this.points.Clear();
                return;
            }

            if (this.line != null)
            {
                this.line.active = true;
            }
            else
            {
                this.refreshLines = true;
            }

            ScaledSpace.LocalToScaledSpace(this.points); //seem very important

            if (this.refreshLines || MapView.Draw3DLines != this.draw3dLines || count != this.points.Count || this.line == null)
            {
                this.CreateLine(ref this.line, this.points);//seems it is multiple separate lines not single continuous line
                this.draw3dLines  = MapView.Draw3DLines;
                this.refreshLines = false;
            }

            //paint the links
            switch (CNCCommNetUI.CustomMode)
            {
            case CNCCommNetUI.CustomDisplayMode.FirstHop:
            {
                this.line.SetColor(colorBlending(getConstellationColor(path.First.a, path.First.b),
                                                 this.colorLow,
                                                 Mathf.Pow((float)path.First.signalStrength, this.colorLerpPower)),
                                   0);
                break;
            }

            case CNCCommNetUI.CustomDisplayMode.Path:
            case CNCCommNetUI.CustomDisplayMode.MultiPaths:
            {
                for (int i = numLinks - 1; i >= 0; i--)
                {
                    this.line.SetColor(colorBlending(getConstellationColor(path[i].a, path[i].b),
                                                     this.colorLow,
                                                     Mathf.Pow((float)path[i].signalStrength, this.colorLerpPower)),
                                       i);
                }
                break;
            }

            case CNCCommNetUI.CustomDisplayMode.VesselLinks:
            {
                CommLink[] links = new CommLink[node.Count];
                node.Values.CopyTo(links, 0);
                for (int i = 0; i < links.Length; i++)
                {
                    this.line.SetColor(colorBlending(getConstellationColor(links[i].a, links[i].b),
                                                     this.colorLow,
                                                     Mathf.Pow((float)links[i].GetSignalStrength(links[i].a != node, links[i].b != node), this.colorLerpPower)),
                                       i);
                }
                break;
            }

            case CNCCommNetUI.CustomDisplayMode.Network:
            {
                for (int i = numLinks - 1; i >= 0; i--)
                {
                    this.line.SetColor(colorBlending(getConstellationColor(net.Links[i].a, net.Links[i].b),
                                                     this.colorLow,
                                                     Mathf.Pow((float)net.Links[i].GetBestSignal(), this.colorLerpPower)),
                                       i);
                }
                break;
            }
            } // end of switch

            if (this.draw3dLines)
            {
                this.line.SetWidth(this.lineWidth3D);
                this.line.Draw3D();
            }
            else
            {
                this.line.SetWidth(this.lineWidth2D);
                this.line.Draw();
            }
        }
        // TODO: Create rule to disconnect vessels without EC
        protected virtual bool TryConnectFreq(CommNode a, CommNode b, double distance, bool aCanRelay, bool bCanRelay, bool bothRelay, short freq = 0)
        {
            bool   flag = false;
            double num1 = a.GetSignalStrengthMultiplier(b) * b.GetSignalStrengthMultiplier(a);
            double num2;

            AntennasByFrequency a_Antennas = Cache.GetNodeAntennaCache(a, freq);
            AntennasByFrequency b_Antennas = Cache.GetNodeAntennaCache(b, freq);

            if (bothRelay)
            {
                double normalizedRange = CommNetScenario.RangeModel.GetNormalizedRange(a_Antennas.relayPower, b_Antennas.relayPower, distance);
                if (normalizedRange > 0.0)
                {
                    num2 = Math.Sqrt(a.antennaRelay.rangeCurve.Evaluate(normalizedRange) * b.antennaRelay.rangeCurve.Evaluate(normalizedRange)) * num1;
                    if (num2 > 0.0)
                    {
                        flag = true;
                    }
                }
                else
                {
                    bothRelay = false;
                    num2      = 0.0;
                }
            }
            else
            {
                num2 = 0.0;
            }
            double num3;

            if (aCanRelay)
            {
                double normalizedRange = CommNetScenario.RangeModel.GetNormalizedRange(a_Antennas.relayPower, b_Antennas.antennaPower, distance);
                if (normalizedRange > 0.0)
                {
                    num3 = Math.Sqrt(a.antennaRelay.rangeCurve.Evaluate(normalizedRange) * b.antennaTransmit.rangeCurve.Evaluate(normalizedRange)) * num1;
                    if (num3 > 0.0)
                    {
                        flag = true;
                    }
                }
                else
                {
                    aCanRelay = false;
                    num3      = 0.0;
                }
            }
            else
            {
                aCanRelay = false;
                num3      = 0.0;
            }
            double num4;

            if (bCanRelay)
            {
                double normalizedRange = CommNetScenario.RangeModel.GetNormalizedRange(a_Antennas.antennaPower, b_Antennas.relayPower, distance);
                if (normalizedRange > 0.0)
                {
                    num4 = Math.Sqrt(b.antennaRelay.rangeCurve.Evaluate(normalizedRange) * a.antennaTransmit.rangeCurve.Evaluate(normalizedRange)) * num1;
                    if (num4 > 0.0)
                    {
                        flag = true;
                    }
                }
                else
                {
                    bCanRelay = false;
                    num4      = 0.0;
                }
            }
            else
            {
                bCanRelay = false;
                num4      = 0.0;
            }
            if (flag)
            {
                CommLink commLink = Connect(a, b, distance);
                commLink.strengthRR = num2;
                commLink.strengthAR = num3;
                commLink.strengthBR = num4;
                commLink.aCanRelay  = aCanRelay;
                commLink.bCanRelay  = bCanRelay;
                commLink.bothRelay  = bothRelay;

                // flag frequency as connected
                //Cache.GetNodeAntennaCache(a, freq).countConnections += 1;
                //Cache.GetNodeAntennaCache(b, freq).countConnections += 1;
                return(true);
            }

            Disconnect(a, b, true);
            //if (Cache.GetNodeAntennaCache(a, freq).countConnections > 0) Cache.GetNodeAntennaCache(a, freq).countConnections -= 1;
            //if (Cache.GetNodeAntennaCache(b, freq).countConnections > 0) Cache.GetNodeAntennaCache(b, freq).countConnections -= 1;
            return(false);
        }
        private List <KeyValuePair <Vessel, double> > getConnectedVessels(Vessel v)
        {
            List <KeyValuePair <Vessel, double> > connections = new List <KeyValuePair <Vessel, double> >();

            List <KeyValuePair <CommNode, double> > checkNodes = new List <KeyValuePair <CommNode, double> >();

            if (v.connection != null)
            {
                CommNode source = v.connection.Comm;

                if (source != null)
                {
                    if (!settings.requireRelay)
                    {
                        checkNodes.Add(new KeyValuePair <CommNode, double>(source, 1));
                    }

                    CommNetwork net = v.connection.Comm.Net;

                    if (net != null)
                    {
                        for (int i = FlightGlobals.Vessels.Count - 1; i >= 0; i--)
                        {
                            Vessel otherVessel = FlightGlobals.Vessels[i];

                            if (otherVessel == null)
                            {
                                continue;
                            }

                            if (otherVessel == v)
                            {
                                continue;
                            }

                            VesselType type = otherVessel.vesselType;

                            if (type == VesselType.Debris || type == VesselType.SpaceObject || type == VesselType.Unknown || type == VesselType.Flag)
                            {
                                continue;
                            }

                            if (otherVessel.connection == null || otherVessel.connection.Comm == null)
                            {
                                continue;
                            }

                            if (!net.FindPath(source, pathCache, otherVessel.connection.Comm))
                            {
                                continue;
                            }

                            if (pathCache == null)
                            {
                                continue;
                            }

                            if (pathCache.Count <= 0)
                            {
                                continue;
                            }

                            if (!settings.requireRelay)
                            {
                                double totalStrength = 1;

                                int l = pathCache.Count;

                                for (int j = 0; j < l; j++)
                                {
                                    CommLink link = pathCache[j];

                                    totalStrength *= link.signalStrength;

                                    if (!link.a.isHome && !updateCommNode(checkNodes, link.a, totalStrength))
                                    {
                                        checkNodes.Add(new KeyValuePair <CommNode, double>(link.a, totalStrength));
                                    }

                                    if (!link.b.isHome && !updateCommNode(checkNodes, link.b, totalStrength))
                                    {
                                        checkNodes.Add(new KeyValuePair <CommNode, double>(link.b, totalStrength));
                                    }
                                }
                            }

                            if (settings.requireMPL && !VesselUtilities.VesselHasModuleName("ModuleScienceLab", otherVessel))
                            {
                                continue;
                            }

                            if (!VesselUtilities.VesselHasModuleName("ModuleScienceContainer", otherVessel))
                            {
                                continue;
                            }

                            double s = pathCache.signalStrength;

                            s = source.scienceCurve.Evaluate(s);

                            connections.Add(new KeyValuePair <Vessel, double>(otherVessel, s + 1));
                        }

                        if (!settings.requireRelay)
                        {
                            for (int k = checkNodes.Count - 1; k >= 0; k--)
                            {
                                KeyValuePair <CommNode, double> pair = checkNodes[k];

                                CommNode node = pair.Key;

                                if (node.isHome)
                                {
                                    continue;
                                }

                                for (int l = FlightGlobals.Vessels.Count - 1; l >= 0; l--)
                                {
                                    Vessel otherVessel = FlightGlobals.Vessels[l];

                                    if (otherVessel == null)
                                    {
                                        continue;
                                    }

                                    if (otherVessel == v)
                                    {
                                        continue;
                                    }

                                    VesselType type = otherVessel.vesselType;

                                    if (type == VesselType.Debris || type == VesselType.SpaceObject || type == VesselType.Unknown || type == VesselType.Flag)
                                    {
                                        continue;
                                    }

                                    if (otherVessel.connection == null || otherVessel.connection.Comm == null)
                                    {
                                        continue;
                                    }

                                    CommNode otherComm = otherVessel.connection.Comm;

                                    if (otherComm.antennaRelay.power > 0)
                                    {
                                        continue;
                                    }

                                    if (settings.requireMPL && !VesselUtilities.VesselHasModuleName("ModuleScienceLab", otherVessel))
                                    {
                                        continue;
                                    }

                                    if (!VesselUtilities.VesselHasModuleName("ModuleScienceContainer", otherVessel))
                                    {
                                        continue;
                                    }

                                    double dist = (otherComm.precisePosition - node.precisePosition).magnitude;

                                    if (isOccluded(node, otherComm, dist, net))
                                    {
                                        continue;
                                    }

                                    double power = directConnection(node, otherComm, dist, source == node, pair.Value);

                                    if (power <= 0)
                                    {
                                        continue;
                                    }

                                    power = source.scienceCurve.Evaluate(power);

                                    bool flag = false;

                                    for (int m = connections.Count - 1; m >= 0; m--)
                                    {
                                        KeyValuePair <Vessel, double> connect = connections[m];

                                        if (connect.Key != otherVessel)
                                        {
                                            continue;
                                        }

                                        if (connect.Value < power + 1)
                                        {
                                            connections[m] = new KeyValuePair <Vessel, double>(connect.Key, power + 1);
                                        }

                                        flag = true;
                                        break;
                                    }

                                    for (int m = connections.Count - 1; m >= 0; m--)
                                    {
                                        KeyValuePair <Vessel, double> connect = connections[m];

                                        if (connect.Key != otherVessel)
                                        {
                                            continue;
                                        }

                                        break;
                                    }

                                    if (!flag)
                                    {
                                        connections.Add(new KeyValuePair <Vessel, double>(otherVessel, power + 1));
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(connections);
        }
        /// <summary>
        /// Overrode UpdateDisplay() fully and add own customisations
        /// </summary>
        private void updateCustomisedView()
        {
            if (FlightGlobals.ActiveVessel == null)
            {
                this.useTSBehavior = true;
            }
            else
            {
                this.useTSBehavior = false;
                this.vessel        = FlightGlobals.ActiveVessel;
            }

            if (this.vessel == null || this.vessel.connection == null || this.vessel.connection.Comm.Net == null) //revert to default display mode if saved mode is inconsistent in current situation
            {
                this.useTSBehavior = true;
                if (CustomModeTrackingStation != CustomDisplayMode.None)
                {
                    if (CustomModeTrackingStation != CustomDisplayMode.Network && CustomModeTrackingStation != CustomDisplayMode.MultiPaths)
                    {
                        CustomModeTrackingStation = CustomDisplayMode.Network;
                        ScreenMessages.PostScreenMessage(Localizer.Format("#autoLOC_118264", new string[]
                        {
                            Localizer.Format(CustomModeTrackingStation.displayDescription())
                        }), CNCSettings.ScreenMessageDuration);
                    }
                }
            }

            if (CommNetNetwork.Instance == null)
            {
                return;
            }
            if (this.useTSBehavior)
            {
                CNCCommNetUI.CustomMode = CNCCommNetUI.CustomModeTrackingStation;
            }
            else
            {
                CNCCommNetUI.CustomMode = CNCCommNetUI.CustomModeFlightMap;
            }

            CommNetwork   net      = CommNetNetwork.Instance.CommNet;
            CommNetVessel cnvessel = null;
            CommNode      node     = null;
            CommPath      path     = null;

            if (this.vessel != null && this.vessel.connection != null && this.vessel.connection.Comm.Net != null)
            {
                cnvessel = this.vessel.connection;
                node     = cnvessel.Comm;
                path     = cnvessel.ControlPath;
            }

            //work out which links to display
            int  count    = this.points.Count;//save previous value
            int  numLinks = 0;
            bool pathLinkExist;

            switch (CNCCommNetUI.CustomMode)
            {
            case CNCCommNetUI.CustomDisplayMode.None:
                numLinks = 0;
                break;

            case CNCCommNetUI.CustomDisplayMode.FirstHop:
                if (cnvessel.ControlState != VesselControlState.Probe && cnvessel.ControlState != VesselControlState.Kerbal && path != null)
                {
                    if (path.Count != 0)
                    {
                        path.First.GetPoints(this.points);
                        numLinks = 1;
                        break;
                    }
                }
                numLinks = 0;
                break;

            case CNCCommNetUI.CustomDisplayMode.Path:
                if (cnvessel.ControlState != VesselControlState.Probe && cnvessel.ControlState != VesselControlState.Kerbal && path != null)
                {
                    if (path.Count != 0)
                    {
                        path.GetPoints(this.points, true);
                        numLinks = path.Count;
                        break;
                    }
                }
                numLinks = 0;
                break;

            case CNCCommNetUI.CustomDisplayMode.VesselLinks:
                numLinks = node.Count;
                node.GetLinkPoints(this.points);
                break;

            case CNCCommNetUI.CustomDisplayMode.Network:
                if (net.Links.Count == 0)
                {
                    numLinks = 0;
                }
                else
                {
                    //net.GetLinkPoints(this.points);
                    //numLinks = net.Links.Count;
                    //KSP 1.8: Likely shader changes led to stackup of 2 or more lines illustrating overall brighter line
                    //Workaround: collect unqiue lines as path
                    path          = new CommPath();
                    path.Capacity = net.Links.Count;

                    for (int i = 0; i < net.Links.Count; i++)
                    {
                        pathLinkExist = false;
                        for (int overallpathIndex = 0; overallpathIndex < path.Count; overallpathIndex++)    //check if path has this link already
                        {
                            if (CNCCommNetwork.AreSame(path[overallpathIndex].a, net.Links[i].a) &&
                                CNCCommNetwork.AreSame(path[overallpathIndex].b, net.Links[i].b))
                            {
                                pathLinkExist = true;
                                break;
                            }
                        }
                        if (!pathLinkExist)
                        {
                            path.Add(net.Links[i]);
                        }
                    }

                    path.GetPoints(this.points, true);
                    numLinks = path.Count;
                }
                break;

            case CNCCommNetUI.CustomDisplayMode.MultiPaths:
                if (net.Links.Count == 0)
                {
                    numLinks = 0;
                }
                else
                {
                    path          = new CommPath();
                    path.Capacity = net.Links.Count;

                    for (int i = 0; i < net.Count; i++)
                    {
                        if (net[i].isControlSource)     //is it ground station/remote-control pilot?
                        {
                            continue;
                        }

                        var thisPath = new CommPath();
                        net.FindHome(net[i], thisPath);
                        for (int controlpathIndex = 0; controlpathIndex < thisPath.Count; controlpathIndex++)
                        {
                            pathLinkExist = false;
                            for (int overallpathIndex = 0; overallpathIndex < path.Count; overallpathIndex++)    //check if overall path has this link already
                            {
                                if (CNCCommNetwork.AreSame(path[overallpathIndex].a, thisPath[controlpathIndex].a) &&
                                    CNCCommNetwork.AreSame(path[overallpathIndex].b, thisPath[controlpathIndex].b))
                                {
                                    pathLinkExist = true;
                                    break;
                                }
                            }
                            if (!pathLinkExist)
                            {
                                path.Add(thisPath[controlpathIndex]);
                            }
                        }
                    }

                    path.GetPoints(this.points, true);
                    numLinks = path.Count;
                }
                break;
            }// end of switch

            //check if nothing to display
            if (numLinks == 0)
            {
                if (this.line != null)
                {
                    this.line.active = false;
                }

                this.points.Clear();
                return;
            }

            if (this.line != null)
            {
                this.line.active = true;
            }
            else
            {
                this.refreshLines = true;
            }

            ScaledSpace.LocalToScaledSpace(this.points); //seem very important
            if (!(!this.refreshLines && MapView.Draw3DLines == this.draw3dLines && count == this.points.Count && this.line != null))
            {
                this.CreateLine(ref this.line, this.points);//seems it is multiple separate lines not single continuous line
                this.draw3dLines  = MapView.Draw3DLines;
                this.refreshLines = false;
            }

            //paint the links
            switch (CNCCommNetUI.CustomMode)
            {
            case CNCCommNetUI.CustomDisplayMode.FirstHop:
            {
                this.line.SetColor(colorBlending(getConstellationColor(path.First.a, path.First.b),
                                                 this.colorLow,
                                                 Mathf.Pow((float)path.First.signalStrength, this.colorLerpPower)),
                                   0);
                break;
            }

            case CNCCommNetUI.CustomDisplayMode.Path:
            case CNCCommNetUI.CustomDisplayMode.MultiPaths:
            {
                for (int i = numLinks - 1; i >= 0; i--)
                {
                    this.line.SetColor(colorBlending(getConstellationColor(path[i].a, path[i].b),
                                                     this.colorLow,
                                                     Mathf.Pow((float)path[i].signalStrength, this.colorLerpPower)),
                                       i);
                }
                break;
            }

            case CNCCommNetUI.CustomDisplayMode.VesselLinks:
            {
                CommLink[] links = new CommLink[node.Count];
                node.Values.CopyTo(links, 0);
                for (int i = 0; i < links.Length; i++)
                {
                    this.line.SetColor(colorBlending(getConstellationColor(links[i].a, links[i].b),
                                                     this.colorLow,
                                                     Mathf.Pow((float)links[i].GetSignalStrength(links[i].a != node, links[i].b != node), this.colorLerpPower)),
                                       i);
                }
                break;
            }

            case CNCCommNetUI.CustomDisplayMode.Network:
            {
                //for (int i = numLinks - 1; i >= 0; i--)
                //{
                //    this.line.SetColor(colorBlending(getConstellationColor(net.Links[i].a, net.Links[i].b),
                //                                     this.colorLow,
                //                                     Mathf.Pow((float) net.Links[i].GetBestSignal(), this.colorLerpPower)),
                //                                     i);
                //}
                for (int i = numLinks - 1; i >= 0; i--)
                {
                    this.line.SetColor(colorBlending(getConstellationColor(path[i].a, path[i].b),
                                                     this.colorLow,
                                                     Mathf.Pow((float)path[i].GetBestSignal(), this.colorLerpPower)),
                                       i);
                }
                break;
            }
            } // end of switch

            if (this.draw3dLines)
            {
                this.line.SetWidth(this.lineWidth3D);
                this.line.Draw3D();
            }
            else
            {
                this.line.SetWidth(this.lineWidth2D);
                this.line.Draw();
            }
        }
Example #19
0
        void DropHandler(DsspDefaultDrop drop)
        {
            Tracer.Trace("SickLRF::DropHandler()");

            try
            {
                if (_link != null)
                {
                    // release dispatcher queue resource
                    ResourceManagerPort.Post(new FreeExecutionResource(_link.TaskQueue));
                    _link.Close();
                    _link = null;
                }
            }
            finally
            {
                base.DefaultDropHandler(drop);
            }
        }
Example #20
0
 /// <summary>
 /// <para>Plays a sound file stored in the NXT brick.</para>
 /// </summary>
 /// <param name="soundFile">The sound file</param>
 public void PlaySoundfile(string soundFile)
 {
     CommLink.PlaySoundfile(false, soundFile);
 }
Example #21
0
        /// <summary>
        /// Start conversation with the SickLRF device.
        /// </summary>
        IEnumerator<ITask> StartLRF(int timeout, int comPort)
        {
            Tracer.Trace("SickLRF::StartLRF() comPort=" + comPort);

            if (timeout > 0)
            {
                //
                // caller asked us to wait <timeout> milliseconds until we start.
                //

                yield return Arbiter.Receive(false, TimeoutPort(timeout),
                    delegate(DateTime dt)
                    {
                        LogInfo("Done Waiting");
                    }
                );
            }

            if (_queue == null)
            {
                //
                // The internal services run on their own dispatcher, we need to create that (once)
                //

                AllocateExecutionResource allocExecRes = new AllocateExecutionResource(0, "SickLRF");

                ResourceManagerPort.Post(allocExecRes);

                yield return Arbiter.Choice(
                    allocExecRes.Result,
                    delegate(ExecutionAllocationResult result)
                    {
                        _queue = result.TaskQueue;
                    },
                    delegate(Exception e)
                    {
                        LogError(e);
                    }
                );
            }

            string comName;

            if (comPort <= 0)
            {
                //
                // We default to COM4, because
                // a) that was our previous behavior and
                // b) the hardware that we have uses COM4
                //
                comName = "COM4";
            }
            else
            {
                comName = "COM" + comPort;
            }

            _link = new CommLink(_queue ?? TaskQueue, comName, _internalPort);
            _link.Parent = ServiceInfo.Service;
            _link.Console = ConsoleOutputPort;

            FlushPortSet(_internalPort);
            yield return(
                Arbiter.Choice(
                    _link.Open(),
                    delegate(SuccessResult success)
                    {
                        LogInfo("Opened link to LRF");
                    },
                    delegate(Exception exception)
                    {
                        LogError(exception);
                    }
                )
            );
        }
 void IPublicCommNet.UpdateShortestPath(CommNode a, CommNode b, CommLink link, double bestCost, CommNode startNode, CommNode endNode)
 {
     this.UpdateShortestPath(a, b, link, bestCost, startNode, endNode);
 }