/*
 * evo_b1553_bite.h
 *
 */

#ifndef EVO_B1553_BITE_H_
#define EVO_B1553_BITE_H_

#include <stdint.h>

namespace icd1553
{

struct bite_word_t
{
	uint16_t raw;

	bite_word_t(): raw(0)
	{
	}
	bite_word_t(int v): raw(static_cast<uint16_t>(v))
	{
	}

	void operator=(int v)
	{
		raw=static_cast<uint16_t>(v);
	}


	void set_fail(unsigned int bit, bool fail_state=true)
	{
		bit=15-bit;
		if (fail_state)
			raw|=(1<<bit);
	}

	void set(unsigned int bit, bool fail_state)
	{
		bit=15-bit;
		if (fail_state)
			raw|=(1<<bit);
		else
			raw=raw & (~(1<<bit));
	}

	bool get(unsigned int bit)
	{
		bit=15-bit;
		return (raw & (1<<bit))!=0;
	}
};

struct bite_raw_word_t
{
	uint16_t raw;

	void operator=(bite_word_t v)
	{
		raw=v.raw;
	}
	
	void set_fail(unsigned int bit, bool fail_state)
	{
		bit=15-bit;
		if (fail_state)
			raw|=(1<<bit);
	}

	void set(unsigned int bit, bool fail_state)
	{
		bit=15-bit;
		if (fail_state)
			raw|=(1<<bit);
		else
			raw=raw & (~(1<<bit));
	}

	bool get(unsigned int bit)
	{
		bit=15-bit;
		return (raw & (1<<bit))!=0;
	}
};

struct evo_raw_bite_msg_t
{
	bite_raw_word_t data[32];
};

enum bite_word_index_t
{
	b_report_label=0,
	b_report_date,
	b_report_time,

	b_degraded_condition_1=3,
	b_degraded_condition_2,

	b_loc_lcu=5,
	b_loc_aesa,
	b_loc_spare1,
	b_loc_rep_plus,
	b_loc_pps,
	b_loc_rep,

	b_tr_sp=11,
	b_tr_rep_ext,
	b_tr_rep,
	b_tr_dsp,
	b_tr_lcu_1,
    b_tr_psm_1,
    b_tr_psm_2,
	b_tr_pps_1,
	b_tr_pps_2,
        b_tr_aesa_1,
        b_tr_system,

	//Extension over first 22 word (not backward compatible)
	b_tr_lcu_2=22,
        b_tr_aesa_2,
        b_tr_24,
	b_tr_25,

	b_tr_sw_eif_fails,		//b_tr_27,
	b_tr_sw_dfe_fails,		//b_tr_28,
	b_tr_sw_dsp_fails,	  	//b_tr_29,
	
        b_tr_aesa_lcu_temp,
        b_tr_rep_temp,     		//b_tr_30,
	b_tr_pps_temp=31, 		//b_tr_31

	//Word range to determine if a new bite report has been generated
	b_update_start=b_degraded_condition_1,
	b_update_loc_and_tr_start= b_loc_lcu,
        b_update_end  = b_tr_sw_eif_fails
};

enum bite_rep_loc_index_t
{
	rep_loc_chassis=0,
	rep_loc_psm,
	rep_loc_eif,
	rep_loc_xif1,
	rep_loc_xif2,
	rep_loc_dfe,
	
	rep_loc_dc1,
	rep_loc_dc2,
	rep_loc_dc3,
	rep_loc_synth,	
	rep_loc_exciter,
	//The following always localize chassis also
	rep_loc_pps_cable,
	rep_loc_aesa_cable,
	rep_loc_bus1553
};
enum bite_rep_tr_index_t
{
	rep_tr_uc,
	rep_tr_psm_if,
	rep_tr_pps_if,
	rep_tr_lcu_if,
	rep_tr_aesa_if,
	rep_tr_synch1553,
	rep_tr_ttag,
	rep_tr_batch,
	rep_tr_signal,
	rep_tr_srio,
	rep_tr_sw_watchdog,
	rep_tr_clink_dc,
	rep_tr_clink_exc_sync,
	
	rep_tr_wow_fail,
	rep_tr_spare_14,
	
	rep_tr_cpu
};

enum bite_rep_plus_loc_index_t
{
	rep_loc_eif_carrier=0,
	rep_loc_eif_dsp,
	rep_loc_eif_zynq,
	rep_loc_xif1_carrier,
	rep_loc_xif1_dsp0,
	rep_loc_xif1_dsp1,
	rep_loc_xif2_carrier,
	rep_loc_xif2_dsp0,
	rep_loc_xif2_dsp1,
	
	rep_loc_dfe_carrier,
	rep_loc_dfe_spare,
	rep_loc_dfe_zynq	
};

enum bite_loc_lcu_index_t
{
	lcu_chassis=0,
	lcu_ctrl_board,
	lcu_motor,
	lcu_filter,
	lcu_aesa_stream,
    lcu_pps_stream,
	lcu_power_input,
	lcu_air_inlet,
	lcu_air_outlet	
};

enum bite_lcu_tr_index_t
{
	lcu_tr_overall,
	lcu_tr_temp_hazard,
	lcu_tr_phase_a,
	lcu_tr_phase_b,
	lcu_tr_phase_c,
	lcu_tr_phase_sequence,
	lcu_tr_board,
	lcu_tr_link,
	lcu_tr_motor,
	lcu_tr_motor_temp_hazard,
	lcu_tr_inlet_flow_aesa,
	lcu_tr_inlet_flow_pps,
	lcu_tr_inlet_temp,
	lcu_tr_outlet_temp,
	lcu_tr_dirty_filter_fail,
	lcu_tr_aesa_stream_fail
};

enum bite_lcu_tr2_index_t
{
	lcu_tr_pressure_sensor,
	lcu_tr_motor_speed_sensor,
	lcu_tr_motor_temp_sensor,
	lcu_tr_inlet_temp_sensor_aesa,
	lcu_tr_inlet_temp_sensor_pps,
    lcu_tr_inlet_temp_sensor_combo,
	lcu_tr_outlet_temp_sensor,
	lcu_tr_by_pass
};

enum bite_loc_pps_index_t
{
	pps_chassis=0,
	pps_hup=1,
	pps_rx,
	pps_input_filter,
	pps_tx1,
	pps_tx2,
    pps_tx3
};


//PSM
enum bite_psm_tr1_index_t
{
	psm_tr_bite,
	psm_tr_temp_warning,
	psm_tr_temp_hazard,
	psm_tr_ov_temp_hazard,
	
	psm_tr_ov_dc_bus,
	
	psm_tr_ov_m15v,
	psm_tr_uv_m15v,	
	psm_tr_ov_15v,
	psm_tr_uv_15v,
	psm_tr_ov_5v,
	psm_tr_uv_5v,	

	psm_tr_lcu_rdy,	
	psm_tr_ac_loss,
	psm_tr_uv_270v,
	psm_tr_power_err,		
	psm_tr_rdr_on_sts
};

enum bite_psm_tr2_index_t
{	
	psm_tr_ov_3v3,
	psm_tr_uv_3v3,

	psm_tr_ov_13v,
	psm_tr_uv_13v,	
	psm_tr_ov_350v,
	psm_tr_uv_350v,
	psm_tr_blko_test,
	
	psm_tr_ph_a,
	psm_tr_ph_b,
	psm_tr_ph_c,
	
	psm_tr_eif_comm
};

enum bite_loc_aesa_index_t
{
	aesa_loc_chassis,
	aesa_loc_cti,
	aesa_loc_aesa,
	aesa_loc_rfif,
	aesa_loc_plank,
	aesa_loc_trc
};

enum bite_aesa_tr1_index_t
{
	aesa_tr_cbit
};

enum bite_intsys_index_t
{
	isys_tr_stc,
	isys_tr_nagc,
	isys_tr_cal1,
	isys_tr_cal2,

	isys_tr_ch1
};

}//namespace icd1553


#endif /* EVO_B1553_BITE_H_ */
