예제 #1
0
        private void buttonApply_Click(object sender, EventArgs e)
        {
            IPAddress ipAddress;

            if (!CheckComponentIPAddress(out ipAddress))
            {
                this.DialogResult = DialogResult.None; return;
            }

            Telescope.starbook.IPAddress = ipAddress;

            bool setLocation = false, setDateTime = false, setGuideRate = false;

            Telescope.Starbook.Place place = this.place;
            DateTime dateTime              = this.dateTime;
            int      guideRate             = Telescope.guideRate;

            double[] guideRates = new double[9];
            Array.Copy(Telescope.guideRates, guideRates, 9);

            if (checkBoxSetLocation.Enabled && checkBoxSetLocation.Checked)
            {
                if (!CheckComponentLocation(ref place))
                {
                    this.DialogResult = DialogResult.None; return;
                }

                setLocation = true;
            }

            if (checkBoxSetDateTime.Enabled && checkBoxSetDateTime.Checked)
            {
                if (!CheckComponentDateTime(ref place, ref dateTime))
                {
                    this.DialogResult = DialogResult.None; return;
                }

                setDateTime = true;
            }

            if (checkBoxSetGuideRate.Enabled && checkBoxSetGuideRate.Checked)
            {
                guideRate = comboBoxGuideRate.SelectedIndex;

                if (!CheckComponentGuideRate(textBoxGuideRate1, 1, out guideRates[1]))
                {
                    this.DialogResult = DialogResult.None; return;
                }
                if (!CheckComponentGuideRate(textBoxGuideRate2, 2, out guideRates[2]))
                {
                    this.DialogResult = DialogResult.None; return;
                }
                if (!CheckComponentGuideRate(textBoxGuideRate3, 3, out guideRates[3]))
                {
                    this.DialogResult = DialogResult.None; return;
                }
                if (!CheckComponentGuideRate(textBoxGuideRate4, 4, out guideRates[4]))
                {
                    this.DialogResult = DialogResult.None; return;
                }
                if (!CheckComponentGuideRate(textBoxGuideRate5, 5, out guideRates[5]))
                {
                    this.DialogResult = DialogResult.None; return;
                }
                if (!CheckComponentGuideRate(textBoxGuideRate6, 6, out guideRates[6]))
                {
                    this.DialogResult = DialogResult.None; return;
                }
                if (!CheckComponentGuideRate(textBoxGuideRate7, 7, out guideRates[7]))
                {
                    this.DialogResult = DialogResult.None; return;
                }
                if (!CheckComponentGuideRate(textBoxGuideRate8, 8, out guideRates[8]))
                {
                    this.DialogResult = DialogResult.None; return;
                }

                setGuideRate = true;
            }

            if (setLocation || setDateTime)
            {
                Telescope.Starbook.Response response = Telescope.starbook.SetPlace(place);
                Telescope.LogMessage("SetupDialogForm", "Apply: Starbook.SetPlace({0},{1},{2})={3}", place.Latitude, place.Longitude, place.Timezone, response);

                if (response == Telescope.Starbook.Response.OK)
                {
                    this.place = place;
                }
                else
                {
                    MessageBox.Show(this, string.Format(CultureInfo.InvariantCulture, "Cannot set location: {0}", response), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            if (setDateTime)
            {
                Telescope.Starbook.Response response = Telescope.starbook.SetTime(dateTime);
                Telescope.LogMessage("SetupDialogForm", "Apply: Starbook.SetTime({0:yyyy/MM/dd HH:mm:ss})={1}", dateTime, response);

                if (response == Telescope.Starbook.Response.OK)
                {
                    this.dateTime = dateTime;
                }
                else
                {
                    MessageBox.Show(this, string.Format(CultureInfo.InvariantCulture, "Cannot set date & time: {0}", response), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            if (setGuideRate)
            {
                Telescope.guideRate = guideRate;
                Array.Copy(guideRates, Telescope.guideRates, 9);
            }

            if (setLocation || setDateTime || setGuideRate)
            {
                Telescope.Starbook.Response response = Telescope.starbook.Save();
                Telescope.LogMessage("SetupDialogForm", "Apply: Starbook.Save()={0}", response);

                if (response != Telescope.Starbook.Response.OK)
                {
                    MessageBox.Show(this, string.Format(CultureInfo.InvariantCulture, "Cannot save setting: {0}", response), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            Telescope.j2000               = checkBoxJ2000.Checked;
            Telescope.autoMeridianFlip    = checkBoxAutoMeridianFlip.Checked ? 60 : 0;
            Telescope.traceLogger.Enabled = checkBoxTraceLogger.Checked;

            buttonApply.Enabled = false;
        }
예제 #2
0
        private void buttonCheck_Click(object sender, EventArgs e)
        {
            if (!CheckComponentIPAddress(out IPAddress ipAddressCheck))
            {
                this.DialogResult = DialogResult.None; return;
            }

            IPAddress ipAddress = Telescope.starbook.IPAddress; Telescope.starbook.IPAddress = ipAddressCheck;

            Telescope.Starbook.Response response = Telescope.starbook.GetStatus(out Telescope.Starbook.Status status);

            if (response == Telescope.Starbook.Response.OK)
            {
                Telescope.LogMessage("SetupDialogForm", "Check: Starbook.GetStatus()={0} / RA={1}, Dec={2}, State={3}, Goto={4}", response, status.RA, status.Dec, status.State, status.Goto);
            }
            else
            {
                Telescope.LogMessage("SetupDialogForm", "Check: Starbook.GetStatus()={0}", response); status = new Telescope.Starbook.Status();
            }

            bool connected = false, initializing = false;

            if (status.State == Telescope.Starbook.State.Unknown)
            {
                labelStatus.Text = "Disconnected";

                textBoxLatitudeDegree.Clear();
                textBoxLatitudeMinute.Clear();
                comboBoxLatitudeDirection.SelectedItem = string.Empty;

                textBoxLongitudeDegree.Clear();
                textBoxLongitudeMinute.Clear();
                comboBoxLongitudeDirection.SelectedItem = string.Empty;

                textBoxElevation.Clear();

                textBoxYear.Clear();
                textBoxMonth.Clear();
                textBoxDay.Clear();
                textBoxHour.Clear();
                textBoxMinute.Clear();
                textBoxSecond.Clear();
                comboBoxTimezone.SelectedItem = string.Empty;

                labelFirmwareVersion.Text = "Firmware Version: --";
            }
            else
            {
                labelStatus.Text = "Connected"; connected = true;

                if (status.State == Telescope.Starbook.State.Init)
                {
                    initializing = true;
                }

                response = Telescope.starbook.GetPlace(out Telescope.Starbook.Place place);

                if (response == Telescope.Starbook.Response.OK)
                {
                    Telescope.LogMessage("SetupDialogForm", "Check: Starbook.GetPlace()={0} / Latitude={1}, Longitude={2}, Timezone={3}", response, place.Latitude, place.Longitude, place.Timezone); this.place = place;
                }
                else
                {
                    Telescope.LogMessage("SetupDialogForm", "Check: Starbook.GetPlace()={0}", response); place = new Telescope.Starbook.Place();
                }

                response = Telescope.starbook.GetTime(out DateTime dateTime);

                if (response == Telescope.Starbook.Response.OK)
                {
                    Telescope.LogMessage("SetupDialogForm", "Check: Starbook.GetTime()={0} / Time={1:yyyy/MM/dd HH:mm:ss}", response, dateTime); this.dateTime = dateTime;
                }
                else
                {
                    Telescope.LogMessage("SetupDialogForm", "Check: Starbook.GetTime()={0}", response); dateTime = DateTime.MinValue;
                }

                textBoxLatitudeDegree.Text = place.Latitude.Degree.ToString(CultureInfo.InvariantCulture);
                textBoxLatitudeMinute.Text = place.Latitude.Minute.ToString(CultureInfo.InvariantCulture);

                if (place.Latitude.Direction == Telescope.Starbook.Direction.North)
                {
                    comboBoxLatitudeDirection.SelectedItem = "N";
                }
                else if (place.Latitude.Direction == Telescope.Starbook.Direction.South)
                {
                    comboBoxLatitudeDirection.SelectedItem = "S";
                }

                textBoxLongitudeDegree.Text = place.Longitude.Degree.ToString(CultureInfo.InvariantCulture);
                textBoxLongitudeMinute.Text = place.Longitude.Minute.ToString(CultureInfo.InvariantCulture);

                if (place.Longitude.Direction == Telescope.Starbook.Direction.East)
                {
                    comboBoxLongitudeDirection.SelectedItem = "E";
                }
                else if (place.Longitude.Direction == Telescope.Starbook.Direction.West)
                {
                    comboBoxLongitudeDirection.SelectedItem = "W";
                }

                textBoxElevation.Text = telescope.transform.SiteElevation.ToString(CultureInfo.InvariantCulture);

                textBoxYear.Text   = dateTime.Year.ToString(CultureInfo.InvariantCulture);
                textBoxMonth.Text  = dateTime.Month.ToString(CultureInfo.InvariantCulture);
                textBoxDay.Text    = dateTime.Day.ToString(CultureInfo.InvariantCulture);
                textBoxHour.Text   = dateTime.Hour.ToString(CultureInfo.InvariantCulture);
                textBoxMinute.Text = dateTime.Minute.ToString(CultureInfo.InvariantCulture);
                textBoxSecond.Text = dateTime.Second.ToString(CultureInfo.InvariantCulture);

                comboBoxTimezone.SelectedIndex = place.Timezone + 12;

                response = Telescope.starbook.GetVersion(out string version);

                if (response == Telescope.Starbook.Response.OK)
                {
                    Telescope.LogMessage("SetupDialogForm", "Check: Starbook.GetVersion()={0} / Version={1}", response, version);
                }
                else
                {
                    Telescope.LogMessage("SetupDialogForm", "Check: Starbook.GetVersion()={0}", response); version = "N/A";
                }

                labelFirmwareVersion.Text = string.Format(CultureInfo.InvariantCulture, "Firmware Version: {0}", version);
            }

            // Location & Timezone

            textBoxLatitudeDegree.ReadOnly = !checkBoxSetLocation.Checked;
            textBoxLatitudeMinute.ReadOnly = !checkBoxSetLocation.Checked;

            textBoxLatitudeDegree.Enabled     = connected && initializing;
            textBoxLatitudeMinute.Enabled     = connected && initializing;
            comboBoxLatitudeDirection.Enabled = connected && initializing && checkBoxSetLocation.Checked;

            textBoxLongitudeDegree.ReadOnly = !checkBoxSetLocation.Checked;
            textBoxLongitudeMinute.ReadOnly = !checkBoxSetLocation.Checked;

            textBoxLongitudeDegree.Enabled     = connected && initializing;
            textBoxLongitudeMinute.Enabled     = connected && initializing;
            comboBoxLongitudeDirection.Enabled = connected && initializing && checkBoxSetLocation.Checked;

            textBoxElevation.ReadOnly = !checkBoxSetLocation.Checked;
            textBoxElevation.Enabled  = connected && initializing;

            checkBoxSetLocation.Enabled = connected && initializing;

            // Date & Time

            textBoxYear.ReadOnly  = !checkBoxSetDateTime.Checked;
            textBoxMonth.ReadOnly = !checkBoxSetDateTime.Checked;
            textBoxDay.ReadOnly   = !checkBoxSetDateTime.Checked;

            textBoxHour.ReadOnly   = !checkBoxSetDateTime.Checked;
            textBoxMinute.ReadOnly = !checkBoxSetDateTime.Checked;
            textBoxSecond.ReadOnly = !checkBoxSetDateTime.Checked;

            textBoxYear.Enabled  = connected && initializing;
            textBoxMonth.Enabled = connected && initializing;
            textBoxDay.Enabled   = connected && initializing;

            textBoxHour.Enabled   = connected && initializing;
            textBoxMinute.Enabled = connected && initializing;
            textBoxSecond.Enabled = connected && initializing;

            comboBoxTimezone.Enabled = connected && initializing && checkBoxSetDateTime.Checked;

            checkBoxSetDateTime.Enabled    = connected && initializing;
            checkBoxSyncSystemTime.Enabled = connected && initializing && checkBoxSetDateTime.Checked;

            // Pulse Guide

            comboBoxGuideRate.Enabled = connected && checkBoxSetGuideRate.Checked;

            textBoxGuideRate0.ReadOnly = !checkBoxSetGuideRate.Checked || comboBoxPredefinedGuideRates.SelectedIndex != 0;
            textBoxGuideRate1.ReadOnly = !checkBoxSetGuideRate.Checked || comboBoxPredefinedGuideRates.SelectedIndex != 0;
            textBoxGuideRate2.ReadOnly = !checkBoxSetGuideRate.Checked || comboBoxPredefinedGuideRates.SelectedIndex != 0;
            textBoxGuideRate3.ReadOnly = !checkBoxSetGuideRate.Checked || comboBoxPredefinedGuideRates.SelectedIndex != 0;
            textBoxGuideRate4.ReadOnly = !checkBoxSetGuideRate.Checked || comboBoxPredefinedGuideRates.SelectedIndex != 0;
            textBoxGuideRate5.ReadOnly = !checkBoxSetGuideRate.Checked || comboBoxPredefinedGuideRates.SelectedIndex != 0;
            textBoxGuideRate6.ReadOnly = !checkBoxSetGuideRate.Checked || comboBoxPredefinedGuideRates.SelectedIndex != 0;
            textBoxGuideRate7.ReadOnly = !checkBoxSetGuideRate.Checked || comboBoxPredefinedGuideRates.SelectedIndex != 0;
            textBoxGuideRate8.ReadOnly = !checkBoxSetGuideRate.Checked || comboBoxPredefinedGuideRates.SelectedIndex != 0;

            textBoxGuideRate0.Enabled = connected;
            textBoxGuideRate1.Enabled = connected;
            textBoxGuideRate2.Enabled = connected;
            textBoxGuideRate3.Enabled = connected;
            textBoxGuideRate4.Enabled = connected;
            textBoxGuideRate5.Enabled = connected;
            textBoxGuideRate6.Enabled = connected;
            textBoxGuideRate7.Enabled = connected;
            textBoxGuideRate8.Enabled = connected;

            comboBoxPredefinedGuideRates.Enabled = connected && checkBoxSetGuideRate.Checked;

            checkBoxSetGuideRate.Enabled = connected;

            Telescope.starbook.IPAddress = ipAddress;
        }