Example #1
0
        private void SendSentenceToFilterItems(NmeaSinkAndSource source, NmeaSentence sentence, FilterRule filter)
        {
            foreach (var sinkName in filter.Sinks)
            {
                if (_sourcesAndSinks.TryGetValue(sinkName, out var sink))
                {
                    // If both source and sink are the local interface, we abort here, as we would be causing a
                    // stack overflow. Note that it is legal to loop messages over Uart interfaces as the TX and RX
                    // line need not be connected to the same physical device. If the receiver is doing the same there,
                    // we'll end up in trouble anyway, though.
                    if (source.InterfaceName == LocalMessageSource && sink.InterfaceName == LocalMessageSource)
                    {
                        continue;
                    }

                    if (filter.ForwardingAction != null)
                    {
                        var newMsg = filter.ForwardingAction(source, sink, sentence);
                        if (newMsg != null)
                        {
                            sink.SendSentence(source, newMsg);
                        }
                    }
                    else
                    {
                        sink.SendSentence(source, sentence);
                    }
                }
            }
        }