Example #1
0
        public INDIFilterWheelNumberEventArgs(INumberVector vector, string dev) : base(vector, dev)
        {
            Values = vector.Values;
            switch (vector.Name)
            {
            case "FILTER_SLOT":
                Type = INDIFilterWheelNumberType.Slot;
                break;

            case "TIME_LST":
                Type = INDIFilterWheelNumberType.TimeLst;
                break;

            case "GEOGRAPHIC_COORD":
                Type = INDIFilterWheelNumberType.GeographicCoord;
                break;

            case "ATMOSPHERE":
                Type = INDIFilterWheelNumberType.Atmosphere;
                break;

            default:
                Type = INDIFilterWheelNumberType.Other;
                break;
            }
        }
Example #2
0
        public INDITelescopeNumberEventArgs(INumberVector vector, string dev) : base(vector, dev)
        {
            Values = vector.Values;
            switch (vector.Name)
            {
            case "EQUATORIAL_COORD":
                Type = INDITelescopeNumberType.EquatorialCoord;
                break;

            case "EQUATORIAL_EOD_COORD":
                Type = INDITelescopeNumberType.EquatorialEodCoord;
                break;

            case "TARGET_EOD_COORD":
                Type = INDITelescopeNumberType.TargetEodCoord;
                break;

            case "HORIZONTAL_COORD":
                Type = INDITelescopeNumberType.HorizontalCoord;
                break;

            case "TELESCOPE_TIMED_GUIDE_NS":
                Type = INDITelescopeNumberType.TimedGuideNS;
                break;

            case "TELESCOPE_TIMED_GUIDE_WE":
                Type = INDITelescopeNumberType.TimedGuideWE;
                break;

            case "TELESCOPE_PARK_POSITION":
                Type = INDITelescopeNumberType.ParkPosition;
                break;

            case "TELESCOPE_INFO":
                Type = INDITelescopeNumberType.Informations;
                break;

            case "TIME_LST":
                Type = INDITelescopeNumberType.TimeLst;
                break;

            case "GEOGRAPHIC_COORD":
                Type = INDITelescopeNumberType.GeographicCoord;
                break;

            case "ATMOSPHERE":
                Type = INDITelescopeNumberType.Atmosphere;
                break;

            default:
                Type = INDITelescopeNumberType.Other;
                break;
            }
        }
Example #3
0
        public void AddNumberVector(INumberVector v)
        {
            INumberVector vector = GetNumberVector(v.Name);

            if (vector != null)
            {
                GetNumberVector(v.Name).Change(v);
                return;
            }
            Numbers.Add(v);
        }
Example #4
0
 public virtual void isNewNumber(Object sender, IsNewNumberEventArgs e)
 {
     Thread.CurrentThread.CurrentCulture   = new CultureInfo("en-US");
     Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
     if (e.Device == Name)
     {
         INumberVector v = GetNumberVector(e.Vector.Name);
         if (v == null)
         {
             AddNumberVector(e.Vector);
         }
     }
 }
Example #5
0
        public INDINumber GetNumber(string vector, string name)
        {
            INumberVector v = GetNumberVector(vector);

            if (v != null)
            {
                for (Int32 i = 0; i < v.Values.Count; i++)
                {
                    if (v.Values[i].Name == name)
                    {
                        return(v.Values[i]);
                    }
                }
            }
            return(null);
        }
Example #6
0
        public INDIDomeNumberEventArgs(INumberVector vector, string dev) : base(vector, dev)
        {
            Values = vector.Values;
            switch (vector.Name)
            {
            case "ABS_DOME_POSITION":
                Type = INDIDomeNumberType.AbsPosition;
                break;

            case "REL_DOME_POSITION":
                Type = INDIDomeNumberType.RelPosition;
                break;

            case "DOME_MEASUREMENTS":
                Type = INDIDomeNumberType.Measurements;
                break;

            case "DOME_SPEED":
                Type = INDIDomeNumberType.Speed;
                break;

            case "DOME_TIMER":
                Type = INDIDomeNumberType.Timer;
                break;

            case "DOME_PARAMS":
                Type = INDIDomeNumberType.Params;
                break;

            case "TIME_LST":
                Type = INDIDomeNumberType.TimeLst;
                break;

            case "GEOGRAPHIC_COORD":
                Type = INDIDomeNumberType.GeographicCoord;
                break;

            case "ATMOSPHERE":
                Type = INDIDomeNumberType.Atmosphere;
                break;

            default:
                Type = INDIDomeNumberType.Other;
                break;
            }
        }
Example #7
0
        public string SetNumber(string vector, string name, Double value)
        {
            INumberVector v = GetNumberVector(vector);

            if (v == null)
            {
                throw new ArgumentException();
            }
            Double[] values = new Double[v.Values.Count];
            for (Int32 i = 0; i < values.Length; i++)
            {
                if (v.Values[i].Name == name)
                {
                    values[i] = value;
                }
                else
                {
                    values[i] = v.Values[i].value;
                }
            }
            return(SetNumberVector(vector, values));
        }
Example #8
0
        public INDIFocuserNumberEventArgs(INumberVector vector, string dev) : base(vector, dev)
        {
            Values = vector.Values;
            switch (vector.Name)
            {
            case "FOCUS_SPEED":
                Type = INDIFocuserNumberType.Speed;
                break;

            case "FOCUS_TIMER":
                Type = INDIFocuserNumberType.Timer;
                break;

            case "REL_FOCUS_POSITION":
                Type = INDIFocuserNumberType.RelPosition;
                break;

            case "ABS_FOCUS_POSITION":
                Type = INDIFocuserNumberType.AbsPosition;
                break;

            case "TIME_LST":
                Type = INDIFocuserNumberType.TimeLst;
                break;

            case "GEOGRAPHIC_COORD":
                Type = INDIFocuserNumberType.GeographicCoord;
                break;

            case "ATMOSPHERE":
                Type = INDIFocuserNumberType.Atmosphere;
                break;

            default:
                Type = INDIFocuserNumberType.Other;
                break;
            }
        }
Example #9
0
        public INDIDetectorNumberEventArgs(INumberVector vector, string dev) : base(vector, dev)
        {
            Values = vector.Values;
            switch (vector.Name)
            {
            case "SENSOR_INTEGRATION":
                Type = INDIDetectorNumberType.Integration;
                break;

            case "SENSOR_ABORT_INTEGRATION":
                Type = INDIDetectorNumberType.AbortIntegration;
                break;

            case "SENSOR_TEMPERATURE":
                Type = INDIDetectorNumberType.Temperature;
                break;

            case "DETECTOR_SETTINGS":
                Type = INDIDetectorNumberType.Settings;
                break;

            case "TIME_LST":
                Type = INDIDetectorNumberType.TimeLst;
                break;

            case "GEOGRAPHIC_COORD":
                Type = INDIDetectorNumberType.GeographicCoord;
                break;

            case "ATMOSPHERE":
                Type = INDIDetectorNumberType.Atmosphere;
                break;

            default:
                Type = INDIDetectorNumberType.Other;
                break;
            }
        }
Example #10
0
 public void Change(INumberVector v)
 {
     base.Change(v);
     Values = v.Values;
 }
Example #11
0
 public IsNewNumberEventArgs(INumberVector vector, string dev)
 {
     Vector = vector;
     Device = dev;
 }
Example #12
0
        bool ParseXML(String xml)
        {
            string            action       = "";
            string            target       = "";
            string            device       = "";
            string            name         = "";
            string            label        = "";
            string            vectorname   = "";
            string            vectorlabel  = "";
            string            group        = "";
            string            permission   = "";
            string            rule         = "";
            string            format       = "";
            string            length       = "";
            string            minimum      = "";
            string            maximum      = "";
            string            step         = "";
            IBlobVector       blobvector   = new IBlobVector("", "", "", "", "", "", null);
            List <INDIBlob>   blobs        = new List <INDIBlob> ();
            ISwitchVector     switchvector = new ISwitchVector("", "", "", "", "", "", null);
            List <INDISwitch> switches     = new List <INDISwitch> ();
            INumberVector     numbervector = new INumberVector("", "", "", "", "", "", null);
            List <INDINumber> numbers      = new List <INDINumber> ();
            ITextVector       textvector   = new ITextVector("", "", "", "", "", "", null);
            List <INDIText>   texts        = new List <INDIText> ();

            try {
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.ConformanceLevel = ConformanceLevel.Fragment;

                XmlReader reader = XmlReader.Create(new StringReader(RemoveInvalidXmlChars(xml)), settings);

                while (reader.Read())
                {
                    try {
                        switch (reader.NodeType)
                        {
                        case XmlNodeType.Element:
                            action = reader.Name.ToLower().Substring(0, 3);
                            target = reader.Name.Substring(3, reader.Name.Length - 3).ToLower();
                            action = action == null ? "" : action;
                            target = target == null ? "" : target;
                            if (action == "mes")
                            {
                                try {
                                    if (IsNewMessage != null)
                                    {
                                        IsNewMessage(this, new IsNewMessageEventArgs(reader.GetAttribute("message"), DateTime.Parse(reader.GetAttribute("timestamp")), reader.GetAttribute("device")));
                                    }
                                } catch {
                                }
                            }
                            if (action == "del" && target.Contains("property"))
                            {
                                try {
                                    if (IsDelProperty != null && name != "")
                                    {
                                        IsDelProperty(this, new IsDelPropertyEventArgs(name, reader.GetAttribute("device")));
                                    }
                                } catch {
                                }
                            }
                            if (action == "get" && target.Contains("properties"))
                            {
                                try {
                                    DefineProperties(reader.GetAttribute("device"));
                                } catch {
                                }
                            }
                            if (target.Contains("vector"))
                            {
                                device      = reader.GetAttribute("device");
                                vectorname  = reader.GetAttribute("name");
                                vectorlabel = reader.GetAttribute("label");
                                group       = reader.GetAttribute("group");
                                permission  = reader.GetAttribute("perm");
                                rule        = reader.GetAttribute("rule");
                                device      = device == null ? "" : device;
                                vectorname  = vectorname == null ? "" : vectorname;
                                vectorlabel = vectorlabel == null ? "" : vectorlabel;
                                group       = group == null ? "" : group;
                                permission  = permission == null ? "ro" : permission;
                                rule        = rule == null ? "" : rule;
                                if (device == "" || vectorname == "")
                                {
                                    break;
                                }
                                AddDevice(new INDIDevice(device, this));
                                if (target.Contains("blob"))
                                {
                                    blobs      = new List <INDIBlob> ();
                                    blobvector = GetDevice(device).GetBlobVector(vectorname);
                                    if (blobvector == null)
                                    {
                                        blobvector = new IBlobVector(device, vectorname, vectorlabel, group, permission, rule, blobs);
                                    }
                                    blobvector.Values = blobs;
                                }
                                if (target.Contains("switch"))
                                {
                                    switches     = new List <INDISwitch> ();
                                    switchvector = GetDevice(device).GetSwitchVector(vectorname);
                                    if (switchvector == null)
                                    {
                                        switchvector = new ISwitchVector(device, vectorname, vectorlabel, group, permission, rule, switches);
                                    }
                                    switchvector.Values = switches;
                                }
                                if (target.Contains("number"))
                                {
                                    numbers      = new List <INDINumber> ();
                                    numbervector = GetDevice(device).GetNumberVector(vectorname);
                                    if (numbervector == null)
                                    {
                                        numbervector = new INumberVector(device, vectorname, vectorlabel, group, permission, rule, numbers);
                                    }
                                    numbervector.Values = numbers;
                                }
                                if (target.Contains("text"))
                                {
                                    texts      = new List <INDIText> ();
                                    textvector = GetDevice(device).GetTextVector(vectorname);
                                    if (textvector == null)
                                    {
                                        textvector = new ITextVector(device, vectorname, vectorlabel, group, permission, rule, texts);
                                    }
                                    textvector.Values = texts;
                                }
                            }
                            else
                            {
                                name  = reader.GetAttribute("name");
                                label = reader.GetAttribute("label");
                                name  = name == null ? "" : name;
                                label = label == null ? "" : label;
                                if (target.Contains("blob"))
                                {
                                    format = reader.GetAttribute("format");
                                    length = reader.GetAttribute("size");
                                    format = format == null ? "" : format;
                                    length = length == null ? "1" : length;
                                }
                                if (target.Contains("number"))
                                {
                                    format  = reader.GetAttribute("format");
                                    minimum = reader.GetAttribute("min");
                                    maximum = reader.GetAttribute("max");
                                    step    = reader.GetAttribute("step");
                                    format  = format == null ? "" : format;
                                    minimum = minimum == null ? "1" : minimum;
                                    maximum = maximum == null ? "1" : maximum;
                                    step    = step == null ? "1" : step;
                                }
                            }
                            break;

                        case XmlNodeType.Text:
                            if (!target.Contains("vector"))
                            {
                                if (target.Contains("blob"))
                                {
                                    try {
                                        blobs.Add(new INDIBlob(name, label, format, Convert.FromBase64String(reader.Value.Replace("\n", "")), Int32.Parse(length)));
                                    }
                                    catch {
                                        blobs.Add(new INDIBlob(name, label, format, new byte[Int32.Parse(length)], Int32.Parse(length)));
                                    }
                                }
                                if (target.Contains("switch"))
                                {
                                    switches.Add(new INDISwitch(name, label, reader.Value.Replace("\n", "").Contains("On")));
                                }
                                if (target.Contains("number"))
                                {
                                    numbers.Add(new INDINumber(name, label, format, Double.Parse(minimum), Double.Parse(maximum), Double.Parse(step), Double.Parse(reader.Value.Replace("\n", ""))));
                                }
                                if (target.Contains("text"))
                                {
                                    texts.Add(new INDIText(name, label, reader.Value.Replace("\n", "")));
                                }
                            }
                            break;

                        case XmlNodeType.XmlDeclaration:
                            Console.WriteLine("<?xml version='1.0'?>");
                            break;

                        case XmlNodeType.EntityReference:
                            Console.WriteLine(reader.Name);
                            break;

                        case XmlNodeType.EndElement:
                            if (reader.Name.ToLower().Contains("vector"))
                            {
                                if (device == "" || vectorname == "")
                                {
                                    break;
                                }
                                if (target.Contains("blob"))
                                {
                                    if (IsNewBlob != null)
                                    {
                                        IsNewBlob(this, new IsNewBlobEventArgs(blobvector, device));
                                    }
                                }
                                if (target.Contains("switch"))
                                {
                                    if (IsNewSwitch != null)
                                    {
                                        IsNewSwitch(this, new IsNewSwitchEventArgs(switchvector, device));
                                    }
                                }
                                if (target.Contains("number"))
                                {
                                    if (IsNewNumber != null)
                                    {
                                        IsNewNumber(this, new IsNewNumberEventArgs(numbervector, device));
                                    }
                                }
                                if (target.Contains("text"))
                                {
                                    if (IsNewText != null)
                                    {
                                        IsNewText(this, new IsNewTextEventArgs(textvector, device));
                                    }
                                }
                            }
                            break;
                        }
                    } catch (XmlException ex) {
                        Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
                        return(false);
                    } catch (Exception ex) {
                        Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
                        return(false);
                    }
                }
                reader.Close();
                return(true);
            } catch (Exception ex) {
                Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
                return(false);
            }
        }