text: from cereal import car
  from common.params import Params
  from opendbc.can.can_define import CANDefine
  from opendbc.can.parser import CANParser
  from selfdrive.car.hyundai.values import (CAR, DBC, EV_CAR, FEATURES,
                                            HYBRID_CAR, STEER_THRESHOLD)
  from selfdrive.car.interfaces import CarStateBase
  from selfdrive.config import Conversions as CV
  
  GearShifter = car.CarState.GearShifter
  
  
  class CarState(CarStateBase):
    def __init__(self, CP):
      super().__init__(CP)
  
      can_define = CANDefine(DBC[CP.carFingerprint]["pt"])
  
      if self.CP.carFingerprint in FEATURES["use_cluster_gears"]:
        self.shifter_values = can_define.dv["CLU15"]["CF_Clu_Gear"]
      elif self.CP.carFingerprint in FEATURES["use_tcu_gears"]:
        self.shifter_values = can_define.dv["TCU12"]["CUR_GR"]
      else:  # preferred and elect gear methods use same definition
        self.shifter_values = can_define.dv["LVR12"]["CF_Lvr_Gear"]
  
      #Auto detection for setup
      self.no_radar = CP.sccBus == -1
      self.mdps_bus = CP.mdpsBus
      self.sas_bus = CP.sasBus
      self.scc_bus = CP.sccBus
      self.has_scc13 = CP.hasScc13 or CP.carFingerprint in FEATURES["has_scc13"]
      self.has_scc14 = CP.hasScc14 or CP.carFingerprint in FEATURES["has_scc14"]
      self.leftBlinker = False
      self.rightBlinker = False
      self.lkas_button_on = True
      self.cruise_main_button = 0
      self.mdps_error_cnt = 0
      self.cruise_unavail_cnt = 0
  
      self.apply_steer = 0.
  
      # scc smoother
      self.acc_mode = False
      self.cruise_gap = 1
      self.brake_pressed = False
      self.gas_pressed = False
      self.standstill = False
      self.cruiseState_enabled = False
      self.cruiseState_speed = 0
  
      self.use_cluster_speed = Params().get_bool('UseClusterSpeed')
  
    def update(self, cp, cp2, cp_cam):
      cp_mdps = cp2 if self.mdps_bus else cp
      cp_sas = cp2 if self.sas_bus else cp
      cp_scc = cp2 if self.scc_bus == 1 else cp_cam if self.scc_bus == 2 else cp
  
      self.prev_cruise_buttons = self.cruise_buttons
      self.prev_cruise_main_button = self.cruise_main_button
      self.prev_left_blinker = self.leftBlinker
      self.prev_right_blinker = self.rightBlinker
      self.prev_lkas_button = self.lkas_button_on
  
      ret = car.CarState.new_message()
  
      ret.doorOpen = any([cp.vl["CGW1"]['CF_Gway_DrvDrSw'], cp.vl["CGW1"]['CF_Gway_AstDrSw'],
                          cp.vl["CGW2"]['CF_Gway_RLDrSw'], cp.vl["CGW2"]['CF_Gway_RRDrSw']])
  
      ret.seatbeltUnlatched = cp.vl["CGW1"]['CF_Gway_DrvSeatBeltSw'] == 0
  
      self.is_set_speed_in_mph = bool(cp.vl["CLU11"]["CF_Clu_SPEED_UNIT"])
      self.speed_conv_to_ms = CV.MPH_TO_MS if self.is_set_speed_in_mph else CV.KPH_TO_MS
  
      if self.use_cluster_speed:
  
        ret.vEgoRaw = cp.vl["CLU11"]["CF_Clu_Vanz"]
        decimal = cp.vl["CLU11"]["CF_Clu_VanzDecimal"]
        if 0. < decimal < 0.5:
          ret.vEgoRaw += decimal
  
        ret.vEgoRaw *= self.speed_conv_to_ms
  
      else:
        ret.wheelSpeeds.fl = cp.vl["WHL_SPD11"]['WHL_SPD_FL'] * CV.KPH_TO_MS
        ret.wheelSpeeds.fr = cp.vl["WHL_SPD11"]['WHL_SPD_FR'] * CV.KPH_TO_MS
        ret.wheelSpeeds.rl = cp.vl["WHL_SPD11"]['WHL_SPD_RL'] * CV.KPH_TO_MS
        ret.wheelSpeeds.rr = cp.vl["WHL_SPD11"]['WHL_SPD_RR'] * CV.KPH_TO_MS
        ret.vEgoRaw = (ret.wheelSpeeds.fl + ret.wheelSpeeds.fr + ret.wheelSpeeds.rl + ret.wheelSpeeds.rr) / 4.
  
      ret.vEgo, ret.aEgo = self.update_speed_kf(ret.vEgoRaw)
  
      ret.standstill = ret.vEgoRaw < 0.1
  
      ret.steeringAngleDeg = cp_sas.vl["SAS11"]['SAS_Angle']
      ret.steeringRateDeg = cp_sas.vl["SAS11"]['SAS_Speed']
      ret.yawRate = cp.vl["ESP12"]['YAW_RATE']
      ret.leftBlinker, ret.rightBlinker = self.update_blinker_from_lamp(50, cp.vl["CGW1"]['CF_Gway_TurnSigLh'],
                                                              cp.vl["CGW1"]['CF_Gway_TurnSigRh'])
      ret.steeringTorque = cp_mdps.vl["MDPS12"]['CR_Mdps_StrColTq']
      ret.steeringTorqueEps = cp_mdps.vl["MDPS12"]['CR_Mdps_OutTq']
      ret.steeringPressed = abs(ret.steeringTorque) > STEER_THRESHOLD
  
      if cp_mdps.vl["MDPS12"]['CF_Mdps_ToiUnavail'] != 0:
        self.mdps_error_cnt += 1
      else:
        self.mdps_error_cnt = 0
  
      ret.steerWarning = self.mdps_error_cnt > 100
  
      if self.CP.enableAutoHold:
        ret.autoHold = cp.vl["ESP11"]['AVH_STAT']
  
      # cruise state
      ret.cruiseState.enabled = (cp_scc.vl["SCC12"]['ACCMode'] != 0) if not self.no_radar else \
                                        cp.vl["LVR12"]['CF_Lvr_CruiseSet'] != 0
      ret.cruiseState.available = (cp_scc.vl["SCC11"]["MainMode_ACC"] != 0) if not self.no_radar else \
                                        cp.vl['EMS16']['CRUISE_LAMP_M'] != 0
      ret.cruiseState.standstill = cp_scc.vl["SCC11"]['SCCInfoDisplay'] == 4. if not self.no_radar else False
  
      if ret.cruiseState.enabled:
        ret.cruiseState.speed = cp_scc.vl["SCC11"]['VSetDis'] * self.speed_conv_to_ms if not self.no_radar else \
                                           cp.vl["LVR12"]["CF_Lvr_CruiseSet"] * self.speed_conv_to_ms
      else:
        ret.cruiseState.speed = 0
      self.cruise_main_button = cp.vl["CLU11"]["CF_Clu_CruiseSwMain"]
      self.cruise_buttons = cp.vl["CLU11"]["CF_Clu_CruiseSwState"]
  
      # TODO: Find brake pressure
      ret.brake = 0
      ret.brakePressed = cp.vl["TCS13"]['DriverBraking'] != 0
  
      # TODO: Check this
      ret.brakeLights = bool(cp.vl["TCS13"]['BrakeLight'] or ret.brakePressed)
  
      ret.gasPressed = cp.vl["TCS13"]["DriverOverride"] == 1
  
      if self.CP.carFingerprint in (HYBRID_CAR | EV_CAR):
        if self.CP.carFingerprint in HYBRID_CAR:
          ret.gas = cp.vl["E_EMS11"]["CR_Vcu_AccPedDep_Pos"] / 254.
        else:
          ret.gas = cp.vl["E_EMS11"]["Accel_Pedal_Pos"] / 254.
  
      if self.CP.hasEms:
        ret.gas = cp.vl["EMS12"]['PV_AV_CAN'] / 100.
        ret.gasPressed = bool(cp.vl["EMS16"]["CF_Ems_AclAct"])
  
      #TPMS
      if cp.vl["TPMS11"]["UNIT"] == 0.0:
        ret.tpmsFl = cp.vl["TPMS11"]["PRESSURE_FL"]
        ret.tpmsFr = cp.vl["TPMS11"]["PRESSURE_FR"]
        ret.tpmsRl = cp.vl["TPMS11"]["PRESSURE_RL"]
        ret.tpmsRr = cp.vl["TPMS11"]["PRESSURE_RR"]
      elif cp.vl["TPMS11"]["UNIT"] == 1.0:
        ret.tpmsFl = cp.vl["TPMS11"]["PRESSURE_FL"] * 5 * 0.145038
        ret.tpmsFr = cp.vl["TPMS11"]["PRESSURE_FR"] * 5 * 0.145038
        ret.tpmsRl = cp.vl["TPMS11"]["PRESSURE_RL"] * 5 * 0.145038
        ret.tpmsRr = cp.vl["TPMS11"]["PRESSURE_RR"] * 5 * 0.145038
      elif cp.vl["TPMS11"]["UNIT"] == 2.0:
        ret.tpmsFl = cp.vl["TPMS11"]["PRESSURE_FL"] / 10 * 14.5038
        ret.tpmsFr = cp.vl["TPMS11"]["PRESSURE_FR"] / 10 * 14.5038
        ret.tpmsRl = cp.vl["TPMS11"]["PRESSURE_RL"] / 10 * 14.5038
        ret.tpmsRr = cp.vl["TPMS11"]["PRESSURE_RR"] / 10 * 14.5038
  
  
      # TODO: refactor gear parsing in function
      # Gear Selection via Cluster - For those Kia/Hyundai which are not fully discovered, we can use the Cluster Indicator for Gear Selection,
      # as this seems to be standard over all cars, but is not the preferred method.
      if self.CP.carFingerprint in FEATURES["use_cluster_gears"]:
        gear = cp.vl["CLU15"]["CF_Clu_Gear"]
      elif self.CP.carFingerprint in FEATURES["use_tcu_gears"]:
        gear = cp.vl["TCU12"]["CUR_GR"]
      elif self.CP.carFingerprint in FEATURES["use_elect_gears"]:
        gear = cp.vl["ELECT_GEAR"]["Elect_Gear_Shifter"]
      else:
        gear = cp.vl["LVR12"]["CF_Lvr_Gear"]
  
      ret.gearShifter = self.parse_gear_shifter(self.shifter_values.get(gear))
  
      if self.CP.carFingerprint in FEATURES["use_fca"]:
        ret.stockAeb = cp.vl["FCA11"]["FCA_CmdAct"] != 0
        ret.stockFcw = cp.vl["FCA11"]["CF_VSM_Warn"] == 2
      else:
        ret.stockAeb = cp.vl["SCC12"]["AEB_CmdAct"] != 0
        ret.stockFcw = cp.vl["SCC12"]["CF_VSM_Warn"] == 2
  
      # Blind Spot Detection and Lane Change Assist signals
      if self.CP.enableBsm:
        ret.leftBlindspot = cp.vl["LCA11"]["CF_Lca_IndLeft"] != 0
        ret.rightBlindspot = cp.vl["LCA11"]["CF_Lca_IndRight"] != 0
      else:
        ret.leftBlindspot = False
        ret.rightBlindspot = False
  
      # save the entire LKAS11, CLU11, SCC12 and MDPS12
      self.lkas11 = cp_cam.vl["LKAS11"]
      self.clu11 = cp.vl["CLU11"]
      self.scc11 = cp_scc.vl["SCC11"]
      self.scc12 = cp_scc.vl["SCC12"]
      self.mdps12 = cp_mdps.vl["MDPS12"]
      self.park_brake = cp.vl["CGW1"]['CF_Gway_ParkBrakeSw']
      self.steer_state = cp_mdps.vl["MDPS12"]['CF_Mdps_ToiActive'] #0 NOT ACTIVE, 1 ACTIVE
      self.cruise_unavail_cnt += 1 if cp.vl["TCS13"]['CF_VSM_Avail'] != 1 and cp.vl["TCS13"]['ACCEnable'] != 0 else -self.cruise_unavail_cnt
      self.cruise_unavail = self.cruise_unavail_cnt > 100
  
      self.lead_distance = cp_scc.vl["SCC11"]['ACC_ObjDist'] if not self.no_radar else 0
      if self.has_scc13:
        self.scc13 = cp_scc.vl["SCC13"]
      if self.has_scc14:
        self.scc14 = cp_scc.vl["SCC14"]
  
      self.lkas_error = cp_cam.vl["LKAS11"]["CF_Lkas_LdwsSysState"] == 7
      if not self.lkas_error and self.car_fingerprint not in [CAR.SONATA,CAR.PALISADE,
                      CAR.SONATA_HEV, CAR.SANTA_FE, CAR.KONA_EV, CAR.NIRO_EV, CAR.KONA]:
        self.lkas_button_on = bool(cp_cam.vl["LKAS11"]["CF_Lkas_LdwsSysState"])
  
  
      # scc smoother
      driver_override = cp.vl["TCS13"]["DriverOverride"]
      self.acc_mode = cp_scc.vl["SCC12"]['ACCMode'] != 0
      self.cruise_gap = cp_scc.vl["SCC11"]['TauGapSet'] if not self.no_radar else 1
      self.gas_pressed = ret.gasPressed or driver_override == 1
      self.brake_pressed = ret.brakePressed or driver_override == 2
      self.standstill = ret.standstill or ret.cruiseState.standstill
      self.cruiseState_enabled = ret.cruiseState.enabled
      self.cruiseState_speed = ret.cruiseState.speed
      ret.cruiseGap = self.cruise_gap
  
      return ret
  
    @staticmethod
    def get_can_parser(CP):
  
      signals = [
        # sig_name, sig_address, default
        ("WHL_SPD_FL", "WHL_SPD11", 0),
        ("WHL_SPD_FR", "WHL_SPD11", 0),
        ("WHL_SPD_RL", "WHL_SPD11", 0),
        ("WHL_SPD_RR", "WHL_SPD11", 0),
  
        ("YAW_RATE", "ESP12", 0),
  
        ("CF_Gway_DrvSeatBeltInd", "CGW4", 1),
  
        ("CF_Gway_DrvSeatBeltSw", "CGW1", 0),
        ("CF_Gway_DrvDrSw", "CGW1", 0),       # Driver Door
        ("CF_Gway_AstDrSw", "CGW1", 0),       # Passenger door
        ("CF_Gway_RLDrSw", "CGW2", 0),        # Rear reft door
        ("CF_Gway_RRDrSw", "CGW2", 0),        # Rear right door
        ("CF_Gway_TurnSigLh", "CGW1", 0),
        ("CF_Gway_TurnSigRh", "CGW1", 0),
        ("CF_Gway_ParkBrakeSw", "CGW1", 0),   # Parking Brake
  
        ("CYL_PRES", "ESP12", 0),
  
        ("CF_Clu_CruiseSwState", "CLU11", 0),
        ("CF_Clu_CruiseSwMain", "CLU11", 0),
        ("CF_Clu_SldMainSW", "CLU11", 0),
        ("CF_Clu_ParityBit1", "CLU11", 0),
        ("CF_Clu_VanzDecimal" , "CLU11", 0),
        ("CF_Clu_Vanz", "CLU11", 0),
        ("CF_Clu_SPEED_UNIT", "CLU11", 0),
        ("CF_Clu_DetentOut", "CLU11", 0),
        ("CF_Clu_RheostatLevel", "CLU11", 0),
        ("CF_Clu_CluInfo", "CLU11", 0),
        ("CF_Clu_AmpInfo", "CLU11", 0),
        ("CF_Clu_AliveCnt1", "CLU11", 0),
  
        ("ACCEnable", "TCS13", 0),
        ("BrakeLight", "TCS13", 0),
        ("DriverBraking", "TCS13", 0),
        ("DriverOverride", "TCS13", 0), # scc smoother
        ("CF_VSM_Avail", "TCS13", 0),
  
        ("ESC_Off_Step", "TCS15", 0),
  
        #("CF_Lvr_GearInf", "LVR11", 0),        # Transmission Gear (0 = N or P, 1-8 = Fwd, 14 = Rev)
  
        ("MainMode_ACC", "SCC11", 1),
        ("SCCInfoDisplay", "SCC11", 0),
        ("AliveCounterACC", "SCC11", 0),
        ("VSetDis", "SCC11", 30),
        ("ObjValid", "SCC11", 0),
        ("DriverAlertDisplay", "SCC11", 0),
        ("TauGapSet", "SCC11", 4),
        ("ACC_ObjStatus", "SCC11", 0),
        ("ACC_ObjLatPos", "SCC11", 0),
        ("ACC_ObjDist", "SCC11", 150), #TK211X value is 204.6
        ("ACC_ObjRelSpd", "SCC11", 0),
        ("Navi_SCC_Curve_Status", "SCC11", 0),
        ("Navi_SCC_Curve_Act", "SCC11", 0),
        ("Navi_SCC_Camera_Act", "SCC11", 0),
        ("Navi_SCC_Camera_Status", "SCC11", 2),
  
        ("ACCMode", "SCC12", 0),
        ("CF_VSM_Prefill", "SCC12", 0),
        ("CF_VSM_DecCmdAct", "SCC12", 0),
        ("CF_VSM_HBACmd", "SCC12", 0),
        ("CF_VSM_Warn", "SCC12", 0),
        ("CF_VSM_Stat", "SCC12", 0),
        ("CF_VSM_BeltCmd", "SCC12", 0),
        ("ACCFailInfo", "SCC12", 0),
        ("StopReq", "SCC12", 0),
        ("CR_VSM_DecCmd", "SCC12", 0),
        ("aReqRaw", "SCC12", 0), #aReqMax
        ("TakeOverReq", "SCC12", 0),
        ("PreFill", "SCC12", 0),
        ("aReqValue", "SCC12", 0), #aReqMin
        ("CF_VSM_ConfMode", "SCC12", 1),
        ("AEB_Failinfo", "SCC12", 0),
        ("AEB_Status", "SCC12", 2),
        ("AEB_CmdAct", "SCC12", 0),
        ("AEB_StopReq", "SCC12", 0),
        ("CR_VSM_Alive", "SCC12", 0),
        ("CR_VSM_ChkSum", "SCC12", 0),
  
        ("SCCDrvModeRValue", "SCC13", 2),
        ("SCC_Equip", "SCC13", 1),
        ("AebDrvSetStatus", "SCC13", 0),
  
        ("JerkUpperLimit", "SCC14", 0),
        ("JerkLowerLimit", "SCC14", 0),
        ("SCCMode2", "SCC14", 0),
        ("ComfortBandUpper", "SCC14", 0),
        ("ComfortBandLower", "SCC14", 0),
  
        ("UNIT", "TPMS11", 0),
        ("PRESSURE_FL", "TPMS11", 0),
        ("PRESSURE_FR", "TPMS11", 0),
        ("PRESSURE_RL", "TPMS11", 0),
        ("PRESSURE_RR", "TPMS11", 0),
      ]
  
      checks = [
        # address, frequency
        ("TCS13", 50),
        ("TCS15", 10),
        ("CLU11", 50),
        ("ESP12", 100),
        ("CGW1", 10),
        ("CGW2", 5),
        ("CGW4", 5),
        ("WHL_SPD11", 50),
      ]
  
      if CP.sccBus == 0 and CP.pcmCruise:
        checks += [
          ("SCC11", 50),
          ("SCC12", 50),
        ]
      if CP.mdpsBus == 0:
        signals += [
          ("CR_Mdps_StrColTq", "MDPS12", 0),
          ("CF_Mdps_Def", "MDPS12", 0),
          ("CF_Mdps_ToiActive", "MDPS12", 0),
          ("CF_Mdps_ToiUnavail", "MDPS12", 0),
          ("CF_Mdps_ToiFlt", "MDPS12", 0),
          ("CF_Mdps_MsgCount2", "MDPS12", 0),
          ("CF_Mdps_Chksum2", "MDPS12", 0),
          ("CF_Mdps_SErr", "MDPS12", 0),
          ("CR_Mdps_StrTq", "MDPS12", 0),
          ("CF_Mdps_FailStat", "MDPS12", 0),
          ("CR_Mdps_OutTq", "MDPS12", 0)
        ]
        checks += [
          ("MDPS12", 50)
        ]
      if CP.sasBus == 0:
        signals += [
          ("SAS_Angle", "SAS11", 0),
          ("SAS_Speed", "SAS11", 0),
        ]
        checks += [
          ("SAS11", 100)
        ]
      if CP.sccBus == -1:
        signals += [
          ("CRUISE_LAMP_M", "EMS16", 0),
          ("CF_Lvr_CruiseSet", "LVR12", 0),
      ]
      if CP.carFingerprint in FEATURES["use_cluster_gears"]:
        signals += [
          ("CF_Clu_Gear", "CLU15", 0),
        ]
      elif CP.carFingerprint in FEATURES["use_tcu_gears"]:
        signals += [
          ("CUR_GR", "TCU12",0),
        ]
      elif CP.carFingerprint in FEATURES["use_elect_gears"]:
        signals += [
          ("Elect_Gear_Shifter", "ELECT_GEAR", 0),
      ]
      else:
        signals += [
          ("CF_Lvr_Gear","LVR12",0),
        ]
  
      if CP.carFingerprint in (HYBRID_CAR | EV_CAR):
        if CP.carFingerprint in HYBRID_CAR:
          signals += [
            ("CR_Vcu_AccPedDep_Pos", "E_EMS11", 0)
          ]
        else:
          signals += [
            ("Accel_Pedal_Pos", "E_EMS11", 0),
          ]
        checks += [
          ("E_EMS11", 50),
        ]
  
      else:
        signals += [
          ("PV_AV_CAN", "EMS12", 0),
          ("CF_Ems_AclAct", "EMS16", 0),
        ]
        checks += [
          ("EMS12", 100),
          ("EMS16", 100),
        ]
  
      if CP.carFingerprint in FEATURES["use_fca"]:
        signals += [
          ("FCA_CmdAct", "FCA11", 0),
          ("CF_VSM_Warn", "FCA11", 0),
        ]
  
        if not CP.openpilotLongitudinalControl:
          checks += [("FCA11", 50)]
  
      if CP.carFingerprint in [CAR.SANTA_FE]:
        checks.remove(("TCS13", 50))
  
      if CP.enableBsm:
        signals += [
          ("CF_Lca_IndLeft", "LCA11", 0),
          ("CF_Lca_IndRight", "LCA11", 0),
        ]
        checks += [("LCA11", 50)]
  
      if CP.enableAutoHold:
        signals += [
          ("AVH_STAT", "ESP11", 0),
          ("LDM_STAT", "ESP11", 0),
        ]
        checks += [("ESP11", 50)]
  
      return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, 0, enforce_checks=False)
  
    @staticmethod
    def get_can2_parser(CP):
      signals = []
      checks = []
      if CP.mdpsBus == 1:
        signals += [
          ("CR_Mdps_StrColTq", "MDPS12", 0),
          ("CF_Mdps_Def", "MDPS12", 0),
          ("CF_Mdps_ToiActive", "MDPS12", 0),
          ("CF_Mdps_ToiUnavail", "MDPS12", 0),
          ("CF_Mdps_ToiFlt", "MDPS12", 0),
          ("CF_Mdps_MsgCount2", "MDPS12", 0),
          ("CF_Mdps_Chksum2", "MDPS12", 0),
          ("CF_Mdps_SErr", "MDPS12", 0),
          ("CR_Mdps_StrTq", "MDPS12", 0),
          ("CF_Mdps_FailStat", "MDPS12", 0),
          ("CR_Mdps_OutTq", "MDPS12", 0)
        ]
        checks += [
          ("MDPS12", 50)
        ]
  
      if CP.sasBus == 1:
        signals += [
          ("SAS_Angle", "SAS11", 0),
          ("SAS_Speed", "SAS11", 0),
        ]
        checks += [
          ("SAS11", 100)
        ]
      if CP.sccBus == 1:
        signals += [
          ("MainMode_ACC", "SCC11", 1),
          ("SCCInfoDisplay", "SCC11", 0),
          ("AliveCounterACC", "SCC11", 0),
          ("VSetDis", "SCC11", 30),
          ("ObjValid", "SCC11", 0),
          ("DriverAlertDisplay", "SCC11", 0),
          ("TauGapSet", "SCC11", 4),
          ("ACC_ObjStatus", "SCC11", 0),
          ("ACC_ObjLatPos", "SCC11", 0),
          ("ACC_ObjDist", "SCC11", 150.),
          ("ACC_ObjRelSpd", "SCC11", 0),
          ("Navi_SCC_Curve_Status", "SCC11", 0),
          ("Navi_SCC_Curve_Act", "SCC11", 0),
          ("Navi_SCC_Camera_Act", "SCC11", 0),
          ("Navi_SCC_Camera_Status", "SCC11", 2),
  
  
          ("ACCMode", "SCC12", 0),
          ("CF_VSM_Prefill", "SCC12", 0),
          ("CF_VSM_DecCmdAct", "SCC12", 0),
          ("CF_VSM_HBACmd", "SCC12", 0),
          ("CF_VSM_Warn", "SCC12", 0),
          ("CF_VSM_Stat", "SCC12", 0),
          ("CF_VSM_BeltCmd", "SCC12", 0),
          ("ACCFailInfo", "SCC12", 0),
          ("StopReq", "SCC12", 0),
          ("CR_VSM_DecCmd", "SCC12", 0),
          ("aReqRaw", "SCC12", 0), #aReqMax
          ("TakeOverReq", "SCC12", 0),
          ("PreFill", "SCC12", 0),
          ("aReqValue", "SCC12", 0), #aReqMin
          ("CF_VSM_ConfMode", "SCC12", 1),
          ("AEB_Failinfo", "SCC12", 0),
          ("AEB_Status", "SCC12", 2),
          ("AEB_CmdAct", "SCC12", 0),
          ("AEB_StopReq", "SCC12", 0),
          ("CR_VSM_Alive", "SCC12", 0),
          ("CR_VSM_ChkSum", "SCC12", 0),
  
          ("SCCDrvModeRValue", "SCC13", 2),
          ("SCC_Equip", "SCC13", 1),
          ("AebDrvSetStatus", "SCC13", 0),
  
          ("JerkUpperLimit", "SCC14", 0),
          ("JerkLowerLimit", "SCC14", 0),
          ("SCCMode2", "SCC14", 0),
          ("ComfortBandUpper", "SCC14", 0),
          ("ComfortBandLower", "SCC14", 0),
  
        ]
        checks += [
          ("SCC11", 50),
          ("SCC12", 50),
        ]
      return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, 1, enforce_checks=False)
  
    @staticmethod
    def get_cam_can_parser(CP):
  
      signals = [
        # sig_name, sig_address, default
        ("CF_Lkas_LdwsActivemode", "LKAS11", 0),
        ("CF_Lkas_LdwsSysState", "LKAS11", 0),
        ("CF_Lkas_SysWarning", "LKAS11", 0),
        ("CF_Lkas_LdwsLHWarning", "LKAS11", 0),
        ("CF_Lkas_LdwsRHWarning", "LKAS11", 0),
        ("CF_Lkas_HbaLamp", "LKAS11", 0),
        ("CF_Lkas_FcwBasReq", "LKAS11", 0),
        ("CF_Lkas_ToiFlt", "LKAS11", 0),
        ("CF_Lkas_HbaSysState", "LKAS11", 0),
        ("CF_Lkas_FcwOpt", "LKAS11", 0),
        ("CF_Lkas_HbaOpt", "LKAS11", 0),
        ("CF_Lkas_FcwSysState", "LKAS11", 0),
        ("CF_Lkas_FcwCollisionWarning", "LKAS11", 0),
        ("CF_Lkas_MsgCount", "LKAS11", 0),
        ("CF_Lkas_FusionState", "LKAS11", 0),
        ("CF_Lkas_FcwOpt_USM", "LKAS11", 0),
        ("CF_Lkas_LdwsOpt_USM", "LKAS11", 0)
      ]
  
      checks = [
        ("LKAS11", 100)
      ]
      if CP.sccBus == 2:
        signals += [
          ("MainMode_ACC", "SCC11", 1),
          ("SCCInfoDisplay", "SCC11", 0),
          ("AliveCounterACC", "SCC11", 0),
          ("VSetDis", "SCC11", 30),
          ("ObjValid", "SCC11", 0),
          ("DriverAlertDisplay", "SCC11", 0),
          ("TauGapSet", "SCC11", 4),
          ("ACC_ObjStatus", "SCC11", 0),
          ("ACC_ObjLatPos", "SCC11", 0),
          ("ACC_ObjDist", "SCC11", 150.),
          ("ACC_ObjRelSpd", "SCC11", 0),
          ("Navi_SCC_Curve_Status", "SCC11", 0),
          ("Navi_SCC_Curve_Act", "SCC11", 0),
          ("Navi_SCC_Camera_Act", "SCC11", 0),
          ("Navi_SCC_Camera_Status", "SCC11", 2),
  
          ("ACCMode", "SCC12", 0),
          ("CF_VSM_Prefill", "SCC12", 0),
          ("CF_VSM_DecCmdAct", "SCC12", 0),
          ("CF_VSM_HBACmd", "SCC12", 0),
          ("CF_VSM_Warn", "SCC12", 0),
          ("CF_VSM_Stat", "SCC12", 0),
          ("CF_VSM_BeltCmd", "SCC12", 0),
          ("ACCFailInfo", "SCC12", 0),
          ("StopReq", "SCC12", 0),
          ("CR_VSM_DecCmd", "SCC12", 0),
          ("aReqRaw", "SCC12", 0), #aReqMax
          ("TakeOverReq", "SCC12", 0),
          ("PreFill", "SCC12", 0),
          ("aReqValue", "SCC12", 0), #aReqMin
          ("CF_VSM_ConfMode", "SCC12", 1),
          ("AEB_Failinfo", "SCC12", 0),
          ("AEB_Status", "SCC12", 2),
          ("AEB_CmdAct", "SCC12", 0),
          ("AEB_StopReq", "SCC12", 0),
          ("CR_VSM_Alive", "SCC12", 0),
          ("CR_VSM_ChkSum", "SCC12", 0),
  
          ("SCCDrvModeRValue", "SCC13", 2),
          ("SCC_Equip", "SCC13", 1),
          ("AebDrvSetStatus", "SCC13", 0),
  
          ("JerkUpperLimit", "SCC14", 0),
          ("JerkLowerLimit", "SCC14", 0),
          ("SCCMode2", "SCC14", 0),
          ("ComfortBandUpper", "SCC14", 0),
          ("ComfortBandLower", "SCC14", 0),
        ]
        checks += [
          ("SCC11", 50),
          ("SCC12", 50),
        ]
  
      return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, 2, enforce_checks=False)
  
  