Ejemplo n.º 1
0
        private bool CSQL_AddDeviceLogFileDescription(CDevice device, SqliteConnection hconn)
        {
            string        sql      = null;
            SqliteCommand dbhCmd   = null;
            int           num_recs = 0;

            for (int i = 0; i < device.DeviceFileDescription.Count; i++)
            {
                CDeviceFileDescription descr = (CDeviceFileDescription)device.DeviceFileDescription [i];

                sql = "INSERT INTO device_logfile_descr VALUES ('" +
                      descr.DeviceCodeType + "', '" +
                      descr.DeviceCodeDescription + "', '" +
                      descr.DeviceCode + "', " +
                      i + ", '" +
                      device.DeviceID + "');";

                dbhCmd   = new SqliteCommand(sql, hconn);
                num_recs = dbhCmd.ExecuteNonQuery();

                if (num_recs == 0)
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        public int CLogFile_Get_Y_Axis_Code_Index(CDevice device)
        {
            CDeviceFileDescription _descr = null;

            for (int i = 0; i < device.DeviceFileDescription.Count; i++)
            {
                // Find the log time and return the index.
                _descr = (CDeviceFileDescription)device.DeviceFileDescription [i];

                if (_descr.DeviceCode == "CURTEMP")
                {
                    _logTimeIndex = i;
                    return(i);
                }
            }

            return(-1);
        }
Ejemplo n.º 3
0
        public CDevice CSQL_GetDevice(string device_id)
        {
            //TODO: Finish CSQL_GetDevice implementation.

            string sql_device = "SELECT * FROM devices " +
                                "WHERE devices.device_id = '" + device_id + "';";

            string sql_device_descr = "SELECT * FROM device_logfile_descr " +
                                      "WHERE device_logfile_descr.device_id = '" + device_id + "' " +
                                      "ORDER BY device_logfile_descr.device_logfile_order;";

            CDevice   _device = null;
            ArrayList _ar_device_logfile_descr;
            CDeviceFileDescription _device_file_descr = null;
            SqliteCommand          dbhCmd             = null;
            SqliteDataReader       dbhReader          = null;

            if (CSQL_Connected())
            {
                dbhCmd    = new SqliteCommand(sql_device, dbh);
                dbhReader = dbhCmd.ExecuteReader();

                if (dbhReader.HasRows)
                {
                    dbhReader.Read();

                    _device = new CDevice(dbhReader.GetString((int)tbl_devices.DEVICE_ID),
                                          dbhReader.GetString((int)tbl_devices.DEVICE_DESCR),
                                          dbhReader.GetString((int)tbl_devices.DEVICE_LOCATION),
                                          dbhReader.GetString((int)tbl_devices.DEVICE_SERVER),
                                          dbhReader.GetString((int)tbl_devices.DEVICE_SERVER_SUBDIR));


                    //Get device log file description.
                    dbhCmd    = new SqliteCommand(sql_device_descr, dbh);
                    dbhReader = dbhCmd.ExecuteReader();

                    if (dbhReader.HasRows)
                    {
                        _ar_device_logfile_descr = new ArrayList();

                        while (dbhReader.Read())
                        {
                            _device_file_descr = new CDeviceFileDescription
                                                 (
                                dbhReader.GetString((int)tbl_device_logfile_descr.DEVICE_SENSOR_CODE),
                                dbhReader.GetString((int)tbl_device_logfile_descr.DEVICE_SENSOR_VALUE_DESCR),
                                dbhReader.GetString((int)tbl_device_logfile_descr.DEVICE_SENSOR_VALUE_TYPES)
                                                 );

                            _ar_device_logfile_descr.Add(_device_file_descr);
                        }

                        _device.DeviceFileDescription = _ar_device_logfile_descr;
                    }
                    else
                    {
                        cleanup();
                        return(_device);
                    }
                }
                else
                {
                    cleanup();
                    return(null);
                }
            }
            else
            {
                cleanup();
                return(null);
            }

            return(_device);
        }
Ejemplo n.º 4
0
    protected void OnBtnLogFileAddClicked(object sender, EventArgs e)
    {
        c_file_description_entry = new CDeviceFileDescription ("CODE", "Description...", "TYPE");
        ar_file_description.Add (c_file_description_entry);

        TreeStore store = (TreeStore)nvDeviceFileDescr.Model;
        TreeIter iter = store.AppendValues (c_file_description_entry.DeviceCode, c_file_description_entry.DeviceCodeDescription, c_file_description_entry.DeviceCodeType);
        TreePath path = store.GetPath (iter);
        nvDeviceFileDescr.SetCursor (path, nvDeviceFileDescr.Columns[0], true);
    }
Ejemplo n.º 5
0
    private void populate_log_file_columns()
    {
        /**
         * COLUMNS
         * =======
         * device_sensor_code
         * device_sensor_description
         * device_sensor_value_type <- combobox
         * device_sensor_value <- Surely NOT?
         * nvDeviceFileDesctiption
         */

        mnu_device.Popdown ();

        TreeStore ls_nvDeviceFileDescription = new TreeStore (typeof(string), typeof(string), typeof(string));
        ListStore ls_dev_sensor_codes = new ListStore (typeof(string));
        ListStore ls_dev_sensor_value_types = new ListStore (typeof(string));

        if (ar_file_description == null)
            ar_file_description = new ArrayList ();

            if (nvDeviceFileDescr.Columns.Length < 1) {
                Gtk.TreeViewColumn col_sensor_code = new Gtk.TreeViewColumn ();
                col_sensor_code.Title = "Sensor Code";
                col_sensor_code.Sizing = TreeViewColumnSizing.Autosize;

                Gtk.TreeViewColumn col_sensor_descr = new Gtk.TreeViewColumn ();
                col_sensor_descr.Title = "Sensor Descr";
                col_sensor_descr.Sizing = TreeViewColumnSizing.Autosize;

                Gtk.TreeViewColumn col_sensor_value_type = new Gtk.TreeViewColumn ();
                col_sensor_value_type.Title = "Value Type";
                col_sensor_value_type.Sizing = TreeViewColumnSizing.Autosize;

                CellRendererCombo dev_sensor_codes = new CellRendererCombo ();
                dev_sensor_codes.Editable = true;
                dev_sensor_codes.Edited += delegate(object o, EditedArgs args) {
                    int i = int.Parse (args.Path);
                    c_file_description_entry = (CDeviceFileDescription)ar_file_description [i];
                    c_file_description_entry.DeviceCode = args.NewText;

                    TreeIter iter;
                    TreeStore store = (TreeStore)nvDeviceFileDescr.Model;
                    store.GetIterFromString (out iter, args.Path);
                    store.SetValue (iter, 0, c_file_description_entry.DeviceCode);

                };

                CellRendererCombo dev_sensor_value_types = new CellRendererCombo ();
                dev_sensor_value_types.Editable = true;
                dev_sensor_value_types.Edited += delegate(object o, EditedArgs args) {
                    int i = int.Parse (args.Path);
                    c_file_description_entry = (CDeviceFileDescription)ar_file_description [i];
                    c_file_description_entry.DeviceCodeType = args.NewText;

                    TreeIter iter;
                    TreeStore store = (TreeStore)nvDeviceFileDescr.Model;
                    store.GetIterFromString (out iter, args.Path);
                    store.SetValue (iter, 2, c_file_description_entry.DeviceCodeType);
                };

                CellRendererText dev_sensor_descr = new CellRendererText ();
                dev_sensor_descr.Editable = true;
                dev_sensor_descr.Edited += delegate(object o, EditedArgs args) {
                    int i = int.Parse (args.Path);
                    c_file_description_entry = (CDeviceFileDescription)ar_file_description [i];
                    c_file_description_entry.DeviceCodeDescription = args.NewText;

                    TreeIter iter;
                    TreeStore store = (TreeStore)nvDeviceFileDescr.Model;
                    store.GetIterFromString (out iter, args.Path);
                    store.SetValue (iter, 1, c_file_description_entry.DeviceCodeDescription);
                };

                dev_sensor_codes.Model = ls_dev_sensor_codes;
                dev_sensor_codes.TextColumn = 0;

                dev_sensor_value_types.Model = ls_dev_sensor_value_types;
                dev_sensor_value_types.TextColumn = 0;

                col_sensor_code.PackStart (dev_sensor_codes, true);
                col_sensor_code.AddAttribute (dev_sensor_codes, "text", 0);

                col_sensor_descr.PackStart (dev_sensor_descr, true);
                col_sensor_descr.AddAttribute (dev_sensor_descr, "text", 1);

                col_sensor_value_type.PackStart (dev_sensor_value_types, true);
                col_sensor_value_type.AddAttribute (dev_sensor_value_types, "text", 2);

                nvDeviceFileDescr.AppendColumn (col_sensor_code);
                nvDeviceFileDescr.AppendColumn (col_sensor_descr);
            //nvDeviceFileDescr.AppendColumn (col_sensor_value_type);
            }

        nvDeviceFileDescr.DoubleBuffered = true;

        string[] _codes = csql.CSQL_GetDeviceSensorCodes ();
        string[] _types = csql.CSQL_GetDeviceSensorValueTypes ();

        // Do codes.
        if (_codes != null) {
            for (int i = 0; i < _codes.Length; i++) {
                ls_dev_sensor_codes.AppendValues (_codes [i]);
            }
        }

        //Do Types
        if (_types != null) {
            for (int i = 0; i < _types.Length; i++) {
                ls_dev_sensor_value_types.AppendValues (_types [i]);
            }
        }

        //Do any description entries, if available.
        if (ar_file_description.Count > 0) {

            for (int i = 0; i < ar_file_description.Count; i++) {

                CDeviceFileDescription file_descr =
                    (CDeviceFileDescription)ar_file_description [i];

                ls_nvDeviceFileDescription.AppendValues (file_descr.DeviceCode,
                    file_descr.DeviceCodeDescription, file_descr.DeviceCodeType);

            }

        }

        nvDeviceFileDescr.Model = ls_nvDeviceFileDescription;
    }
Ejemplo n.º 6
0
        private void parseStream()
        {
            string line = null;

            if (_logFile != null)
            {
                // Populate logFileLines.
                for (int i = 0; (line = _logFile.ReadLine()) != null; i++)
                {
                    if (line != "" && line != "AT+CGREG?" && (line.Substring(0, 1).StartsWith("#") != true))
                    {
                        _ar_logFileLines.Add(line);

                        //Split lines
                        string[] cols = line.Split(',');

                        //Populate devi/** TODO: Populate Alarms Table */ceLogFileValues
                        _ar_deviceLogFileEntries.Add(cols);
                    }
                }


                /**
                 * ===============================
                 * New parse for temps and alarms.
                 * ===============================
                 * Walk through each LogFile Entry.
                 * For each entry, walk through the Device LogFileDescription to get
                 * the sensor codes, as well as the array index for the logfile values
                 * for each Device LogFile Entry.
                 */

                if (_ar_logFileDescription == null)
                {
                    _ar_logFileDescription = new CUtillity().CUTIL_DefaultDeviceFileDescription;
                }

                for (int j = 0; j < _ar_deviceLogFileEntries.Count; j++)
                {
                    for (int k = 0; k < _ar_logFileDescription.Count; k++)
                    {
                        CDeviceFileDescription __device_descr = (CDeviceFileDescription)_ar_logFileDescription [k];

                        switch (__device_descr.DeviceCode)
                        {
                        case "LOGTEMP":

                            try {
                                _ar_logTimeTemp.Add(((string[])_ar_deviceLogFileEntries [j]) [k]);
                            } catch (IndexOutOfRangeException e) {
                                //TODO: Catch array index out of range here.
                            }

                            break;

                        case "LOGTIME":

                            int    __hour        = 0;
                            int    __minute      = 0;
                            string __cur_element = ((string[])_ar_deviceLogFileEntries [j]) [k];

                            try {
                                __hour   = Convert.ToInt32(__cur_element.Substring(0, 2));
                                __minute = Convert.ToInt32(__cur_element.Substring(3, 2));
                            } catch (FormatException) {
                                new Gtk.MessageDialog(null, Gtk.DialogFlags.Modal, Gtk.MessageType.Error, Gtk.ButtonsType.Ok,
                                                      "The file you tried to open was incorrectly formatted.\n" +
                                                      "Please select a different file.", 0).Show();

                                return;
                            }

                            DateTime dt = new DateTime(
                                _logFileModifiedDate.Year,
                                _logFileModifiedDate.Month,
                                _logFileModifiedDate.Day, __hour, __minute, 0
                                );

                            _ar_logTime.Add(dt);

                            break;

                        case "DID":
                            break;

                        default:

                            string value = ((string[])_ar_deviceLogFileEntries [j]) [k];

                            if (value.Length > 1)
                            {
                                CDeviceLogFileEntry __entry = new CDeviceLogFileEntry();

                                __entry.LogFIleSensorCode  = __device_descr.DeviceCode;
                                __entry.LogFileSensorDescr = __device_descr.DeviceCodeDescription;
                                __entry.LogFileSensorValue = value;

                                _ar_logAlarms.Add(__entry);
                            }

                            break;
                        }
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public CDevice CSQL_GetDevice( string device_id )
        {
            //TODO: Finish CSQL_GetDevice implementation.

            string sql_device = "SELECT * FROM devices " +
                                "WHERE devices.device_id = '" + device_id + "';";

            string sql_device_descr = "SELECT * FROM device_logfile_descr " +
                                      "WHERE device_logfile_descr.device_id = '" + device_id + "' " +
                                      "ORDER BY device_logfile_descr.device_logfile_order;";

            CDevice _device = null;
            ArrayList _ar_device_logfile_descr;
            CDeviceFileDescription _device_file_descr = null;
            SqliteCommand dbhCmd = null;
            SqliteDataReader dbhReader = null;

            if (CSQL_Connected ()) {

                dbhCmd = new SqliteCommand (sql_device, dbh);
                dbhReader = dbhCmd.ExecuteReader ();

                if (dbhReader.HasRows) {

                    dbhReader.Read ();

                    _device = new CDevice (dbhReader.GetString ((int)tbl_devices.DEVICE_ID),
                        dbhReader.GetString ((int)tbl_devices.DEVICE_DESCR),
                        dbhReader.GetString ((int)tbl_devices.DEVICE_LOCATION),
                        dbhReader.GetString ((int)tbl_devices.DEVICE_SERVER),
                        dbhReader.GetString ((int)tbl_devices.DEVICE_SERVER_SUBDIR));

                    //Get device log file description.
                    dbhCmd = new SqliteCommand (sql_device_descr, dbh);
                    dbhReader = dbhCmd.ExecuteReader ();

                    if (dbhReader.HasRows) {

                        _ar_device_logfile_descr = new ArrayList ();

                        while (dbhReader.Read()) {

                            _device_file_descr = new CDeviceFileDescription
                            (
                                 dbhReader.GetString ((int)tbl_device_logfile_descr.DEVICE_SENSOR_CODE),
                                 dbhReader.GetString ((int)tbl_device_logfile_descr.DEVICE_SENSOR_VALUE_DESCR),
                                 dbhReader.GetString ((int)tbl_device_logfile_descr.DEVICE_SENSOR_VALUE_TYPES)
                            );

                            _ar_device_logfile_descr.Add (_device_file_descr);

                        }

                        _device.DeviceFileDescription = _ar_device_logfile_descr;

                    } else {
                        cleanup ();
                        return _device;
                    }

                } else {
                    cleanup ();
                    return null;
                }

            } else {
                cleanup ();
                return null;
            }

            return _device;
        }