OneCompiler

2

362

Example heading with h2 size

Example heading with h3 size

Following is sample java code.


import win32com.client
import time
# import ctypes
import globals
import step_libraries
from datetime import datetime
import common_fcns
import sys
import os
import model_path


# clr.AddReference(
#     "ASAM.XIL.Implementation.TestbenchFactory, Version=2.1.0.0, Culture=neutral, PublicKeyToken=fc9d65855b27d387")
# clr.AddReference("ASAM.XIL.Interfaces, Version=2.1.0.0, Culture=neutral, PublicKeyToken=bf471dff114ae984")
# clr.AddReference(
#     "ASAM.XIL.Implementation.FrameworkFactory, Version=2.1.0.0, Culture=neutral, PublicKeyToken=d64b0277da8a2c74")
#
# #Import XIL API.NET classes from the .NET assemblies
# from ASAM.XIL.Implementation.TestbenchFactory.Testbench import TestbenchFactory
# from ASAM.XIL.Interfaces.Testbench.Common.Error import TestbenchPortException
# from ASAM.XIL.Interfaces.Testbench.MAPort.Enum import MAPortState
#

# def setUp():
#     global DemoMAPort, MyValueFactory
#     MAPortConfigFile = model_path.MAPortConfigFile
#
#     WorkingDir = os.path.dirname(sys.argv[0])
#     if not os.path.isdir(WorkingDir):
#         WorkingDir = os.getcwd()
#     if not os.path.isdir(WorkingDir):
#         os.mkdir(WorkingDir)
#
#     MAPortConfigFile = os.path.join(WorkingDir, MAPortConfigFile)
#
#     try:
#         MyTestbenchFactory = TestbenchFactory()
#         MyTestbench = MyTestbenchFactory.CreateVendorSpecificTestbench("dSPACE GmbH", "XIL API", "2018-B")
#         MyMAPortFactory = MyTestbench.MAPortFactory
#         globals.MyValueFactory = MyTestbench.ValueFactory
#
#         print("Creating MAPort instance...")
#         # Create an MAPort object using the MAPortFactory
#         globals.DemoMAPort = MyMAPortFactory.CreateMAPort("DemoMAPort")
#         print("...done.\n")
#
#         # Load the MAPort configuration
#         print("Configuring MAPort...")
#         DemoMAPortConfig = globals.DemoMAPort.LoadConfiguration(MAPortConfigFile)
#
#         # Apply the MAPort configuration
#         globals.DemoMAPort.Configure(DemoMAPortConfig, False)
#         print("...done.\n")
#
#         if globals.DemoMAPort.State != MAPortState.eSIMULATION_RUNNING:
#             # Start the simulation
#             print("Starting simulation...")
#             globals.DemoMAPort.StartSimulation()
#             print("...done.\n")
#
#         return globals.DemoMAPort, globals.MyValueFactory
#
#     except TestbenchPortException as ex:
#         print("A TestbenchPortException occurred:")
#         print(f"CodeDescription: {ex.CodeDescription}")
#         print(f"VendorCodeDescription: {ex.VendorCodeDescription}")
#         raise



try:

    #______________________________________________________________________________

    globals.excel = win32com.client.Dispatch('Excel.application')
    globals.dir_path = os.path.dirname(os.path.realpath(sys.argv[0]))
    print(globals.dir_path)
    a = globals.dir_path.rfind("\\")
    print("vALUE OF A : ",a)
    fileLoc = globals.dir_path[:a]
    print(fileLoc)

    tl_path = r"C:\Users\AK001027556\Desktop\python_excel_script\Automation\DEMO Test\Test_Library_All_Feature_Activation.xlsx"
    # tl_path = model_path.ExcelFilePath
    Result_loc, globals.Report_loc = common_fcns.create_result(tl_path)
#_______________________
    print(Result_loc)
    print()
    print(globals.Report_loc)
#________________________
    globals.Result_file = common_fcns.openxl(globals.excel, Result_loc)
# _______________________
    print(globals.Result_file)

# ________________________

    now = datetime.now()
    # _______________________
    print(now)
    # ________________________


    dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
    globals.Result_file.Worksheets(1).Range("C1").Value = dt_string
    print("Opening TL - Completed")
    print("Result_loc", Result_loc, "Report_loc", globals.Report_loc, "Result_file", globals.Result_file)



    globals.Sheet_No = globals.Result_file.Sheets.Count
    # _______________________
    print(globals.Sheet_No)
    # ________________________
    #testsheet_no=1
    print("tl_operation_start")
    ##TL operation Start--------------------

    for testsheet_no in range(1, globals.Sheet_No + 1):
        globals.TL_sheet = globals.Result_file.Worksheets(testsheet_no)
        globals.excel.Visible = True
        SL_start = globals.TL_sheet.Range("C4")
        xl_endloc = "C" + str(globals.TL_sheet.Rows.Count)
        print("xl_endloc", xl_endloc)
        globals.SL_endrow = globals.TL_sheet.Range(xl_endloc).End(-4162).Row

        SL_endloc = "C" + str(globals.SL_endrow)
        print("SL_endloc", SL_endloc)
        SL_range = globals.TL_sheet.Range(SL_start, globals.TL_sheet.Range(SL_endloc))
        globals.SL = SL_start

        # #to update debug file and command window
        TL_starttime = time.time()
        # globals.debug_file.write("\n------------[START] - TL Execution-------------    ")


        print("\n------------[START] - TL Execution-------------")
        print("SL.Row", globals.SL.Row)
        print("SL_endrow", globals.SL_endrow)

        while globals.SL.Row <= globals.SL_endrow:
            #print ("globals.SL.Value ",globals.SL.Value)
            print("_______________________________________________________________")
            print()
            globals.rowNum = globals.SL.Row
            globals.clmNum = globals.SL_endrow
            print("SL.Row inside while loop", globals.SL.Row)
            print("SL_endrow inside while loop", globals.SL_endrow)
            print("SL :", globals.SL)
            print("SL Value : ", globals.SL.Value)
            if globals.SL.Value != None:
                try:
                    print("_______________________________________________________________")
                    print()
                    #to update debug file and command window
                    # globals.debug_file.write("\n" + str(globals.SL.Row) + "  " + str(globals.SL.Value) + "    ")
                    #eg: [1/40] - CD_SetKeyOn
                    print("[" + str(globals.SL.Row) + "/" + str(globals.SL_endrow) + "] - " + str(globals.SL.Value))
                    # if(str(globals.SL.Value)=="ECU_reset"):
                    #    common_fcns.post_condition()
                    #    #print("end_loc in main function",data)
                    #    common_fcns.Print_State()
                    # else:
                    globals.Result_file.Worksheets(testsheet_no)
                    #Getting the function name of the SL and calling it to execute
                    Call_SL = getattr(step_libraries, globals.SL.Value)
                    print("main call SL", Call_SL)
                    start_time = time.time()
                    # print("globals.SL.Row", globals.SL.Row, "globals.SL.Value", globals.SL.Value,
                    #       'globals.SL.Offset(1,2).Value', globals.SL.Offset(1, 2).Value, "globals.SL.Offset(1,3).Value",
                    #       globals.SL.Offset(1, 3).Value)

                    print("globals.SL.Row   ", globals.SL.Row)
                    print("Action : ", globals.SL.Value)
                    print('Message : ', globals.SL.Offset(1, 2).Value)
                    print("Signal : ", globals.SL.Offset(1, 3).Value)
                    print("Value : ", globals.SL.offset(1, 4).Value)
                    # Call_SL()
                    if callable(Call_SL):
                        result = Call_SL()

                    else:
                        print("The attribute is not callable or does not exists.")
                    # print("SL called")
                    if globals.SL.Offset(1, 5).Value != "ERROR":
                        elapsed_time = time.time() - start_time
                        globals.SL.Offset(1, 8).Value = elapsed_time

                    print("_______________________________________________________________")


                except Exception as log:
                    globals.SL.Offset(1, 8).Value = "Incorrect sequence name"
                    globals.SL.Offset(1, 5).Value = "ERROR"
                    # globals.debug_file.write("ERROR    " + str(log))


            #wait for one second between SLs, delay time could be changed by TA_SetDelayBetweenSteps SL
            delay_time = 1
            time.sleep(globals.delay_time)
            globals.SL = globals.SL.Offset(2, 1)
        print("End of while in main")
        #commenting for now becuase only single sheet used

        testsheet_no = testsheet_no + 1

        globals.delay_time = 1

        # globals.debug_file.write("\n------------[END] - TL Execution-------------   \n ")
        print("\n------------[END] - TL Execution-------------")
        TL_endtime = time.time()
        TL_executiontime = TL_endtime - TL_starttime
        globals.TL_sheet.Range("I2").Value = TL_executiontime
    #-----------------------------------------------------------------------------------------------
    #to close the experiment and switch off IGN and Power supply after execution

    # if globals.Sheet_No == 1:
    #     func_call()
    # else:
    #     for testsheet_no in range(1,globals.Sheet_No):
    #         func_call()
    #         testsheet_no = testsheet_no + 1

    #only for demo
    time.sleep(5)
    ## TL operation end_____
    print("tl_operation_close")
    step_libraries.CD_Close()

    # if globals.Result_file != None:
    #     globals.Result_file.Save()
    #     globals.Result_file.Close()
    #     globals.Result_file = None
    # if globals.Macro != None:
    #     #globals.Macro1.Save()
    #     #globals.Macro1.Close()
    #     globals.excel.Workbooks("XLS_2_DDT.xlsm").Close(1)
    #     globals.Macro = None

    # globals.ProjObj.RemoveAll()
    # wait(120)

    # globals.ProjObj.Close()
    # AudObj.Quit()
    # time.sleep(2)
    # globals.excel.Application.Quit()
    #
    # globals.canoe_inst.stop_measurement()
    # globals.canoe_inst.quit()
    # caneo_setup = 0
    # globals.debug_file.close
    print("Process Completed")


except Exception as log:
    print()
    # if globals.Result_file != None:
    #     globals.Result_file.Save()
    #     globals.Result_file.Close()
    #
    # if AudObj != None:
    #     AudObj.Quit()
    #     time.sleep(2)
    #
    # if caneo_setup == 1:
    #     globals.canoe_inst.stop_measurement()
    #     globals.canoe_inst.quit()
    #     caneo_setup = 0
    # if globals.excel != None:
    #     globals.excel.Application.Quit()
    #
    # if globals.debug_file != None:
    #     globals.debug_file.close()
    #
    # ctypes.windll.user32.MessageBoxW(0, str(log) + ". Stopping Execution..", "Message", 0)
    #
    # if caneo_setup == 1:
    #     globals.canoe_inst.stop_measurement()
    #     globals.canoe_inst.quit()
    #     caneo_setup = 0
finally:
    print()
    # #globals.excel
    # globals.Result_file = None
    # globals.excel = None
    # #AUD
    # Inputs = None
    # globals.Step_libraries = None
    # globals.InputchildObj = None
    # globals.FIU_InputschildObj = None
    # PlatformLibObj = None
    # Platformtemplobj = None
    # PlatformObj = None
    # MyProjObj = None
    # globals.ProjObj = None
    # ProjsObj = None
    # time.sleep(5)
    # AudObj = None
    # #Error handling
    # globals.error_SL = None
    
    
    
    
    
    
    
    
    
#Objects and variables which are required to be used across modules are initialized in this file

setup = 0
count=0
dir_path = None
parameters = None
Modelroot = None
cal_defaultvalues = {}
debug_file = None
Call_SL=None

#Handle for TL result document
Result_file = None
Result_path = None
Report_loc = None

#Handle for SL, to access values in row of SL
TL_sheet = None
SL = None
SL1 = None
SL_endrow = None
SL1_endrow=None
delay_time = 1
cnt=0
xl_endloc1=None
Sheet_No=None
#INCA handles for experiment
ExperimentView = None
Experiment = None
WrkDev = None

#Handles for AutomationDesk sequence folder and Inputs data container
ProjObj = None
Step_libraries = None
Inputs = None
InputchildObj = None # Objects inside Inputs data container
FIU_Inputs = None
FIU_InputschildObj = None


#Handle for 2nd Excelsheet
excel = None
#excel_open = None
Macro = None
Macro_path = None


# Time Logging
INCA_Start_time = None

#FIU Initial setting
FIU_setup = 1
FIU_used = False

#record condition
record_on = 0

#DefaultVariables
DefaultVars = []
DefaultCals = []

#DDT Client
hDDT = None
TargetECU_name = ""
TargetCAN_name = ""
TargetECU_DescFile = ""
TargetCAN_DescFile = ""
DDT_Status = False
step_libraries_1=None
#INCA_StoreValue Dictionary
INCA_StoreValue_Dict = {}

#Error handling
error_SL = None
SP = 0

#Stimuli
Stimuli_path = None

LED_Name = None
lis= None
data=None
randomList=[]
seq_Num=None
range1=None
range2=None
rowNum =None
clmNum=None
Result_loc=None

#handel XIL Api's

DemoMAPort = None
MyValueFactory = None



Voltage_path="()://Model Root/IOUserInterface/IO_PAR/Simulator/Power_Supply/Voltage_Out/Value"
CmdIgnSts='()://Model Root/IOUserInterface/IO_PAR/SoftECU/BCM/BCM_FD_10/CmdIgnSts/Value'

#CANOE 
canoe_inst=""

#Proxy
proxy_dict = {
"PROXI_Default":"30 30 30 30 30 30 35 36 33 39 30 50 43 38 33 38 30 32 32 42 46 20 12 11 23 4B 0C 20 04 10 00 20 00 02 00 00 00 00 00 00 40 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 30 E4 2E 21 80 00 09 35 13 33 41 07 80 10 01 00 00 00 00 01 00 C0 00 00 00 00 00 00 00 43 09 24 00 21 02 00 22 00 00 00 00 00 00 01 00 00 00 82 00 02 03 91 20 00 00 09 00 00 00 01 00 3A 00 00 20 00 00 0D 40 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
"PROXI1":"30 30 30 30 30 30 35 39 35 38 38 50 43 38 33 38 30 32 32 42 46 20 12 11 23 4B 0C 20 04 10 00 20 00 02 00 00 00 00 00 00 00 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 30 E4 2E 21 80 00 09 35 13 33 41 07 80 10 01 00 00 00 00 01 00 C0 00 00 00 00 00 00 00 43 09 24 00 21 02 00 22 00 00 00 00 00 00 01 00 00 00 82 00 02 03 91 20 00 00 09 00 00 00 01 00 3A 00 00 20 00 00 0D 40 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
"PROXI2":"30 30 30 30 30 30 33 33 34 32 35 50 43 38 33 38 30 32 32 42 46 20 12 11 23 4B 0C 20 04 10 00 20 00 02 00 00 00 00 00 00 40 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 30 E4 2E 21 80 00 09 35 13 33 41 07 80 10 00 00 00 00 00 01 00 C0 00 00 00 00 00 00 00 43 09 24 00 21 02 00 22 00 00 00 00 00 00 01 00 00 00 82 00 02 03 91 20 00 00 09 00 00 00 01 00 3A 00 00 20 00 00 0D 40 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
"PROXI3":"30 30 30 30 30 30 31 36 39 36 30 50 43 38 33 38 30 32 32 42 46 20 12 11 23 4B 0C 20 04 10 00 20 00 02 00 00 00 00 00 00 40 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 20 E4 2E 21 80 00 09 35 13 33 41 07 80 10 01 00 00 00 00 01 00 C0 00 00 00 00 00 00 00 43 09 24 00 21 02 00 22 00 00 00 00 00 00 01 00 00 00 82 00 02 03 91 20 00 00 09 00 00 00 01 00 3A 00 00 20 00 00 0D 40 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
"PROXI4":"30 30 30 30 30 30 32 32 32 30 31 50 43 38 33 38 30 32 32 42 46 20 12 11 23 4B 0C 20 04 10 00 20 00 02 00 00 00 00 00 00 40 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 30 E4 2E 21 80 00 09 35 13 33 41 07 80 10 01 00 00 00 00 01 00 C0 00 00 00 00 00 00 00 43 09 24 00 21 02 00 22 00 00 00 00 00 00 01 00 00 00 82 00 02 03 91 20 00 00 09 00 00 00 01 00 3A 00 00 20 00 00 0D 40 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
"PROXI5":"30 30 30 30 30 30 34 39 35 37 37 50 43 38 33 38 30 32 32 42 46 20 12 11 23 4B 0C 20 04 10 00 20 00 02 00 00 00 00 00 00 40 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 30 E4 2E 21 80 00 09 35 13 33 41 07 80 10 01 00 00 00 00 01 00 C0 00 00 00 00 00 00 00 43 09 24 00 21 02 00 22 00 00 00 00 00 00 01 00 00 00 82 00 02 03 91 20 00 00 09 00 00 00 01 00 3A 00 00 20 00 00 0D 40 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
"PROXI6":"30 30 30 30 30 30 31 39 32 38 36 50 43 38 33 38 30 32 32 42 46 20 12 11 23 4B 0C 20 04 10 00 20 00 02 00 00 00 00 00 00 40 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 30 E4 2E 21 80 00 09 35 13 33 41 07 80 10 01 00 00 00 00 01 00 C0 00 00 00 00 00 00 00 43 09 24 00 21 02 00 22 00 00 00 00 00 00 01 00 00 00 82 00 02 03 91 20 00 00 09 00 00 00 01 00 3A 00 00 20 00 00 0D 40 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 60 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
"PROXI7":"30 30 30 30 30 30 30 35 37 31 32 50 43 38 33 38 30 32 32 42 46 20 12 11 23 4B 0C 20 04 10 00 20 00 02 00 00 00 00 00 00 40 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 30 E4 2E 21 80 00 09 35 13 33 41 07 80 10 01 00 00 00 00 01 00 C0 00 00 00 00 00 00 00 43 09 24 00 21 02 00 22 00 00 00 00 00 00 01 00 00 00 82 00 02 03 91 20 00 00 09 00 00 00 01 00 3A 00 00 20 00 00 0D 40 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
"PROXI8":"30 30 30 30 30 30 31 36 35 30 37 50 43 38 33 38 30 32 32 42 46 20 12 11 23 4B 0C 20 04 10 00 20 00 02 00 00 00 00 00 00 40 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 30 E4 2E 21 80 00 09 35 13 33 41 07 80 10 01 00 00 00 00 01 00 C0 00 00 00 00 00 00 00 43 09 24 00 21 02 00 22 00 00 00 00 00 00 01 00 00 00 82 00 02 03 91 20 00 00 09 00 00 00 01 00 3A 00 00 20 00 00 0D 40 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
"PROXI9":"30 30 30 30 30 30 33 35 34 33 37 50 43 38 33 38 30 32 32 42 46 20 12 11 23 4B 0C 20 04 10 00 20 00 02 00 00 00 00 00 00 40 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 30 E4 2E 21 80 00 09 35 13 33 41 07 80 10 01 00 00 00 00 01 00 C0 00 00 00 00 00 00 00 43 09 24 00 21 02 00 22 00 00 00 00 00 00 01 00 00 00 82 00 02 03 91 20 00 00 09 00 00 00 01 00 3A 00 00 20 00 00 0D 40 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
"PROXI10":"30 30 30 30 30 30 36 30 34 36 31 50 43 38 33 38 30 32 32 42 46 20 12 11 23 4B 0C 20 04 10 00 20 00 02 00 00 00 00 00 00 40 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 30 E4 2E 21 80 00 09 35 13 33 41 07 80 10 01 00 00 00 00 01 00 C0 00 00 00 00 00 00 00 43 09 24 00 21 02 00 22 00 00 00 00 00 00 01 00 00 00 82 00 02 03 91 20 00 00 09 00 00 00 01 00 3A 00 00 20 00 00 0D 40 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
"PROXI11":"30 30 30 30 30 30 30 39 37 38 37 50 43 38 33 38 30 32 32 42 46 20 12 11 23 4B 0C 20 04 10 00 20 00 02 00 00 00 00 00 00 40 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 30 E4 2E 21 80 00 09 35 13 33 41 07 80 10 01 00 00 00 00 01 00 C0 00 00 00 00 00 00 00 43 09 24 00 21 02 00 22 00 00 00 00 00 00 01 00 00 00 82 00 02 03 91 20 00 00 09 00 00 00 01 00 3A 00 00 20 00 00 0D 40 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 05 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
"PROXI12":"30 30 30 30 30 30 32 38 36 38 38 50 43 38 33 38 30 32 32 42 46 20 12 11 23 4B 0C 20 04 10 00 20 00 02 00 00 00 00 00 00 40 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 30 E4 2E 21 80 00 09 35 13 33 41 07 80 10 01 00 00 00 00 01 00 C0 00 00 00 00 00 00 00 43 09 24 00 21 02 00 22 00 00 00 00 00 00 01 00 00 00 82 00 02 03 91 20 00 00 09 00 00 00 01 00 3A 00 00 20 00 00 0D 40 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 06 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
"PROXI13":"30 30 30 30 30 30 30 31 33 36 34 50 43 38 33 38 30 32 32 42 46 20 12 11 23 4B 0C 20 04 10 00 20 00 02 00 00 00 00 00 00 40 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 30 E4 2E 21 80 00 09 35 13 33 41 07 80 10 01 00 00 00 00 01 00 C0 00 00 00 00 00 00 00 43 09 24 00 21 02 00 22 00 00 00 00 00 00 01 00 00 00 82 00 02 03 91 20 00 00 09 00 00 00 01 00 3A 00 00 20 00 00 0D 40 00 00 00 0A 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 82 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"
}

data={
      "left"  :  "2",
      "right" :  "1",
      "both"  :  "3",
      "crank" :  "5",
      "run"   :  "4"
      }

ExtNtc_SLML = { 
    "Turn_indicator" : "AnIn_4_LH",
    "Position_light" : "AnIn_3_LH",
    "Low_beam"       : "AnIn_1_LH",
    "High_beam"      : "AnIn_2_LH",
    "DRL"            : "AnIn_3_LH",
    "Signature_light": "AnIn_4_LH"
        }

ExtNtc_SLMR = { 
    "Turn_indicator" : "AnIn_4_RH",
    "Position_light" : "AnIn_3_RH",
    "Low_beam"       : "AnIn_1_RH",
    "High_beam"      : "AnIn_2_RH",
    "DRL"            : "AnIn_3_RH",
    "Signature_light": "AnIn_4_RH"
        }

LED_path_SLMR = {
    "Turn_indicator" : "()://Model Root/IOUserInterface/IO_DISP/SLMR/LED/PWM/LED2_RH_Duty/In1",
    "Position_light" : "()://Model Root/IOUserInterface/IO_DISP/SLMR/LED/PWM/LED6_RH_Duty/In1",
    "Low_beam"       : " ()://Model Root/IOUserInterface/IO_DISP/SLMR/LED/PWM/LED1_RH_Duty/In1",
    "High_beam"      : "()://Model Root/IOUserInterface/IO_DISP/SLMR/LED/PWM/LED5_RH_Duty/In1",
    "DRL"            : "()://Model Root/IOUserInterface/IO_DISP/SLMR/LED/PWM/LED6_RH_Duty/In1",
    "Signature_light": "()://Model Root/IOUserInterface/IO_DISP/SLMR/LED/PWM/LED4_RH_Duty/In1"
    
    }
LED_path_SLML = {
    "Turn_indicator" : "()://Model Root/IOUserInterface/IO_DISP/SLML/LED/PWM/LED2_LH_Duty/In1",
    "Position_light" : "()://Model Root/IOUserInterface/IO_DISP/SLML/LED/PWM/LED6_LH_Duty/In1",
    "Low_beam"       : " ()://Model Root/IOUserInterface/IO_DISP/SLML/LED/PWM/LED1_LH_Duty/In1",
    "High_beam"      : "()://Model Root/IOUserInterface/IO_DISP/SLML/LED/PWM/LED5_LH_Duty/In1",
    "DRL"            : "()://Model Root/IOUserInterface/IO_DISP/SLML/LED/PWM/LED6_LH_Duty/In1",
    "Signature_light": "()://Model Root/IOUserInterface/IO_DISP/SLML/LED/PWM/LED4_LH_Duty/In1"
    
    }

LED = {
       "Turn_indicator" : "LED2",
       "Position_light" : "LED6",
       "Low_beam"       : "LED1",
       "High_beam"      : "LED5",
       "DRL"            : "LED6",
       "Signature_light": "LED4",
       "Side_marker" : "HSD1",
       "Front_fog" : "HSD2"
       
       }

Ntc = {
       "AIN1" : "Analog_Input_1",
       "AIN2" : "Analog_Input_2",
       "AIN3" : "Analog_Input_3",
       "AIN4" : "Analog_Input_4",
       "AIN5" : "Analog_Input_5",
       "AIN6" : "Analog_Input_6",
       "AIN7" : "Analog_Input_7",
       "AIN8" : "Analog_Input_8",
       "AIN9" : "Analog_Input_9_Sns1",
       "AIN10" :"Analog_Input_10_Sns2"    
        }

HSD = {
          
       }





# -*- coding: utf-8 -*-
"""
Created on Fri Feb  2 11:49:24 2024

@author: TN0G118148
"""
import time

import globals
import common_fcns
import model_path


#this function to check and get any error occured in AUD sequences
# def CD_SL_Status():
#     try:
#         print("Inside CD_SL")
#         Error_log = globals.InputchildObj.Item("Error")
#         print("Error_log")
#         print("SL", globals.SL.Offset(1, 2).Value, Error_log.Value)
#         if "Error" in Error_log.Value or "failed" in Error_log.Value:
#
#             globals.SL.Offset(1, 5).Value = "ERROR"
#             globals.SL.Offset(1, 6).Value = "   "
#             globals.SL.Offset(1, 8).Value = "Error in step library execution "
#             # globals.debug_file.write("ERROR\n" + Error_log.Value)
#
#         else:
#             globals.SL.Offset(1, 5).Value = "OK"
#             globals.SL.Offset(1, 6).Value = "PASSED"
#             # globals.debug_file.write("PASSED")
#
#         Error_log.Value = ""  #resetting the value
#         ResObj0 = " "
#
#     except Exception as log:
#         print("Inexception of cd_sl")
#         print(log)
#         # globals.debug_file.write("ERROR    " + str(log))


def Update_err(log):
    globals.SL.Offset(1, 5).Value = "ERROR"
    globals.SL.Offset(1, 8).Value = str(log)
    globals.debug_file.write("ERROR    " + str(log))


# def CD_OpenEnvironment():
#     try:
#         print("Loading Application", globals.Step_libraries)
#         Sequence = globals.Step_libraries.SubBlocks.Item("CD_OpenEnvironment")
#         #ResObj0 = Sequence.Execute(random. randint(0, 5000),"")
#         common_fcns.select_number()
#         ResObj0 = Sequence.Execute(globals.seq_Num, "")
#
#         time.sleep(2)
#
#         Sequence = globals.Step_libraries.SubBlocks.Item("CD_SL_Status")
#
#         common_fcns.select_number()
#         ResObj0 = Sequence.Execute(globals.seq_Num, "")
#
#         Error_log = globals.InputchildObj.Item("Error")
#
#         if "Error" in Error_log.Value:
#             Error_log.Value = ""
#             raise Exception("ERROR in Loading Application")
#             print("ERROR in Loading Application")
#         else:
#             print("Loading Application - Completed")
#     except:
#         raise Exception("ERROR in Loading Application")


# used for demo purpose only
# def CD_Close():
#     try:
#         Sequence = globals.Step_libraries.SubBlocks.Item("CD_Close")
#         common_fcns.select_number()
#         ResObj0 = Sequence.Execute(globals.seq_Num, "")
#
#     except:
#         print("ERROR")


# def CD_CANCheckFrame():
#     try:
#         ActiveObj = globals.InputchildObj.item("Active")
#         FrameName = globals.SL.Offset(1, 2).Value
#         ActiveObj.Value = FrameName + '_' + FrameName + '_Enable'
#         #ActiveObj.Value = globals.Modelroot[globals.SL.Offset(1,2).Value]
#
#         Sequence = globals.Step_libraries.SubBlocks.Item("CD_CANCheckFrame")  # SL from AUD
#         common_fcns.select_number()
#         ResObj0 = Sequence.Execute(globals.seq_Num, "")
#
#         CD_SL_Status()
#
#     except Exception as log:
#         Update_err(log)
#
#
# def CD_CANUncheckFrame():
#     try:
#         ActiveObj = globals.InputchildObj.item("Active")
#         FrameName = globals.SL.Offset(1, 2).Value
#         ActiveObj.Value = FrameName + '_' + FrameName + '_Enable'
#         #ActiveObj.Value = globals.Modelroot[globals.SL.Offset(1,2).Value]
#
#         Sequence = globals.Step_libraries.SubBlocks.Item("CD_CANUncheckFrame")  # SL from AUD
#         common_fcns.select_number()
#         ResObj0 = Sequence.Execute(globals.seq_Num, "")
#
#         #ResObj0 = Sequence.Execute(data,"")
#         CD_SL_Status()
#
#     except Exception as log:
#         Update_err(log)


#--------------------------------------CAN Read -----------------------------------------#
'''
    Version           : v0.1
    Function name     : can_read  
    Description       :
    Parameters used   :
    Created   by      :    Lakshmi Narayanan
    Created On        :
        
    Version          Date           Author         Change info   

'''


def can_read():
    try:
        #canpath= "//BusSystems/CAN/CAN/SLML_STATUS_FD/RX/LowBeamSts_L"
        print("can_read inside", "2", globals.SL.Offset(1, 2).Value, "3", globals.SL.Offset(1, 3).Value)
        sig_name = globals.SL.Offset(1, 3).Value
        msg_name = globals.SL.Offset(1, 2).Value

        path = r"()://BusSystems/CAN/CAN/" + msg_name + "/RX/" + sig_name
        output_value = 1
        # output_value = globals.DemoMAPort.Read(path)
        globals.SL.Offset(1, 7).Value = output_value  # NewReadVal
        common_fcns.result_calc()

        # Sequ = globals.Step_libraries.SubBlocks.Item("CD_Canread")
        #
        # keyObj = globals.InputchildObj.Item("can_path")
        # keyObj.Value = canpath
        #
        # common_fcns.select_number()
        # ResObj0 = Sequ.Execute(globals.seq_Num, "")
        #
        # # Update Log with AUD status

        # keyObj = globals.InputchildObj.Item("sig_value")
        # globals.SL.Offset(1, 7).Value = keyObj.Value
        #
        # CD_SL_Status()
        #
        # if globals.SL.Offset(1, 5).Value != "ERROR":
        #     common_fcns.result_calc()
    except Exception as log:
        Update_err(log)

    #--------------------------------End of CAN read function--------------------------------------#


#--------------------------------------CAN Write -----------------------------------------# 

'''
    Latest version    :
    Function name     : can_write
    Description       :
    Parameters used   :
    Created By        : Lakshmi Narayanan
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


def can_write():
    try:
        #canpath= "//Model Root/IOUserInterface/IO_PAR/SoftECU/BCM/BCM_FD_2/LowBeamCmd/Value"
        print("can_write inside", "2", globals.SL.Offset(1, 2).Value, "3", globals.SL.Offset(1, 3).Value)
        sig_name = globals.SL.Offset(1, 3).Value
        print("after sig")
        # msg_name = globals.SL.Offset(1, 2).Value
        # print("after msg")
        input_value = globals.SL.Offset(1, 4).Value
        print("after msg")
        output_value = 2

        canpath = r"()://Model Root/IOUserInterface/IO_PAR/SoftECU/BCM/BCM_FD_2/" + sig_name + "/Value"
        # globals.DemoMAPort.Write(path, globals.MyValueFactory.CreateFloatValue(input_value))
        # output_value = globals.DemoMAPort.Read(path)
        globals.SL.Offset(1, 7).Value = output_value  # NewReadVal

        common_fcns.result_calc()




        # canpath_sw = canpath + "_Switch"
        # Sequ = globals.Step_libraries.SubBlocks.Item("CD_CanWrite")

        # keyObj = globals.InputchildObj.Item("can_path")
        # keyObj.Value = canpath
        # keyObj = globals.InputchildObj.Item("Target_value")
        # keyObj.Value = target_value
        # keyObj = globals.InputchildObj.Item("can_sw")
        # keyObj.Value = canpath_sw
        # lis = range(0, 5000)

        # common_fcns.select_number()
        # ResObj0 = Sequ.Execute(globals.seq_Num, "")
        #
        # keyObj = globals.InputchildObj.Item("current_value")
        # globals.SL.Offset(1, 7).Value = keyObj.Value

        # CD_SL_Status()
        #
        # if globals.SL.Offset(1, 5).Value != "ERROR":
        #     common_fcns.result_calc()


    except Exception as log:
        Update_err(log)

    #--------------------------------End of CAN write function--------------------------------------#


#--------------------------------------KL30 OFF -----------------------------------------#   

'''
    Latest version    :
    Function name     : KL30_off
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


def KL30_off():
    try:
        print("Inside Kl30")
        path = model_path.kl30
        input_value = common_fcns.check_type()
        print("Value : ", input_value)
        output_value = 0.0
        # globals.DemoMAPort.Write(path, globals.MyValueFactory.CreateFloatValue(input_value))
        #output_value = globals.DemoMAPort.Read(path)
        globals.SL.Offset(1, 7).Value = output_value  #NewReadVal
        # if common_fcns.equalValue(var, NewReadVal):
        #     globals.SL.Offset(1, 7).Value = 0.0  # NewReadVal
        # else:
        common_fcns.result_calc()
    except Exception as log:
        Update_err(log)

    #--------------------------------End of KL30 OFF function--------------------------------------#


#--------------------------------------KL30 ON -----------------------------------------#    

'''
    Latest version    :
    Function name     : KL30_on
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


def KL30_on():
    try:
        path = model_path.kl30
        target_value = globals.SL.Offset(1, 4).Value
        input_value = common_fcns.check_type()
        print("Target Value : ", target_value)
        print(" actual_value : ", input_value)

        output_value = 2
        # globals.DemoMAPort.Write(path, globals.MyValueFactory.CreateFloatValue(input_value))
        # output_value = globals.DemoMAPort.Read(path)
        globals.SL.Offset(1, 7).Value = output_value  # NewReadVal
        common_fcns.result_calc()

        # keyObj = globals.InputchildObj.Item("KL30_Ip")
        # keyObj.Value = globals.data[target_value]
        # print("KeyObject .value : ", keyObj.Value)
        # common_fcns.select_number()
        # ResObj0 = Sequ.Execute(globals.seq_Num,"")
        # #Update Log with AUD status
        # keyObj = globals.InputchildObj.Item("current_value")
        # globals.SL.Offset(1, 7).Value = keyObj.Value
        # CD_SL_Status()
        # if globals.SL.Offset(1, 5).Value != "ERROR":
        #     common_fcns.result_calc()
    except Exception as log:
        Update_err(log)

    #--------------------------------End of KL30 ON function--------------------------------------#


#--------------------------------------Ignition state -----------------------------------------# 

'''
    Latest version    :
    Function name     : ign_write
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


# def ign_write():
#     try:
#         #canpath= "()://BusSystems/CAN/CAN/BCM_FD_2/TX/TurnEvent_Indication"
#         print("Crank_mode inside", "2", globals.SL.Offset(1, 2).Value, "3", globals.SL.Offset(1, 3).Value)
#
#         target_value = globals.SL.Offset(1, 4).Value
#
#         Sequ = globals.Step_libraries.SubBlocks.Item("ign_write")
#
#         keyObj = globals.InputchildObj.Item("can_path")
#         keyObj.Value = globals.CmdIgnSts
#
#         keyObj = globals.InputchildObj.Item("Target_value")
#         keyObj.Value = globals.data[target_value]
#
#         common_fcns.select_number()
#         ResObj0 = Sequ.Execute(globals.seq_Num, "")
#
#         #Update Log with AUD status
#
#         keyObj = globals.InputchildObj.Item("current_value")
#         globals.SL.Offset(1, 7).Value = keyObj.Value
#
#         CD_SL_Status()
#
#         if globals.SL.Offset(1, 5).Value != "ERROR":
#             common_fcns.result_calc()
#
#     except Exception as log:
#         Update_err(log)
    #--------------------------------Ignition state function end--------------------------------------#


#--------------------------------------Message enable---------------------------------------------#

'''
    Latest version    :
    Function name     : msg_enable
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


# def msg_enable():
#     try:
#         #canpath= "()://BusSystems/CAN/CAN/BCM_FD_2/TX/TurnEvent_Indication"
#         print("can_enable inside", "2", globals.SL.Offset(1, 2).Value, "3", globals.SL.Offset(1, 3).Value)
#         sig_name = globals.SL.Offset(1, 3).Value
#         print("after sig")
#         msg_name = globals.SL.Offset(1, 2).Value
#         print("after msg")
#         target_value = globals.SL.Offset(1, 4).Value
#         print("after msg")
#         canpath = r"()://Model Root/IOUserInterface/IO_PAR/SoftECU/BCM/MESSAGE_Enable/BCM_FD_2_en/Value"
#         #canpath_sw =canpath+"_Switch"
#         Sequ = globals.Step_libraries.SubBlocks.Item("msg_enable")
#
#         keyObj = globals.InputchildObj.Item("can_path")
#         keyObj.Value = canpath
#         keyObj = globals.InputchildObj.Item("Target_value")
#         keyObj.Value = target_value
#
#         common_fcns.select_number()
#         ResObj0 = Sequ.Execute(globals.seq_Num, "")
#
#         #Update Log with AUD status
#
#         keyObj = globals.InputchildObj.Item("current_value")
#         globals.SL.Offset(1, 7).Value = keyObj.Value
#
#         CD_SL_Status()
#
#         if globals.SL.Offset(1, 5).Value != "ERROR":
#             common_fcns.result_calc()
#
#     except Exception as log:
#         Update_err(log)


#--------------------------------------Message enable function end ---------------------------------------# 


#--------------------------------------Message Disable-----------------------------------------------------#       

'''
    Latest version    :
    Function name     : msg_disable
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


# def msg_disable():
#     try:
#         #canpath= "()://BusSystems/CAN/CAN/BCM_FD_2/TX/TurnEvent_Indication"
#         print("can_disable inside", "2", globals.SL.Offset(1, 2).Value, "3", globals.SL.Offset(1, 3).Value)
#         sig_name = globals.SL.Offset(1, 3).Value
#         print("after sig")
#         msg_name = globals.SL.Offset(1, 2).Value
#         print("after msg")
#         target_value = globals.SL.Offset(1, 4).Value
#         print("after msg")
#         canpath = r"()://Model Root/IOUserInterface/IO_PAR/SoftECU/BCM/MESSAGE_Enable/BCM_FD_2_en/Value"
#         #canpath_sw =canpath+"_Switch"
#         Sequ = globals.Step_libraries.SubBlocks.Item("msg_disable")
#
#         keyObj = globals.InputchildObj.Item("can_path")
#         keyObj.Value = canpath
#         keyObj = globals.InputchildObj.Item("Target_value")
#         keyObj.Value = target_value
#
#         common_fcns.select_number()
#         ResObj0 = Sequ.Execute(globals.seq_Num, "")
#
#         #Update Log with AUD status
#
#         keyObj = globals.InputchildObj.Item("current_value")
#         globals.SL.Offset(1, 7).Value = keyObj.Value
#
#         CD_SL_Status()
#
#         if globals.SL.Offset(1, 5).Value != "ERROR":
#             common_fcns.result_calc()
#
#     except Exception as log:
#         Update_err(log)


#--------------------------------------Message disable function end ---------------------------------------# 

#--------------------------------------Voltage write-------------------------------------------------------#    

'''
    Latest version    :
    Function name     : vol_write
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


def vol_write():
    try:
        #canpath= "()://BusSystems/CAN/CAN/BCM_FD_2/TX/TurnEvent_Indication"
        print("vol_write inside", "2", globals.SL.Offset(1, 2).Value, "3", globals.SL.Offset(1, 3).Value)
        ''' sig_name = globals.SL.Offset(1,3).Value
        print("after sig")
        msg_name = globals.SL.Offset(1,2).Value
        print("after msg")'''
        path = model_path.batteryVolt_Write
        input_value = globals.SL.Offset(1, 4).Value
        output_value = 12
        # globals.DemoMAPort.Write(path, globals.MyValueFactory.CreateFloatValue(input_value))
        # output_value = globals.DemoMAPort.Read(path)
        globals.SL.Offset(1, 7).Value = output_value  # NewReadVal

        common_fcns.result_calc()

        # common_fcns.select_number()
        # ResObj0 = Sequ.Execute(globals.seq_Num, "")
        # #Update Log with AUD status
        # keyObj = globals.InputchildObj.Item("current_value")
        # globals.SL.Offset(1, 7).Value = keyObj.Value
        # CD_SL_Status()
        # if globals.SL.Offset(1, 5).Value != "ERROR":
        #     common_fcns.result_calc()

    except Exception as log:
        Update_err(log)


#--------------------------------------Voltage write function end ---------------------------------------# 

#--------------------------------------Internal NTC write------------------------------------------------#

'''
    Latest version    :
    Function name     : InNtc_write
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


def InNtc_write():
    try:
        #canpath= "()://BusSystems/CAN/CAN/BCM_FD_2/TX/TurnEvent_Indication"
        print("vol_write inside", "2", globals.SL.Offset(1, 2).Value, "3", globals.SL.Offset(1, 3).Value)
        ''' sig_name = globals.SL.Offset(1,3).Value
        print("after sig")'''
        msg_name = globals.SL.Offset(1, 2).Value
        input_value = globals.SL.Offset(1, 4).Value
        if msg_name == "SLMR":
            canpath = r"()://Model Root/IOUserInterface/IO_PAR/" + msg_name + "/Analog_Input/ECU_NTC_RH/Value"
        elif msg_name == "SLML":
            canpath = r"()://Model Root/IOUserInterface/IO_PAR/" + msg_name + "/Analog_Input/ECU_NTC_LH/Value"
        output_value = 25
        # globals.DemoMAPort.Write(path, globals.MyValueFactory.CreateFloatValue(input_value))
        # output_value = globals.DemoMAPort.Read(path)
        globals.SL.Offset(1, 7).Value = output_value  # NewReadVal
        common_fcns.result_calc()

        #canpath_sw =canpath+"_Switch"
        # Sequ = globals.Step_libraries.SubBlocks.Item("InNtc_write")
        #
        # keyObj = globals.InputchildObj.Item("can_path")
        # keyObj.Value = canpath
        # keyObj = globals.InputchildObj.Item("Target_value")
        # keyObj.Value = target_value
        #
        # common_fcns.select_number()
        # ResObj0 = Sequ.Execute(globals.seq_Num, "")
        #
        # #Update Log with AUD status
        #
        # keyObj = globals.InputchildObj.Item("current_value")
        # globals.SL.Offset(1, 7).Value = keyObj.Value
        #
        # CD_SL_Status()
        #
        # if globals.SL.Offset(1, 5).Value != "ERROR":
        #     common_fcns.result_calc()

    except Exception as log:
        Update_err(log)

    #--------------------------------------Internal NTC write function end ---------------------------------------#


#--------------------------------------External NTC write -----------------------------------------------#

'''
    Latest version    :
    Function name     : ExtNtc_write
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


# def ExtNtc_write():
#     try:
#         #canpath= "()://BusSystems/CAN/CAN/BCM_FD_2/TX/TurnEvent_Indication"
#         print("vol_write inside", "2", globals.SL.Offset(1, 2).Value, "3", globals.SL.Offset(1, 3).Value)
#         ''' sig_name = globals.SL.Offset(1,3).Value
#         print("after sig") '''
#         msg_name = globals.SL.Offset(1, 2).Value
#         Feature_name = globals.SL.Offset(1, 3).Value
#         target_value = globals.SL.Offset(1, 4).Value
#
#         if (msg_name == "SLML"):
#             AnIn_value = globals.ExtNtc_SLML[Feature_name]
#
#         elif (msg_name == "SLMR"):
#             AnIn_value = globals.ExtNtc_SLMR[Feature_name]
#
#         #print("after msg")
#         canpath = r"()://Model Root/IOUserInterface/IO_PAR/" + msg_name + "/Analog_Input/" + AnIn_value + "/Value"
#         print(canpath)
#         #canpath_sw =canpath+"_Switch"
#         Sequ = globals.Step_libraries.SubBlocks.Item("ExtNtc_write")
#
#         keyObj = globals.InputchildObj.Item("can_path")
#         keyObj.Value = canpath
#         keyObj = globals.InputchildObj.Item("Target_value")
#         keyObj.Value = target_value
#
#         common_fcns.select_number()
#         ResObj0 = Sequ.Execute(globals.seq_Num, "")
#
#         #Update Log with AUD status
#
#         keyObj = globals.InputchildObj.Item("current_value")
#         globals.SL.Offset(1, 7).Value = keyObj.Value
#
#         CD_SL_Status()
#
#         if globals.SL.Offset(1, 5).Value != "ERROR":
#             common_fcns.result_calc()
#
#     except Exception as log:
#         Update_err(log)


#--------------------------------------External NTC write function end ---------------------------------------#

#--------------------------------------LED PWD Read-----------------------------------------------------------#    

'''
    Latest version    :
    Function name     : LED_read
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


def LED_read():
    try:
        #canpath= "()://BusSystems/CAN/CAN/BCM_FD_2/TX/TurnEvent_Indication"
        print("LED_PWM_TI inside", "2", globals.SL.Offset(1, 2).Value, "3", globals.SL.Offset(1, 3).Value)

        feature_name = globals.SL.Offset(1, 3).Value
        msg_name = globals.SL.Offset(1, 2).Value
        output_value = 100

        if (msg_name == "SLML"):
            LED_path = globals.LED_path_SLML[feature_name]


        elif (msg_name == "SLMR"):
            LED_path = globals.LED_path_SLMR[feature_name]
        # output_value = globals.DemoMAPort.Read(path)
        globals.SL.Offset(1, 7).Value = output_value  # NewReadVal
        common_fcns.result_calc()



    # Sequ = globals.Step_libraries.SubBlocks.Item("LED_read")
        #
        # keyObj = globals.InputchildObj.Item("can_path")
        # keyObj.Value = LED_path
        # print("Value of LED path: ", keyObj.Value)
        #
        # common_fcns.select_number()
        # ResObj0 = Sequ.Execute(globals.seq_Num, "")
        #
        # #Update Log with AUD status
        #
        # keyObj = globals.InputchildObj.Item("Float_value")
        # globals.SL.Offset(1, 7).Value = keyObj.Value
        #
        # CD_SL_Status()
        #
        # if globals.SL.Offset(1, 5).Value != "ERROR":
        #     common_fcns.result_calc()

    except Exception as log:
        Update_err(log)

    #--------------------------------------LED PWD Read function end ---------------------------------------#


#--------------------------------------Create fault-----------------------------------------------------# 

'''
    Latest version    :
    Function name     : set_FIU
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


# def set_FIU():
#     try:
#         #canpath= "()://BusSystems/CAN/CAN/BCM_FD_2/TX/TurnEvent_Indication"
#         print("LED_PWM_TI inside", "2", globals.SL.Offset(1, 3).Value, "3", globals.SL.Offset(1, 4).Value)
#         sig_name = globals.SL.Offset(1, 2).Value
#         fault_type = globals.SL.Offset(1, 3).Value
#
#         LED_Name = globals.LED[fault_type]
#         #var="\\"
#
#         FIU_path = sig_name + "\\LED\\" + LED_Name
#         #FIU_path= sig_name+ "\" + LED_Name[:3] + "\" +LED_Name
#
#         print("Value of FIU_path: ", FIU_path)
#         Sequ = globals.Step_libraries.SubBlocks.Item("FIU_activate")
#
#         keyObj = globals.InputchildObj.Item("SignalName")
#         keyObj.Value = FIU_path
#
#         keyObj = globals.InputchildObj.Item("Error_Category")
#         keyObj.Value = globals.SL.Offset(1, 4).Value
#
#         common_fcns.select_number()
#         ResObj0 = Sequ.Execute(globals.seq_Num, "")
#
#         CD_SL_Status()
#
#         if globals.SL.Offset(1, 5).Value != "ERROR":
#             common_fcns.result_calc()
#
#     except Exception as log:
#         Update_err(log)
#
#         #Update Log with AUD status
#         CD_SL_Status()


#--------------------------------------Create fault function end ---------------------------------------#

#--------------------------------------Create fault-----------------------------------------------------# 

'''
    Latest version    :
    Function name     : set_FIU
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


# def set_HSD_FIU():
#     try:
#         #canpath= "()://BusSystems/CAN/CAN/BCM_FD_2/TX/TurnEvent_Indication"
#         print("LED_PWM_TI inside", "2", globals.SL.Offset(1, 3).Value, "3", globals.SL.Offset(1, 4).Value)
#         sig_name = globals.SL.Offset(1, 2).Value
#         fault_type = globals.SL.Offset(1, 3).Value
#
#         LED_Name = globals.LED[fault_type]
#         var = "\\"
#
#         FIU_path = sig_name + "\\HSD\\" + LED_Name
#         #FIU_path= sig_name+ "\" + LED_Name[:3] + "\" +LED_Name
#
#         print("Value of FIU_path: ", FIU_path)
#         Sequ = globals.Step_libraries.SubBlocks.Item("FIU_activate")
#
#         keyObj = globals.InputchildObj.Item("SignalName")
#         keyObj.Value = FIU_path
#
#         keyObj = globals.InputchildObj.Item("Error_Category")
#         keyObj.Value = globals.SL.Offset(1, 4).Value
#
#         common_fcns.select_number()
#         ResObj0 = Sequ.Execute(globals.seq_Num, "")
#
#         CD_SL_Status()
#
#         if globals.SL.Offset(1, 5).Value != "ERROR":
#             common_fcns.result_calc()
#
#     except Exception as log:
#         Update_err(log)
#
#         #Update Log with AUD status
#         CD_SL_Status()


#--------------------------------------Create fault function end ---------------------------------------#


#--------------------------------------Create fault-----------------------------------------------------# 

'''
    Latest version    :
    Function name     : set_FIU
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


# def set_ntc_FIU():
#     try:
#         #canpath= "()://BusSystems/CAN/CAN/BCM_FD_2/TX/TurnEvent_Indication"
#         print("LED_PWM_TI inside", "2", globals.SL.Offset(1, 3).Value, "3", globals.SL.Offset(1, 4).Value)
#         ecu_name = globals.SL.Offset(1, 2).Value
#         fault_type = globals.SL.Offset(1, 3).Value
#
#         LED_Name = globals.Ntc[fault_type]
#
#         FIU_path = ecu_name + "\\Analog_Input\\" + LED_Name
#
#         print("Value of FIU_path: ", FIU_path)
#         Sequ = globals.Step_libraries.SubBlocks.Item("FIU_activate")
#
#         keyObj = globals.InputchildObj.Item("SignalName")
#         keyObj.Value = FIU_path
#
#         keyObj = globals.InputchildObj.Item("Error_Category")
#         keyObj.Value = globals.SL.Offset(1, 4).Value
#
#         common_fcns.select_number()
#         ResObj0 = Sequ.Execute(globals.seq_Num, "")
#
#         CD_SL_Status()
#
#         if globals.SL.Offset(1, 5).Value != "ERROR":
#             common_fcns.result_calc()
#
#     except Exception as log:
#         Update_err(log)
#
#         #Update Log with AUD status
#         CD_SL_Status()


#--------------------------------------Create fault function end ---------------------------------------#

#--------------------------------------Remove fault-----------------------------------------------------#

'''
    Latest version    :
    Function name     : clear_FIU
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


# def clear_FIU():
#     try:
#         #canpath= "()://BusSystems/CAN/CAN/BCM_FD_2/TX/TurnEvent_Indication"
#         print("LED_PWM_TI inside", "2", globals.SL.Offset(1, 3).Value, "3", globals.SL.Offset(1, 4).Value)
#
#         Sequ = globals.Step_libraries.SubBlocks.Item("FIU_deactivate")
#
#         common_fcns.select_number()
#         ResObj0 = Sequ.Execute(globals.seq_Num, "")
#
#         CD_SL_Status()
#
#         if globals.SL.Offset(1, 5).Value != "ERROR":
#             common_fcns.result_calc()
#
#     except Exception as log:
#         Update_err(log)
#
#         #Update Log with AUD status
#         CD_SL_Status()


#--------------------------------------Remove fault function end ---------------------------------------#

#--------------------------------------Waiting time---------------------------------------------#  

'''
    Latest version    :
    Function name     : wait
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


# def wait():
#     try:
#
#         value = globals.SL.Offset(1, 4).Value
#         print("after msg")
#         Sequ = globals.Step_libraries.SubBlocks.Item("Wait")
#
#         keyObj = globals.InputchildObj.Item("sig_value")
#         keyObj.Value = value
#
#         common_fcns.select_number()
#         ResObj0 = Sequ.Execute(globals.seq_Num, "")
#
#         #Update Log with AUD status
#         CD_SL_Status()
#
#         if globals.SL.Offset(1, 5).Value != "ERROR":
#             globals.SL.Offset(1, 6).Value = "PASSED"
#             globals.SL.Offset(1, 5).Value = "OK"
#
#         else:
#             globals.SL.Offset(1, 6).Value = " "
#             globals.SL.Offset(1, 5).Value = "Error"
#
#     except Exception as log:
#         Update_err(log)

    #--------------------------------------Wait time function end ---------------------------------------#


#--------------------------------------Modify variable using diagnsotic write-------------------------#

'''
    Latest version    :
    Function name     : set_proxy
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


def set_proxy():
    try:

        para1 = globals.SL.Offset(1, 2).Value
        para2 = globals.SL.Offset(1, 4).Value
        print("the ecu:", para1, "the did:", para2)
        proxy_ip = globals.proxy_dict[para2]
        print("proxy_ip:", proxy_ip)
        resp = globals.canoe_inst.send_diag_request(para1, "2E 20 23 " + proxy_ip)
        print("the received byte:", resp)
        if resp[:2] == "6E":
            print("positive response")
            globals.SL.Offset(1, 6).Value = "PASSED"
            globals.SL.Offset(1, 5).Value = "OK"
            globals.SL.Offset(1, 7).Value = resp

        elif resp[:2] == "7F":
            print("Negative resposne")
            globals.SL.Offset(1, 6).Value = "FAILED"
            globals.SL.Offset(1, 5).Value = "OK"
            globals.SL.Offset(1, 7).Value = resp

        else:
            globals.SL.Offset(1, 6).Value = "ERROR"
            globals.SL.Offset(1, 5).Value = "NG"
            globals.SL.Offset(1, 7).Value = "No response"

    except:
        globals.SL.Offset(1, 6).Value = "ERROR"
        globals.SL.Offset(1, 5).Value = "NG"


#--------------------------------------Set_Proxy function end-------------------------#

#--------------------------------------Load default values to proxy-------------------------#

'''
    Latest version    :
    Function name     : clear_proxy
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


def clear_proxy():
    try:

        para1 = globals.SL.Offset(1, 2).Value
        proxy_ip = globals.proxy_dict["PROXI_Default"]
        resp = globals.canoe_inst.send_diag_request(para1, "2E 20 23 " + proxy_ip)
        if resp[:2] == "6E":
            print("positive response")
            globals.SL.Offset(1, 6).Value = "PASSED"
            globals.SL.Offset(1, 5).Value = "OK"
            globals.SL.Offset(1, 7).Value = resp

        elif resp[:2] == "7F":
            print("Negative resposne")
            globals.SL.Offset(1, 6).Value = "FAILED"
            globals.SL.Offset(1, 5).Value = "OK"
            globals.SL.Offset(1, 7).Value = resp

        else:
            globals.SL.Offset(1, 6).Value = "ERROR"
            globals.SL.Offset(1, 5).Value = "NG"
            globals.SL.Offset(1, 7).Value = "No response"

    except:
        globals.SL.Offset(1, 6).Value = "ERROR"
        globals.SL.Offset(1, 5).Value = "NG"


#--------------------------------------Clear_Proxy function end-------------------------#

#--------------------------------------read proxy data using diagnsotic read-------------------------# 

'''
    Latest version    :
    Function name     : read_proxy
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


def read_proxy():
    try:

        para1 = globals.SL.Offset(1, 2).Value
        resp = globals.canoe_inst.send_diag_request(para1, "22 20 24")
        if resp[:2] == "62":
            print("positive response")
            globals.SL.Offset(1, 6).Value = "PASSED"
            globals.SL.Offset(1, 5).Value = "OK"
            globals.SL.Offset(1, 7).Value = resp

        elif resp[:2] == "7F":
            print("Negative resposne")
            globals.SL.Offset(1, 6).Value = "FAILED"
            globals.SL.Offset(1, 5).Value = "OK"
            globals.SL.Offset(1, 7).Value = resp

        else:
            globals.SL.Offset(1, 6).Value = "ERROR"
            globals.SL.Offset(1, 5).Value = "NG"
            globals.SL.Offset(1, 7).Value = "No response"

    except:
        globals.SL.Offset(1, 6).Value = "ERROR"
        globals.SL.Offset(1, 5).Value = "NG"


#--------------------------------------Read_Proxy function end-------------------------#  

#--------------------------------------Clear DTC from history using diagnsotic Service-14-------------------------#  

'''
    Latest version    :
    Function name     : clear_dtc
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


def clear_dtc():
    try:
        para1 = globals.SL.Offset(1, 2).Value
        resp = globals.canoe_inst.send_diag_request(para1, "14 FF FF FF")
        if resp[:2] == "54":
            print("positive response")
            globals.SL.Offset(1, 6).Value = "PASSED"
            globals.SL.Offset(1, 5).Value = "OK"
            globals.SL.Offset(1, 7).Value = resp

        elif resp[:2] == "7F":
            print("Negative resposne")
            globals.SL.Offset(1, 6).Value = "FAILED"
            globals.SL.Offset(1, 5).Value = "OK"
            globals.SL.Offset(1, 7).Value = resp

        else:
            globals.SL.Offset(1, 6).Value = "ERROR"
            globals.SL.Offset(1, 5).Value = "NG"
            globals.SL.Offset(1, 7).Value = "No response"

    except:
        globals.SL.Offset(1, 6).Value = "ERROR"
        globals.SL.Offset(1, 5).Value = "NG"


#--------------------------------------Clear dtc  function end-------------------------#

#--------------------------------------Check dtc status using diagnostic service-19-------------------------# 

'''
    Latest version    :
    Function name     : read_dtc
    Description       :
    Parameters used   :
    Created By        :
    Created On        :
    Initial version   :
    Modified Date       Modified By           Purpose
    

'''


def read_dtc():
    try:
        para1 = globals.SL.Offset(1, 2).Value
        dtc_no = globals.SL.Offset(1, 3).Value
        dtc_status = globals.SL.Offset(1, 4).Value
        resp = globals.canoe_inst.send_diag_request(para1, "19 02 0C")
        if resp[:2] == "59":
            dtc_no = resp.find(dtc_no)
            if dtc_status == "active":
                if dtc_no != -1:
                    print("positive response")
                    globals.SL.Offset(1, 6).Value = "PASSED"
                    globals.SL.Offset(1, 5).Value = "OK"
                    globals.SL.Offset(1, 7).Value = resp
                else:
                    print("positive response")
                    globals.SL.Offset(1, 6).Value = "FAILED"
                    globals.SL.Offset(1, 5).Value = "OK"
                    globals.SL.Offset(1, 7).Value = resp

            elif dtc_status == "inactive":
                if dtc_no == -1:
                    print("positive response")
                    globals.SL.Offset(1, 6).Value = "PASSED"
                    globals.SL.Offset(1, 5).Value = "OK"
                    globals.SL.Offset(1, 7).Value = resp
                else:
                    print("positive response")
                    globals.SL.Offset(1, 6).Value = "FAILED"
                    globals.SL.Offset(1, 5).Value = "OK"
                    globals.SL.Offset(1, 7).Value = resp
            else:
                print("ERROR")
                globals.SL.Offset(1, 6).Value = "ERROR"
                globals.SL.Offset(1, 5).Value = "NG"
                globals.SL.Offset(1, 7).Value = "Invalid parameter"

        elif resp[:2] == "7F":
            print("Negative resposne")
            globals.SL.Offset(1, 6).Value = "FAILED"
            globals.SL.Offset(1, 5).Value = "OK"
            globals.SL.Offset(1, 7).Value = resp

        else:
            print("ERROR")
            globals.SL.Offset(1, 6).Value = "ERROR"
            globals.SL.Offset(1, 5).Value = "NG"
            globals.SL.Offset(1, 7).Value = "Missing parameter"


    except:
        globals.SL.Offset(1, 6).Value = "ERROR"
        globals.SL.Offset(1, 5).Value = "NG"


#--------------------------------------Read dtc function end-------------------------#   

#--------------------------------------End of Step libraries--------------------------#

#---------------------------------------History-------------------------------------#
'''  
Initial file version :1.0
Created on :
Created by : Lakshmi Narayanan
Modified by : Ramya B V             
    modified Date           Modified By            Purpose
    06/06/2024              Ramya B V               Modified functions by replacing if loop with Dictionaary to access data
Final version : 1.1
    
'''

#------------------------------------------------------------------------------------#