Beispiel #1
0
        private static object DeserializeValue(BinaryReader br)
        {
            HomeSimCockpitSDK.VariableType vt = (HomeSimCockpitSDK.VariableType)br.ReadInt32();
            switch (vt)
            {
            case HomeSimCockpitSDK.VariableType.Bool:
                return(br.ReadBoolean());

            case HomeSimCockpitSDK.VariableType.Int:
                return(br.ReadInt32());

            case HomeSimCockpitSDK.VariableType.Double:
                return(br.ReadDouble());

            case HomeSimCockpitSDK.VariableType.String:
                return(br.ReadString());

            case HomeSimCockpitSDK.VariableType.Bool_Array:
                bool[] vb = new bool[br.ReadInt32()];
                for (int i = 0; i < vb.Length; i++)
                {
                    vb[i] = br.ReadBoolean();
                }
                return(vb);

            case HomeSimCockpitSDK.VariableType.Int_Array:
                int[] vi = new int[br.ReadInt32()];
                for (int i = 0; i < vi.Length; i++)
                {
                    vi[i] = br.ReadInt32();
                }
                return(vi);

            case HomeSimCockpitSDK.VariableType.Double_Array:
                double[] vd = new double[br.ReadInt32()];
                for (int i = 0; i < vd.Length; i++)
                {
                    vd[i] = br.ReadDouble();
                }
                return(vd);

            case HomeSimCockpitSDK.VariableType.String_Array:
                string[] vs = new string[br.ReadInt32()];
                for (int i = 0; i < vs.Length; i++)
                {
                    vs[i] = br.ReadString();
                }
                return(vs);

            case HomeSimCockpitSDK.VariableType.Array:
                object[] vo = new object[br.ReadInt32()];
                for (int i = 0; i < vo.Length; i++)
                {
                    vo[i] = DeserializeValue(br);
                }
                return(vo);
            }
            return(null);
        }
 public void RegisterChangableVariable(string variableID, HomeSimCockpitSDK.VariableType type)
 {
     foreach (OutputVariable v in _outputs)
     {
         if (v.ID == variableID && v.Type == type)
         {
             if (!_registered.ContainsKey(variableID))
             {
                 _registered.Add(variableID, v);
             }
             return;
         }
     }
     throw new Exception(string.Format("Brak zmiennej o identyfikatorze '{0}' i type '{1}'.", variableID, type));
 }
Beispiel #3
0
 public void RegisterChangableVariable(string variableID, HomeSimCockpitSDK.VariableType type)
 {
 }
Beispiel #4
0
 public void RegisterListenerForVariable(HomeSimCockpitSDK.VariableChangeSignalDelegate listenerMethod, string variableID, HomeSimCockpitSDK.VariableType type)
 {
     foreach (InputVariable v in _inputs)
     {
         if (v.ID == variableID && v.Type == type)
         {
             v.VariableChanged += listenerMethod;
             return;
         }
     }
     throw new Exception(string.Format("Brak zmiennej o identyfikatorze '{0}' i type '{1}'.", variableID, type));
 }
Beispiel #5
0
 public bool CanUseVariable(string variableID, HomeSimCockpitSDK.VariableType variableType)
 {
     // dopuszczam wszystkie zmienne
     return(true);
 }
Beispiel #6
0
 public void RegisterListenerForVariable(HomeSimCockpitSDK.VariableChangeSignalDelegate listenerMethod, string variableID, HomeSimCockpitSDK.VariableType type)
 {
     if (!_variablesListeners.ContainsKey(variableID))
     {
         VariableEvent ve = new VariableEvent();
         _variablesListeners.Add(variableID, ve);
     }
     _variablesListeners[variableID].Signal += listenerMethod;
 }
        public static ModulesConfiguration Load()
        {
            if (__instance == null)
            {
                if (!File.Exists(ConfigurationFilePath))
                {
                    throw new FileNotFoundException(ConfigurationFilePath);
                }
                ModulesConfiguration c   = new ModulesConfiguration();
                XmlDocument          xml = new XmlDocument();
                xml.Load(ConfigurationFilePath);

                // wczytanie konfiguracji modułu
                c.Settings = ModuleSettings.Load(xml.SelectSingleNode("configuration/settings"));

                // wczytanie zmiennych wejściowych
                List <InputVariable> inputs = new List <InputVariable>();
                XmlNodeList          nodes  = xml.SelectNodes("configuration/variables/input/variable");
                foreach (XmlNode node in nodes)
                {
                    string        id   = node.Attributes["id"].Value;
                    InputVariable find = inputs.Find(delegate(InputVariable o)
                    {
                        return(o.ID == id);
                    });
                    if (find != null)
                    {
                        continue;
                    }

                    HomeSimCockpitSDK.VariableType type = (HomeSimCockpitSDK.VariableType)Enum.Parse(typeof(HomeSimCockpitSDK.VariableType), node.Attributes["type"].Value);
                    FSDataType    fsType = (FSDataType)Enum.Parse(typeof(FSDataType), node.Attributes["fsType"].Value);
                    int           size   = int.Parse(node.Attributes["fsSize"].Value);
                    InputVariable iv     = null;
                    switch (type)
                    {
                    case HomeSimCockpitSDK.VariableType.Int:
                        switch (fsType)
                        {
                        case FSDataType.Byte:
                        case FSDataType.Short:
                        case FSDataType.Int:
                            iv = new IntToIntInputVariable();
                            break;

                        case FSDataType.Long:
                            iv = new LongToIntInputVariable();
                            break;

                        default:
                            throw new Exception();
                        }
                        break;

                    case HomeSimCockpitSDK.VariableType.Double:
                        switch (fsType)
                        {
                        case FSDataType.Byte:
                        case FSDataType.Short:
                        case FSDataType.Int:
                            iv = new IntToDoubleInputVariable();
                            break;

                        case FSDataType.Long:
                            iv = new LongToDoubleInputVariable();
                            break;

                        case FSDataType.FLOAT64:
                            iv = new FLOAT64ToDoubleInputVariable();
                            break;

                        default:
                            throw new Exception();
                        }
                        break;

                    case HomeSimCockpitSDK.VariableType.String:
                        switch (fsType)
                        {
                        case FSDataType.ByteArray:
                            iv = new StringInputVariable();
                            break;

                        default:
                            throw new Exception();
                        }
                        break;
                    }
                    if (iv != null)
                    {
                        string offset = node.Attributes["fsOffset"].Value;
                        if (offset.StartsWith("0x") || offset.StartsWith("0X"))
                        {
                            iv.Offset = int.Parse(offset.Substring(2), System.Globalization.NumberStyles.HexNumber);
                        }
                        else
                        {
                            iv.Offset = int.Parse(offset);
                        }
                        iv.ID          = id;
                        iv.Description = node.Attributes["description"].Value;
                        iv.Type        = type;
                        iv.FSType      = fsType;
                        iv.Size        = size;
//                        string ssss = node.Attributes["change"].Value.Replace(".", System.Threading.Thread.CurrentThread.CurrentUICulture.NumberFormat.NumberDecimalSeparator);
//                        double dddd = double.Parse(ssss);
                        iv.Change = double.Parse(node.Attributes["change"].Value, NumberStyles.Float, NumberFormatInfo.InvariantInfo);// .Replace(".", System.Threading.Thread.CurrentThread.CurrentUICulture.NumberFormat.NumberDecimalSeparator));

                        if (inputs.Contains(iv))
                        {
                            throw new ApplicationException("Redefinicja zmiennej wejściowej z offsetem '0x" + iv.Offset.ToString("X8") + "'.");
                        }

                        inputs.Add(iv);
                    }
                }
                inputs.Sort(new VariableComparerForSort <InputVariable>());
                c.InputVariables = inputs.ToArray();

                // wczytanie zmiennych wyjściowych
                List <OutputVariable> outputs = new List <OutputVariable>();
                nodes = xml.SelectNodes("configuration/variables/output/variable");
                foreach (XmlNode node in nodes)
                {
                    string         id   = node.Attributes["id"].Value;
                    OutputVariable find = outputs.Find(delegate(OutputVariable o)
                    {
                        return(o.ID == id);
                    });
                    if (find != null)
                    {
                        continue;
                    }

                    HomeSimCockpitSDK.VariableType type = (HomeSimCockpitSDK.VariableType)Enum.Parse(typeof(HomeSimCockpitSDK.VariableType), node.Attributes["type"].Value);
                    FSDataType     fsType = (FSDataType)Enum.Parse(typeof(FSDataType), node.Attributes["fsType"].Value);
                    int            size   = int.Parse(node.Attributes["fsSize"].Value);
                    OutputVariable ov     = null;
                    switch (type)
                    {
                    case HomeSimCockpitSDK.VariableType.Int:
                        switch (fsType)
                        {
                        case FSDataType.Byte:
                        case FSDataType.Short:
                        case FSDataType.Int:
                        case FSDataType.Long:
                            ov = new IntOutputVariable();
                            break;

                        default:
                            throw new Exception();
                        }
                        break;

                    case HomeSimCockpitSDK.VariableType.Double:
                        switch (fsType)
                        {
                        case FSDataType.Byte:
                        case FSDataType.Short:
                        case FSDataType.Int:
                        case FSDataType.Long:
                            ov = new DoubleOutputVariable();
                            break;

                        default:
                            throw new Exception();
                        }
                        break;

                    case HomeSimCockpitSDK.VariableType.String:
                        switch (fsType)
                        {
                        case FSDataType.ByteArray:
                            ov = new StringOutputVariable();
                            break;

                        default:
                            throw new Exception();
                        }
                        break;
                    }
                    if (ov != null)
                    {
                        string offset = node.Attributes["fsOffset"].Value;
                        if (offset.StartsWith("0x") || offset.StartsWith("0X"))
                        {
                            ov.Offset = int.Parse(offset.Substring(2), System.Globalization.NumberStyles.HexNumber);
                        }
                        else
                        {
                            ov.Offset = int.Parse(offset);
                        }
                        ov.ID          = id;
                        ov.Description = node.Attributes["description"].Value;
                        ov.Type        = type;
                        ov.FSType      = fsType;
                        ov.Size        = size;
                        //ov.Change = double.Parse(node.Attributes["change"].Value, NumberStyles.Float, NumberFormatInfo.InvariantInfo);// double.Parse(node.Attributes["change"].Value.Replace(".", System.Threading.Thread.CurrentThread.CurrentUICulture.NumberFormat.NumberDecimalSeparator));
                        ov.Change = double.Parse(node.Attributes["change"].Value.Replace(".", NumberFormatInfo.CurrentInfo.NumberDecimalSeparator));

                        if (outputs.Contains(ov))
                        {
                            throw new ApplicationException("Redefinicja zmiennej wyjściowej z offsetem '0x" + ov.Offset.ToString("X8") + "'.");
                        }

                        outputs.Add(ov);
                    }
                }
                outputs.Sort(new VariableComparerForSort <OutputVariable>());
                c.OutputVariables = outputs.ToArray();

                __instance = c;
            }
            return(__instance);
        }
        public void RegisterListenerForVariable(HomeSimCockpitSDK.VariableChangeSignalDelegate listenerMethod, string variableID, HomeSimCockpitSDK.VariableType type)
        {
            Key key = Array.Find <Key>(LoadConfiguration().Keys, delegate(Key o)
            {
                return(o.ID == variableID);
            });

            if (type == HomeSimCockpitSDK.VariableType.Bool && key != null)
            {
                key.VariableChanged += listenerMethod;
            }
            else
            {
                key = Array.Find <Key>(LoadConfiguration().Keys, delegate(Key o)
                {
                    return(o.HasFastDetection && o.IDFast == variableID);
                });
                if (type == HomeSimCockpitSDK.VariableType.Bool && key != null)
                {
                    key.VariableChangedFast += listenerMethod;
                }
                else
                {
                    throw new Exception(string.Format("Brak zmiennej o identyfikatorze '{0}' i type '{1}'.", variableID, type));
                }
            }
        }
 public virtual bool ExistsVariable(string id, HomeSimCockpitSDK.VariableType type)
 {
     return(ID == id && Type == type);
 }
 protected InputVariable(HomeSimCockpitSDK.VariableType type, InputType inputType)
 {
     Type       = type;
     _inputType = inputType;
 }
Beispiel #11
0
 public bool CanUseVariable(string variableID, HomeSimCockpitSDK.VariableType variableType)
 {
     return(variableType == HomeSimCockpitSDK.VariableType.Int);
 }
Beispiel #12
0
        public void RegisterListenerForVariable(HomeSimCockpitSDK.VariableChangeSignalDelegate listenerMethod, string variableID, HomeSimCockpitSDK.VariableType type)
        {
            string [] tmp = variableID.Split(new char [] { ':' });
            if (tmp.Length > 1)
            {
                Device device = GetDevice(tmp[0]);
                if (device == null)
                {
                    throw new Exception(string.Format("Device '{0}' not found.", tmp[0]));
                }

                Input input = Array.Find <Input>(device.Variables, delegate(Input o)
                {
                    return(o.ID == variableID);
                });
                if (input == null)
                {
                    throw new Exception(string.Format("Variable '{0}' not found.", variableID));
                }

                if (input.Type != type)
                {
                    throw new Exception(string.Format("Bad variable '{0}' type '{1}'.", variableID, type));
                }

                input.VariableChangedEvent += listenerMethod;
            }
            else
            {
                throw new Exception(string.Format("Unknown variable ID '{0}'.", variableID));
            }
        }
Beispiel #13
0
 public void RegisterListenerForVariable(HomeSimCockpitSDK.VariableChangeSignalDelegate listenerMethod, string variableID, HomeSimCockpitSDK.VariableType type)
 {
     if (type != HomeSimCockpitSDK.VariableType.Int)
     {
         throw new Exception(string.Format("Nieobsługiwany typ '{0}' zmiennej '{1}'.", type, variableID));
     }
     if (!_variablesListeners.ContainsKey(variableID))
     {
         VariableEvent ve = new VariableEvent(variableID);
         _variablesListeners.Add(variableID, ve);
     }
     _variablesListeners[variableID].Signal += listenerMethod;
 }
Beispiel #14
0
 public void RegisterChangableVariable(string variableID, HomeSimCockpitSDK.VariableType type)
 {
     throw new Exception("Moduł nie udostępnia żadnych zmiennych.");
 }