当前位置: 首页>>代码示例>>Golang>>正文


Golang Msg.HasPosition方法代码示例

本文整理汇总了Golang中github.com/skypies/adsb.Msg.HasPosition方法的典型用法代码示例。如果您正苦于以下问题:Golang Msg.HasPosition方法的具体用法?Golang Msg.HasPosition怎么用?Golang Msg.HasPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/skypies/adsb.Msg的用法示例。


在下文中一共展示了Msg.HasPosition方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Add

// MaybeAdd looks at a new message, and updates the buffer as appropriate.
func (mb *MsgBuffer) Add(m *adsb.Msg) {

	mb.ageOutQuietSenders()

	if _, exists := mb.Senders[m.Icao24]; exists == false {
		// We've not seen this sender before. If we have position data,
		// start the whitelisting thing. We only Whitelist senders who
		// will eventually send useful info (e.g. position), so wait until
		// we see that.
		if m.HasPosition() {
			mb.Senders[m.Icao24] = &ADSBSender{LastSeen: time.Now().UTC()}
		}
	} else {
		mb.Senders[m.Icao24].updateFromMsg(m) // Pluck out anything interesting
		if composite := mb.Senders[m.Icao24].maybeCreateComposite(m); composite != nil {
			// We have a message to store !!
			mb.Messages = append(mb.Messages, composite)
		}
	}

	// We use the timestamp in the message to decide when to flush,
	// rather than the time at which we received the message; this is to
	// deliver a better end-to-end QoS for message delivery.

	// But stale messages can arrive, with timestamps from the past;
	// they would always trigger a flush, and flushing every message
	// slows things down (so we never ever catch up again :().
	// So we also enforce a minimum interval between flushes.
	if len(mb.Messages) > 0 {
		t := mb.Messages[0].GeneratedTimestampUTC
		if time.Since(t) >= mb.MaxMessageAge && time.Since(mb.lastFlush) >= mb.MinPublishInterval {
			mb.flush()
		}
	}
}
开发者ID:skypies,项目名称:adsb,代码行数:36,代码来源:msgbuffer.go

示例2: main

func main() {
	Log.Printf("reading file '%s' (dumpPos=%v)", fFilename, fDumpPos)

	h := histogram.Histogram{
		ValMin:     0,
		ValMax:     80,
		NumBuckets: 80,
	}
	_ = h
	if osFile, err := os.Open(fFilename); err != nil {
		Log.Fatal(err)
	} else {
		scanner := bufio.NewScanner(osFile) // os.File implements io.Reader
		for scanner.Scan() {
			m := adsb.Msg{}
			text := scanner.Text()
			if err := m.FromSBS1(text); err != nil {
				Log.Fatal(err)
				break
			}

			if fDumpPos {
				if m.HasPosition() {
					fmt.Printf("\"%.5f,%.5f\"\n", m.Position.Lat, m.Position.Long)
				}
			} else {
				Log.Print(m)
			}

		}
		if err := scanner.Err(); err != nil {
			Log.Fatal(err)
		}
	}
}
开发者ID:skypies,项目名称:pi,代码行数:35,代码来源:analyse.go

示例3: maybeCreateComposite

// If this message has new position info, *and* we have good backfill, then craft a CompositeMsg.
// Note, we don't wait for squawk info.
func (s *ADSBSender) maybeCreateComposite(m *adsb.Msg) *adsb.CompositeMsg {
	if !m.HasPosition() {
		return nil
	}

	//if s.LastGroundSpeed == 0 || s.LastTrack == 0 || s.LastCallsign == "" { return nil }

	cm := adsb.CompositeMsg{Msg: *m} // Clone the input into the embedded struct

	// Overwrite with cached info (from previous packets), if we don't have it in this packet
	if cm.GroundSpeed == 0 {
		cm.GroundSpeed = s.LastGroundSpeed
	}
	if cm.VerticalRate == 0 {
		cm.VerticalRate = s.LastVerticalSpeed
	}
	if cm.Track == 0 {
		cm.Track = s.LastTrack
	}
	if cm.Callsign == "" {
		cm.Callsign = s.LastCallsign
	}
	if cm.Squawk == "" {
		cm.Squawk = s.LastSquawk
	}

	return &cm
}
开发者ID:skypies,项目名称:adsb,代码行数:30,代码来源:msgbuffer.go


注:本文中的github.com/skypies/adsb.Msg.HasPosition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。