Пример #1
0
        /// <summary>
        /// Apply a new thermal setting to the system.
        /// </summary>
        /// <param name="thermalSetting">Thermal setting to apply</param>
        /// <returns>True if successful, false if not</returns>
        public static bool SetThermalSetting(ThermalSetting thermalSetting)
        {
            if (thermalSetting != ThermalSetting.Error)
            {
                try
                {
                    DellSmmBiosMessage message = new DellSmmBiosMessage
                    {
                        Class      = ThermalModeClass,
                        Selector   = ThermalModeSelector,
                        Result1    = DefaultResult1,
                        Parameter1 = 1,
                        Parameter2 = (uint)thermalSetting
                    };

                    return(ExecuteCommand(ref message));
                }
                catch (Exception)
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
        /// <summary>
        /// Get the current thermal setting for the system.
        /// </summary>
        /// <returns>Current thermal setting; ThermalSetting.Error on error</returns>
        public static ThermalSetting GetThermalSetting()
        {
            try
            {
                DellSmmBiosMessage message = new DellSmmBiosMessage
                {
                    Class    = ThermalModeClass,
                    Selector = ThermalModeSelector,
                    Result1  = DefaultResult1
                };

                bool result = ExecuteCommand(ref message);
                if (result)
                {
                    return((ThermalSetting)message.Result3);
                }
                else
                {
                    return(ThermalSetting.Error);
                }
            }
            catch (Exception)
            {
                return(ThermalSetting.Error);
            }
        }
Пример #3
0
        /// <summary>
        /// Execute a command against the SMM BIOS via the ACPI/WMI interface.
        /// </summary>
        /// <param name="message">SMM BIOS message (a packaged-up command to be executed)</param>
        /// <returns>True if successful, false if not; note that exceptions on error conditions can come back from this method as well</returns>
        private static bool ExecuteCommand(ref DellSmmBiosMessage message)
        {
            byte[] bytes  = StructToByteArray(message);
            byte[] buffer = new byte[BufferLength];
            Buffer.BlockCopy(bytes, 0, buffer, 0, bytes.Length);
            bool result = ExecuteCommand(ref buffer);

            message = ByteArrayToStruct(buffer);

            return(result);
        }
Пример #4
0
        /// <summary>
        /// Convert a SMM BIOS message struct to a byte array.
        /// </summary>
        /// <param name="message">SMM BIOS message struct</param>
        /// <returns>Byte array</returns>
        /// <seealso cref="https://stackoverflow.com/questions/3278827/how-to-convert-a-structure-to-a-byte-array-in-c"/>
        private static byte[] StructToByteArray(DellSmmBiosMessage message)
        {
            int size = Marshal.SizeOf(message);

            byte[] array = new byte[size];

            IntPtr pointer = Marshal.AllocHGlobal(size);

            Marshal.StructureToPtr(message, pointer, true);
            Marshal.Copy(pointer, array, 0, size);
            Marshal.FreeHGlobal(pointer);
            return(array);
        }
Пример #5
0
        /// <summary>
        /// Convert a byte array to a SMM BIOS message struct.
        /// </summary>
        /// <param name="array">Byte array</param>
        /// <returns>SMM BIOS message struct</returns>
        /// <seealso cref="https://stackoverflow.com/questions/3278827/how-to-convert-a-structure-to-a-byte-array-in-c"/>
        private static DellSmmBiosMessage ByteArrayToStruct(byte[] array)
        {
            DellSmmBiosMessage message = new DellSmmBiosMessage();

            int    size    = Marshal.SizeOf(message);
            IntPtr pointer = Marshal.AllocHGlobal(size);

            Marshal.Copy(array, 0, pointer, size);

            message = (DellSmmBiosMessage)Marshal.PtrToStructure(pointer, message.GetType());
            Marshal.FreeHGlobal(pointer);

            return(message);
        }