
/* ----------------------------------------------------------------------------
 * Implements
 */
#include "UDS_Services_Common.h"

/* ----------------------------------------------------------------------------
 * Uses
 */
//#include "CommonMacros.h"
//#include "Platform_Types.h"
//#include "ProjectCfg.h"
//#include "Global.h"


#include "UDS_CoreServices_CB.h"
#include "DiagnosticR/UDS/UDS_Services_Common.h"
#include <string.h>
#include "TouchPanel.h"
//#include "TouchPanel_Cfg.h"
#include "Std_Types.h"
#include "device.h"
#include "touch/touch.h"
#include "math.h"
#include "stdlib.h"
#include <stddef.h>                     // Defines NULL
#include <stdbool.h>                    // Defines true
#include <stdlib.h>                     // Defines EXIT_FAILURE
#include "definitions.h"                // SYS function prototypes
#include "OsekCom/OsekCom.h"
#include "Speaker/Speaker.h"
#include "P417_SWTR_App_ert_rtw/P417_SWTR_App.h"
#include "TouchPanel/TouchPanel.h"
#include "forceSnsr/forcedetect.h"
#include "TLE9263/TLE926x_Main.h"
#include "DiagnosticR/Comp_ISO_15765_3/Iso15765_3.h"
#include "ModelsInterfaces/CommonMacros.h"
#include "calib_public.h"

extern UI_8 frm_diag_physresp_swtr[8];

t_UDS_ERR Get_DID_Fun1(uint8 *data)
{
    data[0] = Calib_GetData(data0)>>8;
    data[1] = Calib_GetData(data0);
    return ISO15765_3_POSITIVE_RESPONSE;
}
t_UDS_ERR Get_DID_Fun2(uint8 *data)
{
    data[0] = Calib_GetData(data1)>>8;
    data[1] = Calib_GetData(data1);
    return ISO15765_3_POSITIVE_RESPONSE;
}
t_UDS_ERR Get_DID_Fun3(uint8 *data)
{
    data[0] = Calib_GetData(data2)>>8;
    data[1] = Calib_GetData(data2);    
    return ISO15765_3_POSITIVE_RESPONSE;
}
t_UDS_ERR Get_DID_UP(uint8 *data)
{
    data[0] = Calib_GetData(data3)>>8;
    data[1] = Calib_GetData(data3);    
    return ISO15765_3_POSITIVE_RESPONSE;
}
t_UDS_ERR Get_DID_DOWN(uint8 *data)
{
    data[0] = Calib_GetData(data4)>>8;
    data[1] = Calib_GetData(data4);    
    return ISO15765_3_POSITIVE_RESPONSE;
}
t_UDS_ERR Get_DID_LEFT(uint8 *data)
{
    data[0] = Calib_GetData(data5)>>8;
    data[1] = Calib_GetData(data5);    
    return ISO15765_3_POSITIVE_RESPONSE;
}
t_UDS_ERR Get_DID_RIGHT(uint8 *data)
{
    data[0] = Calib_GetData(data6)>>8;
    data[1] = Calib_GetData(data6);    
    return ISO15765_3_POSITIVE_RESPONSE;
}
t_UDS_ERR Get_DID_OK(uint8 *data)
{
    data[0] = Calib_GetData(data7)>>8;
    data[1] = Calib_GetData(data7);    
    return ISO15765_3_POSITIVE_RESPONSE;
}


/* ----------------------------------------------------------------------------
 * Private macros
 */
/********************* MACRO for support DID read *****************************/
#define SUPPORT_ID_FOR_22_SERVICE				((uint8)0xDF)
#define SUPPORT_ID_FOR_2E_SERVICE				((uint8)0xEC)
#define SUPPORT_ID_FOR_2F_SERVICE				((uint8)0xED)
#define SUPPORT_ID_FOR_31_SERVICE				((uint8)0xEE)

#define    BAT_MODE_A         ((uint8)0)
#define    BAT_MODE_B  		  ((uint8)1)
#define    BAT_MODE_C         ((uint8)2)

/* ----------------------------------------------------------------------------
 * Forward declarations
 */
 UI_16 g16_DiagTouchPressSenRes[3][15] = {0};

static t_UDS_ERR Get_DID_GAC_Active_Diagnostic_session(uint8 *data);

t_UDSReadDidSubCommands uds_did_read_commands[] =
{
  /** ECU Identification ***********************************************************************************/
  { DID_CD_SYSID_ACTIVE_DIAG_SESSION,     1, UDS_DEFAULT_SESSION, Get_DID_GAC_Active_Diagnostic_session    },
  { DID_CD_SYSID_VIN,                    17, UDS_DEFAULT_SESSION, Get_DID_CD_SYSID_VIN        		       },
  { DID_CD_SYSID_REPROGRAMING_DATE ,      4, UDS_DEFAULT_SESSION, Get_DID_Reprogramming_Date               },
  { DID_CD_SYSID_SYSTEMSUPPLIER_ID,      6 , UDS_DEFAULT_SESSION, Get_DID_System_Supplier_Id               },
  { DID_CD_SYSID_SPARE_PART_NUMBER,      21, UDS_DEFAULT_SESSION, Get_DID_Gac_Spare_Number                 },
  { DID_CD_SYSID_REPAIR_SHOP_CODE,                    16, UDS_DEFAULT_SESSION, Get_DID_GAC_Repair_Shop_Id        		       },
  { DID_CD_SYSID_ECU_HW_VER_NUMBER,       16, UDS_DEFAULT_SESSION, Get_DID_Gac_Hw_Version                   },
  { DID_CD_SYSID_ECU_SW_VER_NUMBER , 	 16, UDS_DEFAULT_SESSION, Get_DID_Gac_Ecusw_Version                 },
  /*Application*/
  { DID_TOUCH_SEN1_BASE_LINE , 	 2, UDS_DEFAULT_SESSION, Get_DID_TouchSen1_BaseLine                },
  { DID_TOUCH_SEN2_BASE_LINE , 	 2, UDS_DEFAULT_SESSION, Get_DID_TouchSen2_BaseLine                },
  { DID_TOUCH_SEN3_BASE_LINE , 	 2, UDS_DEFAULT_SESSION, Get_DID_TouchSen3_BaseLine                },
  { DID_TOUCH_SEN4_BASE_LINE , 	 2, UDS_DEFAULT_SESSION, Get_DID_TouchSen4_BaseLine                },
  { DID_TOUCH_SEN5_BASE_LINE , 	 2, UDS_DEFAULT_SESSION, Get_DID_TouchSen5_BaseLine                },
  { DID_TOUCH_SEN6_BASE_LINE , 	 2, UDS_DEFAULT_SESSION, Get_DID_TouchSen6_BaseLine                },
  { DID_TOUCH_SEN7_BASE_LINE , 	 2, UDS_DEFAULT_SESSION, Get_DID_TouchSen7_BaseLine                },
  { DID_TOUCH_SEN8_BASE_LINE , 	 2, UDS_DEFAULT_SESSION, Get_DID_TouchSen8_BaseLine                },
  { DID_TOUCH_SEN9_BASE_LINE , 	 2, UDS_DEFAULT_SESSION, Get_DID_TouchSen9_BaseLine                },
  { DID_TOUCH_SEN10_BASE_LINE , 	 2, UDS_DEFAULT_SESSION, Get_DID_TouchSen10_BaseLine                },
  { DID_TOUCH_SEN11_BASE_LINE , 	 2, UDS_DEFAULT_SESSION, Get_DID_TouchSen11_BaseLine                },
  { DID_TOUCH_SEN12_BASE_LINE , 	 2, UDS_DEFAULT_SESSION, Get_DID_TouchSen12_BaseLine                },
  { DID_TOUCH_SEN13_BASE_LINE , 	 2, UDS_DEFAULT_SESSION, Get_DID_TouchSen13_BaseLine                },
  { DID_TOUCH_SEN14_BASE_LINE , 	 2, UDS_DEFAULT_SESSION, Get_DID_TouchSen14_BaseLine                },
  { DID_TOUCH_SEN15_BASE_LINE , 	 2, UDS_DEFAULT_SESSION, Get_DID_TouchSen15_BaseLine                },

   { DID_TOUCH_SEN1_SIGNAL , 	 2, UDS_DEFAULT_SESSION, Get_DID_TouchSen1_Signal                },
   { DID_TOUCH_SEN2_SIGNAL , 	 2, UDS_DEFAULT_SESSION, Get_DID_TouchSen2_Signal                },
   { DID_TOUCH_SEN3_SIGNAL , 	 2, UDS_DEFAULT_SESSION, Get_DID_TouchSen3_Signal                },
   { DID_TOUCH_SEN4_SIGNAL , 	 2, UDS_DEFAULT_SESSION, Get_DID_TouchSen4_Signal                },
   { DID_TOUCH_SEN5_SIGNAL , 	 2, UDS_DEFAULT_SESSION, Get_DID_TouchSen5_Signal                },
   { DID_TOUCH_SEN6_SIGNAL , 	 2, UDS_DEFAULT_SESSION, Get_DID_TouchSen6_Signal                },
   { DID_TOUCH_SEN7_SIGNAL , 	 2, UDS_DEFAULT_SESSION, Get_DID_TouchSen7_Signal                },
   { DID_TOUCH_SEN8_SIGNAL , 	 2, UDS_DEFAULT_SESSION, Get_DID_TouchSen8_Signal                },
   { DID_TOUCH_SEN9_SIGNAL , 	 2, UDS_DEFAULT_SESSION, Get_DID_TouchSen9_Signal                },
   { DID_TOUCH_SEN10_SIGNAL , 	 2, UDS_DEFAULT_SESSION, Get_DID_TouchSen10_Signal                },
   { DID_TOUCH_SEN11_SIGNAL , 	 2, UDS_DEFAULT_SESSION, Get_DID_TouchSen11_Signal                },
   { DID_TOUCH_SEN12_SIGNAL , 	 2, UDS_DEFAULT_SESSION, Get_DID_TouchSen12_Signal                },
   { DID_TOUCH_SEN13_SIGNAL , 	 2, UDS_DEFAULT_SESSION, Get_DID_TouchSen13_Signal                },
   { DID_TOUCH_SEN14_SIGNAL , 	 2, UDS_DEFAULT_SESSION, Get_DID_TouchSen14_Signal                },
   { DID_TOUCH_SEN15_SIGNAL , 	 2, UDS_DEFAULT_SESSION, Get_DID_TouchSen15_Signal                },

   { DID_PRESEE_SEN_BASELINE , 	 2, UDS_DEFAULT_SESSION, Get_DID_PressSen_Baseline                },
   { DID_PRESEE_SEN_SIGNAL , 	 2, UDS_DEFAULT_SESSION, Get_DID_PressSen_Signal                },
   { DID_PRESEE_SEN_PRE_VAL , 	 2, UDS_DEFAULT_SESSION, Get_DID_Pre_Value                },
   
   {DID_FUN1, 2, UDS_DEFAULT_SESSION, Get_DID_Fun1},
   {DID_FUN2, 2, UDS_DEFAULT_SESSION, Get_DID_Fun2},  
   {DID_FUN3, 2, UDS_DEFAULT_SESSION, Get_DID_Fun3},
   {DID_UP, 2, UDS_DEFAULT_SESSION, Get_DID_UP},
   {DID_DOWN, 2, UDS_DEFAULT_SESSION, Get_DID_DOWN},
   {DID_LEFT, 2, UDS_DEFAULT_SESSION, Get_DID_LEFT},
   {DID_RIGHT, 2, UDS_DEFAULT_SESSION, Get_DID_RIGHT},
   {DID_OK, 2, UDS_DEFAULT_SESSION, Get_DID_OK},
};


static t_UDS_ERR Get_DID_GAC_Active_Diagnostic_session(uint8 *data)
{
	data[0] = Iso15765_3QueryActiveSession();
    return ISO15765_3_POSITIVE_RESPONSE;
}

uint8 GetReadDidServiceNumber(void)
{
    return NOOF(uds_did_read_commands);
}
