/***************************************************************************
 * Copyright (c) 2009 Digi International Inc., All Rights Reserved
 * 
 * This software contains proprietary and confidential information of Digi
 * International Inc.  By accepting transfer of this copy, Recipient agrees
 * to retain this software in confidence, to prevent disclosure to others,
 * and to make no use of this software other than that for which it was
 * delivered.  This is an unpublished copyrighted work of Digi International
 * Inc.  Except as permitted by federal law, 17 USC 117, copying is strictly
 * prohibited.
 * 
 * Restricted Rights Legend
 *
 * Use, duplication, or disclosure by the Government is subject to
 * restrictions set forth in sub-paragraph (c)(1)(ii) of The Rights in
 * Technical Data and Computer Software clause at DFARS 252.227-7031 or
 * subparagraphs (c)(1) and (2) of the Commercial Computer Software -
 * Restricted Rights at 48 CFR 52.227-19, as applicable.
 *
 * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
 *
 ***************************************************************************
 *
 * @Descr: WinIOCTL Class
 *
 * @History:
 *	07/17/09:	aramos      initial version.
 *  08/12/09:   aramos      code revision.
 *
 ***************************************************************************/

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

/*! \package Digi.Imported
 */
/// <summary>
/// The Digi.Imported includes files imported from C
/// </summary>
namespace Digi.Imported
{
    /*! \enum MethodType
    */
    /// <summary>
    /// Method Type enum
    /// </summary>
    /// <example>
    /// <code>
    /// // Use of the constants
    /// MethodType.Buffered
    /// MethodType.InDirect
    /// MethodType.OutDirect
    /// MethodType.Neither</code>
    /// </example>
    public enum MethodType
    {
        Buffered = 0,
        InDirect = 1,
        OutDirect = 2,
        Neither = 3,
    }

    /*! \enum AccessType
    */
    /// <summary>
    /// Access Type enum
    /// </summary>
    /// <example>
    /// <code>
    /// // Use of the constants
    /// AccessType.Any
    /// AccessType.Read
    /// AccessType.Write</code>
    /// </example>
    public enum AccessType
    {
        Any = 0,
        Read = 1,
        Write = 2,
    }

    /*! \enum DeviceType
    */
    /// <summary>
    /// Device Type enum
    /// </summary>
    /// <example>
    /// <code>
    /// // Use of the Digi constants
    /// DeviceType.I2cPort
    /// DeviceType.GpioPort
    /// DeviceType.SpiPort
    /// DeviceType.ADC</code>
    /// </example>
    public enum DeviceType
    {
        Beep = 0x00000001,
        CDRom = 0x00000002,
        CDRomFileSystem = 0x00000003,
        Controller = 0x00000004,
        Datalink = 0x00000005,
        Dfs = 0x00000006,
        Disk = 0x00000007,
        DiskFileSystem = 0x00000008,
        FileSystem = 0x00000009,
        InportPort = 0x0000000a,
        Keyboard = 0x0000000b,
        Mailslot = 0x0000000c,
        MidiIn = 0x0000000d,
        MidiOut = 0x0000000e,
        Mouse = 0x0000000f,
        MultiUncProvider = 0x00000010,
        NamedPipe = 0x00000011,
        Network = 0x00000012,
        NetworkBrowser = 0x00000013,
        NetworkFileSystem = 0x00000014,
        Null = 0x00000015,
        ParallelPort = 0x00000016,
        PhysicalNetcard = 0x00000017,
        Printer = 0x00000018,
        Scanner = 0x00000019,
        SerialMousePort = 0x0000001a,
        SerialPort = 0x0000001b,
        Screen = 0x0000001c,
        Sound = 0x0000001d,
        Streams = 0x0000001e,
        Tape = 0x0000001f,
        TapeFileSystem = 0x00000020,
        Transport = 0x00000021,
        Unknown = 0x00000022,
        Video = 0x00000023,
        VirtualDisk = 0x00000024,
        WaveIn = 0x00000025,
        WaveOut = 0x00000026,
        Port8042 = 0x00000027,
        NetworkRedirector = 0x00000028,
        Battery = 0x00000029,
        BusExtender = 0x0000002a,
        Modem = 0x0000002b,
        Vdm = 0x0000002c,
        MassStorage = 0x0000002d,
        Smb = 0x0000002e,
        Ks = 0x0000002f,
        Changer = 0x00000030,
        Smartcard = 0x00000031,
        Acpi = 0x00000032,
        Dvd = 0x00000033,
        FullscreenVideo = 0x00000034,
        DfsFileSystem = 0x00000035,
        DfsVolume = 0x00000036,

        //Digi defined
        I2cPort = 32768,
        GpioPort = 32770,
        SpiPort = 32772,
        ADC = 32774,

        // windows ce specific defines
        Hal = 0x00000101,
        Console = 0x00000102,
        Psl = 0x00000103,
        Service = 0x00000104,

    }

    /*! \class WINIOCTL_H
     */
    /// <summary>
    /// This class wraps the CTL_CODE function into a C# class.
    /// </summary>
    public class WINIOCTL_H
    {
        /*! \fn public static uint CTL_CODE(DeviceType Device, int Function, MethodType Method, AccessType Access)
            */
        /// <summary>
        /// Compose CTL code
        /// </summary>
        /// <param name="Device">Device type (use DeviceType)</param>
        /// <param name="Function">Fuction code</param>
        /// <param name="Method">Method type (use MethodyType)</param>
        /// <param name="Access">Access type (use AccessType)</param>
        /// <returns></returns>
        public static uint CTL_CODE(DeviceType Device, int Function, MethodType Method, AccessType Access)
        {
            return (uint)(((int)Device << 16) | ((int)Access << 14) | (Function << 2) | (int)(Method));
        }
    }
}
