/** * Calculates the sun's azimuth at a given location and time * @param Location azimuth at what location * @param time azimuth at what time * @param dec precalculated declination angle * @return sun's azimuth * @see http://www.providence.edu/mcs/rbg/java/sungraph.htm */ static Angle CalculateAzimuth(const GeoPoint &Location, const BrokenTime &time, const fixed time_zone, const Angle dec) { assert(time.Plausible()); fixed T = fixed(time.GetSecondOfDay()) / 3600 - fixed(12) + time_zone; Angle t = Angle::Degrees(15) * T; return -Angle::FromXY(Location.latitude.cos() * dec.sin() - Location.latitude.sin() * dec.cos() * t.cos(), dec.cos() * t.sin()); }
bool IGCParseTime(const char *buffer, BrokenTime &time) { unsigned hour, minute, second; if (sscanf(buffer, "%02u%02u%02u", &hour, &minute, &second) != 3) return false; time = BrokenTime(hour, minute, second); return time.IsPlausible(); }
void RASPSettingsPanel::UpdateTimeControl() { const DataFieldEnum &item = (const DataFieldEnum &)GetDataField(ITEM); const int item_index = item.GetValue(); SetRowEnabled(TIME, item_index >= 0); if (item_index >= 0) { DataFieldEnum &time_df = (DataFieldEnum &)GetDataField(TIME); time_df.ClearChoices(); time_df.addEnumText(_("Now")); rasp->ForEachTime(item_index, [&time_df](BrokenTime t){ TCHAR timetext[10]; _stprintf(timetext, _T("%02u:%02u"), t.hour, t.minute); time_df.addEnumText(timetext, t.GetMinuteOfDay()); }); if (time.IsPlausible()) time_df.Set(time.GetMinuteOfDay()); GetControl(TIME).RefreshDisplay(); } }
static bool ReadTime(NMEAInputLine &line, BrokenTime &time) { char buffer[10]; line.Read(buffer, sizeof(buffer)); char *p = buffer, *endptr; time.hour = strtoul(p, &endptr, 10); if (endptr == p || *endptr != ':') return false; p = endptr + 1; time.minute = strtoul(p, &endptr, 10); if (endptr == p || *endptr != ':') return false; p = endptr + 1; time.second = strtoul(p, &endptr, 10); if (endptr == p || *endptr != 0) return false; return time.IsPlausible(); }
bool FlytecDevice::DownloadFlight(const RecordedFlightInfo &flight, Path path, OperationEnvironment &env) { port.StopRxThread(); PeriodClock status_clock; status_clock.Update(); // Request flight record char buffer[256]; sprintf(buffer, "$PBRTR,%02d", flight.internal.flytec); AppendNMEAChecksum(buffer); strcat(buffer, "\r\n"); port.Write(buffer); if (!ExpectXOff(port, env, 1000)) return false; // Open file writer FileHandle writer(path, _T("wb")); if (!writer.IsOpen()) return false; unsigned start_sec = flight.start_time.GetSecondOfDay(); unsigned end_sec = flight.end_time.GetSecondOfDay(); if (end_sec < start_sec) end_sec += 24 * 60 * 60; unsigned range = end_sec - start_sec; env.SetProgressRange(range); while (true) { // Check if the user cancelled the operation if (env.IsCancelled()) return false; // Receive the next line if (!ReceiveLine(port, buffer, ARRAY_SIZE(buffer), 1000)) return false; // XON was received if (StringIsEmpty(buffer)) break; if (status_clock.CheckUpdate(250) && *buffer == 'B') { // Parse the fix time BrokenTime time; if (IGCParseTime(buffer + 1, time)) { unsigned time_sec = time.GetSecondOfDay(); if (time_sec < start_sec) time_sec += 24 * 60 * 60; if (time_sec > end_sec + 5 * 60) time_sec = start_sec; unsigned position = time_sec - start_sec; if (position > range) position = range; env.SetProgressPosition(position); } } // Write line to the file writer.Write(buffer); } return true; }
bool IsDefined() const { return time.IsPlausible(); }