/// <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 void HMSToDegrees(string hms, double expected) { var value = Astrometry.HMSToDegrees(hms); Assert.AreEqual(expected, value, ANGLE_TOLERANCE); }