Beispiel #1
0
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)
		}
	}
}
Beispiel #2
0
func addFr24ToAirspace(ctx context.Context, as *airspace.Airspace) {
	fr, _ := fr24.NewFr24(urlfetch.Client(ctx))

	if asFr24, err := fr.FetchAirspace(sfo.KAirports["KSFO"].Box(250, 250)); err != nil {
		return
	} else {
		for k, ad := range asFr24.Aircraft {
			// FIXME: This whole thing is a crock. Track down usage of fr24/icaoids and rewrite all of it
			newk := string(k)
			newk = "EE" + strings.TrimPrefix(newk, "EE") // Remove (if present), then add
			ad.Airframe.Icao24 = newk
			as.Aircraft[adsb.IcaoId(newk)] = ad
		}
	}
}
Beispiel #3
0
func (a Airspace) String() string {
	str := ""

	keys := []string{}
	for k, _ := range a.Aircraft {
		keys = append(keys, string(k))
	}
	sort.Strings(keys)

	for _, k := range keys {
		ac := a.Aircraft[adsb.IcaoId(k)]
		str += fmt.Sprintf(" %8.8s/%-8.8s/%-6.6s (%s last:%6.1fs at %s/%s, %5d msgs) %5df, %3dk\n",
			ac.Msg.Callsign, ac.Msg.Icao24, ac.Registration,
			ac.Msg.DataSystem(),
			time.Since(ac.Msg.GeneratedTimestampUTC).Seconds(),
			ac.Source, ac.Msg.ReceiverName,
			ac.NumMessagesSeen,
			ac.Msg.Altitude, ac.Msg.GroundSpeed)
	}
	return str
}