// Created with MonoDevelop
//
//    Copyright (C) 2010 Hiperscan GmbH Dresden, Germany
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.

using System.Collections.Generic;

using Hiperscan.Common;


namespace Hiperscan.SGS.SerialInterface
{
    public delegate void IdleTaskHandler();

    //Is it still needed?
    public enum DriverType
    {
        FTDI,
        LibFTDI,
        LibUSB,
        WinUSB,
        None
    }

    public enum DeviceType : ulong
    {
        [StringValue("Unknown")] Unknown = 0,
        [StringValue("SGS1900")] Sgs1900 = 1,
        [StringValue("PT-IM100")] PTIM100,
        [StringValue("GerberScan")] GerberScan,
        [StringValue("Spectral Engines NSeries")] NSeries = 4,
        [StringValue("SGS-NT")] SgsNt,
        [StringValue("Calibration Device")] CalibrationDevice = 6,
        [StringValue("ApoIdent")] ApoIdent,
        [StringValue("ApoIdent")] ApoIdent2X,
        [StringValue("Finder X")] FinderX,
    }

    public enum SpectrometerVersion : ulong
    {
        [StringValue("Unknown")] Unknown       = 0,
        [StringValue("SGS1900_V1")] Sgs1900_V1 = 1,
        [StringValue("SGS1900_V2")] Sgs1900_V2 = 2,
        [StringValue("SGS1900_V3")] Sgs1900_V3 = 3,
        [StringValue("SGS1900_V4")] Sgs1900_V4 = 4,
        [StringValue("SGS1900_V5")] Sgs1900_V5 = 5,
        [StringValue("SGS1900_V6")] Sgs1900_V6 = 6,
        [StringValue("SGS1900_V7")] Sgs1900_V7 = 7,
        [StringValue("SGS1900_V8")] Sgs1900_V8 = 8,
        [StringValue("SGS1900_V9")] Sgs1900_V9 = 9,
        [StringValue("ES20_V1")] ES20_V1       = 10,
        [StringValue("ES22_V1")] ES22_V1       = 11
    }

    public interface ISerialInterface
    {
        void OpenBySerialNumber(string serial);
        void Close();
        void ResetDevice();
        void SetTimeouts(int read_timeout, int write_timeout);
        void SetTimeouts();
        void SetLatency();
        void Purge();
        
        uint Write(byte[] data);
        uint Read(out byte[] data);
        uint Read(out byte[] data, uint len);
        byte[] ReadBlocking(uint len, int timeout, IdleTaskHandler idle_task);

        DriverType DriverType { get; }
    }
}
