Exemplo n.º 1
0
        static void ReplMain(string[] cmd, ref QhyCcd camera, ref Mount mount)
        {
            switch (cmd[0])
            {
            case "camera":
                if (cmd.Length == 1)
                {
                    var numCameras = QhyCcd.NumCameras();
                    if (numCameras == 0)
                    {
                        Console.WriteLine("No QHY cameras found");
                    }
                    else if (numCameras == 1)
                    {
                        camera = new QhyCcd(false, 0);
                        Console.WriteLine("One QHY camera found, automatically connected");
                    }
                    else
                    {
                        Console.WriteLine($"Num cameras: {numCameras}");
                        for (var i = 0; i < numCameras; i++)
                        {
                            var name = QhyCcd.CameraName(i);
                            Console.WriteLine($"{i} = {name}");
                        }
                    }
                }
                else if (cmd.Length == 2 && int.TryParse(cmd[1], out var index))
                {
                    camera = new QhyCcd(false, index);
                }
                else
                {
                    goto default;
                }
                break;

            case "mount":
                if (cmd.Length == 1)
                {
                    mount = Mount.Create();
                    if (mount == null)
                    {
                        var ports = Mount.Ports();
                        if (ports.Length == 0)
                        {
                            Console.WriteLine("No serial ports");
                        }
                        else
                        {
                            Console.WriteLine("More than one serial ports:");
                            Console.WriteLine(string.Join(", ", ports));
                        }
                    }
                    else
                    {
                        Console.WriteLine("One serial port, automatically connected to mount");
                    }
                }
                else if (cmd.Length == 2)
                {
                    mount = new Mount(cmd[1]);
                }
                else
                {
                    goto default;
                }
                break;

            case "solve":
                if (cmd.Length == 2)
                {
                    //var task = PlateSolve.SolveFile(cmd[1]);
                    Console.WriteLine("TODO");
                }
                else
                {
                    goto default;
                }
                break;

            default:
                Console.WriteLine($"Unknown command {string.Join(" ", cmd)}");
                break;
            }
        }
Exemplo n.º 2
0
        private static async Task ReplMount(string[] cmd, Mount mount)
        {
            switch (cmd[0])
            {
            case "help":
                Console.WriteLine("slew [ra] [dec] - slew to direction");
                Console.WriteLine("slewra [ra] - slow goto");
                Console.WriteLine("slewdec [dec] - slow goto");
                Console.WriteLine("cancel - cancel slew");
                Console.WriteLine("pos - get current direction");
                Console.WriteLine("setpos - overwrite current direction");
                Console.WriteLine("syncpos - sync/calibrate current direction");
                Console.WriteLine("azalt - get current az/alt");
                Console.WriteLine("azalt [az] [alt] - slew to az/alt");
                Console.WriteLine("track - get tracking mode");
                Console.WriteLine("track [value] - set tracking mode");
                Console.WriteLine("location - get lat/lon");
                Console.WriteLine("location [lat] [lon] - set lat/lon");
                Console.WriteLine("time - get mount's time");
                Console.WriteLine("time now - set mount's time to now");
                Console.WriteLine("aligned - get true/false if mount is aligned");
                Console.WriteLine("ping - ping mount, prints time it took");
                Console.WriteLine("solve [filename] - plate-solve image with ANSVR");
                break;

            case "slew":
            {
                cmd[1] = cmd[1].TrimEnd(',');
                if (cmd.Length == 3 && Dms.TryParse(cmd[1], out var ra) && Dms.TryParse(cmd[2], out var dec))
                {
                    await mount.Slew(ra, dec);
                }
                else
                {
                    goto default;
                }
            }
            break;

            case "slewra":
            {
                if (cmd.Length == 2 && Dms.TryParse(cmd[1], out var ra))
                {
                    await mount.SlowGotoRA(ra);
                }
                else
                {
                    goto default;
                }
            }
            break;

            case "slewdec":
            {
                if (cmd.Length == 2 && Dms.TryParse(cmd[1], out var ra))
                {
                    await mount.SlowGotoDec(ra);
                }
                else
                {
                    goto default;
                }
            }
            break;

            case "cancel":
                await mount.CancelSlew();

                break;

            case "pos":
            {
                var(ra, dec) = await mount.GetRaDec();

                Console.WriteLine($"{ra.ToDmsString(Dms.Unit.Hours)}, {dec.ToDmsString(Dms.Unit.Degrees)}");
            }
            break;

            case "setpos":
            {
                cmd[1] = cmd[1].TrimEnd(',');
                if (cmd.Length == 3 && Dms.TryParse(cmd[1], out var ra) && Dms.TryParse(cmd[2], out var dec))
                {
                    await mount.ResetRA(ra);

                    await mount.ResetDec(dec);
                }
                else
                {
                    goto default;
                }
            }
            break;

            case "syncpos":
            {
                cmd[1] = cmd[1].TrimEnd(',');
                if (cmd.Length == 3 && Dms.TryParse(cmd[1], out var ra) && Dms.TryParse(cmd[2], out var dec))
                {
                    await mount.OverwriteRaDec(ra, dec);
                }
                else
                {
                    goto default;
                }
            }
            break;

            case "azalt":
                if (cmd.Length == 1)
                {
                    var(az, alt) = await mount.GetAzAlt();

                    Console.WriteLine($"{az.ToDmsString(Dms.Unit.Degrees)}, {alt.ToDmsString(Dms.Unit.Degrees)}");
                }
                else if (cmd.Length == 3 && Dms.TryParse(cmd[1], out var az) && Dms.TryParse(cmd[2], out var alt))
                {
                    await mount.SlewAzAlt(az, alt);
                }
                else
                {
                    goto default;
                }
                break;

            case "track":
                if (cmd.Length == 1)
                {
                    var track = await mount.GetTrackingMode();

                    Console.WriteLine($"Mode: {track}");
                    Console.WriteLine($"(available: {string.Join(", ", (Mount.TrackingMode[])Enum.GetValues(typeof(Mount.TrackingMode)))})");
                }
                else if (cmd.Length == 2 && Enum.TryParse <Mount.TrackingMode>(cmd[1], out var mode))
                {
                    await mount.SetTrackingMode(mode);
                }
                else
                {
                    goto default;
                }
                break;

            case "location":
                if (cmd.Length == 1)
                {
                    var(lat, lon) = await mount.GetLocation();

                    Console.WriteLine($"{lat.ToDmsString(Dms.Unit.Degrees)}, {lon.ToDmsString(Dms.Unit.Degrees)}");
                }
                else if (cmd.Length == 3 && Dms.TryParse(cmd[1], out var lat) && Dms.TryParse(cmd[2], out var lon))
                {
                    await mount.SetLocation(lat, lon);
                }
                else
                {
                    goto default;
                }
                break;

            case "time":
                if (cmd.Length == 1)
                {
                    var now_one = DateTime.Now;
                    var time    = await mount.GetTime();

                    Console.WriteLine($"Mount time: {time} (off by {now_one - time})");
                }
                else if (cmd.Length == 2 && cmd[1] == "now")
                {
                    await mount.SetTime(DateTime.Now);
                }
                else
                {
                    goto default;
                }
                break;

            case "aligned":
            {
                var aligned = await mount.IsAligned();

                Console.WriteLine($"IsAligned: {aligned}");
            }
            break;

            case "ping":
            {
                var timer = Stopwatch.StartNew();
                var res   = await mount.Echo('p');

                Console.WriteLine($"{timer.ElapsedMilliseconds}ms");
            }
            break;

            case "solve":
                if (cmd.Length == 2)
                {
                    var task = PlateSolve.SolveFile(cmd[1]);
                }
                else
                {
                    goto default;
                }
                break;

            default:
                Console.WriteLine($"Unknown command {string.Join(" ", cmd)}");
                break;
            }
        }