/*
 * xlru_interface.h
 *
 */

#ifndef XLRU_MANAGER_H_
#define XLRU_MANAGER_H_


class XLruManager
{
public:

	struct manager_status_t
	{
		unsigned int poroduce_messages;
		unsigned int received_bytes;
		unsigned int received_garbage;
		unsigned int received_messages;

		unsigned int received_invalid_unit;
		unsigned int received_overlapping;

		unsigned int good_messages;
		unsigned int error_messages;

		unsigned int transmitted_bytes;

		unsigned int overruns;
		unsigned int biterror;

		unsigned int received_oob;
	};

	struct unit_comm_status_t
	{
		bool commDeviceOk;	//the communication device is working
		bool linkUp;		//communication with unit is OK. Unit status is valid

		unsigned int good_messages;
		unsigned int error_messages;

		unsigned int reply_missed;
		unsigned int reply_pending;

		unsigned int sent_messages;
		unsigned int reply_overlap;
	};

	struct unit_basic_status_t	//Common to all units
	{
		bool unitOk;		//unit is OK

		bool overtempWarning;	//Override-able over-temperature warning
		bool overtempHazard;	//No Override-able over-temperature hazard
	};

	struct unit_status_t
	{
		unit_comm_status_t commStatus;
		unit_basic_status_t basicStatus;
	};

	struct psm_status_t
	{
		unit_status_t status;

		bool wow; //Weight-on-Wheel
		bool inputPowerFail;
		float inAmp;
	};

	enum pps_power_sts_t { pps_power_err, pps_power_idle, pps_power_stby, pps_power_full, pps_power_low};

	struct pps_tx_status_t
	{
		char sts_char;
		bool comm_fail;
		bool overtemp;
		bool board_fail;
	};

	struct pps_status_t
	{
		unit_status_t status;
		bool warning;
		pps_power_sts_t power_sts;
		char power_sts_char;
		float rxPower;
		float txPower;
		float txPowerMax;
		float txPowerAvg;
		float rxTemperature;
		float txHigherTemperature;

		int txPowerMaxValitity;
		int txPowerAvgValitity;

		pps_tx_status_t tx[3];

		int rxPhaseValidity;

		float rxPhaseMin[3];	// R;S;T
		float rxPhaseMax[3];	// R;S;T
	};

	struct lcu_status_t
	{
		unit_status_t status;
	};

	static bool start();

	static manager_status_t& managerStatus();

	static void emergyEnable(bool enable=true);

	static bool wowActive();
	static bool wowFail();

	static unsigned int wowPpsTxFail();

	typedef unsigned short ext_bite_word_t;

    struct bite_report_t
    {
		ext_bite_word_t localization;
		ext_bite_word_t test[2];
    };

	//PSM:
	static psm_status_t& psmStatus();
	static float psmTemperature();

	static void psmPowerDown(bool enable=true);
	static void psmRecycle(bool enable=true);
	static void psmEmergency(bool enable);
	static void psmFastEnable(bool enable=true);
	static bool psmFastPowerup();

	static bite_report_t psm_bite_report();

	static bool psmRecycled(); //true if reyccled!!!
	static int psmRecycleCode(); //the reason (0=recycle by PSM)
	//PPS

	static bite_report_t pps_bite_report();

	static pps_status_t& ppsStatus();

	static float ppsTemperature();

	static void ppsPowerOuputEnable(bool enable);
	static void ppsPowerLimitationEnable(bool enable);

	static void ppsExecuteInterruptiveBit(bool enable);

	//LCU:
	static bool lcu_ready();

	static bite_report_t lcu_bite_report();

	static lcu_status_t& lcuStatus();

	static float lcuTemperature();
	static float lcuAesaInletTemperature();
	static float lcuAesaOutletTemperature();

	static void lcuHeaterOn(bool enable);

	static void lcuExecuteInterruptiveBit(bool enable);
	static void lcuReset(bool enable);


	//Ony for debug
	static void setOutOfBandDataHandler(void (*handler)(char c));
	static void injectOutofBandData(char c);

	static void setHostMode(unsigned int hmode);
	static void psmFastOverride(int ovr);
	static void psmWowOverride(int ovr);

	static bool risMode();

	enum panic_reason_t
	{
		panic_none,
		panic_dsp=(1<<0),
		panic_dfe=(1<<1),
		panic_aesa=(1<<2),
		panic_pwerr=(1<<3),
		panic_rdy=(1<<4)
	};
	typedef unsigned int panic_event_t;	//or of panic_reason_t

	static unsigned int panicAlert(panic_event_t evn);
};

void XLruManagerRisMode(bool enable);
void XlruManagerDisableUdpLog(bool please_disable);

#endif /* XLRU_MANAGER_H_ */
