/// <summary> /// Get the selected object in CdC /// </summary> /// <returns></returns> public async Task <DeepSkyObject> GetTarget() { try { var response = await Query("GETSELECTEDOBJECT"); if (!response.StartsWith("OK!")) { throw new PlanetariumObjectNotSelectedException(); } var columns = response.Split('\t'); // An "OK!" response with fewer than 2 columns means that CdC is listening ok but the user has not selected an object. if (columns.Count() < 2) { throw new PlanetariumObjectNotSelectedException(); } if (!Match(columns[0].Replace("OK!", ""), @"(([0-9]{1,2})([h|:]|[?]{2})([0-9]{1,2})([m|:]|[?]{2})?([0-9]{1,2}(?:\.[0-9]+){0,1})?([s|:]|[?]{2}))", out var raString)) { throw new PlanetariumObjectNotSelectedException(); } var ra = Astrometry.HMSToDegrees(raString); if (!Match(columns[1], @"([\+|-]([0-9]{1,2})([d|°|:]|[?]{2})([0-9]{1,2})([m|'|:]|[?]{2})?([0-9]{1,2}(?:\.[0-9]+){0,1})?([s|""|:]|[?]{2}))", out var decString)) { throw new PlanetariumObjectNotSelectedException(); } var dec = Astrometry.DMSToDegrees(decString); if (!Match(columns.Last(), @"(?<=Equinox:).*", out var equinox)) { throw new PlanetariumObjectNotSelectedException(); } equinox = equinox.Replace("\r", "").Replace("\n", ""); var coordinates = new Coordinates(Angle.ByDegree(ra), Angle.ByDegree(dec), equinox.ToLower() == "now" ? Epoch.JNOW : Epoch.J2000); var dso = new DeepSkyObject(columns[3].Trim(), coordinates.Transform(Epoch.J2000), string.Empty); return(dso); } catch (Exception ex) { Logger.Error(ex); throw ex; } }
public async Task <Coords> GetSite() { try { var response = await Query("GETOBS"); if (!response.StartsWith("OK!")) { throw new PlanetariumFailedToGetCoordinates(); } if (!Match(response, @"(?<=LAT:)[\+|-]([0-9]{1,2})[:|d]([0-9]{1,2})[:|m]?([0-9]{1,2}(?:\.[0-9]+){0,1})?[:|s]", out var latutideString)) { throw new PlanetariumFailedToGetCoordinates(); } if (!Match(response, @"(?<=LON:)[\+|-]([0-9]{1,3})[:|d]([0-9]{1,2})[:|m]?([0-9]{1,2}(?:\.[0-9]+){0,1})?[:|s]", out var longitudeString)) { throw new PlanetariumFailedToGetCoordinates(); } if (!Match(response, @"(?<=ALT:)([0-9]{0,5})[m]", out var altitudeString)) { throw new PlanetariumFailedToGetCoordinates(); } var coords = new Coords { Latitude = Astrometry.DMSToDegrees(latutideString), Longitude = -Astrometry.DMSToDegrees(longitudeString), Elevation = Astrometry.DMSToDegrees(altitudeString) }; return(coords); } catch (Exception ex) { Logger.Error(ex); throw ex; } }
public void DMSToDegrees(string hms, double expected) { var value = Astrometry.DMSToDegrees(hms); Assert.AreEqual(expected, value, ANGLE_TOLERANCE); }