using System;

namespace KaltgasTool
{
    public interface IDevice
    {
        /// <summary>
        /// Reads a floating point value from a ModBus device
        /// </summary>
        /// <param name="address">Address of the Parameter</param>
        /// <returns>IEEE 32 floating point value</returns>
        float? ReadFloat(ushort address);

        ///<summary>
        /// Reads a floating point value from a ModBus device
        ///</summary>
        ///<param name="address"></param>
        ///<returns>IEEE 32 floating point value</returns>
        float? ReadParameterFloat(ushort address);

        ///<summary>
        /// Converts the two values to a IEEE 32 floating point value
        ///</summary>
        ///<param name="p1">value1</param>
        ///<param name="p2">value2</param>
        ///<returns>IEEE 32 floating point value</returns>
        float ParseParameterFloat(ushort p1, ushort p2);

        ///<summary>
        /// Reads a byte block from a ModBus device
        ///</summary>
        ///<param name="address"></param>
        ///<param name="numRegisters"></param>
        ///<returns></returns>
        ushort[] ReadBlock(ushort address, ushort numRegisters);

        ///<summary>
        /// Writes a byte block from a ModBus device
        ///</summary>
        ///<param name="startAddress"></param>
        ///<param name="values"></param>
        void WriteBlock(ushort startAddress, ushort[] values);

        /// <summary>
        /// Reads a integer value from a ModBus device
        /// </summary>
        /// <param name="startAddress">Address of the Parameter</param>
        /// <returns>Integer Value</returns>
        ushort? ReadInt(ushort startAddress);

        /// <summary>
        /// Reads a integer value from a ModBus device
        /// </summary>
        /// <param name="startAddress">Address of the Parameter</param>
        /// <param name="slaveId">Slave Id if Device to read from</param>
        /// <returns>Integer Value</returns>
        ushort? ReadInt(ushort startAddress, byte slaveId);

        /// <summary>
        /// Write to a ModBus device
        /// </summary>
        /// <param name="startAddress">Address of the Parameter</param>
        /// <param name="value">value to be written</param>
        void WriteInt(ushort startAddress, ushort value);

        /// <summary>
        /// Write to a ModBus device
        /// </summary>
        /// <param name="startAddress">Address of the Parameter</param>
        /// <param name="value">value to be written</param>
        /// <param name="slaveId">Slave Id if Device to write to</param>
        void WriteInt(ushort startAddress, ushort value, byte slaveId);

        /// <summary>
        /// Write to a ModBus device
        /// </summary>
        /// <param name="startAddress">Address of the Parameter</param>
        /// <param name="value">float to be written</param>
        void WriteFloat(ushort startAddress, float value);

        ///<summary>
        ///
        ///</summary>
        ///<param name="startAddress">Address of the Parameter</param>
        ///<param name="value">value to be written</param>
        void WriteParameterFloat(ushort startAddress, float value);

        ///<summary>
        ///
        ///</summary>
        ///<param name="field"></param>
        ///<param name="offset"></param>
        ///<param name="value"></param>
        void ModifyParameterFloat(ref ushort[] field, int offset, float value);

        ///<summary>
        ///
        ///</summary>
        ///<param name="field"></param>
        ///<param name="offset"></param>
        ///<param name="byteZero"></param>
        ///<param name="value"></param>
        void ModifyParameterByte(ref ushort[] field, int offset, bool byteZero, byte value);

        ///<summary>
        ///
        ///</summary>
        ///<param name="field"></param>
        ///<param name="offset"></param>
        ///<param name="value"></param>
        void ModifyParameterInt(ref ushort[] field, int offset, int value);

        /// <summary>
        /// Write to a ModBus device
        /// </summary>
        /// <param name="startAddress">Address of the Parameter</param>
        /// <param name="valueString">string containing a float value to be written</param>
        /// <exception cref="ArgumentOutOfRangeException"><c>valueString</c> is out of range.</exception>
        void WriteFloat(ushort startAddress, string valueString);

        /// <summary>
        /// Converts a IEEE 32 floating point format into two UInt16 values
        /// </summary>
        /// <param name="f">IEEE 32 floating point value</param>
        /// <returns>Array of 2 shorts</returns>
        ushort[] GetFloatBytes(float f);

        /// <summary>
        /// Switches to Parameter Page
        /// </summary>
        void SwitchParameterPage(bool on);
    }
}