#include "g346_common.h"
#include "g346_a3.h"
#include "icd_g346.h"
using namespace grifo_icd;

GrifoMsg_A3::GrifoMsg_A3()
{
    Ads1553MsgQ* a3=Ads1553Manager::instance().getMsgObj("A3");

    GRIFO_ADS_MAP(waypoints[0].dWayPoint, "DISPL_WAY_01", msg_graphic_setting_t, graphic_order, waypoint_01_flag_field_t, *a3);
    GRIFO_ADS_MAP(waypoints[1].dWayPoint, "DISPL_WAY_02", msg_graphic_setting_t, graphic_order, waypoint_02_flag_field_t, *a3);
    GRIFO_ADS_MAP(waypoints[2].dWayPoint, "DISPL_WAY_03", msg_graphic_setting_t, graphic_order, waypoint_03_flag_field_t, *a3);

    GRIFO_ADS_MAP(dIntFlightDirector, "INT_FLIGHT_DIR", msg_graphic_setting_t, graphic_order, intercept_flight_director_field_t, *a3);
    GRIFO_ADS_MAP(dBreakAwayCue, "BREAK_AWAY_CUE", msg_graphic_setting_t, graphic_order, break_away_cue_field_t, *a3);
    GRIFO_ADS_MAP(dIntZonesAndTgtTip, "INT_ZONES_AND_TGT_TIP", msg_graphic_setting_t, graphic_order, intercept_zones_and_target_tip_field_t, *a3);
    GRIFO_ADS_MAP(dTimeToGoToCursor, "TIME_TO_GO_TO_CURSOR", msg_graphic_setting_t, graphic_order, time_to_go_to_cursor_field_t, *a3);
    GRIFO_ADS_MAP(dAllowableSteeringErrorCircle, "ALLOWABLE_STEERING_ERROR_CIRCLE", msg_graphic_setting_t, graphic_order, allowable_steering_error_circle_field_t, *a3);
    GRIFO_ADS_MAP(dAttackSteeringCue, "ATTACK_STEERING_CUE", msg_graphic_setting_t, graphic_order, attack_steering_cue_field_t, *a3);

    GRIFO_ADS_MAP(dBullsEye, "BULLS_EYE", msg_graphic_setting_t, graphic_order, bulls_eye_identifier_field_t, *a3);
    GRIFO_ADS_MAP(dTimeToGoToCursorValue, "TIME_TO_GO_TO_CURSOR_VALUE", msg_graphic_setting_t, time_to_go_to_cursor, time_to_go_to_cursor_t, *a3);

    //WAYPOINT
    for(int i=0; i<3; ++i)
    {
        const float WP_LATLON_LSB=ICD1553_WAYPOINT_LATLON_LSB*GC_K_RAD_TO_DEG;

        const unsigned int wpid=i+1;

        WaypointInfo& w=waypoints[i];

        //tmp=QString("WAY_%1_LAT").arg(i);
        //GRIFO_ADS_MAP_SCALED(w.dWaypointLat, tmp, msg_graphic_setting_t, waypoints.wp[i].waypoint_lat_sel_qual.waypoint_lat, icd_waypoint_latlon_t, *a3, 1);

        w.dWaypointLat.setDataName(QString("WAY_%1_LAT").arg(wpid).toLatin1().constData());
        w.dWaypointLat.setFormat(waypoint_latlon_t::start_bit, waypoint_latlon_t::set_mask);
        w.dWaypointLat.setLsb(WP_LATLON_LSB);
        w.dWaypointLat.attachToMsg(a3, ((i*sizeof(waypoint_data_t))/2)+ICD_WOFFSETOF(msg_graphic_setting_t, waypoints.wp[0].waypoint_lat_sel_qual));
        g346_ads_data_setmanip<int32_t>(w.dWaypointLat);


        w.dWaypointLon.setDataName(QString("WAY_%1_LON").arg(wpid));
        w.dWaypointLon.setFormat(waypoint_latlon_t::start_bit, waypoint_latlon_t::set_mask);
        w.dWaypointLon.setLsb(WP_LATLON_LSB);
        w.dWaypointLon.attachToMsg(a3, ((i*sizeof(waypoint_data_t))/2)+ICD_WOFFSETOF(msg_graphic_setting_t, waypoints.wp[0].waypoint_lon_code));
        g346_ads_data_setmanip<int32_t>(w.dWaypointLon);

        w.dWaypointCode.setDataName(QString("WAY_%1_CODE").arg(wpid));
        w.dWaypointCode.setFormat(waypoint_code_t::start_bit, waypoint_code_t::set_mask);
        w.dWaypointCode.attachToMsg(a3, 1+((i*sizeof(waypoint_data_t))/2)+ICD_WOFFSETOF(msg_graphic_setting_t, waypoints.wp[0].waypoint_lon_code));

        w.dWaypointQualValidity.setDataName(QString("WAY_VAL_%1").arg(wpid));
        w.dWaypointQualValidity.setFormat(waypoint_qualifier_validity_t::start_bit, waypoint_qualifier_validity_t::set_mask);
        w.dWaypointQualValidity.attachToMsg(a3, 1+((i*sizeof(waypoint_data_t))/2)+ICD_WOFFSETOF(msg_graphic_setting_t, waypoints.wp[0].waypoint_lat_sel_qual));//ICD_WOFFSETOF(msg_graphic_setting_t, waypoint_01_lat_sel_qual));

        w.dWaypointFytSel.setDataName(QString("WAY_FYT_%1").arg(wpid));
        w.dWaypointFytSel.setFormat(waypoint_fyt_selection_field_t::start_bit, waypoint_fyt_selection_field_t::set_mask);
        w.dWaypointFytSel.attachToMsg(a3, 1+((i*sizeof(waypoint_data_t))/2)+ICD_WOFFSETOF(msg_graphic_setting_t, waypoints.wp[0].waypoint_lat_sel_qual));//ICD_WOFFSETOF(msg_graphic_setting_t, waypoint_01_lat_sel_qual));

        w.dWaypointQualValue.setDataName(QString("WAY_VALUE_%1").arg(wpid));
        w.dWaypointQualValue.setFormat(waypoint_qualifier_value_field_t::start_bit, waypoint_qualifier_value_field_t::set_mask);
        w.dWaypointQualValue.attachToMsg(a3, 1+((i*sizeof(waypoint_data_t))/2)+ICD_WOFFSETOF(msg_graphic_setting_t, waypoints.wp[0].waypoint_lat_sel_qual));//ICD_WOFFSETOF(msg_graphic_setting_t, waypoint_01_lat_sel_qual));

    }
#if 0
    dWaypoint1Lat.setDataName("WAY_1_LAT");
    dWaypoint1Lat.setFormat(waypoint_lat_t::start_bit, waypoint_lat_t::set_mask);
    dWaypoint1Lat.setLsb(ICD1553_SEMICIRCLE2_RAD_LSB*GC_K_RAD_TO_DEG);
    dWaypoint1Lat.attachToMsg(a3, ICD_WOFFSETOF(msg_graphic_setting_t, waypoint_01_lat_sel_qual));

    dWaypoint1Lon.setDataName("WAY_1_LON");
    dWaypoint1Lon.setFormat(waypoint_lon_t::start_bit, waypoint_lon_t::set_mask);
    dWaypoint1Lon.setLsb(ICD1553_SEMICIRCLE2_RAD_LSB*GC_K_RAD_TO_DEG);
    dWaypoint1Lon.attachToMsg(a3, ICD_WOFFSETOF(msg_graphic_setting_t, waypoint_01_lon_code));

    dWaypoint1Code.setDataName("WAY_1_CODE");
    dWaypoint1Code.setFormat(waypoint_code_t::start_bit, waypoint_code_t::set_mask);
    dWaypoint1Code.attachToMsg(a3, ICD_WOFFSETOF(msg_graphic_setting_t, waypoint_01_lon_code));

    dWaypoint1QualValidity.setDataName("WAY_VAL_1");
    dWaypoint1QualValidity.setFormat(waypoint_qualifier_validity_t::start_bit, waypoint_qualifier_validity_t::set_mask);
    dWaypoint1QualValidity.attachToMsg(a3, ICD_WOFFSETOF(msg_graphic_setting_t, waypoint_01_lat_sel_qual));

    dWaypoint1FytSel.setDataName("WAY_FYT_1");
    dWaypoint1FytSel.setFormat(waypoint_fyt_selection_field_t::start_bit, waypoint_fyt_selection_field_t::set_mask);
    dWaypoint1FytSel.attachToMsg(a3, ICD_WOFFSETOF(msg_graphic_setting_t, waypoint_01_lat_sel_qual));

    dWaypoint1QualValue.setDataName("WAY_VALUE_1");
    dWaypoint1QualValue.setFormat(waypoint_qualifier_value_field_t::start_bit, waypoint_qualifier_value_field_t::set_mask);
    dWaypoint1QualValue.attachToMsg(a3, ICD_WOFFSETOF(msg_graphic_setting_t, waypoint_01_lat_sel_qual));

    dWaypoint2Lat.setDataName("WAY_2_LAT");
    dWaypoint2Lat.setFormat(waypoint_lat_t::start_bit, waypoint_lat_t::set_mask);
    dWaypoint2Lat.setLsb(ICD1553_SEMICIRCLE2_RAD_LSB*GC_K_RAD_TO_DEG);
    dWaypoint2Lat.attachToMsg(a3, ICD_WOFFSETOF(msg_graphic_setting_t, waypoint_02_lat_sel_qual));

    dWaypoint2Lon.setDataName("WAY_2_LON");
    dWaypoint2Lon.setFormat(waypoint_lon_t::start_bit, waypoint_lon_t::set_mask);
    dWaypoint2Lon.setLsb(ICD1553_SEMICIRCLE2_RAD_LSB*GC_K_RAD_TO_DEG);
    dWaypoint2Lon.attachToMsg(a3, ICD_WOFFSETOF(msg_graphic_setting_t, waypoint_02_lon_code));

    dWaypoint2Code.setDataName("WAY_2_CODE");
    dWaypoint2Code.setFormat(waypoint_code_t::start_bit, waypoint_code_t::set_mask);
    dWaypoint2Code.attachToMsg(a3, ICD_WOFFSETOF(msg_graphic_setting_t, waypoint_02_lon_code));

    dWaypoint2QualValidity.setDataName("WAY_VAL_2");
    dWaypoint2QualValidity.setFormat(waypoint_qualifier_validity_t::start_bit, waypoint_qualifier_validity_t::set_mask);
    dWaypoint2QualValidity.attachToMsg(a3, ICD_WOFFSETOF(msg_graphic_setting_t, waypoint_02_lat_sel_qual));

    dWaypoint2FytSel.setDataName("WAY_FYT_2");
    dWaypoint2FytSel.setFormat(waypoint_fyt_selection_field_t::start_bit, waypoint_fyt_selection_field_t::set_mask);
    dWaypoint2FytSel.attachToMsg(a3, ICD_WOFFSETOF(msg_graphic_setting_t, waypoint_02_lat_sel_qual));

    dWaypoint2QualValue.setDataName("WAY_VALUE_2");
    dWaypoint2QualValue.setFormat(waypoint_qualifier_value_field_t::start_bit, waypoint_qualifier_value_field_t::set_mask);
    dWaypoint2QualValue.attachToMsg(a3, ICD_WOFFSETOF(msg_graphic_setting_t, waypoint_02_lat_sel_qual));

    dWaypoint3Lat.setDataName("WAY_3_LAT");
    dWaypoint3Lat.setFormat(waypoint_lat_t::start_bit, waypoint_lat_t::set_mask);
    dWaypoint3Lat.setLsb(ICD1553_SEMICIRCLE2_RAD_LSB*GC_K_RAD_TO_DEG);
    dWaypoint3Lat.attachToMsg(a3, ICD_WOFFSETOF(msg_graphic_setting_t, waypoint_03_lat_sel_qual));

    dWaypoint3Lon.setDataName("WAY_3_LON");
    dWaypoint3Lon.setFormat(waypoint_lon_t::start_bit, waypoint_lon_t::set_mask);
    dWaypoint3Lon.setLsb(ICD1553_SEMICIRCLE2_RAD_LSB*GC_K_RAD_TO_DEG);
    dWaypoint3Lon.attachToMsg(a3, ICD_WOFFSETOF(msg_graphic_setting_t, waypoint_03_lon_code));

    dWaypoint3Code.setDataName("WAY_3_CODE");
    dWaypoint3Code.setFormat(waypoint_code_t::start_bit, waypoint_code_t::set_mask);
    dWaypoint3Code.attachToMsg(a3, ICD_WOFFSETOF(msg_graphic_setting_t, waypoint_03_lon_code));

    dWaypoint3QualValidity.setDataName("WAY_VAL_3");
    dWaypoint3QualValidity.setFormat(waypoint_qualifier_validity_t::start_bit, waypoint_qualifier_validity_t::set_mask);
    dWaypoint3QualValidity.attachToMsg(a3, ICD_WOFFSETOF(msg_graphic_setting_t, waypoint_03_lat_sel_qual));

    dWaypoint3FytSel.setDataName("WAY_FYT_3");
    dWaypoint3FytSel.setFormat(waypoint_fyt_selection_field_t::start_bit, waypoint_fyt_selection_field_t::set_mask);
    dWaypoint3FytSel.attachToMsg(a3, ICD_WOFFSETOF(msg_graphic_setting_t, waypoint_03_lat_sel_qual));

    dWaypoint3QualValue.setDataName("WAY_VALUE_3");
    dWaypoint3QualValue.setFormat(waypoint_qualifier_value_field_t::start_bit, waypoint_qualifier_value_field_t::set_mask);
    dWaypoint3QualValue.attachToMsg(a3, ICD_WOFFSETOF(msg_graphic_setting_t, waypoint_03_lat_sel_qual));
#endif

    //INTECEPT FLIGHT

    GRIFO_ADS_MAP(dIntModeSel, "INT_MODE_SEL", msg_graphic_setting_t, intercept_flight_director_x_and_selectors, intercept_mode_selector_field_t, *a3);
    GRIFO_ADS_MAP(dIFDModeSel, "IFD_MODE_SEL", msg_graphic_setting_t, intercept_flight_director_x_and_selectors, normal_dashed_selector_field_t, *a3);
    GRIFO_ADS_MAP(dAscModeSel, "ASC_MODE_SEL", msg_graphic_setting_t, asc_x_and_selector, normal_blink_selector_t, *a3);
    GRIFO_ADS_MAP(dAsecModelSel, "ASEC_MODE_SEL", msg_graphic_setting_t, asec_radius_and_selector, normal_blink_selector_t, *a3);
    GRIFO_ADS_MAP(dIFDX, "IFD_X", msg_graphic_setting_t, intercept_flight_director_x_and_selectors, display_coord_t, *a3);
    GRIFO_ADS_MAP(dIFDY, "IFD_Y", msg_graphic_setting_t, intercept_flight_director_y, display_coord_t, *a3);
    GRIFO_ADS_MAP(dRMinInt, "R_MIN_INT", msg_graphic_setting_t, intercept_zone_r_min, display_coord_t, *a3);
    GRIFO_ADS_MAP(dRMaxInt, "R_MAX_INT", msg_graphic_setting_t, intercept_zone_r_max, display_coord_t, *a3);
    GRIFO_ADS_MAP(dNoEscapeY, "NO_ESCAPE_Y", msg_graphic_setting_t, no_escape_zone_r_max, display_coord_t, *a3);
    GRIFO_ADS_MAP(dTargetTipY, "TARGET_TIP_Y", msg_graphic_setting_t, intercept_zone_target_tip, display_coord_t, *a3);
    GRIFO_ADS_MAP(dAscX, "ASC_X", msg_graphic_setting_t, asc_x_and_selector, display_coord_t, *a3);
    GRIFO_ADS_MAP(dAscY, "ASC_Y", msg_graphic_setting_t, asc_y, display_coord_t, *a3);
    GRIFO_ADS_MAP(dAsecRadius, "ASEC_RADIUS", msg_graphic_setting_t, asec_radius_and_selector, radius_of_the_asec_t, *a3);

    //HPT/SPT
    GRIFO_ADS_MAP(dHPTIntZone, "HPT_INT_ZONE", msg_graphic_setting_t, tracked_target_info, hpt_within_intercept_zone_selector_t, *a3);
    GRIFO_ADS_MAP(dSPTIntZone, "SPT_INT_ZONE", msg_graphic_setting_t, tracked_target_info, spt_within_intercept_zone_selector_t, *a3);
    GRIFO_ADS_MAP(dHPTDatalink, "HPT_DATALINK", msg_graphic_setting_t, tracked_target_info, hpt_data_link_correlation_selector_t, *a3);
    GRIFO_ADS_MAP(dSPTDatalink, "SPT_DATALINK", msg_graphic_setting_t, tracked_target_info, spt_data_link_correlation_selector_t, *a3);
    GRIFO_ADS_MAP(dHPTFriendFoe, "HPT_FRIEND_FOE", msg_graphic_setting_t, tracked_target_info, hpt_friend_foe_selector_field_t, *a3);
    GRIFO_ADS_MAP(dSPTFriendFoe, "SPT_FRIEND_FOE", msg_graphic_setting_t, tracked_target_info, spt_friend_foe_selector_field_t, *a3);
    GRIFO_ADS_MAP(dTWSTgt1, "TWS_TRACKED_TGT_1", msg_graphic_setting_t, tracked_target_info, tws_tracket_tgt_01_within_int_zone_selector_t, *a3);
    GRIFO_ADS_MAP(dTWSTgt2, "TWS_TRACKED_TGT_2", msg_graphic_setting_t, tracked_target_info, tws_tracket_tgt_02_within_int_zone_selector_t, *a3);
    GRIFO_ADS_MAP(dTWSTgt3, "TWS_TRACKED_TGT_3", msg_graphic_setting_t, tracked_target_info, tws_tracket_tgt_03_within_int_zone_selector_t, *a3);
    GRIFO_ADS_MAP(dTWSTgt4, "TWS_TRACKED_TGT_4", msg_graphic_setting_t, tracked_target_info, tws_tracket_tgt_04_within_int_zone_selector_t, *a3);
    GRIFO_ADS_MAP(dTWSTgt5, "TWS_TRACKED_TGT_5", msg_graphic_setting_t, tracked_target_info, tws_tracket_tgt_05_within_int_zone_selector_t, *a3);
    GRIFO_ADS_MAP(dTWSTgt6, "TWS_TRACKED_TGT_6", msg_graphic_setting_t, tracked_target_info, tws_tracket_tgt_06_within_int_zone_selector_t, *a3);
    GRIFO_ADS_MAP(dTWSTgt7, "TWS_TRACKED_TGT_7", msg_graphic_setting_t, tracked_target_info, tws_tracket_tgt_07_within_int_zone_selector_t, *a3);
    GRIFO_ADS_MAP(dTWSTgt8, "TWS_TRACKED_TGT_8", msg_graphic_setting_t, tracked_target_info, tws_tracket_tgt_08_within_int_zone_selector_t, *a3);

    GRIFO_ADS_MAP(dTWSTgtId1, "TWS_TRACKED_TGT_ID_1", msg_graphic_setting_t, track_id_of_tws_tracked_targets_01_and_02, track_id_of_tws_tracked_tgt_xx_t, *a3);
    GRIFO_ADS_MAP(dTWSTgtId2, "TWS_TRACKED_TGT_ID_2", msg_graphic_setting_t, track_id_of_tws_tracked_targets_01_and_02, track_id_of_tws_tracked_tgt_yy_t, *a3);
    GRIFO_ADS_MAP(dTWSTgtId3, "TWS_TRACKED_TGT_ID_3", msg_graphic_setting_t, track_id_of_tws_tracked_targets_03_and_04, track_id_of_tws_tracked_tgt_xx_t, *a3);
    GRIFO_ADS_MAP(dTWSTgtId4, "TWS_TRACKED_TGT_ID_4", msg_graphic_setting_t, track_id_of_tws_tracked_targets_03_and_04, track_id_of_tws_tracked_tgt_yy_t, *a3);
    GRIFO_ADS_MAP(dTWSTgtId5, "TWS_TRACKED_TGT_ID_5", msg_graphic_setting_t, track_id_of_tws_tracked_targets_05_and_06, track_id_of_tws_tracked_tgt_xx_t, *a3);
    GRIFO_ADS_MAP(dTWSTgtId6, "TWS_TRACKED_TGT_ID_6", msg_graphic_setting_t, track_id_of_tws_tracked_targets_05_and_06, track_id_of_tws_tracked_tgt_yy_t, *a3);
    GRIFO_ADS_MAP(dTWSTgtId7, "TWS_TRACKED_TGT_ID_7", msg_graphic_setting_t, track_id_of_tws_tracked_targets_07_and_08, track_id_of_tws_tracked_tgt_xx_t, *a3);
    GRIFO_ADS_MAP(dTWSTgtId8, "TWS_TRACKED_TGT_ID_8", msg_graphic_setting_t, track_id_of_tws_tracked_targets_07_and_08, track_id_of_tws_tracked_tgt_yy_t, *a3);
}
