コード例 #1
0
        public static bool TryParse(string coordinates, out DMS value)
        {
            value = new DMS(-1000m);
            decimal val;

            //Regex r = new Regex(@"(\d+)[°\s]+(\d+)['\s]+(\d+)[\.\,]?(\d*)['\s]*");
            //var m = r.Match(coordinates);
            var c = coordinates.Split(new[] { ' ', '°', '\'', '.', ',', '"' });

            try
            {
                //if (m.Success)
                //{
                //    value.D = int.Parse(m.Groups[1].Value);
                //    value.M = int.Parse(m.Groups[2].Value);
                //    var dig = m.Groups[4].Length > 0 ? decimal.Parse("0" + Telescope.decimalSeparator + m.Groups[4].Value) : 0;
                //    value.S = int.Parse(m.Groups[3].Value) + dig;
                if (c.Length > 2)
                {
                    value.D = int.Parse(c[0]);
                    value.M = int.Parse(c[1]);
                    var dig = c.Length > 3 ? decimal.Parse("0" + decimalSeparator + c[3]) : 0;
                    value.S = int.Parse(c[2]) + dig;

                    return(true);
                }
            }
            catch
            {
                return(false);
            }
            if (decimal.TryParse(coordinates, out val))
            {
                value.Deg = val;
                return(true);
            }
            return(false);
        }
コード例 #2
0
        public static bool TryParse(string coordinates, out DMS value)
        {
            value = new DMS(-1000m);
            decimal val;

            //Regex r = new Regex(@"(\d+)[°\s]+(\d+)['\s]+(\d+)[\.\,]?(\d*)['\s]*");
            //var m = r.Match(coordinates);
            var c = coordinates.Split(new[] { ' ', '°', '\'', '.', ',', '"' });

            try
            {
                //if (m.Success)
                //{
                //    value.D = int.Parse(m.Groups[1].Value);
                //    value.M = int.Parse(m.Groups[2].Value);
                //    var dig = m.Groups[4].Length > 0 ? decimal.Parse("0" + Telescope.decimalSeparator + m.Groups[4].Value) : 0;
                //    value.S = int.Parse(m.Groups[3].Value) + dig;
                if (c.Length > 2)
                {
                    value.D = int.Parse(c[0]);
                    value.M = int.Parse(c[1]);
                    var dig = c.Length > 3 ? decimal.Parse("0" + decimalSeparator + c[3]) : 0;
                    value.S = int.Parse(c[2]) + dig;

                    return true;
                }
            }
            catch
            {
                return false;
            }
            if (decimal.TryParse(coordinates, out val))
            {
                value.Deg = val;
                return true;
            }
            return false;
        }
        public byte[] exchange(byte[] input)
        {
            var ans = new List<byte>();
            if(input == null || !input.Any()) throw new Exception("Empty transfer");

            var t = input[0];
            switch (t)
            {
                case (byte)'V':
                    return this.makeVersion();
                case (byte)'Z':
                    return "12AB,4000#".ToBytes();
                case (byte)'z':
                    return "12AB0500,40000500#".ToBytes();
                case (byte)'E':
                    return "34AB,12CE#".ToBytes();
                case (byte)'e':
                    return "34AB0500,12CE0500#".ToBytes();
                case (byte)'S': //Sync
                case (byte)'s':
                case (byte)'B': //Slew AltAzm
                case (byte)'b':
                case (byte)'R': //Slew RaDec
                case (byte)'r':
                    return "#".ToBytes();
                case (byte)'t':
                    return new byte[]{(byte)_tracking, (byte)(char)GeneralCommands.TERMINATOR};
                case (byte)'T':
                    _tracking = (TrackingMode)input[1];
                    return new byte[] { (byte)(char)GeneralCommands.TERMINATOR };
                case (byte)'P':
                    return this.SendCommand(input[1], (DeviceID)input[2], (DeviceCommands)input[3], input.Skip(4).ToArray());
                case (byte)'w':
                    {
                        var lat = Location.Lat.ToDMS();
                        var lon = Location.Lon.ToDMS();

                        return new byte[]
                                   {
                                       (byte)lat.D, (byte)lat.M, (byte)lat.S, (byte)(lat.Sign > 0 ? 0 : 1), (byte)lon.D,
                                       (byte)lon.M, (byte)lon.S, (byte)(lon.Sign > 0 ? 0 : 1), (byte)(char)GeneralCommands.TERMINATOR
                                   };
                    }
                case (byte)'W':
                    {
                        var lat = new DMS(input[1], input[2], input[3], input[4] > 0 ? -1 : 1);
                        var lon = new DMS(input[5], input[6], input[7], input[8] > 0 ? -1 : 1);
                        Location = new LatLon(lat.Deg, lon.Deg);
                        return "#".ToBytes();
                    }
                case (byte)'h':
                    {
                        var tm = DateTime.Now;
                        var tz = (int)(TimeZone.CurrentTimeZone.GetUtcOffset(tm).TotalHours + 0.5);
                        var dlst = TimeZone.CurrentTimeZone.IsDaylightSavingTime(DateTime.Now) ? 1 : 0;
                        return new byte[]
                                   {
                                       (byte)tm.Hour, (byte)tm.Minute, (byte)tm.Second, (byte)tm.Month, (byte)tm.Day,
                                       (byte)(tm.Year - 2000), (byte)tz, (byte)dlst, (byte)(char)GeneralCommands.TERMINATOR
                                   };
                    }
                case (byte)'H':
                    return "#".ToBytes();
                default:
                    return "#".ToBytes();
            }

            ans.Add((byte)(char)GeneralCommands.TERMINATOR);
            return ans.ToArray();
        }