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


Golang Msg.SubType方法代码示例

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


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

示例1: generateData

func generateData() {
	fmt.Printf("(launching mock dump0190 on localhost:%d; mlat=%v)\n", port, mlat)

	ln, _ := net.Listen("tcp", fmt.Sprintf("localhost:%d", port))

outerLoop:
	for {
		conn, _ := ln.Accept()
		fmt.Printf("(connection started)\n")

		m := adsb.Msg{
			Icao24:                adsb.IcaoId("A81BD0"),
			Callsign:              "ABW123",
			Type:                  "MSG",
			Altitude:              12345,
			GroundSpeed:           300,
			Track:                 315,
			VerticalRate:          64,
			Position:              geo.Latlong{36.0, -122.0},
			GeneratedTimestampUTC: time.Now().UTC(),
			LoggedTimestampUTC:    time.Now().UTC(),
		}

		// We need to prime the pump, and trick the msgbuffer
		m.SubType = 3 // Get an entry in the sender table for our Icao, by proving we have pos data
		conn.Write([]byte(fmt.Sprintf("%s\n", m.ToSBS1())))
		m.SubType = 1 // Populate the sender table entry with a callsign (MSG,1 only)
		conn.Write([]byte(fmt.Sprintf("%s\n", m.ToSBS1())))
		m.SubType = 4 // Populate the sender table entry with velocity data (MSG,4 only)
		conn.Write([]byte(fmt.Sprintf("%s\n", m.ToSBS1())))
		m.SubType = 3 // All future messages are linear position updates (MSG,3 only)

		for {
			now := time.Now().UTC().Add(-1 * delay)
			m.Position.Lat += 0.01
			m.GeneratedTimestampUTC = now
			m.LoggedTimestampUTC = now

			if mlat {
				m.Type = "MLAT"
			}

			if _, err := conn.Write([]byte(fmt.Sprintf("%s\n", m.ToSBS1()))); err != nil {
				fmt.Printf("(connection ended)\n")
				continue outerLoop
			}

			time.Sleep(time.Millisecond * 1000)
		}
	}
}
开发者ID:skypies,项目名称:pi,代码行数:51,代码来源:mockdump1090.go


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