 //////////////////////////////////////////////////////////////////////////
//类型说明文件
//////////////////////////////////////////////////////////////////////////
#pragma once
#include "pch.h"
#include <string>
#define MAX_DEVICENUMBER_FS 2
#define MAX_LINEARSHUTTER_POSITION 12
#define ZZ_Enum2String(x) #x

namespace ZZ_MISCDEF
{
	typedef unsigned char       ZZ_U8;
	typedef unsigned short int  ZZ_U16;
	typedef unsigned int        ZZ_U32;
	typedef long     int        ZZ_S32;

	
	namespace IRIS 
	{
		//Fiber Spectrometer
		namespace FS  
		{
			typedef struct tagDataFrame
			{
				ZZ_U32    usExposureTimeInMS = 0;
				ZZ_S32    lData[4096] = {0};
				float     fTemperature = 0;
				double    dTimes = 0;
			}DataFrame;



			typedef struct tagDeviceInfo
			{
				std::string strPN;
				std::string strSN;
			}DeviceInfo;

			typedef struct tagDeviceAttribute
			{
				int   iPixels;
				int   iMaxIntegrationTimeInMS;
				int   iMinIntegrationTimeInMS;
				float fWaveLengthInNM[4096];

			}DeviceAttribute;

// 			inline DataFrame GetIndex(DataFrame dfDark, DataFrame dfSignal)
// 			{
// 
// 			}
		}

		enum DeviceModel
		{
			OSIFAlpha=0,
			OSIFBeta,
			ISIF,
			IS1, 
			IS2
		};

		

		inline std::string GetDeviceModelName(int iModel)
		{
			switch (iModel)
			{
			case DeviceModel::OSIFAlpha:   return "OSIFAlpha"; break;
			case DeviceModel::OSIFBeta:    return "OSIFBeta"; break;
			case DeviceModel::ISIF:        return "ISIF"; break;
			case DeviceModel::IS1:         return "IS1"; break;
			case DeviceModel::IS2:         return "IS2"; break;
			default: return "error"; break;
			}
		}

		inline int GetIndex(std::string strDeviceModelName)
		{
			if (strDeviceModelName == "OSIFAlpha")
			{
				return DeviceModel::OSIFAlpha;
			}
			else if (strDeviceModelName == "OSIFBeta")
			{
				return DeviceModel::OSIFBeta;
			}
			else if (strDeviceModelName == "ISIF")
			{
				return DeviceModel::ISIF;
			}
			else if (strDeviceModelName == "IS1")
			{
				return DeviceModel::IS1;
			}
			else if (strDeviceModelName == "IS2")
			{
				return DeviceModel::IS2;
			}
			else
			{
				return -1;
			}
		}
		
	};

	//ATP指令转译
	namespace ATP
	{ 
		const int MAX_SPECTRUM_SIZE = 4096;

		const int GET_MODULECIRCUIT_TEMP = 0x01;
		const int GET_PN_NUMBER = 0x03;
		const int GET_SN_NUMBER = 0x04;
		const int GET_MANUFACTURE_DATA = 0x06;
		const int GET_MANUFACTURE_INFO = 0x09;
		const int GET_PIXEL_LENGTH = 0x0a;
		const int GET_TEC_TEMP = 0x13;
		const int SET_TEC_TEMP = 0x12;
		const int GET_OPTICS_TEMP = 0x35;
		const int GET_CIRCUITBOARD_TEMP = 0x36;
		const int SET_INTEGRATION_TIME = 0x14;
		const int GET_INTEGRATION_TIME = 0x41;
		const int GET_MAX_INTEGRATION_TIME = 0x42;
		const int GET_MIN_INTEGRATION_TIME = 0x43;
		const int ASYNC_COLLECT_DARK = 0x23;
		const int ASYNC_START_COLLECTION = 0x16;
		const int ASYNC_READ_DATA = 0x17;
		const int SET_AVERAGE_NUMBER = 0x28;
		const int SYNC_GET_DATA = 0x1e;
		const int SYNC_GET_DARK = 0x2f;
		const int EXTERNAL_TRIGGER_ENABLE = 0x1f;
		const int SET_XENON_LAMP_DELAY_TIME = 0x24;
		const int GET_WAVELENGTH_CALIBRATION_COEF = 0x55;
		const int GET_STAT_LAMPOUT = 0x60;
		const int SET_GPIO = 0x61;
		//const int SYNCHRONIZATION_GET_DARK = 0x23

	//////////////////////////////////////////////////////////////////////////device
		enum Model
		{
			ATP1010 = 0,
			ATP6500
		};

		//数据帧描述
		typedef struct tagATPDataFrame
		{
			unsigned short usExposureTime;
			ZZ_U16    usData[4096];
			float  fTemperature;
			double dTimes = 0;
		}ATPDataFrame;

		//设备信息描述
		typedef struct tagATPDeviceInfo
		{
			std::string strPN;
			std::string strSN;
		}ATPDeviceInfo;

		//设备特征描述
		typedef struct tagATPDeviceAttribute
		{
			int iPixels;
			int iMaxIntegrationTime;
			int iMinIntegrationTime;
			float  fWaveLength[4096];

		}ATPDeviceAttribute;
		//////////////////////////////////////////////////////////////////////////config file



	}

	//运行参数
	namespace ZZ_RUNPARAMS
	{
		typedef struct tagErrorInfo
		{
			int iDataTransferErr     = -1000;
			float fTecTempErr        = -1000;
			int iShutterErr          = -1000;
			float fChassisTempErr    = -1000;
		}ErrInfo;

		typedef struct tagFiberSpecContext
		{
			ZZ_U8         ucDeviceNumber;
			ZZ_U8         ucDeviceModel[MAX_DEVICENUMBER_FS];
			std::string   strInterface[MAX_DEVICENUMBER_FS];
			std::string   strSN[MAX_DEVICENUMBER_FS];
			long          lDepth[MAX_DEVICENUMBER_FS];
			float         fMinFactor[MAX_DEVICENUMBER_FS];
			float         fMaxFactor[MAX_DEVICENUMBER_FS];
			ZZ_U16        usPixels[MAX_DEVICENUMBER_FS];
			float         fWavelength[MAX_DEVICENUMBER_FS][4096];
		}FSContext;


		typedef struct tagDualShutterStatus
		{
			std::string strChannelA;
			std::string strChannelB;
			int iChannelA = 0;
			int iChannelB = 0;
		}DSStatus;


		typedef struct tagLinearShutterContext
		{
			std::string   strInterface;
			ZZ_U8         ucProtocolType;
			ZZ_U16        usCmdID;
		}LSContext;

		typedef struct tagAcquisitionTimeSettings
		{
			QTime  qtStartTime;
			QTime  qtStopTime;
			QTime  qtInterval;
		}AcqTimeSettings;

		typedef struct tagAcquisitionPositionSettings
		{
			int iTotalPosition;
			int iPosition[MAX_LINEARSHUTTER_POSITION];
		}AcqPosSettings;

		typedef struct tagRunTimeGrabberParams
		{
			LSContext       lscParam;
			FSContext       fscParams;
			AcqTimeSettings atsParams;
			AcqPosSettings  apsParams;
		}RunTimeGrabberParams;

		typedef struct tagATPCalibrationSettings
		{
			//Up0 Down1,2,3
			QString qsISIF_CalibrationFilePath[4];
			QString qsIS1_CalibrationFilePath[4];
		}ATPCalibrationSettings;
	}

	//系统数据文件结构
	namespace ZZ_DATAFILE
	{
		typedef struct tagEnvironmentalContext
		{
			QString qstrUTCDateTime;
			QString qstrLocation;
			QString qstrGPS_Longtitude;
			QString qstrGPS_Latitude;
			QString qstrGPS_Altitude;
			QString qstrGPS_North;
			QString qstrCaseTemperature;
			QString qstrCaseHumidity;
			QString qstrDEV_SN;
		}EContext;

		typedef struct tagManmadeEnviromentalContext
		{
			QString qstrOriFileName;
			QString qstrInstallationTime;
			QString qstrISIFCalibrationTime;
			QString qstrIS1CalibrationTime;
			QString qstrNameOfMaintenanceStaff;
			QString qstrPhoneNumberOfMaintenanceStaff;
			QString qstrDownloadUserID;
			QString qstrDownlaodAddress;
			QString qstrHTTPServer;
		}MEContext;


		typedef struct tagIS1Information
		{
			QString qstrSN_ATP;
			QString qstrSN_IRIS;

			QString qstrCalFile_U0;
			QString qstrCalFile_D1;
			QString qstrCalFile_D2;
			QString qstrCalFile_D3;

			int iPixelCount;

			int iExposureTimeInMS_U0;
			int iExposureTimeInMS_D1;
			int iExposureTimeInMS_D2;
			int iExposureTimeInMS_D3;

			float fTemperature_U0;
			float fTemperature_D1;
			float fTemperature_D2;
			float fTemperature_D3;
		}IS1Info;

		typedef struct tagISIFInformation
		{
			QString qstrSN_ATP;
			QString qstrSN_IRIS;

			QString qstrCalFile_U0;
			QString qstrCalFile_D1;
			QString qstrCalFile_D2;
			QString qstrCalFile_D3;

			int iPixelCount;

			int iExposureTimeInMS_U0;
			int iExposureTimeInMS_D1;
			int iExposureTimeInMS_D2;
			int iExposureTimeInMS_D3;

			float fTemperature_U0;
			float fTemperature_D1;
			float fTemperature_D2;
			float fTemperature_D3;
		}ISIFInfo;

		typedef struct tagATPDataHeader
		{
			

		}ATPDataHeader;

		typedef struct tagCalibrationFrame
		{
			ZZ_U32 uiExposureTimeInMS;
			float  fTemperature;
			int    iPixels;
			float  fWaveLength[4096] = { 0 };
			double dCal_Gain[4096]   = { 0 };
			double dCal_Offset[4096] = { 0 };
		}CalFrame;

		typedef struct tagCalDataFrame
		{
			ZZ_U32    usExposureTimeInMS;
			float     fTemperature = 0;
			int       iPixels;
			float     fData[4096];
			QString   qstrGrabDate;
		}CalDataFrame;
	}

	//misc detector
	namespace MISC_DETECTOR 
	{
		typedef struct tagHumitureDeviceInfo
		{
			QString qstrInterfaceName;
		}HumitureDeviceInfo;
	}
};
