private void settingsToolStripMenuItem_Click(object sender, EventArgs e) { string startingIP = settings.eth32Address; this.Stop(); mainTimer.Stop(); updateThread.Abort(); Config cfgDialog = new Config(dev, this.settings); if (cfgDialog.ShowDialog() == DialogResult.OK) { string configFile = Application.StartupPath + "\\dishConfig.xml"; configFileHandler.writeConfig(configFile, cfgDialog.settings); RollingLogger.setupRollingLogger(settings.positionFileLog, settings.maxPosLogSizeBytes, settings.maxPosLogFiles); MessageBox.Show("Saved"); appConfigured = true; } if (appConfigured) { string resultString = Regex.Match(settings.outputPort, @"\d+").Value; Int32.TryParse(resultString, out outputPortNum); azEncoder = new Encoder(this.dev, this.settings, true); elEncoder = new Encoder(this.dev, this.settings, false); Connect(startingIP.Equals(settings.eth32Address)); } }
public MainForm(Eth32 dev) { //set up UI control attributes (auto-generated) InitializeComponent(); this.dev = dev; //setup for jog button handler thread, triggering event jogEvent = new ManualResetEvent(false); this.buttonThread = new Thread(buttonThreadHandler); this.buttonThread.Start(); //try to read config file - open config dialog if not found string configFile = Application.StartupPath + "\\dishConfig.xml"; if (File.Exists(configFile)) { settings = configFileHandler.readConfig(configFile); appConfigured = true; }//if config exists else { settings = new configModel(); Config cfgDialog = new Config(dev, this.settings); if (cfgDialog.ShowDialog() == DialogResult.OK) { configFileHandler.writeConfig(configFile, cfgDialog.settings); MessageBox.Show("Saved"); appConfigured = true; } }//no config found state = DishState.Unknown; //set up presets, set up various Motion control objects, logger but only if config exists and is valid. if (appConfigured) { //get presets array Presets = settings.getPresetList(); foreach (presets p in Presets) { if (!String.IsNullOrEmpty(p.Text)) { presetSelector.Items.Add(p.Text); } } presetSelector.SelectedIndex = 0; RollingLogger.setupRollingLogger(settings.positionFileLog, settings.maxPosLogSizeBytes, settings.maxPosLogFiles); }//if config exists }
//update position display private void updatePosition() { if ((DateTime.Now - messageTime).TotalSeconds > 30) { Message.Text = ""; } //read actual form encoders //if (dev.Connected && state == DishState.Stopped) //{ // azPos = azReadPosition(); // elPos = elReadPosition(); //} //set up display variables in deg, min, sec format GeoAngle AzAngle = GeoAngle.FromDouble(azPos, true); GeoAngle ElAngle = GeoAngle.FromDouble(elPos); //convert to RA/DEC RaDec astro = celestialConversion.CalcualteRaDec(elPos, azPos, settings.latitude, settings.longitude); //set up RA DEC as deg,min,sec GeoAngle Dec = GeoAngle.FromDouble(astro.Dec); GeoAngle RA = GeoAngle.FromDouble(astro.RA, true); //log position every tenth time through string posLog = string.Format("RA {0:D3} : {1:D2}\t DEC {2:D3} : {3:D2}", RA.Degrees, RA.Minutes, Dec.Degrees, Dec.Minutes); currentIncrement++; if (currentIncrement % 9 == 0) { RollingLogger.LogMessage(posLog); currentIncrement = 0; } //show AZ, EL on main form this.Azimuth.Text = string.Format("{0:D3} : {1:D2}", AzAngle.Degrees, AzAngle.Minutes); this.Elevation.Text = string.Format("{0:D2} : {1:D2}", ElAngle.Degrees, ElAngle.Minutes); //show RA,DEC on main form this.RA.Text = string.Format("{0:D3} : {1:D2}", RA.Degrees, RA.Minutes); this.DEC.Text = string.Format("{0:D2} : {1:D2}", Dec.Degrees, Dec.Minutes); //if celestial track is set, check to make sure command position is above horizon if so then enable motion //probably have to have a completely seperate velocity track loop here - PID loop may not be satisfactor //-----NEEDS TESTING if (trackCelestial) { AltAz aa = celestialConversion.CalculateAltAz(RAcommand, decCommand, settings.latitude, settings.longitude); if (aa.Alt < 0) { Message.Text = "Requested position is below horizon!"; trackMoon = false; messageTime = DateTime.Now; trackCelestial = false; } GeoAngle cAzAngle = GeoAngle.FromDouble(aa.Az, true); GeoAngle cElAngle = GeoAngle.FromDouble(aa.Alt); azCommand = aa.Az; elCommand = aa.Alt; this.commandAz.Text = string.Format("{0:D3} : {1:D2}", cAzAngle.Degrees, cAzAngle.Minutes); this.commandEl.Text = string.Format("{0:D2} : {1:D2}", cElAngle.Degrees, cElAngle.Minutes); if (state != DishState.Moving && state != DishState.Tracking && aa.Alt > 1.0) { this.Go(); } } //if Lunar track is set, check to make sure Moon position is above horizon if so then enable motion //probably have to have a completely seperate velocity track loop here - PID loop may not be satisfactor //-----NEEDS TESTING if (trackMoon) { SunCalc sc = new SunCalc(); long eDate = sc.epochDate(DateTime.UtcNow); double jdate = sc.toJulian(eDate); AltAz aa = sc.getMoonPosition(eDate, settings.latitude, settings.longitude); if (aa.Alt < 0) { Message.Text = "Moon is below horizon!"; trackMoon = false; messageTime = DateTime.Now; } moonRiseSet mrs = sc.getMoonTimes(eDate, settings.latitude, settings.longitude, true); azCommand = aa.Az; elCommand = aa.Alt; GeoAngle mAzAngle = GeoAngle.FromDouble(aa.Az, true); GeoAngle mElAngle = GeoAngle.FromDouble(aa.Alt); this.commandAz.Text = string.Format("{0} : {1}", mAzAngle.Degrees, mAzAngle.Minutes); this.commandEl.Text = string.Format("{2}{0} : {1}", mElAngle.Degrees, mElAngle.Minutes, mElAngle.IsNegative ? "-" : ""); double Alt = elCommand; if (Alt > 90.0) { Alt = Alt - 90.0; } RaDec mastro = celestialConversion.CalcualteRaDec(Alt, azCommand, settings.latitude, settings.longitude); GeoAngle mDec = GeoAngle.FromDouble(mastro.Dec); GeoAngle mRA = GeoAngle.FromDouble(mastro.RA, true); this.commandRA.Text = string.Format("{0:D3} : {1:D2}", mRA.Degrees, mRA.Minutes); this.commandDec.Text = string.Format("{0:D2} : {1:D2}", mDec.Degrees, mDec.Minutes); if (state != DishState.Moving && state != DishState.Tracking && aa.Alt > 1.0) { this.Go(); } }//trackMoon //send stop command if we have to here if (state != DishState.Stopped && state != DishState.Unknown) { if (azPid.Complete && elPid.Complete) { this.Stop(); } } }