Example #1
0
        public void SendRequest(FSDataType requestType)
        {
            if (simconnect == null)
            {
                return;
            }

            //simconnect.RequestDataOnSimObjectType(DATA_REQUESTS.REQUEST_MAPDATA, DEFINITIONS.StructMapData, 0, SIMCONNECT_SIMOBJECT_TYPE.USER);

            switch (requestType)
            {
            case FSDataType.DT_MAP:
                simconnect.RequestDataOnSimObject(DATA_REQUESTS.REQUEST_MAPDATA, DEFINITIONS.StructMapData, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD.SECOND, SIMCONNECT_DATA_REQUEST_FLAG.CHANGED, 0, 0, 0);
                break;

            case FSDataType.DT_FLIGHTSIM_STATUS:
                simconnect.RequestSystemState(DATA_REQUESTS.REQUEST_SYSTEMSTATE, "Sim");
                break;

            case FSDataType.DT_FLIGHTPLAN:
                simconnect.RequestSystemState(DATA_REQUESTS.REQUEST_FLIGHTPLAN, "FlightPlan");
                break;

            default:
                break;
            }
        }
        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 static IEnumerable <byte[]> convertDataStructToByte(FSDataType dType, object data)
        {
            List <byte[]> retData = new List <byte[]>();

            // byte[0] is the packet size to be sent not including the packet size.
            byte[] sData = null;

            switch (dType)
            {
            case FSDataType.DT_MAP:
                byte[] lat = BitConverter.GetBytes(((MAP_DATA_STRUCT)data).latitude);
                byte[] lon = BitConverter.GetBytes(((MAP_DATA_STRUCT)data).longitude);
                byte[] hed = BitConverter.GetBytes(((MAP_DATA_STRUCT)data).heading);
                sData    = new byte[(sizeof(double) * 3) + 2];
                sData[0] = (byte)(sData.Length - 1);
                sData[1] = (byte)FSDataType.DT_MAP;
                for (int i = 0; i < (sizeof(double)); i++)
                {
                    sData[i + 2] = lat[i];
                    sData[i + (sizeof(double)) + 2]     = lon[i];
                    sData[i + (sizeof(double) * 2) + 2] = hed[i];
                }
                retData.Add(sData);
                break;

            case FSDataType.DT_FLIGHTPLAN:
                FlightPlanParser prs = new FlightPlanParser(((FLIGHTPLAN_LINK)data).flightPlanFilename);
                if (prs.waypoints == null)
                {
                    // If new flight plan is null then new flight is loaded and therefore restart message will be sent instead.
                    sData    = new byte[2];
                    sData[0] = 1;
                    sData[1] = (byte)FSDataType.DT_RESTART;
                    retData.Add(sData);
                    break;
                }
                for (int i = 0; i < prs.waypoints.Count; i++)
                {
                    byte[] pData = null;
                    pData    = new byte[2 * sizeof(double) + 3];
                    pData[0] = (byte)(pData.Length - 1);
                    pData[1] = (byte)FSDataType.DT_FLIGHTPLAN;
                    pData[2] = (byte)(prs.waypoints.Count - (i + 1));
                    byte[] lt = BitConverter.GetBytes(prs.waypoints[i].latitude);
                    byte[] ln = BitConverter.GetBytes(prs.waypoints[i].longitude);
                    for (int j = 0; j < sizeof(double); j++)
                    {
                        pData[3 + j] = lt[j];
                        pData[(sizeof(double)) + 3 + j] = ln[j];
                    }
                    retData.Add(pData);
                }
                break;

            case FSDataType.DT_RESTART:
                sData    = new byte[2];
                sData[0] = 1;
                sData[1] = (byte)FSDataType.DT_RESTART;
                retData.Add(sData);
                break;

            case FSDataType.DT_CLIENTTYPE:
                CLIENT_TYPE ct = (CLIENT_TYPE)data;
                sData    = new byte[6];
                sData[0] = (byte)(sData.Length - 1);
                sData[1] = (byte)FSDataType.DT_CLIENTTYPE;
                sData[2] = (byte)ct.ccode;
                sData[3] = ct.ReleaseVersion;
                sData[4] = ct.MajorVersion;
                sData[5] = ct.MinorVersion;
                retData.Add(sData);
                break;

            default:
                break;
            }

            return(retData);
        }
Example #4
0
 public DataReceivedEventArgs(FSDataType dt, object data)
 {
     dataType = dt;
     oData    = data;
 }