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

#ifndef B1553_ICD_TH_H_
#define B1553_ICD_TH_H_

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

#include "gc_math.h"

#include "th_b1553_icd_messages_id.h"

using namespace idd_codec;

namespace icd1553
{

IDD_VERSION(grifo_icd, "TH", 1, 0, "IDDxxxxx-48", "IRSxxxxx-48");

#define ICD1553_TIMETAG_MICROSECONDS_LSB	(64)

#include "idd_pack16.h"

//Some common constant
#define ICD1553_SEMICIRCLE_LSB	(3.05176E-05f)
#define ICD1553_SEMICIRCLE2_LSB	(5.96046E-08f)

#define ICD1553_SEMICIRCLE_RAD_LSB	(GC_K_PI*ICD1553_SEMICIRCLE_LSB)
#define ICD1553_SEMICIRCLE2_RAD_LSB	(GC_K_PI*ICD1553_SEMICIRCLE2_LSB)

typedef uint16_t icd_raw_word_t;
typedef uint32_t icd_raw_dword_t;

#define ICD_STATIC_CHECK_SIZE_WORD(type_, word_size_) IDD_STATIC_CHECK_SIZE(type_, (word_size_)*2)
#define ICD_STATIC_CHECK_OFFSET_WORD(struct_, member_, offset_) IDD_STATIC_CHECK_OFFSET(struct_, member_, 2*((offset_)-1))

typedef idd_bitfield_i16_t<IDD_REVBIT16(7), 8, int16_t> call_sign_character1_msw_t;
typedef idd_bitfield_i16_t<IDD_REVBIT16(15), 8, int16_t> call_sign_character2_msw_t;
typedef idd_bitfield_i16_t<IDD_REVBIT16(7), 8, int16_t> call_sign_character3_lsw_t;
typedef idd_bitfield_i16_t<IDD_REVBIT16(15), 8, int16_t> call_sign_character4_lsw_t;

//Message A1: Radar Operational Setting and Parameter Transfer

//Word A1-01: Radar Setting
enum target_history_t
{
	TARGET_HISTORY_LEVEL_01,
	TARGET_HISTORY_LEVEL_02,
	TARGET_HISTORY_LEVEL_03,
	TARGET_HISTORY_LEVEL_04,
};

typedef idd_bitfield_u16_t<IDD_REVBIT16(1), 2, target_history_t> tgt_history_level_field_t;

typedef idd_bitfield_u16_t<IDD_REVBIT16(8), 7, icd_raw_word_t> symb_intensity_field_t;

enum ground_target_rejected_radial_vel_t
{
	GROUND_TARGET_REJ_LOW,
	GROUND_TARGET_REJ_HIGH,
};
typedef idd_bitfield_u16_t<IDD_REVBIT16(9), 1, ground_target_rejected_radial_vel_t> ground_reject_vel_high_field_t;

enum min_detect_ground_tgt_radial_vel_t
{
	MIN_DETECT_GROUND_LOW,
	MIN_DETECT_GROUND_HIGH,
};
typedef idd_bitfield_u16_t<IDD_REVBIT16(10), 1, min_detect_ground_tgt_radial_vel_t> min_dectect_ground_radial_vel_high_field_t;

enum ale_blanking_t
{
	ALE_BLANKING_ENABLED,
	ALE_BLANKING_DISABLED
};
typedef idd_bitfield_u16_t<IDD_REVBIT16(11), 1, ale_blanking_t> ale_blanking_disable_field_t;

enum altitude_block_t
{
  BTBK,
  TPBK,
  NORMAL_BK,

  altitude_block_enum_max
};

typedef idd_bitfield_u16_t<IDD_REVBIT16(13), 2, altitude_block_t> altitude_block_field_t;

enum prf_lookup_selection_t
{
  LPRF,
  MPRF_LOOKUP
};

typedef idd_bitfield_u16_t<IDD_REVBIT16(14), 1, prf_lookup_selection_t> prf_lookup_selection_field_t;

typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 1, icd_raw_word_t> spare1_15_field_t;

//Word A1-01: Radar Setting
union rdr_settings_t
{
  tgt_history_level_field_t  history_level;
  symb_intensity_field_t sym_intensity;
  ground_reject_vel_high_field_t ground_reject_vel_high;
  min_dectect_ground_radial_vel_high_field_t min_dectect_ground_radial_vel_high;
  ale_blanking_disable_field_t ale_blanking_disable;
  altitude_block_field_t altitude_block;
  prf_lookup_selection_field_t prf_lookup_selection;

  spare1_15_field_t sett_spare15;

  icd_raw_word_t raw;
};

//Word A1-02: Frequency Agility Setting and Interleave selection

enum frequency_agility_type_t
{
  FIXED,
  RANDOM,
  ADAPTIVE,

  AGILITY_NOT_VALID,

  frequency_agility_enum_max
};

typedef idd_bitfield_u16_t<IDD_REVBIT16(1), 2, frequency_agility_type_t> frq_agility_field_t;

enum frequency_group_selector_tellback_t
{
	FREQUENCY_GROUP_NOT_ACTIVE,
	FREQUENCY_GROUP_ACTIVE
};

typedef idd_bitfield_u16_t<IDD_REVBIT16(2), 1, frequency_group_selector_tellback_t> frq_group1_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(3), 1, frequency_group_selector_tellback_t> frq_group2_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(4), 1, frequency_group_selector_tellback_t> frq_group3_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(5), 1, frequency_group_selector_tellback_t> frq_group4_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(6), 1, frequency_group_selector_tellback_t> frq_group5_field_t;

#define ICD1553_CHANNEL_MIN	1
#define ICD1553_CHANNEL_MAX	30

typedef idd_range_bitfield_t<ICD1553_CHANNEL_MIN, ICD1553_CHANNEL_MAX, IDD_REVBIT16(12), 6, unsigned int, uint16_t> frq_channel_field_t;

enum waveform_interleave_selection_tellback_t
{
	WAVEFORM_INT_SEL_SPARE,
	WAVEFORM_INT_01_SEL_SPARE,
	WAVEFORM_INT_02_SEL_SPARE,
	WAVEFORM_INT_03_SEL_SPARE,
};
typedef idd_bitfield_u16_t<IDD_REVBIT16(14), 2, waveform_interleave_selection_tellback_t> frq_waveform_interleave_field_t;

enum lprf_threshold_selection_tellback_t
{
	THRESHOLD_LOW,
	THRESHOLD_HIGH
};
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 1, lprf_threshold_selection_tellback_t> lprf_threshold_high_field_t;

//Word A1-02: Frequency Agility Setting and Interleave selection

union frequency_t {
  frq_agility_field_t agility;

  frq_group1_field_t g1;
  frq_group2_field_t g2;
  frq_group3_field_t g3;
  frq_group4_field_t g4;
  frq_group5_field_t g5;

  frq_channel_field_t channel;

  frq_waveform_interleave_field_t waveform;

  lprf_threshold_high_field_t lprf_threshold;

  icd_raw_word_t raw;
};


//Word A1-03: Beacon Delay and Code

typedef idd_bitfield_u16_t<IDD_REVBIT16(11), 12, unsigned int> becon_delay_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 4, unsigned int> becon_code_field_t;

union beacon_delay_and_code_t
{
  becon_delay_field_t delay;
  becon_code_field_t code;

  icd_raw_word_t raw;
};

//Word A1-04: Radar Gains and RF Channels Grouping Options

typedef idd_bitfield_u16_t<IDD_REVBIT16(6), 7, icd_raw_word_t> if_gain_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(13), 7, icd_raw_word_t> moving_target_gain_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(14), 1, bool> frq_group_option_field_t;

enum frequency_grouping_t
{
	FREQUENCY_GROUPING_OPTION_01,
	FREQUENCY_GROUPING_OPTION_02,
};

typedef idd_bitfield_u16_t<IDD_REVBIT16(14), 1, frequency_grouping_t> frequency_grouping_field_t;

typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 1, uint16_t> spare1_15_field_t ;

union gains_and_chgrp_t
{
  if_gain_field_t if_gain;
  moving_target_gain_field_t moving_target_gain;
  frequency_grouping_field_t frequency_grouping_field;

  spare1_15_field_t spare;

  icd_raw_word_t raw;
};

//Word A1-05: A/C Identifier

/*union ac_identifier_t {
  uint16_t ac_id;
  icd_raw_word_t raw;
};*/


typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 16, uint16_t> ac_identifier_t;

//Word A1-06: Date of Mission
#define ICD1553_YEAR_OF_MISSION_MIN	0
#define ICD1553_YEAR_OF_MISSION_MAX	63
typedef idd_range_bitfield_t<ICD1553_YEAR_OF_MISSION_MIN, ICD1553_YEAR_OF_MISSION_MAX, IDD_REVBIT16(5), 6, unsigned int, uint16_t> year_of_mission_t;

#define ICD1553_MONTH_OF_MISSION_MIN	1
#define ICD1553_MONTH_OF_MISSION_MAX	12
typedef idd_range_bitfield_t<ICD1553_MONTH_OF_MISSION_MIN, ICD1553_MONTH_OF_MISSION_MAX, IDD_REVBIT16(9), 4, unsigned int, uint16_t> month_of_mission_t;

#define ICD1553_DAY_OF_MISSION_MIN	1
#define ICD1553_DAY_OF_MISSION_MAX	31
typedef idd_range_bitfield_t<ICD1553_DAY_OF_MISSION_MIN, ICD1553_DAY_OF_MISSION_MAX, IDD_REVBIT16(14), 5, unsigned int, uint16_t> day_of_mission_t;

//Word A1-07: Time of Mission
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 16, uint16_t> time_of_mission_t;

//A1-08: Parameter identifier
enum parameter_transfer_enabled_t
{
	PAR_TRANSF_NOT_ACTIVE,
	PAR_TRANSF_ACTIVE
};

typedef idd_bitfield_u16_t<IDD_REVBIT16(0), 1, parameter_transfer_enabled_t> param_enable_field_t;

enum receive_transmit_selector_t
{
	SELECTOR_RECEIVE,
	SELECTOR_TRANSMIT
};
typedef idd_bitfield_u16_t<IDD_REVBIT16(1), 1, receive_transmit_selector_t> param_tx_field_t;

enum param_id_code_t
{
  param_antenna_haromization_yaw=1,
  param_antenna_haromization_pitch=2,
  param_antenna_haromization_roll=3,
  param_bulkhead_x_displacement=4,
  param_bulkhead_y_displacement=5,
  param_bulkhead_z_displacement=6,

  param_symbol_intensity_a=11,
  param_symbol_intensity_b=12,
  param_symbol_intensity_c=13,
  param_symbol_waveform_command=21,
  param_symbol_cutt_off_velocity=31,
  param_symbol_range_threshold_for_aws=41,
  param_symbol_test_01_for_new_modes=51,
  param_symbol_test_02_for_new_modes=52,
  param_symbol_test_03_for_new_modes=53,
  param_symbol_test_04_for_new_modes=54,
  param_symbol_white_level_for_sar_images=61,
  param_symbol_black_level_for_sar_images=62,
  param_symbol_pre_compression_factor_for_sar_images=63,
};

typedef idd_bitfield_u16_t<IDD_REVBIT16(9), 8, param_id_code_t> param_num_field_t;

#define ICD1553_PARAM_ANGLE_RAD_LSB (ICD1553_SEMICIRCLE_RAD_LSB)

IDD_FIXEDPOINT_TRAIT_DECLARATION(param_angle_lsb, float, ICD1553_PARAM_ANGLE_RAD_LSB, -1, 1, ICD1553_PARAM_ANGLE_RAD_LSB, ICD1553_PARAM_ANGLE_RAD_LSB);

typedef idd_fixedpoint<float, icd_raw_word_t, param_angle_lsb> param_angle_t;

typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 6, uint16_t> spare6_15_t;

union param_id_t
{
  param_enable_field_t enable;
  param_tx_field_t tx;
  param_num_field_t num;

  spare6_15_t spare;

  icd_raw_word_t raw;
};

typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 16, uint16_t> param_int_field_t;


union param_value_t
{
    param_int_field_t ivalue;
    param_angle_t angle;
    icd_raw_word_t raw;
};

typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 1, icd_raw_word_t> mission_time_mark_field_t;

union date_of_mission_t
{
	year_of_mission_t year_of_mission;
	month_of_mission_t month_of_mission;
	day_of_mission_t day_of_mission;

        mission_time_mark_field_t time_mark; //spare;

	icd_raw_word_t raw;
};

// Message A1: Radar Operational Setting and Parameter Transfer

struct msg_rdr_settings_and_parameters_t
{
	//WORD A1-01, radar settings
	rdr_settings_t settings;

	//WORD A1-02, Frequency Agility Setting and Interleave selection
	frequency_t frequency;

	//WORD A1-03, Beacon Delay and Code
	beacon_delay_and_code_t beacon;

	//Word A1-04: Radar Gains and RF Channels Grouping Options
	gains_and_chgrp_t gains_and_chgrp;

	//Word A1-05: A/C Identifier
	ac_identifier_t ac_id;

	//Word A1-06: Date of Mission
	date_of_mission_t date_of_mission;

	//Word A1-07: Time of Mission
	time_of_mission_t time_of_mission;

	//Word A1-08: Parameter Identifier
	param_id_t param_id;

	//TODO, Word A1-09/10: Parameter Value
    param_value_t param_value_1;

	//TODO, Word A1-09/10: Parameter Value
    param_value_t param_value_2;
};

ICD_STATIC_CHECK_SIZE_WORD(msg_rdr_settings_and_parameters_t, LEN_A1_rdr_operational_setting);


//Message A2: Radar Operation Command

//Word A2-01: Radar Mode Command

enum rdr_modes_t
{
  RWS=0,
  VS,
  ACM,
  TWS,
  MODE_SPARE_4=4,
  GM,
  SEA_LOW,
  SEA_HIGH,
  GMTI,
  BCN,
  AGR,
  TA,
  WA,
  TS,
  MODE_SPARE_14,
  RDR_DLY  //this is actually only a tell-back, a not command-able mode
};

enum des_control_t
{
  LOCK_ON,
  LOCK_ON_DTT,
  TRANS_HPT_BUT,
  REJECT,
  LOCK_ON_STT,
  DES_TRACK_LABEL,
  EXEC_SAR,
  NOT_VALID
};

enum ibit_request_t
{
  NORMAL=0,
  INT_BIT=1
};

enum stby_selection_t
{
  STBY_OFF,
  STBY_ON
};

typedef bool freeze_selection_t;
typedef bool stop_powerup_selection_t;
typedef bool emergency_selection_t;
typedef bool silence_selection_t;

enum sar_exec_selection_t
{
  SAR_ON_CURSOR,
  SAR_ON_SPOI
};

typedef idd_bitfield_u16_t<IDD_REVBIT16(3) , 4, rdr_modes_t> rdr_mode_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(6) , 3, des_control_t> des_control_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(7) , 1, ibit_request_t> ibit_request_field_t;
typedef idd_boolfield_u16_t<IDD_REVBIT16(8) , stby_selection_t> stby_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(9) , 1, freeze_selection_t> freeze_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(10), 1, stop_powerup_selection_t> stop_powerup_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(11), 1, icd_raw_word_t> reserved11_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(12), 1, silence_selection_t> silence_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(13), 1, sar_exec_selection_t> sar_exec_filed_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 2, icd_raw_word_t> spare2_15_field_t;

//Word A2-01: Radar Mode Command

union rdr_mode_command_word_t {
  rdr_mode_field_t master_mode;
  des_control_field_t des_ctrl;
  ibit_request_field_t ibit;
  stby_field_t stby;
  freeze_field_t freeze;
  stop_powerup_field_t stop_powerup;	//reserved
  reserved11_field_t reserved11;
  silence_field_t silence;	//reserved
  sar_exec_filed_t sar_type;

  spare2_15_field_t spare;

  icd_raw_word_t raw;
};

//Word A2-02: Radar Functions and Parameters (word#1)

enum rws_submode_t
{
  RWS_NAM,
  RWS_ASM
};

enum spot_selection_t
{
	SEL_NORMAL,
	SEL_SPOT
};

enum acm_submode_t
{
  BORESIGHT,
  NARROW,
  HUD,
  WIDE,
  VERTICAL,
  SLEWABLE,
  ACM_SPARE_6,
  ACM_SPARE_7
};

enum gm_submode_t
{
  GM_RBM,
  GM_DBS
};

enum expand_t
{
  EXP_NORMAL,
  EXPAND,
  EXP_SPARE2,
  EXP_SPARE3
};

enum range_scale_t
{
  NM80,
  NM40,
  NM20,
  NM10
};

enum bars_num_t
{
  BARS_1=0,
  BARS_2,
  BARS_SPARE,
  BARS_4
};

enum scan_width_t
{
  W60,
  W30,
  W25,
  W15
};

enum velocity_scale_t {
  KTS2400,
  KTS1200
};

typedef idd_bitfield_u16_t<IDD_REVBIT16(0), 1, rws_submode_t> rws_submode_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(1), 1, spot_selection_t> spot_selection_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(4), 3, acm_submode_t> acm_submode_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(5), 1, gm_submode_t> gm_submode_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(7), 2, expand_t> expand_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(9), 2, range_scale_t> range_scale_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(11), 2, bars_num_t> bars_num_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(13), 2, scan_width_t> scan_width_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(14), 1, velocity_scale_t> velocity_scale_field_t;

//Word A2-02: Radar Functions and Parameters (word#1)

union rdr_fun_and_param1_t {
  rws_submode_field_t rws_submode;
  spot_selection_field_t spot;
  acm_submode_field_t acm_submode;
  gm_submode_field_t gm_submode;
  expand_field_t expand;
  range_scale_field_t range_scale;
  bars_num_field_t bars_num;
  scan_width_field_t scan_width;
  velocity_scale_field_t velocity_scale;
  spare1_15_field_t spare;

  icd_raw_word_t raw;
};

//Word A2-03: Radar Functions and Parameters (word#2)

enum range_scale_extension_t	//TODO: so far not used
{
  NM_LEGACY,
  NM160,
  NM60,
  NM2_5
};

enum zoom_t
{
  ZOOM_NOT_ATIVE,
  ZOOM_IN,
  ZOOM_OUT,
  ZOOM_SPARE
};

enum sar_map_orientation_t
{
	SAR_AC_NOSE_REFERENCE,
	SAR_SLANT_CROSS_RANGE,
	NOT_USED_1,
	NOT_USED_2
};

typedef idd_bitfield_u16_t<IDD_REVBIT16(3), 4, icd_raw_word_t> spare0_4_field_t;

typedef idd_bitfield_u16_t<IDD_REVBIT16(5), 2, zoom_t> zoom_field_t;

typedef idd_bitfield_u16_t<IDD_REVBIT16(7), 2, sar_map_orientation_t> sar_map_orientation_field_t;

typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 8, icd_raw_word_t> spare8_15_field_t;

//Word A2-03: Radar Functions and Parameters (word#2)

union rdr_fun_and_param2_t {
  spare0_4_field_t spare_0_4;

  zoom_field_t zoom;
  sar_map_orientation_field_t sar_map_orientation;

  spare8_15_field_t spare_8_15;

  icd_raw_word_t raw;
};

//Message A2: Radar Operation Command

struct msg_rdr_operation_command_t
{
	//Word A2-01: Radar Mode Command
	rdr_mode_command_word_t rdr_mode_command;

	//Word A2-02: Radar Functions and Parameters (word#1)
	rdr_fun_and_param1_t param1;

	//Word A2-03: Radar Functions and Parameters (word#2)
	rdr_fun_and_param2_t param2;
};

ICD_STATIC_CHECK_SIZE_WORD(msg_rdr_operation_command_t, LEN_A2_rdr_operation_command);

//**A3: Graphic settings

//Word A3-01: Graphic Order
enum bulls_eye_identifier_t
{
	NO_BULLS_EYE,
	BULLS_EYE_WAYPOINT_01,
	BULLS_EYE_WAYPOINT_02,
	BULLS_EYE_WAYPOINT_03
};

typedef idd_bitfield_u16_t<IDD_REVBIT16(10), 2, bulls_eye_identifier_t> bulls_eye_identifier_field_t;

typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 5, icd_raw_word_t> spare5_15_field_t;

typedef idd_bitfield_u16_t<IDD_REVBIT16(0), 1, bool> waypoint_01_flag_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(1), 1, bool> waypoint_02_flag_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(2), 1, bool> waypoint_03_flag_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(3), 1, bool> intercept_flight_director_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(4), 1, bool> break_away_cue_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(5), 1, bool> intercept_zones_and_target_tip_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(6), 1, bool> time_to_go_to_cursor_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(7), 1, bool> allowable_steering_error_circle_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(8), 1, bool> attack_steering_cue_field_t;



union graphic_order_t
{
    waypoint_01_flag_field_t waypoint_01_flag;
    waypoint_02_flag_field_t waypoint_02_flag;
    waypoint_03_flag_field_t waypoint_03_flag;

    intercept_flight_director_field_t intercept_flight_director;
    break_away_cue_field_t break_away_cue;
    intercept_zones_and_target_tip_field_t intercept_zones_and_target_tip;
    time_to_go_to_cursor_field_t time_to_go_to_cursor;
    allowable_steering_error_circle_field_t allowable_steering_error_circle;
    attack_steering_cue_field_t attack_steering_cue;

	bulls_eye_identifier_field_t bulls_eye_identifier;

	spare5_15_field_t spare;
};

//Word A3-02: Time-to-Go to Cursor
//todo lsb
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 16, int16_t> time_to_go_to_cursor_t;

//Word A3-03/04: Waypoint 1 Latitude, Selector and Qualifier


//typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 16, int16_t> waypoint_lat_msw_t;
//typedef idd_bitfield_u16_t<IDD_REVBIT16(8), 9, int16_t> waypoint_lat_lsw_t;
//typedef idd_bitfield_u32_t<IDD_REVBIT32(24), 25, int32_t> waypoint_lat_t;

#define ICD1553_WAYPOINT_LATLON_LSB	((5.96046E-8f)*GC_K_PI)

IDD_FIXEDPOINT_TRAIT_LSB_DECLARATION(icd_waypoint_latlon_lsb, float, ICD1553_WAYPOINT_LATLON_LSB);
typedef idd_fixedpoint32_bitfield<IDD_REVBIT16(8), 25, icd_waypoint_latlon_lsb> waypoint_latlon_t;

//typedef idd_fixedpoint_bitfield<IDD_REVBIT16(0), 10, float, uint16_t, icd_cas_lsb> cas_t;

//IDD_FIXEDPOINT_TRAIT_LSB_DECLARATION(icd_semicircle2_lsb, float, ICD1553_SEMICIRCLE2_RAD_LSB);
//typedef idd_fixedpoint16x<float, int32_t, icd_semicircle2_lsb> semicircle2_t;
//typedef idd_bitfield_u32_t<IDD_REVBIT32(24), 25, semicircle2_t> waypoint_lat_t;

enum waypoint_fyt_selection_t
{
	WAYPOINT,
	FYT
};


typedef idd_bitfield_gap_low_t<IDD_REVBIT16(9), 1, waypoint_fyt_selection_t, uint16_t> waypoint_fyt_selection_field_t;

typedef idd_bitfield_gap_low_t<IDD_REVBIT16(10), 1, bool, uint16_t> waypoint_qualifier_validity_t;

enum waypoint_qualifier_value_t
{
	WAYPOINT_LEFT,
	WAYPOINT_RIGHT,
	WAYPOINT_DTK,
	WAYPOINT_MARK
};

typedef idd_bitfield_gap_low_t<IDD_REVBIT16(12), 2, waypoint_qualifier_value_t, uint16_t> waypoint_qualifier_value_field_t;

typedef idd_bitfield_gap_low_t<IDD_REVBIT16(15), 3, icd_raw_word_t, uint16_t> dspare3_15_field_t;

union waypoint_lat_sel_qual_t
{
	//waypoint_lat_msw_t waypoint_lat_msw;
	//waypoint_lat_lsw_t waypoint_lat_lsw;

	//waypoint_lat_t waypoint_lat;
	waypoint_latlon_t waypoint_lat;

	waypoint_fyt_selection_field_t waypoint_fyt_selection_field;

	waypoint_qualifier_validity_t waypoint_qualifier_validity;

	waypoint_qualifier_value_field_t waypoint_qualifier_value_field;

    dspare3_15_field_t spare;

    icd_raw_word_t raw[2];
};

//Word A3-05/06: Waypoint 1 Longitude and Code
//typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 16, int16_t> waypoint_lon_msw_t;
//typedef idd_bitfield_u16_t<IDD_REVBIT16(8), 9, int16_t> waypoint_lon_lsw_t;

//typedef idd_bitfield_u32_t<IDD_REVBIT32(24), 25, int32_t> waypoint_lon_t;

//typedef idd_bitfield_u32_t<IDD_REVBIT32(24), 25, semicircle2_t> waypoint_lon_t;

#define ICD1553_WAYPOINT_SYMBOL_MIN 0
#define ICD1553_WAYPOINT_SYMBOL_MAX	99
//typedef idd_range_bitfield_t<ICD1553_WAYPOINT_SYMBOL_MIN, ICD1553_WAYPOINT_SYMBOL_MAX, IDD_REVBIT16(15), 7, unsigned int, uint16_t> waypoint_code_t;
typedef idd_bitfield_gap_low_t<IDD_REVBIT16(15), 7, unsigned int, uint16_t> waypoint_code_t;

//typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 7, int16_t> waypoint_code_t;

union waypoint_lon_code_t
{
	waypoint_latlon_t waypoint_lon;
	waypoint_code_t waypoint_code;

	icd_raw_word_t raw[2];
};

//Word A3-15: Intercept Flight Director X and Selectors
//Y-Display coord. of the IFD symbol
//todo lsb
typedef idd_bitfield_u16_t<IDD_REVBIT16(8), 9, int16_t> display_coord_t;

typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 7, icd_raw_word_t> spare7_15_field_t;

typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 5, icd_raw_word_t> spare5_15_field_t;

enum intercept_mode_selector_t
{
	REAR,
	ALL
};

typedef idd_bitfield_u16_t<IDD_REVBIT16(9), 1, intercept_mode_selector_t> intercept_mode_selector_field_t;

enum normal_dashed_selector_t
{
	SELECTOR_NORMAL,
	SELECTOR_DASHED
};

typedef idd_bitfield_u16_t<IDD_REVBIT16(10), 1, normal_dashed_selector_t> normal_dashed_selector_field_t;

//Word A3-15: Intercept Flight Director X and Selectors
union intercept_flight_director_x_and_selectors_t
{
	display_coord_t x_display_coord_of_the_ifd_symbol;

	intercept_mode_selector_field_t intercept_mode_selector;

	normal_dashed_selector_field_t normal_dashed_selector;

	spare5_15_field_t spare;

	icd_raw_word_t raw;
};

//Word A3-16: Intercept Flight Director Y
union intercept_flight_director_y_t
{
	display_coord_t y_display_coord_of_the_ifd_symbol;
	spare7_15_field_t spare;

	icd_raw_word_t raw;
};

//Word A3-17: Intercept Zone Rmin
union intercept_zone_r_min_t
{
	display_coord_t y_display_coord_of_the_r_min_posit_of_the_intercept_zone;
	spare7_15_field_t spare;

	icd_raw_word_t raw;
};

//Word A3-18: Intercept Zone Rmax
union intercept_zone_r_max_t
{
	display_coord_t y_display_coord_of_the_r_max_posit_of_the_intercept_zone;
	spare7_15_field_t spare;

	icd_raw_word_t raw;
};

//Word A3-19: No Escape Zone Rmax
union no_escape_zone_r_max_t
{
	display_coord_t y_display_coord_of_the_r_max_posit_of_the_no_escape_zone;
	spare7_15_field_t spare;

	icd_raw_word_t raw;
};

//Word A3-20: Intercept Zone Target Tip
union intercept_zone_target_tip_t
{
	display_coord_t y_display_coord_of_the_intercept_zone_target_tip;
	spare7_15_field_t spare;

	icd_raw_word_t raw;
};

//Radius of the ASEC
//todo lsb
typedef idd_bitfield_u16_t<IDD_REVBIT16(8), 9, int16_t> radius_of_the_asec_t;

enum asec_blink_normal_t
{
	ASEC_NORMAL,
	ASEC_BLINK
};
typedef idd_bitfield_u16_t<IDD_REVBIT16(9), 1, asec_blink_normal_t> normal_blink_selector_t;

typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 6, icd_raw_word_t> spare6_15_field_t;

//Word A3-21: Allowable Steering Error Circle (ASEC) Radius and Selector
union asec_radius_and_selector_t
{
	radius_of_the_asec_t radius_of_the_asec;
	normal_blink_selector_t normal_blink_selector;
	spare6_15_field_t spare;

	icd_raw_word_t raw;
};

//Word A3-22: Attack Steering Cue (ASC) X and Selector
union asc_x_and_selector_t
{
	display_coord_t x_display_coord_of_the_asc_symbol;
	normal_blink_selector_t normal_blink_selector;
	spare6_15_field_t spare;

	icd_raw_word_t raw;
};

//Word A3-23: Attack Steering Cue (ASC) Y
union asc_y_t
{
	display_coord_t y_display_coord_of_the_asc_symbol;
	spare7_15_field_t spare;

	icd_raw_word_t raw;
};

//Word A3-24: Tracked Target Info (Intercept and Data Link)
typedef idd_bitfield_u16_t<IDD_REVBIT16(0), 1, bool> hpt_within_intercept_zone_selector_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(1), 1, bool> hpt_data_link_correlation_selector_t;

enum friend_foe_selector_t
{
	FRIEND,
	FOE
};
typedef idd_bitfield_u16_t<IDD_REVBIT16(2), 1, friend_foe_selector_t> hpt_friend_foe_selector_field_t;

typedef idd_bitfield_u16_t<IDD_REVBIT16(3), 1, bool> spt_within_intercept_zone_selector_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(4), 1, bool> spt_data_link_correlation_selector_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(5), 1, friend_foe_selector_t> spt_friend_foe_selector_field_t;

typedef idd_bitfield_u16_t<IDD_REVBIT16(6), 1, bool> tws_tracket_tgt_01_within_int_zone_selector_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(7), 1, bool> tws_tracket_tgt_02_within_int_zone_selector_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(8), 1, bool> tws_tracket_tgt_03_within_int_zone_selector_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(9), 1, bool> tws_tracket_tgt_04_within_int_zone_selector_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(10), 1, bool> tws_tracket_tgt_05_within_int_zone_selector_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(11), 1, bool> tws_tracket_tgt_06_within_int_zone_selector_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(12), 1, bool> tws_tracket_tgt_07_within_int_zone_selector_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(13), 1, bool> tws_tracket_tgt_08_within_int_zone_selector_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(14), 1, bool> tws_tracket_tgt_09_within_int_zone_selector_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 1, bool> tws_tracket_tgt_10_within_int_zone_selector_t;

typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 2, icd_raw_word_t> spare2_15_field_t;

union tracked_target_info_t
{
	hpt_within_intercept_zone_selector_t hpt_within_intercept_zone_selector;
	hpt_data_link_correlation_selector_t hpt_data_link_correlation_selector;
	hpt_friend_foe_selector_field_t hpt_friend_foe_selector_field;

	spt_within_intercept_zone_selector_t spt_within_intercept_zone_selector;
	spt_data_link_correlation_selector_t spt_data_link_correlation_selector;
	spt_friend_foe_selector_field_t spt_friend_foe_selector_field;

    tws_tracket_tgt_01_within_int_zone_selector_t tws_tracket_tgt_01_within_int_zone_selector;
    tws_tracket_tgt_02_within_int_zone_selector_t tws_tracket_tgt_02_within_int_zone_selector;
    tws_tracket_tgt_03_within_int_zone_selector_t tws_tracket_tgt_03_within_int_zone_selector;
    tws_tracket_tgt_04_within_int_zone_selector_t tws_tracket_tgt_04_within_int_zone_selector;
    tws_tracket_tgt_05_within_int_zone_selector_t tws_tracket_tgt_05_within_int_zone_selector;
    tws_tracket_tgt_06_within_int_zone_selector_t tws_tracket_tgt_06_within_int_zone_selector;
    tws_tracket_tgt_07_within_int_zone_selector_t tws_tracket_tgt_07_within_int_zone_selector;
    tws_tracket_tgt_08_within_int_zone_selector_t tws_tracket_tgt_08_within_int_zone_selector;

    tws_tracket_tgt_09_within_int_zone_selector_t tws_tracket_tgt_09_within_int_zone_selector;
    tws_tracket_tgt_10_within_int_zone_selector_t tws_tracket_tgt_10_within_int_zone_selector;
	//spare2_15_field_t spare;

	icd_raw_word_t raw;
};

//Word A3-25/26: HPT Call Sign
union hpt_call_sign_t
{
	call_sign_character1_msw_t character1;
	call_sign_character2_msw_t character2;
	call_sign_character3_lsw_t character3;
	call_sign_character4_lsw_t character4;

	icd_raw_word_t raw[2];
};

//Word A3-27/28: SPT Call Sign
/*union spt_call_sign_t
{
	call_sign_character1_msw_t character1;
	call_sign_character2_msw_t character2;
	call_sign_character3_lsw_t character3;
	call_sign_character4_lsw_t character4;

	icd_raw_word_t raw[2];
};*/

//Word A3-27: Reserved
union a3_27_reserved_t
{
	icd_raw_word_t raw;
};

typedef idd_bitfield_u16_t<IDD_REVBIT16(7), 8, int16_t>	track_id_of_tws_tracked_tgt_xx_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 8, int16_t> track_id_of_tws_tracked_tgt_yy_t;

//Word A3-28: Track Id of TWS Tracked Targets 09 and 10
union track_id_of_tws_tracked_targets_09_and_10_t
{
	track_id_of_tws_tracked_tgt_xx_t track_id_of_tws_tracked_tgt_09;
	track_id_of_tws_tracked_tgt_yy_t track_id_of_tws_tracked_tgt_10;

	icd_raw_word_t raw;
};

//Word A3-29: Track Id of TWS Tracked Targets 01 and 02
union track_id_of_tws_tracked_targets_01_and_02_t
{
	track_id_of_tws_tracked_tgt_xx_t track_id_of_tws_tracked_tgt_01;
	track_id_of_tws_tracked_tgt_yy_t track_id_of_tws_tracked_tgt_02;

	icd_raw_word_t raw;
};

//Word A3-30: Track Id of TWS Tracked Targets 03 and 04
union track_id_of_tws_tracked_targets_03_and_04_t
{
	track_id_of_tws_tracked_tgt_xx_t track_id_of_tws_tracked_tgt_03;
	track_id_of_tws_tracked_tgt_yy_t track_id_of_tws_tracked_tgt_04;

	icd_raw_word_t raw;
};

//Word A3-31: Track Id of TWS Tracked Targets 05 and 06
union track_id_of_tws_tracked_targets_05_and_06_t
{
	track_id_of_tws_tracked_tgt_xx_t track_id_of_tws_tracked_tgt_05;
	track_id_of_tws_tracked_tgt_yy_t track_id_of_tws_tracked_tgt_06;

	icd_raw_word_t raw;
};

//Word A3-32: Track Id of TWS Tracked Targets 07 and 08
union track_id_of_tws_tracked_targets_07_and_08_t
{
	track_id_of_tws_tracked_tgt_xx_t track_id_of_tws_tracked_tgt_07;
	track_id_of_tws_tracked_tgt_yy_t track_id_of_tws_tracked_tgt_08;

	icd_raw_word_t raw;
};

//Message A3: Graphic Settings

struct waypoint_data_t
{
	//Word A3-03/04: Waypoint 1 Latitude, Selector and Qualifier
	waypoint_lat_sel_qual_t waypoint_lat_sel_qual;

	//Word A3-05/06: Waypoint 1 Longitude and Code
	waypoint_lon_code_t waypoint_lon_code;
};

struct waypoint_data_array_t
{
    waypoint_data_t wp[3];
};

struct msg_graphic_setting_t
{
	//Word A3-01: Graphic Order
	graphic_order_t graphic_order;

	//Word A3-02: Time-to-Go to Cursor
	time_to_go_to_cursor_t time_to_go_to_cursor;

	waypoint_data_array_t waypoints;

#if 0
	//Word A3-03/04: Waypoint 1 Latitude, Selector and Qualifier
	waypoint_lat_sel_qual_t waypoint_01_lat_sel_qual;

	//Word A3-05/06: Waypoint 1 Longitude and Code
	waypoint_lon_code_t waypoint_01_lon_code;

	//Word A3-07/08: Waypoint 2 Latitude, Selector and Qualifier
	waypoint_lat_sel_qual_t waypoint_02_lat_sel_qual;

	//Word A3-09/10: Waypoint 2 Longitude and Code
	waypoint_lon_code_t waypoint_02_lon_code;

	//Word A3-11/12: Waypoint 3 Latitude, Selector and Qualifier
	waypoint_lat_sel_qual_t waypoint_03_lat_sel_qual;

	//Word A3-13/14: Waypoint 3 Longitude and Code
	waypoint_lon_code_t waypoint_03_lon_code;
#endif

	//Word A3-15: Intercept Flight Director X and Selectors
	intercept_flight_director_x_and_selectors_t intercept_flight_director_x_and_selectors;

	//Word A3-16: Intercept Flight Director Y
	intercept_flight_director_y_t intercept_flight_director_y;

	//Word A3-17: Intercept Zone Rmin
	intercept_zone_r_min_t intercept_zone_r_min;

	//Word A3-18: Intercept Zone Rmax
	intercept_zone_r_max_t intercept_zone_r_max;

	//Word A3-19: No Escape Zone Rmax
	no_escape_zone_r_max_t no_escape_zone_r_max;

	//Word A3-20: Intercept Zone Target Tip
	intercept_zone_target_tip_t intercept_zone_target_tip;

	//Word A3-21: Allowable Steering Error Circle (ASEC) Radius and Selector
	asec_radius_and_selector_t asec_radius_and_selector;

	//Word A3-22: Attack Steering Cue (ASC) X and Selector
	asc_x_and_selector_t asc_x_and_selector;

	//Word A3-23: Attack Steering Cue (ASC) Y
	asc_y_t asc_y;

	//Word A3-24: Tracked Target Info (Intercept and Data Link)
	tracked_target_info_t tracked_target_info;

	//Word A3-25/26: HPT Call Sign
	hpt_call_sign_t hpt_call_sign;

	//Word A3-27/28: SPT Call Sign
	//spt_call_sign_t spt_call_sign;

	//Word A3-27 - reserved
	a3_27_reserved_t a3_27_reserved;

	//Word A3-28: Track Id of TWS Tracked Targets 09 and 10
	track_id_of_tws_tracked_targets_09_and_10_t track_id_of_tws_tracked_targets_09_and_10;

	//Word A3-29: Track Id of TWS Tracked Targets 01 and 02
	track_id_of_tws_tracked_targets_01_and_02_t track_id_of_tws_tracked_targets_01_and_02;

	//Word A3-30: Track Id of TWS Tracked Targets 03 and 04
	track_id_of_tws_tracked_targets_03_and_04_t track_id_of_tws_tracked_targets_03_and_04;

	//Word A3-31: Track Id of TWS Tracked Targets 05 and 06
	track_id_of_tws_tracked_targets_05_and_06_t track_id_of_tws_tracked_targets_05_and_06;

	//Word A3-32: Track Id of TWS Tracked Targets 07 and 08
	track_id_of_tws_tracked_targets_07_and_08_t track_id_of_tws_tracked_targets_07_and_08;
};

ICD_STATIC_CHECK_SIZE_WORD(msg_graphic_setting_t, LEN_A3_graphic_settings);

//**A4: Navigation Data and Acquisition Cursor Data

//typedef icd_raw_word_t relative_timetag_t;
//IDD_FIXEDPOINT_TRAIT_DECLARATION(icd_timetag_lsb, float, 0.064f, 0, 4000.0f, 0.064f, 0.064f);
//typedef idd_fixedpoint<float, icd_raw_word_t, icd_timetag_lsb> relative_timetag_t;

typedef idd_scaled_integer<uint32_t, icd_raw_word_t, ICD1553_TIMETAG_MICROSECONDS_LSB> relative_timetag_t;

#define ICD1553_ACCELERATION_FEET_LSB	(0.03125)
#define ICD1553_ACCELERATION_METERS_LSB	(ICD1553_ACCELERATION_FEET_LSB/GC_K_METERS_TO_FEETS)

IDD_FIXEDPOINT_TRAIT_LSB_DECLARATION(icd_acceleration_lsb, float, ICD1553_ACCELERATION_METERS_LSB);
typedef idd_fixedpoint<float, int16_t, icd_acceleration_lsb> acceleration_t;

IDD_FIXEDPOINT_TRAIT_LSB_DECLARATION(icd_semicircle_lsb, float, ICD1553_SEMICIRCLE_RAD_LSB);
typedef idd_fixedpoint<float, int16_t, icd_semicircle_lsb> semicircle_t;

#define ICD1553_TAS_KNOTS_LSB	(0.125f)
#define ICD1553_TAS_MS_LSB	(ICD1553_TAS_KNOTS_LSB*GC_K_KNOTS_TO_MS)

IDD_FIXEDPOINT_TRAIT_LSB_DECLARATION(icd_tas_lsb, float, ICD1553_TAS_MS_LSB);
typedef idd_fixedpoint<float, int16_t, icd_tas_lsb> tas_t;

#define ICD1553_CAS_KNOTS_LSB	(1.0)
#define ICD1553_CAS_MS_LSB	(ICD1553_CAS_KNOTS_LSB*GC_K_KNOTS_TO_MS)

IDD_FIXEDPOINT_TRAIT_LSB_DECLARATION(icd_cas_lsb, float, ICD1553_CAS_MS_LSB);
//typedef idd_fixedpoint<float, int16_t, icd_cas_lsb> cas_t;
typedef idd_fixedpoint_bitfield<IDD_REVBIT16(9), 10, float, uint16_t, icd_cas_lsb> cas_t;

#define ICD1553_BARO_ALT_FEET_LSB	(4.0)
#define ICD1553_BARO_ALT_METERS_LSB	(ICD1553_BARO_ALT_FEET_LSB*GC_K_FEETS_TO_METERS)

IDD_FIXEDPOINT_TRAIT_LSB_DECLARATION(icd_baro_altitude_lsb, float, ICD1553_BARO_ALT_METERS_LSB);
typedef idd_fixedpoint<float, int16_t, icd_baro_altitude_lsb> baro_altitude_t;

#define ICD1553_RADIO_ALT_FEET_LSB	(2.0)
#define ICD1553_RADIO_ALT_METERS_LSB	(ICD1553_RADIO_ALT_FEET_LSB*GC_K_FEETS_TO_METERS)

IDD_FIXEDPOINT_TRAIT_LSB_DECLARATION(icd_radio_altitude_lsb, float, ICD1553_RADIO_ALT_METERS_LSB);
typedef idd_fixedpoint<float, int16_t, icd_radio_altitude_lsb> radio_altitude_t;

#define ICD1553_SPOI_ALT_FEET_LSB	(1.0)
#define ICD1553_SPOI_ALT_METERS_LSB	(ICD1553_SPOI_ALT_FEET_LSB*GC_K_FEETS_TO_METERS)

IDD_FIXEDPOINT_TRAIT_LSB_DECLARATION(icd_spoi_altitude_lsb, float, ICD1553_SPOI_ALT_METERS_LSB);
typedef idd_fixedpoint<float, int16_t, icd_spoi_altitude_lsb> spoi_altitude_t;

#define ICD1553_GEOPOS_SC_LSB	(4.65661E-10)
#define ICD1553_GEOPOS_RAD_LSB	(ICD1553_GEOPOS_SC_LSB*GC_K_PI)

IDD_FIXEDPOINT_TRAIT_LSB_DECLARATION(icd_latlong_altitude_lsb, float, ICD1553_GEOPOS_RAD_LSB);
typedef idd_fixedpoint16x<float, int32_t, icd_latlong_altitude_lsb> latlong_t;

#define ICD1553_CRS_SLAVE_RNG_METERS_LSB	(8*GC_K_FEETS_TO_METERS)

IDD_FIXEDPOINT_TRAIT_LSB_DECLARATION(icd_crs_range_slave_lsb, float, ICD1553_CRS_SLAVE_RNG_METERS_LSB);
typedef idd_fixedpoint<float, uint16_t, icd_crs_range_slave_lsb> crs_slave_range_t;

template<unsigned int POS_> struct nav_data_invalid_field_t: public idd_bitfield_u16_t<IDD_REVBIT16(POS_), 1, bool> {};

typedef idd_bitfield_u16_t<IDD_REVBIT16(0), 1, bool> navigation_invalid_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(1), 1, bool> attitude_invalid_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(2), 1, bool> baro_intertial_altitude_invalid_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(3), 1, bool> correct_baro_altitude_invalid_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(4), 1, bool> radio_altimeter_invalid_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(5), 1, bool> spoi_altitude_invalid_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(6), 1, bool> spoi_position_invalid_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(7), 1, bool> tas_invalid_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(8), 1, bool> cas_invalid_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(9), 1, bool> present_position_invalid_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(10), 1, bool> ant_slew_valid_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(11), 1, bool> crs_rate_invalid_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(12), 1, bool> crs_slave_selector_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(13), 1, bool> crs_zero_valid_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(14), 1, bool> crs_snowplough_valid_field_t;


union a4_validity_and_slew_t	// Word A4-01: Validity and Slew Data
{
	navigation_invalid_t navigation_invalid;
    attitude_invalid_t attitude_invalid;
    baro_intertial_altitude_invalid_t baro_intertial_altitude_invalid;
    correct_baro_altitude_invalid_t correct_baro_altitude_invalid;
    radio_altimeter_invalid_t radio_altimeter_invalid;
    spoi_altitude_invalid_t spoi_altitude_invalid;
    spoi_position_invalid_t spoi_position_invalid;
    tas_invalid_t tas_invalid;
    cas_invalid_t cas_invalid;
    present_position_invalid_t present_position_invalid;

	ant_slew_valid_field_t ant_slew_valid;
	crs_rate_invalid_field_t crs_rate_invalid;
	crs_slave_selector_field_t crs_normal_slave;
	crs_zero_valid_field_t crs_zero_valid_field;
	crs_snowplough_valid_field_t crs_snowplough_valid_field;

	icd_raw_word_t raw;
};

//A5-19: Rate of motion of acquisition cursor x
typedef idd_bitfield_i16_t<IDD_REVBIT16(8), 9, int16_t> crs_motion_rate_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(9), 1, bool> crs_ghost_selector_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(10), 1, bool> crs_dtt_selector_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(11), 1, bool> crs_sar_selector_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 1, bool> crs_abs_pos_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(8), 9, unsigned int> crs_motion_abs_field_t;

//typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 16, int16_t> clearance_plane_distance_t;
typedef idd_scaled_integer<uint32_t, icd_raw_word_t, 1> clearance_plane_distance_t;

#define ICD1553_WIND_KNOTS_LSB	(0.0625)
#define ICD1553_WIND_MS_LSB	(ICD1553_WIND_KNOTS_LSB*GC_K_KNOTS_TO_MS)
IDD_FIXEDPOINT_TRAIT_LSB_DECLARATION(icd_wind_lsb, float, ICD1553_WIND_MS_LSB);
typedef idd_fixedpoint_bitfield<IDD_REVBIT16(12), 13, float, uint16_t, icd_wind_lsb> wind_speed_t;


union crs_motion_x_t {
  crs_motion_rate_field_t rate;
  crs_ghost_selector_field_t ghost;
  crs_dtt_selector_field_t dtt;
  crs_sar_selector_field_t sar;

  crs_motion_abs_field_t abs_pos;
  crs_abs_pos_field_t abs;

  icd_raw_word_t raw;
};

//A4-20: Rate of motion of acq cursor y

union crs_motion_y_t {
  crs_motion_rate_field_t rate;

  crs_motion_abs_field_t abs_pos;

  icd_raw_word_t raw;
};

//Message A4: Navigation Data and Acquisition Cursor Data

struct msg_nav_data_and_cursor_t
{
	//Word A4-01: Validity and Slew Data
	a4_validity_and_slew_t validity_and_slew;

	//Word A4-02: Time Tag
	relative_timetag_t timetag;

	//Word A4-03: Present True Heading
	semicircle_t true_heading;

	//Word A4-04: Present Magnetic Heading
	semicircle_t magnetic_heading;

	//Word A4-05: X Acceleration
	acceleration_t x_acceleration;

	//Word A4-06: Y Acceleration
	acceleration_t y_acceleration;

	//Word A4-07: Z Acceleration
	acceleration_t z_acceleration;

	//Word A4-08: True Air Speed (DADC)
	tas_t true_air_speed;

	//Word A4-09: Ownship Calibrated Air Speed
	cas_t calibrated_air_speed;

	//Word A4-10: Barometric / Inertial Altitude
	baro_altitude_t baro_altitude;

	//Word A4-11: Corrected Barometric Altitude
	baro_altitude_t corrected_baro_altitude;

	//Word A4-12: Radio Altimeter Altitude
	radio_altitude_t radio_altitude;

	//Word A4-13: SPOI Altitude Above Sea Level
	spoi_altitude_t spoi_baro_altitude;

	//Word A4-14: Clearance Plane Distance
    clearance_plane_distance_t clearance_plane_distance;

	//Word A4-15: Wind Direction
	semicircle_t wind_direction;

	//Word A4-16: Wind Speed
	wind_speed_t wind_speed;

	//Word A4-17: AZ Antenna Demand
	semicircle_t az_antenna_demand;

	//Word A4-18: EL Antenna Demand
	semicircle_t el_antenna_demand;

	//Word A4-19: Rate of Motion of Acquisition Cursor X and Selectors
	crs_motion_x_t acq_crs_x;

	//Word A4-20: Rate of Motion of Acquisition Cursor Y
	crs_motion_y_t acq_crs_y;

	//Word A4-21: Acquisition Cursor - Range
	crs_slave_range_t acq_crs_rng;

	//Word A4-22: Acquisition Cursor - Azimuth
	semicircle_t acq_crs_az;

	//Word A4-23: Present Position Data Time Tag
	relative_timetag_t ppos_timetag;

	//Word A4-24/25: Present Position Latitude
	latlong_t ppos_lat;

	//Word A4-26/27: Present Position Longitude
	latlong_t ppos_lon;

	//Word A4-28/29: SPOI Latitude
	latlong_t spoi_lat;

	//Word A4-30/31: SPOI Longitude
	latlong_t spoi_lon;
};

ICD_STATIC_CHECK_SIZE_WORD(msg_nav_data_and_cursor_t, LEN_A4_navigation_andcursor_data);

//**A5: INU High Speed Vector

#define ICD1553_VELOCITY_FEET_LSB (3.81470E-06)
#define ICD1553_VELOCITY_METERS_LSB	(ICD1553_VELOCITY_FEET_LSB*GC_K_FEETS_TO_METERS)

IDD_FIXEDPOINT_TRAIT_LSB_DECLARATION(icd_velocity_lsb, float, ICD1553_VELOCITY_METERS_LSB);
typedef idd_fixedpoint16x<float, int32_t, icd_velocity_lsb> velocity_t;

#define ICD1553_ATTITUDE_RATE_SC_LSB (1.22070E-04)
#define ICD1553_ATTITUDE_RATE_RAD_LSB	(ICD1553_ATTITUDE_RATE_SC_LSB*GC_K_PI)

IDD_FIXEDPOINT_TRAIT_LSB_DECLARATION(attitude_rate_lsb, float, ICD1553_ATTITUDE_RATE_RAD_LSB);

typedef idd_fixedpoint<float, int16_t, attitude_rate_lsb> attitude_rate_t;

#define ICD1553_ANGULAR_RATE_SC_LSB (2.44141E-04)
#define ICD1553_ALGULAR_RATE_RAD_LSB	(ICD1553_ANGULAR_RATE_SC_LSB*GC_K_PI)

IDD_FIXEDPOINT_TRAIT_LSB_DECLARATION(angular_rate_lsb, float, ICD1553_ALGULAR_RATE_RAD_LSB);

typedef idd_fixedpoint<float, int16_t, angular_rate_lsb> ang_acc_t;

//Message A5: INU High Speed Vector

struct msg_inu_high_speed_t
{
	//Word A5-01: INU Mode Word, ignorata dal radar
	icd_raw_word_t mode_word;

	//Word A5-02: INU Control Word 2 (Time Tag)
	relative_timetag_t timetag;

	//Word A5-03/04: X Velocity
	velocity_t x_vel;

	//Word A5-05/06: Y Velocity
	velocity_t y_vel;

	//Word A5-07/08: Z Velocity
	velocity_t z_vel;

	//Word A5-09: Platform Azimuth
	semicircle_t platform_azimuth;

	//Word A5-10: Roll
	semicircle_t roll;

	//Word A5-11: Pitch
	semicircle_t pitch;

	//Word A5-12: Roll Rate
	attitude_rate_t roll_rate;

	//Word A5-13: Pitch Rate
	attitude_rate_t pitch_rate;

	//Word A5-14: Yaw Rate
	attitude_rate_t yaw_rate;

	//Word A5-15: Longitudinal Acceleration (nx)
	acceleration_t longitudinal_acc;

	//Word A5-16: Lateral Acceleration (ny)
	acceleration_t lateral_acc;

	//Word A5-17: Normal Acceleration (nz)
	acceleration_t normal_acc;

	//Word A5-18: Platform Azimuth Time Tag
	relative_timetag_t ptaz_tt;

	//Word A5-19: Roll Time Tag
	relative_timetag_t roll_tt;

	//Word A5-20: Pitch Time Tag
	relative_timetag_t pitch_tt;

	//Word A5-21: Roll Axis Angular Acceleration
	ang_acc_t roll_ang_acc;

	//Word A5-22: Pitch Axis Angular Acceleration
	ang_acc_t pitch_ang_acc;

	//Word A5-23: Yaw Axis Angular Acceleration
	ang_acc_t yaw_ang_acc;
};

ICD_STATIC_CHECK_SIZE_WORD(msg_inu_high_speed_t, LEN_A5_inu_high_speed_vector);

//**A6: N/A

//**A7: Data Link Targets (Message#1)

//A7-01: DL Targets Validity
enum dl_target_validity_t
{
	DL_TGT_VALIDITY_NOT_ACTIVE,
	DL_TGT_VALIDITY_ACTIVE
};

typedef idd_bitfield_u16_t<IDD_REVBIT16(0), 1, dl_target_validity_t> dl_target_validity_01_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(1), 1, dl_target_validity_t> dl_target_validity_02_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(2), 1, dl_target_validity_t> dl_target_validity_03_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(3), 1, dl_target_validity_t> dl_target_validity_04_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(4), 1, dl_target_validity_t> dl_target_validity_05_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(5), 1, dl_target_validity_t> dl_target_validity_06_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(6), 1, dl_target_validity_t> dl_target_validity_07_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(7), 1, dl_target_validity_t> dl_target_validity_08_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(8), 1, dl_target_validity_t> dl_target_validity_09_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(9), 1, dl_target_validity_t> dl_target_validity_10_field_t;

typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 6, icd_raw_word_t> spare6_15_field_t;

union dl_target_xx_validity_t	// Word A7-01: DL Targets Validity
{
        dl_target_validity_01_field_t dl_target_validity_01;
        dl_target_validity_02_field_t dl_target_validity_02;
        dl_target_validity_03_field_t dl_target_validity_03;
        dl_target_validity_04_field_t dl_target_validity_04;
        dl_target_validity_05_field_t dl_target_validity_05;
        dl_target_validity_06_field_t dl_target_validity_06;
        dl_target_validity_07_field_t dl_target_validity_07;
        dl_target_validity_08_field_t dl_target_validity_08;
        dl_target_validity_09_field_t dl_target_validity_09;
        dl_target_validity_10_field_t dl_target_validity_10;

	spare6_15_field_t spare;

        icd_raw_word_t raw;
};

//A7-02,  A7-08, A7-14, A7-20, A7-26: Target 01/02/03/04/05 Position X
//TODO lsb
//typedef idd_bitfield_i16_t<IDD_REVBIT16(15), 16, int16_t> target_position_x_t;

#define ICD1553_DL_POSITION_METERS_LSB	float(1/32767)

IDD_FIXEDPOINT_TRAIT_DECLARATION(dl_position_lsb, float, ICD1553_DL_POSITION_METERS_LSB, -1, 1, ICD1553_DL_POSITION_METERS_LSB, ICD1553_DL_POSITION_METERS_LSB);

typedef idd_fixedpoint<float, icd_raw_word_t, dl_position_lsb> target_position_x_t;

//A7-03,  A7-09, A7-15, A7-21, A7-27: Target 01/02/03/04/05 Position Y
//TODO lsb
//typedef idd_bitfield_i16_t<IDD_REVBIT16(15), 16, int16_t> target_position_y_t;
typedef idd_fixedpoint<float, icd_raw_word_t, dl_position_lsb> target_position_y_t;

//A7-04,  A7-10, A7-16, A7-22, A7-28: Target 01/02/03/04/05 Ground Track Angle
//TODO lsb
//typedef idd_bitfield_i16_t<IDD_REVBIT16(15), 16, int16_t> target_ground_track_angle_t;
typedef semicircle_t target_ground_track_angle_t;

//A7-05,  A7-11, A7-17, A7-23, A7-29: Target 01/02/03/04/05 Presentation Data

//Type of Target 01/02/03/04/05
enum dl_target_type_selector_t
{
	DL_TARGET,
	DL_HIGH_PRIORITY_TARGET, 	//HPL
	DL_MEMBER,
	DL_HIGH_PRIORITY_MEMBER 	//HPM
};

typedef idd_bitfield_i16_t<IDD_REVBIT16(1), 2, dl_target_type_selector_t> dl_target_type_selector_field_t;

//Velocity of Target 01/02/03/04/05
//TODO lsb
typedef idd_bitfield_i16_t<IDD_REVBIT16(3), 2, int16_t> velocity_of_target_t;


//Altitude of Target 01/02/03/04/05
//TODO lsb
typedef idd_bitfield_i16_t<IDD_REVBIT16(11), 7, int16_t> altitude_of_target_t;

//Target 01/02/03/04/05 within Intercept Zone selector
//TODO lsb
typedef idd_bitfield_i16_t<IDD_REVBIT16(12), 1, bool> intercept_zone_selector_t;

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

union target_presentation_data_t
{
	dl_target_type_selector_field_t dl_target_type_selector;
	velocity_of_target_t velocity_of_target;
	altitude_of_target_t altitude_of_target;
	intercept_zone_selector_t intercept_zone_selector;
	spare3_15_field_t spare;
        icd_raw_word_t raw;
};

//A7-06/07,  A7-12/13, A7-18/19, A7-24/25, A7-30/31: Target 01/02/03/04/05 Call Sign
union target_call_sign_t
{
	call_sign_character1_msw_t character1_msw;
	call_sign_character2_msw_t character2_msw;
	call_sign_character3_lsw_t character3_lsw;
	call_sign_character4_lsw_t character4_lsw;
        icd_raw_word_t raw;
};

union target_half_call_sign_t
{
	call_sign_character1_msw_t character1_msw;
	call_sign_character2_msw_t character2_msw;
        icd_raw_word_t raw;
};

//Message A7: Data Link Targets (Message#1)
struct data_link_target_t
{
	target_position_x_t	tgt_pos_x;
	target_position_y_t	tgt_pos_y;
	target_ground_track_angle_t tgt_ground_track_angle;
	target_presentation_data_t tgt_presentation_data;
	target_half_call_sign_t	tgt_call_sign[2];
};

struct msg1_data_link_target_t
{
	dl_target_xx_validity_t dl_target_validity;
#if 0
	data_link_target_t dl[5];
#else
	target_position_x_t	tgt_01_pos_x;
	target_position_y_t	tgt_01_pos_y;
	target_ground_track_angle_t tgt_01_ground_track_angle;
	target_presentation_data_t tgt_01_presentation_data;
        target_half_call_sign_t	tgt_01_call_sign[2];//
        //target_call_sign_t	tgt_01_call_sign;

	target_position_x_t	tgt_02_pos_x;
	target_position_y_t	tgt_02_pos_y;
	target_ground_track_angle_t tgt_02_ground_track_angle;
	target_presentation_data_t tgt_02_presentation_data;
        target_half_call_sign_t	tgt_02_call_sign[2];//
        //target_call_sign_t	tgt_02_call_sign;

	target_position_x_t	tgt_03_pos_x;
	target_position_y_t	tgt_03_pos_y;
	target_ground_track_angle_t tgt_03_ground_track_angle;
	target_presentation_data_t tgt_03_presentation_data;
        target_half_call_sign_t	tgt_03_call_sign[2];//
        //target_call_sign_t	tgt_03_call_sign;

	target_position_x_t	tgt_04_pos_x;
	target_position_y_t	tgt_04_pos_y;
	target_ground_track_angle_t tgt_04_ground_track_angle;
	target_presentation_data_t tgt_04_presentation_data;
        target_half_call_sign_t	tgt_04_call_sign[2];//
        //target_call_sign_t	tgt_04_call_sign;

	target_position_x_t	tgt_05_pos_x;
	target_position_y_t	tgt_05_pos_y;
	target_ground_track_angle_t tgt_05_ground_track_angle;
	target_presentation_data_t tgt_05_presentation_data;
        target_half_call_sign_t	tgt_05_call_sign[2];//
        //target_call_sign_t	tgt_05_call_sign;
#endif
};

ICD_STATIC_CHECK_SIZE_WORD(msg1_data_link_target_t, LEN_A7_data_link_targets_1);

//**A8: Data link targets

//Message A8: Data Link Targets (Message#2)
struct msg2_data_link_target_t
{
#if 0
	data_link_target_t dl[5];
#else
	target_position_x_t	tgt_06_pos_x;
	target_position_y_t	tgt_06_pos_y;
	target_ground_track_angle_t tgt_06_ground_track_angle;
	target_presentation_data_t tgt_06_presentation_data;
        target_half_call_sign_t	tgt_06_call_sign[2];//
        //target_call_sign_t	tgt_06_call_sign;

	target_position_x_t	tgt_07_pos_x;
	target_position_y_t	tgt_07_pos_y;
	target_ground_track_angle_t tgt_07_ground_track_angle;
	target_presentation_data_t tgt_07_presentation_data;
        target_half_call_sign_t	tgt_07_call_sign[2];//
        //target_call_sign_t	tgt_07_call_sign;

	target_position_x_t	tgt_08_pos_x;
	target_position_y_t	tgt_08_pos_y;
	target_ground_track_angle_t tgt_08_ground_track_angle;
	target_presentation_data_t tgt_08_presentation_data;
        target_half_call_sign_t	tgt_08_call_sign[2];//
        //target_call_sign_t	tgt_08_call_sign;

	target_position_x_t	tgt_09_pos_x;
	target_position_y_t	tgt_09_pos_y;
	target_ground_track_angle_t tgt_09_ground_track_angle;
	target_presentation_data_t tgt_09_presentation_data;
        target_half_call_sign_t	tgt_09_call_sign[2];//
        //target_call_sign_t	tgt_09_call_sign;

	target_position_x_t	tgt_10_pos_x;
	target_position_y_t	tgt_10_pos_y;
	target_ground_track_angle_t tgt_10_ground_track_angle;
	target_presentation_data_t tgt_10_presentation_data;
        target_half_call_sign_t	tgt_10_call_sign[2];//
        //target_call_sign_t	tgt_10_call_sign;
#endif
};

ICD_STATIC_CHECK_SIZE_WORD(msg2_data_link_target_t, LEN_A8_data_link_targets_2);

//Message A9: Reserved RX Message
struct msg_reserved_t
{
	icd_raw_word_t raw[32];
};

ICD_STATIC_CHECK_SIZE_WORD(msg_reserved_t, LEN_A9_reserved_debug);

//TODO Message A20: reserved development message (da aggiungere al documento)
struct msg_dev0_reserved_t
{
	icd_raw_word_t marker;

	icd_raw_word_t dbg_ctrl;

	icd_raw_word_t dbg_mode;

	icd_raw_word_t gc_dbg_ctrl;
	icd_raw_word_t gc_dbg_crs_xy;


	icd_raw_word_t raw[32-5];
};

ICD_STATIC_CHECK_SIZE_WORD(msg_dev0_reserved_t, 32);

//****** TX Messages

//todo Message B1: TWS Status and Targets 1 and 2

//Word B1-01: Validity Word and HPT Identifier

enum tws_target_validity_t
{
	TWS_NOT_ACTIVE,
	TWS_ACTIVE
};

typedef idd_bitfield_u16_t<IDD_REVBIT16(0), 1, tws_target_validity_t> tws_target_01_validity_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(1), 1, tws_target_validity_t> tws_target_02_validity_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(2), 1, tws_target_validity_t> tws_target_03_validity_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(3), 1, tws_target_validity_t> tws_target_04_validity_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(4), 1, tws_target_validity_t> tws_target_05_validity_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(5), 1, tws_target_validity_t> tws_target_06_validity_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(6), 1, tws_target_validity_t> tws_target_07_validity_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(7), 1, tws_target_validity_t> tws_target_08_validity_field_t;

enum tws_target_which_t
{
	TARGET_01_HPT,
	TARGET_02_HPT,
	TARGET_03_HPT,
	TARGET_04_HPT,
	TARGET_05_HPT,
	TARGET_06_HPT,
	TARGET_07_HPT,
	TARGET_08_HPT,
	HPT_NOT_PRESENT
};

typedef idd_bitfield_u16_t<IDD_REVBIT16(11), 4, tws_target_which_t> tws_target_which_field_t;

typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 4, icd_raw_word_t> spare4_15_field_t;

union valitidy_word_and_hpt_identifier_t
{
	tws_target_01_validity_field_t track_01_validity;
	tws_target_02_validity_field_t track_02_validity;
	tws_target_03_validity_field_t track_03_validity;
	tws_target_04_validity_field_t track_04_validity;
	tws_target_05_validity_field_t track_05_validity;
	tws_target_06_validity_field_t track_06_validity;
	tws_target_07_validity_field_t track_07_validity;
	tws_target_08_validity_field_t track_08_validity;

	tws_target_which_field_t tws_target_which_field;

	spare4_15_field_t spare;

	icd_raw_word_t raw;
};

//Word B1-02: Track Priority (Targets 01 to 04)

enum track_priority_t
{
	PRIORITY_LEVEL_1,
	PRIORITY_LEVEL_2,
	PRIORITY_LEVEL_3,
	PRIORITY_LEVEL_4,
	PRIORITY_LEVEL_5,
	PRIORITY_LEVEL_6,
	PRIORITY_LEVEL_7,
	PRIORITY_LEVEL_8
};

typedef idd_bitfield_u16_t<IDD_REVBIT16(2), 3, track_priority_t> track_01_priority_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(5), 3, track_priority_t> track_02_priority_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(8), 3, track_priority_t> track_03_priority_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(11), 3, track_priority_t> track_04_priority_field_t;

typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 4, icd_raw_word_t> spare4_15_field_t;

union track_priority_01_04_t
{
	track_01_priority_field_t track_01_priority_field;
	track_02_priority_field_t track_02_priority_field;
	track_03_priority_field_t track_03_priority_field;
	track_04_priority_field_t track_04_priority_field;

	spare4_15_field_t spare;

	icd_raw_word_t raw;
};

//Word B1-03: Track Priority (Targets 05 to 08)
typedef idd_bitfield_u16_t<IDD_REVBIT16(2), 3, track_priority_t> track_05_priority_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(5), 3, track_priority_t> track_06_priority_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(8), 3, track_priority_t> track_07_priority_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(11), 3, track_priority_t> track_08_priority_field_t;

union track_priority_05_08_t
{
	track_05_priority_field_t track_05_priority_field;
	track_06_priority_field_t track_06_priority_field;
	track_07_priority_field_t track_07_priority_field;
	track_08_priority_field_t track_08_priority_field;

	spare4_15_field_t spare;

	icd_raw_word_t raw;
};

//Word B1-04: Track Accuracy (Targets 01 to 04)
enum target_accurancy_t
{
	TARGET_ACCURANCY_LEVEL_0,
	TARGET_ACCURANCY_LEVEL_1,
	TARGET_ACCURANCY_LEVEL_2,
	TARGET_ACCURANCY_LEVEL_3
};

typedef idd_bitfield_u16_t<IDD_REVBIT16(1), 2, target_accurancy_t> track_01_position_accurancy_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(3), 2, target_accurancy_t> track_01_velocity_accurancy_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(5), 2, target_accurancy_t> track_02_position_accurancy_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(7), 2, target_accurancy_t> track_02_velocity_accurancy_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(9), 2, target_accurancy_t> track_03_position_accurancy_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(11), 2, target_accurancy_t> track_03_velocity_accurancy_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(13), 2, target_accurancy_t> track_04_position_accurancy_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 2, target_accurancy_t> track_04_velocity_accurancy_t;

union track_accurancy_01_04_t
{
	track_01_position_accurancy_t track_01_position_accurancy;
	track_01_velocity_accurancy_t track_01_velocity_accurancy;
	track_02_position_accurancy_t track_02_position_accurancy;
	track_02_velocity_accurancy_t track_02_velocity_accurancy;
	track_03_position_accurancy_t track_03_position_accurancy;
	track_03_velocity_accurancy_t track_03_velocity_accurancy;
	track_04_position_accurancy_t track_04_position_accurancy;
	track_04_velocity_accurancy_t track_04_velocity_accurancy;

	icd_raw_word_t raw;
};

//Word B1-05: Track Accuracy (Targets 05 to 08)
typedef idd_bitfield_u16_t<IDD_REVBIT16(1), 2, target_accurancy_t> track_05_position_accurancy_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(3), 2, target_accurancy_t> track_05_velocity_accurancy_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(5), 2, target_accurancy_t> track_06_position_accurancy_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(7), 2, target_accurancy_t> track_06_velocity_accurancy_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(9), 2, target_accurancy_t> track_07_position_accurancy_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(11), 2, target_accurancy_t> track_07_velocity_accurancy_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(13), 2, target_accurancy_t> track_08_position_accurancy_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 2, target_accurancy_t> track_08_velocity_accurancy_t;

union track_accurancy_05_08_t
{
	track_05_position_accurancy_t track_05_position_accurancy;
	track_05_velocity_accurancy_t track_05_velocity_accurancy;
	track_06_position_accurancy_t track_06_position_accurancy;
	track_06_velocity_accurancy_t track_06_velocity_accurancy;
	track_07_position_accurancy_t track_07_position_accurancy;
	track_07_velocity_accurancy_t track_07_velocity_accurancy;
	track_08_position_accurancy_t track_08_position_accurancy;
	track_08_velocity_accurancy_t track_08_velocity_accurancy;

	icd_raw_word_t raw;
};

//Word B1-06: Track Id of TWS Tracked targets 01 and 02
typedef idd_bitfield_u16_t<IDD_REVBIT16(7), 8, int32_t> track_id_of_tws_tracked_tgt_a_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 8, int32_t> track_id_of_tws_tracked_tgt_b_t;

union track_id_of_tws_tracked_target_01_02_t
{
	track_id_of_tws_tracked_tgt_a_t track_id_of_tws_tracked_tgt_01;
	track_id_of_tws_tracked_tgt_b_t track_id_of_tws_tracked_tgt_02;
	icd_raw_word_t raw;
};

//Word B1-07: Track Id of TWS Tracked targets 03 and 04
union track_id_of_tws_tracked_target_03_04_t
{
	track_id_of_tws_tracked_tgt_a_t track_id_of_tws_tracked_tgt_03;
	track_id_of_tws_tracked_tgt_b_t track_id_of_tws_tracked_tgt_04;
	icd_raw_word_t raw;
};

//Word B1-08: Track Id of TWS Tracked targets 05 and 06
union track_id_of_tws_tracked_target_05_06_t
{
	track_id_of_tws_tracked_tgt_a_t track_id_of_tws_tracked_tgt_05;
	track_id_of_tws_tracked_tgt_b_t track_id_of_tws_tracked_tgt_06;
	icd_raw_word_t raw;
};

//Word B1-09: Track Id of TWS Tracked targets 07 and 08
union track_id_of_tws_tracked_target_07_08_t
{
	track_id_of_tws_tracked_tgt_a_t track_id_of_tws_tracked_tgt_07;
	track_id_of_tws_tracked_tgt_b_t track_id_of_tws_tracked_tgt_08;
	icd_raw_word_t raw;
};

//Word B1-10: HPT X Display Coordinate
#define ICD1553_DISPLAY_PIXEL_MIN 0
#define ICD1553_DISPLAY_PIXEL_MAX 483
typedef idd_range_bitfield_t<ICD1553_DISPLAY_PIXEL_MIN, ICD1553_DISPLAY_PIXEL_MAX, IDD_REVBIT16(8), 9, unsigned int, uint16_t> display_coord_htp_target_t;

typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 7, icd_raw_word_t> spare7_15_field_t;

union x_display_coord_of_the_hpt_target_t
{
	display_coord_htp_target_t display_coord_htp_target;

	spare7_15_field_t spare;

	icd_raw_word_t raw;
};

//Word B1-11: HPT Y Display Coordinate
union y_display_coord_of_the_hpt_target_t
{
	display_coord_htp_target_t display_coord_htp_target;

	spare7_15_field_t spare;

	icd_raw_word_t raw;
};

//Word B1-13: Target 01 Range
//Word B1-22: Target 02 Range
//todo lsb
//typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 16, int16_t> range_of_tracked_target_t;
#define ICD1553_TARGET_RANGE_FEET_LSB	(8)
#define ICD1553_TARGET_RANGE_METERS_LSB	(ICD1553_TARGET_RANGE_FEET_LSB/GC_K_METERS_TO_FEETS)

IDD_FIXEDPOINT_TRAIT_LSB_DECLARATION(target_range_lsb, float, ICD1553_TARGET_RANGE_METERS_LSB);
typedef idd_fixedpoint<float, uint16_t, target_range_lsb> range_of_tracked_target_t;

//Word B1-14: Target 01 Position X
//Word B1-23: Target 02 Position X
//Word B1-15: Target 01 Position Y
//Word B1-24: Target 02 Position Y
#define ICD1553_TWS_POS_XY_LSB  16.0f

IDD_FIXEDPOINT_TRAIT_DECLARATION(tws_pos_xy_lsb, float, ICD1553_TWS_POS_XY_LSB, -1, 1, ICD1553_TWS_POS_XY_LSB, ICD1553_TWS_POS_XY_LSB);

typedef idd_fixedpoint<float, int16_t, tws_pos_xy_lsb> tws_xy_t;



//Word B1-16: Target 01 Position Z
//Word B1-25: Target 02 Position Z
#define ICD1553_TWS_POS_Z_LSB  2.5f

IDD_FIXEDPOINT_TRAIT_DECLARATION(tws_pos_z_lsb, float, ICD1553_TWS_POS_Z_LSB, -1, 1, ICD1553_TWS_POS_Z_LSB, ICD1553_TWS_POS_Z_LSB);

typedef idd_fixedpoint<float, int16_t, tws_pos_z_lsb> tws_z_t;


//Word B1-17: Target 01 Velocity (magnitude)
//Word B1-26: Target 02 Velocity (magnitude)
#define ICD1553_TWS_VEL_MAGNITUDE_FEET_LSB 0.0625f
#define ICD1553_TWS_VEL_MAGNITUDE_METERS_LSB (0.0625f/GC_K_METERS_TO_FEETS)

IDD_FIXEDPOINT_TRAIT_LSB_DECLARATION(tws_vel_magnitude_lsb, float, ICD1553_TWS_VEL_MAGNITUDE_METERS_LSB); //, 0, 1, ICD1553_TWS_VEL_MAGNITUDE_LSB, ICD1553_TWS_VEL_MAGNITUDE_LSB);

typedef idd_fixedpoint<float, uint16_t, tws_vel_magnitude_lsb> target_velocity_magnitude_t;

//#define ICD1553_VEL_MAGN_MIN 0
//#define ICD1553_VEL_MAGN_MAX 4000
//typedef idd_range_bitfield_t<ICD1553_VEL_MAGN_MIN, ICD1553_VEL_MAGN_MAX, IDD_REVBIT16(15), 16, unsigned int, uint16_t> velocity_magnitude_t;


//Word B1-18: Target 01 Velocity X
//Word B1-19: Target 01 Velocity Y
//Word B1-20: Target 01 Velocity Z
//Word B1-27: Target 02 Velocity X
//Word B1-28: Target 02 Velocity Y
//Word B1-29: Target 02 Velocity Z
#define ICD1553_TWS_VEL_LSB 0.125f

IDD_FIXEDPOINT_TRAIT_DECLARATION(tws_vel_lsb, float, ICD1553_TWS_VEL_LSB, -1, 1, ICD1553_TWS_VEL_LSB, ICD1553_TWS_VEL_LSB);

typedef idd_fixedpoint<float, int16_t, tws_vel_lsb> tws_velocity_t;


//Message B1: TWS Status and Targets 1 and 2
struct tws_status_and_targets_01_02_t
{
	//Word B1-01: Validity Word and HPT Identifier
	valitidy_word_and_hpt_identifier_t valitidy_word_and_hpt_identifier;

	//Word B1-02: Track Priority (Targets 01 to 04)
	track_priority_01_04_t track_priority_01_04;

	//Word B1-03: Track Priority (Targets 05 to 08)
	track_priority_05_08_t track_priority_05_08;

	//Word B1-04: Track Accuracy (Targets 01 to 04)
	track_accurancy_01_04_t track_accurancy_01_04;

	//Word B1-05: Track Accuracy (Targets 05 to 08)
	track_accurancy_05_08_t track_accurancy_05_08;

	//Word B1-06: Track Id of TWS Tracked targets 01 and 02
	track_id_of_tws_tracked_target_01_02_t track_id_of_tws_tracked_target_01_02;

	//Word B1-07: Track Id of TWS Tracked targets 03 and 04
	track_id_of_tws_tracked_target_03_04_t track_id_of_tws_tracked_target_03_04;

	//Word B1-08: Track Id of TWS Tracked targets 05 and 06
	track_id_of_tws_tracked_target_05_06_t track_id_of_tws_tracked_target_05_06;

	//Word B1-09: Track Id of TWS Tracked targets 07 and 08
	track_id_of_tws_tracked_target_07_08_t track_id_of_tws_tracked_target_07_08;

	//Word B1-10: HPT X Display Coordinate
	x_display_coord_of_the_hpt_target_t x_display_coord_of_the_hpt_target;

	//Word B1-11: HPT Y Display Coordinate
	y_display_coord_of_the_hpt_target_t y_display_coord_of_the_hpt_target;

	//Word B1-12: Target 01 Time Tag
	relative_timetag_t time_tag_of_tracked_target_01_data;

	//Word B1-13: Target 01 Range
	range_of_tracked_target_t range_of_tracked_01_target;

	//Word B1-14: Target 01 Position X
	tws_xy_t target_01_position_x;

	//Word B1-15: Target 01 Position Y
	tws_xy_t target_01_position_y;

	//Word B1-16: Target 01 Position Z
	tws_z_t target_01_position_z;

	//Word B1-17: Target 01 Velocity (magnitude)
	target_velocity_magnitude_t target_01_velocity_magnitude;

	//Word B1-18: Target 01 Velocity X
	tws_velocity_t target_01_velocity_x;

	//Word B1-19: Target 01 Velocity Y
	tws_velocity_t target_01_velocity_y;

	//Word B1-20: Target 01 Velocity Z
	tws_velocity_t target_01_velocity_z;

	//Word B1-21: Target 02 Time Tag
	relative_timetag_t time_tag_of_tracked_target_02_data;

	//Word B1-22: Target 02 Range
	range_of_tracked_target_t range_of_tracked_02_target;

	//Word B1-23: Target 02 Position X
	tws_xy_t target_02_position_x;

	//Word B1-24: Target 02 Position Y
	tws_xy_t target_02_position_y;

	//Word B1-25: Target 02 Position Z
	tws_z_t target_02_position_z;

	//Word B1-26: Target 02 Velocity (magnitude)
	target_velocity_magnitude_t target_02_velocity_magnitude;

	//Word B1-27: Target 02 Velocity X
	tws_velocity_t target_02_velocity_x;

	//Word B1-28: Target 02 Velocity Y
	tws_velocity_t target_02_velocity_y;

	//Word B1-29: Target 02 Velocity Z
	tws_velocity_t target_02_velocity_z;
};

ICD_STATIC_CHECK_SIZE_WORD(tws_status_and_targets_01_02_t, LEN_B1_tws_status_1_2);

//Message B2: TWS Targets 3, 4, 5
struct tws_status_and_targets_03_04_05_t
{
	//Word B2-01: Target 03 Time Tag
	relative_timetag_t time_tag_of_tracked_target_03_data;

	//Word B2-02: Target 03 Range
	range_of_tracked_target_t range_of_tracked_03_target;

	//Word B2-03: Target 03 Position X
	tws_xy_t target_03_position_x;

	//Word B2-04: Target 03 Position Y
	tws_xy_t target_03_position_y;

	//Word B2-05: Target 03 Position Z
	tws_z_t target_03_position_z;

	//Word B2-06: Target 03 Velocity (magnitude)
	target_velocity_magnitude_t target_03_velocity_magnitude;

	//Word B2-07: Target 03 Velocity X
	tws_velocity_t target_03_velocity_x;

	//Word B2-08: Target 03 Velocity Y
	tws_velocity_t target_03_velocity_y;

	//Word B2-09: Target 03 Velocity Z
	tws_velocity_t target_03_velocity_z;

	//Word B2-10: Target 04 Time Tag
	relative_timetag_t time_tag_of_tracked_target_04_data;

	//Word B2-11: Target 04 Range
	range_of_tracked_target_t range_of_tracked_04_target;

	//Word B2-12: Target 04 Position X
	tws_xy_t target_04_position_x;

	//Word B2-13: Target 04 Position Y
	tws_xy_t target_04_position_y;

	//Word B2-14: Target 04 Position Z
	tws_z_t target_04_position_z;

	//Word B2-15: Target 04 Velocity (magnitude)
	target_velocity_magnitude_t target_04_velocity_magnitude;

	//Word B2-16: Target 04 Velocity X
	tws_velocity_t target_04_velocity_x;

	//Word B2-17: Target 04 Velocity Y
	tws_velocity_t target_04_velocity_y;

	//Word B2-18: Target 04 Velocity Z
	tws_velocity_t target_04_velocity_z;

	//Word B2-19: Target 05 Time Tag
	relative_timetag_t time_tag_of_tracked_target_05_data;

	//Word B2-20: Target 05 Range
	range_of_tracked_target_t range_of_tracked_05_target;

	//Word B2-21: Target 05 Position X
	tws_xy_t target_05_position_x;

	//Word B2-22: Target 05 Position Y
	tws_xy_t target_05_position_y;

	//Word B2-23: Target 05 Position Z
	tws_z_t target_05_position_z;

	//Word B2-24: Target 05 Velocity (magnitude)
	target_velocity_magnitude_t target_05_velocity_magnitude;

	//Word B2-25: Target 05 Velocity X
	tws_velocity_t target_05_velocity_x;

	//Word B2-26: Target 05 Velocity Y
	tws_velocity_t target_05_velocity_y;

	//Word B2-27: Target 05 Velocity Z
	tws_velocity_t target_05_velocity_z;
};

ICD_STATIC_CHECK_SIZE_WORD(tws_status_and_targets_03_04_05_t, LEN_B2_tws_status_3_4_5);

//Message B3: TWS Targets 6, 7, 8
struct tws_status_and_targets_06_07_08_t
{
	//Word B3-01: Target 06 Time Tag
	relative_timetag_t time_tag_of_tracked_target_06_data;

	//Word B3-02: Target 06 Range
	range_of_tracked_target_t range_of_tracked_06_target;

	//Word B3-03: Target 06 Position X
	tws_xy_t target_06_position_x;

	//Word B3-04: Target 06 Position Y
	tws_xy_t target_06_position_y;

	//Word B3-05: Target 06 Position Z
	tws_z_t target_06_position_z;

	//Word B3-06: Target 06 Velocity (magnitude)
	target_velocity_magnitude_t target_06_velocity_magnitude;

	//Word B3-07: Target 06 Velocity X
	tws_velocity_t target_06_velocity_x;

	//Word B3-08: Target 06 Velocity Y
	tws_velocity_t target_06_velocity_y;

	//Word B3-09: Target 06 Velocity Z
	tws_velocity_t target_06_velocity_z;

	//Word B3-10: Target 07 Time Tag
	relative_timetag_t time_tag_of_tracked_target_07_data;

	//Word B3-11: Target 07 Range
	range_of_tracked_target_t range_of_tracked_07_target;

	//Word B3-12: Target 07 Position X
	tws_xy_t target_07_position_x;

	//Word B3-13: Target 07 Position Y
	tws_xy_t target_07_position_y;

	//Word B3-14: Target 07 Position Z
	tws_z_t target_07_position_z;

	//Word B3-15: Target 07 Velocity (magnitude)
	target_velocity_magnitude_t target_07_velocity_magnitude;

	//Word B3-16: Target 07 Velocity X
	tws_velocity_t target_07_velocity_x;

	//Word B3-17: Target 07 Velocity Y
	tws_velocity_t target_07_velocity_y;

	//Word B3-18: Target 07 Velocity Z
	tws_velocity_t target_07_velocity_z;

	//Word B3-19: Target 08 Time Tag
	relative_timetag_t time_tag_of_tracked_target_08_data;

	//Word B3-20: Target 08 Range
	range_of_tracked_target_t range_of_tracked_08_target;

	//Word B3-21: Target 08 Position X
	tws_xy_t target_08_position_x;

	//Word B3-22: Target 08 Position Y
	tws_xy_t target_08_position_y;

	//Word B3-23: Target 08 Position Z
	tws_z_t target_08_position_z;

	//Word B3-24: Target 08 Velocity (magnitude)
	target_velocity_magnitude_t target_08_velocity_magnitude;

	//Word B3-25: Target 08 Velocity X
	tws_velocity_t target_08_velocity_x;

	//Word B3-26: Target 08 Velocity Y
	tws_velocity_t target_08_velocity_y;

	//Word B3-27: Target 08 Velocity Z
	tws_velocity_t target_08_velocity_z;
};

ICD_STATIC_CHECK_SIZE_WORD(tws_status_and_targets_06_07_08_t, LEN_B3_tws_status_6_7_8);


//TODO Message B4: SPT Target Message

//Word B4-01: Track Validity and Status Word #1
typedef idd_bitfield_u16_t<IDD_REVBIT16(0), 1, bool> range_validity_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(1), 1, bool> position_z_y_z_validity_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(2), 1, bool> range_rate_validity_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(3), 1, bool> velocity_data_validity_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(4), 1, bool> acceleration_data_validity_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(5), 1, bool> aspect_validity_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(6), 1, bool> cas_and_mach_number_validity_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(7), 1, icd_raw_word_t> spare1_7_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(8), 1, bool> display_coordinates_validity_t;

enum accurancy_level_t
{
	ACCURANCY_LELEL_0,
	ACCURANCY_LELEL_1,
	ACCURANCY_LELEL_2,
	ACCURANCY_LELEL_3
};

typedef idd_bitfield_u16_t<IDD_REVBIT16(10), 2, accurancy_level_t> position_accurancy_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(12), 2, accurancy_level_t> velocity_accurancy_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(14), 2, accurancy_level_t> acceleration_accurancy_t;

typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 1, icd_raw_word_t> spare1_15_field_t;

union b4_track_validity_and_status_word_01_t
{
	range_validity_t range_validity;
	position_z_y_z_validity_t position_z_y_z_validity;
	range_rate_validity_t range_rate_validity;
	velocity_data_validity_t velocity_data_validity;
	acceleration_data_validity_t acceleration_data_validity;
	aspect_validity_t aspect_validity;
	cas_and_mach_number_validity_t cas_and_mach_number_validity;
	spare1_7_field_t spare7;
	display_coordinates_validity_t display_coordinates_validity;
	position_accurancy_t position_accurancy;
	velocity_accurancy_t velocity_accurancy;
	acceleration_accurancy_t acceleration_accurancy;
	spare1_15_field_t spare15;

	icd_raw_word_t raw;
};

//Word B4-02: Track Validity and Status Word #2
typedef idd_bitfield_u16_t<IDD_REVBIT16(0), 1, bool> reacquisition_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(1), 1, bool> target_in_coast_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(2), 1, bool> hoj_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(3), 1, bool> aoj_t;

enum normalization_factor_6_lev_t
{
	NORMALIZATION_FACTOR_6_LEV_0,
	NORMALIZATION_FACTOR_6_LEV_1,
	NORMALIZATION_FACTOR_6_LEV_2,
	NORMALIZATION_FACTOR_6_LEV_3,
	NORMALIZATION_FACTOR_6_LEV_4,
	NORMALIZATION_FACTOR_6_LEV_5
};

typedef idd_bitfield_u16_t<IDD_REVBIT16(6), 3, normalization_factor_6_lev_t> normalization_factor_for_target_position_x_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(9), 3, normalization_factor_6_lev_t> normalization_factor_for_target_position_y_t;

enum normalization_factor_4_lev_t
{
	NORMALIZATION_FACTOR_4_LEV_0,
	NORMALIZATION_FACTOR_4_LEV_1,
	NORMALIZATION_FACTOR_4_LEV_2,
	NORMALIZATION_FACTOR_4_LEV_3,
};

typedef idd_bitfield_u16_t<IDD_REVBIT16(11), 2, normalization_factor_4_lev_t> normalization_factor_for_target_position_z_t;

typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 4, icd_raw_word_t> spare4_15_field_t;

union b4_track_validity_and_status_word_02_t
{
	reacquisition_t reacquisition;
	target_in_coast_t target_in_coast;
	hoj_t hoj;
	aoj_t aoj;
	normalization_factor_for_target_position_x_t normalization_factor_for_target_position_x;
	normalization_factor_for_target_position_y_t normalization_factor_for_target_position_y;
	normalization_factor_for_target_position_z_t normalization_factor_for_target_position_z;

	spare4_15_field_t spare;

	icd_raw_word_t raw;
};

//Word B4-06: Normalized Target Position Y
//Word B4-05: Normalized Target Position X
//Word B4-07: Normalized Target Position Z
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 16, uint16_t> normalized_target_position_t;

//Word B4-08: Target Range Rate
//todo lsb
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 16, uint16_t> range_rate_of_the_tracked_target_t;

//Word B4-09: Target Velocity (Magnitude)
//todo lsb
//typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 16, uint16_t> target_velocity_magnitude_t;

//Word B4-10: Target Velocity X
//Word B4-11: Target Velocity Y
//Word B4-12: Target Velocity Z
//todo lsb
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 16, uint16_t> target_velocity_t;

//Word B4-13: Target Acceleration (Magnitude)
//todo lsb
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 16, uint16_t> target_acceleration_magnitude_t;

//Word B4-17: Target Aspect Angle
//todo lsb
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 16, uint16_t> target_aspect_angle_t;

//Word B4-18: Target CAS
//todo lsb
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 16, uint16_t> target_cas_t;

//Word B4-19: Target Mach Number
//todo lsb
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 16, uint16_t> target_mach_number_t;

//Word B4-20: Target X Display Coordinate
//Word B4-21: Target Y Display Coordinate
union target_nn_display_coordinate_t
{
	display_coord_t display_coord_of_the_tracked_target;
	spare7_15_field_t spare;

	icd_raw_word_t raw;
};

//Word B4-22: Standard Deviation of Position X estimate
//Word B4-23: Standard Deviation of Position Y estimate
//Word B4-24: Standard Deviation of Position Z estimate
#define ICD1553_STD_DEV_POS_FEET_LSB	(0.42725)
#define ICD1553_STD_DEV_POS_METERS_LSB	(ICD1553_STD_DEV_POS_FEET_LSB/GC_K_METERS_TO_FEETS)

IDD_FIXEDPOINT_TRAIT_LSB_DECLARATION(standard_deviation_of_position_nn_estimate_slb, float, ICD1553_STD_DEV_POS_METERS_LSB);
typedef idd_fixedpoint<float, int16_t, standard_deviation_of_position_nn_estimate_slb> standard_deviation_of_position_nn_estimate_t;

struct spt_target_message_t
{
	//Word B4-01: Track Validity and Status Word #1
	b4_track_validity_and_status_word_01_t track_validity_and_status_word_01;

	//Word B4-02: Track Validity and Status Word #2
	b4_track_validity_and_status_word_02_t track_validity_and_status_word_02;

	//Word B4-03: Time Tag
	relative_timetag_t relative_timetag;

	//Word B4-04: Target Range
	range_of_tracked_target_t range_of_tracked_target;

	//Word B4-05: Normalized Target Position X
	normalized_target_position_t normalized_target_position_x;

	//Word B4-06: Normalized Target Position Y
	normalized_target_position_t normalized_target_position_y;

	//Word B4-07: Normalized Target Position Z
	normalized_target_position_t normalized_target_position_z;

	//Word B4-08: Target Range Rate
	range_rate_of_the_tracked_target_t range_rate_of_the_tracked_target;

	//Word B4-09: Target Velocity (Magnitude)
	target_velocity_magnitude_t target_velocity_magnitude;

	//Word B4-10: Target Velocity X
	target_velocity_t target_velocity_x;

	//Word B4-11: Target Velocity Y
	target_velocity_t target_velocity_y;

	//Word B4-12: Target Velocity Z
	target_velocity_t target_velocity_z;

	//Word B4-13: Target Acceleration (Magnitude)
	target_acceleration_magnitude_t target_acceleration_magnitude;

	//Word B4-14: Target Acceleration X
	acceleration_t target_acceleration_x;

	//Word B4-15: Target Acceleration Y
	acceleration_t target_acceleration_y;

	//Word B4-16: Target Acceleration Z
	acceleration_t target_acceleration_z;

	//Word B4-17: Target Aspect Angle
	target_aspect_angle_t target_aspect_angle;

	//Word B4-18: Target CAS
	target_cas_t target_cas;

	//Word B4-19: Target Mach Number
	target_mach_number_t target_mach_number;

	//Word B4-20: Target X Display Coordinate
	target_nn_display_coordinate_t target_x_display_coordinate;

	//Word B4-21: Target Y Display Coordinate
	target_nn_display_coordinate_t target_y_display_coordinate;

	//Word B4-22: Standard Deviation of Position X estimate
	standard_deviation_of_position_nn_estimate_t standard_deviation_of_position_x_estimate;

	//Word B4-23: Standard Deviation of Position Y estimate
	standard_deviation_of_position_nn_estimate_t standard_deviation_of_position_y_estimate;

	//Word B4-24: Standard Deviation of Position Z estimate
	standard_deviation_of_position_nn_estimate_t standard_deviation_of_position_z_estimate;
};

ICD_STATIC_CHECK_SIZE_WORD(spt_target_message_t, LEN_B4_stp_legacy);


//TODO Message B5: Tracked Target Message

//Word B5-01: Track Validity and Status Word #1
typedef idd_bitfield_u16_t<IDD_REVBIT16(5), 1, bool> aspect_angle_and_ground_track_angle_validity_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(7), 1, bool> antenna_position_validity_t;

union b5_track_validity_and_status_word_01_t
{
	range_validity_t range_validity;
	position_z_y_z_validity_t position_z_y_z_validity;
	range_rate_validity_t range_rate_validity;
	velocity_data_validity_t velocity_data_validity;
	acceleration_data_validity_t acceleration_data_validity;
	aspect_angle_and_ground_track_angle_validity_t aspect_angle_and_ground_track_angle_validity;
	cas_and_mach_number_validity_t cas_and_mach_number_validity;
	antenna_position_validity_t antenna_position_validity;
	display_coordinates_validity_t display_coordinates_validity;
	position_accurancy_t position_accurancy;
	velocity_accurancy_t velocity_accurancy;
	acceleration_accurancy_t acceleration_accurancy;
	spare1_15_field_t spare15;

	icd_raw_word_t raw;
};

//Word B5-02: Track Validity and Status Word #2

typedef idd_bitfield_u16_t<IDD_REVBIT16(12), 1, bool> target_moving_in_ftt_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(13), 1, bool> swap_hpt_flag_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(14), 1, bool> single_pt_rejected_t;

union b5_track_validity_and_status_word_02_t
{
	reacquisition_t reacquisition;
	target_in_coast_t target_in_coast;
	hoj_t hoj;
	aoj_t aoj;
	normalization_factor_for_target_position_x_t normalization_factor_for_target_position_x;
	normalization_factor_for_target_position_y_t normalization_factor_for_target_position_y;
	normalization_factor_for_target_position_z_t normalization_factor_for_target_position_z;

	target_moving_in_ftt_t target_moving_in_ftt;
	swap_hpt_flag_t swap_hpt_flag;
	single_pt_rejected_t single_pt_rejected;

	spare1_15_field_t spare;

	icd_raw_word_t raw;
};


typedef idd_bitfield_u16_t<IDD_REVBIT16(7), 8, int32_t> track_id_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 8, int32_t> track_id_spare_t;

union track_aux_info_t
{
	track_id_t id;
	track_id_spare_t reseved;
	icd_raw_word_t raw;
};

//Word B5-25: Antenna Azimuth Position
//todo lsb
//typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 16, uint16_t> antenna_azimuth_position_t;

//Word B5-26: Antenna Elevation Position
//todo lsb
//typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 16, uint16_t> antenna_elevation_position_t;

struct tracked_target_message_t
{
	//Word B5-01: Track Validity and Status Word #1
	b5_track_validity_and_status_word_01_t track_validity_and_status_word_01;

	//Word B5-02: Track Validity and Status Word #2
	b5_track_validity_and_status_word_02_t track_validity_and_status_word_02;

	//Word B5-03: Time Tag
	relative_timetag_t relative_timetag;

	//Word B5-04: Target Range
	range_of_tracked_target_t range_of_tracked_target;

	//Word B5-05: Normalized Target Position X
	normalized_target_position_t normalized_target_position_x;

	//Word B5-06: Normalized Target Position Y
	normalized_target_position_t normalized_target_position_y;

	//Word B5-07: Normalized Target Position Z
	normalized_target_position_t normalized_target_position_z;

	//Word B5-08: Target Range Rate
	range_rate_of_the_tracked_target_t range_rate_of_the_tracked_target;

	//Word B5-09: Target Velocity (Magnitude)
	target_velocity_magnitude_t target_velocity_magnitude;

	//Word B5-10: Target Velocity X
	target_velocity_t target_velocity_x;

	//Word B5-11: Target Velocity Y
	target_velocity_t target_velocity_y;

	//Word B5-12: Target Velocity Z
	target_velocity_t target_velocity_z;

	//Word B5-13: Target Acceleration (Magnitude)
	target_acceleration_magnitude_t target_acceleration_magnitude;

	//Word B5-14: Target Acceleration X
	acceleration_t target_acceleration_x;

	//Word B5-15: Target Acceleration Y
	acceleration_t target_acceleration_y;

	//Word B5-16: Target Acceleration Z
	acceleration_t target_acceleration_z;

	//Word B5-17: Target Aspect Angle
	target_aspect_angle_t target_aspect_angle;

	//Word B5-18: Target CAS
	target_cas_t target_cas;

	//Word B5-19: Target Mach Number
	target_mach_number_t target_mach_number;

	//Word B5-20: Target X Display Coordinate
	target_nn_display_coordinate_t target_x_display_coordinate;

	//Word B5-21: Target Y Display Coordinate
	target_nn_display_coordinate_t target_y_display_coordinate;

	//Word B5-22: Standard Deviation of Position X estimate
	standard_deviation_of_position_nn_estimate_t standard_deviation_of_position_x_estimate;

	//Word B5-23: Standard Deviation of Position Y estimate
	standard_deviation_of_position_nn_estimate_t standard_deviation_of_position_y_estimate;

	//Word B5-24: Standard Deviation of Position Z estimate
	standard_deviation_of_position_nn_estimate_t standard_deviation_of_position_z_estimate;

	//Word B5-25: Antenna Azimuth Position
	semicircle_t antenna_azimuth_position;

	//Word B5-26: Antenna Elevation Position
	semicircle_t antenna_elevation_position;

	track_aux_info_t aux;
};

ICD_STATIC_CHECK_SIZE_WORD(tracked_target_message_t, LEN_B5_stt);

//Message B6: Radar Operational Setting and Parameter Transfer Tell-Back

//Word B6-05: Radar Health Status and BIT report validity
enum radar_fails_status_t
{
	RDR_OK,
	RDR_FAILED
};
typedef idd_bitfield_u16_t<IDD_REVBIT16(0), 1, radar_fails_status_t> radar_fails_status_field_t;

enum lru_fail_status_t
{
	LRU_OK,
	LRU_FAILED
};
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> pedestal_status_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(3), 1, lru_fail_status_t> servoloop_status_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(4), 1, lru_fail_status_t> rx_front_end_status_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(5), 1, lru_fail_status_t> receiver_status_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(6), 1, lru_fail_status_t> trasmitter_status_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(7), 1, lru_fail_status_t> processor_status_t;

#if 0
enum over_temperature_alarm_t
{
	NO_OVERTEMP,
	OVERTEMP
};
typedef idd_bitfield_u16_t<IDD_REVBIT16(8), 1, over_temperature_alarm_t> transmitter_over_temperature_alarm_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(9), 1, over_temperature_alarm_t> processor_over_temperature_alarm_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(10), 1, over_temperature_alarm_t> servoloop_over_temperature_alarm_field_t;

enum pressurization_status_t
{
	PRESSURIZATION_OK,
	PRESSURIZATION_FAIL
};
typedef idd_bitfield_u16_t<IDD_REVBIT16(11), 1, pressurization_status_t> pressurization_status_field_t;
#else

typedef idd_bitfield_u16_t<IDD_REVBIT16(8), 1, bool> transmitter_over_temperature_alarm_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(9), 1, bool> processor_over_temperature_alarm_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(10), 1, bool> servoloop_over_temperature_alarm_field_t;

typedef idd_bitfield_u16_t<IDD_REVBIT16(11), 1, bool> pressurization_status_field_t;
//typedef idd_bitfield_u16_t<IDD_REVBIT16(11), 1, bool> lcu_over_temperature_status_field_t;

#endif

enum bit_report_available_t
{
	BIT_NOT_AVAILABLE,
	BIT_AVAILABLE
};
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 radar_health_status_and_bit_report_validity_t
{
	radar_fails_status_field_t radar_fails_status_field;

	array_status_t array_status;
	pedestal_status_t pedestal_status;
	servoloop_status_t servoloop_status;
	rx_front_end_status_t rx_front_end_status;
	receiver_status_t receiver_status;
	trasmitter_status_t trasmitter_status;
	processor_status_t processor_status;

	transmitter_over_temperature_alarm_field_t transmitter_over_temperature_alarm_field;
	processor_over_temperature_alarm_field_t processor_over_temperature_alarm_field;
	servoloop_over_temperature_alarm_field_t servoloop_over_temperature_alarm_field;

	pressurization_status_field_t pressurization_status_field;

	bit_report_available_field_t bit_report_available_field;

	spare3_15_field_t spare;

	icd_raw_word_t raw;
};

//Word B6-06: SW Release 1
typedef idd_bitfield_u16_t<IDD_REVBIT16(3), 4, uint16_t> main_computer_sw_release_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(7), 4, uint16_t> main_computer_sw_version_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(11), 4, uint16_t> graphics_computer_sw_release_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 4, uint16_t> graphics_computer_sw_version_t;

union sw_release_01_t
{
	main_computer_sw_release_t main_computer_sw_release;
	main_computer_sw_version_t main_computer_sw_version;
	graphics_computer_sw_release_t graphics_computer_sw_release;
	graphics_computer_sw_version_t graphics_computer_sw_version;

	icd_raw_word_t raw;
};

//Word B6-07: SW Release 2
typedef idd_bitfield_u16_t<IDD_REVBIT16(3), 4, uint16_t> antenna_computer_sw_release_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(7), 4, uint16_t> antenna_computer_sw_version_t;

typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 8, uint16_t> spare8_15_field_t ;

union sw_release_02_t
{
	antenna_computer_sw_release_t antenna_computer_sw_release;
	antenna_computer_sw_version_t antenna_computer_sw_version;

	spare8_15_field_t spare;

	icd_raw_word_t raw;
};

//Word B6-10: Clearance Plane Distance Tell-Back
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 16, uint16_t> distance_of_second_clearance_plane_in_ta_t;


//Word B6-11: Terrain Avoidance Data (word#1)
typedef idd_bitfield_u16_t<IDD_REVBIT16(11), 12, uint16_t> min_range_of_protrusion_high_clearance_plane_t;

enum no_signal_available_indication_t
{
	SIGNAL_AVAILABLE,
	NO_SIGNAL_AVAILABLE
};
typedef idd_bitfield_u16_t<IDD_REVBIT16(12), 1, no_signal_available_indication_t> no_signal_available_indication_field_t;

enum jammer_within_corridor_indication_t
{
	NO_JAMMER_WITHIN_CORRIDOR,
	JAMMER_PRESENT_WITHIN_CORRIDOR
};
typedef idd_bitfield_u16_t<IDD_REVBIT16(13), 1, jammer_within_corridor_indication_t> jammer_within_corridor_indication_field_t;

typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 2, uint16_t> spare2_15_field_t ;

union ta_data_01_t
{
	min_range_of_protrusion_high_clearance_plane_t min_range_of_protrusion_high_clearance_plane;

	no_signal_available_indication_field_t no_signal_available_indication_field;

	jammer_within_corridor_indication_field_t jammer_within_corridor_indication_field;

	spare2_15_field_t spare2_15_field;

	icd_raw_word_t raw;
};


//Word B6-12: Terrain Avoidance Data (word#2)

typedef idd_bitfield_u16_t<IDD_REVBIT16(11), 12, uint16_t> min_range_of_protrusion_low_clearance_plane_t;

typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 4, uint16_t> spare4_15_field_t ;

union ta_data_02_t
{
	min_range_of_protrusion_low_clearance_plane_t min_range_of_protrusion_low_clearance_plane;

	spare4_15_field_t spare;

	icd_raw_word_t raw;
};

//Word B6-16: Cursor X-Display coordinate and Qualifiers

typedef idd_bitfield_u16_t<IDD_REVBIT16(8), 9, uint16_t> crs_pixel_pos_field_t;

enum normal_slave_selector_tellback_t
{
	SEL_CURSOR_NORMAL,
	SEL_CURSOR_SLAVE
};
typedef idd_boolfield_u16_t<IDD_REVBIT16(9), normal_slave_selector_tellback_t> normal_slave_selector_tellback_field_t ;

enum normal_snowplough_selector_tellback_t
{
	NORMAL_SEL,
	SNOWPLOUGH_SEL
};
typedef idd_boolfield_u16_t<IDD_REVBIT16(11), normal_snowplough_selector_tellback_t> normal_snowplough_selector_tellback_field_t ;

enum normal_sar_enabled_selector_tellback_t
{
	SEL_SAR_NORMAL,
	SEL_SAR_ENABLED
};
typedef idd_boolfield_u16_t<IDD_REVBIT16(12), normal_sar_enabled_selector_tellback_t> normal_sar_enabled_selector_tellback_field_t ;

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

union crs_x_coord_t
{
  crs_pixel_pos_field_t pos;

  normal_slave_selector_tellback_field_t normal_slave;

  idd_bitfield_u16_t<IDD_REVBIT16(10), 1, bool> zero;

  normal_snowplough_selector_tellback_field_t snowplugh;

  normal_sar_enabled_selector_tellback_field_t sar_enabled;

  spare3_15_field_t spare;

  icd_raw_word_t raw;
};

//Word B6-17: Cursor Y-Display coordinate

typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 7, uint16_t> spare7_15_field_t ;

union crs_y_coord_t
{
  crs_pixel_pos_field_t pos;

  spare7_15_field_t spare;

  icd_raw_word_t raw;
};

//Message B6: Radar Operational Setting and Parameter Transfer Tell-Back

struct msg_settings_tellback_t
{
  rdr_settings_t settings;				//Word B6-01: Radar Setting Tell-Back
  frequency_t frequency;				//Word B6-02: Frequency Agility Setting and Interleave selection Tell-Back
  beacon_delay_and_code_t beacon;		//Word B6-03: Beacon Delay and Code Tell-Back
  gains_and_chgrp_t gains_and_chgrp;	//Word B6-04: Radar Gains and RF Channel Grouping Tell-Back

  radar_health_status_and_bit_report_validity_t health_status; //Word B6-05: Radar Health Status and BIT report validity

  sw_release_01_t sw_release_01;		//Word B6-06: SW Release 1,
  sw_release_02_t sw_release_02;  	  	//Word B6-07: SW Release 2

  semicircle_t az_scan_centre;			//Word B6-08: AZ Scan Centre
  semicircle_t el_scan_centre;			//Word B6-09: EL Scan Centre

  distance_of_second_clearance_plane_in_ta_t clearance_plane_distance; //Word B6-10: Clearance Plane Distance Tell-Back

  ta_data_01_t ta_data_01; 			  //Word B6-11: Terrain Avoidance Data (word#1)
  ta_data_02_t ta_data_02;	  	  	  //Word B6-12: Terrain Avoidance Data (word#2)

  param_id_t param_id;					//Word B6-13: Parameter Identifier Tell-Back
  icd_raw_word_t param_value_1;			//Word B6-14: Parameter Value (word 1)
  icd_raw_word_t param_value_2;			//Word B6-15: Parameter Value (word 2)

  crs_x_coord_t crs_x;					//Word B6-16: Cursor X-Display coordinate and Qualifiers
  crs_y_coord_t crs_y;					//Word B6-17: Cursor Y-Display coordinate

  crs_slave_range_t crs_range;				//Word B6-18: Cursor Inertial position (range)
  semicircle_t crs_azimuth;				//Word B6-19: Cursor Inertial position (Azimuth)
  latlong_t crs_lat;					//Word B6-20/21: Cursor Position Latitude
  latlong_t crs_long;					//Word B6-22/23: Cursor Position Longitude

  //icd_raw_word_t	grifo_reseved_[4];
};

ICD_STATIC_CHECK_SIZE_WORD(msg_settings_tellback_t, LEN_B6_rdr_operational_setting_tellback);

//Message B7: Radar Status Tell-Back

//Word B7-01: Radar Mode Tell-Back
enum rdr_design_sts_t {
  DS_STT,
  DS_DTT,
  DS_SAM,
  DS_TWS_with_HPT,
  DS_AGR_Lock_On,
  DS_ACQUISITION_in_Progress,
  DS_SAR,
  DS_NOT_VALID
};

typedef idd_bitfield_u16_t<IDD_REVBIT16(6), 3, rdr_design_sts_t> rdr_design_sts_field_t;
//typedef idd_bitfield_u16_t<IDD_REVBIT16(8), 1, bool> ibit_status_field_t;
//typedef idd_bitfield_u16_t<IDD_REVBIT16(9), 1, bool> standby_tellback_field_t;
//typedef idd_bitfield_u16_t<IDD_REVBIT16(10), 1, bool> freeze_tellback_field_t;

enum degraded_performance_status_t
{
	PERF_NORMAL,
	PERF_DEGRADED
};
typedef idd_bitfield_u16_t<IDD_REVBIT16(10), 1, degraded_performance_status_t> degraded_performance_field_t;

enum rf_radiation_status_t
{
	RADIATION_ON,
	RADIATION_OFF
};
typedef idd_boolfield_u16_t<IDD_REVBIT16(12), rf_radiation_status_t> rf_radiation_field_t;

enum transition_status_t
{
	NO_TRANSITION,
	TRANSITION_IN_PROGRESS
};
typedef idd_boolfield_u16_t<IDD_REVBIT16(13), transition_status_t> transition_status_field_t;

enum last_acquisition_result_t
{
	LAST_ACQUISITION_UNSUCCESSFUL,
	LAST_ACQUISITION_SUCCESSFUL
};
typedef idd_bitfield_u16_t<IDD_REVBIT16(14), 1, last_acquisition_result_t> last_acq_result_field_t;

typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 1, sar_exec_selection_t> sar_acquisition_field_t;

//Word B7-01: Radar Mode Tell-Back
union rdr_mode_tellback_t
{
  rdr_mode_field_t master_mode;
  rdr_design_sts_field_t design_sts;
  ibit_request_field_t ibit_sts;
  stby_field_t stby_sts;
  freeze_field_t freeze_sts;
  degraded_performance_field_t degrad_perf;
  reserved11_field_t reserved11;	//A.k.a. emergency
  rf_radiation_field_t rf_radiation;
  transition_status_field_t transition_status;
  last_acq_result_field_t last_acq_result;
  sar_acquisition_field_t sar_acquisition;

  icd_raw_word_t raw;
};

//Word B7-02: Radar Functions and Parameters Tell-Back (word#1)
enum scan_width_tb_t {
  TB_W60,
  TB_W55,
  TB_W50,
  TB_W45,
  TB_W40,
  TB_W35,
  TB_W30,
  TB_W25,
  TB_W20,
  TB_W15,
  TB_W10,
  TB_W05,
  TB_W0,
  TB_W_NV13,
  TB_W_NV14,
  TB_W_NV15
};

typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 4, scan_width_tb_t> scan_width_tellback_field_t;

enum velocity_scale_tb_t
{
  VS_NM80,
  VS_NM40,

  VS_2400KTS,
  VS_1200KTS
};

IDD_INT_TRAIT_DECLARATION(velocity_scale_tb_trait_t, velocity_scale_tb_t, VS_NM80, VS_1200KTS);

typedef idd_bitfield_u16_t<IDD_REVBIT16(9), 2, velocity_scale_tb_t> velocity_scale_tb_field_t;

//Word B7-02: Radar Functions and Parameters Tell-Back (word#1)

union rdr_fun_and_param1_tellback_t {
  rws_submode_field_t rws_submode;
  spot_selection_field_t spot;
  acm_submode_field_t acm_submode;
  gm_submode_field_t gm_submode;
  expand_field_t expand;
  range_scale_field_t range_scale;
  velocity_scale_tb_field_t velocity_scale;
  bars_num_field_t bars_num;
  scan_width_tellback_field_t scan_width;
  spare1_15_field_t spare;

  icd_raw_word_t raw;
};

//Word B7-03: Radar Functions and Parameters Tell-Back (word#2)
#if 0
enum sar_feasibility_for_cursor_t
{
	SAR_NOT_FEASIBLE,
	SAR_FEASIBLE
};

enum sar_feasibility_for_spoi_t
{
	SAR_NOT_FEASIBLE_ON_SPOI,
	SAR_FEASIBLE_ON_SPOI
};
#endif
typedef bool sar_feasibility_for_cursor_t;
typedef bool sar_feasibility_for_spoi_t;

typedef idd_bitfield_u16_t<IDD_REVBIT16(8), 1, sar_feasibility_for_cursor_t> sar_feasibility_for_cursor_field_t;
typedef idd_bitfield_u16_t<IDD_REVBIT16(9), 1, sar_feasibility_for_spoi_t> sar_feasibility_for_spoi_field_t;


//Word B7-03: Radar Functions and Parameters Tell-Back (word#2)

typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 6, uint16_t> spare6_15_field_t ;

union rdr_fun_and_param2_tellback_t
{
  spare0_4_field_t spare_0_4;

  zoom_field_t zoom;
  sar_map_orientation_field_t sar_map_orientation;

  sar_feasibility_for_cursor_field_t sar_crs_feasibility;
  sar_feasibility_for_spoi_field_t sar_spoi_feasibility;

  spare6_15_field_t spare;

  icd_raw_word_t raw;
};

//Message B7: Radar Status Tell-Back

struct msg_rdr_status_tellback_t
{
  rdr_mode_tellback_t mode;				//Word B7-01: Radar Mode Tell-Back
  rdr_fun_and_param1_tellback_t param1;	//Word B7-02: Radar Functions and Parameters Tell-Back (word#1)
  rdr_fun_and_param2_tellback_t param2;	//Word B7-03: Radar Functions and Parameters Tell-Back (word#2)
};

ICD_STATIC_CHECK_SIZE_WORD(msg_rdr_status_tellback_t, LEN_B7_rdrstatus_tellback);

//Message B8: BIT Report Message
//todo

//Word B8-01: BIT Report Label


enum bit_report_label_t
{
	BIT_REP_POWER_UP,
	BIT_REP_FAST_POWER_UP,
	BIT_REP_INT,
	BIT_REP_SWITCH_OFF,
	BIT_REP_FAIL_ONSET,
	BIT_REP_FAIL_STOP,
	BIT_REP_SPARE_6,
	BIT_REP_SPAR_7
};
typedef idd_bitfield_u16_t<IDD_REVBIT16(2), 3, bit_report_label_t> bit_report_label_field_t ;

typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 13, uint16_t> spare13_15_field_t ;

union bit_report_label_union_t
{
	bit_report_label_field_t bit_report_label_field;
	spare13_15_field_t spare;

	icd_raw_word_t raw;
};

//Word B8-02: BIT Report Date
union bit_report_date_union_t
{
	year_of_mission_t year_of_mission;
	month_of_mission_t month_of_mission;
	day_of_mission_t day_of_mission;

	spare1_15_field_t spare;

	icd_raw_word_t raw;
};

//Word B8-04: Degradation Conditions (word 1)
union degradation_conditions_word_01_t
{
	idd_bitfield_u16_t<IDD_REVBIT16(0), 1, bool> degradation_message_01;
	idd_bitfield_u16_t<IDD_REVBIT16(1), 1, bool> degradation_message_02;
	idd_bitfield_u16_t<IDD_REVBIT16(2), 1, bool> degradation_message_03;
	idd_bitfield_u16_t<IDD_REVBIT16(3), 1, bool> degradation_message_04;
	idd_bitfield_u16_t<IDD_REVBIT16(4), 1, bool> degradation_message_05;
	idd_bitfield_u16_t<IDD_REVBIT16(5), 1, bool> degradation_message_06;
	idd_bitfield_u16_t<IDD_REVBIT16(6), 1, bool> degradation_message_07;
	idd_bitfield_u16_t<IDD_REVBIT16(7), 1, bool> degradation_message_08;
	idd_bitfield_u16_t<IDD_REVBIT16(8), 1, bool> degradation_message_09;
	idd_bitfield_u16_t<IDD_REVBIT16(9), 1, bool> degradation_message_10;
	idd_bitfield_u16_t<IDD_REVBIT16(10), 1, bool> degradation_message_11;
	idd_bitfield_u16_t<IDD_REVBIT16(11), 1, bool> degradation_message_12;
	idd_bitfield_u16_t<IDD_REVBIT16(12), 1, bool> degradation_message_13;
	idd_bitfield_u16_t<IDD_REVBIT16(13), 1, bool> degradation_message_14;
	idd_bitfield_u16_t<IDD_REVBIT16(14), 1, bool> degradation_message_15;
	idd_bitfield_u16_t<IDD_REVBIT16(15), 1, bool> degradation_message_16;
	icd_raw_word_t raw;
};

//Word B8-05: Degradation Conditions (word 2)
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 16, uint16_t> spare16_15_field_t ;

//Word B8-06: Failure Location (Pedestal)
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 11, uint16_t> spare11_15_field_t ;
union failure_location_pedestal_t
{
	idd_bitfield_u16_t<IDD_REVBIT16(0), 1, bool> sru_01_gimbal;
	idd_bitfield_u16_t<IDD_REVBIT16(1), 1, bool> sru_02_waveguide;
	idd_bitfield_u16_t<IDD_REVBIT16(2), 1, bool> sru_03_waveguide;
	idd_bitfield_u16_t<IDD_REVBIT16(3), 1, bool> sru_04_delta_guard_lna_switch;
	idd_bitfield_u16_t<IDD_REVBIT16(4), 1, bool> sru_05_waveguide_switch;
	spare11_15_field_t spare;
	icd_raw_word_t raw;
};

//Word B8-07: Failure Location (Servoloop)
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 13, uint16_t> spare13_15_field_t ;
union failure_location_servoloop_t
{
	idd_bitfield_u16_t<IDD_REVBIT16(0), 1, bool> sru_01_chassis;
	idd_bitfield_u16_t<IDD_REVBIT16(1), 1, bool> sru_02_power_supply;
	idd_bitfield_u16_t<IDD_REVBIT16(2), 1, bool> sru_03_digital_controller;
	spare13_15_field_t spare;
	icd_raw_word_t raw;
};

//Word B8-08: Failure Location (RX Front-End)
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 10, uint16_t> spare10_15_field_t ;
union failure_location_rx_front_end_t
{
	idd_bitfield_u16_t<IDD_REVBIT16(0), 1, bool> sru_01_chassis;
	idd_bitfield_u16_t<IDD_REVBIT16(1), 1, bool> sru_02_delta_guard_lna;
	idd_bitfield_u16_t<IDD_REVBIT16(2), 1, bool> sru_03_sum_act_prot_and_lna;
	idd_bitfield_u16_t<IDD_REVBIT16(3), 1, bool> sru_04_4_port_circulator;
        idd_bitfield_u16_t<IDD_REVBIT16(4), 1, bool> sru_05_stc_attenuators_delta_guard;
	idd_bitfield_u16_t<IDD_REVBIT16(5), 1, bool> sru_05_stc_attenuators_sum;
	spare10_15_field_t spare;
	icd_raw_word_t raw;
};

//Word B8-09: Failure Location (Receiver)
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 9, uint16_t> spare9_15_field_t ;
union failure_location_receiver_t
{
	idd_bitfield_u16_t<IDD_REVBIT16(0), 1, bool> sru_01_chassis;
	idd_bitfield_u16_t<IDD_REVBIT16(1), 1, bool> sru_02_uhf_assy;
	idd_bitfield_u16_t<IDD_REVBIT16(2), 1, bool> sru_03_synthesizer;
	idd_bitfield_u16_t<IDD_REVBIT16(3), 1, bool> sru_04_delta_guard_down_converter;
	idd_bitfield_u16_t<IDD_REVBIT16(4), 1, bool> sru_05_sum_down_converter;
	idd_bitfield_u16_t<IDD_REVBIT16(5), 1, bool> sru_06_l_o_distributor;
	idd_bitfield_u16_t<IDD_REVBIT16(6), 1, bool> sru_07_up_converter;
	spare9_15_field_t spare;
	icd_raw_word_t raw;
};

//Word B8-10: Failure Location (Transmitter)
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 8, uint16_t> spare8_15_field_t ;
union failure_location_transmitter_t
{
	idd_bitfield_u16_t<IDD_REVBIT16(0), 1, bool> sru_01_chassis;
	idd_bitfield_u16_t<IDD_REVBIT16(1), 1, bool> sru_02_rex_f_tx;
	idd_bitfield_u16_t<IDD_REVBIT16(2), 1, bool> sru_03_power_supply;
	idd_bitfield_u16_t<IDD_REVBIT16(3), 1, bool> sru_04_valve_el_twt_tx;
	idd_bitfield_u16_t<IDD_REVBIT16(4), 1, bool> sru_05_rf_driver;
	idd_bitfield_u16_t<IDD_REVBIT16(5), 1, bool> sru_06_controller_tx;
	idd_bitfield_u16_t<IDD_REVBIT16(6), 1, bool> sru_07_h_v_power_supply;
	idd_bitfield_u16_t<IDD_REVBIT16(7), 1, bool> sru_08_eht_power_supply;
	spare8_15_field_t spare;
	icd_raw_word_t raw;
};

//Word B8-11: Failure Location (Processor)
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 2, uint16_t> spare2_15_field_t ;
union failure_location_processor_t
{
	idd_bitfield_u16_t<IDD_REVBIT16(0), 1, bool> sru_01_mother_board_and_chassis;
	idd_bitfield_u16_t<IDD_REVBIT16(1), 1, bool> sru_02_pulse_compressor;
	idd_bitfield_u16_t<IDD_REVBIT16(2), 1, bool> sru_03_mti_fft;
	idd_bitfield_u16_t<IDD_REVBIT16(3), 1, bool> sru_04_dbs;
	idd_bitfield_u16_t<IDD_REVBIT16(4), 1, bool> sru_05_cfar;
	idd_bitfield_u16_t<IDD_REVBIT16(5), 1, bool> sru_06_timer;
	idd_bitfield_u16_t<IDD_REVBIT16(6), 1, bool> sru_07_post_processor;
	idd_bitfield_u16_t<IDD_REVBIT16(7), 1, bool> sru_08_agc_clutter_lock;
	idd_bitfield_u16_t<IDD_REVBIT16(8), 1, bool> sru_09_aux_computer;
	idd_bitfield_u16_t<IDD_REVBIT16(9), 1, bool> sru_10_main_computer;
	idd_bitfield_u16_t<IDD_REVBIT16(10), 1, bool> sru_11_graphic_computer;
	idd_bitfield_u16_t<IDD_REVBIT16(11), 1, bool> sru_12_power_supply;
	idd_bitfield_u16_t<IDD_REVBIT16(12), 1, bool> sru_13_det_exp;
	idd_bitfield_u16_t<IDD_REVBIT16(13), 1, bool> sru_14_rx_module;

	spare2_15_field_t spare;
	icd_raw_word_t raw;
};

//Word B8-12: Signal Processor Test Results
union signal_processor_test_result_t
{
	idd_bitfield_u16_t<IDD_REVBIT16(0), 1, bool> test_sp_01_timer1_micro_p;
	idd_bitfield_u16_t<IDD_REVBIT16(1), 1, bool> test_sp_02_timer1_timing;
	idd_bitfield_u16_t<IDD_REVBIT16(2), 1, bool> test_sp_03_timer1_to_timer2_if;
	idd_bitfield_u16_t<IDD_REVBIT16(3), 1, bool> test_sp_04_time2_micro_p;
	idd_bitfield_u16_t<IDD_REVBIT16(4), 1, bool> test_sp_05_sp_chain_vector_test_coherent_search;
	idd_bitfield_u16_t<IDD_REVBIT16(5), 1, bool> test_sp_06_sp_chain_vector_test_non_coherent_search;
	idd_bitfield_u16_t<IDD_REVBIT16(6), 1, bool> test_sp_07_sp_chain_vector_test_coherent_track;
	idd_bitfield_u16_t<IDD_REVBIT16(7), 1, bool> test_sp_08_sp_chain_vector_test_non_coherent_track;
	idd_bitfield_u16_t<IDD_REVBIT16(8), 1, bool> test_sp_09_a_d_and_d_a;
	idd_bitfield_u16_t<IDD_REVBIT16(9), 1, bool> test_sp_10_sp_if;
	idd_bitfield_u16_t<IDD_REVBIT16(10), 1, bool> test_sp_11_attenuators_and_antenna;
	idd_bitfield_u16_t<IDD_REVBIT16(11), 1, bool> test_sp_12_fast_bus_interface;
	idd_bitfield_u16_t<IDD_REVBIT16(12), 1, bool> test_sp_13_dbs_input;
	idd_bitfield_u16_t<IDD_REVBIT16(13), 1, bool> test_sp_14_external_sp_interfaces;
	idd_bitfield_u16_t<IDD_REVBIT16(14), 1, bool> test_sp_15_dbs_output;
	idd_bitfield_u16_t<IDD_REVBIT16(15), 1, bool> test_sp_16_bcn;

	icd_raw_word_t raw;
};

//Word B8-13: Rx Module Test Results
typedef idd_bitfield_u16_t<IDD_REVBIT16(14), 10, uint16_t> spare10_14_field_t ;
union rx_module_test_results_t
{
	idd_bitfield_u16_t<IDD_REVBIT16(0), 1, bool> test_rm_01_master_clock_level;
	idd_bitfield_u16_t<IDD_REVBIT16(1), 1, bool> test_rm_02_expander_level;
	idd_bitfield_u16_t<IDD_REVBIT16(2), 1, bool> test_rm_03_sum_channel_down_converter;
	idd_bitfield_u16_t<IDD_REVBIT16(3), 1, bool> test_rm_04_d_g_channel_down_converter;
	idd_bitfield_u16_t<IDD_REVBIT16(4), 1, bool> test_rm_05_noise_attenuators;
	spare2_15_field_t spare;
	idd_bitfield_u16_t<IDD_REVBIT16(15), 1, bool> test_rm_16_calibration_sum_channel_fail;

	icd_raw_word_t raw;
};

//Word B8-14: Data Processor Test Results
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 2, uint16_t> spare2_15_field_t ;
union data_processor_test_results_t
{
	idd_bitfield_u16_t<IDD_REVBIT16(0), 1, bool> test_dp_01_486_cpu_tests;
	idd_bitfield_u16_t<IDD_REVBIT16(1), 1, bool> test_dp_02_486_interfaces_with_r3000_and_gc;
	idd_bitfield_u16_t<IDD_REVBIT16(2), 1, bool> test_dp_03_486_interface_with_slc;
	idd_bitfield_u16_t<IDD_REVBIT16(3), 1, bool> test_dp_04_slc_communications;
	idd_bitfield_u16_t<IDD_REVBIT16(4), 1, bool> test_dp_05_r3000_cpu_tests;
	idd_bitfield_u16_t<IDD_REVBIT16(5), 1, bool> test_dp_06_r3000_interfaces;
	idd_bitfield_u16_t<IDD_REVBIT16(6), 1, bool> test_dp_07_1553_and_discretes;
	idd_bitfield_u16_t<IDD_REVBIT16(7), 1, bool> test_dp_08_graphic_cpu;
	idd_bitfield_u16_t<IDD_REVBIT16(8), 1, bool> test_dp_09_graphic_processors;
	idd_bitfield_u16_t<IDD_REVBIT16(9), 1, bool> test_dp_10_video_memory;
	idd_bitfield_u16_t<IDD_REVBIT16(10), 1, bool> test_dp_11_video_unit;
	idd_bitfield_u16_t<IDD_REVBIT16(11), 1, bool> test_dp_12_transputer_unit;
	idd_bitfield_u16_t<IDD_REVBIT16(12), 1, bool> test_dp_13_scan_converter_polar_memory;
	idd_bitfield_u16_t<IDD_REVBIT16(13), 1, bool> test_dp_14_scan_converter_format_converter;

	spare2_15_field_t spare;

	icd_raw_word_t raw;
};

//Word B8-15: Post Processor Test Results
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 8, uint16_t> spare8_15_field_t ;
union post_processor_test_results_t
{
	idd_bitfield_u16_t<IDD_REVBIT16(0), 1, bool> test_pp_01_master_dsp;
	idd_bitfield_u16_t<IDD_REVBIT16(1), 1, bool> test_pp_02_interface_card;
	idd_bitfield_u16_t<IDD_REVBIT16(2), 1, bool> test_pp_03_cpu_cards;
	idd_bitfield_u16_t<IDD_REVBIT16(3), 1, bool> test_pp_04_dma_bus;
	idd_bitfield_u16_t<IDD_REVBIT16(4), 1, bool> test_pp_05_sp_interface;
	idd_bitfield_u16_t<IDD_REVBIT16(5), 1, bool> test_pp_06_dp_interface;
	idd_bitfield_u16_t<IDD_REVBIT16(6), 1, bool> test_pp_07_scan_converter_interface;
	idd_bitfield_u16_t<IDD_REVBIT16(7), 1, bool> test_pp_08_agc_interface;

	spare8_15_field_t spare;

	icd_raw_word_t raw;
};

//Word B8-16: AGC Test Results
typedef idd_bitfield_u16_t<IDD_REVBIT16(11), 1, uint16_t> spare1_11_field_t ;
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 1, uint16_t> spare1_15_field_t ;
union agc_test_results_t
{
	idd_bitfield_u16_t<IDD_REVBIT16(0), 1, bool> test_agc_01_non_destr_internal_xyp_ram;
	idd_bitfield_u16_t<IDD_REVBIT16(1), 1, bool> test_agc_02_non_destr_external_xyp_ram;
	idd_bitfield_u16_t<IDD_REVBIT16(2), 1, bool> test_agc_03_eprom_checksum;
	idd_bitfield_u16_t<IDD_REVBIT16(3), 1, bool> test_agc_04_eeprom_checksum;
	idd_bitfield_u16_t<IDD_REVBIT16(4), 1, bool> test_agc_05_dual_port_ram;
	idd_bitfield_u16_t<IDD_REVBIT16(5), 1, bool> test_agc_06_agc_machine;
	idd_bitfield_u16_t<IDD_REVBIT16(6), 1, bool> test_agc_07_sat_machine;
	idd_bitfield_u16_t<IDD_REVBIT16(7), 1, bool> test_agc_08_phs_machine;
	idd_bitfield_u16_t<IDD_REVBIT16(8), 1, bool> test_agc_09_c_ram_xy_data_checksum;
	idd_bitfield_u16_t<IDD_REVBIT16(9), 1, bool> test_agc_10_pulse_compressor_interface;
	idd_bitfield_u16_t<IDD_REVBIT16(10), 1, bool> test_agc_11_dp_interface;

	spare1_11_field_t spare11;

	idd_bitfield_u16_t<IDD_REVBIT16(12), 1, bool> test_agc_13_taxi_running;
	idd_bitfield_u16_t<IDD_REVBIT16(13), 1, bool> test_agc_14_non_destr_ext_xup_ram;
	idd_bitfield_u16_t<IDD_REVBIT16(14), 1, bool> test_agc_15_servoloop_interface;

	spare1_15_field_t spare15;

	icd_raw_word_t raw;
};

//Word B8-17: Power Supply Test Results
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 12, uint16_t> spare12_15_field_t ;
union power_supply_test_result_t
{
	idd_bitfield_u16_t<IDD_REVBIT16(0), 1, bool> test_ps_01_power_supply;
	idd_bitfield_u16_t<IDD_REVBIT16(1), 1, bool> test_ps_02_over_temperature;
	idd_bitfield_u16_t<IDD_REVBIT16(2), 1, bool> test_ps_03;

	spare12_15_field_t spare11;

	icd_raw_word_t raw;
};

//Word B8-18: Servoloop Test Results
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 1, uint16_t> spare1_15_field_t ;
union servoloop_test_results_t
{
	idd_bitfield_u16_t<IDD_REVBIT16(0), 1, bool> test_sl_01_low_voltage_power_supply;
	idd_bitfield_u16_t<IDD_REVBIT16(1), 1, bool> test_sl_02_high_voltage_power_supply;
	idd_bitfield_u16_t<IDD_REVBIT16(2), 1, bool> test_sl_03_motors_drivers;
	idd_bitfield_u16_t<IDD_REVBIT16(3), 1, bool> test_sl_04_resolvers_power_supply;
	idd_bitfield_u16_t<IDD_REVBIT16(4), 1, bool> test_sl_05_waveguide_switch;
	idd_bitfield_u16_t<IDD_REVBIT16(5), 1, bool> test_sl_06_over_temperature;
	idd_bitfield_u16_t<IDD_REVBIT16(6), 1, bool> test_sl_07_resolver_to_digital_conv;
	idd_bitfield_u16_t<IDD_REVBIT16(7), 1, bool> test_sl_08_position_loop_error;
	idd_bitfield_u16_t<IDD_REVBIT16(8), 1, bool> test_sl_09_microprocessor;
	idd_bitfield_u16_t<IDD_REVBIT16(9), 1, bool> test_sl_10_agc_control;
	idd_bitfield_u16_t<IDD_REVBIT16(10), 1, bool> test_sl_11_a_and_d;
	idd_bitfield_u16_t<IDD_REVBIT16(11), 1, bool> test_sl_12_d_and_a_s;
	idd_bitfield_u16_t<IDD_REVBIT16(12), 1, bool> test_sl_13_serial_communications;
	idd_bitfield_u16_t<IDD_REVBIT16(13), 1, bool> test_sl_14_taxi_interface;
	idd_bitfield_u16_t<IDD_REVBIT16(14), 1, bool> test_sl_15_pedestal_centre_scan_location;

	spare1_15_field_t spare15;

	icd_raw_word_t raw;
};

//Word B8-19: Transmitter Test Results (word 1)
union transmitter_test_result_word_01_t
{
	idd_bitfield_u16_t<IDD_REVBIT16(0), 1, bool> test_tx_01_microprocessors;
	idd_bitfield_u16_t<IDD_REVBIT16(1), 1, bool> test_tx_02_tx_rf_input;
	idd_bitfield_u16_t<IDD_REVBIT16(2), 1, bool> test_tx_03_twt_rf_input;
	idd_bitfield_u16_t<IDD_REVBIT16(3), 1, bool> test_tx_04_twt_rf_output;
	idd_bitfield_u16_t<IDD_REVBIT16(4), 1, bool> test_tx_05_tx_rf_ouput_level;
	idd_bitfield_u16_t<IDD_REVBIT16(5), 1, bool> test_tx_06_vswr;
	idd_bitfield_u16_t<IDD_REVBIT16(6), 1, bool> test_tx_07_3_phase_input_power;
	idd_bitfield_u16_t<IDD_REVBIT16(7), 1, bool> test_tx_08_low_voltage_power_supplies;
	idd_bitfield_u16_t<IDD_REVBIT16(8), 1, bool> test_tx_09_hv_ps_over_temperature_hazard;
	idd_bitfield_u16_t<IDD_REVBIT16(9), 1, bool> test_tx_10_hv_ps_over_temperature_warning;
	idd_bitfield_u16_t<IDD_REVBIT16(10), 1, bool> test_tx_11_twt_helix_over_current;
	idd_bitfield_u16_t<IDD_REVBIT16(11), 1, bool> test_tx_12_cathode_to_helix_arc;
	idd_bitfield_u16_t<IDD_REVBIT16(12), 1, bool> test_tx_13_twt_over_temperature_hazard;
	idd_bitfield_u16_t<IDD_REVBIT16(13), 1, bool> test_tx_14_txt_over_temperature_warning;
	idd_bitfield_u16_t<IDD_REVBIT16(14), 1, bool> test_tx_15_cathode_under_voltage;
	idd_bitfield_u16_t<IDD_REVBIT16(15), 1, bool> test_tx_16_cathode_over_voltage;

	icd_raw_word_t raw;
};

//Word B8-20: Transmitter Test Results (word 2)
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 6, uint16_t> spare6_15_field_t ;
union transmitter_test_result_word_02_t
{
	idd_bitfield_u16_t<IDD_REVBIT16(0), 1, bool> test_tx_17_collector_undex_voltage;
	idd_bitfield_u16_t<IDD_REVBIT16(1), 1, bool> test_tx_18_collector_over_voltage;
	idd_bitfield_u16_t<IDD_REVBIT16(2), 1, bool> test_tx_19_rectified_voltage;
	idd_bitfield_u16_t<IDD_REVBIT16(3), 1, bool> test_tx_20_cathode_inv_current_fail;
	idd_bitfield_u16_t<IDD_REVBIT16(4), 1, bool> test_tx_21_collector_inv_current_fail;
	idd_bitfield_u16_t<IDD_REVBIT16(5), 1, bool> test_tx_22_waveguide_pressurization;
	idd_bitfield_u16_t<IDD_REVBIT16(6), 1, bool> test_tx_23_grid_window_over_duty;
	idd_bitfield_u16_t<IDD_REVBIT16(7), 1, bool> test_tx_24_floating_deck_fail;
	idd_bitfield_u16_t<IDD_REVBIT16(8), 1, bool> test_tx_25_floating_deck_ps_fail;
	idd_bitfield_u16_t<IDD_REVBIT16(9), 1, bool> test_tx_26_power_supplies_synch;

	spare6_15_field_t spare;

	icd_raw_word_t raw;
};

//Word B8-21: Receiver and Rx Front-End Test Results
typedef idd_bitfield_u16_t<IDD_REVBIT16(7), 3, uint16_t> spare3_7_field_t ;
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 6, uint16_t> spare6_15_field_t ;
union receiver_and_rx_front_end_test_results_t
{
	idd_bitfield_u16_t<IDD_REVBIT16(0), 1, bool> test_rx_01_17_collector_undex_voltage;
	idd_bitfield_u16_t<IDD_REVBIT16(1), 1, bool> test_rx_02_collector_over_voltage;
	idd_bitfield_u16_t<IDD_REVBIT16(2), 1, bool> test_rx_03_rectified_voltage;
	idd_bitfield_u16_t<IDD_REVBIT16(3), 1, bool> test_rx_04_cathode_inv_current_fail;
	idd_bitfield_u16_t<IDD_REVBIT16(4), 1, bool> test_rx_05_collector_inv_current_fail;

	spare3_7_field_t spare7;

	idd_bitfield_u16_t<IDD_REVBIT16(8), 1, bool> test_fe_01_lna;
	idd_bitfield_u16_t<IDD_REVBIT16(9), 1, bool> test_fe_02_agc_attenuators;

	spare6_15_field_t spare6;

	icd_raw_word_t raw;
};

//Word B8-22: Integrated System Test Results and LRU status
typedef idd_bitfield_u16_t<IDD_REVBIT16(15), 1, uint16_t> spare1_15_field_t ;
union integrated_system_test_results_and_lru_status_t
{
	idd_bitfield_u16_t<IDD_REVBIT16(0), 1, bool> test_is_01_upconverter_chain_levels;
	idd_bitfield_u16_t<IDD_REVBIT16(1), 1, bool> test_is_02_downconverter_chain_levels;
	idd_bitfield_u16_t<IDD_REVBIT16(2), 1, bool> test_is_03_antenna_status_inconsistent;
	idd_bitfield_u16_t<IDD_REVBIT16(3), 1, bool> test_is_04_tx_status_inconsistent;
	idd_bitfield_u16_t<IDD_REVBIT16(4), 1, bool> test_is_05_tx_power_level;
	idd_bitfield_u16_t<IDD_REVBIT16(5), 1, bool> array_status;
	idd_bitfield_u16_t<IDD_REVBIT16(6), 1, bool> pedestal_status;
	idd_bitfield_u16_t<IDD_REVBIT16(7), 1, bool> servoloop_status;
	idd_bitfield_u16_t<IDD_REVBIT16(8), 1, bool> rx_front_end_status;
	idd_bitfield_u16_t<IDD_REVBIT16(9), 1, bool> receiver_status;
	idd_bitfield_u16_t<IDD_REVBIT16(10), 1, bool> transmitter_status;
	idd_bitfield_u16_t<IDD_REVBIT16(11), 1, bool> processor_status;
	idd_bitfield_u16_t<IDD_REVBIT16(12), 1, bool> calibration_noise_fail;
	idd_bitfield_u16_t<IDD_REVBIT16(13), 1, bool> calibration_injection_fail;
	idd_bitfield_u16_t<IDD_REVBIT16(14), 1, bool> calibration_delta_channel_fail;

	spare1_15_field_t spare15;

	icd_raw_word_t raw;
};


//Message B8: BIT Report Message
struct 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_pedestal;

	//Word B8-07: Failure Location (Servoloop)
	failure_location_servoloop_t failure_location_servoloop;

	//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_processor_t failure_location_processor;

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

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

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

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

	//Word B8-16: AGC Test Results
	agc_test_results_t agc_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;
};

ICD_STATIC_CHECK_SIZE_WORD(bit_report_message_t, LEN_B8_bit_report);


//Message B9: Reserved Message #1 (Search Target Message)

struct msg_b09_t
{
  relative_timetag_t tt_low;
  relative_timetag_t tt_high;
  icd_raw_word_t scan_sts;
  semicircle_t nav_az;
  semicircle_t nav_el;
  semicircle_t body_az;
  semicircle_t body_el;

  icd_raw_word_t spare[32-7];
};

ICD_STATIC_CHECK_SIZE_WORD(msg_b09_t, LEN_B9_reserved_1);

//Message B10: Reserved Message #2 (Mode Data Message)

struct msg_b10_t
{
  icd_raw_word_t mode;
  relative_timetag_t tt_low;
  relative_timetag_t tt_high;

  icd_raw_word_t spare[32-3];
};

ICD_STATIC_CHECK_SIZE_WORD(msg_b10_t, LEN_B10_reserved_2);

//Message B11: Reserved TX Message (Debug Message)

struct msg_b11_t
{
  icd_raw_word_t spare[32];
};

ICD_STATIC_CHECK_SIZE_WORD(msg_b11_t, LEN_B11_reserved_debug);


//**B20
struct msg_dev0_result_t
{
	  icd_raw_word_t spare[32];
};

ICD_STATIC_CHECK_SIZE_WORD(msg_dev0_result_t, LEN_B11_reserved_debug);


#include "idd_unpack.h"


template<unsigned int sa_, typename T_, int rxtx_=0> class  icd1553_message_trait
{
public:
	enum sizes_enum
	{
		wc=sizeof(T_)/2,
		size=sizeof(T_)
	};
	enum sa_enum { sa=sa_};

	enum rxmode {rxtx=rxtx_};

	typedef T_ type_t;
};

#define ICD_MSGLEN(s_)  (sizeof(s_)/sizeof(icd_raw_word_t))

//With MinGW offsetof() generate a warning to the dummy pointer ot 0!
//#define ICD_WOFFSET(s_, f_)  ((((unsigned int)&(((s_*)0x10)->f_))-0x10)/sizeof(icd_raw_word_t))
#define ICD_WOFFSETOF(s_, f_) (IDD_OFFSETOF(s_, f_)/sizeof(icd_raw_word_t))
#define ICD_WOFFSETOFD(s_, f_) (IDD_OFFSETOF(s_, f_)/sizeof(icd_raw_dword_t))

//Messages traits:

//RX:
typedef icd1553_message_trait<SA_A1_rdr_operational_setting, msg_rdr_settings_and_parameters_t>  msg_rdr_settings_and_parameters_trait;
typedef icd1553_message_trait<SA_A2_rdr_operation_command, msg_rdr_operation_command_t>  msg_rdr_operation_command_trait;
typedef icd1553_message_trait<SA_A3_graphic_settings, msg_graphic_setting_t>  msg_graphic_setting_trait;

typedef icd1553_message_trait<SA_A4_navigation_andcursor_data, msg_nav_data_and_cursor_t>  msg_nav_data_and_cursor_trait;
typedef icd1553_message_trait<SA_A5_inu_high_speed_vector, msg_inu_high_speed_t>  msg_inu_high_speed_trait;

typedef icd1553_message_trait<SA_A7_data_link_targets_1, msg1_data_link_target_t>  msg1_data_link_target_trait;
typedef icd1553_message_trait<SA_A8_data_link_targets_2, msg2_data_link_target_t>  msg2_data_link_target_trait;

typedef icd1553_message_trait<SA_A9_reserved_debug, msg_dev0_reserved_t>  msg_dev0_reserved_trait;
//typedef icd1553_message_trait<21, msg_dev1_reserved_t>  msg_dev0_reserved_trait;

//TX:
typedef icd1553_message_trait<SA_B1_tws_status_1_2, tws_status_and_targets_01_02_t, 1>  tws_status_and_targets_01_02_trait;
typedef icd1553_message_trait<SA_B2_tws_status_3_4_5, tws_status_and_targets_03_04_05_t, 1>  tws_status_and_targets_03_04_05_trait;
typedef icd1553_message_trait<SA_B3_tws_status_6_7_8, tws_status_and_targets_06_07_08_t, 1>  tws_status_and_targets_06_07_08_trait;

typedef icd1553_message_trait<SA_B4_stp, spt_target_message_t, 1>  spt_target_message_trait;
typedef icd1553_message_trait<SA_B5_stt, tracked_target_message_t, 1>  hpt_target_message_trait;

typedef icd1553_message_trait<SA_B6_rdr_operational_setting_tellback, msg_settings_tellback_t, 1>  msg_settings_tellback_trait;
typedef icd1553_message_trait<SA_B7_rdrstatus_tellback, msg_rdr_status_tellback_t, 1>  msg_rdr_status_tellback_trait;

typedef icd1553_message_trait<SA_B8_bit_report, bit_report_message_t, 1>  bit_report_message_trait;

typedef icd1553_message_trait<SA_B9_reserved_1, msg_b09_t, 1>  msg_b09_trait;
typedef icd1553_message_trait<SA_B10_reserved_2, msg_b10_t, 1>  msg_b10_trait;

typedef icd1553_message_trait<SA_B0_reserved_debug, msg_dev0_result_t, 1>  msg_dev0_result_trait;

class IcdInfo
{
public:
  virtual unsigned int major_version() const =0;
  virtual unsigned int minor_version() const =0;
  virtual const char* name() const =0;
  virtual const char* pn() const =0;

  virtual ~IcdInfo() {}
};


extern IcdInfo& Icd_GetInfo();

}  //namespace icd1553

#include "evo_b1553_bite_icd.h"

#endif /* B1553_ICD_TH_H_ */
