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


Golang Msg.IsMasked方法代码示例

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


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

示例1: readMsgFromSocket

// readMsgFromSocket will pull basestation (and extended basestation)
// formatted messages from the socket, and send them down the channel.
// It will retry the connection on failure.
func readMsgFromSocket(wg *sync.WaitGroup, hostport string, msgChan chan<- *adsb.Msg) {
	nTimeMismatches := 0
	lastBackoff := time.Second

	wg.Add(1)

outerLoop:
	for {
		if weAreDone() {
			break
		} // outer

		conn, err := net.Dial("tcp", hostport)
		if err != nil {
			Log.Printf("connect '%s': err %s; trying again in %s ...", hostport, err, lastBackoff*2)
			time.Sleep(lastBackoff)
			if lastBackoff < time.Minute*5 {
				lastBackoff *= 2
			}
			continue
		}

		lastBackoff = time.Second
		Log.Printf("connected to '%s'", hostport)

		// a net.Conn implements io.Reader
		scanner := bufio.NewScanner(conn)
		for scanner.Scan() { // This can block indefinitely ...
			if weAreDone() {
				break outerLoop
			}

			if err := scanner.Err(); err != nil {
				Log.Printf("killing connection, scanner err: %v\n", err)
				conn.Close()
				break // inner
			}

			msg := adsb.Msg{}
			text := scanner.Text()
			if err := msg.FromSBS1(text); err != nil {
				Log.Printf("killing connection, SBS  input:%q, parse fail: %v", text, err)
				break // inner
			}

			// If there is significant clock skew, we should bail. But, it seems
			// that sometimes we pick up stale data from dump1090; so wait to see
			// if it passes.
			offset := time.Since(msg.GeneratedTimestampUTC)
			if offset > time.Minute*30 || offset < time.Minute*-30 {
				nTimeMismatches++
				if nTimeMismatches < 100 {
					continue // do not process this message
				} else {
					Log.Fatalf("100 bad msgs; set -timeloc ?\nNow = %s\nmsg = %s\n", time.Now(),
						msg.GeneratedTimestampUTC)
				}
			}

			// If the message is flagged as one we should mask, honor that
			if msg.IsMasked() {
				continue
			}

			msgChan <- &msg
		}
	}

	wg.Done()
	Log.Printf(" ---- readMsgFromSocket, clean shutdown\n")
}
开发者ID:skypies,项目名称:pi,代码行数:74,代码来源:skypi.go


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