示例#1
0
文件: msgbuffer.go 项目: skypies/adsb
// Some subtype packets have data we don't get in the bulk of position packets (those of subtype:3),
// so just cache their interesting data and inject it into next position packet.
// http://woodair.net/SBS/Article/Barebones42_Socket_Data.htm
func (s *ADSBSender) updateFromMsg(m *adsb.Msg) {
	s.LastSeen = time.Now().UTC()

	// If the message had any of the optional fields, cache the value for later
	if m.HasCallsign() {
		if len(m.Callsign) > 0 {
			s.LastCallsign = m.Callsign
		} else {
			s.LastCallsign = "_._._._." // Our nil value :/
		}
	}
	if m.HasSquawk() {
		s.LastSquawk = m.Squawk
	}
	if m.HasGroundSpeed() {
		s.LastGroundSpeed = m.GroundSpeed
	}
	if m.HasTrack() {
		s.LastTrack = m.Track
	}
	if m.HasVerticalRate() {
		s.LastVerticalSpeed = m.VerticalRate
	}

	if m.Type == "MSG_foooo" {
		if m.SubType == 1 {
			// TODO: move this to m.hasCallsign()
			// MSG,1 - the callsign/ident subtype - is sometimes blank. But we
			// don't really want to confuse flights that have a purposefully
			// blank callsign with those for yet we've yet to receive a MSG,1.
			// So we use a magic string instead.
			if m.Callsign == "" {
				s.LastCallsign = "_._._._."
			}
			if m.Callsign != "" {
				s.LastCallsign = m.Callsign
			}

		} else if m.SubType == 2 {
			if m.HasGroundSpeed() {
				s.LastGroundSpeed = m.GroundSpeed
			}
			if m.HasTrack() {
				s.LastTrack = m.Track
			}

		} else if m.SubType == 4 {
			if m.HasGroundSpeed() {
				s.LastGroundSpeed = m.GroundSpeed
			}
			if m.HasVerticalRate() {
				s.LastVerticalSpeed = m.VerticalRate
			}
			if m.HasTrack() {
				s.LastTrack = m.Track
			}

		} else if m.SubType == 6 {
			if m.Squawk != "" {
				s.LastSquawk = m.Squawk
			}
		}
	}
}