Method: NMEAPlus::SourceDecoder#each_complete_message
- Defined in:
- lib/nmea_plus.rb
#each_complete_message {|NMEAPlus::Message| ... } ⇒ void
This method returns an undefined value.
Attempts to group multipart NMEA messages into chains, and executes the block once for every complete chain. To limit memory use (and be realistic about our ability to match up messages), only 1 message of chain of each NMEA message type can be in progress at any one time.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/nmea_plus.rb', line 79 def partials = {} # hash of message type to message-chain-in-progress do |msg| # don't clutter things up if the message arrives already complete if msg. yield msg next end # put message into partials slot (merge if necessary) based on its data type slot = msg.data_type if partials[slot].nil? # no message in there partials[slot] = msg elsif 1 != (msg. - partials[slot].) # broken sequence # error! just overwrite what was there partials[slot] = msg else # chain on to what's there partials[slot].(msg) end # take action if we've completed the chain maybe_full = partials[slot] if maybe_full. partials[slot] = nil yield maybe_full end end end |