| 
						
						
							
								
							
						
						
					 | 
					 | 
					@ -3,6 +3,7 @@ from cereal import car | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					VisualAlert = car.CarControl.HUDControl.VisualAlert | 
					 | 
					 | 
					 | 
					VisualAlert = car.CarControl.HUDControl.VisualAlert | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					def create_steering_control(packer, apply_steer): | 
					 | 
					 | 
					 | 
					def create_steering_control(packer, apply_steer): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  values = { | 
					 | 
					 | 
					 | 
					  values = { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    "LKAS_Output": apply_steer, | 
					 | 
					 | 
					 | 
					    "LKAS_Output": apply_steer, | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -11,9 +12,11 @@ def create_steering_control(packer, apply_steer): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  } | 
					 | 
					 | 
					 | 
					  } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  return packer.make_can_msg("ES_LKAS", 0, values) | 
					 | 
					 | 
					 | 
					  return packer.make_can_msg("ES_LKAS", 0, values) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					def create_steering_status(packer): | 
					 | 
					 | 
					 | 
					def create_steering_status(packer): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  return packer.make_can_msg("ES_LKAS_State", 0, {}) | 
					 | 
					 | 
					 | 
					  return packer.make_can_msg("ES_LKAS_State", 0, {}) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					def create_es_distance(packer, es_distance_msg, bus, pcm_cancel_cmd): | 
					 | 
					 | 
					 | 
					def create_es_distance(packer, es_distance_msg, bus, pcm_cancel_cmd): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  values = copy.copy(es_distance_msg) | 
					 | 
					 | 
					 | 
					  values = copy.copy(es_distance_msg) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  values["COUNTER"] = (values["COUNTER"] + 1) % 0x10 | 
					 | 
					 | 
					 | 
					  values["COUNTER"] = (values["COUNTER"] + 1) % 0x10 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -21,8 +24,8 @@ def create_es_distance(packer, es_distance_msg, bus, pcm_cancel_cmd): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    values["Cruise_Cancel"] = 1 | 
					 | 
					 | 
					 | 
					    values["Cruise_Cancel"] = 1 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  return packer.make_can_msg("ES_Distance", bus, values) | 
					 | 
					 | 
					 | 
					  return packer.make_can_msg("ES_Distance", bus, values) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					def create_es_lkas_state(packer, es_lkas_state_msg, enabled, visual_alert, left_line, right_line, left_lane_depart, right_lane_depart): | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					def create_es_lkas_state(packer, es_lkas_state_msg, enabled, visual_alert, left_line, right_line, left_lane_depart, right_lane_depart): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  values = copy.copy(es_lkas_state_msg) | 
					 | 
					 | 
					 | 
					  values = copy.copy(es_lkas_state_msg) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  # Filter the stock LKAS "Keep hands on wheel" alert | 
					 | 
					 | 
					 | 
					  # Filter the stock LKAS "Keep hands on wheel" alert | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -64,6 +67,7 @@ def create_es_lkas_state(packer, es_lkas_state_msg, enabled, visual_alert, left_ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  return packer.make_can_msg("ES_LKAS_State", 0, values) | 
					 | 
					 | 
					 | 
					  return packer.make_can_msg("ES_LKAS_State", 0, values) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					def create_es_dashstatus(packer, dashstatus_msg): | 
					 | 
					 | 
					 | 
					def create_es_dashstatus(packer, dashstatus_msg): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  values = copy.copy(dashstatus_msg) | 
					 | 
					 | 
					 | 
					  values = copy.copy(dashstatus_msg) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -73,6 +77,7 @@ def create_es_dashstatus(packer, dashstatus_msg): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  return packer.make_can_msg("ES_DashStatus", 0, values) | 
					 | 
					 | 
					 | 
					  return packer.make_can_msg("ES_DashStatus", 0, values) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					def create_infotainmentstatus(packer, infotainmentstatus_msg, visual_alert): | 
					 | 
					 | 
					 | 
					def create_infotainmentstatus(packer, infotainmentstatus_msg, visual_alert): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  # Filter stock LKAS disabled and Keep hands on steering wheel OFF alerts | 
					 | 
					 | 
					 | 
					  # Filter stock LKAS disabled and Keep hands on steering wheel OFF alerts | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  if infotainmentstatus_msg["LKAS_State_Infotainment"] in (3, 4): | 
					 | 
					 | 
					 | 
					  if infotainmentstatus_msg["LKAS_State_Infotainment"] in (3, 4): | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -88,12 +93,14 @@ def create_infotainmentstatus(packer, infotainmentstatus_msg, visual_alert): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  return packer.make_can_msg("INFOTAINMENT_STATUS", 0, infotainmentstatus_msg) | 
					 | 
					 | 
					 | 
					  return packer.make_can_msg("INFOTAINMENT_STATUS", 0, infotainmentstatus_msg) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					# *** Subaru Pre-global *** | 
					 | 
					 | 
					 | 
					# *** Subaru Pre-global *** | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					def subaru_preglobal_checksum(packer, values, addr): | 
					 | 
					 | 
					 | 
					def subaru_preglobal_checksum(packer, values, addr): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  dat = packer.make_can_msg(addr, 0, values)[2] | 
					 | 
					 | 
					 | 
					  dat = packer.make_can_msg(addr, 0, values)[2] | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  return (sum(dat[:7])) % 256 | 
					 | 
					 | 
					 | 
					  return (sum(dat[:7])) % 256 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					def create_preglobal_steering_control(packer, apply_steer): | 
					 | 
					 | 
					 | 
					def create_preglobal_steering_control(packer, apply_steer): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  values = { | 
					 | 
					 | 
					 | 
					  values = { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    "LKAS_Command": apply_steer, | 
					 | 
					 | 
					 | 
					    "LKAS_Command": apply_steer, | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -103,8 +110,8 @@ def create_preglobal_steering_control(packer, apply_steer): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  return packer.make_can_msg("ES_LKAS", 0, values) | 
					 | 
					 | 
					 | 
					  return packer.make_can_msg("ES_LKAS", 0, values) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					def create_preglobal_es_distance(packer, cruise_button, es_distance_msg): | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					def create_preglobal_es_distance(packer, cruise_button, es_distance_msg): | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  values = copy.copy(es_distance_msg) | 
					 | 
					 | 
					 | 
					  values = copy.copy(es_distance_msg) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  values["Cruise_Button"] = cruise_button | 
					 | 
					 | 
					 | 
					  values["Cruise_Button"] = cruise_button | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					 | 
					
  |