Beispiel #1
0
func FillPredictionView(p scheduler.Prediction, pv *predictionView) {
	pv.SatelliteId = *p.Satellite.Id
	pv.SatelliteName = RenderSatelliteName(p.Satellite.Name)
	pv.StartTime = timestamp.TimestampFloatToTime(
		p.StartTimestamp).UTC().Format(TimeFormat)
	pv.Duration = scheduler.Duration(
		p.EndTimestamp - p.StartTimestamp).String()
	pv.StartAzimuth = p.StartAzimuthDegrees
	pv.EndAzimuth = p.EndAzimuthDegrees
	pv.MaxAltitude = p.MaxAltitudeDegrees
}
Beispiel #2
0
// blocking
// FIXME: handle disconnections
func scheduleStation(stationdb *db.StationDB,
	contactdb *db.ContactDB,
	mux_client *rpc.Client,
	station_id string,
	shutdown_chan chan string) {

	defer func() { shutdown_chan <- station_id }()

	log_label := station_id
	log.Printf("%s: Scheduling starting.", log_label)

	for {
		// Lookup the station in the loop since the owner might
		// edit the parameters.
		station, err := stationdb.Lookup(station_id)
		if err != nil {
			log.Printf("%s: Station lookup error: %s",
				log_label, err.Error())
			continue
		}
		if station == nil {
			log.Printf("%s: Station doesn't exist.", log_label)
			return
		}

		next_pass, err := getNextPass(station)
		if err != nil {
			log.Printf("%s: Error getting pass predictions: %s",
				log_label, err.Error())
		}

		var delay time.Duration
		if next_pass.Satellite == nil {
			// No passes coming up soon. Just wait a bit and try
			// again.
			log.Printf("%s: no upcoming passes", log_label)
			delay = maxPredictionDuration
		} else if station.SchedulerEnabled == nil ||
			*station.SchedulerEnabled == false {
			//log.Printf("%s: scheduler disabled", station_id)
			// TODO: We are effectively polling the SchedulerEnabled
			// bit. We really should instead have the frontend
			// send a notification to reschedule the station.
			delay = controlDisabledDuration
		} else {
			log.Printf("%s: next pass: %s",
				log_label, *next_pass.Satellite.Id)
			delay = timestamp.TimestampFloatToTime(
				next_pass.StartTimestamp).Sub(time.Now())
		}

		log.Printf("%s: waiting for %s", log_label, delay)

		// wait {timer, disconnect}
		// FIXME: handle disconnections during the sleep
		time.Sleep(delay)

		if next_pass.Satellite == nil {
			continue
		}

		// Check that station has enabled scheduling.
		// We have to look up the station again since it might have
		// changed while we were sleeping.
		station, err = stationdb.Lookup(station_id)
		if err != nil {
			log.Printf("%s: Station lookup error: %s",
				log_label, err.Error())
			continue
		}
		if station == nil {
			log.Printf("%s: Station doesn't exist.", log_label)
			return
		}
		if station.SchedulerEnabled == nil ||
			*station.SchedulerEnabled == false {
			continue
		}

		err = capturePass(contactdb, mux_client, *station, next_pass)
		if err != nil {
			// There was an error of some sort.
			// Wait a bit before trying again.
			time.Sleep(errorWaitDuration)
		}
	}
}