示例#1
0
        // creates a new empty hub
        public VintHub CreateNewHub()
        {
            PhidgetSensor[] sensors =
            {
                CreateSensor("None", 0, "New Hub", true),
                CreateSensor("None", 1, "New Hub", true),
                CreateSensor("None", 2, "New Hub", true),
                CreateSensor("None", 3, "New Hub", true),
                CreateSensor("None", 4, "New Hub", true),
                CreateSensor("None", 5, "New Hub", true)
            };

            VintHub ret = new VintHub(sensors, true, "New Hub");

            return(ret);
        }
示例#2
0
        public void CreateNewVintHub()
        {
            VintHub vintHub = _data.CreateNewHub();

            UnsavedVintHubs.Add(vintHub);
        }
示例#3
0
        void LoadConfiguration()
        {
            _data = new DataAccessor();

            if (_data.LoadConfiguration() == "good")
            {
                // load general config values
                RecipientEmailAddress      = _data.RecipientEmailAddress;
                SenderEmailAddress         = _data.SenderEmailAddress;
                SenderEmailPassword        = _data.SenderEmailPassword;
                SenderEmailSmtpAddress     = _data.SenderEmailSmtpAddress;
                SenderEmailSmtpPort        = _data.SenderEmailSmtpPort.ToString();
                DataCollectionIntervalTime = _data.DataCollectionIntervalTime.ToString();
                GpsEnabled         = _data.GpsEnabled;
                MinSoilTemperature = _data.MinSoilTemperature;
                MaxSoilTemperature = _data.MaxSoilTemperature;
                MinAirTemperature  = _data.MinAirTemperature;
                MaxAirTemperature  = _data.MaxAirTemperature;
                MinHumidity        = _data.MinHumidity;
                MaxHumidity        = _data.MaxHumidity;
                MinMoisture        = _data.MinMoisture;
                MaxMoisture        = _data.MaxMoisture;
                MinOxygen          = _data.MinOxygen;
                MaxOxygen          = _data.MaxOxygen;
                MinVOC             = _data.MinVOC;
                MaxVOC             = _data.MaxVOC;
                MinCO2             = _data.MinCO2;
                MaxCO2             = _data.MaxCO2;

                // load saved vint hubs
                SavedVintHubs   = _data.VintHubs;
                UnsavedVintHubs = SavedVintHubs;

                SelectedConfigHub = _unsavedVintHubs[0];
                HubPort0          = SelectedConfigHub.Sensor0.SensorType;
                HubPort1          = SelectedConfigHub.Sensor1.SensorType;
                HubPort2          = SelectedConfigHub.Sensor2.SensorType;
                HubPort3          = SelectedConfigHub.Sensor3.SensorType;
                HubPort4          = SelectedConfigHub.Sensor4.SensorType;
                HubPort5          = SelectedConfigHub.Sensor5.SensorType;

                // Instantiates the data collection timer, sets the timer interval
                _dataCollectionTimer          = new System.Timers.Timer();
                _dataCollectionTimer.Interval = Convert.ToInt32(DataCollectionIntervalTime);
                _dataCollectionTimer.Elapsed += Tmr_Elapsed;

                // Build GPS and VOC Sensors
                if (GpsEnabled)
                {
                    _gps = new MyGpsSensor(-1, "GPS", 5000);
                    _gps.thresholdBroken += SendEmailAlert;
                    // _gps.checkReplies += RetrieveEmailReply;
                }

                AQS = new AirQualitySensor(_minVOC, _maxVOC, _minCO2, _minCO2);
                AQS.thresholdBroken += SendEmailAlert;
                // AQS.checkReplies += RetrieveEmailReply;
            }
            else
            {
                // make sure database is built
                _data.BuildDataStores();

                // create new hub and add it to unsaved vint hubs
                UnsavedVintHubs = new ItemsChangeObservableCollection <VintHub>();
                VintHub newHub = _data.CreateNewHub();
                UnsavedVintHubs.Add(newHub);
                SelectedConfigHub = newHub;

                // set hubports to default
                HubPort0 = _sensorTypes[5];
                HubPort1 = _sensorTypes[5];
                HubPort2 = _sensorTypes[5];
                HubPort3 = _sensorTypes[5];
                HubPort4 = _sensorTypes[5];
                HubPort5 = _sensorTypes[5];

                MessageBox.Show(_mainWindow, "No valid configuration profile was detected. Default values will be displayed in this form", "No Configuration Found", MessageBox.MessageBoxButtons.YesNoCancel);
            }
        }
示例#4
0
        // loads configuration from database
        public string LoadConfiguration()
        {
            string result = "";
            string getGeneralConfigQuery = $@"select * from GeneralConfig";
            string getVintConfig         = "select * from VintHubConfig";
            string getExtensionConfig    = "select * from ExtensionHubConfig";

            if (CheckForConfig())
            {
                try
                {
                    _tradDBConn.Open();

                    // Loads General Configuration Values
                    using (SQLiteCommand cmd = new SQLiteCommand(getGeneralConfigQuery, _tradDBConn))
                    {
                        using (SQLiteDataReader reader = cmd.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                if (reader[0].GetType().ToString() != "System.DBNull")
                                {
                                    RecipientEmailAddress = reader.GetString(0);
                                }

                                if (reader[1].GetType().ToString() != "System.DBNull")
                                {
                                    SenderEmailAddress = reader.GetString(1);
                                }

                                if (reader[2].GetType().ToString() != "System.DBNull")
                                {
                                    SenderEmailPassword = reader.GetString(2);
                                }

                                if (reader[3].GetType().ToString() != "System.DBNull")
                                {
                                    SenderEmailSmtpAddress = reader.GetString(3);
                                }

                                if (reader[4].GetType().ToString() != "System.DBNull")
                                {
                                    SenderEmailSmtpPort = reader.GetInt32(4);
                                }

                                if (reader[5].GetType().ToString() != "System.DBNull")
                                {
                                    DataCollectionIntervalTime = reader.GetInt32(5);
                                }

                                if (reader[6].GetType().ToString() != "System.DBNull")
                                {
                                    MinSoilTemperature = reader.GetDouble(6);
                                }

                                if (reader[7].GetType().ToString() != "System.DBNull")
                                {
                                    MinAirTemperature = reader.GetDouble(7);
                                }

                                if (reader[8].GetType().ToString() != "System.DBNull")
                                {
                                    MinHumidity = reader.GetDouble(8);
                                }

                                if (reader[9].GetType().ToString() != "System.DBNull")
                                {
                                    MinMoisture = reader.GetDouble(9);
                                }

                                if (reader[10].GetType().ToString() != "System.DBNull")
                                {
                                    MinOxygen = reader.GetDouble(10);
                                }

                                if (reader[11].GetType().ToString() != "System.DBNull")
                                {
                                    MinCO2 = reader.GetDouble(11);
                                }

                                if (reader[12].GetType().ToString() != "System.DBNull")
                                {
                                    MinVOC = reader.GetDouble(12);
                                }

                                if (reader[13].GetType().ToString() != "System.DBNull")
                                {
                                    MaxSoilTemperature = reader.GetDouble(13);
                                }

                                if (reader[14].GetType().ToString() != "System.DBNull")
                                {
                                    MaxAirTemperature = reader.GetDouble(14);
                                }

                                if (reader[15].GetType().ToString() != "System.DBNull")
                                {
                                    MaxHumidity = reader.GetDouble(15);
                                }

                                if (reader[16].GetType().ToString() != "System.DBNull")
                                {
                                    MaxMoisture = reader.GetDouble(16);
                                }

                                if (reader[17].GetType().ToString() != "System.DBNull")
                                {
                                    MaxOxygen = reader.GetDouble(17);
                                }

                                if (reader[18].GetType().ToString() != "System.DBNull")
                                {
                                    MaxVOC = reader.GetDouble(18);
                                }

                                if (reader[19].GetType().ToString() != "System.DBNull")
                                {
                                    MaxCO2 = reader.GetDouble(19);
                                }

                                if (reader[20].GetType().ToString() != "System.DBNull")
                                {
                                    GpsEnabled = reader.GetBoolean(20);
                                }
                            }
                        }
                    }
                    VintHubs = new ItemsChangeObservableCollection <VintHub>();

                    // loads all sets of saved VINT hub configs,
                    using (SQLiteCommand cmd = new SQLiteCommand(getVintConfig, _tradDBConn))
                    {
                        using (SQLiteDataReader reader = cmd.ExecuteReader())
                        {
                            if (!reader.HasRows)
                            {
                                VintHubs.Add(CreateNewHub());
                            }
                            else
                            {
                                while (reader.Read())
                                {
                                    string hubName = reader.GetString(0);

                                    PhidgetSensor[] sensors = new PhidgetSensor[6];
                                    for (int i = 0; i < 6; i++)
                                    {
                                        PhidgetSensor sensor = CreateSensor(reader.GetString(i + 1), i, hubName, reader.GetBoolean(7));
                                        sensors[i] = sensor;
                                    }

                                    VintHub newVint = new VintHub(sensors, reader.GetBoolean(7), hubName);
                                    VintHubs.Add(newVint);
                                }
                            }
                        }
                    }
                    _tradDBConn.Close();

                    result = "good";
                }
                catch (Exception ex)
                {
                    result = ex.Message;
                    _tradDBConn.Close();
                    throw;
                }
            }
            return(result);
        }