/// <summary> /// Reads an FSUIPC offset and updates a VoiceAttack variable /// </summary> /// <param name="offsetAddress">address of offset</param> /// <param name="dataType">the data type to read</param> /// <param name="sourceVariable">VoiceAttack variable which will be written to</param> public void readOffset(int offsetAddress, Type dataType, string destinationVariable) { 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); m_fsuipc.Process(); if (!Utilities.setVariableValueFromOffset(dataType, offset, destinationVariable, m_vaProxy)) { writeErrorToLog("Failed to set '" + destinationVariable + "' with type " + dataType.Name); } }
private Dictionary <string, object> getMonitorContext() { Dictionary <string, object> context = new Dictionary <string, object>(); // Get the altimeter setting (feet/meters) IOffset <short> altimeterSetting = m_offsetFactory.createOffset <short>(OffsetValues.AltimeterSetting); m_fsuipc.Process(); context.Add("altimeterSetting", altimeterSetting.Value); return(context); }
public bool read(int idcode, Type dataType, string destinationVariable, 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) int ackCode = 0; // Set up MJC_VAR_READ_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_READ_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_READ_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); } } // Now read MJC_VAR_READ_VALUE int numBytes = Utilities.numBytesFromType(dataType); IOffset valueWriteOffset = m_offsetFactory.createOffset(lvarWriteLocation, numBytes); int hiword = (int)geSizeMaskForType(dataType); if ((SizeMask)hiword == SizeMask.INVALID) { errorFunc("readMjc: FSUIPC does not support Lvar data type " + dataType.Name); return(false); } // Now read MJC_VAR_READ_VALUE lvarParamAddress.Value = hiword | lvarWriteLocation; lvarName.Value = ":MJC_VAR_READ_VALUE"; m_fsuipc.Process(); Utilities.setVariableValueFromOffset(dataType, valueWriteOffset, destinationVariable, m_vaProxy); return(true); }