/*
 * b1553_icd_br.h
 *
 *  Created on: 18/mag/2017
 *      Author: chessaa
 */

#ifndef EVO_B1553_ICD_TH_H_
#define EVO_B1553_ICD_TH_H_

#include "idd_types.h"
#include "stddef.h"

#include "gc_math.h"

//#include "th_b1553_icd.h" - this file shall be included at the end of th_b1553_icd.h
#include "th_b1553_icd.h"

using namespace idd_codec;

namespace icd1553
{

#include "idd_pack16.h"

//typedef idd_bitfield_u16_t<IDD_REVBIT16(1), 1, lru_fail_status_t> array_status_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(2), 1, lru_fail_status_t> evo_lcu_status_t;	//N/A
typedef idd_bitfield_u16_t<IDD_REVBIT16(3), 1, lru_fail_status_t> evo_aesa_status_t;	//N/A
//typedef idd_bitfield_u16_t<IDD_REVBIT16(4), 1, lru_fail_status_t> rx_front_end_status_t; //N/A
//typedef idd_bitfield_u16_t<IDD_REVBIT16(5), 1, lru_fail_status_t> receiver_status_t;	//N/A
typedef idd_bitfield_u16_t<IDD_REVBIT16(6), 1, lru_fail_status_t> evo_pps_status_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(7), 1, lru_fail_status_t> evo_rep_status_t;

typedef idd_bitfield_u16_t<IDD_REVBIT16(8), 1, bool> evo_pps_over_temperature_alarm_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(9), 1, bool> evo_rep_over_temperature_alarm_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(10), 1, bool> evo_aesa_over_temperature_alarm_field_t;

typedef idd_bitfield_u16_t<IDD_REVBIT16(11), 1, bool> evo_lcu_over_temperature_alarm_field_t;

typedef idd_bitfield_u16_t<IDD_REVBIT16(12), 1, bit_report_available_t> bit_report_available_field_t;

typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 3, uint16_t> spare3_15_field_t ;

union evo_radar_health_status_and_bit_report_validity_t
{
	radar_fails_status_field_t radar_fails_status_field;

	//array_status_t array_status;
	evo_lcu_status_t lcu_status;
	evo_aesa_status_t aesa_status;
	//rx_front_end_status_t rx_front_end_status;
	//receiver_status_t receiver_status;
	evo_pps_status_t pps_status;
	evo_rep_status_t rep_status;

	evo_pps_over_temperature_alarm_field_t pps_over_temperature_alarm_field;
	evo_rep_over_temperature_alarm_field_t rep_over_temperature_alarm_field;
	evo_aesa_over_temperature_alarm_field_t aesa_over_temperature_alarm_field;

	pressurization_status_field_t pressurization_status_field;

	bit_report_available_field_t bit_report_available_field;

	idd_boolfield_u16_t<IDD_REVBIT16(13), lru_fail_status_t> lcu_fail;

	idd_boolfield_u16_t<IDD_REVBIT16(14), lru_fail_status_t> spare_14;
	idd_boolfield_u16_t<IDD_REVBIT16(15), lru_fail_status_t> spare_15;

	icd_raw_word_t raw;
};


//Message B8: BIT Report Message

//Word B8-01: BIT Report Label



//Word B8-06: Failure Location (Pedestal)
union failure_location_aesa_t
{
	idd_bitfield_u16_t<IDD_REVBIT16(0), 1, bool> chassis;

	icd_raw_word_t raw;
};

//Word B8-11: Failure Location (Processor)
union failure_location_rep_t
{
	idd_bitfield_u16_t<IDD_REVBIT16(0), 1, bool> chassis;
	idd_bitfield_u16_t<IDD_REVBIT16(1), 1, bool> pps;
	idd_bitfield_u16_t<IDD_REVBIT16(2), 1, bool> eif;
	idd_bitfield_u16_t<IDD_REVBIT16(3), 1, bool> xif1;
	idd_bitfield_u16_t<IDD_REVBIT16(4), 1, bool> xif2;
	idd_bitfield_u16_t<IDD_REVBIT16(5), 1, bool> dfe;

	idd_bitfield_u16_t<IDD_REVBIT16(6), 1, bool> dc1;
	idd_bitfield_u16_t<IDD_REVBIT16(7), 1, bool> dc2;
	idd_bitfield_u16_t<IDD_REVBIT16(8), 1, bool> dc3;

	idd_bitfield_u16_t<IDD_REVBIT16(9), 1, bool> exciter;
	idd_bitfield_u16_t<IDD_REVBIT16(10), 1, bool> synthetizer;

	icd_raw_word_t raw;
};

enum evo_pps_test0_list_t
{
    pps_serial_link=0,
    pps_comm,
    pps_fail_status,
    pps_rx_input_dc_overcurrent,
    pps_rx_rectified_dc_under_voltage_fail_ac_power_loss,
    pps_output_rx_over_voltage_fail,
    pps_output_rx_under_voltage_fail,
    pps_wow_fail,

    pps_LP_under_voltage_fail,
    pps_HP_under_voltage_fail,
    pps_AC_power_umbalance_fail_ph1,
    pps_AC_power_umbalance_fail_ph2,
    pps_AC_power_umbalance_fail_ph3
};

enum evo_pps_test1_list_t
{
    pps_tx1_comm=0,
    pps_tx1_input_dc_over_current_fail,
    pps_tx1_rectified_dc_under_voltage_fail_270_uv,
    pps_output_tx1_over_voltage_fail,
    pps_output_tx1_under_voltage_fail,

    pps_tx2_comm,
    pps_tx2_input_dc_over_current_fail,
    pps_tx2_rectified_dc_under_voltage_fail_270_uv,
    pps_output_tx2_over_voltage_fail,
    pps_output_tx2_under_voltage_fail,

    pps_tx3_comm,
    pps_tx3_input_dc_over_current_fail,
    pps_tx3_rectified_dc_under_voltage_fail_270_uv,
    pps_tx3_output_over_voltage_fail,
    pps_tx3_output_under_voltage_fail
};


typedef idd_bitfield_i16_t<IDD_REVBIT16(0), 8, int16_t> temperature_field_a_t;
typedef idd_bitfield_i16_t<IDD_REVBIT16(8), 8, int16_t> temperature_field_b_t;

union evo_rep_temperature_union_t
{
	temperature_field_a_t psm;
	temperature_field_a_t rep;
	icd_raw_word_t raw;
};

union evo_xlru_temperature_union_t
{
	temperature_field_a_t pps;
	temperature_field_a_t lcu;
	icd_raw_word_t raw;
};

//Message B8: BIT Report Message
struct evo_bit_report_message_t
{
	//Word B8-01: BIT Report Label
	bit_report_label_union_t bit_report_label;

	//Word B8-02: BIT Report Date
	bit_report_date_union_t bit_report_date;

	//Word B8-03: BIT Report Time Tag
	time_of_mission_t bit_report_time_tag;

	//Word B8-04: Degradation Conditions (word 1)
	degradation_conditions_word_01_t degradation_conditions_word_01;

	//Word B8-05: Degradation Conditions (word 2)
	spare16_15_field_t degradation_conditions_word_02;

	//Word B8-06: Failure Location (Pedestal)
	failure_location_pedestal_t failure_location_lcu;

	//Word B8-07:
	failure_location_aesa_t failure_location_aesa;

	//Word B8-08: Failure Location (RX Front-End)
	failure_location_rx_front_end_t failure_location_rx_front_end;

	//Word B8-09: Failure Location (Receiver)
	failure_location_receiver_t failure_location_receiver;

	//Word B8-10: Failure Location (Transmitter)
	failure_location_transmitter_t failure_location_transmitter;

	//Word B8-11: Failure Location (Processor)
	failure_location_rep_t failure_location_processor;

	//Word B8-12: Signal Processor Test Results
        signal_processor_test_result_t lcu_test_result;

	//Word B8-13: Rx Module Test Results
	rx_module_test_results_t sp1_test_results;

	//Word B8-14: Data Processor Test Results
	data_processor_test_results_t rep_test_results;

	//Word B8-15: Post Processor Test Results
	post_processor_test_results_t dsp0_test_results;

	//Word B8-16: AGC Test Results
	agc_test_results_t dsp1_test_results;

	//Word B8-17: Power Supply Test Results
	power_supply_test_result_t power_supply_test_result;

	//Word B8-18: Servoloop Test Results
	servoloop_test_results_t servoloop_test_results;

	//Word B8-19: Transmitter Test Results (word 1)
	transmitter_test_result_word_01_t transmitter_test_result_word_01;

	//Word B8-20: Transmitter Test Results (word 2)
	transmitter_test_result_word_02_t transmitter_test_result_word_02;

	//Word B8-21: Receiver and Rx Front-End Test Results
	receiver_and_rx_front_end_test_results_t receiver_and_rx_front_end_test_results;

	//Word B8-22: Integrated System Test Results and LRU status
	integrated_system_test_results_and_lru_status_t integrated_system_test_results_and_lru_status;

        //Word B8-23: LCU2
        icd_raw_word_t         lcu_test_results_word_02;

	//Bite extension:

        icd_raw_word_t spare[3];
        icd_raw_word_t eif_sw_fails;
        icd_raw_word_t def_sw_fails;
        icd_raw_word_t dsp_sw_fails;
        evo_rep_temperature_union_t aesa_lcu_temperature;
        evo_rep_temperature_union_t rep_temperature;
        evo_xlru_temperature_union_t pps_temperature;

};


#include "idd_unpack.h"

//Messages traits:


typedef ::icd1553::icd1553_message_trait<icd1553::SA_B8_bit_report, evo_bit_report_message_t, 1>  evo_bit_report_message_trait;


}  //namespace icd1553


#endif /* EVO_B1553_ICD_TH_H_ */
