#pragma once
#include "..\EpdBase\EpdBase.h"
#pragma comment(lib,"dll2/Reader2.lib")
using namespace System;

namespace EpdBaseClr {

	public ref class sEpdBase
	{
	public	:
		DateTime^ RealTime;
		unsigned int CurrentDeviceID;
	};


	public ref class Epd2
	{
		

	public: 
		EpdBase::Epd2U *epd;
		sEpdBase^ b;
		DateTime^ RealTime;
		String^ WearerName;
		String^ WearerID;
		bool Issued; 
		bool isOn;

		int InitRV;
		int DiscRV;
		int StatusRV;
		int GetStatusError;
		int GetDosesError;
		int ReadTresholdsError;
		int PrepareForIssueError;
		int SetIssuedError;
		int ConnectError;
		int ReadDosesRV;
		int DeviceCount = 0;


		double Hp07;
		double Hp10;
		double Hp07Peak;
		double Hp10Peak;
		System::Nullable<System::DateTime> Hp10PeakTime;
		System::Nullable<System::DateTime> Hp07PeakTime;
		double Hp07Total;
		double Hp10Total;

		double alarmHP07;
		double alarmHP10;


		double Hp10THDose1;
		double Hp10THDose2;
		double Hp07THDose;

		double Hp10Rate1On;
		double Hp10Rate2On;
		double Hp07RateOn;
		double Hp10Rate1Off;
		double Hp10Rate2Off;
		double Hp07RateOff;

		int K1;
		int K2;
		int K3;
		int K4;
		int K5;
		int K6;
		int SG;
		int BC;
		int FB;
		int HG;
		int QualityData;

		unsigned int D1, D2, D3, D4, CountsClock, CountsClockBase;

		int epdType;
		int alarmStatus ;
		int otherAlarms ;
		int errorStatus ;
		int operatingStatus ;
		unsigned int EpdID ;
		int HardVersion ;
		int SoftVersion ;
		int FunctionFlags ;


		unsigned short BatADC;
		unsigned short SupplyADC;


		//OperatingStatus
		BYTE DetectorsOn = 0;
		BYTE EPDIssued = 0;
		BYTE EPDLocked = 0;
		BYTE EPDTesting = 0;
		BYTE EPDProcSec = 0;
		BYTE EPDFaulty = 0;


		//ERrrostatus
		BYTE EPDNewFault = 0;
		BYTE EPDComFault = 0;
		BYTE EPDCalFault = 0;
		BYTE EPDDetFault = 0;
		BYTE EPDEprFault = 0;
		BYTE EPDTrhFault = 0;
		BYTE EPDOthFault = 0;


		//AlarmStatus
		BYTE AlarmDoseHP101G = 0;
		BYTE AlarmDoseHP102G = 0;
		BYTE AlarmDoseHP07N = 0;
		BYTE AlarmRateHP101G = 0;
		BYTE AlarmRateHP102G = 0;
		BYTE AlarmRateHP07N = 0;

		//OtherAlarm
		BYTE OtherAlarmRateHp101G = 0;
		BYTE OtherAlarmRateHp102G = 0;
		BYTE OtherAlarmRateHp07N = 0;
		BYTE OtherAlarmReturn = 0;
		BYTE OtherAlarmBatLow = 0;
		BYTE OtherAlarmCarrier = 0;
		BYTE OtherAlarmBatVolt = 0;

		
		Epd2(int port);
		~Epd2();
		!Epd2();
		
		int Connect(bool reinit);

		int Close();

		int DecodeStatus();

		int GetStatus();

		int GetDoses();

		int SetDeIssued();

		int SetIssued();


		int PrepareForIssue();		
		int WriteCalibration();

		int ReadTresholds();

		int ReadExtraStatus();



	};
}
