Ejemplo n.º 1
0
        /// <summary>
        /// Writes an offset which contains a string from a Text source variable
        /// </summary>
        /// <param name="offsetAddress">address of offset</param>
        /// <param name="length">the length of the string data</param>
        /// <param name="sourceVariable">the Text variable source in VoiceAttack</param>
        public void writeStringOffset(int offsetAddress, int length, string sourceVariable)
        {
            lock (m_connectionLock)
            {
                if (!m_isConnected)
                {
                    writeErrorToLog("Not connected");
                    return;
                }
            }

            string value = m_vaProxy.GetText(sourceVariable);

            if (value != null)
            {
                IOffset offset = m_offsetFactory.createOffset(offsetAddress, value.Length, true);
                offset.SetValue(value);

                m_fsuipc.Process();
            }
            else
            {
                writeErrorToLog("Variable '" + sourceVariable + "' does not contain a value for Text type");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Writes an FSUIPC offset using data supplied in a VoiceAttack variable
        /// </summary>
        /// <param name="offsetAddress">address of offset</param>
        /// <param name="dataType">the data type to write</param>
        /// <param name="sourceVariable">VoiceAttack variable containing the data</param>
        public void writeOffset(int offsetAddress, Type dataType, string sourceVariable)
        {
            lock (m_connectionLock)
            {
                if (!m_isConnected)
                {
                    writeErrorToLog("Not connected");
                    return;
                }
            }

            int numBytes = Utilities.numBytesFromType(dataType);

            if (numBytes < 1)
            {
                writeErrorToLog(dataType.Name + " is an unsupported type");
                return;
            }

            IOffset offset = m_offsetFactory.createOffset(offsetAddress, numBytes, true);

            object value = Utilities.getVariableValueForOffset(dataType, sourceVariable, m_vaProxy);

            if (value != null)
            {
                offset.SetValue(value);

                m_fsuipc.Process();
            }
            else
            {
                writeErrorToLog("Variable '" + sourceVariable + "' does not contain a value for type " + dataType.Name);
            }
        }
Ejemplo n.º 3
0
Archivo: Mjc.cs Proyecto: arron-h/VAP3D
        public bool write(int idcode, Type dataType, string sourceVariable, Action <string> errorFunc)
        {
            if (!dataType.IsPrimitive)
            {
                errorFunc("readMjc: Only primitive data types are supported");
                return(false);
            }

            IOffset <int>    lvarParamAddress = m_offsetFactory.createOffset <int>(OffsetValues.LvarParam, true);
            IOffset <string> lvarName         = m_offsetFactory.createOffset <string>(OffsetValues.LvarName, 40, true);

            int lvarReadLocation  = OffsetValues.User;
            int lvarWriteLocation = OffsetValues.User + 4; // Only need 4 bytes for read location (idcode)

            // Write the value
            int     numBytes        = Utilities.numBytesFromType(dataType);
            IOffset valueReadOffset = m_offsetFactory.createOffset(lvarReadLocation, numBytes);

            object val = Utilities.getVariableValueForOffset(dataType, sourceVariable, m_vaProxy);

            valueReadOffset.SetValue(val);

            int hiword = (int)geSizeMaskForType(dataType);

            if ((SizeMask)hiword == SizeMask.INVALID)
            {
                errorFunc("readMjc: FSUIPC does not support Lvar data type " + dataType.Name);
                return(false);
            }

            // Now write MJC_VAR_WRITE_VALUE
            lvarParamAddress.Value = hiword | lvarReadLocation;
            lvarName.Value         = "::MJC_VAR_WRITE_VALUE";
            m_fsuipc.Process();

            int ackCode = 0;

            // Set up MJC_VAR_WRITE_CODE and wait for success
            {
                IOffset <int> readOffset  = m_offsetFactory.createOffset <int>(lvarReadLocation);
                IOffset <int> writeOffset = m_offsetFactory.createOffset <int>(lvarWriteLocation);

                // Write mjcCode to our user region, ready for consumption
                readOffset.Value = idcode;
                m_fsuipc.Process();

                // Tell FSUIPC where to read the mjcCode
                lvarParamAddress.Value = (int)SizeMask.INT32 | lvarReadLocation;
                // Write the code to MJC_VAR_READ_CODE L:var
                lvarName.Value = "::MJC_VAR_WRITE_CODE";
                m_fsuipc.Process();

                int ackAttempts = 0;
                do
                {
                    ackAttempts++;
                    // Tell FSUIPC where to write the mjcCode result
                    lvarParamAddress.Value = (int)SizeMask.INT32 | lvarWriteLocation;
                    // Read from MJC_VAR_READ_CODE L:var
                    lvarName.Value = ":MJC_VAR_WRITE_CODE";
                    m_fsuipc.Process();

                    ackCode = writeOffset.Value;
                } while (ackCode != ACK_SUCCESS && ackCode != ACK_ERROR && ackAttempts < 50);

                if (ackCode == ACK_ERROR)
                {
                    errorFunc("readMjc: Variable with id '" + idcode.ToString() + "' not found");
                    return(false);
                }

                if (ackAttempts >= 50)
                {
                    errorFunc("readMjc: Failed waiting for ACK code to be set");
                    return(false);
                }
            }

            return(true);
        }